Created
December 26, 2022 01:57
-
-
Save kinoko87/a7b9ed8b7579221ea4ed69aabb000a76 to your computer and use it in GitHub Desktop.
The shit needed for undo/redo implementation in FNF's charting state
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum abstract ChartActionType(Int) from Int to Int { | |
var AddNote:Int = 0; | |
var RemoveNote:Int = 1; | |
var AddEvent:Int = 2; | |
var RemoveEvent:Int = 3; | |
} | |
typedef ChartAction = { | |
var action:ChartActionType; | |
var data:Dynamic; | |
} | |
var chartActions:Array<ChartAction> = []; | |
var undoneStuff:Array<ChartAction> = []; | |
function undo() { | |
if (chartActions.length == 0) return; | |
trace(chartActions); | |
var cA = chartActions[chartActions.length - 1]; | |
switch (cA.action) { | |
case AddNote: | |
_song.notes[curSec].sectionNotes.remove(cA.data); | |
if (curSelectedNote == cA.data) | |
curSelectedNote = null; | |
case RemoveNote: | |
_song.notes[curSec].sectionNotes.push(cA.data); | |
curSelectedNote = cA.data; | |
case AddEvent: | |
_song.events.remove(cA.data); | |
if (curSelectedNote == cA.data) | |
curSelectedNote = null; | |
case RemoveEvent: | |
_song.events.push(cA.data); | |
curSelectedNote = cA.data; | |
} | |
undoneStuff.push(cA); | |
chartActions.pop(); | |
updateGrid(); | |
} | |
function redo() { | |
if (undoneStuff.length == 0) return; | |
trace(undoneStuff); | |
var cA = undoneStuff[undoneStuff.length - 1]; | |
switch (cA.action) { | |
case AddNote: | |
_song.notes[curSec].sectionNotes.push(cA.data); | |
curSelectedNote = cA.data; | |
case RemoveNote: | |
_song.notes[curSec].sectionNotes.remove(cA.data); | |
if (curSelectedNote == cA.data) | |
curSelectedNote = null; | |
case AddEvent: | |
_song.events.push(cA.data); | |
curSelectedNote = cA.data; | |
case RemoveEvent: | |
_song.events.remove(cA.data); | |
if (curSelectedNote == cA.data) | |
curSelectedNote = null; | |
} | |
undoneStuff.pop(); | |
chartActions.push(cA); | |
updateGrid(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment