diff --git a/source/LoadingState.hx b/source/LoadingState.hx index 391b05c53..2c520ea0d 100644 --- a/source/LoadingState.hx +++ b/source/LoadingState.hx @@ -4,6 +4,7 @@ import flixel.FlxG; import flixel.FlxSprite; import flixel.FlxState; import flixel.graphics.frames.FlxAtlasFrames; +import flixel.math.FlxMath; import flixel.util.FlxTimer; import haxe.io.Path; import lime.app.Future; @@ -23,6 +24,8 @@ class LoadingState extends MusicBeatState var danceLeft = false; + var loadBar:FlxSprite; + function new(target:FlxState, stopMusic:Bool) { super(); @@ -44,6 +47,10 @@ class LoadingState extends MusicBeatState funkay.scrollFactor.set(); funkay.screenCenter(); + loadBar = new FlxSprite(0, FlxG.height - 20).makeGraphic(FlxG.width, 10, 0xFFff16d2); + loadBar.screenCenter(X); + add(loadBar); + initSongsManifest().onComplete(function(lib) { callbacks = new MultiCallback(onLoad); @@ -111,9 +118,20 @@ class LoadingState extends MusicBeatState gfDance.animation.play('danceLeft'); */ } + var targetShit:Float = 0; + override function update(elapsed:Float) { super.update(elapsed); + + if (callbacks != null) + { + targetShit = FlxMath.remapToRange(callbacks.numRemaining / callbacks.length, 1, 0, 0, 1); + + loadBar.scale.x = FlxMath.lerp(loadBar.scale.x, targetShit, 0.50); + FlxG.watch.addQuick('percentage?', callbacks.numRemaining / callbacks.length); + } + #if debug if (FlxG.keys.justPressed.SPACE) trace('fired: ' + callbacks.getFired() + " unfired:" + callbacks.getUnfired()); diff --git a/source/StoryMenuState.hx b/source/StoryMenuState.hx index 692f0449c..55ea89e3f 100644 --- a/source/StoryMenuState.hx +++ b/source/StoryMenuState.hx @@ -55,7 +55,7 @@ class StoryMenuState extends MusicBeatState "MOMMY MUST MURDER", "RED SNOW", "hating simulator ft. moawling", - "cock Joke" + "TANKMAN" ]; var txtWeekTitle:FlxText; diff --git a/source/TitleState.hx b/source/TitleState.hx index 6e4e1222b..9f5bfd3bb 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -20,6 +20,15 @@ import flixel.util.FlxTimer; import lime.app.Application; import lime.ui.Window; import openfl.Assets; +import openfl.display.Sprite; +import openfl.events.AsyncErrorEvent; +import openfl.events.AsyncErrorEvent; +import openfl.events.Event; +import openfl.events.MouseEvent; +import openfl.events.NetStatusEvent; +import openfl.media.Video; +import openfl.net.NetConnection; +import openfl.net.NetStream; import shaderslmfao.ColorSwap; import ui.PreferencesMenu; @@ -50,6 +59,10 @@ class TitleState extends MusicBeatState var swagShader:ColorSwap; var thingie:FlxSprite; + var video:Video; + var netStream:NetStream; + private var overlay:Sprite; + override public function create():Void { #if polymod @@ -96,6 +109,31 @@ class TitleState extends MusicBeatState FlxG.switchState(new FreeplayState()); #elseif CHARTING FlxG.switchState(new ChartingState()); + #elseif web + if (!initialized) + { + video = new Video(); + FlxG.stage.addChild(video); + + var netConnection = new NetConnection(); + netConnection.connect(null); + + netStream = new NetStream(netConnection); + netStream.client = {onMetaData: client_onMetaData}; + netStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, netStream_onAsyncError); + netConnection.addEventListener(NetStatusEvent.NET_STATUS, netConnection_onNetStatus); + // netStream.addEventListener(NetStatusEvent.NET_STATUS) // netStream.play(Paths.file('music/kickstarterTrailer.mp4')); + + overlay = new Sprite(); + overlay.graphics.beginFill(0, 0.5); + overlay.graphics.drawRect(0, 0, 1280, 720); + overlay.addEventListener(MouseEvent.MOUSE_DOWN, overlay_onMouseDown); + + overlay.buttonMode = true; + FlxG.stage.addChild(overlay); + } + + // netConnection.addEventListener(MouseEvent.MOUSE_DOWN, overlay_onMouseDown); #else new FlxTimer().start(1, function(tmr:FlxTimer) { @@ -105,14 +143,48 @@ class TitleState extends MusicBeatState #if discord_rpc DiscordClient.initialize(); - - Application.current.onExit.add (function (exitCode) { + + Application.current.onExit.add(function(exitCode) + { DiscordClient.shutdown(); - }); + }); #end } + private function client_onMetaData(metaData:Dynamic) + { + video.attachNetStream(netStream); + + video.width = video.videoWidth; + video.height = video.videoHeight; + } + + private function netStream_onAsyncError(event:AsyncErrorEvent):Void + { + trace("Error loading video"); + } + + private function netConnection_onNetStatus(event:NetStatusEvent):Void + { + if (event.info.code == 'NetStream.Play.Complete') + { + netStream.dispose(); + FlxG.stage.removeChild(video); + + startIntro(); + } + + trace(event.toString()); + } + + private function overlay_onMouseDown(event:MouseEvent):Void + { + netStream.play(Paths.file('music/kickstarterTrailer.mp4')); + FlxG.stage.removeChild(overlay); + } + var logoBl:FlxSprite; + var gfDance:FlxSprite; var danceLeft:Bool = false; var titleText:FlxSprite; @@ -352,8 +424,18 @@ class TitleState extends MusicBeatState skipIntro(); } - if (FlxG.keys.justPressed.SPACE) - swagShader.hasOutline = !swagShader.hasOutline; + #if web + if (!initialized && FlxG.keys.justPressed.ENTER) + { + netStream.dispose(); + FlxG.stage.removeChild(video); + + startIntro(); + } + #end + + // if (FlxG.keys.justPressed.SPACE) + // swagShader.hasOutline = !swagShader.hasOutline; if (controls.UI_LEFT) {