undoing and better pasting
This commit is contained in:
parent
0dd0a059f5
commit
7f80d19765
@ -1360,7 +1360,58 @@ class ChartingState extends MusicBeatState
|
||||
}
|
||||
|
||||
|
||||
function pasteNotesFromArray(array:Array<Array<Dynamic>>,fromStrum:Bool = true)
|
||||
{
|
||||
for(i in array)
|
||||
{
|
||||
var strum:Float = i[0];
|
||||
if (fromStrum)
|
||||
strum += Conductor.songPosition;
|
||||
var section = 0;
|
||||
for(ii in _song.notes)
|
||||
{
|
||||
if (ii.startTime <= strum && ii.endTime > strum)
|
||||
{
|
||||
trace("new strum " + strum + " - at section " + section);
|
||||
// alright we're in this section lets paste the note here.
|
||||
var newData = [strum,i[1],i[2]];
|
||||
ii.sectionNotes.push(newData);
|
||||
|
||||
var note:Note = new Note(strum, Math.floor(i[1] % 4),null,false,true);
|
||||
note.rawNoteData = i[1];
|
||||
note.sustainLength = i[2];
|
||||
note.setGraphicSize(Math.floor(GRID_SIZE), Math.floor(GRID_SIZE));
|
||||
note.updateHitbox();
|
||||
note.x = Math.floor(i[1] * GRID_SIZE);
|
||||
|
||||
note.charterSelected = true;
|
||||
|
||||
|
||||
note.y = Math.floor(getYfromStrum(strum) * zoomFactor);
|
||||
|
||||
var box = new ChartingBox(note.x,note.y,note);
|
||||
selectedBoxes.add(box);
|
||||
|
||||
curRenderedNotes.add(note);
|
||||
|
||||
pastedNotes.push(note);
|
||||
|
||||
if (note.sustainLength > 0)
|
||||
{
|
||||
var sustainVis:FlxSprite = new FlxSprite(note.x + (GRID_SIZE / 2),
|
||||
note.y + GRID_SIZE).makeGraphic(8, Math.floor((getYfromStrum(note.strumTime + note.sustainLength) * zoomFactor) - note.y));
|
||||
|
||||
note.noteCharterObject = sustainVis;
|
||||
|
||||
curRenderedSustains.add(sustainVis);
|
||||
}
|
||||
trace("section new length: " + ii.sectionNotes.length);
|
||||
continue;
|
||||
}
|
||||
section++;
|
||||
}
|
||||
}
|
||||
}
|
||||
function loadSong(daSong:String):Void
|
||||
{
|
||||
if (FlxG.sound.music != null)
|
||||
@ -1559,10 +1610,13 @@ class ChartingState extends MusicBeatState
|
||||
|
||||
public var copiedNotes:Array<Array<Dynamic>> = [];
|
||||
public var pastedNotes:Array<Note> = [];
|
||||
public var deletedNotes:Array<Array<Dynamic>> = [];
|
||||
|
||||
public var selectInitialX:Float = 0;
|
||||
public var selectInitialY:Float = 0;
|
||||
|
||||
public var lastAction:String = "";
|
||||
|
||||
override function update(elapsed:Float)
|
||||
{
|
||||
updateHeads();
|
||||
@ -1652,7 +1706,7 @@ class ChartingState extends MusicBeatState
|
||||
claps.splice(0, claps.length);
|
||||
|
||||
|
||||
if (FlxG.keys.pressed.CONTROL)
|
||||
if (FlxG.keys.pressed.CONTROL && !waitingForRelease)
|
||||
{
|
||||
var amount = FlxG.mouse.wheel;
|
||||
|
||||
@ -1773,9 +1827,11 @@ class ChartingState extends MusicBeatState
|
||||
|
||||
if (FlxG.keys.pressed.CONTROL && FlxG.keys.justPressed.D)
|
||||
{
|
||||
lastAction = "delete";
|
||||
var notesToBeDeleted = [];
|
||||
for(i in 0...selectedBoxes.members.length)
|
||||
{
|
||||
deletedNotes.push([selectedBoxes.members[i].connectedNote.strumTime,selectedBoxes.members[i].connectedNote.rawNoteData,selectedBoxes.members[i].connectedNote.sustainLength]);
|
||||
notesToBeDeleted.push(selectedBoxes.members[i].connectedNote);
|
||||
}
|
||||
|
||||
@ -1787,9 +1843,11 @@ class ChartingState extends MusicBeatState
|
||||
|
||||
if (FlxG.keys.justPressed.DELETE)
|
||||
{
|
||||
lastAction = "delete";
|
||||
var notesToBeDeleted = [];
|
||||
for(i in 0...selectedBoxes.members.length)
|
||||
{
|
||||
deletedNotes.push([selectedBoxes.members[i].connectedNote.strumTime,selectedBoxes.members[i].connectedNote.rawNoteData,selectedBoxes.members[i].connectedNote.sustainLength]);
|
||||
notesToBeDeleted.push(selectedBoxes.members[i].connectedNote);
|
||||
}
|
||||
|
||||
@ -1800,37 +1858,24 @@ class ChartingState extends MusicBeatState
|
||||
}
|
||||
|
||||
|
||||
if (FlxG.keys.pressed.CONTROL && FlxG.keys.justPressed.D)
|
||||
{
|
||||
for(i in 0...selectedBoxes.members.length)
|
||||
{
|
||||
deleteNote(selectedBoxes.members[i].connectedNote);
|
||||
}
|
||||
}
|
||||
|
||||
if (FlxG.keys.justPressed.DELETE)
|
||||
{
|
||||
for(i in 0...selectedBoxes.members.length)
|
||||
{
|
||||
deleteNote(selectedBoxes.members[i].connectedNote);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (FlxG.keys.pressed.CONTROL && FlxG.keys.justPressed.C)
|
||||
{
|
||||
if (selectedBoxes.members.length != 0)
|
||||
{
|
||||
copiedNotes = [];
|
||||
for(i in selectedBoxes.members)
|
||||
copiedNotes.push([i.connectedNote.strumTime,i.connectedNote.noteData,i.connectedNote.sustainLength]);
|
||||
copiedNotes.push([i.connectedNote.strumTime,i.connectedNote.rawNoteData,i.connectedNote.sustainLength]);
|
||||
|
||||
var firstNote = copiedNotes[0][0];
|
||||
|
||||
for(i in copiedNotes) // normalize the notes
|
||||
{
|
||||
i[0] = i[0] - firstNote;
|
||||
trace("Normalized time: " + i[0]);
|
||||
trace("Normalized time: " + i[0] + " | " + i[1]);
|
||||
}
|
||||
|
||||
trace(copiedNotes.length);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1844,51 +1889,40 @@ class ChartingState extends MusicBeatState
|
||||
selectedBoxes.members[0].destroy();
|
||||
selectedBoxes.members.remove(selectedBoxes.members[0]);
|
||||
}
|
||||
|
||||
trace("Pasting " + copiedNotes.length);
|
||||
|
||||
|
||||
for(i in copiedNotes)
|
||||
{
|
||||
for(ii in _song.notes)
|
||||
{
|
||||
var strum:Float = Conductor.songPosition + i[0];
|
||||
if (ii.startTime <= strum && ii.endTime > strum)
|
||||
{
|
||||
trace("new strum " + strum);
|
||||
// alright we're in this section lets paste the note here.
|
||||
ii.sectionNotes.push(i);
|
||||
pasteNotesFromArray(copiedNotes);
|
||||
|
||||
var note:Note = new Note(strum, Math.floor(i[1] % 4),null,false,true);
|
||||
note.rawNoteData = i[1];
|
||||
note.sustainLength = i[2];
|
||||
note.setGraphicSize(Math.floor(GRID_SIZE), Math.floor(GRID_SIZE));
|
||||
note.updateHitbox();
|
||||
note.x = Math.floor(i[1] * GRID_SIZE);
|
||||
|
||||
note.charterSelected = true;
|
||||
|
||||
|
||||
note.y = Math.floor(getYfromStrum(strum) * zoomFactor);
|
||||
|
||||
var box = new ChartingBox(note.x,note.y,note);
|
||||
selectedBoxes.add(box);
|
||||
|
||||
curRenderedNotes.add(note);
|
||||
|
||||
pastedNotes.push(note);
|
||||
|
||||
if (note.sustainLength > 0)
|
||||
{
|
||||
var sustainVis:FlxSprite = new FlxSprite(note.x + (GRID_SIZE / 2),
|
||||
note.y + GRID_SIZE).makeGraphic(8, Math.floor((getYfromStrum(note.strumTime + note.sustainLength) * zoomFactor) - note.y));
|
||||
lastAction = "paste";
|
||||
|
||||
note.noteCharterObject = sustainVis;
|
||||
|
||||
curRenderedSustains.add(sustainVis);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (FlxG.keys.pressed.CONTROL && FlxG.keys.justPressed.Z)
|
||||
{
|
||||
switch(lastAction)
|
||||
{
|
||||
case "paste":
|
||||
trace("undo paste");
|
||||
if (pastedNotes.length != 0)
|
||||
{
|
||||
for(i in pastedNotes)
|
||||
{
|
||||
if (curRenderedNotes.members.contains(i))
|
||||
deleteNote(i);
|
||||
}
|
||||
|
||||
pastedNotes = [];
|
||||
}
|
||||
case "delete":
|
||||
trace("undoing delete");
|
||||
if (deletedNotes.length != 0)
|
||||
{
|
||||
trace("undoing delete");
|
||||
pasteNotesFromArray(deletedNotes,false);
|
||||
deletedNotes = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2311,17 +2345,6 @@ class ChartingState extends MusicBeatState
|
||||
if (!typingShit.hasFocus)
|
||||
{
|
||||
|
||||
if (FlxG.keys.pressed.CONTROL)
|
||||
{
|
||||
if (FlxG.keys.justPressed.Z && lastNote != null)
|
||||
{
|
||||
trace(curRenderedNotes.members.contains(lastNote) ? "delete note" : "add note");
|
||||
if (curRenderedNotes.members.contains(lastNote))
|
||||
deleteNote(lastNote);
|
||||
else
|
||||
addNote(lastNote);
|
||||
}
|
||||
}
|
||||
|
||||
var shiftThing:Int = 1;
|
||||
if (FlxG.keys.pressed.SHIFT)
|
||||
@ -2409,23 +2432,22 @@ class ChartingState extends MusicBeatState
|
||||
{
|
||||
curSelectedNote[2] += value;
|
||||
curSelectedNote[2] = Math.max(curSelectedNote[2], 0);
|
||||
|
||||
if (curSelectedNoteObject.noteCharterObject != null)
|
||||
curRenderedSustains.remove(curSelectedNoteObject.noteCharterObject);
|
||||
|
||||
var sustainVis:FlxSprite = new FlxSprite(curSelectedNoteObject.x + (GRID_SIZE / 2),
|
||||
curSelectedNoteObject.y + GRID_SIZE).makeGraphic(8, Math.floor((getYfromStrum(curSelectedNoteObject.strumTime + curSelectedNote[2]) * zoomFactor) - curSelectedNoteObject.y));
|
||||
curSelectedNoteObject.sustainLength = curSelectedNote[2];
|
||||
trace("new sustain " + curSelectedNoteObject.sustainLength);
|
||||
curSelectedNoteObject.noteCharterObject = sustainVis;
|
||||
|
||||
curRenderedSustains.add(sustainVis);
|
||||
}
|
||||
}
|
||||
|
||||
updateNoteUI();
|
||||
if (curSelectedNoteObject.sustainLength == 0)
|
||||
{
|
||||
var sustainVis:FlxSprite = new FlxSprite(curSelectedNoteObject.x + (GRID_SIZE / 2),
|
||||
curSelectedNoteObject.y + GRID_SIZE).makeGraphic(8, Math.floor((getYfromStrum(curSelectedNoteObject.strumTime + curSelectedNote[2]) * zoomFactor) - curSelectedNoteObject.y));
|
||||
|
||||
curSelectedNoteObject.noteCharterObject = sustainVis;
|
||||
|
||||
curRenderedSustains.add(sustainVis);
|
||||
}
|
||||
else
|
||||
{
|
||||
curSelectedNoteObject.noteCharterObject.height = Math.floor((getYfromStrum(curSelectedNoteObject.strumTime + curSelectedNote[2]) * zoomFactor) - curSelectedNoteObject.y);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -2715,9 +2737,10 @@ class ChartingState extends MusicBeatState
|
||||
for(i in 0...selectedBoxes.members.length)
|
||||
{
|
||||
var box = selectedBoxes.members[i];
|
||||
if (box.x == note.x && box.y == note.y)
|
||||
if (box.connectedNote == note)
|
||||
{
|
||||
selectedBoxes.members.remove(box);
|
||||
box.destroy();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -2970,7 +2993,7 @@ class ChartingState extends MusicBeatState
|
||||
else
|
||||
{
|
||||
var note:Note = new Note(n.strumTime, n.noteData % 4,null,false,true);
|
||||
note.rawNoteData = noteData;
|
||||
note.rawNoteData = n.noteData;
|
||||
note.sustainLength = noteSus;
|
||||
note.setGraphicSize(Math.floor(GRID_SIZE), Math.floor(GRID_SIZE));
|
||||
note.updateHitbox();
|
||||
|
Loading…
x
Reference in New Issue
Block a user