From ca345e6c4fad9cc7fd3e6d0de41e68a6cb0298b9 Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Thu, 6 Jun 2024 21:38:00 -0400 Subject: [PATCH] Play song IDs based on the chart file's "instrumental" field, not the variation ID. --- source/funkin/play/PlayState.hx | 9 ++++++++- source/funkin/play/song/Song.hx | 4 ++-- source/funkin/ui/freeplay/FreeplayState.hx | 18 ++++++++++++++---- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index b02cc69f7..6bc4b2d89 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -175,6 +175,12 @@ class PlayState extends MusicBeatSubState */ public var currentVariation:String = Constants.DEFAULT_VARIATION; + /** + * The currently selected instrumental ID. + * @default `''` + */ + public var currentInstrumental:String = ''; + /** * The currently active Stage. This is the object containing all the props. */ @@ -603,6 +609,7 @@ class PlayState extends MusicBeatSubState currentSong = params.targetSong; if (params.targetDifficulty != null) currentDifficulty = params.targetDifficulty; if (params.targetVariation != null) currentVariation = params.targetVariation; + if (params.targetInstrumental != null) currentInstrumental = params.targetInstrumental; isPracticeMode = params.practiceMode ?? false; isBotPlayMode = params.botPlayMode ?? false; isMinimalMode = params.minimalMode ?? false; @@ -1968,7 +1975,7 @@ class PlayState extends MusicBeatSubState if (!overrideMusic && !isGamePaused && currentChart != null) { - currentChart.playInst(1.0, false); + currentChart.playInst(1.0, currentInstrumental, false); } if (FlxG.sound.music == null) diff --git a/source/funkin/play/song/Song.hx b/source/funkin/play/song/Song.hx index df3e343e2..dde5ee7b8 100644 --- a/source/funkin/play/song/Song.hx +++ b/source/funkin/play/song/Song.hx @@ -682,9 +682,9 @@ class SongDifficulty FlxG.sound.cache(getInstPath(instrumental)); } - public function playInst(volume:Float = 1.0, looped:Bool = false):Void + public function playInst(volume:Float = 1.0, instId:String = '', looped:Bool = false):Void { - var suffix:String = (variation != null && variation != '' && variation != 'default') ? '-$variation' : ''; + var suffix:String = (instId != '') ? '-$instId' : ''; FlxG.sound.music = FunkinSound.load(Paths.inst(this.song.id, suffix), volume, looped, false, true); diff --git a/source/funkin/ui/freeplay/FreeplayState.hx b/source/funkin/ui/freeplay/FreeplayState.hx index 607b7a353..c47933fd7 100644 --- a/source/funkin/ui/freeplay/FreeplayState.hx +++ b/source/funkin/ui/freeplay/FreeplayState.hx @@ -1726,11 +1726,20 @@ class FreeplayState extends MusicBeatSubState FlxG.log.warn('WARN: could not find song with id (${cap.songData.songId})'); return; } - var targetDifficulty:String = currentDifficulty; - var targetVariation:String = targetSong.getFirstValidVariation(targetDifficulty); - + var targetDifficultyId:String = currentDifficulty; + var targetVariation:String = targetSong.getFirstValidVariation(targetDifficultyId); PlayStatePlaylist.campaignId = cap.songData.levelId; + var targetDifficulty:SongDifficulty = targetSong.getDifficulty(targetDifficultyId, targetVariation); + if (targetDifficulty == null) + { + FlxG.log.warn('WARN: could not find difficulty with id (${targetDifficultyId})'); + return; + } + + // TODO: Change this with alternate instrumentals + var targetInstId:String = targetDifficulty.characters.instrumental; + // Visual and audio effects. FunkinSound.playOnce(Paths.sound('confirmMenu')); dj.confirm(); @@ -1779,8 +1788,9 @@ class FreeplayState extends MusicBeatSubState LoadingState.loadPlayState( { targetSong: targetSong, - targetDifficulty: targetDifficulty, + targetDifficulty: targetDifficultyId, targetVariation: targetVariation, + targetInstrumental: targetInstId, practiceMode: false, minimalMode: false,