From f36d2311bd5d5e6ba5687f0f104ab66c6662a037 Mon Sep 17 00:00:00 2001 From: TheZoroForce240 <86524550+TheZoroForce240@users.noreply.github.com> Date: Fri, 23 Aug 2024 14:55:13 +0100 Subject: [PATCH] caching totalKeyCount and startingID --- source/funkin/editors/charter/Charter.hx | 5 +++++ .../editors/charter/CharterStrumLineGroup.hx | 14 +++++++++++++- source/funkin/editors/charter/CharterStrumline.hx | 7 +++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index d2427204..1e4adff3 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -1060,6 +1060,7 @@ class Charter extends UIState { public function createStrumline(strumLineID:Int, strL:ChartStrumLine, addToUndo:Bool = true, ?__createNotes:Bool = true) { var cStr = new CharterStrumline(strL); strumLines.insert(strumLineID, cStr); + strumLines.refreshStrumlineIDs(); strumLines.snapStrums(); if (__createNotes) { @@ -1093,6 +1094,7 @@ class Charter extends UIState { var strL = strumLines.members[strumLineID].strumLine; strumLines.members[strumLineID].destroy(); strumLines.members.remove(strumLines.members[strumLineID]); + strumLines.refreshStrumlineIDs(); strumLines.snapStrums(); if (addToUndo) { @@ -1132,6 +1134,7 @@ class Charter extends UIState { FlxG.state.openSubState(new CharterStrumlineScreen(strID, strL, (_) -> { strumLines.members[strID].strumLine = _; strumLines.members[strID].updateInfo(); + strumLines.refreshStrumlineIDs(); undos.addToUndo(CEditStrumLine(strID, oldData, _)); @@ -1465,6 +1468,7 @@ class Charter extends UIState { case CEditStrumLine(strumLineID, oldStrumLine, newStrumLine): strumLines.members[strumLineID].strumLine = oldStrumLine; strumLines.members[strumLineID].updateInfo(); + strumLines.refreshStrumlineIDs(); case CCreateSelection(selection): deleteSelection(selection, false); case CDeleteSelection(selection): @@ -1511,6 +1515,7 @@ class Charter extends UIState { case CEditStrumLine(strumLineID, oldStrumLine, newStrumLine): strumLines.members[strumLineID].strumLine = newStrumLine; strumLines.members[strumLineID].updateInfo(); + strumLines.refreshStrumlineIDs(); case CCreateSelection(selection): createSelection(selection, false); case CDeleteSelection(selection): diff --git a/source/funkin/editors/charter/CharterStrumLineGroup.hx b/source/funkin/editors/charter/CharterStrumLineGroup.hx index 83e2e638..67e27b8a 100644 --- a/source/funkin/editors/charter/CharterStrumLineGroup.hx +++ b/source/funkin/editors/charter/CharterStrumLineGroup.hx @@ -9,10 +9,13 @@ class CharterStrumLineGroup extends FlxTypedGroup { var draggingOffset:Float = 0; public var totalKeyCount(get, never):Int; + private var __totalKeyCount:Int = -1; public function get_totalKeyCount():Int { + if (__totalKeyCount != -1) return __totalKeyCount; + var v:Int = 0; for (strumLine in members) v += strumLine.keyCount; - return v; + return __totalKeyCount = v; } public var draggable:Bool = false; @@ -40,6 +43,7 @@ class CharterStrumLineGroup extends FlxTypedGroup { if (isDragging) { draggingObj.x = __mousePos.x - draggingOffset; this.sort(function(o, a, b) return FlxSort.byValues(o, a.x, b.x), -1); + refreshStrumlineIDs(); } for (i=>strum in members) @@ -69,6 +73,7 @@ class CharterStrumLineGroup extends FlxTypedGroup { members.remove(strumLine); members.insert(newID, strumLine); + refreshStrumlineIDs(); finishDrag(false); } @@ -85,6 +90,7 @@ class CharterStrumLineGroup extends FlxTypedGroup { draggingObj = null; fixEvents(); + refreshStrumlineIDs(); } public inline function fixEvents() { @@ -100,6 +106,12 @@ class CharterStrumLineGroup extends FlxTypedGroup { __pastStrumlines = null; } + public inline function refreshStrumlineIDs() { + __totalKeyCount = -1; + @:privateAccess + for (strumLine in members) strumLine.__startingID = -1; + } + public function getStrumlineFromID(id:Int) { var v:Int = 0; for (strumLine in members) { diff --git a/source/funkin/editors/charter/CharterStrumline.hx b/source/funkin/editors/charter/CharterStrumline.hx index 7b757add..58dcd9be 100644 --- a/source/funkin/editors/charter/CharterStrumline.hx +++ b/source/funkin/editors/charter/CharterStrumline.hx @@ -25,13 +25,16 @@ class CharterStrumline extends UISprite { public var keyCount:Int = 4; public var startingID(get, null):Int; + private var __startingID:Int = -1; public function get_startingID():Int { + if (__startingID != -1) return __startingID; + var index = Charter.instance.strumLines.members.indexOf(this); - if (index < 1) return 0; //-1 or 0 + if (index < 1) return __startingID = 0; //-1 or 0 var v:Int = 0; for (i in 0...index) v += Charter.instance.strumLines.members[i].keyCount; - return v; + return __startingID = v; } public var selectedWaveform(default, set):Int = -1;