file and folder detection
This commit is contained in:
parent
f0b799410c
commit
0e44032eda
|
@ -1,39 +1,37 @@
|
||||||
package;
|
package;
|
||||||
|
|
||||||
import lime.app.Promise;
|
|
||||||
import lime.app.Future;
|
|
||||||
import flixel.FlxG;
|
import flixel.FlxG;
|
||||||
import flixel.FlxState;
|
|
||||||
import flixel.FlxSprite;
|
import flixel.FlxSprite;
|
||||||
|
import flixel.FlxState;
|
||||||
import flixel.graphics.frames.FlxAtlasFrames;
|
import flixel.graphics.frames.FlxAtlasFrames;
|
||||||
import flixel.util.FlxTimer;
|
import flixel.util.FlxTimer;
|
||||||
|
import haxe.io.Path;
|
||||||
import openfl.utils.Assets;
|
import lime.app.Future;
|
||||||
import lime.utils.Assets as LimeAssets;
|
import lime.app.Promise;
|
||||||
import lime.utils.AssetLibrary;
|
import lime.utils.AssetLibrary;
|
||||||
import lime.utils.AssetManifest;
|
import lime.utils.AssetManifest;
|
||||||
|
import lime.utils.Assets as LimeAssets;
|
||||||
import haxe.io.Path;
|
import openfl.utils.Assets;
|
||||||
|
|
||||||
class LoadingState extends MusicBeatState
|
class LoadingState extends MusicBeatState
|
||||||
{
|
{
|
||||||
inline static var MIN_TIME = 1.0;
|
inline static var MIN_TIME = 1.0;
|
||||||
|
|
||||||
var target:FlxState;
|
var target:FlxState;
|
||||||
var stopMusic = false;
|
var stopMusic = false;
|
||||||
var callbacks:MultiCallback;
|
var callbacks:MultiCallback;
|
||||||
|
|
||||||
var logo:FlxSprite;
|
var logo:FlxSprite;
|
||||||
var gfDance:FlxSprite;
|
var gfDance:FlxSprite;
|
||||||
var danceLeft = false;
|
var danceLeft = false;
|
||||||
|
|
||||||
function new(target:FlxState, stopMusic:Bool)
|
function new(target:FlxState, stopMusic:Bool)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.stopMusic = stopMusic;
|
this.stopMusic = stopMusic;
|
||||||
}
|
}
|
||||||
|
|
||||||
override function create()
|
override function create()
|
||||||
{
|
{
|
||||||
logo = new FlxSprite(-150, -100);
|
logo = new FlxSprite(-150, -100);
|
||||||
|
@ -52,29 +50,26 @@ class LoadingState extends MusicBeatState
|
||||||
gfDance.antialiasing = true;
|
gfDance.antialiasing = true;
|
||||||
add(gfDance);
|
add(gfDance);
|
||||||
add(logo);
|
add(logo);
|
||||||
|
|
||||||
initSongsManifest().onComplete
|
initSongsManifest().onComplete(function(lib)
|
||||||
(
|
{
|
||||||
function (lib)
|
callbacks = new MultiCallback(onLoad);
|
||||||
{
|
var introComplete = callbacks.add("introComplete");
|
||||||
callbacks = new MultiCallback(onLoad);
|
checkLoadSong(getSongPath());
|
||||||
var introComplete = callbacks.add("introComplete");
|
if (PlayState.SONG.needsVoices)
|
||||||
checkLoadSong(getSongPath());
|
checkLoadSong(getVocalPath());
|
||||||
if (PlayState.SONG.needsVoices)
|
checkLibrary("shared");
|
||||||
checkLoadSong(getVocalPath());
|
if (PlayState.storyWeek > 0)
|
||||||
checkLibrary("shared");
|
checkLibrary("week" + PlayState.storyWeek);
|
||||||
if (PlayState.storyWeek > 0)
|
else
|
||||||
checkLibrary("week" + PlayState.storyWeek);
|
checkLibrary("tutorial");
|
||||||
else
|
|
||||||
checkLibrary("tutorial");
|
var fadeTime = 0.5;
|
||||||
|
FlxG.camera.fade(FlxG.camera.bgColor, fadeTime, true);
|
||||||
var fadeTime = 0.5;
|
new FlxTimer().start(fadeTime + MIN_TIME, function(_) introComplete());
|
||||||
FlxG.camera.fade(FlxG.camera.bgColor, fadeTime, true);
|
});
|
||||||
new FlxTimer().start(fadeTime + MIN_TIME, function(_) introComplete());
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkLoadSong(path:String)
|
function checkLoadSong(path:String)
|
||||||
{
|
{
|
||||||
if (!Assets.cache.hasSound(path))
|
if (!Assets.cache.hasSound(path))
|
||||||
|
@ -86,10 +81,13 @@ class LoadingState extends MusicBeatState
|
||||||
// @:privateAccess
|
// @:privateAccess
|
||||||
// library.pathGroups.set(symbolPath, [library.__cacheBreak(symbolPath)]);
|
// library.pathGroups.set(symbolPath, [library.__cacheBreak(symbolPath)]);
|
||||||
var callback = callbacks.add("song:" + path);
|
var callback = callbacks.add("song:" + path);
|
||||||
Assets.loadSound(path).onComplete(function (_) { callback(); });
|
Assets.loadSound(path).onComplete(function(_)
|
||||||
|
{
|
||||||
|
callback();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkLibrary(library:String)
|
function checkLibrary(library:String)
|
||||||
{
|
{
|
||||||
trace(Assets.hasLibrary(library));
|
trace(Assets.hasLibrary(library));
|
||||||
|
@ -98,25 +96,28 @@ class LoadingState extends MusicBeatState
|
||||||
@:privateAccess
|
@:privateAccess
|
||||||
if (!LimeAssets.libraryPaths.exists(library))
|
if (!LimeAssets.libraryPaths.exists(library))
|
||||||
throw "Missing library: " + library;
|
throw "Missing library: " + library;
|
||||||
|
|
||||||
var callback = callbacks.add("library:" + library);
|
var callback = callbacks.add("library:" + library);
|
||||||
Assets.loadLibrary(library).onComplete(function (_) { callback(); });
|
Assets.loadLibrary(library).onComplete(function(_)
|
||||||
|
{
|
||||||
|
callback();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override function beatHit()
|
override function beatHit()
|
||||||
{
|
{
|
||||||
super.beatHit();
|
super.beatHit();
|
||||||
|
|
||||||
logo.animation.play('bump');
|
logo.animation.play('bump');
|
||||||
danceLeft = !danceLeft;
|
danceLeft = !danceLeft;
|
||||||
|
|
||||||
if (danceLeft)
|
if (danceLeft)
|
||||||
gfDance.animation.play('danceRight');
|
gfDance.animation.play('danceRight');
|
||||||
else
|
else
|
||||||
gfDance.animation.play('danceLeft');
|
gfDance.animation.play('danceLeft');
|
||||||
}
|
}
|
||||||
|
|
||||||
override function update(elapsed:Float)
|
override function update(elapsed:Float)
|
||||||
{
|
{
|
||||||
super.update(elapsed);
|
super.update(elapsed);
|
||||||
|
@ -125,30 +126,30 @@ class LoadingState extends MusicBeatState
|
||||||
trace('fired: ' + callbacks.getFired() + " unfired:" + callbacks.getUnfired());
|
trace('fired: ' + callbacks.getFired() + " unfired:" + callbacks.getUnfired());
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
function onLoad()
|
function onLoad()
|
||||||
{
|
{
|
||||||
if (stopMusic && FlxG.sound.music != null)
|
if (stopMusic && FlxG.sound.music != null)
|
||||||
FlxG.sound.music.stop();
|
FlxG.sound.music.stop();
|
||||||
|
|
||||||
FlxG.switchState(target);
|
FlxG.switchState(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function getSongPath()
|
static function getSongPath()
|
||||||
{
|
{
|
||||||
return Paths.inst(PlayState.SONG.song);
|
return Paths.inst(PlayState.SONG.song);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function getVocalPath()
|
static function getVocalPath()
|
||||||
{
|
{
|
||||||
return Paths.voices(PlayState.SONG.song);
|
return Paths.voices(PlayState.SONG.song);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static public function loadAndSwitchState(target:FlxState, stopMusic = false)
|
inline static public function loadAndSwitchState(target:FlxState, stopMusic = false)
|
||||||
{
|
{
|
||||||
FlxG.switchState(getNextState(target, stopMusic));
|
FlxG.switchState(getNextState(target, stopMusic));
|
||||||
}
|
}
|
||||||
|
|
||||||
static function getNextState(target:FlxState, stopMusic = false):FlxState
|
static function getNextState(target:FlxState, stopMusic = false):FlxState
|
||||||
{
|
{
|
||||||
Paths.setCurrentLevel("week" + PlayState.storyWeek);
|
Paths.setCurrentLevel("week" + PlayState.storyWeek);
|
||||||
|
@ -156,35 +157,35 @@ class LoadingState extends MusicBeatState
|
||||||
var loaded = isSoundLoaded(getSongPath())
|
var loaded = isSoundLoaded(getSongPath())
|
||||||
&& (!PlayState.SONG.needsVoices || isSoundLoaded(getVocalPath()))
|
&& (!PlayState.SONG.needsVoices || isSoundLoaded(getVocalPath()))
|
||||||
&& isLibraryLoaded("shared");
|
&& isLibraryLoaded("shared");
|
||||||
|
|
||||||
if (!loaded)
|
if (!loaded)
|
||||||
return new LoadingState(target, stopMusic);
|
return new LoadingState(target, stopMusic);
|
||||||
#end
|
#end
|
||||||
if (stopMusic && FlxG.sound.music != null)
|
if (stopMusic && FlxG.sound.music != null)
|
||||||
FlxG.sound.music.stop();
|
FlxG.sound.music.stop();
|
||||||
|
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if NO_PRELOAD_ALL
|
#if NO_PRELOAD_ALL
|
||||||
static function isSoundLoaded(path:String):Bool
|
static function isSoundLoaded(path:String):Bool
|
||||||
{
|
{
|
||||||
return Assets.cache.hasSound(path);
|
return Assets.cache.hasSound(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function isLibraryLoaded(library:String):Bool
|
static function isLibraryLoaded(library:String):Bool
|
||||||
{
|
{
|
||||||
return Assets.getLibrary(library) != null;
|
return Assets.getLibrary(library) != null;
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
|
|
||||||
override function destroy()
|
override function destroy()
|
||||||
{
|
{
|
||||||
super.destroy();
|
super.destroy();
|
||||||
|
|
||||||
callbacks = null;
|
callbacks = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function initSongsManifest()
|
static function initSongsManifest()
|
||||||
{
|
{
|
||||||
var id = "songs";
|
var id = "songs";
|
||||||
|
@ -245,7 +246,7 @@ class LoadingState extends MusicBeatState
|
||||||
}
|
}
|
||||||
}).onError(function(_)
|
}).onError(function(_)
|
||||||
{
|
{
|
||||||
promise.error("There is no asset library with an ID of \"" + id + "\"");
|
promise.error("There is no asset library with an ID of \"" + id + "\"");
|
||||||
});
|
});
|
||||||
|
|
||||||
return promise.future;
|
return promise.future;
|
||||||
|
@ -258,33 +259,33 @@ class MultiCallback
|
||||||
public var logId:String = null;
|
public var logId:String = null;
|
||||||
public var length(default, null) = 0;
|
public var length(default, null) = 0;
|
||||||
public var numRemaining(default, null) = 0;
|
public var numRemaining(default, null) = 0;
|
||||||
|
|
||||||
var unfired = new Map<String, Void->Void>();
|
var unfired = new Map<String, Void->Void>();
|
||||||
var fired = new Array<String>();
|
var fired = new Array<String>();
|
||||||
|
|
||||||
public function new (callback:Void->Void, logId:String = null)
|
public function new(callback:Void->Void, logId:String = null)
|
||||||
{
|
{
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.logId = logId;
|
this.logId = logId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add(id = "untitled")
|
public function add(id = "untitled")
|
||||||
{
|
{
|
||||||
id = '$length:$id';
|
id = '$length:$id';
|
||||||
length++;
|
length++;
|
||||||
numRemaining++;
|
numRemaining++;
|
||||||
var func:Void->Void = null;
|
var func:Void->Void = null;
|
||||||
func = function ()
|
func = function()
|
||||||
{
|
{
|
||||||
if (unfired.exists(id))
|
if (unfired.exists(id))
|
||||||
{
|
{
|
||||||
unfired.remove(id);
|
unfired.remove(id);
|
||||||
fired.push(id);
|
fired.push(id);
|
||||||
numRemaining--;
|
numRemaining--;
|
||||||
|
|
||||||
if (logId != null)
|
if (logId != null)
|
||||||
log('fired $id, $numRemaining remaining');
|
log('fired $id, $numRemaining remaining');
|
||||||
|
|
||||||
if (numRemaining == 0)
|
if (numRemaining == 0)
|
||||||
{
|
{
|
||||||
if (logId != null)
|
if (logId != null)
|
||||||
|
@ -298,13 +299,16 @@ class MultiCallback
|
||||||
unfired[id] = func;
|
unfired[id] = func;
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline function log(msg):Void
|
inline function log(msg):Void
|
||||||
{
|
{
|
||||||
if (logId != null)
|
if (logId != null)
|
||||||
trace('$logId: $msg');
|
trace('$logId: $msg');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFired() return fired.copy();
|
public function getFired()
|
||||||
public function getUnfired() return [for (id in unfired.keys()) id];
|
return fired.copy();
|
||||||
}
|
|
||||||
|
public function getUnfired()
|
||||||
|
return [for (id in unfired.keys()) id];
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package;
|
||||||
|
|
||||||
|
import flixel.text.FlxText;
|
||||||
|
import sys.FileSystem;
|
||||||
|
|
||||||
|
class ModdingSubstate extends MusicBeatSubstate
|
||||||
|
{
|
||||||
|
public function new():Void
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
|
||||||
|
// var pathShit
|
||||||
|
|
||||||
|
var modList = [];
|
||||||
|
|
||||||
|
for (file in FileSystem.readDirectory('./mods'))
|
||||||
|
{
|
||||||
|
if (FileSystem.isDirectory("./mods/" + file))
|
||||||
|
modList.push(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
trace(modList);
|
||||||
|
|
||||||
|
var loopNum:Int = 0;
|
||||||
|
for (i in modList)
|
||||||
|
{
|
||||||
|
var txt:FlxText = new FlxText(0, 10 + (40 * loopNum), 0, i, 32);
|
||||||
|
add(txt);
|
||||||
|
|
||||||
|
loopNum++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,6 +19,10 @@ class OptionsSubState extends MusicBeatSubstate
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
#if desktop
|
||||||
|
textMenuItems.push('Mods');
|
||||||
|
#end
|
||||||
|
|
||||||
grpOptionsTexts = new FlxTypedGroup<FlxText>();
|
grpOptionsTexts = new FlxTypedGroup<FlxText>();
|
||||||
add(grpOptionsTexts);
|
add(grpOptionsTexts);
|
||||||
|
|
||||||
|
@ -64,6 +68,9 @@ class OptionsSubState extends MusicBeatSubstate
|
||||||
case "Controls":
|
case "Controls":
|
||||||
FlxG.state.closeSubState();
|
FlxG.state.closeSubState();
|
||||||
FlxG.state.openSubState(new ControlsSubState());
|
FlxG.state.openSubState(new ControlsSubState());
|
||||||
|
case "Mods":
|
||||||
|
FlxG.state.closeSubState();
|
||||||
|
FlxG.state.openSubState(new ModdingSubstate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue