2021-02-09 18:07:05 +00:00
|
|
|
package;
|
|
|
|
|
2021-02-10 20:18:14 +00:00
|
|
|
import lime.app.Promise;
|
|
|
|
import lime.app.Future;
|
2021-02-09 18:07:05 +00:00
|
|
|
import flixel.FlxG;
|
|
|
|
import flixel.FlxState;
|
|
|
|
import flixel.FlxSprite;
|
|
|
|
import flixel.graphics.frames.FlxAtlasFrames;
|
|
|
|
import flixel.util.FlxTimer;
|
|
|
|
|
|
|
|
import openfl.utils.Assets;
|
|
|
|
import lime.utils.Assets as LimeAssets;
|
|
|
|
import lime.utils.AssetLibrary;
|
|
|
|
import lime.utils.AssetManifest;
|
|
|
|
|
|
|
|
import haxe.io.Path;
|
|
|
|
|
|
|
|
class LoadingState extends MusicBeatState
|
|
|
|
{
|
|
|
|
inline static var MIN_TIME = 1.0;
|
|
|
|
|
|
|
|
var target:FlxState;
|
|
|
|
var stopMusic = false;
|
|
|
|
var callbacks:MultiCallback;
|
|
|
|
|
|
|
|
var logo:FlxSprite;
|
|
|
|
var gfDance:FlxSprite;
|
|
|
|
var danceLeft = false;
|
|
|
|
|
|
|
|
function new(target:FlxState, stopMusic:Bool)
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
this.target = target;
|
|
|
|
this.stopMusic = stopMusic;
|
|
|
|
}
|
|
|
|
|
|
|
|
override function create()
|
|
|
|
{
|
|
|
|
logo = new FlxSprite(-150, -100);
|
2021-02-10 20:18:14 +00:00
|
|
|
logo.frames = Paths.getSparrowAtlas('logoBumpin');
|
2021-02-09 18:07:05 +00:00
|
|
|
logo.antialiasing = true;
|
|
|
|
logo.animation.addByPrefix('bump', 'logo bumpin', 24);
|
|
|
|
logo.animation.play('bump');
|
|
|
|
logo.updateHitbox();
|
|
|
|
// logoBl.screenCenter();
|
|
|
|
// logoBl.color = FlxColor.BLACK;
|
|
|
|
|
|
|
|
gfDance = new FlxSprite(FlxG.width * 0.4, FlxG.height * 0.07);
|
2021-02-10 20:18:14 +00:00
|
|
|
gfDance.frames = Paths.getSparrowAtlas('gfDanceTitle');
|
2021-02-09 18:07:05 +00:00
|
|
|
gfDance.animation.addByIndices('danceLeft', 'gfDance', [30, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], "", 24, false);
|
|
|
|
gfDance.animation.addByIndices('danceRight', 'gfDance', [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29], "", 24, false);
|
|
|
|
gfDance.antialiasing = true;
|
|
|
|
add(gfDance);
|
|
|
|
add(logo);
|
|
|
|
|
2021-02-10 20:18:14 +00:00
|
|
|
initSongsManifest().onComplete
|
|
|
|
(
|
|
|
|
function (lib)
|
|
|
|
{
|
|
|
|
callbacks = new MultiCallback(onLoad);
|
|
|
|
var introComplete = callbacks.add("introComplete");
|
|
|
|
checkLoadSong(getSongPath());
|
|
|
|
if (PlayState.SONG.needsVoices)
|
|
|
|
checkLoadSong(getVocalPath());
|
|
|
|
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 18:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkLoadSong(path:String)
|
|
|
|
{
|
|
|
|
if (!Assets.cache.hasSound(path))
|
|
|
|
{
|
|
|
|
var library = Assets.getLibrary("songs");
|
|
|
|
final symbolPath = path.split(":").pop();
|
2021-02-10 20:18:14 +00:00
|
|
|
// @:privateAccess
|
|
|
|
// library.types.set(symbolPath, SOUND);
|
|
|
|
// @:privateAccess
|
|
|
|
// library.pathGroups.set(symbolPath, [library.__cacheBreak(symbolPath)]);
|
2021-02-09 18:07:05 +00:00
|
|
|
var callback = callbacks.add("song:" + path);
|
|
|
|
Assets.loadSound(path).onComplete(function (_) { callback(); });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkLibrary(library:String)
|
|
|
|
{
|
2021-02-10 20:18:14 +00:00
|
|
|
trace(Assets.hasLibrary(library));
|
2021-02-09 18:07:05 +00:00
|
|
|
if (Assets.getLibrary(library) == null)
|
|
|
|
{
|
2021-02-10 20:18:14 +00:00
|
|
|
@:privateAccess
|
|
|
|
if (!LimeAssets.libraryPaths.exists(library))
|
|
|
|
throw "Missing library: " + library;
|
|
|
|
|
2021-02-09 18:07:05 +00:00
|
|
|
var callback = callbacks.add("library:" + library);
|
|
|
|
Assets.loadLibrary(library).onComplete(function (_) { callback(); });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override function beatHit()
|
|
|
|
{
|
|
|
|
super.beatHit();
|
|
|
|
|
|
|
|
logo.animation.play('bump');
|
|
|
|
danceLeft = !danceLeft;
|
|
|
|
|
|
|
|
if (danceLeft)
|
|
|
|
gfDance.animation.play('danceRight');
|
|
|
|
else
|
|
|
|
gfDance.animation.play('danceLeft');
|
|
|
|
}
|
|
|
|
|
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
|
|
|
super.update(elapsed);
|
2021-02-10 20:18:14 +00:00
|
|
|
#if debug
|
|
|
|
if (FlxG.keys.justPressed.SPACE)
|
|
|
|
trace('fired: ' + callbacks.getFired() + " unfired:" + callbacks.getUnfired());
|
|
|
|
#end
|
2021-02-09 18:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function onLoad()
|
|
|
|
{
|
|
|
|
if (stopMusic && FlxG.sound.music != null)
|
|
|
|
FlxG.sound.music.stop();
|
|
|
|
|
|
|
|
FlxG.switchState(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
static function getSongPath()
|
|
|
|
{
|
|
|
|
return Paths.inst(PlayState.SONG.song);
|
|
|
|
}
|
|
|
|
|
|
|
|
static function getVocalPath()
|
|
|
|
{
|
|
|
|
return Paths.voices(PlayState.SONG.song);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static public function loadAndSwitchState(target:FlxState, stopMusic = false)
|
|
|
|
{
|
|
|
|
FlxG.switchState(getNextState(target, stopMusic));
|
|
|
|
}
|
|
|
|
|
|
|
|
static function getNextState(target:FlxState, stopMusic = false):FlxState
|
|
|
|
{
|
2021-02-10 20:18:14 +00:00
|
|
|
Paths.setCurrentLevel("week" + PlayState.storyWeek);
|
2021-02-11 19:14:02 +00:00
|
|
|
#if NO_PRELOAD_ALL
|
2021-02-09 18:07:05 +00:00
|
|
|
var loaded = isSoundLoaded(getSongPath())
|
|
|
|
&& (!PlayState.SONG.needsVoices || isSoundLoaded(getVocalPath()))
|
|
|
|
&& isLibraryLoaded("shared");
|
|
|
|
|
|
|
|
if (!loaded)
|
|
|
|
return new LoadingState(target, stopMusic);
|
|
|
|
#end
|
|
|
|
if (stopMusic && FlxG.sound.music != null)
|
|
|
|
FlxG.sound.music.stop();
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2021-02-11 19:14:02 +00:00
|
|
|
#if NO_PRELOAD_ALL
|
2021-02-09 18:07:05 +00:00
|
|
|
static function isSoundLoaded(path:String):Bool
|
|
|
|
{
|
|
|
|
return Assets.cache.hasSound(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static function isLibraryLoaded(library:String):Bool
|
|
|
|
{
|
|
|
|
return Assets.getLibrary(library) != null;
|
|
|
|
}
|
|
|
|
#end
|
|
|
|
|
|
|
|
override function destroy()
|
|
|
|
{
|
|
|
|
super.destroy();
|
|
|
|
|
|
|
|
callbacks = null;
|
|
|
|
}
|
|
|
|
|
2021-02-10 20:18:14 +00:00
|
|
|
static function initSongsManifest()
|
2021-02-09 18:07:05 +00:00
|
|
|
{
|
2021-02-10 20:18:14 +00:00
|
|
|
var id = "songs";
|
2021-02-09 18:07:05 +00:00
|
|
|
var promise = new Promise<AssetLibrary>();
|
|
|
|
|
|
|
|
var library = LimeAssets.getLibrary(id);
|
|
|
|
|
|
|
|
if (library != null)
|
|
|
|
{
|
|
|
|
return Future.withValue(library);
|
|
|
|
}
|
2021-02-10 20:18:14 +00:00
|
|
|
|
2021-02-09 18:07:05 +00:00
|
|
|
var path = id;
|
|
|
|
var rootPath = null;
|
|
|
|
|
2021-02-10 20:18:14 +00: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 18:07:05 +00:00
|
|
|
{
|
2021-02-10 20:18:14 +00:00
|
|
|
rootPath = path;
|
|
|
|
path += "/library.json";
|
2021-02-09 18:07:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-10 20:18:14 +00:00
|
|
|
rootPath = Path.directory(path);
|
2021-02-09 18:07:05 +00:00
|
|
|
}
|
2021-02-10 20:18:14 +00:00
|
|
|
@:privateAccess
|
|
|
|
path = LimeAssets.__cacheBreak(path);
|
|
|
|
}
|
2021-02-09 18:07:05 +00:00
|
|
|
|
2021-02-10 20:18:14 +00:00
|
|
|
AssetManifest.loadFromFile(path, rootPath).onComplete(function(manifest)
|
|
|
|
{
|
|
|
|
if (manifest == null)
|
2021-02-09 18:07:05 +00:00
|
|
|
{
|
2021-02-10 20:18:14 +00:00
|
|
|
promise.error("Cannot parse asset manifest for library \"" + id + "\"");
|
|
|
|
return;
|
|
|
|
}
|
2021-02-09 18:07:05 +00:00
|
|
|
|
2021-02-10 20:18:14 +00:00
|
|
|
var library = AssetLibrary.fromManifest(manifest);
|
2021-02-09 18:07:05 +00:00
|
|
|
|
2021-02-10 20:18:14 +00:00
|
|
|
if (library == null)
|
2021-02-09 18:07:05 +00:00
|
|
|
{
|
2021-02-10 20:18:14 +00: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(_)
|
|
|
|
{
|
|
|
|
promise.error("There is no asset library with an ID of \"" + id + "\"");
|
|
|
|
});
|
2021-02-09 18:07:05 +00: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;
|
|
|
|
|
|
|
|
var unfired = new Map<String, Void->Void>();
|
|
|
|
var fired = new Array<String>();
|
|
|
|
|
|
|
|
public function new (callback:Void->Void, logId:String = null)
|
|
|
|
{
|
|
|
|
this.callback = callback;
|
|
|
|
this.logId = logId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function add(id = "untitled")
|
|
|
|
{
|
|
|
|
id = '$length:$id';
|
|
|
|
length++;
|
|
|
|
numRemaining++;
|
|
|
|
var func:Void->Void = null;
|
|
|
|
func = function ()
|
|
|
|
{
|
|
|
|
if (unfired.exists(id))
|
|
|
|
{
|
|
|
|
unfired.remove(id);
|
|
|
|
fired.push(id);
|
|
|
|
numRemaining--;
|
|
|
|
|
|
|
|
if (logId != null)
|
|
|
|
log('fired $id, $numRemaining remaining');
|
|
|
|
|
|
|
|
if (numRemaining == 0)
|
|
|
|
{
|
|
|
|
if (logId != null)
|
|
|
|
log('all callbacks fired');
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
log('already fired $id');
|
|
|
|
}
|
|
|
|
unfired[id] = func;
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline function log(msg):Void
|
|
|
|
{
|
|
|
|
if (logId != null)
|
|
|
|
trace('$logId: $msg');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFired() return fired.copy();
|
2021-02-10 20:18:14 +00:00
|
|
|
public function getUnfired() return [for (id in unfired.keys()) id];
|
2021-02-09 18:07:05 +00:00
|
|
|
}
|