2023-10-26 09:46:22 +00:00
|
|
|
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>;
|
2024-01-04 13:20:34 +00:00
|
|
|
var previousNoteSelection:Array<SongNoteData> = [];
|
|
|
|
var previousEventSelection:Array<SongEventData> = [];
|
2023-10-26 09:46:22 +00:00
|
|
|
|
2024-01-04 13:20:34 +00:00
|
|
|
public function new(notes:Array<SongNoteData>, events:Array<SongEventData>)
|
2023-10-26 09:46:22 +00:00
|
|
|
{
|
|
|
|
this.notes = notes;
|
|
|
|
this.events = events;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(state:ChartEditorState):Void
|
|
|
|
{
|
2024-01-04 13:20:34 +00:00
|
|
|
this.previousNoteSelection = state.currentNoteSelection;
|
|
|
|
this.previousEventSelection = state.currentEventSelection;
|
|
|
|
|
2023-10-26 09:46:22 +00:00
|
|
|
state.currentNoteSelection = notes;
|
|
|
|
state.currentEventSelection = events;
|
|
|
|
|
2024-01-04 00:53:17 +00:00
|
|
|
// If we just selected one or more events (and no notes), then we should make the event data toolbox display the event data for the selected event.
|
2024-02-17 07:13:11 +00:00
|
|
|
if (this.notes.length == 0 && this.events.length == 1)
|
2024-01-04 00:53:17 +00:00
|
|
|
{
|
|
|
|
var eventSelected = this.events[0];
|
2024-01-04 02:10:14 +00:00
|
|
|
|
2024-06-06 20:44:47 +00:00
|
|
|
if (state.eventKindToPlace == eventSelected.eventKind)
|
|
|
|
{
|
|
|
|
trace('Target event kind matches selection: ${eventSelected.eventKind}');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trace('Switching target event kind to match selection: ${state.eventKindToPlace} != ${eventSelected.eventKind}');
|
|
|
|
state.eventKindToPlace = eventSelected.eventKind;
|
|
|
|
}
|
2024-01-04 02:10:14 +00:00
|
|
|
|
|
|
|
// This code is here to parse event data that's not built as a struct for some reason.
|
|
|
|
// TODO: Clean this up or get rid of it.
|
|
|
|
var eventSchema = eventSelected.getSchema();
|
|
|
|
var defaultKey = null;
|
|
|
|
if (eventSchema == null)
|
|
|
|
{
|
2024-02-18 08:02:36 +00:00
|
|
|
trace('[WARNING] Event schema not found for event ${eventSelected.eventKind}.');
|
2024-01-04 02:10:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
defaultKey = eventSchema.getFirstField()?.name;
|
|
|
|
}
|
|
|
|
var eventData = eventSelected.valueAsStruct(defaultKey);
|
|
|
|
|
2024-03-22 03:57:26 +00:00
|
|
|
var eventDataClone = Reflect.copy(eventData);
|
|
|
|
|
|
|
|
if (eventDataClone != null)
|
|
|
|
{
|
|
|
|
state.eventDataToPlace = eventDataClone;
|
|
|
|
}
|
2024-01-04 02:10:14 +00:00
|
|
|
|
2024-01-04 00:53:17 +00:00
|
|
|
state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT);
|
|
|
|
}
|
|
|
|
|
2024-02-17 03:01:47 +00:00
|
|
|
// IF we just selected one or more notes (and no events), then we should make the note data toolbox display the note data for the selected note.
|
2024-02-17 07:13:11 +00:00
|
|
|
if (this.events.length == 0 && this.notes.length == 1)
|
2024-02-17 03:01:47 +00:00
|
|
|
{
|
|
|
|
var noteSelected = this.notes[0];
|
|
|
|
|
|
|
|
state.noteKindToPlace = noteSelected.kind;
|
|
|
|
|
|
|
|
state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_NOTE_DATA_LAYOUT);
|
|
|
|
}
|
|
|
|
|
2023-10-26 09:46:22 +00:00
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function undo(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
state.currentNoteSelection = previousNoteSelection;
|
|
|
|
state.currentEventSelection = previousEventSelection;
|
|
|
|
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
}
|
|
|
|
|
2024-01-04 13:20:34 +00:00
|
|
|
public function shouldAddToHistory(state:ChartEditorState):Bool
|
|
|
|
{
|
|
|
|
// Add to the history if we actually performed an action.
|
|
|
|
return (state.currentNoteSelection != previousNoteSelection && state.currentEventSelection != previousEventSelection);
|
|
|
|
}
|
|
|
|
|
2023-10-26 09:46:22 +00:00
|
|
|
public function toString():String
|
|
|
|
{
|
2024-01-04 13:20:34 +00:00
|
|
|
return 'Select ${notes.length + events.length} Items';
|
2023-10-26 09:46:22 +00:00
|
|
|
}
|
|
|
|
}
|