1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-15 19:33:36 +00:00
Funkin/source/funkin/ui/charSelect/IntroSubState.hx

134 lines
2.6 KiB
Haxe
Raw Normal View History

2024-09-10 22:55:14 +00:00
package funkin.ui.charSelect;
#if html5
import funkin.graphics.video.FlxVideo;
#end
#if hxCodec
import hxcodec.flixel.FlxVideoSprite;
#end
import funkin.ui.MusicBeatSubState;
import funkin.audio.FunkinSound;
2024-09-11 18:49:55 +00:00
import funkin.save.Save;
2024-09-10 22:55:14 +00:00
/**
2024-09-11 18:49:55 +00:00
* When you first enter the character select state, it will play an introductory video opening up the lights
2024-09-10 22:55:14 +00:00
*/
class IntroSubState extends MusicBeatSubState
{
2024-09-11 18:49:55 +00:00
static final LIGHTS_VIDEO_PATH:String = Paths.stripLibrary(Paths.videos('introSelect'));
2024-09-10 22:55:14 +00:00
public override function create():Void
{
2024-09-11 18:49:55 +00:00
if (Save.instance.oldChar)
{
onLightsEnd();
return;
}
2024-09-10 22:55:14 +00:00
// Pause existing music.
if (FlxG.sound.music != null)
{
FlxG.sound.music.destroy();
FlxG.sound.music = null;
}
#if html5
2024-09-11 18:49:55 +00:00
trace('Playing web video ${LIGHTS_VIDEO_PATH}');
playVideoHTML5(LIGHTS_VIDEO_PATH);
2024-09-10 22:55:14 +00:00
#end
#if hxCodec
2024-09-11 18:49:55 +00:00
trace('Playing native video ${LIGHTS_VIDEO_PATH}');
playVideoNative(LIGHTS_VIDEO_PATH);
2024-09-10 22:55:14 +00:00
#end
2024-09-12 23:56:04 +00:00
// // Im TOO lazy to even care, so uh, yep
// FlxG.camera.zoom = 0.66666666666666666666666666666667;
// vid.x = -(FlxG.width - (FlxG.width * FlxG.camera.zoom));
// vid.y = -((FlxG.height - (FlxG.height * FlxG.camera.zoom)) * 0.75);
2024-09-10 22:55:14 +00:00
}
#if html5
var vid:FlxVideo;
function playVideoHTML5(filePath:String):Void
{
// Video displays OVER the FlxState.
vid = new FlxVideo(filePath);
vid.scrollFactor.set();
if (vid != null)
{
vid.zIndex = 0;
2024-09-11 18:49:55 +00:00
vid.finishCallback = onLightsEnd;
2024-09-10 22:55:14 +00:00
add(vid);
}
else
{
trace('ALERT: Video is null! Could not play cutscene!');
}
}
#end
#if hxCodec
var vid:FlxVideoSprite;
function playVideoNative(filePath:String):Void
{
// Video displays OVER the FlxState.
vid = new FlxVideoSprite(0, 0);
vid.scrollFactor.set();
if (vid != null)
{
vid.zIndex = 0;
2024-09-11 18:49:55 +00:00
vid.bitmap.onEndReached.add(onLightsEnd);
2024-09-10 22:55:14 +00:00
add(vid);
vid.play(filePath, false);
}
else
{
trace('ALERT: Video is null! Could not play cutscene!');
}
}
#end
public override function update(elapsed:Float):Void
{
super.update(elapsed);
2024-09-11 18:49:55 +00:00
// if (!introSound.paused)
// {
// #if html5
// @:privateAccess
// vid.netStream.seek(introSound.time);
// #elseif hxCodec
// vid.bitmap.time = Std.int(introSound.time);
// #end
// }
2024-09-10 22:55:14 +00:00
}
/**
2024-09-11 18:49:55 +00:00
* When the lights video finishes, it will close the substate
2024-09-10 22:55:14 +00:00
*/
2024-09-11 18:49:55 +00:00
function onLightsEnd():Void
2024-09-10 22:55:14 +00:00
{
if (vid != null)
{
#if hxCodec
2024-09-10 22:55:14 +00:00
vid.stop();
#end
2024-09-10 22:55:14 +00:00
remove(vid);
vid.destroy();
vid = null;
2024-09-10 22:55:14 +00:00
}
2024-09-11 18:49:55 +00:00
FlxG.camera.zoom = 1;
2024-09-10 22:55:14 +00:00
close();
}
}