Skip to content

Commit a01513f

Browse files
fix(freeplay): prevent song previews from cutting out when navigating through the menus to quickly
1 parent 0527624 commit a01513f

1 file changed

Lines changed: 13 additions & 19 deletions

File tree

source/funkin/ui/freeplay/FreeplayState.hx

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ class FreeplayState extends MusicBeatSubState
401401
// Set rememberedSongId to last played song if accessed from the RANDOM option
402402
rememberedSongId = fromResultsParams.songId;
403403
}
404-
405404
@:privateAccess
406405
this._parentState._constructor = () ->
407406
{
@@ -967,21 +966,11 @@ class FreeplayState extends MusicBeatSubState
967966
switch (renderType)
968967
{
969968
case 'animateatlas':
970-
dj = (scriptClass != '') ? (AnimateAtlasFreeplayDJ.scriptInit(
971-
scriptClass,
972-
x,
973-
y,
974-
characterId
975-
)) : (new AnimateAtlasFreeplayDJ(x, y, characterId));
969+
dj = (scriptClass != '') ? (AnimateAtlasFreeplayDJ.scriptInit(scriptClass, x, y, characterId)) : (new AnimateAtlasFreeplayDJ(x, y, characterId));
976970
case 'sparrow':
977971
dj = (scriptClass != '') ? (SparrowFreeplayDJ.scriptInit(scriptClass, x, y, characterId)) : (new SparrowFreeplayDJ(x, y, characterId));
978972
case 'multisparrow':
979-
dj = (scriptClass != '') ? (MultiSparrowFreeplayDJ.scriptInit(
980-
scriptClass,
981-
x,
982-
y,
983-
characterId
984-
)) : (new MultiSparrowFreeplayDJ(x, y, characterId));
973+
dj = (scriptClass != '') ? (MultiSparrowFreeplayDJ.scriptInit(scriptClass, x, y, characterId)) : (new MultiSparrowFreeplayDJ(x, y, characterId));
985974
case 'packer':
986975
dj = (scriptClass != '') ? (PackerFreeplayDJ.scriptInit(scriptClass, x, y, characterId)) : (new PackerFreeplayDJ(x, y, characterId));
987976
case 'custom':
@@ -1247,7 +1236,8 @@ class FreeplayState extends MusicBeatSubState
12471236
});
12481237
}
12491238

1250-
function rankDisplayNew(fromResults:Null<FromResultsParams>, capsuleToRank:SongMenuItem):Void
1239+
function rankDisplayNew(fromResults:Null<FromResultsParams>,
1240+
capsuleToRank:SongMenuItem):Void
12511241
{
12521242
dispatchEvent(new CapsuleScriptEvent(FREEPLAY_RANK_SLAM, currentCapsule, currentDifficulty, currentVariation, fromResults?.newRank));
12531243

@@ -1397,7 +1387,6 @@ class FreeplayState extends MusicBeatSubState
13971387
new FlxTimer().start(0.5, _ ->
13981388
{
13991389
dispatchEvent(new CapsuleScriptEvent(FREEPLAY_CAPSULE_SLAM, currentCapsule, currentDifficulty, currentVariation, fromResultsParams?.newRank));
1400-
14011390
// Capsule slam vibration.
14021391
HapticUtil.vibrate(Constants.DEFAULT_VIBRATION_PERIOD, Constants.DEFAULT_VIBRATION_DURATION, Constants.MAX_VIBRATION_AMPLITUDE);
14031392

@@ -3257,11 +3246,16 @@ class FreeplayState extends MusicBeatSubState
32573246

32583247
if (grpCapsules.countLiving() > 0 && !prepForNewRank && uiStateMachine.canInteract())
32593248
{
3260-
FlxG.sound.music?.pause();
3261-
FlxTimer.wait(FADE_IN_DELAY, playCurSongPreview.bind(currentCapsule));
3262-
currentCapsule.selected = true;
3249+
clearPreviews();
3250+
3251+
// Create a timer to delay the song preview to prevent overlapping or cutting out.
3252+
var previewTransition = new FlxTimer().start(FADE_IN_DELAY, function(_)
3253+
{
3254+
if (FlxG.sound.music != null) FlxG.sound.music.stop();
3255+
playCurSongPreview(currentCapsule);
3256+
});
32633257

3264-
// switchBackingImage(currentCapsule.freeplayData);
3258+
previewTimers.push(previewTransition);
32653259
}
32663260

32673261
// Small vibrations every selection change.

0 commit comments

Comments
 (0)