mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2024-11-10 08:44:47 +00:00
73 lines
2.1 KiB
Haxe
73 lines
2.1 KiB
Haxe
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;
|
|
|
|
public function new(notes:Array<SongEventData>, offset:Float)
|
|
{
|
|
// 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();
|
|
resultEvent.time = (resultEvent.time + offset).clamp(0, Conductor.getStepTimeInMs(state.songLengthInSteps - (1 * state.noteSnapRatio)));
|
|
|
|
movedEvents.push(resultEvent);
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
public function toString():String
|
|
{
|
|
var len:Int = events.length;
|
|
return 'Move $len Events';
|
|
}
|
|
}
|