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;
|
|
|
|
}
|
|
|
|
|
2023-12-14 16:56:20 -05:00
|
|
|
var stepEndOfSong:Float = Conductor.instance.getTimeInSteps(state.songLengthInMs);
|
2023-11-28 20:36:59 -05:00
|
|
|
var stepCutoff:Float = stepEndOfSong - 1.0;
|
2023-12-14 16:56:20 -05:00
|
|
|
var msCutoff:Float = Conductor.instance.getStepTimeInMs(stepCutoff);
|
2023-10-26 05:46:22 -04:00
|
|
|
|
|
|
|
addedNotes = SongDataUtils.offsetSongNoteData(currentClipboard.notes, Std.int(targetTimestamp));
|
2023-11-28 20:36:59 -05:00
|
|
|
addedNotes = SongDataUtils.clampSongNoteData(addedNotes, 0.0, msCutoff);
|
2023-10-26 05:46:22 -04:00
|
|
|
addedEvents = SongDataUtils.offsetSongEventData(currentClipboard.events, Std.int(targetTimestamp));
|
2023-11-28 20:36:59 -05:00
|
|
|
addedEvents = SongDataUtils.clampSongEventData(addedEvents, 0.0, msCutoff);
|
2023-10-26 05:46:22 -04:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2024-01-04 08:20:34 -05:00
|
|
|
public function shouldAddToHistory(state:ChartEditorState):Bool
|
|
|
|
{
|
|
|
|
// This command is undoable. Add to the history if we actually performed an action.
|
|
|
|
return (addedNotes.length > 0 || addedEvents.length > 0);
|
|
|
|
}
|
|
|
|
|
2023-10-26 05:46:22 -04:00
|
|
|
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';
|
|
|
|
}
|
|
|
|
}
|