2023-10-26 09:46:22 +00:00
|
|
|
package funkin.ui.debug.charting.commands;
|
|
|
|
|
|
|
|
import funkin.data.song.SongData.SongEventData;
|
|
|
|
import funkin.data.song.SongData.SongNoteData;
|
|
|
|
import funkin.data.song.SongDataUtils;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move the given events by the given offset and shift them by the given number of columns in the chart editor.
|
|
|
|
*/
|
|
|
|
@:nullSafety
|
|
|
|
@:access(funkin.ui.debug.charting.ChartEditorState)
|
|
|
|
class MoveEventsCommand implements ChartEditorCommand
|
|
|
|
{
|
|
|
|
var events:Array<SongEventData>;
|
|
|
|
var movedEvents:Array<SongEventData>;
|
|
|
|
var offset:Float;
|
|
|
|
|
2023-11-21 06:00:06 +00:00
|
|
|
public function new(events:Array<SongEventData>, offset:Float)
|
2023-10-26 09:46:22 +00:00
|
|
|
{
|
|
|
|
// Clone the notes to prevent editing from affecting the history.
|
|
|
|
this.events = [for (event in events) event.clone()];
|
|
|
|
this.offset = offset;
|
|
|
|
this.movedEvents = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
state.currentSongChartEventData = SongDataUtils.subtractEvents(state.currentSongChartEventData, events);
|
|
|
|
|
|
|
|
movedEvents = [];
|
|
|
|
|
|
|
|
for (event in events)
|
|
|
|
{
|
|
|
|
// Clone the notes to prevent editing from affecting the history.
|
|
|
|
var resultEvent = event.clone();
|
2023-12-14 21:56:20 +00:00
|
|
|
resultEvent.time = (resultEvent.time + offset).clamp(0, Conductor.instance.getStepTimeInMs(state.songLengthInSteps - (1 * state.noteSnapRatio)));
|
2023-10-26 09:46:22 +00:00
|
|
|
|
|
|
|
movedEvents.push(resultEvent);
|
|
|
|
}
|
|
|
|
|
2023-11-21 06:00:06 +00:00
|
|
|
state.currentSongChartEventData = SongDataUtils.subtractEvents(state.currentSongChartEventData, events);
|
2023-10-26 09:46:22 +00:00
|
|
|
state.currentSongChartEventData = state.currentSongChartEventData.concat(movedEvents);
|
|
|
|
state.currentEventSelection = movedEvents;
|
|
|
|
|
|
|
|
state.playSound(Paths.sound('chartingSounds/noteLay'));
|
|
|
|
|
|
|
|
state.saveDataDirty = true;
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
|
|
|
|
|
|
|
state.sortChartData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function undo(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
state.currentSongChartEventData = SongDataUtils.subtractEvents(state.currentSongChartEventData, movedEvents);
|
|
|
|
state.currentSongChartEventData = state.currentSongChartEventData.concat(events);
|
|
|
|
|
|
|
|
state.currentEventSelection = events;
|
|
|
|
|
|
|
|
state.saveDataDirty = true;
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
|
|
|
|
|
|
|
state.sortChartData();
|
|
|
|
}
|
|
|
|
|
2024-01-04 13:20:34 +00:00
|
|
|
public function shouldAddToHistory(state:ChartEditorState):Bool
|
|
|
|
{
|
|
|
|
// This command is undoable. Add to the history if we actually performed an action.
|
|
|
|
return (events.length > 0);
|
|
|
|
}
|
|
|
|
|
2023-10-26 09:46:22 +00:00
|
|
|
public function toString():String
|
|
|
|
{
|
|
|
|
var len:Int = events.length;
|
|
|
|
return 'Move $len Events';
|
|
|
|
}
|
|
|
|
}
|