2023-11-07 09:04:22 +00:00
|
|
|
package funkin.ui.transition;
|
2021-02-09 18:07:05 +00:00
|
|
|
|
|
|
|
import flixel.FlxSprite;
|
2021-04-09 23:17:14 +00:00
|
|
|
import flixel.math.FlxMath;
|
2023-11-29 01:52:45 +00:00
|
|
|
import flixel.tweens.FlxEase;
|
2024-02-23 04:37:52 +00:00
|
|
|
import funkin.graphics.FunkinSprite;
|
2023-11-29 01:52:45 +00:00
|
|
|
import flixel.tweens.FlxTween;
|
2021-02-09 18:07:05 +00:00
|
|
|
import flixel.util.FlxTimer;
|
2023-11-29 01:52:45 +00:00
|
|
|
import funkin.graphics.shaders.ScreenWipeShader;
|
2022-04-18 23:36:09 +00:00
|
|
|
import funkin.play.PlayState;
|
2023-11-29 01:52:45 +00:00
|
|
|
import funkin.play.PlayStatePlaylist;
|
|
|
|
import funkin.play.song.Song.SongDifficulty;
|
|
|
|
import funkin.ui.MusicBeatState;
|
2021-03-10 00:41:03 +00:00
|
|
|
import haxe.io.Path;
|
2024-01-16 21:49:15 +00:00
|
|
|
import funkin.graphics.FunkinSprite;
|
2021-03-10 00:41:03 +00:00
|
|
|
import lime.app.Future;
|
|
|
|
import lime.app.Promise;
|
2021-02-09 18:07:05 +00:00
|
|
|
import lime.utils.AssetLibrary;
|
|
|
|
import lime.utils.AssetManifest;
|
2021-03-10 00:41:03 +00:00
|
|
|
import lime.utils.Assets as LimeAssets;
|
2023-11-07 09:04:22 +00:00
|
|
|
import openfl.filters.ShaderFilter;
|
2023-11-29 01:52:45 +00:00
|
|
|
import openfl.utils.Assets;
|
2024-02-06 00:46:11 +00:00
|
|
|
import flixel.util.typeLimit.NextState;
|
2021-02-09 18:07:05 +00:00
|
|
|
|
2024-03-16 04:55:57 +00:00
|
|
|
class LoadingState extends MusicBeatSubState
|
2021-02-09 18:07:05 +00:00
|
|
|
{
|
2023-01-23 03:25:45 +00:00
|
|
|
inline static var MIN_TIME = 1.0;
|
|
|
|
|
2024-03-16 04:55:57 +00:00
|
|
|
var asSubState:Bool = false;
|
|
|
|
|
2024-02-06 00:46:11 +00:00
|
|
|
var target:NextState;
|
2024-02-17 04:48:43 +00:00
|
|
|
var playParams:Null<PlayStateParams>;
|
|
|
|
var stopMusic:Bool = false;
|
2023-01-23 03:25:45 +00:00
|
|
|
var callbacks:MultiCallback;
|
2024-02-17 04:48:43 +00:00
|
|
|
var danceLeft:Bool = false;
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
var loadBar:FlxSprite;
|
|
|
|
var funkay:FlxSprite;
|
|
|
|
|
2024-02-17 04:48:43 +00:00
|
|
|
function new(target:NextState, stopMusic:Bool, playParams:Null<PlayStateParams> = null)
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
super();
|
|
|
|
this.target = target;
|
2024-02-17 04:48:43 +00:00
|
|
|
this.playParams = playParams;
|
2023-01-23 03:25:45 +00:00
|
|
|
this.stopMusic = stopMusic;
|
|
|
|
}
|
|
|
|
|
2023-06-06 21:38:31 +00:00
|
|
|
override function create():Void
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2024-02-22 23:55:24 +00:00
|
|
|
var bg:FunkinSprite = new FunkinSprite().makeSolidColor(FlxG.width, FlxG.height, 0xFFcaff4d);
|
2023-01-23 03:25:45 +00:00
|
|
|
add(bg);
|
|
|
|
|
2024-03-13 01:34:50 +00:00
|
|
|
funkay = FunkinSprite.create('funkay');
|
2023-01-23 03:25:45 +00:00
|
|
|
funkay.setGraphicSize(0, FlxG.height);
|
|
|
|
funkay.updateHitbox();
|
|
|
|
add(funkay);
|
|
|
|
funkay.scrollFactor.set();
|
|
|
|
funkay.screenCenter();
|
|
|
|
|
2024-01-16 21:49:15 +00:00
|
|
|
loadBar = new FunkinSprite(0, FlxG.height - 20).makeSolidColor(FlxG.width, 10, 0xFFff16d2);
|
2023-01-23 03:25:45 +00:00
|
|
|
loadBar.screenCenter(X);
|
|
|
|
add(loadBar);
|
|
|
|
|
2023-06-01 19:59:56 +00:00
|
|
|
initSongsManifest().onComplete(function(lib) {
|
2023-01-23 03:25:45 +00:00
|
|
|
callbacks = new MultiCallback(onLoad);
|
2023-06-06 21:38:31 +00:00
|
|
|
var introComplete = callbacks.add('introComplete');
|
2023-11-29 01:52:45 +00:00
|
|
|
|
2024-02-17 04:48:43 +00:00
|
|
|
if (playParams != null)
|
2023-11-29 01:52:45 +00:00
|
|
|
{
|
2024-02-17 04:48:43 +00:00
|
|
|
// Load and cache the song's charts.
|
|
|
|
if (playParams.targetSong != null)
|
|
|
|
{
|
|
|
|
playParams.targetSong.cacheCharts(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Preload the song for the play state.
|
|
|
|
var difficulty:String = playParams.targetDifficulty ?? Constants.DEFAULT_DIFFICULTY;
|
|
|
|
var variation:String = playParams.targetVariation ?? Constants.DEFAULT_VARIATION;
|
|
|
|
var targetChart:SongDifficulty = playParams.targetSong?.getDifficulty(difficulty, variation);
|
2024-04-23 22:32:07 +00:00
|
|
|
var instPath:String = targetChart.getInstPath(playParams.targetInstrumental);
|
2023-11-29 01:52:45 +00:00
|
|
|
var voicesPaths:Array<String> = targetChart.buildVoiceList();
|
|
|
|
|
|
|
|
checkLoadSong(instPath);
|
|
|
|
for (voicePath in voicesPaths)
|
|
|
|
{
|
|
|
|
checkLoadSong(voicePath);
|
|
|
|
}
|
|
|
|
}
|
2023-06-06 21:38:31 +00:00
|
|
|
|
|
|
|
checkLibrary('shared');
|
|
|
|
checkLibrary(PlayStatePlaylist.campaignId);
|
|
|
|
checkLibrary('tutorial');
|
|
|
|
|
|
|
|
var fadeTime:Float = 0.5;
|
2023-01-23 03:25:45 +00:00
|
|
|
FlxG.camera.fade(FlxG.camera.bgColor, fadeTime, true);
|
|
|
|
new FlxTimer().start(fadeTime + MIN_TIME, function(_) introComplete());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 21:38:31 +00:00
|
|
|
function checkLoadSong(path:String):Void
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
if (!Assets.cache.hasSound(path))
|
|
|
|
{
|
2023-06-06 21:38:31 +00:00
|
|
|
var library = Assets.getLibrary('songs');
|
|
|
|
var symbolPath = path.split(':').pop();
|
2023-01-23 03:25:45 +00:00
|
|
|
// @:privateAccess
|
|
|
|
// library.types.set(symbolPath, SOUND);
|
|
|
|
// @:privateAccess
|
|
|
|
// library.pathGroups.set(symbolPath, [library.__cacheBreak(symbolPath)]);
|
2023-06-06 21:38:31 +00:00
|
|
|
var callback = callbacks.add('song:' + path);
|
2023-06-01 19:59:56 +00:00
|
|
|
Assets.loadSound(path).onComplete(function(_) {
|
2023-01-23 03:25:45 +00:00
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-06 21:38:31 +00:00
|
|
|
function checkLibrary(library:String):Void
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
trace(Assets.hasLibrary(library));
|
|
|
|
if (Assets.getLibrary(library) == null)
|
|
|
|
{
|
|
|
|
@:privateAccess
|
2023-06-06 21:38:31 +00:00
|
|
|
if (!LimeAssets.libraryPaths.exists(library)) throw 'Missing library: ' + library;
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-06-06 21:38:31 +00:00
|
|
|
var callback = callbacks.add('library:' + library);
|
2023-06-01 19:59:56 +00:00
|
|
|
Assets.loadLibrary(library).onComplete(function(_) {
|
2023-01-23 03:25:45 +00:00
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override function beatHit():Bool
|
|
|
|
{
|
|
|
|
// super.beatHit() returns false if a module cancelled the event.
|
|
|
|
if (!super.beatHit()) return false;
|
|
|
|
|
|
|
|
danceLeft = !danceLeft;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var targetShit:Float = 0;
|
|
|
|
|
2023-06-06 21:38:31 +00:00
|
|
|
override function update(elapsed:Float):Void
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
super.update(elapsed);
|
|
|
|
|
|
|
|
funkay.setGraphicSize(Std.int(FlxMath.lerp(FlxG.width * 0.88, funkay.width, 0.9)));
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2023-06-06 21:38:31 +00:00
|
|
|
if (FlxG.keys.justPressed.SPACE) trace('fired: ' + callbacks.getFired() + ' unfired:' + callbacks.getUnfired());
|
2023-01-23 03:25:45 +00:00
|
|
|
#end
|
|
|
|
}
|
|
|
|
|
2023-06-06 21:38:31 +00:00
|
|
|
function onLoad():Void
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2024-03-23 21:50:48 +00:00
|
|
|
// Stop the instrumental.
|
|
|
|
if (stopMusic && FlxG.sound.music != null)
|
|
|
|
{
|
|
|
|
FlxG.sound.music.destroy();
|
|
|
|
FlxG.sound.music = null;
|
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2024-03-16 04:55:57 +00:00
|
|
|
if (asSubState)
|
|
|
|
{
|
|
|
|
this.close();
|
|
|
|
// We will assume the target is a valid substate.
|
|
|
|
FlxG.state.openSubState(cast target);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FlxG.switchState(target);
|
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
2023-06-06 21:38:31 +00:00
|
|
|
static function getSongPath():String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2023-09-08 21:46:44 +00:00
|
|
|
return Paths.inst(PlayState.instance.currentSong.id);
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
2024-02-17 04:48:43 +00:00
|
|
|
/**
|
|
|
|
* Starts the transition to a new `PlayState` to start a new song.
|
|
|
|
* First switches to the `LoadingState` if assets need to be loaded.
|
|
|
|
* @param params The parameters for the next `PlayState`.
|
2024-03-16 04:55:57 +00:00
|
|
|
* @param asSubState Whether to open as a substate rather than switching to the `PlayState`.
|
2024-02-17 04:48:43 +00:00
|
|
|
* @param shouldStopMusic Whether to stop the current music while loading.
|
|
|
|
*/
|
2024-03-16 04:55:57 +00:00
|
|
|
public static function loadPlayState(params:PlayStateParams, shouldStopMusic = false, asSubState = false, ?onConstruct:PlayState->Void):Void
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2023-06-06 21:38:31 +00:00
|
|
|
Paths.setCurrentLevel(PlayStatePlaylist.campaignId);
|
2024-03-16 04:55:57 +00:00
|
|
|
var playStateCtor:() -> PlayState = function() {
|
|
|
|
return new PlayState(params);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (onConstruct != null)
|
|
|
|
{
|
|
|
|
playStateCtor = function() {
|
|
|
|
var result = new PlayState(params);
|
|
|
|
onConstruct(result);
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
#if NO_PRELOAD_ALL
|
2024-02-17 04:48:43 +00:00
|
|
|
// Switch to loading state while we load assets (default on HTML5 target).
|
2024-04-03 03:33:10 +00:00
|
|
|
var loadStateCtor = function() {
|
2024-03-16 04:55:57 +00:00
|
|
|
var result = new LoadingState(playStateCtor, shouldStopMusic, params);
|
|
|
|
@:privateAccess
|
|
|
|
result.asSubState = asSubState;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (asSubState)
|
|
|
|
{
|
2024-04-03 03:33:10 +00:00
|
|
|
FlxG.state.openSubState(cast loadStateCtor());
|
2024-03-16 04:55:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FlxG.switchState(loadStateCtor);
|
|
|
|
}
|
2024-02-17 04:48:43 +00:00
|
|
|
#else
|
|
|
|
// All assets preloaded, switch directly to play state (defualt on other targets).
|
|
|
|
if (shouldStopMusic && FlxG.sound.music != null)
|
|
|
|
{
|
2024-03-23 21:50:48 +00:00
|
|
|
FlxG.sound.music.destroy();
|
|
|
|
FlxG.sound.music = null;
|
2024-02-17 04:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Load and cache the song's charts.
|
2024-03-29 04:49:02 +00:00
|
|
|
// Don't do this if we already provided the music and charts.
|
|
|
|
if (params?.targetSong != null && !params.overrideMusic)
|
2024-02-17 04:48:43 +00:00
|
|
|
{
|
|
|
|
params.targetSong.cacheCharts(true);
|
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2024-03-16 04:55:57 +00:00
|
|
|
var shouldPreloadLevelAssets:Bool = !(params?.minimalMode ?? false);
|
|
|
|
|
|
|
|
if (shouldPreloadLevelAssets) preloadLevelAssets();
|
|
|
|
|
|
|
|
if (asSubState)
|
|
|
|
{
|
|
|
|
FlxG.state.openSubState(cast playStateCtor());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FlxG.switchState(playStateCtor);
|
|
|
|
}
|
|
|
|
#end
|
|
|
|
}
|
|
|
|
|
|
|
|
#if NO_PRELOAD_ALL
|
|
|
|
static function isSoundLoaded(path:String):Bool
|
|
|
|
{
|
|
|
|
return Assets.cache.hasSound(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static function isLibraryLoaded(library:String):Bool
|
|
|
|
{
|
|
|
|
return Assets.getLibrary(library) != null;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static function preloadLevelAssets():Void
|
|
|
|
{
|
2024-02-23 04:37:52 +00:00
|
|
|
// TODO: This section is a hack! Redo this later when we have a proper asset caching system.
|
|
|
|
FunkinSprite.preparePurgeCache();
|
2024-02-22 23:55:24 +00:00
|
|
|
FunkinSprite.cacheTexture(Paths.image('healthBar'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('menuDesat'));
|
2024-02-23 04:37:52 +00:00
|
|
|
FunkinSprite.cacheTexture(Paths.image('combo'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('num0'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('num1'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('num2'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('num3'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('num4'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('num5'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('num6'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('num7'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('num8'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('num9'));
|
2024-02-23 05:16:11 +00:00
|
|
|
FunkinSprite.cacheTexture(Paths.image('notes', 'shared'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('noteSplashes', 'shared'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('noteStrumline', 'shared'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('NOTE_hold_assets'));
|
2024-02-23 04:37:52 +00:00
|
|
|
FunkinSprite.cacheTexture(Paths.image('ready', 'shared'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('set', 'shared'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('go', 'shared'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('sick', 'shared'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('good', 'shared'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('bad', 'shared'));
|
|
|
|
FunkinSprite.cacheTexture(Paths.image('shit', 'shared'));
|
2024-02-23 05:16:11 +00:00
|
|
|
FunkinSprite.cacheTexture(Paths.image('miss', 'shared')); // TODO: remove this
|
|
|
|
|
2024-03-12 03:42:32 +00:00
|
|
|
// List all image assets in the level's library.
|
|
|
|
// This is crude and I want to remove it when we have a proper asset caching system.
|
|
|
|
// TODO: Get rid of this junk!
|
2024-03-16 04:55:57 +00:00
|
|
|
var library = PlayStatePlaylist.campaignId != null ? openfl.utils.Assets.getLibrary(PlayStatePlaylist.campaignId) : null;
|
|
|
|
|
|
|
|
if (library == null) return; // We don't need to do anymore precaching.
|
|
|
|
|
2024-03-12 03:42:32 +00:00
|
|
|
var assets = library.list(lime.utils.AssetType.IMAGE);
|
|
|
|
trace('Got ${assets.length} assets: ${assets}');
|
|
|
|
|
|
|
|
// TODO: assets includes non-images! This is a bug with Polymod
|
|
|
|
for (asset in assets)
|
|
|
|
{
|
|
|
|
// Exclude items of the wrong type.
|
|
|
|
var path = '${PlayStatePlaylist.campaignId}:${asset}';
|
|
|
|
// TODO DUMB HACK DUMB HACK why doesn't filtering by AssetType.IMAGE above work
|
|
|
|
// I will fix this properly later I swear -eric
|
|
|
|
if (!path.endsWith('.png')) continue;
|
|
|
|
|
2024-04-29 06:31:40 +00:00
|
|
|
new Future<String>(function() {
|
|
|
|
FunkinSprite.cacheTexture(path);
|
|
|
|
// Another dumb hack: FlxAnimate fetches from OpenFL's BitmapData cache directly and skips the FlxGraphic cache.
|
|
|
|
// Since FlxGraphic tells OpenFL to not cache it, we have to do it manually.
|
|
|
|
if (path.endsWith('spritemap1.png'))
|
|
|
|
{
|
|
|
|
trace('Preloading FlxAnimate asset: ${path}');
|
|
|
|
openfl.Assets.getBitmapData(path, true);
|
|
|
|
}
|
|
|
|
return 'Done precaching ${path}';
|
|
|
|
}, true);
|
2024-03-12 03:42:32 +00:00
|
|
|
|
2024-04-29 06:31:40 +00:00
|
|
|
trace("Queued ${path} for precaching");
|
|
|
|
// FunkinSprite.cacheTexture(path);
|
2024-03-12 03:42:32 +00:00
|
|
|
}
|
|
|
|
|
2024-02-23 05:16:11 +00:00
|
|
|
// FunkinSprite.cacheAllNoteStyleTextures(noteStyle) // This will replace the stuff above!
|
|
|
|
// FunkinSprite.cacheAllCharacterTextures(player)
|
|
|
|
// FunkinSprite.cacheAllCharacterTextures(girlfriend)
|
|
|
|
// FunkinSprite.cacheAllCharacterTextures(opponent)
|
|
|
|
// FunkinSprite.cacheAllStageTextures(stage)
|
2024-03-12 03:42:32 +00:00
|
|
|
// FunkinSprite.cacheAllSongTextures(stage)
|
2024-02-23 05:16:11 +00:00
|
|
|
|
2024-02-23 04:37:52 +00:00
|
|
|
FunkinSprite.purgeCache();
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
#end
|
|
|
|
|
2023-06-06 21:38:31 +00:00
|
|
|
override function destroy():Void
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
super.destroy();
|
|
|
|
|
|
|
|
callbacks = null;
|
|
|
|
}
|
|
|
|
|
2023-06-06 21:38:31 +00:00
|
|
|
static function initSongsManifest():Future<AssetLibrary>
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2023-06-06 21:38:31 +00:00
|
|
|
var id = 'songs';
|
2023-01-23 03:25:45 +00:00
|
|
|
var promise = new Promise<AssetLibrary>();
|
|
|
|
|
|
|
|
var library = LimeAssets.getLibrary(id);
|
|
|
|
|
|
|
|
if (library != null)
|
|
|
|
{
|
|
|
|
return Future.withValue(library);
|
|
|
|
}
|
|
|
|
|
|
|
|
var path = id;
|
|
|
|
var rootPath = null;
|
|
|
|
|
|
|
|
@:privateAccess
|
|
|
|
var libraryPaths = LimeAssets.libraryPaths;
|
|
|
|
if (libraryPaths.exists(id))
|
|
|
|
{
|
|
|
|
path = libraryPaths[id];
|
|
|
|
rootPath = Path.directory(path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-06 21:38:31 +00:00
|
|
|
if (path.endsWith('.bundle'))
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
rootPath = path;
|
2023-06-06 21:38:31 +00:00
|
|
|
path += '/library.json';
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rootPath = Path.directory(path);
|
|
|
|
}
|
|
|
|
@:privateAccess
|
|
|
|
path = LimeAssets.__cacheBreak(path);
|
|
|
|
}
|
|
|
|
|
2023-06-01 19:59:56 +00:00
|
|
|
AssetManifest.loadFromFile(path, rootPath).onComplete(function(manifest) {
|
2023-01-23 03:25:45 +00:00
|
|
|
if (manifest == null)
|
|
|
|
{
|
2023-06-06 21:38:31 +00:00
|
|
|
promise.error('Cannot parse asset manifest for library \'' + id + '\'');
|
2023-01-23 03:25:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var library = AssetLibrary.fromManifest(manifest);
|
|
|
|
|
|
|
|
if (library == null)
|
|
|
|
{
|
2023-06-06 21:38:31 +00:00
|
|
|
promise.error('Cannot open library \'' + id + '\'');
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
@:privateAccess
|
|
|
|
LimeAssets.libraries.set(id, library);
|
|
|
|
library.onChange.add(LimeAssets.onChange.dispatch);
|
|
|
|
promise.completeWith(Future.withValue(library));
|
|
|
|
}
|
2023-06-01 19:59:56 +00:00
|
|
|
}).onError(function(_) {
|
2023-06-06 21:38:31 +00:00
|
|
|
promise.error('There is no asset library with an ID of \'' + id + '\'');
|
2023-01-23 03:25:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return promise.future;
|
|
|
|
}
|
2021-02-09 18:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class MultiCallback
|
|
|
|
{
|
2023-01-23 03:25:45 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-06-06 21:38:31 +00:00
|
|
|
public function add(id = 'untitled'):Void->Void
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
id = '$length:$id';
|
|
|
|
length++;
|
|
|
|
numRemaining++;
|
|
|
|
var func:Void->Void = null;
|
2023-06-01 19:59:56 +00:00
|
|
|
func = function() {
|
2023-01-23 03:25:45 +00:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2023-06-06 21:38:31 +00:00
|
|
|
public function getFired():Array<String>
|
2023-01-23 03:25:45 +00:00
|
|
|
return fired.copy();
|
|
|
|
|
2023-06-06 21:38:31 +00:00
|
|
|
public function getUnfired():Array<Void->Void>
|
2023-01-23 03:25:45 +00:00
|
|
|
return unfired.array();
|
2023-11-07 09:04:22 +00:00
|
|
|
|
2024-03-13 01:34:50 +00:00
|
|
|
/**
|
|
|
|
* Perform an FlxG.switchState with a nice transition
|
|
|
|
* @param state
|
|
|
|
* @param transitionTex
|
|
|
|
* @param time
|
|
|
|
*/
|
2024-02-06 00:46:11 +00:00
|
|
|
public static function coolSwitchState(state:NextState, transitionTex:String = "shaderTransitionStuff/coolDots", time:Float = 2)
|
2023-11-07 09:04:22 +00:00
|
|
|
{
|
2024-03-13 01:34:50 +00:00
|
|
|
var screenShit:FunkinSprite = FunkinSprite.create('shaderTransitionStuff/coolDots');
|
2023-11-07 09:04:22 +00:00
|
|
|
var screenWipeShit:ScreenWipeShader = new ScreenWipeShader();
|
|
|
|
|
|
|
|
screenWipeShit.funnyShit.input = screenShit.pixels;
|
|
|
|
FlxTween.tween(screenWipeShit, {daAlphaShit: 1}, time,
|
|
|
|
{
|
|
|
|
ease: FlxEase.quadInOut,
|
|
|
|
onComplete: function(twn) {
|
|
|
|
screenShit.destroy();
|
2024-02-06 00:46:11 +00:00
|
|
|
FlxG.switchState(state);
|
2023-11-07 09:04:22 +00:00
|
|
|
}
|
|
|
|
});
|
2024-02-06 00:46:11 +00:00
|
|
|
FlxG.camera.filters = [new ShaderFilter(screenWipeShit)];
|
2023-11-07 09:04:22 +00:00
|
|
|
}
|
2021-03-10 00:41:03 +00:00
|
|
|
}
|