diff --git a/source/funkin/editors/SaveWarning.hx b/source/funkin/editors/SaveWarning.hx index b712ad079..fad155b48 100644 --- a/source/funkin/editors/SaveWarning.hx +++ b/source/funkin/editors/SaveWarning.hx @@ -39,7 +39,7 @@ class SaveWarning { } }, { - label: closingWindow ? "Save & Exit Game" : "Save&Exit To Menu", + label: closingWindow ? "Save & Exit Game" : "Save & Exit To Menu", color: 0x969533, onClick: function(_) { if (saveFunc != null) saveFunc(); diff --git a/source/funkin/editors/charter/ChartDataScreen.hx b/source/funkin/editors/charter/ChartDataScreen.hx index d05f5d0fd..b4592d056 100644 --- a/source/funkin/editors/charter/ChartDataScreen.hx +++ b/source/funkin/editors/charter/ChartDataScreen.hx @@ -70,6 +70,6 @@ class ChartDataScreen extends UISubstateWindow { PlayState.SONG.stage = stageTextBox.label.text; PlayState.SONG.scrollSpeed = scrollSpeedStepper.value; - Charter.instance.undos.addToUndo(CEditChartData(oldData, {stage: stageTextBox.label.text, speed: scrollSpeedStepper.value})); + Charter.undos.addToUndo(CEditChartData(oldData, {stage: stageTextBox.label.text, speed: scrollSpeedStepper.value})); } } \ No newline at end of file diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index f5bc92198..64869b451 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -23,7 +23,6 @@ import openfl.net.FileReference; class Charter extends UIState { public static var __song:String; - public static var __lastPos:Float; static var __diff:String; static var __reload:Bool; @@ -82,10 +81,12 @@ class Charter extends UIState { public var uiCamera:FlxCamera; public var selectionBox:UISliceSprite; - public var selection:Selection = new Selection(); - public var undos:UndoList = new UndoList(); + public static var selection:Selection; - public var clipboard:Array = []; + public static var playtestInfo:PlaytestInfo; + public static var undos:UndoList; + + public static var clipboard:Array = []; public function new(song:String, diff:String, reload:Bool = true) { super(); @@ -454,6 +455,8 @@ class Charter extends UIState { } override function destroy() { + __updatePlaytestInfo(); + if(Framerate.isLoaded) { Framerate.fpsCounter.alpha = 1; Framerate.memoryCounter.alpha = 1; @@ -464,13 +467,12 @@ class Charter extends UIState { public function loadSong() { if (__reload) { - EventsData.reloadEvents(); __lastPos = 0; + EventsData.reloadEvents(); PlayState.loadSong(__song, __diff, false, false); + __resetStatics(); } Conductor.setupSong(PlayState.SONG); - Conductor.songPosition = __lastPos; noteTypes = PlayState.SONG.noteTypes; - // noteTypes = ["Hurt Note", "Bullet Note", "Penis Note", "Boobs Note"]; FlxG.sound.setMusic(FlxG.sound.load(Paths.inst(__song, __diff))); vocals = FlxG.sound.load(Paths.voices(__song, __diff)); @@ -500,6 +502,7 @@ class Charter extends UIState { notesGroup.autoSort = true; // create events + eventsGroup.autoSort = false; var __last:CharterEvent = null; var __lastTime:Float = Math.NaN; for(e in PlayState.SONG.events) { @@ -513,11 +516,20 @@ class Charter extends UIState { } } + eventsGroup.sortEvents(); + eventsGroup.autoSort = true; + for(e in eventsGroup.members) e.refreshEventIcons(); + buildNoteTypesUI(); refreshBPMSensitive(); + + // Cool shit :DD + __relinkSelection(); + __relinkUndos(); + __applyPlaytestInfo(); } public var __endStep:Float = 0; @@ -667,7 +679,10 @@ class Charter extends UIState { if (s is CharterNote) cast(s, CharterNote).snappedToStrumline = true; if (s is UISprite) cast(s, UISprite).cursor = BUTTON; } - if (!(verticalChange == 0 && horizontalChange == 0)) undos.addToUndo(CSelectionDrag(undoDrags)); + if (!(verticalChange == 0 && horizontalChange == 0)) { + notesGroup.sortNotes(); eventsGroup.sortEvents(); + undos.addToUndo(CSelectionDrag(undoDrags)); + } hoverOffset.put(); gridActionType = NONE; @@ -779,11 +794,13 @@ class Charter extends UIState { if (selected is CharterNote) { var note:CharterNote = cast selected; - notesGroup.remove(note, true); + note.strumLineID = strumLines.members.indexOf(note.strumLine); + note.strumLine = null; // For static undos :D + notesGroup.remove(note); note.kill(); } else if (selected is CharterEvent) { var event:CharterEvent = cast selected; - eventsGroup.remove(event, true); + eventsGroup.remove(event); event.kill(); } @@ -798,11 +815,12 @@ class Charter extends UIState { notesGroup.autoSort = false; selection.loop(function (n:CharterNote) { - notesGroup.add(n); + n.strumLine = strumLines.members[n.strumLineID]; n.revive(); + notesGroup.add(n); }, function (e:CharterEvent) { - eventsGroup.add(e); e.revive(); + eventsGroup.add(e); e.refreshEventIcons(); }, false); notesGroup.sortNotes(); @@ -1023,7 +1041,6 @@ class Charter extends UIState { vocals.pause(); for (strumLine in strumLines.members) strumLine.vocals.pause(); } - __lastPos = Conductor.songPosition; songPosInfo.text = '${CoolUtil.timeToStr(Conductor.songPosition)} / ${CoolUtil.timeToStr(songLength)}' + '\nStep: ${curStep}' @@ -1077,7 +1094,7 @@ class Charter extends UIState { #if REGION function _file_exit(_) { if (undos.unsaved) SaveWarning.triggerWarning(); - else FlxG.switchState(new CharterSelection()); + else {undos = null; FlxG.switchState(new CharterSelection());} } function _file_save(_) { @@ -1180,6 +1197,7 @@ class Charter extends UIState { selection = []; var undo = undos.undo(); + trace(undo); switch(undo) { case null: // do nothing case CDeleteStrumLine(strumLineID, strumLine): @@ -1201,7 +1219,7 @@ class Charter extends UIState { for (s in selectionDrags) if (s.selectable.draggable) s.selectable.handleDrag(s.change * -1); - this.selection = [for (s in selectionDrags) s.selectable]; + selection = [for (s in selectionDrags) s.selectable]; case CEditSustains(changes): for(n in changes) n.note.updatePos(n.note.step, n.note.id, n.before, n.note.type); @@ -1527,6 +1545,7 @@ class Charter extends UIState { s.strumLine.notes = []; PlayState.SONG.strumLines.push(s.strumLine); } + notesGroup.sortNotes(); for(n in notesGroup.members) { if (PlayState.SONG.strumLines[n.strumLineID] != null) PlayState.SONG.strumLines[n.strumLineID].notes.push(buildNote(n)); @@ -1556,6 +1575,101 @@ class Charter extends UIState { public inline function hitsoundsEnabled(id:Int) return strumLines.members[id] != null && strumLines.members[id].hitsounds; + + // UH OH!!! DANGER ZONE APPOARCHING !!!! LUNARS SHITTY CODE !!!! -lunar + + @:noCompletion public function __fixSingleSelection(selectable:ICharterSelectable):ICharterSelectable { + if (selectable is CharterNote) + return selectable.ID == -1 ? cast(selectable, CharterNote) : notesGroup.members[selectable.ID]; + else if (selectable is CharterEvent) + return selectable.ID == -1 ? cast(selectable, CharterEvent) : eventsGroup.members[selectable.ID]; + return null; + } + + @:noCompletion public function __fixSelection(selection:Selection) @:privateAccess { + var newSelection:Selection = new Selection(); + for (i => selectable in selection) + newSelection[i] = __fixSingleSelection(selectable); + return newSelection; + } + + @:noCompletion public inline function __relinkSelection() + selection = __fixSelection(selection); + + @:noCompletion public inline function __relinkUndos() { + for (list => changeList in [undos.undoList, undos.redoList]) { + var newChanges:Array = []; + for (i => change in changeList) { + switch (change) { + case CCreateSelection(selection): + newChanges[i] = CCreateSelection(__fixSelection(selection)); + case CDeleteSelection(selection): + newChanges[i] = CDeleteSelection(__fixSelection(selection)); + case CSelectionDrag(selectionDrags): + newChanges[i] = CSelectionDrag([ + for (selectionDrag in selectionDrags) + { + selectable: __fixSingleSelection(selectionDrag.selectable), + change: selectionDrag.change + } + ]); + case CEditSustains(noteChanges): + newChanges[i] = CEditSustains([ + for (noteChange in noteChanges) + { + note: cast(__fixSingleSelection(noteChange.note), CharterNote), + before: noteChange.before, + after: noteChange.after + } + ]); + case CEditEvent(event, oldEvents, newEvents): + newChanges[i] = CEditEvent(cast(__fixSingleSelection(event), CharterEvent), oldEvents, newEvents); + case CEditSpecNotesType(notesChanged, oldNoteTypes, newNoteTypes): + newChanges[i] = CEditSpecNotesType([ + for (noteChanged in notesChanged) + cast(__fixSingleSelection(noteChanged), CharterNote) + ], oldNoteTypes, newNoteTypes); + default: newChanges[i] = change; + } + } + + if (list == 0) undos.undoList = newChanges; + else undos.redoList = newChanges; + } + } + + @:noCompletion public function __resetStatics() { + selection = new Selection(); + undos = new UndoList(); + clipboard = []; playtestInfo = null; + } + + @:noCompletion public function __updatePlaytestInfo() { + playtestInfo = { + songPosition: Conductor.songPosition, + playbackSpeed: playBackSlider.value, + quantSelected: quant, + noteTypeSelected: noteType, + strumlinesDraggable: strumLines.draggable, + hitSounds: [for (strumLine in strumLines.members) strumLine.hitsounds], + mutedVocals: [for (strumLine in strumLines.members) !(strumLine.vocals.volume > 0)], + } + } + + @:noCompletion public function __applyPlaytestInfo() { + if (playtestInfo == null) return; + + Conductor.songPosition = playtestInfo.songPosition; + playBackSlider.value = playtestInfo.playbackSpeed; + quant = playtestInfo.quantSelected; + noteType = playtestInfo.noteTypeSelected; + strumLines.draggable = playtestInfo.strumlinesDraggable; + + for (i => strumLine in strumLines.members) + strumLine.hitsounds = playtestInfo.hitSounds[i]; + for (i => strumLine in strumLines.members) + strumLine.vocals.volume = playtestInfo.mutedVocals[i] ? 0 : 1; + } } enum CharterChange { @@ -1607,6 +1721,7 @@ typedef SelectionDragChange = { interface ICharterSelectable { public var x(default, set):Float; public var y(default, set):Float; + public var ID:Int; public var step:Float; public var selected:Bool; @@ -1623,3 +1738,13 @@ enum abstract CharterGridActionType(Int) { var DRAG = 2; var INVALID_DRAG = 3; } + +typedef PlaytestInfo = { + var songPosition:Float; + var playbackSpeed:Float; + var quantSelected:Int; + var noteTypeSelected:Int; + var strumlinesDraggable:Bool; + var hitSounds:Array; + var mutedVocals:Array; +} \ No newline at end of file diff --git a/source/funkin/editors/charter/CharterEventGroup.hx b/source/funkin/editors/charter/CharterEventGroup.hx index 5022b3a47..aab06d18e 100644 --- a/source/funkin/editors/charter/CharterEventGroup.hx +++ b/source/funkin/editors/charter/CharterEventGroup.hx @@ -5,16 +5,23 @@ import flixel.util.FlxSort; class CharterEventGroup extends FlxTypedGroup { public var eventsBackdrop:EventBackdrop; + + public var autoSort:Bool = true; var __lastSort:Int = 0; public override function update(elapsed:Float) { filterEvents(); - if (length != __lastSort) + if (autoSort && members.length != __lastSort) sortEvents(); super.update(elapsed); } + public override function remove(v:CharterEvent, force:Bool = true):CharterEvent { + v.ID = -1; + return super.remove(v, force); + } + public override function draw() { for (event in members) { event.eventsBackdrop = eventsBackdrop; @@ -24,12 +31,16 @@ class CharterEventGroup extends FlxTypedGroup { } public inline function sortEvents() { - __lastSort = length; + __lastSort = members.length; this.sort(function(i, e1, e2) { return FlxSort.byValues(FlxSort.ASCENDING, e1.step, e2.step); }); + updateEventsIDs(); } + public inline function updateEventsIDs() + for (i => n in members) n.ID = i; + public inline function filterEvents() { for (event in members) if (event.events.length == 0) { diff --git a/source/funkin/editors/charter/CharterEventScreen.hx b/source/funkin/editors/charter/CharterEventScreen.hx index d8bce3060..5dc3ca8ec 100644 --- a/source/funkin/editors/charter/CharterEventScreen.hx +++ b/source/funkin/editors/charter/CharterEventScreen.hx @@ -80,7 +80,7 @@ class CharterEventScreen extends UISubstateWindow { chartEvent.events = [for (i in eventsList.buttons.members) i.event]; chartEvent.refreshEventIcons(); - Charter.instance.undos.addToUndo(CEditEvent(chartEvent, oldEvents, [for (event in events) Reflect.copy(event)])); + Charter.undos.addToUndo(CEditEvent(chartEvent, oldEvents, [for (event in events) Reflect.copy(event)])); } } diff --git a/source/funkin/editors/charter/CharterNote.hx b/source/funkin/editors/charter/CharterNote.hx index c710e268d..ffd40bd80 100644 --- a/source/funkin/editors/charter/CharterNote.hx +++ b/source/funkin/editors/charter/CharterNote.hx @@ -27,7 +27,8 @@ class CharterNote extends UISprite implements ICharterSelectable { public function new() { super(); - antialiasing = true; + + antialiasing = true; ID = -1; loadGraphic(Paths.image('editors/charter/note'), true, 157, 154); animation.add("note", [for(i in 0...frames.frames.length) i], 0, true); animation.play("note"); @@ -58,9 +59,9 @@ class CharterNote extends UISprite implements ICharterSelectable { public var type:Int; public var strumLine:CharterStrumline; - public var strumLineID(get, never):Int; + public var strumLineID(get, default):Int = -1; public function get_strumLineID():Int - return strumLine == null ? -1 : Charter.instance.strumLines.members.indexOf(strumLine); + return strumLineID = (strumLine == null ? strumLineID : Charter.instance.strumLines.members.indexOf(strumLine)); public var snappedToStrumline:Bool = true; diff --git a/source/funkin/editors/charter/CharterNoteGroup.hx b/source/funkin/editors/charter/CharterNoteGroup.hx index 0cfebeb9c..78995dca9 100644 --- a/source/funkin/editors/charter/CharterNoteGroup.hx +++ b/source/funkin/editors/charter/CharterNoteGroup.hx @@ -29,10 +29,10 @@ class CharterNoteGroup extends FlxTypedGroup { for(i in begin...end) { __loopSprite = members[i]; - if (!Charter.instance.selection.contains(__loopSprite)) + if (!Charter.selection.contains(__loopSprite)) noteFunc(__loopSprite); } - for(c in Charter.instance.selection.copy()) + for(c in Charter.selection.copy()) if (c is CharterNote) noteFunc(cast (c, CharterNote)); __currentlyLooping = oldCur; @@ -43,8 +43,10 @@ class CharterNoteGroup extends FlxTypedGroup { return v; } - public override function remove(v:CharterNote, force:Bool = true):CharterNote + public override function remove(v:CharterNote, force:Bool = true):CharterNote { + v.ID = -1; return super.remove(v, true); + } private static function getVar(n:CharterNote) return n.step; @@ -56,30 +58,36 @@ class CharterNoteGroup extends FlxTypedGroup { public override function draw() {} - public override function update(elapsed:Float) { - @:privateAccess var oldDefaultCameras = FlxCamera._defaultCameras; - @:privateAccess if (cameras != null) FlxCamera._defaultCameras = cameras; + public override function update(elapsed:Float) @:privateAccess { + var oldDefaultCameras = FlxCamera._defaultCameras; + if (cameras != null) FlxCamera._defaultCameras = cameras; - if (length != __lastSort && autoSort) + if (autoSort && members.length != __lastSort) sortNotes(); forEach((n) -> { - if(n.exists && n.active) + if(n.exists && n.active) { + n.cameras = n.__lastDrawCameras = cameras; n.update(elapsed); + } }); - @:privateAccess FlxCamera._defaultCameras = oldDefaultCameras; + FlxCamera._defaultCameras = oldDefaultCameras; } public function sortNotes() { - __lastSort = length; + __lastSort = members.length; this.sort(function(i, n1, n2) { if (n1.step == n2.step) return FlxSort.byValues(FlxSort.ASCENDING, n1.fullID, n2.fullID); return FlxSort.byValues(FlxSort.ASCENDING, n1.step, n2.step); }); + updateNoteIDs(); } + public inline function updateNoteIDs() + for (i => n in members) n.ID = i; + public inline function preallocate(len:Int) { members = cast new haxe.ds.Vector(len); length = len; diff --git a/source/funkin/editors/charter/CharterNoteTypesList.hx b/source/funkin/editors/charter/CharterNoteTypesList.hx index bf61c2dc5..7eb3abce3 100644 --- a/source/funkin/editors/charter/CharterNoteTypesList.hx +++ b/source/funkin/editors/charter/CharterNoteTypesList.hx @@ -57,15 +57,14 @@ class CharterNoteTypesList extends UISubstateWindow { return list; } - public function saveList() - { + public function saveList() { var oldList:Array = Charter.instance.noteTypes; var newList:Array = [for (note in noteTypesList.buttons.members) note.textBox.label.text]; Charter.instance.noteTypes = newList; Charter.instance.changeNoteType(null, false); - Charter.instance.undos.addToUndo(CEditNoteTypes(oldList, newList)); + Charter.undos.addToUndo(CEditNoteTypes(oldList, newList)); } } diff --git a/source/funkin/editors/charter/CharterStrumLineGroup.hx b/source/funkin/editors/charter/CharterStrumLineGroup.hx index c4c3c17ce..3018300c5 100644 --- a/source/funkin/editors/charter/CharterStrumLineGroup.hx +++ b/source/funkin/editors/charter/CharterStrumLineGroup.hx @@ -73,7 +73,7 @@ class CharterStrumLineGroup extends FlxTypedGroup { if (addToUndo) { var oldID = __pastStrumlines.indexOf(draggingObj); var newID = members.indexOf(draggingObj); - if (newID != oldID) Charter.instance.undos.addToUndo(COrderStrumLine(newID, oldID, newID)); + if (newID != oldID) Charter.undos.addToUndo(COrderStrumLine(newID, oldID, newID)); } draggingObj = null;