2023-11-07 04:04:22 -05:00
|
|
|
package funkin.ui.transition;
|
2021-02-09 13:07:05 -05:00
|
|
|
|
|
|
|
import flixel.FlxSprite;
|
2021-03-09 19:41:03 -05:00
|
|
|
import flixel.FlxState;
|
2021-04-09 19:17:14 -04:00
|
|
|
import flixel.math.FlxMath;
|
2023-11-28 20:52:45 -05:00
|
|
|
import flixel.tweens.FlxEase;
|
|
|
|
import flixel.tweens.FlxTween;
|
2021-02-09 13:07:05 -05:00
|
|
|
import flixel.util.FlxTimer;
|
2023-11-28 20:52:45 -05:00
|
|
|
import funkin.graphics.shaders.ScreenWipeShader;
|
2022-04-18 19:36:09 -04:00
|
|
|
import funkin.play.PlayState;
|
2023-11-28 20:52:45 -05:00
|
|
|
import funkin.play.PlayStatePlaylist;
|
|
|
|
import funkin.play.song.Song.SongDifficulty;
|
|
|
|
import funkin.ui.mainmenu.MainMenuState;
|
|
|
|
import funkin.ui.MusicBeatState;
|
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;
|
2023-11-07 04:04:22 -05:00
|
|
|
import openfl.filters.ShaderFilter;
|
2023-11-28 20:52:45 -05:00
|
|
|
import openfl.utils.Assets;
|
2021-02-09 13:07:05 -05:00
|
|
|
|
|
|
|
class LoadingState extends MusicBeatState
|
|
|
|
{
|
2023-01-22 22:25:45 -05:00
|
|
|
inline static var MIN_TIME = 1.0;
|
|
|
|
|
|
|
|
var target:FlxState;
|
|
|
|
var stopMusic = false;
|
|
|
|
var callbacks:MultiCallback;
|
|
|
|
var danceLeft = false;
|
|
|
|
|
|
|
|
var loadBar:FlxSprite;
|
|
|
|
var funkay:FlxSprite;
|
|
|
|
|
|
|
|
function new(target:FlxState, stopMusic:Bool)
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
this.target = target;
|
|
|
|
this.stopMusic = stopMusic;
|
|
|
|
}
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
override function create():Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
var bg:FlxSprite = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, 0xFFcaff4d);
|
|
|
|
add(bg);
|
|
|
|
|
|
|
|
funkay = new FlxSprite();
|
|
|
|
funkay.loadGraphic(Paths.image('funkay'));
|
|
|
|
funkay.setGraphicSize(0, FlxG.height);
|
|
|
|
funkay.updateHitbox();
|
|
|
|
add(funkay);
|
|
|
|
funkay.scrollFactor.set();
|
|
|
|
funkay.screenCenter();
|
|
|
|
|
|
|
|
loadBar = new FlxSprite(0, FlxG.height - 20).makeGraphic(FlxG.width, 10, 0xFFff16d2);
|
|
|
|
loadBar.screenCenter(X);
|
|
|
|
add(loadBar);
|
|
|
|
|
2023-06-01 15:59:56 -04:00
|
|
|
initSongsManifest().onComplete(function(lib) {
|
2023-01-22 22:25:45 -05:00
|
|
|
callbacks = new MultiCallback(onLoad);
|
2023-06-06 17:38:31 -04:00
|
|
|
var introComplete = callbacks.add('introComplete');
|
2023-11-28 20:52:45 -05:00
|
|
|
|
|
|
|
if (Std.isOfType(target, PlayState))
|
|
|
|
{
|
|
|
|
var targetPlayState:PlayState = cast target;
|
|
|
|
var targetChart:SongDifficulty = targetPlayState.currentChart;
|
|
|
|
var instPath:String = Paths.inst(targetChart.song.id);
|
|
|
|
var voicesPaths:Array<String> = targetChart.buildVoiceList();
|
|
|
|
|
|
|
|
checkLoadSong(instPath);
|
|
|
|
for (voicePath in voicesPaths)
|
|
|
|
{
|
|
|
|
checkLoadSong(voicePath);
|
|
|
|
}
|
|
|
|
}
|
2023-06-06 17:38:31 -04:00
|
|
|
|
|
|
|
checkLibrary('shared');
|
|
|
|
checkLibrary(PlayStatePlaylist.campaignId);
|
|
|
|
checkLibrary('tutorial');
|
|
|
|
|
|
|
|
var fadeTime:Float = 0.5;
|
2023-01-22 22:25:45 -05:00
|
|
|
FlxG.camera.fade(FlxG.camera.bgColor, fadeTime, true);
|
|
|
|
new FlxTimer().start(fadeTime + MIN_TIME, function(_) introComplete());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
function checkLoadSong(path:String):Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
if (!Assets.cache.hasSound(path))
|
|
|
|
{
|
2023-06-06 17:38:31 -04:00
|
|
|
var library = Assets.getLibrary('songs');
|
|
|
|
var symbolPath = path.split(':').pop();
|
2023-01-22 22:25:45 -05:00
|
|
|
// @:privateAccess
|
|
|
|
// library.types.set(symbolPath, SOUND);
|
|
|
|
// @:privateAccess
|
|
|
|
// library.pathGroups.set(symbolPath, [library.__cacheBreak(symbolPath)]);
|
2023-06-06 17:38:31 -04:00
|
|
|
var callback = callbacks.add('song:' + path);
|
2023-06-01 15:59:56 -04:00
|
|
|
Assets.loadSound(path).onComplete(function(_) {
|
2023-01-22 22:25:45 -05:00
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
function checkLibrary(library:String):Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
trace(Assets.hasLibrary(library));
|
|
|
|
if (Assets.getLibrary(library) == null)
|
|
|
|
{
|
|
|
|
@:privateAccess
|
2023-06-06 17:38:31 -04:00
|
|
|
if (!LimeAssets.libraryPaths.exists(library)) throw 'Missing library: ' + library;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
var callback = callbacks.add('library:' + library);
|
2023-06-01 15:59:56 -04:00
|
|
|
Assets.loadLibrary(library).onComplete(function(_) {
|
2023-01-22 22:25:45 -05: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 17:38:31 -04:00
|
|
|
override function update(elapsed:Float):Void
|
2023-01-22 22:25:45 -05: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 17:38:31 -04:00
|
|
|
if (FlxG.keys.justPressed.SPACE) trace('fired: ' + callbacks.getFired() + ' unfired:' + callbacks.getUnfired());
|
2023-01-22 22:25:45 -05:00
|
|
|
#end
|
|
|
|
}
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
function onLoad():Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
if (stopMusic && FlxG.sound.music != null) FlxG.sound.music.stop();
|
|
|
|
|
|
|
|
FlxG.switchState(target);
|
|
|
|
}
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
static function getSongPath():String
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-09-08 17:46:44 -04:00
|
|
|
return Paths.inst(PlayState.instance.currentSong.id);
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
inline static public function loadAndSwitchState(nextState:FlxState, shouldStopMusic = false):Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-06-06 17:38:31 -04:00
|
|
|
FlxG.switchState(getNextState(nextState, shouldStopMusic));
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
static function getNextState(nextState:FlxState, shouldStopMusic = false):FlxState
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-06-06 17:38:31 -04:00
|
|
|
Paths.setCurrentLevel(PlayStatePlaylist.campaignId);
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
#if NO_PRELOAD_ALL
|
2023-06-06 17:38:31 -04:00
|
|
|
// var loaded = isSoundLoaded(getSongPath())
|
|
|
|
// && (!PlayState.currentSong.needsVoices || isSoundLoaded(getVocalPath()))
|
|
|
|
// && isLibraryLoaded('shared');
|
|
|
|
//
|
|
|
|
if (true) return new LoadingState(nextState, shouldStopMusic);
|
2023-01-22 22:25:45 -05:00
|
|
|
#end
|
2023-06-06 17:38:31 -04:00
|
|
|
if (shouldStopMusic && FlxG.sound.music != null) FlxG.sound.music.stop();
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
return nextState;
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#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;
|
|
|
|
}
|
|
|
|
#end
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
override function destroy():Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
super.destroy();
|
|
|
|
|
|
|
|
callbacks = null;
|
|
|
|
}
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
static function initSongsManifest():Future<AssetLibrary>
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-06-06 17:38:31 -04:00
|
|
|
var id = 'songs';
|
2023-01-22 22:25:45 -05: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 17:38:31 -04:00
|
|
|
if (path.endsWith('.bundle'))
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
rootPath = path;
|
2023-06-06 17:38:31 -04:00
|
|
|
path += '/library.json';
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rootPath = Path.directory(path);
|
|
|
|
}
|
|
|
|
@:privateAccess
|
|
|
|
path = LimeAssets.__cacheBreak(path);
|
|
|
|
}
|
|
|
|
|
2023-06-01 15:59:56 -04:00
|
|
|
AssetManifest.loadFromFile(path, rootPath).onComplete(function(manifest) {
|
2023-01-22 22:25:45 -05:00
|
|
|
if (manifest == null)
|
|
|
|
{
|
2023-06-06 17:38:31 -04:00
|
|
|
promise.error('Cannot parse asset manifest for library \'' + id + '\'');
|
2023-01-22 22:25:45 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var library = AssetLibrary.fromManifest(manifest);
|
|
|
|
|
|
|
|
if (library == null)
|
|
|
|
{
|
2023-06-06 17:38:31 -04:00
|
|
|
promise.error('Cannot open library \'' + id + '\'');
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
@:privateAccess
|
|
|
|
LimeAssets.libraries.set(id, library);
|
|
|
|
library.onChange.add(LimeAssets.onChange.dispatch);
|
|
|
|
promise.completeWith(Future.withValue(library));
|
|
|
|
}
|
2023-06-01 15:59:56 -04:00
|
|
|
}).onError(function(_) {
|
2023-06-06 17:38:31 -04:00
|
|
|
promise.error('There is no asset library with an ID of \'' + id + '\'');
|
2023-01-22 22:25:45 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
return promise.future;
|
|
|
|
}
|
2021-02-09 13:07:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
class MultiCallback
|
|
|
|
{
|
2023-01-22 22:25:45 -05: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 17:38:31 -04:00
|
|
|
public function add(id = 'untitled'):Void->Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
id = '$length:$id';
|
|
|
|
length++;
|
|
|
|
numRemaining++;
|
|
|
|
var func:Void->Void = null;
|
2023-06-01 15:59:56 -04:00
|
|
|
func = function() {
|
2023-01-22 22:25:45 -05: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 17:38:31 -04:00
|
|
|
public function getFired():Array<String>
|
2023-01-22 22:25:45 -05:00
|
|
|
return fired.copy();
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
public function getUnfired():Array<Void->Void>
|
2023-01-22 22:25:45 -05:00
|
|
|
return unfired.array();
|
2023-11-07 04:04:22 -05:00
|
|
|
|
|
|
|
public static function coolSwitchState(state:FlxState, transitionTex:String = "shaderTransitionStuff/coolDots", time:Float = 2)
|
|
|
|
{
|
|
|
|
var screenShit:FlxSprite = new FlxSprite().loadGraphic(Paths.image("shaderTransitionStuff/coolDots"));
|
|
|
|
var screenWipeShit:ScreenWipeShader = new ScreenWipeShader();
|
|
|
|
|
|
|
|
screenWipeShit.funnyShit.input = screenShit.pixels;
|
|
|
|
FlxTween.tween(screenWipeShit, {daAlphaShit: 1}, time,
|
|
|
|
{
|
|
|
|
ease: FlxEase.quadInOut,
|
|
|
|
onComplete: function(twn) {
|
|
|
|
screenShit.destroy();
|
|
|
|
FlxG.switchState(new MainMenuState());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
FlxG.camera.setFilters([new ShaderFilter(screenWipeShit)]);
|
|
|
|
}
|
2021-03-09 19:41:03 -05:00
|
|
|
}
|