1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2025-01-08 05:07:10 +00:00

Make the playback rate option explicit so it doesn't break in the future.

This commit is contained in:
EliteMasterEric 2024-02-29 18:49:20 -05:00
parent d9dbb5791c
commit 684eb919b5
3 changed files with 29 additions and 2 deletions

View file

@ -97,7 +97,7 @@ typedef PlayStateParams =
?targetDifficulty:String, ?targetDifficulty:String,
/** /**
* The variation to play on. * The variation to play on.
* @default `Constants.DEFAULT_VARIATION` . * @default `Constants.DEFAULT_VARIATION`
*/ */
?targetVariation:String, ?targetVariation:String,
/** /**
@ -118,8 +118,14 @@ typedef PlayStateParams =
?minimalMode:Bool, ?minimalMode:Bool,
/** /**
* If specified, the game will jump to the specified timestamp after the countdown ends. * If specified, the game will jump to the specified timestamp after the countdown ends.
* @default `0.0`
*/ */
?startTimestamp:Float, ?startTimestamp:Float,
/**
* If specified, the game will play the song with the given speed.
* @default `1.0` for 100% speed.
*/
?playbackRate:Float,
/** /**
* If specified, the game will not load the instrumental or vocal tracks, * If specified, the game will not load the instrumental or vocal tracks,
* and must be loaded externally. * and must be loaded externally.
@ -210,6 +216,12 @@ class PlayState extends MusicBeatSubState
*/ */
public var startTimestamp:Float = 0.0; public var startTimestamp:Float = 0.0;
/**
* Play back the song at this speed.
* @default `1.0` for normal speed.
*/
public var playbackRate:Float = 1.0;
/** /**
* An empty FlxObject contained in the scene. * An empty FlxObject contained in the scene.
* The current gameplay camera will always follow this object. Tween its position to move the camera smoothly. * The current gameplay camera will always follow this object. Tween its position to move the camera smoothly.
@ -550,6 +562,7 @@ class PlayState extends MusicBeatSubState
isPracticeMode = params.practiceMode ?? false; isPracticeMode = params.practiceMode ?? false;
isMinimalMode = params.minimalMode ?? false; isMinimalMode = params.minimalMode ?? false;
startTimestamp = params.startTimestamp ?? 0.0; startTimestamp = params.startTimestamp ?? 0.0;
playbackRate = params.playbackRate ?? 1.0;
overrideMusic = params.overrideMusic ?? false; overrideMusic = params.overrideMusic ?? false;
previousCameraFollowPoint = params.cameraFollowPoint; previousCameraFollowPoint = params.cameraFollowPoint;
@ -777,6 +790,7 @@ class PlayState extends MusicBeatSubState
// Reset music properly. // Reset music properly.
FlxG.sound.music.time = startTimestamp - Conductor.instance.instrumentalOffset; FlxG.sound.music.time = startTimestamp - Conductor.instance.instrumentalOffset;
FlxG.sound.music.pitch = playbackRate;
FlxG.sound.music.pause(); FlxG.sound.music.pause();
if (!overrideMusic) if (!overrideMusic)
@ -1783,14 +1797,16 @@ class PlayState extends MusicBeatSubState
// A negative instrumental offset means the song skips the first few milliseconds of the track. // A negative instrumental offset means the song skips the first few milliseconds of the track.
// This just gets added into the startTimestamp behavior so we don't need to do anything extra. // This just gets added into the startTimestamp behavior so we don't need to do anything extra.
FlxG.sound.music.play(true, startTimestamp - Conductor.instance.instrumentalOffset); FlxG.sound.music.play(true, startTimestamp - Conductor.instance.instrumentalOffset);
FlxG.sound.music.pitch = playbackRate;
// I am going insane. // I am going insane.
FlxG.sound.music.volume = 1.0; FlxG.sound.music.volume = 1.0;
FlxG.sound.music.fadeTween.cancel(); if (FlxG.sound.music.fadeTween != null) FlxG.sound.music.fadeTween.cancel();
trace('Playing vocals...'); trace('Playing vocals...');
add(vocals); add(vocals);
vocals.play(); vocals.play();
vocals.pitch = playbackRate;
resyncVocals(); resyncVocals();
#if discord_rpc #if discord_rpc

View file

@ -5308,6 +5308,10 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
var startTimestamp:Float = 0; var startTimestamp:Float = 0;
if (playtestStartTime) startTimestamp = scrollPositionInMs + playheadPositionInMs; if (playtestStartTime) startTimestamp = scrollPositionInMs + playheadPositionInMs;
var playbackRate:Float = (menubarItemPlaybackSpeed.value.toFloat() * 2.0) / 100.0;
playbackRate = Math.floor(playbackRate / 0.05) * 0.05; // Round to nearest 5%
playbackRate = Math.max(0.05, Math.min(2.0, playbackRate)); // Clamp to 5% to 200%
var targetSong:Song; var targetSong:Song;
try try
{ {
@ -5357,6 +5361,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
practiceMode: playtestPracticeMode, practiceMode: playtestPracticeMode,
minimalMode: minimal, minimalMode: minimal,
startTimestamp: startTimestamp, startTimestamp: startTimestamp,
playbackRate: playbackRate,
overrideMusic: true, overrideMusic: true,
}); });

View file

@ -1143,6 +1143,12 @@ class FreeplayState extends MusicBeatSubState
targetSong: targetSong, targetSong: targetSong,
targetDifficulty: targetDifficulty, targetDifficulty: targetDifficulty,
targetVariation: targetVariation, targetVariation: targetVariation,
// TODO: Make this an option!
// startTimestamp: 0.0,
// TODO: Make this an option!
// playbackRate: 0.5,
practiceMode: false,
minimalMode: false,
}, true); }, true);
}); });
} }