2023-10-26 05:46:22 -04:00
|
|
|
package funkin.ui.debug.charting.commands;
|
|
|
|
|
|
|
|
import funkin.data.song.SongData.SongEventData;
|
|
|
|
import funkin.data.song.SongData.SongNoteData;
|
|
|
|
import funkin.data.song.SongDataUtils;
|
|
|
|
import funkin.data.song.SongDataUtils.SongClipboardItems;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A command which inserts the contents of the clipboard into the chart editor.
|
|
|
|
*/
|
|
|
|
@:nullSafety
|
|
|
|
@:access(funkin.ui.debug.charting.ChartEditorState)
|
|
|
|
class PasteItemsCommand implements ChartEditorCommand
|
|
|
|
{
|
|
|
|
var targetTimestamp:Float;
|
|
|
|
// Notes we added with this command, for undo.
|
|
|
|
var addedNotes:Array<SongNoteData> = [];
|
|
|
|
var addedEvents:Array<SongEventData> = [];
|
|
|
|
|
|
|
|
public function new(targetTimestamp:Float)
|
|
|
|
{
|
|
|
|
this.targetTimestamp = targetTimestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
var currentClipboard:SongClipboardItems = SongDataUtils.readItemsFromClipboard();
|
|
|
|
|
|
|
|
if (currentClipboard.valid != true)
|
|
|
|
{
|
2023-11-22 19:16:38 -05:00
|
|
|
state.error('Failed to Paste', 'Could not parse clipboard contents.');
|
2023-10-26 05:46:22 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
trace(currentClipboard.notes);
|
|
|
|
|
|
|
|
addedNotes = SongDataUtils.offsetSongNoteData(currentClipboard.notes, Std.int(targetTimestamp));
|
|
|
|
addedEvents = SongDataUtils.offsetSongEventData(currentClipboard.events, Std.int(targetTimestamp));
|
|
|
|
|
|
|
|
state.currentSongChartNoteData = state.currentSongChartNoteData.concat(addedNotes);
|
|
|
|
state.currentSongChartEventData = state.currentSongChartEventData.concat(addedEvents);
|
|
|
|
state.currentNoteSelection = addedNotes.copy();
|
|
|
|
state.currentEventSelection = addedEvents.copy();
|
|
|
|
|
|
|
|
state.saveDataDirty = true;
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
|
|
|
|
|
|
|
state.sortChartData();
|
|
|
|
|
2023-11-22 19:16:38 -05:00
|
|
|
state.success('Paste Successful', 'Successfully pasted clipboard contents.');
|
2023-10-26 05:46:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function undo(state:ChartEditorState):Void
|
|
|
|
{
|
|
|
|
state.playSound(Paths.sound('chartingSounds/undo'));
|
|
|
|
|
|
|
|
state.currentSongChartNoteData = SongDataUtils.subtractNotes(state.currentSongChartNoteData, addedNotes);
|
|
|
|
state.currentSongChartEventData = SongDataUtils.subtractEvents(state.currentSongChartEventData, addedEvents);
|
|
|
|
state.currentNoteSelection = [];
|
|
|
|
state.currentEventSelection = [];
|
|
|
|
|
|
|
|
state.saveDataDirty = true;
|
|
|
|
state.noteDisplayDirty = true;
|
|
|
|
state.notePreviewDirty = true;
|
|
|
|
|
|
|
|
state.sortChartData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toString():String
|
|
|
|
{
|
|
|
|
var currentClipboard:SongClipboardItems = SongDataUtils.readItemsFromClipboard();
|
|
|
|
|
|
|
|
var len:Int = currentClipboard.notes.length + currentClipboard.events.length;
|
|
|
|
|
|
|
|
if (currentClipboard.notes.length == 0) return 'Paste $len Events';
|
|
|
|
else if (currentClipboard.events.length == 0) return 'Paste $len Notes';
|
|
|
|
else
|
|
|
|
return 'Paste $len Items';
|
|
|
|
}
|
|
|
|
}
|