2022-10-07 00:37:21 -04:00
|
|
|
package funkin.ui.debug.charting;
|
|
|
|
|
2022-10-10 20:04:09 -04:00
|
|
|
import funkin.play.song.SongData.SongEventData;
|
2022-10-11 03:14:57 -04:00
|
|
|
import funkin.play.song.SongData.SongNoteData;
|
|
|
|
import funkin.play.song.SongDataUtils;
|
2022-10-10 20:04:09 -04:00
|
|
|
|
|
|
|
using Lambda;
|
2022-10-07 00:37:21 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Actions in the chart editor are backed by the Command pattern
|
|
|
|
* (see Bob Nystrom's book "Game Programming Patterns" for more info)
|
|
|
|
*
|
|
|
|
* To make a function compatible with the undo/redo history, create a new class
|
|
|
|
* that implements ChartEditorCommand, then call `ChartEditorState.performCommand(new Command())`
|
|
|
|
*/
|
|
|
|
interface ChartEditorCommand
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Calling this function should perform the action that this command represents.
|
|
|
|
* @param state The ChartEditorState to perform the action on.
|
|
|
|
*/
|
|
|
|
public function execute(state:ChartEditorState):Void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calling this function should perform the inverse of the action that this command represents,
|
|
|
|
* effectively undoing the action.
|
|
|
|
* @param state The ChartEditorState to undo the action on.
|
|
|
|
*/
|
|
|
|
public function undo(state:ChartEditorState):Void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a short description of the action (for the UI).
|
|
|
|
* For example, return `Add Left Note` to display `Undo Add Left Note` in the menu.
|
|
|
|
*/
|
|
|
|
public function toString():String;
|
|
|
|
}
|
|
|
|
|
2022-10-10 20:04:09 -04:00
|
|
|
class AddNotesCommand implements ChartEditorCommand
|
2022-10-07 00:37:21 -04:00
|
|
|
{
|
2022-10-11 03:14:57 -04:00
|
|
|
private var notes:Array<SongNoteData>;
|
2022-10-07 00:37:21 -04:00
|
|
|
|
2022-10-11 03:14:57 -04:00
|
|
|
public function new(notes:Array<SongNoteData>)
|
2022-10-07 00:37:21 -04:00
|
|
|
{
|
2022-10-10 20:04:09 -04:00
|
|
|
this.notes = notes;
|
2022-10-07 00:37:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(state:ChartEditorState):Void
|
|
|
|
{
|
2022-10-11 03:14:57 -04:00
|
|
|
for (note in notes)
|
|
|
|
{
|
2022-10-10 20:04:09 -04:00
|
|
|
state.currentSongChartNoteData.push(note);
|
|
|
|
}
|
|
|
|
|
|
|
|
state.currentSelection = notes;
|
2022-10-07 00:37:21 -04:00
|
|
|
state.playSound(Paths.sound('funnyNoise/funnyNoise-08'));
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-07 00:37:21 -04:00
|
|
|
state.noteDisplayDirty = true;
|
2022-10-10 20:04:09 -04:00
|
|
|
state.notePreviewDirty = true;
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-07 00:37:21 -04:00
|
|
|
state.sortChartData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function undo(state:ChartEditorState):Void
|
|
|
|
{
|
2022-10-10 20:04:09 -04:00
|
|
|
state.currentSongChartNoteData = SongDataUtils.subtractNotes(state.currentSongChartNoteData, notes);
|
|
|
|
state.currentSelection = [];
|
2022-10-07 00:37:21 -04:00
|
|
|
state.playSound(Paths.sound('funnyNoise/funnyNoise-01'));
|
2022-10-10 20:04:09 -04:00
|
|
|
|
2022-10-07 00:37:21 -04:00
|
|
|
state.noteDisplayDirty = true;
|
2022-10-10 20:04:09 -04:00
|
|
|
state.notePreviewDirty = true;
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-07 00:37:21 -04:00
|
|
|
state.sortChartData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toString():String
|
|
|
|
{
|
2022-10-11 03:14:57 -04:00
|
|
|
if (notes.length == 1)
|
|
|
|
{
|
2022-10-10 20:04:09 -04:00
|
|
|
var dir:String = notes[0].getDirectionName();
|
|
|
|
return 'Add $dir Note';
|
|
|
|
}
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-10 20:04:09 -04:00
|
|
|
return 'Add ${notes.length} Notes';
|
2022-10-07 00:37:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-11 03:14:57 -04:00
|
|
|
class RemoveNotesCommand implements ChartEditorCommand
|
2022-10-07 00:37:21 -04:00
|
|
|
{
|
2022-10-11 03:14:57 -04:00
|
|
|
private var notes:Array<SongNoteData>;
|
2022-10-07 00:37:21 -04:00
|
|
|
|
2022-10-11 03:14:57 -04:00
|
|
|
public function new(notes:Array<SongNoteData>)
|
2022-10-07 00:37:21 -04:00
|
|
|
{
|
2022-10-11 03:14:57 -04:00
|
|
|
this.notes = notes;
|
2022-10-07 00:37:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(state:ChartEditorState):Void
|
|
|
|
{
|
2022-10-11 03:14:57 -04:00
|
|
|
state.currentSongChartNoteData = SongDataUtils.subtractNotes(state.currentSongChartNoteData, notes);
|
2022-10-10 20:04:09 -04:00
|
|
|
state.currentSelection = [];
|
2022-10-07 00:37:21 -04:00
|
|
|
state.playSound(Paths.sound('funnyNoise/funnyNoise-01'));
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-07 00:37:21 -04:00
|
|
|
state.noteDisplayDirty = true;
|
2022-10-10 20:04:09 -04:00
|
|
|
state.notePreviewDirty = true;
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-07 00:37:21 -04:00
|
|
|
state.sortChartData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function undo(state:ChartEditorState):Void
|
|
|
|
{
|
2022-10-11 03:14:57 -04:00
|
|
|
for (note in notes)
|
|
|
|
{
|
|
|
|
state.currentSongChartNoteData.push(note);
|
|
|
|
}
|
|
|
|
state.currentSelection = notes;
|
2022-10-07 00:37:21 -04:00
|
|
|
state.playSound(Paths.sound('funnyNoise/funnyNoise-08'));
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-07 00:37:21 -04:00
|
|
|
state.noteDisplayDirty = true;
|
2022-10-10 20:04:09 -04:00
|
|
|
state.notePreviewDirty = true;
|
|
|
|
|
2022-10-07 00:37:21 -04:00
|
|
|
state.sortChartData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toString():String
|
|
|
|
{
|
2022-10-13 21:32:19 -04:00
|
|
|
if (notes.length == 1 && notes[0] != null)
|
2022-10-11 03:14:57 -04:00
|
|
|
{
|
2022-10-10 20:04:09 -04:00
|
|
|
var dir:String = notes[0].getDirectionName();
|
|
|
|
return 'Remove $dir Note';
|
|
|
|
}
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-10 20:04:09 -04:00
|
|
|
return 'Remove ${notes.length} Notes';
|
2022-10-07 00:37:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SwitchDifficultyCommand implements ChartEditorCommand
|
|
|
|
{
|
|
|
|
private var prevDifficulty:String;
|
|
|
|
private var newDifficulty:String;
|
|
|
|
private var prevVariation:String;
|
|
|
|
private var newVariation:String;
|
|
|
|
|
|
|
|
public function new(prevDifficulty:String, newDifficulty:String, prevVariation:String, newVariation:String)
|
|
|
|
{
|
|
|
|
this.prevDifficulty = prevDifficulty;
|
|
|
|
this.newDifficulty = newDifficulty;
|
|
|
|
this.prevVariation = prevVariation;
|
|
|
|
this.newVariation = newVariation;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
state.selectedVariation = newVariation != null ? newVariation : prevVariation;
|
|
|
|
state.selectedDifficulty = newDifficulty != null ? newDifficulty : prevDifficulty;
|
|
|
|
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function undo(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
state.selectedVariation = prevVariation != null ? prevVariation : newVariation;
|
|
|
|
state.selectedDifficulty = prevDifficulty != null ? prevDifficulty : newDifficulty;
|
|
|
|
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toString():String
|
|
|
|
{
|
|
|
|
return 'Switch Difficulty';
|
|
|
|
}
|
|
|
|
}
|
2022-10-10 20:04:09 -04:00
|
|
|
|
|
|
|
class SelectNotesCommand implements ChartEditorCommand
|
|
|
|
{
|
|
|
|
private var notes:Array<SongNoteData>;
|
|
|
|
|
|
|
|
public function new(notes:Array<SongNoteData>)
|
|
|
|
{
|
|
|
|
this.notes = notes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(state:ChartEditorState):Void
|
|
|
|
{
|
2022-10-11 03:14:57 -04:00
|
|
|
for (note in this.notes)
|
|
|
|
{
|
2022-10-10 20:04:09 -04:00
|
|
|
state.currentSelection.push(note);
|
|
|
|
}
|
|
|
|
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function undo(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
state.currentSelection = SongDataUtils.subtractNotes(state.currentSelection, this.notes);
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-10 20:04:09 -04:00
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toString():String
|
|
|
|
{
|
2022-10-11 03:14:57 -04:00
|
|
|
if (notes.length == 1)
|
|
|
|
{
|
2022-10-10 20:04:09 -04:00
|
|
|
var dir:String = notes[0].getDirectionName();
|
|
|
|
return 'Select $dir Note';
|
|
|
|
}
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-10 20:04:09 -04:00
|
|
|
return 'Select ${notes.length} Notes';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-11 03:14:57 -04:00
|
|
|
class DeselectNotesCommand implements ChartEditorCommand
|
2022-10-10 20:04:09 -04:00
|
|
|
{
|
|
|
|
private var notes:Array<SongNoteData>;
|
|
|
|
|
|
|
|
public function new(notes:Array<SongNoteData>)
|
|
|
|
{
|
|
|
|
this.notes = notes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
state.currentSelection = SongDataUtils.subtractNotes(state.currentSelection, this.notes);
|
|
|
|
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function undo(state:ChartEditorState):Void
|
|
|
|
{
|
2022-10-11 03:14:57 -04:00
|
|
|
for (note in this.notes)
|
|
|
|
{
|
2022-10-10 20:04:09 -04:00
|
|
|
state.currentSelection.push(note);
|
|
|
|
}
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-10 20:04:09 -04:00
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toString():String
|
|
|
|
{
|
2022-10-11 03:14:57 -04:00
|
|
|
if (notes.length == 1)
|
|
|
|
{
|
2022-10-10 20:04:09 -04:00
|
|
|
var dir:String = notes[0].getDirectionName();
|
|
|
|
return 'Deselect $dir Note';
|
|
|
|
}
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-10 20:04:09 -04:00
|
|
|
return 'Deselect ${notes.length} Notes';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SelectAllNotesCommand implements ChartEditorCommand
|
|
|
|
{
|
|
|
|
private var previousSelection:Array<SongNoteData>;
|
|
|
|
|
|
|
|
public function new(?previousSelection:Array<SongNoteData>)
|
|
|
|
{
|
|
|
|
this.previousSelection = previousSelection == null ? [] : previousSelection;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(state:ChartEditorState):Void
|
|
|
|
{
|
2022-10-11 03:14:57 -04:00
|
|
|
state.currentSelection = state.currentSongChartNoteData;
|
2022-10-10 20:04:09 -04:00
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function undo(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
state.currentSelection = previousSelection;
|
|
|
|
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toString():String
|
|
|
|
{
|
|
|
|
return 'Select All Notes';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class DeselectAllNotesCommand implements ChartEditorCommand
|
|
|
|
{
|
|
|
|
private var previousSelection:Array<SongNoteData>;
|
|
|
|
|
|
|
|
public function new(?previousSelection:Array<SongNoteData>)
|
|
|
|
{
|
|
|
|
this.previousSelection = previousSelection == null ? [] : previousSelection;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
state.currentSelection = [];
|
|
|
|
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function undo(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
state.currentSelection = previousSelection;
|
|
|
|
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toString():String
|
|
|
|
{
|
|
|
|
return 'Deselect All Notes';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CutNotesCommand implements ChartEditorCommand
|
|
|
|
{
|
|
|
|
private var notes:Array<SongNoteData>;
|
|
|
|
|
2022-10-13 21:32:19 -04:00
|
|
|
public function new(notes:Array<SongNoteData>)
|
2022-10-10 20:04:09 -04:00
|
|
|
{
|
|
|
|
this.notes = notes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
// Copy the notes.
|
2022-10-12 21:42:40 -04:00
|
|
|
SongDataUtils.writeNotesToClipboard(SongDataUtils.buildClipboard(notes));
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-10 20:04:09 -04:00
|
|
|
// Delete the notes.
|
|
|
|
state.currentSongChartNoteData = SongDataUtils.subtractNotes(state.currentSongChartNoteData, notes);
|
|
|
|
state.currentSelection = [];
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
|
|
|
state.sortChartData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function undo(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
state.currentSongChartNoteData = state.currentSongChartNoteData.concat(notes);
|
|
|
|
state.currentSelection = notes;
|
|
|
|
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-10 20:04:09 -04:00
|
|
|
state.sortChartData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toString():String
|
|
|
|
{
|
|
|
|
var len:Int = notes.length;
|
|
|
|
return 'Cut $len Notes to Clipboard';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class PasteNotesCommand implements ChartEditorCommand
|
|
|
|
{
|
2022-10-12 21:42:40 -04:00
|
|
|
private var targetTimestamp:Float;
|
2022-10-13 21:32:19 -04:00
|
|
|
// Notes we added with this command, for undo.
|
|
|
|
private var addedNotes:Array<SongNoteData>;
|
2022-10-10 20:04:09 -04:00
|
|
|
|
2022-10-12 21:42:40 -04:00
|
|
|
public function new(targetTimestamp:Float)
|
2022-10-10 20:04:09 -04:00
|
|
|
{
|
|
|
|
this.targetTimestamp = targetTimestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(state:ChartEditorState):Void
|
|
|
|
{
|
2022-10-12 21:42:40 -04:00
|
|
|
var currentClipboard:Array<SongNoteData> = SongDataUtils.readNotesFromClipboard();
|
|
|
|
|
2022-10-13 21:32:19 -04:00
|
|
|
addedNotes = SongDataUtils.offsetSongNoteData(currentClipboard, Std.int(targetTimestamp));
|
2022-10-10 20:04:09 -04:00
|
|
|
|
2022-10-13 21:32:19 -04:00
|
|
|
state.currentSongChartNoteData = state.currentSongChartNoteData.concat(addedNotes);
|
|
|
|
state.currentSelection = addedNotes.copy();
|
2022-10-10 20:04:09 -04:00
|
|
|
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-10 20:04:09 -04:00
|
|
|
state.sortChartData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function undo(state:ChartEditorState):Void
|
|
|
|
{
|
2022-10-13 21:32:19 -04:00
|
|
|
state.currentSongChartNoteData = SongDataUtils.subtractNotes(state.currentSongChartNoteData, addedNotes);
|
2022-10-10 20:04:09 -04:00
|
|
|
state.currentSelection = [];
|
|
|
|
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-10 20:04:09 -04:00
|
|
|
state.sortChartData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toString():String
|
|
|
|
{
|
2022-10-12 21:42:40 -04:00
|
|
|
var currentClipboard:Array<SongNoteData> = SongDataUtils.readNotesFromClipboard();
|
|
|
|
return 'Paste ${currentClipboard.length} Notes from Clipboard';
|
2022-10-10 20:04:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AddEventsCommand implements ChartEditorCommand
|
|
|
|
{
|
|
|
|
private var events:Array<SongEventData>;
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-10 20:04:09 -04:00
|
|
|
// private var previousSelection:Array<SongEventData>;
|
|
|
|
|
|
|
|
public function new(events:Array<SongEventData>, ?previousSelection:Array<SongEventData>)
|
|
|
|
{
|
|
|
|
this.events = events;
|
|
|
|
// this.previousSelection = previousSelection == null ? [] : previousSelection;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
state.currentSongChartEventData = state.currentSongChartEventData.concat(events);
|
|
|
|
// TODO: Allow selecting events.
|
|
|
|
// state.currentSelection = events;
|
|
|
|
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-10 20:04:09 -04:00
|
|
|
state.sortChartData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function undo(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
state.currentSongChartEventData = SongDataUtils.subtractEvents(state.currentSongChartEventData, events);
|
|
|
|
// TODO: Allow selecting events.
|
|
|
|
// state.currentSelection = previousSelection;
|
|
|
|
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
2022-10-11 03:14:57 -04:00
|
|
|
|
2022-10-10 20:04:09 -04:00
|
|
|
state.sortChartData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toString():String
|
|
|
|
{
|
|
|
|
var len:Int = events.length;
|
|
|
|
return 'Add $len Events';
|
|
|
|
}
|
2022-10-11 03:14:57 -04:00
|
|
|
}
|