From 74b925d2c6cafe29c216e9b8b092c1c038f52cfa Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Mon, 9 Oct 2023 14:13:14 -0400 Subject: [PATCH 1/2] Assert the difficulty exists (and throw an error if it doesn't) before performing reset. --- source/funkin/play/PlayState.hx | 79 ++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index ce72fa56c..3cfe9e8f2 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -511,41 +511,7 @@ class PlayState extends MusicBeatSubState NoteSplash.buildSplashFrames(); - // Returns null if the song failed to load or doesn't have the selected difficulty. - if (currentSong == null || currentChart == null) - { - // We have encountered a critical error. Prevent Flixel from trying to run any gameplay logic. - criticalFailure = true; - - // Choose an error message. - var message:String = 'There was a critical error. Click OK to return to the main menu.'; - if (currentSong == null) - { - message = 'The was a critical error loading this song\'s chart. Click OK to return to the main menu.'; - } - else if (currentDifficulty == null) - { - message = 'The was a critical error selecting a difficulty for this song. Click OK to return to the main menu.'; - } - else if (currentSong.getDifficulty(currentDifficulty) == null) - { - message = 'The was a critical error retrieving data for this song on "$currentDifficulty" difficulty. Click OK to return to the main menu.'; - } - - // Display a popup. This blocks the application until the user clicks OK. - lime.app.Application.current.window.alert(message, 'Error loading PlayState'); - - // Force the user back to the main menu. - if (isSubState) - { - this.close(); - } - else - { - FlxG.switchState(new MainMenuState()); - } - return; - } + if (!assertChartExists()) return; if (false) { @@ -660,6 +626,47 @@ class PlayState extends MusicBeatSubState initialized = true; } + function assertChartExists():Bool + { + // Returns null if the song failed to load or doesn't have the selected difficulty. + if (currentSong == null || currentChart == null) + { + // We have encountered a critical error. Prevent Flixel from trying to run any gameplay logic. + criticalFailure = true; + + // Choose an error message. + var message:String = 'There was a critical error. Click OK to return to the main menu.'; + if (currentSong == null) + { + message = 'The was a critical error loading this song\'s chart. Click OK to return to the main menu.'; + } + else if (currentDifficulty == null) + { + message = 'The was a critical error selecting a difficulty for this song. Click OK to return to the main menu.'; + } + else if (currentSong.getDifficulty(currentDifficulty) == null) + { + message = 'The was a critical error retrieving data for this song on "$currentDifficulty" difficulty. Click OK to return to the main menu.'; + } + + // Display a popup. This blocks the application until the user clicks OK. + lime.app.Application.current.window.alert(message, 'Error loading PlayState'); + + // Force the user back to the main menu. + if (isSubState) + { + this.close(); + } + else + { + FlxG.switchState(new MainMenuState()); + } + return false; + } + + return true; + } + public override function update(elapsed:Float):Void { if (criticalFailure) return; @@ -672,6 +679,8 @@ class PlayState extends MusicBeatSubState // Handle restarting the song when needed (player death or pressing Retry) if (needsReset) { + if (!assertChartExists()) return; + dispatchEvent(new ScriptEvent(ScriptEvent.SONG_RETRY)); resetCamera(); From e967b1e7f33e4f1fd807373b3fea79bb4c941a8d Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Mon, 9 Oct 2023 14:19:52 -0400 Subject: [PATCH 2/2] Fix vocals not changing when switching difficulties. --- source/funkin/play/PlayState.hx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index 3cfe9e8f2..d7c2a2a4c 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -695,8 +695,10 @@ class PlayState extends MusicBeatSubState // Reset music properly. FlxG.sound.music.pause(); - vocals.pause(); FlxG.sound.music.time = (startTimestamp); + + vocals = currentChart.buildVocals(); + vocals.pause(); vocals.time = 0; FlxG.sound.music.volume = 1;