2023-11-28 20:36:59 -05:00
|
|
|
package funkin.ui.debug.charting.commands;
|
|
|
|
|
2023-11-29 16:53:08 -05:00
|
|
|
import funkin.data.song.SongData.SongTimeChange;
|
|
|
|
|
2023-11-28 20:36:59 -05:00
|
|
|
/**
|
|
|
|
* A command which changes the starting BPM of the song.
|
|
|
|
*/
|
|
|
|
@:nullSafety
|
|
|
|
@:access(funkin.ui.debug.charting.ChartEditorState)
|
|
|
|
class ChangeStartingBPMCommand implements ChartEditorCommand
|
|
|
|
{
|
|
|
|
var targetBPM:Float;
|
|
|
|
|
|
|
|
var previousBPM:Float = 100;
|
|
|
|
|
|
|
|
public function new(targetBPM:Float)
|
|
|
|
{
|
|
|
|
this.targetBPM = targetBPM;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
var timeChanges:Array<SongTimeChange> = state.currentSongMetadata.timeChanges;
|
|
|
|
if (timeChanges == null || timeChanges.length == 0)
|
|
|
|
{
|
|
|
|
previousBPM = 100;
|
2023-11-29 16:53:08 -05:00
|
|
|
timeChanges = [new SongTimeChange(0, targetBPM)];
|
2023-11-28 20:36:59 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
previousBPM = timeChanges[0].bpm;
|
2023-11-29 16:53:08 -05:00
|
|
|
timeChanges[0].bpm = targetBPM;
|
2023-11-28 20:36:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
state.currentSongMetadata.timeChanges = timeChanges;
|
|
|
|
|
2023-12-14 00:47:04 -05:00
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
|
|
|
state.notePreviewViewportBoundsDirty = true;
|
|
|
|
state.scrollPositionInPixels = 0;
|
|
|
|
|
2023-12-14 16:56:20 -05:00
|
|
|
Conductor.instance.mapTimeChanges(state.currentSongMetadata.timeChanges);
|
2023-11-28 20:36:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function undo(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
var timeChanges:Array<SongTimeChange> = state.currentSongMetadata.timeChanges;
|
|
|
|
if (timeChanges == null || timeChanges.length == 0)
|
|
|
|
{
|
|
|
|
timeChanges = [new SongTimeChange(0, previousBPM)];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
timeChanges[0].bpm = previousBPM;
|
|
|
|
}
|
|
|
|
|
|
|
|
state.currentSongMetadata.timeChanges = timeChanges;
|
|
|
|
|
2023-12-14 00:47:04 -05:00
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
|
|
|
state.notePreviewViewportBoundsDirty = true;
|
|
|
|
state.scrollPositionInPixels = 0;
|
|
|
|
|
2023-12-14 16:56:20 -05:00
|
|
|
Conductor.instance.mapTimeChanges(state.currentSongMetadata.timeChanges);
|
2023-11-28 20:36:59 -05:00
|
|
|
}
|
2023-11-29 16:53:08 -05:00
|
|
|
|
2024-01-04 08:20:34 -05:00
|
|
|
public function shouldAddToHistory(state:ChartEditorState):Bool
|
|
|
|
{
|
|
|
|
// This command is undoable. Add to the history if we actually performed an action.
|
|
|
|
return (targetBPM != previousBPM);
|
|
|
|
}
|
|
|
|
|
2023-11-29 16:53:08 -05:00
|
|
|
public function toString():String
|
|
|
|
{
|
|
|
|
return 'Change Starting BPM to ${targetBPM}';
|
|
|
|
}
|
2023-11-28 20:36:59 -05:00
|
|
|
}
|