mirror of
https://github.com/FunkinCrew/Funkin.git
synced 2024-11-24 00:27:59 -05:00
81 lines
2.6 KiB
Haxe
81 lines
2.6 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;
|
|
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)
|
|
{
|
|
state.error('Failed to Paste', 'Could not parse clipboard contents.');
|
|
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();
|
|
|
|
state.success('Paste Successful', 'Successfully pasted clipboard contents.');
|
|
}
|
|
|
|
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';
|
|
}
|
|
}
|