2021-02-09 13:07:05 -05:00
|
|
|
package;
|
|
|
|
|
|
|
|
import flixel.FlxSprite;
|
2021-03-09 19:41:03 -05:00
|
|
|
import flixel.FlxState;
|
2021-02-09 13:07:05 -05:00
|
|
|
import flixel.graphics.frames.FlxAtlasFrames;
|
2021-04-09 19:17:14 -04:00
|
|
|
import flixel.math.FlxMath;
|
2021-02-09 13:07:05 -05:00
|
|
|
import flixel.util.FlxTimer;
|
2021-03-09 19:41:03 -05:00
|
|
|
import haxe.io.Path;
|
|
|
|
import lime.app.Future;
|
|
|
|
import lime.app.Promise;
|
2021-02-09 13:07:05 -05:00
|
|
|
import lime.utils.AssetLibrary;
|
|
|
|
import lime.utils.AssetManifest;
|
2021-03-09 19:41:03 -05:00
|
|
|
import lime.utils.Assets as LimeAssets;
|
|
|
|
import openfl.utils.Assets;
|
2021-02-09 13:07:05 -05:00
|
|
|
|
|
|
|
class LoadingState extends MusicBeatState
|
|
|
|
{
|
|
|
|
inline static var MIN_TIME = 1.0;
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
var target:FlxState;
|
|
|
|
var stopMusic = false;
|
|
|
|
var callbacks:MultiCallback;
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
var danceLeft = false;
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-04-09 19:17:14 -04:00
|
|
|
var loadBar:FlxSprite;
|
2021-04-18 04:28:50 -04:00
|
|
|
var funkay:FlxSprite;
|
2021-04-09 19:17:14 -04:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
function new(target:FlxState, stopMusic:Bool)
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
this.target = target;
|
|
|
|
this.stopMusic = stopMusic;
|
|
|
|
}
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
override function create()
|
|
|
|
{
|
2021-04-09 03:03:27 -04:00
|
|
|
var bg:FlxSprite = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, 0xFFcaff4d);
|
|
|
|
add(bg);
|
|
|
|
|
2021-04-18 04:28:50 -04:00
|
|
|
funkay = new FlxSprite();
|
2021-04-09 03:03:27 -04:00
|
|
|
funkay.loadGraphic(Paths.image('funkay'));
|
|
|
|
funkay.setGraphicSize(0, FlxG.height);
|
|
|
|
funkay.updateHitbox();
|
|
|
|
funkay.antialiasing = true;
|
|
|
|
add(funkay);
|
|
|
|
funkay.scrollFactor.set();
|
|
|
|
funkay.screenCenter();
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-04-09 19:17:14 -04:00
|
|
|
loadBar = new FlxSprite(0, FlxG.height - 20).makeGraphic(FlxG.width, 10, 0xFFff16d2);
|
|
|
|
loadBar.screenCenter(X);
|
|
|
|
add(loadBar);
|
|
|
|
|
2021-03-09 19:41:03 -05:00
|
|
|
initSongsManifest().onComplete(function(lib)
|
|
|
|
{
|
|
|
|
callbacks = new MultiCallback(onLoad);
|
|
|
|
var introComplete = callbacks.add("introComplete");
|
|
|
|
checkLoadSong(getSongPath());
|
|
|
|
if (PlayState.SONG.needsVoices)
|
2021-09-22 21:09:28 -04:00
|
|
|
{
|
|
|
|
var files = PlayState.SONG.voiceList;
|
|
|
|
|
|
|
|
if (files == null)
|
|
|
|
files = [""]; // loads with no file name assumption, to load "Voices.ogg" or whatev normally
|
|
|
|
|
|
|
|
for (sndFile in files)
|
|
|
|
{
|
|
|
|
checkLoadSong(getVocalPath(sndFile));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-09 19:41:03 -05:00
|
|
|
checkLibrary("shared");
|
|
|
|
if (PlayState.storyWeek > 0)
|
|
|
|
checkLibrary("week" + PlayState.storyWeek);
|
|
|
|
else
|
|
|
|
checkLibrary("tutorial");
|
|
|
|
|
|
|
|
var fadeTime = 0.5;
|
|
|
|
FlxG.camera.fade(FlxG.camera.bgColor, fadeTime, true);
|
|
|
|
new FlxTimer().start(fadeTime + MIN_TIME, function(_) introComplete());
|
|
|
|
});
|
2021-02-09 13:07:05 -05:00
|
|
|
}
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
function checkLoadSong(path:String)
|
|
|
|
{
|
|
|
|
if (!Assets.cache.hasSound(path))
|
|
|
|
{
|
|
|
|
var library = Assets.getLibrary("songs");
|
2021-03-13 21:11:56 -05:00
|
|
|
var symbolPath = path.split(":").pop();
|
2021-02-10 15:18:14 -05:00
|
|
|
// @:privateAccess
|
|
|
|
// library.types.set(symbolPath, SOUND);
|
|
|
|
// @:privateAccess
|
|
|
|
// library.pathGroups.set(symbolPath, [library.__cacheBreak(symbolPath)]);
|
2021-02-09 13:07:05 -05:00
|
|
|
var callback = callbacks.add("song:" + path);
|
2021-03-09 19:41:03 -05:00
|
|
|
Assets.loadSound(path).onComplete(function(_)
|
|
|
|
{
|
|
|
|
callback();
|
|
|
|
});
|
2021-02-09 13:07:05 -05:00
|
|
|
}
|
|
|
|
}
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
function checkLibrary(library:String)
|
|
|
|
{
|
2021-02-10 15:18:14 -05:00
|
|
|
trace(Assets.hasLibrary(library));
|
2021-02-09 13:07:05 -05:00
|
|
|
if (Assets.getLibrary(library) == null)
|
|
|
|
{
|
2021-02-10 15:18:14 -05:00
|
|
|
@:privateAccess
|
|
|
|
if (!LimeAssets.libraryPaths.exists(library))
|
|
|
|
throw "Missing library: " + library;
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
var callback = callbacks.add("library:" + library);
|
2021-03-09 19:41:03 -05:00
|
|
|
Assets.loadLibrary(library).onComplete(function(_)
|
|
|
|
{
|
|
|
|
callback();
|
|
|
|
});
|
2021-02-09 13:07:05 -05:00
|
|
|
}
|
|
|
|
}
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
override function beatHit()
|
|
|
|
{
|
|
|
|
super.beatHit();
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-04-09 11:38:09 -04:00
|
|
|
// logo.animation.play('bump');
|
2021-02-09 13:07:05 -05:00
|
|
|
danceLeft = !danceLeft;
|
2021-04-09 11:38:09 -04:00
|
|
|
/*
|
|
|
|
if (danceLeft)
|
|
|
|
gfDance.animation.play('danceRight');
|
|
|
|
else
|
|
|
|
gfDance.animation.play('danceLeft'); */
|
2021-02-09 13:07:05 -05:00
|
|
|
}
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-04-09 19:17:14 -04:00
|
|
|
var targetShit:Float = 0;
|
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
|
|
|
super.update(elapsed);
|
2021-04-09 19:17:14 -04:00
|
|
|
|
2021-04-18 04:29:01 -04:00
|
|
|
funkay.setGraphicSize(Std.int(FlxMath.lerp(FlxG.width * 0.88, funkay.width, 0.9)));
|
2021-04-18 04:28:50 -04:00
|
|
|
funkay.updateHitbox();
|
|
|
|
// funkay.updateHitbox();
|
|
|
|
|
|
|
|
if (controls.ACCEPT)
|
|
|
|
{
|
|
|
|
funkay.setGraphicSize(Std.int(funkay.width + 60));
|
|
|
|
funkay.updateHitbox();
|
|
|
|
// funkay.setGraphicSize(0, Std.int(funkay.height + 50));
|
|
|
|
// funkay.updateHitbox();
|
|
|
|
// funkay.screenCenter();
|
|
|
|
}
|
|
|
|
|
2021-04-09 19:17:14 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-02-10 15:18:14 -05:00
|
|
|
#if debug
|
|
|
|
if (FlxG.keys.justPressed.SPACE)
|
|
|
|
trace('fired: ' + callbacks.getFired() + " unfired:" + callbacks.getUnfired());
|
|
|
|
#end
|
2021-02-09 13:07:05 -05:00
|
|
|
}
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
function onLoad()
|
|
|
|
{
|
|
|
|
if (stopMusic && FlxG.sound.music != null)
|
|
|
|
FlxG.sound.music.stop();
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
FlxG.switchState(target);
|
|
|
|
}
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
static function getSongPath()
|
|
|
|
{
|
|
|
|
return Paths.inst(PlayState.SONG.song);
|
|
|
|
}
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-09-22 21:09:28 -04:00
|
|
|
static function getVocalPath(?suffix:String)
|
2021-02-09 13:07:05 -05:00
|
|
|
{
|
2021-09-22 21:09:28 -04:00
|
|
|
return Paths.voices(PlayState.SONG.song, suffix);
|
2021-02-09 13:07:05 -05:00
|
|
|
}
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
inline static public function loadAndSwitchState(target:FlxState, stopMusic = false)
|
|
|
|
{
|
|
|
|
FlxG.switchState(getNextState(target, stopMusic));
|
|
|
|
}
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
static function getNextState(target:FlxState, stopMusic = false):FlxState
|
|
|
|
{
|
2022-02-26 23:26:30 -05:00
|
|
|
if (PlayState.storyWeek == 0)
|
|
|
|
{
|
|
|
|
Paths.setCurrentLevel('tutorial');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Paths.setCurrentLevel("week" + PlayState.storyWeek);
|
|
|
|
}
|
2021-02-11 14:14:02 -05:00
|
|
|
#if NO_PRELOAD_ALL
|
2021-02-09 13:07:05 -05:00
|
|
|
var loaded = isSoundLoaded(getSongPath())
|
|
|
|
&& (!PlayState.SONG.needsVoices || isSoundLoaded(getVocalPath()))
|
|
|
|
&& isLibraryLoaded("shared");
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
if (!loaded)
|
|
|
|
return new LoadingState(target, stopMusic);
|
|
|
|
#end
|
|
|
|
if (stopMusic && FlxG.sound.music != null)
|
|
|
|
FlxG.sound.music.stop();
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
return target;
|
|
|
|
}
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-11 14:14:02 -05:00
|
|
|
#if NO_PRELOAD_ALL
|
2021-02-09 13:07:05 -05:00
|
|
|
static function isSoundLoaded(path:String):Bool
|
|
|
|
{
|
|
|
|
return Assets.cache.hasSound(path);
|
|
|
|
}
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
static function isLibraryLoaded(library:String):Bool
|
|
|
|
{
|
|
|
|
return Assets.getLibrary(library) != null;
|
|
|
|
}
|
|
|
|
#end
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
override function destroy()
|
|
|
|
{
|
|
|
|
super.destroy();
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
callbacks = null;
|
|
|
|
}
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-10 15:18:14 -05:00
|
|
|
static function initSongsManifest()
|
2021-02-09 13:07:05 -05:00
|
|
|
{
|
2021-02-10 15:18:14 -05:00
|
|
|
var id = "songs";
|
2021-02-09 13:07:05 -05:00
|
|
|
var promise = new Promise<AssetLibrary>();
|
|
|
|
|
|
|
|
var library = LimeAssets.getLibrary(id);
|
|
|
|
|
|
|
|
if (library != null)
|
|
|
|
{
|
|
|
|
return Future.withValue(library);
|
|
|
|
}
|
2021-02-10 15:18:14 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
var path = id;
|
|
|
|
var rootPath = null;
|
|
|
|
|
2021-02-10 15:18:14 -05:00
|
|
|
@:privateAccess
|
|
|
|
var libraryPaths = LimeAssets.libraryPaths;
|
|
|
|
if (libraryPaths.exists(id))
|
|
|
|
{
|
|
|
|
path = libraryPaths[id];
|
|
|
|
rootPath = Path.directory(path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (StringTools.endsWith(path, ".bundle"))
|
2021-02-09 13:07:05 -05:00
|
|
|
{
|
2021-02-10 15:18:14 -05:00
|
|
|
rootPath = path;
|
|
|
|
path += "/library.json";
|
2021-02-09 13:07:05 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-10 15:18:14 -05:00
|
|
|
rootPath = Path.directory(path);
|
2021-02-09 13:07:05 -05:00
|
|
|
}
|
2021-02-10 15:18:14 -05:00
|
|
|
@:privateAccess
|
|
|
|
path = LimeAssets.__cacheBreak(path);
|
|
|
|
}
|
2021-02-09 13:07:05 -05:00
|
|
|
|
2021-02-10 15:18:14 -05:00
|
|
|
AssetManifest.loadFromFile(path, rootPath).onComplete(function(manifest)
|
|
|
|
{
|
|
|
|
if (manifest == null)
|
2021-02-09 13:07:05 -05:00
|
|
|
{
|
2021-02-10 15:18:14 -05:00
|
|
|
promise.error("Cannot parse asset manifest for library \"" + id + "\"");
|
|
|
|
return;
|
|
|
|
}
|
2021-02-09 13:07:05 -05:00
|
|
|
|
2021-02-10 15:18:14 -05:00
|
|
|
var library = AssetLibrary.fromManifest(manifest);
|
2021-02-09 13:07:05 -05:00
|
|
|
|
2021-02-10 15:18:14 -05:00
|
|
|
if (library == null)
|
2021-02-09 13:07:05 -05:00
|
|
|
{
|
2021-02-10 15:18:14 -05:00
|
|
|
promise.error("Cannot open library \"" + id + "\"");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
@:privateAccess
|
|
|
|
LimeAssets.libraries.set(id, library);
|
|
|
|
library.onChange.add(LimeAssets.onChange.dispatch);
|
|
|
|
promise.completeWith(Future.withValue(library));
|
|
|
|
}
|
|
|
|
}).onError(function(_)
|
|
|
|
{
|
2021-03-09 19:41:03 -05:00
|
|
|
promise.error("There is no asset library with an ID of \"" + id + "\"");
|
2021-02-10 15:18:14 -05:00
|
|
|
});
|
2021-02-09 13:07:05 -05:00
|
|
|
|
|
|
|
return promise.future;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MultiCallback
|
|
|
|
{
|
|
|
|
public var callback:Void->Void;
|
|
|
|
public var logId:String = null;
|
|
|
|
public var length(default, null) = 0;
|
|
|
|
public var numRemaining(default, null) = 0;
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
var unfired = new Map<String, Void->Void>();
|
|
|
|
var fired = new Array<String>();
|
2021-03-09 19:41:03 -05:00
|
|
|
|
|
|
|
public function new(callback:Void->Void, logId:String = null)
|
2021-02-09 13:07:05 -05:00
|
|
|
{
|
|
|
|
this.callback = callback;
|
|
|
|
this.logId = logId;
|
|
|
|
}
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
public function add(id = "untitled")
|
|
|
|
{
|
|
|
|
id = '$length:$id';
|
|
|
|
length++;
|
|
|
|
numRemaining++;
|
|
|
|
var func:Void->Void = null;
|
2021-03-09 19:41:03 -05:00
|
|
|
func = function()
|
2021-02-09 13:07:05 -05:00
|
|
|
{
|
|
|
|
if (unfired.exists(id))
|
|
|
|
{
|
|
|
|
unfired.remove(id);
|
|
|
|
fired.push(id);
|
|
|
|
numRemaining--;
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
if (logId != null)
|
|
|
|
log('fired $id, $numRemaining remaining');
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
if (numRemaining == 0)
|
|
|
|
{
|
|
|
|
if (logId != null)
|
|
|
|
log('all callbacks fired');
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
log('already fired $id');
|
|
|
|
}
|
|
|
|
unfired[id] = func;
|
|
|
|
return func;
|
|
|
|
}
|
2021-03-09 19:41:03 -05:00
|
|
|
|
2021-02-09 13:07:05 -05:00
|
|
|
inline function log(msg):Void
|
|
|
|
{
|
|
|
|
if (logId != null)
|
|
|
|
trace('$logId: $msg');
|
|
|
|
}
|
2021-03-09 19:41:03 -05:00
|
|
|
|
|
|
|
public function getFired()
|
|
|
|
return fired.copy();
|
|
|
|
|
|
|
|
public function getUnfired()
|
|
|
|
return [for (id in unfired.keys()) id];
|
|
|
|
}
|