1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2025-09-03 20:28:04 +00:00
Funkin/source/funkin/ui/charSelect/IntroSubState.hx

152 lines
3.1 KiB
Haxe
Raw Permalink Normal View History

2024-09-10 22:55:14 +00:00
package funkin.ui.charSelect;
#if html5
import funkin.graphics.video.FlxVideo;
#end
2024-12-17 14:43:16 +00:00
#if hxvlc
import funkin.graphics.video.FunkinVideoSprite;
2024-09-10 22:55:14 +00:00
#end
import funkin.ui.MusicBeatSubState;
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-12-17 14:43:16 +00:00
#if html5
2024-09-11 18:49:55 +00:00
static final LIGHTS_VIDEO_PATH:String = Paths.stripLibrary(Paths.videos('introSelect'));
2024-12-17 14:43:16 +00:00
#end
#if hxvlc
static final LIGHTS_VIDEO_PATH:String = Paths.videos('introSelect');
#end
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
2024-12-17 14:43:16 +00:00
#if hxvlc
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
2024-12-17 14:43:16 +00:00
#if hxvlc
var vid:FunkinVideoSprite;
2024-09-10 22:55:14 +00:00
function playVideoNative(filePath:String):Void
{
// Video displays OVER the FlxState.
vid = new FunkinVideoSprite(0, 0);
2024-09-10 22:55:14 +00:00
vid.scrollFactor.set();
if (vid != null)
{
vid.zIndex = 0;
2025-01-03 20:29:31 +00:00
vid.active = false;
2025-06-12 14:56:26 +00:00
vid.bitmap.onEncounteredError.add(function(msg:String):Void {
trace('[VLC] Encountered an error: $msg');
onLightsEnd();
});
2024-09-11 18:49:55 +00:00
vid.bitmap.onEndReached.add(onLightsEnd);
vid.bitmap.onFormatSetup.add(() -> {
vid.setGraphicSize(FlxG.initialWidth, FlxG.initialHeight);
vid.updateHitbox();
vid.screenCenter();
});
2024-09-10 22:55:14 +00:00
add(vid);
2024-12-17 14:43:16 +00:00
if (vid.load(filePath)) vid.play();
2024-09-10 22:55:14 +00:00
}
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);
2024-12-17 14:43:16 +00:00
// #elseif hxvlc
2024-09-11 18:49:55 +00:00
// 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 (html5 || hxvlc)
2024-09-10 22:55:14 +00:00
if (vid != null)
{
2024-12-17 14:43:16 +00:00
#if hxvlc
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
}
#end
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();
}
}