From deda73f8a82e67db86c42793f901c1dc6f58161a Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Mon, 5 Aug 2024 18:52:12 +0200 Subject: [PATCH] Fix bug with autoplay --- source/funkin/menus/FreeplayState.hx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/source/funkin/menus/FreeplayState.hx b/source/funkin/menus/FreeplayState.hx index 24e93b4f..d29cd108 100644 --- a/source/funkin/menus/FreeplayState.hx +++ b/source/funkin/menus/FreeplayState.hx @@ -196,6 +196,10 @@ class FreeplayState extends MusicBeatState * Path to the currently playing song instrumental. */ public var curPlayingInst:String = null; + /** + * If it should play the song automatically. + */ + public var autoplayShouldPlay:Bool = true; #end override function update(elapsed:Float) @@ -236,7 +240,17 @@ class FreeplayState extends MusicBeatState autoplayElapsed += elapsed; if (!disableAutoPlay && !songInstPlaying && (autoplayElapsed > timeUntilAutoplay || FlxG.keys.justPressed.SPACE)) { if (curPlayingInst != (curPlayingInst = Paths.inst(songs[curSelected].name, songs[curSelected].difficulties[curDifficulty]))) { - var huh:Void->Void = function() FlxG.sound.playMusic(curPlayingInst, 0); + var huh:Void->Void = function() { + var soundPath = curPlayingInst; + var sound = null; + if (Assets.exists(soundPath, SOUND) || Assets.exists(soundPath, MUSIC)) + sound = Assets.getSound(soundPath); + else + FlxG.log.error('Could not find a Sound asset with an ID of \'$soundPath\'.'); + + if (sound != null && autoplayShouldPlay) + FlxG.sound.playMusic(sound, 0); + } if(!disableAsyncLoading) Main.execAsync(huh); else huh(); } @@ -289,6 +303,10 @@ class FreeplayState extends MusicBeatState if (event.cancelled) return; + #if PRELOAD_ALL + autoplayShouldPlay = false; + #end + Options.freeplayLastSong = songs[curSelected].name; Options.freeplayLastDifficulty = songs[curSelected].difficulties[curDifficulty];