Funkin/source/funkin/ui/debug/charting/commands/SetItemSelectionCommand.hx

55 lines
1.6 KiB
Haxe
Raw Normal View History

package funkin.ui.debug.charting.commands;
import funkin.data.song.SongData.SongNoteData;
import funkin.data.song.SongData.SongEventData;
/**
* Command to set the current selection in the chart editor (rather than appending it).
* Deselects any notes that are not in the new selection.
*/
@:nullSafety
@:access(funkin.ui.debug.charting.ChartEditorState)
class SetItemSelectionCommand implements ChartEditorCommand
{
var notes:Array<SongNoteData>;
var events:Array<SongEventData>;
var previousNoteSelection:Array<SongNoteData> = [];
var previousEventSelection:Array<SongEventData> = [];
public function new(notes:Array<SongNoteData>, events:Array<SongEventData>)
{
this.notes = notes;
this.events = events;
}
public function execute(state:ChartEditorState):Void
{
this.previousNoteSelection = state.currentNoteSelection;
this.previousEventSelection = state.currentEventSelection;
state.currentNoteSelection = notes;
state.currentEventSelection = events;
state.noteDisplayDirty = true;
}
public function undo(state:ChartEditorState):Void
{
state.currentNoteSelection = previousNoteSelection;
state.currentEventSelection = previousEventSelection;
state.noteDisplayDirty = true;
}
public function shouldAddToHistory(state:ChartEditorState):Bool
{
// Add to the history if we actually performed an action.
return (state.currentNoteSelection != previousNoteSelection && state.currentEventSelection != previousEventSelection);
}
public function toString():String
{
return 'Select ${notes.length + events.length} Items';
}
}