From 33a50092acfe4b12bd78bdde81766735291c6ef0 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Wed, 2 Oct 2024 22:05:45 +0200 Subject: [PATCH 01/16] Show selected mod --- source/funkin/menus/ModSwitchMenu.hx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/funkin/menus/ModSwitchMenu.hx b/source/funkin/menus/ModSwitchMenu.hx index eb14ddcd..4746b565 100644 --- a/source/funkin/menus/ModSwitchMenu.hx +++ b/source/funkin/menus/ModSwitchMenu.hx @@ -2,6 +2,7 @@ package funkin.menus; #if MOD_SUPPORT import flixel.tweens.FlxTween; +import flixel.util.FlxColor; import funkin.backend.assets.ModsFolder; import haxe.io.Path; import sys.FileSystem; @@ -28,6 +29,8 @@ class ModSwitchMenu extends MusicBeatSubstate { alphabets = new FlxTypedGroup(); for(mod in mods) { var a = new Alphabet(0, 0, mod == null ? "DISABLE MODS" : mod, true); + if(mod == ModsFolder.currentModFolder) + a.color = FlxColor.LIME; a.isMenuItem = true; a.scrollFactor.set(); alphabets.add(a); From fc5daea6b184c9b6656c2eff96bdd1fd2568b420 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Wed, 2 Oct 2024 22:51:13 +0200 Subject: [PATCH 02/16] Add Array and Array and Float to flags macro --- source/funkin/backend/system/macros/FlagMacro.macro.hx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/funkin/backend/system/macros/FlagMacro.macro.hx b/source/funkin/backend/system/macros/FlagMacro.macro.hx index 477512c0..4cfb49bc 100644 --- a/source/funkin/backend/system/macros/FlagMacro.macro.hx +++ b/source/funkin/backend/system/macros/FlagMacro.macro.hx @@ -52,6 +52,10 @@ class FlagMacro { parser = macro value.split(",").map((e) -> e.trim()); case macro: Array: parser = macro value.split(","); + case macro: Array: + parser = macro value.split(",").map((e) -> Std.parseInt(e)); + case macro: Array: + parser = macro value.split(",").map((e) -> Std.parseFloat(e)); case macro: Array: parser = macro value.split(",").map((e) -> { e = e.trim(); @@ -59,6 +63,8 @@ class FlagMacro { }); case macro: Int: parser = macro Std.parseInt(value); + case macro: Float: + parser = macro Std.parseFloat(value); case macro: String: parser = macro value; case macro: Bool: From ab8c509cdee371395789392ef523fcdc7d6af037 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Wed, 2 Oct 2024 22:52:45 +0200 Subject: [PATCH 03/16] Update the support message --- source/funkin/backend/system/macros/FlagMacro.macro.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/funkin/backend/system/macros/FlagMacro.macro.hx b/source/funkin/backend/system/macros/FlagMacro.macro.hx index 4cfb49bc..3f827d7b 100644 --- a/source/funkin/backend/system/macros/FlagMacro.macro.hx +++ b/source/funkin/backend/system/macros/FlagMacro.macro.hx @@ -151,7 +151,7 @@ class FlagMacro { case TPath({name: "Map", pack: []}): Context.error("Flag " + field.name + " cannot be a Map", field.pos); default: - Context.error("Flag " + field.name + " must be either a Bool, Int, String, Array, Array or Array", field.pos); + Context.error("Flag " + field.name + " must be either a Bool, Int, Float, String, Array, Array, Array, Array or Array", field.pos); } if(parser == null) { From f2ec8da540626f427e687876532e0dee3f8c515c Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Thu, 3 Oct 2024 00:37:35 +0200 Subject: [PATCH 04/16] Small change to flags --- source/funkin/backend/system/Flags.hx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/source/funkin/backend/system/Flags.hx b/source/funkin/backend/system/Flags.hx index fed62113..25d13ebf 100644 --- a/source/funkin/backend/system/Flags.hx +++ b/source/funkin/backend/system/Flags.hx @@ -30,9 +30,9 @@ class Flags { var splitContent = [for(e in data.split("\n")) if ((trimmed = e.trim()) != "") trimmed]; for(line in splitContent) { - if (line.startsWith(";")) continue; - if (line.startsWith("#")) continue; - if (line.startsWith("//")) continue; + if(line.startsWith(";")) continue; + if(line.startsWith("#")) continue; + if(line.startsWith("//")) continue; if(line.length == 0) continue; if(line.charAt(0) == "[" && line.charAt(line.length-1) == "]") continue; @@ -41,10 +41,9 @@ class Flags { var name = line.substr(0, index).trim(); var value = line.substr(index+1).trim(); - if (value.length > 1 && value.charCodeAt(0) == '"'.code && value.charCodeAt(value.length-1) == '"'.code) - value = value.substr(1, value.length - 2); - - if (value.length == 0 || name.length == 0) + var wasQuoted = value.length > 1 && value.charCodeAt(0) == '"'.code && value.charCodeAt(value.length-1) == '"'.code; + if(wasQuoted) value = value.substr(1, value.length - 2); + if((!wasQuoted && value.length == 0) || name.length == 0) continue; if(!flags.exists(name)) From fa899bdd02380e31c681ea6e99597ab8d9586bfd Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Fri, 4 Oct 2024 17:59:21 +0200 Subject: [PATCH 05/16] Small fix <3 --- source/funkin/menus/TitleState.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/funkin/menus/TitleState.hx b/source/funkin/menus/TitleState.hx index edf5dd26..e1245a1e 100644 --- a/source/funkin/menus/TitleState.hx +++ b/source/funkin/menus/TitleState.hx @@ -355,7 +355,7 @@ class IntroText { for(e in lines) { if (e is String) { var text = cast(e, String); - for(k=>e in state.curWacky) text = text.replace('{introText${k+1}', e); + for(k=>e in state.curWacky) text = text.replace('{introText${k+1}}', e); state.addMoreText(text); } else if (e is Dynamic) { var image:TitleStateImage = e; From 2c52720244a6b30a166d601185bf589ad12a0a15 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Mon, 7 Oct 2024 00:10:43 +0200 Subject: [PATCH 06/16] Added getAnim and isAnimAtEnd --- source/funkin/backend/FunkinSprite.hx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/source/funkin/backend/FunkinSprite.hx b/source/funkin/backend/FunkinSprite.hx index d18585ae..fa79a95b 100644 --- a/source/funkin/backend/FunkinSprite.hx +++ b/source/funkin/backend/FunkinSprite.hx @@ -1,5 +1,7 @@ package funkin.backend; +import flixel.animation.FlxAnimation; +import flxanimate.animate.FlxAnim.FlxSymbolAnimation; import funkin.backend.utils.XMLUtil.BeatAnim; import funkin.backend.utils.XMLUtil.AnimData; import funkin.backend.utils.XMLUtil.IXMLEvents; @@ -11,6 +13,7 @@ import funkin.backend.system.interfaces.IOffsetCompatible; import flixel.math.FlxMatrix; import flixel.math.FlxRect; import flixel.math.FlxPoint; +import flixel.util.typeLimit.OneOfTwo; import funkin.backend.system.interfaces.IBeatReceiver; enum abstract XMLAnimType(Int) @@ -325,6 +328,12 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I lastAnimContext = Context; } + public function getAnim(name:String):OneOfTwo { + if(animateAtlas != null) + return animateAtlas.anim.getByName(name); + return animation.getByName(name); + } + public inline function getAnimOffset(name:String) { if (animOffsets.exists(name)) @@ -378,7 +387,11 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I public inline function isAnimFinished() { - return animateAtlas != null ? (animateAtlas.anim.finished) : (animation.curAnim != null ? animation.curAnim.finished : true); + return animateAtlas != null ? animateAtlas.anim.finished : (animation.curAnim != null ? animation.curAnim.finished : true); + } + + public inline function isAnimAtEnd() { + return animateAtlas != null ? animateAtlas.anim.isAtEnd : (animation.curAnim != null ? animation.curAnim.isAtEnd : false); } #end From 620650bb81d0e314228ff863cd0edd15af37efe1 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Mon, 7 Oct 2024 00:59:54 +0200 Subject: [PATCH 07/16] Allow introLength = 0 --- source/funkin/game/PlayState.hx | 16 ++++++++-------- source/funkin/game/StrumLine.hx | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index 4e125724..77e39ca9 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -865,12 +865,12 @@ class PlayState extends MusicBeatState Conductor.songPosition = 0; Conductor.songPosition -= Conductor.crochet * introLength - Conductor.songOffset; - var swagCounter:Int = 0; - - startTimer = new FlxTimer().start(Conductor.crochet / 1000, function(tmr:FlxTimer) - { - countdown(swagCounter++); - }, introLength); + if(introLength > 0) { + var swagCounter:Int = 0; + startTimer = new FlxTimer().start(Conductor.crochet / 1000, (tmr:FlxTimer) -> { + countdown(swagCounter++); + }, introLength); + } scripts.call("onPostStartCountdown"); } @@ -1047,7 +1047,7 @@ class PlayState extends MusicBeatState vocals.pause(); } - if (!startTimer.finished) + if (startTimer != null && !startTimer.finished) startTimer.active = false; } @@ -1067,7 +1067,7 @@ class PlayState extends MusicBeatState resyncVocals(); } - if (!startTimer.finished) + if (startTimer != null && !startTimer.finished) startTimer.active = true; paused = false; diff --git a/source/funkin/game/StrumLine.hx b/source/funkin/game/StrumLine.hx index 17650a5a..3e88bc7c 100644 --- a/source/funkin/game/StrumLine.hx +++ b/source/funkin/game/StrumLine.hx @@ -309,7 +309,7 @@ class StrumLine extends FlxTypedGroup { babyArrow.scrollSpeed = data.scrollSpeed; var event = EventManager.get(StrumCreationEvent).recycle(babyArrow, PlayState.instance.strumLines.members.indexOf(this), i, animPrefix); - event.__doAnimation = !MusicBeatState.skipTransIn; + event.__doAnimation = !MusicBeatState.skipTransIn && (PlayState.instance != null ? PlayState.instance.introLength > 0 : true); event = PlayState.instance.scripts.event("onStrumCreation", event); if (!event.cancelled) { From a8860604e8a6d14d2781dda94bf14387e18c58e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:51:40 +0200 Subject: [PATCH 08/16] mods dialogues fonts fix --- source/funkin/backend/assets/Paths.hx | 15 +++++++++++++-- source/funkin/backend/utils/CoolUtil.hx | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/source/funkin/backend/assets/Paths.hx b/source/funkin/backend/assets/Paths.hx index d8c6ba39..1bc880ff 100644 --- a/source/funkin/backend/assets/Paths.hx +++ b/source/funkin/backend/assets/Paths.hx @@ -116,17 +116,28 @@ class Paths return scriptPath; } - static public function chart(song:String, ?difficulty:String = "normal"):String { + static public function chart(song:String, ?difficulty:String = "normal"):String + { difficulty = difficulty.toLowerCase(); song = song.toLowerCase(); return getPath('songs/$song/charts/$difficulty.json', null); } - static public function character(character:String):String { + inline static public function character(character:String):String + { return getPath('data/characters/$character.xml', null); } + /** + * Gets the name of a registered font. + * @param font The font's path (if it's already passed as a font name, the same name will be returned) + */ + inline static public function getFontName(font:String) + { + return OpenFlAssets.exists(font, FONT) ? OpenFlAssets.getFont(font).fontName : font; + } + inline static public function font(key:String) { return getPath('fonts/$key'); diff --git a/source/funkin/backend/utils/CoolUtil.hx b/source/funkin/backend/utils/CoolUtil.hx index 70feb55f..9fd7f3c5 100644 --- a/source/funkin/backend/utils/CoolUtil.hx +++ b/source/funkin/backend/utils/CoolUtil.hx @@ -582,7 +582,7 @@ class CoolUtil var fmt = new FlxTextFormat(); fmt.format.color = Reflect.hasField(fmtt, "color") ? FlxColor.fromString(fmtt.color) : text.color; - fmt.format.font = Reflect.hasField(fmtt, "font") ? Paths.font(fmtt.font) : text.font; + fmt.format.font = Reflect.hasField(fmtt, "font") ? Paths.getFontName(Paths.font(fmtt.font)) : text.font; fmt.format.size = Reflect.hasField(fmtt, "size") ? Std.parseInt(fmtt.size) : text.size; fmt.format.italic = Reflect.hasField(fmtt, "italic") ? fmtt.italic == "true" : text.italic; fmt.format.bold = Reflect.hasField(fmtt, "bold") ? fmtt.bold == "true" : text.bold; From 9504495eabcfa755dc0696671fd40ebb5c5d60d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Tue, 8 Oct 2024 22:33:42 +0200 Subject: [PATCH 09/16] fix credits desc text with purple formats staying --- source/funkin/menus/credits/CreditsCodename.hx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/funkin/menus/credits/CreditsCodename.hx b/source/funkin/menus/credits/CreditsCodename.hx index 579360ed..2ea401ea 100644 --- a/source/funkin/menus/credits/CreditsCodename.hx +++ b/source/funkin/menus/credits/CreditsCodename.hx @@ -64,6 +64,11 @@ class CreditsCodename extends funkin.options.OptionsScreen { ]); } + override function close() { + super.close(); + parent.treeParent.pathDesc.clearFormats(); + } + public function checkUpdate():Bool { var curTime:Float = Date.now().getTime(); if(Options.lastUpdated != null && curTime < Options.lastUpdated + 120000) return false; // Fuck you Github rate limits - Nex From 2b81220c15ed77acecd17c09a975ed401677165f Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Thu, 10 Oct 2024 22:36:33 +0200 Subject: [PATCH 10/16] Shorthand for boyfriend --- source/funkin/game/PlayState.hx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index d793a7a9..cd5d2d2f 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -160,6 +160,11 @@ class PlayState extends MusicBeatState * Boyfriend character */ public var boyfriend(get, set):Character; + /** + * Boyfriend character + * Same as boyfriend, just shorter + **/ + public var bf(get, set):Character; /** * Strum line position @@ -1852,6 +1857,16 @@ class PlayState extends MusicBeatState strumLines.members[1].characters = [bf]; return bf; } + private function set_bf(bf:Character):Character { + if (strumLines != null && strumLines.members[1] != null) + strumLines.members[1].characters = [bf]; + return bf; + } + private function get_bf():Character { + if (strumLines != null && strumLines.members[1] != null) + return strumLines.members[1].characters[0]; + return null; + } private function get_dad():Character { if (strumLines != null && strumLines.members[0] != null) return strumLines.members[0].characters[0]; From 8c539b54bf8d3b3a1741d3391d538723a88d4237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Mon, 14 Oct 2024 16:57:01 +0200 Subject: [PATCH 11/16] better dynamic fix --- source/funkin/menus/credits/CreditsCodename.hx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/funkin/menus/credits/CreditsCodename.hx b/source/funkin/menus/credits/CreditsCodename.hx index 2ea401ea..e6c717c0 100644 --- a/source/funkin/menus/credits/CreditsCodename.hx +++ b/source/funkin/menus/credits/CreditsCodename.hx @@ -11,9 +11,11 @@ using StringTools; class CreditsCodename extends funkin.options.OptionsScreen { public var error:Bool = false; public var author:String = "FNF-CNE-Devs"; + public var totalContributions:Int = 0; + public var mainDevCol:FlxColor = 0xFF9C35D5; public var minContrCol:FlxColor = 0xFFB4A7DA; - public var totalContributions:Int = 0; + public var contribFormats:Array = []; public override function new() { @@ -58,7 +60,7 @@ class CreditsCodename extends funkin.options.OptionsScreen { if(parent == null || parent.treeParent == null) return; var text:String = parent.treeParent.pathDesc.text; parent.treeParent.pathDesc.text = ""; - parent.treeParent.pathDesc.applyMarkup(text, [ + parent.treeParent.pathDesc.applyMarkup(text, contribFormats = [ new FlxTextFormatMarkerPair(new FlxTextFormat(mainDevCol), '*'), new FlxTextFormatMarkerPair(new FlxTextFormat(FlxColor.interpolate(minContrCol, mainDevCol, Options.contributors[curSelected].contributions / totalContributions)), '~') ]); @@ -66,7 +68,7 @@ class CreditsCodename extends funkin.options.OptionsScreen { override function close() { super.close(); - parent.treeParent.pathDesc.clearFormats(); + for (frmt in contribFormats) parent.treeParent.pathDesc.removeFormat(frmt.format); } public function checkUpdate():Bool { From 0db00222ca23414f63ee448495a4daaed738d20d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Mon, 14 Oct 2024 17:52:29 +0200 Subject: [PATCH 12/16] e idk felt like --- assets/data/dialogue/characters/senpai.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/data/dialogue/characters/senpai.hx b/assets/data/dialogue/characters/senpai.hx index cd17b115..1ea774d7 100644 --- a/assets/data/dialogue/characters/senpai.hx +++ b/assets/data/dialogue/characters/senpai.hx @@ -1,6 +1,6 @@ function postHide() { if(curTween != null) { - if(animation.curAnim?.name == 'angry-show') curTween.cancel(); + if(getAnimName() == 'angry-show') curTween.cancel(); else curTween.percent = 1; } -} \ No newline at end of file +} From 682358c93a0c17469d1a481de0523e4c4e19c6ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Fri, 18 Oct 2024 01:17:09 +0200 Subject: [PATCH 13/16] characters xml events + script extensions too! Co-Authored-By: Ne_Eo --- .../scripting/events/CharacterNodeEvent.hx | 21 +++++ .../scripting/events/CharacterXMLEvent.hx | 16 ++++ .../backend/system/modules/AudioSwitchFix.hx | 1 + source/funkin/backend/utils/XMLUtil.hx | 48 ++++++++++ source/funkin/game/Character.hx | 87 ++++++++++++++----- source/funkin/game/Stage.hx | 54 ++---------- 6 files changed, 158 insertions(+), 69 deletions(-) create mode 100644 source/funkin/backend/scripting/events/CharacterNodeEvent.hx create mode 100644 source/funkin/backend/scripting/events/CharacterXMLEvent.hx diff --git a/source/funkin/backend/scripting/events/CharacterNodeEvent.hx b/source/funkin/backend/scripting/events/CharacterNodeEvent.hx new file mode 100644 index 00000000..9577a64f --- /dev/null +++ b/source/funkin/backend/scripting/events/CharacterNodeEvent.hx @@ -0,0 +1,21 @@ +package funkin.backend.scripting.events; + +import funkin.game.Character; +import haxe.xml.Access; + +final class CharacterNodeEvent extends CancellableEvent { + /** + * The character instance + */ + public var character:Character; + + /** + * The node which is currently being parsed + */ + public var node:Access; + + /** + * The name of the node, quicker access than e.node.name + */ + public var name:String; +} \ No newline at end of file diff --git a/source/funkin/backend/scripting/events/CharacterXMLEvent.hx b/source/funkin/backend/scripting/events/CharacterXMLEvent.hx new file mode 100644 index 00000000..e4f107fd --- /dev/null +++ b/source/funkin/backend/scripting/events/CharacterXMLEvent.hx @@ -0,0 +1,16 @@ +package funkin.backend.scripting.events; + +import funkin.game.Character; +import haxe.xml.Access; + +final class CharacterXMLEvent extends CancellableEvent { + /** + * The character instance + */ + public var character:Character; + + /** + * The xml + */ + public var xml:Access; +} \ No newline at end of file diff --git a/source/funkin/backend/system/modules/AudioSwitchFix.hx b/source/funkin/backend/system/modules/AudioSwitchFix.hx index db8360c1..5674660b 100644 --- a/source/funkin/backend/system/modules/AudioSwitchFix.hx +++ b/source/funkin/backend/system/modules/AudioSwitchFix.hx @@ -62,6 +62,7 @@ class AudioSwitchFix { } } +@:dox(hide) typedef PlayingSound = { var sound:FlxSound; var time:Float; diff --git a/source/funkin/backend/utils/XMLUtil.hx b/source/funkin/backend/utils/XMLUtil.hx index dc39244d..afb8ae04 100644 --- a/source/funkin/backend/utils/XMLUtil.hx +++ b/source/funkin/backend/utils/XMLUtil.hx @@ -6,6 +6,9 @@ import funkin.backend.system.ErrorCode; import funkin.backend.FunkinSprite.XMLAnimType; import flixel.util.FlxColor; import haxe.xml.Access; +import funkin.backend.scripting.Script; +import funkin.backend.scripting.DummyScript; +import funkin.backend.scripting.ScriptPack; import flixel.util.typeLimit.OneOfTwo; import funkin.backend.system.interfaces.IOffsetCompatible; @@ -326,6 +329,51 @@ class XMLUtil { } } +class XMLImportedScriptInfo { + public var path:String; + public var shortLived:Bool = false; + public var loadBefore:Bool = true; + public var importStageSprites:Bool = false; // maybe will change later?? - Nex + public var parentScriptPack:ScriptPack = null; + + public function new(path:String, parentScriptPack:ScriptPack) { + this.parentScriptPack = parentScriptPack; + this.path = path; + } + + public function getScript():Script + return parentScriptPack == null ? null : parentScriptPack.getByPath(path); + + public static function prepareInfos(node:Access, parentScriptPack:ScriptPack, ?onScriptPreLoad:XMLImportedScriptInfo->Void):XMLImportedScriptInfo { + if (!node.has.script || parentScriptPack == null) return null; + + var folder = node.getAtt("folder").getDefault("data/scripts/"); + if (!folder.endsWith("/")) folder += "/"; + + var path = Paths.script(folder + node.getAtt("script")); + var daScript = Script.create(path); + if (daScript is DummyScript) { + Logs.trace('Script Extension at ${path} does not exist.', ERROR); + return null; + } + + var infos = new XMLImportedScriptInfo(daScript.path, parentScriptPack); + infos.shortLived = node.getAtt("isShortLived") == "true" || node.getAtt("shortLived") == "true"; + infos.importStageSprites = node.getAtt("importStageSprites") == "true"; + @:privateAccess infos.loadBefore = shouldLoadBefore(node); + + if (onScriptPreLoad != null) onScriptPreLoad(infos); + parentScriptPack.add(daScript); + daScript.set("scriptInfo", infos); + daScript.load(); + + return infos; + } + + @:dox(hide) public static inline function shouldLoadBefore(node:Access):Bool + return node.getAtt("loadBefore") != "false"; +} + typedef AnimData = { var name:String; var anim:String; diff --git a/source/funkin/game/Character.hx b/source/funkin/game/Character.hx index ac13c820..b74bceca 100644 --- a/source/funkin/game/Character.hx +++ b/source/funkin/game/Character.hx @@ -8,6 +8,9 @@ import flixel.util.FlxColor; import funkin.backend.FunkinSprite; import funkin.backend.scripting.DummyScript; import funkin.backend.scripting.Script; +import funkin.backend.scripting.ScriptPack; +import funkin.backend.scripting.events.CharacterNodeEvent; +import funkin.backend.scripting.events.CharacterXMLEvent; import funkin.backend.scripting.events.DanceEvent; import funkin.backend.scripting.events.DirectionAnimEvent; import funkin.backend.scripting.events.PlayAnimEvent; @@ -44,8 +47,22 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset public var cameraOffset:FlxPoint = FlxPoint.get(0, 0); public var globalOffset:FlxPoint = FlxPoint.get(0, 0); - public var script:Script; public var xml:Access; + public var scripts:ScriptPack; + public var xmlImportedScripts:Array = []; + public var script(default, set):Script; + + public function prepareInfos(node:Access) + return XMLImportedScriptInfo.prepareInfos(node, scripts, (infos) -> xmlImportedScripts.push(infos)); + + // backward compat - Nex + private function set_script(script:Script):Script { + if (scripts == null) (scripts = new ScriptPack("Character")).setParent(this); + else scripts.remove(scripts.scripts[0]); + if(script != null) scripts.insert(0, script); + this.script = script; + return script; + } public var idleSuffix:String = ""; public var stunned(default, set):Bool = false; @@ -71,16 +88,15 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset script = Script.create(Paths.script(Path.withoutExtension(Paths.xml('characters/$curCharacter')), null, true)); else script = new DummyScript(curCharacter); - script.setParent(this); script.load(); buildCharacter(xml); - script.call("create"); + scripts.call("create"); if (script == null) script = new DummyScript(curCharacter); - script.call("postCreate"); + scripts.call("postCreate"); } @:noCompletion var __swappedLeftRightAnims:Bool = false; @@ -92,9 +108,9 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset __autoInterval = autoInterval; // character is flipped - if (isPlayer != playerOffsets && switchAnims) + if (isPlayer != playerOffsets && switchAnims) swapLeftRightAnimations(); - + frameOffset.set(getAnimOffset(getAnimName()).x, getAnimOffset(getAnimName()).y); if (isPlayer) flipX = !flipX; __baseFlipped = flipX; @@ -115,7 +131,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset override function update(elapsed:Float) { super.update(elapsed); - script.call("update", [elapsed]); + scripts.call("update", [elapsed]); if (stunned) { __stunnedTime += elapsed; if (__stunnedTime > 5 / 60) @@ -134,7 +150,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset if(debugMode) return; var event = EventManager.get(DanceEvent).recycle(danced); - script.call("onDance", [event]); + scripts.call("onDance", [event]); if (event.cancelled) return; if (isDanceLeftDanceRight) @@ -164,14 +180,14 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset */ public var danceOnBeat:Bool = true; public override function beatHit(curBeat:Int) { - script.call("beatHit", [curBeat]); + scripts.call("beatHit", [curBeat]); if (danceOnBeat && (curBeat + beatOffset) % beatInterval == 0 && !__lockAnimThisFrame) tryDance(); } public override function stepHit(curStep:Int) - script.call("stepHit", [curStep]); + scripts.call("stepHit", [curStep]); @:noCompletion var __reverseDrawProcedure:Bool = false; public override function getScreenBounds(?newRect:FlxRect, ?camera:FlxCamera):FlxRect { @@ -209,14 +225,14 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset public var singAnims = ["singLEFT", "singDOWN", "singUP", "singRIGHT"]; public function playSingAnim(direction:Int, suffix:String = "", Context:PlayAnimContext = SING, ?Force:Null = null, Reversed:Bool = false, Frame:Int = 0) { var event = EventManager.get(DirectionAnimEvent).recycle(singAnims[direction % singAnims.length] + suffix, direction, suffix, Context, Reversed, Frame, Force); - script.call("onPlaySingAnim", [event]); + scripts.call("onPlaySingAnim", [event]); if (!event.cancelled) playAnim(event.animName, event.force, event.context, event.reversed, event.frame); } public override function playAnim(AnimName:String, ?Force:Bool, Context:PlayAnimContext = NONE, Reversed:Bool = false, Frame:Int = 0) { var event = EventManager.get(PlayAnimEvent).recycle(AnimName, Force, Reversed, Frame, Context); - script.call("onPlayAnim", [event]); + scripts.call("onPlayAnim", [event]); if (event.cancelled) return; super.playAnim(event.animName, event.force, event.context, event.reverse, event.startingFrame); @@ -231,15 +247,15 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset var event = EventManager.get(PointEvent).recycle( midpoint.x + (isPlayer ? -100 : 150) + globalOffset.x + cameraOffset.x, midpoint.y - 100 + globalOffset.y + cameraOffset.y); - script.call("onGetCamPos", [event]); + scripts.call("onGetCamPos", [event]); midpoint.put(); return new FlxPoint(event.x, event.y); } public override function destroy() { - script.call('destroy'); - script.destroy(); + scripts.call('destroy'); + scripts.destroy(); super.destroy(); cameraOffset.put(); @@ -281,9 +297,18 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset } public inline function buildCharacter(xml:Access) { - this.xml = xml; // Modders wassup :D + for(node in xml.elements) + switch(node.name) { + case "use-extension" | "extension" | "ext": + if (!XMLImportedScriptInfo.shouldLoadBefore(node)) continue; + prepareInfos(node); + } + + xml = scripts.event("onCharacterXMLParsed", EventManager.get(CharacterXMLEvent).recycle(this, xml)).xml; + sprite = curCharacter; spriteAnimType = BEAT; + this.xml = xml; // Modders wassup :D if (xml.x.exists("isPlayer")) playerOffsets = (xml.x.get("isPlayer") == "true"); if (xml.x.exists("x")) globalOffset.x = Std.parseFloat(xml.x.get("x")); @@ -307,9 +332,19 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset if (hasInterval) beatInterval = Std.parseInt(xml.x.get("interval")); loadSprite(Paths.image('characters/$sprite')); + for(node in xml.elements) { + switch(node.name) { + case "anim": + XMLUtil.addXMLAnimation(this, node); + case "use-extension" | "extension" | "ext": + if (XMLImportedScriptInfo.shouldLoadBefore(node)) continue; + prepareInfos(node); + default: + // nothing + } - for (anim in xml.nodes.anim) - XMLUtil.addXMLAnimation(this, anim); + scripts.event("onCharacterNodeParsed", EventManager.get(CharacterNodeEvent).recycle(this, node, node.name)); + } for (attribute in xml.x.attributes()) if (!characterProperties.contains(attribute)) @@ -317,11 +352,19 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset fixChar(__switchAnims, !hasInterval); dance(); + + for (info in xmlImportedScripts) if (info.shortLived) { + var script = info.getScript(); + if (script == null) continue; + + scripts.remove(script); + script.destroy(); + } } public static var characterProperties:Array = [ - "x", "y", "sprite", "scale", "antialiasing", - "flipX", "camx", "camy", "isPlayer", "icon", + "x", "y", "sprite", "scale", "antialiasing", + "flipX", "camx", "camy", "isPlayer", "icon", "color", "gameOverChar", "holdTime" ]; public static var characterAnimProperties:Array = [ @@ -331,7 +374,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset public inline function buildXML(?animsOrder:Array):Xml { var xml:Xml = Xml.createElement("character"); xml.attributeOrder = characterProperties.copy(); - + if (globalOffset.x != 0) xml.set("x", Std.string(FlxMath.roundDecimal(globalOffset.x, 2))); if (globalOffset.y != 0) xml.set("y", Std.string(FlxMath.roundDecimal(globalOffset.y, 2))); @@ -436,7 +479,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset Logs.trace('Error while loading character ${character}: ${e}', ERROR); character = FALLBACK_CHARACTER; - if (char != null) + if (char != null) char.curCharacter = character; continue; } diff --git a/source/funkin/game/Stage.hx b/source/funkin/game/Stage.hx index 7687d897..9b3782ca 100644 --- a/source/funkin/game/Stage.hx +++ b/source/funkin/game/Stage.hx @@ -5,6 +5,7 @@ import funkin.backend.scripting.events.StageNodeEvent; import flixel.math.FlxPoint; import flixel.FlxState; import haxe.xml.Access; +import funkin.backend.utils.XMLUtil.XMLImportedScriptInfo; import funkin.backend.system.interfaces.IBeatReceiver; import funkin.backend.scripting.DummyScript; import funkin.backend.scripting.Script; @@ -30,6 +31,9 @@ class Stage extends FlxBasic implements IBeatReceiver { public function setStagesSprites(script:Script) for (k=>e in stageSprites) script.set(k, e); + public function prepareInfos(node:Access) + return XMLImportedScriptInfo.prepareInfos(node, PlayState.instance.scripts, (infos) -> xmlImportedScripts.push(infos)); + public function new(stage:String, ?state:FlxState) { super(); @@ -136,7 +140,7 @@ class Stage extends FlxBasic implements IBeatReceiver { PlayState.instance.add(PlayState.instance.comboGroup); PlayState.instance.comboGroup; case "use-extension" | "extension" | "ext": - if (__shouldLoadBefore(node) || XMLImportedScriptInfo.prepareInfos(node, this) == null) continue; + if (XMLImportedScriptInfo.shouldLoadBefore(node) || prepareInfos(node) == null) continue; null; default: null; } @@ -201,13 +205,10 @@ class Stage extends FlxBasic implements IBeatReceiver { @:dox(hide) private function __pushNcheckNode(array:Array, node:Access) { array.push(node); - if ((node.name == "use-extension" || node.name == "extension" || node.name == "ext") && __shouldLoadBefore(node)) - XMLImportedScriptInfo.prepareInfos(node, this); + if ((node.name == "use-extension" || node.name == "extension" || node.name == "ext") && XMLImportedScriptInfo.shouldLoadBefore(node)) + prepareInfos(node); } - @:dox(hide) private static inline function __shouldLoadBefore(node:Access):Bool - return node.getAtt("loadBefore") != "false"; - public function addCharPos(name:String, node:Access, ?nonXMLInfo:StageCharPosInfo):StageCharPos { var charPos = new StageCharPos(); charPos.visible = charPos.active = false; @@ -317,45 +318,4 @@ typedef StageCharPosInfo = { var y:Float; var flip:Bool; var scroll:Float; -} - -class XMLImportedScriptInfo { - public var path:String; - public var shortLived:Bool = false; - public var loadBefore:Bool = true; - public var importStageSprites:Bool = false; - - public function new(path:String) - this.path = path; - - public function getScript():Script - return PlayState.instance == null ? null : PlayState.instance.scripts.getByPath(path); - - public static function prepareInfos(node:Access, ?stage:Stage):XMLImportedScriptInfo { - if (!node.has.script || PlayState.instance == null) return null; - - var folder = node.getAtt("folder").getDefault("data/scripts/"); - if (!folder.endsWith("/")) folder += "/"; - - var path = Paths.script(folder + node.getAtt("script")); - var daScript = Script.create(path); - if (daScript is DummyScript) { - var msg = 'Script Extension at ${path} does not exist'; - if (stage != null) msg += ' through stage "${stage.stageName}"'; - Logs.trace(msg + ".", ERROR); - return null; - } - - var infos = new XMLImportedScriptInfo(daScript.path); - infos.shortLived = node.getAtt("isShortLived") == "true"; - infos.importStageSprites = node.getAtt("importStageSprites") == "true"; - @:privateAccess infos.loadBefore = Stage.__shouldLoadBefore(node); - - if (stage != null) stage.xmlImportedScripts.push(infos); - PlayState.instance.scripts.add(daScript); - daScript.set("scriptInfo", infos); - daScript.load(); - - return infos; - } } \ No newline at end of file From d197205cc526501887f290818dc63ff5d1382768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Fri, 18 Oct 2024 01:35:26 +0200 Subject: [PATCH 14/16] opaa Co-Authored-By: Ne_Eo --- source/funkin/game/Character.hx | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/source/funkin/game/Character.hx b/source/funkin/game/Character.hx index b74bceca..456dcae3 100644 --- a/source/funkin/game/Character.hx +++ b/source/funkin/game/Character.hx @@ -55,15 +55,6 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset public function prepareInfos(node:Access) return XMLImportedScriptInfo.prepareInfos(node, scripts, (infos) -> xmlImportedScripts.push(infos)); - // backward compat - Nex - private function set_script(script:Script):Script { - if (scripts == null) (scripts = new ScriptPack("Character")).setParent(this); - else scripts.remove(scripts.scripts[0]); - if(script != null) scripts.insert(0, script); - this.script = script; - return script; - } - public var idleSuffix:String = ""; public var stunned(default, set):Bool = false; @@ -443,6 +434,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset return stunned = b; } + // ---- Backwards compat ---- // Interval at which the character will dance (higher number = slower dance) @:noCompletion public var danceInterval(get, set):Int; @:noCompletion private function set_danceInterval(v:Int) @@ -450,6 +442,22 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset @:noCompletion private function get_danceInterval() return beatInterval; + private function set_script(script:Script):Script { + if (scripts == null) (scripts = new ScriptPack("Character")).setParent(this); + + var lastIndex = scripts.scripts.indexOf(this.script); + if(lastIndex >= 0) { + if(script == null) // last != null && new == null + scripts.scripts.splice(lastIndex, 1); + else // last != null && new != null + scripts.scripts[lastIndex] = script; + } else if(script != null) // last == null + scripts.insert(0, script); + + return this.script = script; + } + // ---- end of Backwards compat ---- + public static var FALLBACK_CHARACTER:String = "bf"; public static var FALLBACK_DEAD_CHARACTER:String = "bf-dead"; From 2bfc58ccb0851ca498173dc6b253073000895d73 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Fri, 18 Oct 2024 02:50:41 +0200 Subject: [PATCH 15/16] Some optimizations I wish there was a cleaner way of doing this --- source/flx3d/Flx3DCamera.hx | 2 +- source/flx3d/Flx3DView.hx | 2 +- source/funkin/backend/MusicBeatGroup.hx | 6 +-- source/funkin/backend/MusicBeatState.hx | 11 ++--- source/funkin/backend/MusicBeatSubstate.hx | 9 ++-- .../backend/scripting/MultiThreadedScript.hx | 4 +- source/funkin/backend/system/Conductor.hx | 8 +++- .../backend/system/framerate/SystemInfo.hx | 2 +- .../backend/system/modules/CrashHandler.hx | 4 +- source/funkin/backend/utils/MemoryUtil.hx | 21 --------- source/funkin/backend/utils/NativeAPI.hx | 4 +- source/funkin/backend/utils/XMLUtil.hx | 2 +- source/funkin/editors/charter/Charter.hx | 43 ++++++++++++------- source/funkin/editors/charter/CharterEvent.hx | 2 +- .../editors/charter/CharterNoteGroup.hx | 2 +- .../editors/charter/CharterNoteHoverer.hx | 2 +- source/funkin/editors/ui/UIFileExplorer.hx | 6 ++- source/funkin/editors/ui/UITopMenu.hx | 9 ++-- source/funkin/editors/ui/UIUtil.hx | 2 +- source/funkin/game/Character.hx | 2 +- source/funkin/game/Note.hx | 2 +- source/funkin/menus/ui/Alphabet.hx | 2 +- 22 files changed, 75 insertions(+), 72 deletions(-) diff --git a/source/flx3d/Flx3DCamera.hx b/source/flx3d/Flx3DCamera.hx index 4e1da93d..129ace5d 100644 --- a/source/flx3d/Flx3DCamera.hx +++ b/source/flx3d/Flx3DCamera.hx @@ -87,7 +87,7 @@ class Flx3DCamera extends FlxCamera { default: new OBJParser(); }, (event:Asset3DEvent) -> { if (event.asset != null && event.asset.assetType == Asset3DType.MESH) { - var mesh:Mesh = cast(event.asset, Mesh); + var mesh:Mesh = cast event.asset; if (material != null) mesh.material = material; meshes.push(mesh); diff --git a/source/flx3d/Flx3DView.hx b/source/flx3d/Flx3DView.hx index e76500c3..5413fe94 100644 --- a/source/flx3d/Flx3DView.hx +++ b/source/flx3d/Flx3DView.hx @@ -60,7 +60,7 @@ class Flx3DView extends FlxView3D { default: new OBJParser(); }, (event:Asset3DEvent) -> { if (event.asset != null && event.asset.assetType == Asset3DType.MESH) { - var mesh:Mesh = cast(event.asset, Mesh); + var mesh:Mesh = cast event.asset; if (material != null) mesh.material = material; meshes.push(mesh); diff --git a/source/funkin/backend/MusicBeatGroup.hx b/source/funkin/backend/MusicBeatGroup.hx index ec6f2693..5cccf0f6 100644 --- a/source/funkin/backend/MusicBeatGroup.hx +++ b/source/funkin/backend/MusicBeatGroup.hx @@ -4,12 +4,12 @@ import funkin.backend.system.interfaces.IBeatReceiver; class MusicBeatGroup extends FlxTypedSpriteGroup implements IBeatReceiver { public function beatHit(curBeat:Int) { - for(e in members) if (e is IBeatReceiver) cast(e, IBeatReceiver).beatHit(curBeat); + for(e in members) if (e is IBeatReceiver) ({var _:IBeatReceiver = cast e;_;}).beatHit(curBeat); } public function stepHit(curStep:Int) { - for(e in members) if (e is IBeatReceiver) cast(e, IBeatReceiver).stepHit(curStep); + for(e in members) if (e is IBeatReceiver) ({var _:IBeatReceiver = cast e;_;}).stepHit(curStep); } public function measureHit(curMeasure:Int) { - for(e in members) if (e is IBeatReceiver) cast(e, IBeatReceiver).measureHit(curMeasure); + for(e in members) if (e is IBeatReceiver) ({var _:IBeatReceiver = cast e;_;}).measureHit(curMeasure); } } \ No newline at end of file diff --git a/source/funkin/backend/MusicBeatState.hx b/source/funkin/backend/MusicBeatState.hx index e519ed0e..56dc1874 100644 --- a/source/funkin/backend/MusicBeatState.hx +++ b/source/funkin/backend/MusicBeatState.hx @@ -192,19 +192,19 @@ class MusicBeatState extends FlxState implements IBeatReceiver @:dox(hide) public function stepHit(curStep:Int):Void { - for(e in members) if (e != null && e is IBeatReceiver) cast(e, IBeatReceiver).stepHit(curStep); + for(e in members) if (e != null && e is IBeatReceiver) ({var _:IBeatReceiver=cast e;_;}).stepHit(curStep); call("stepHit", [curStep]); } @:dox(hide) public function beatHit(curBeat:Int):Void { - for(e in members) if (e != null && e is IBeatReceiver) cast(e, IBeatReceiver).beatHit(curBeat); + for(e in members) if (e != null && e is IBeatReceiver) ({var _:IBeatReceiver=cast e;_;}).beatHit(curBeat); call("beatHit", [curBeat]); } @:dox(hide) public function measureHit(curMeasure:Int):Void { - for(e in members) if (e != null && e is IBeatReceiver) cast(e, IBeatReceiver).measureHit(curMeasure); + for(e in members) if (e != null && e is IBeatReceiver) ({var _:IBeatReceiver=cast e;_;}).measureHit(curMeasure); call("measureHit", [curMeasure]); } @@ -278,8 +278,9 @@ class MusicBeatState extends FlxState implements IBeatReceiver public override function resetSubState() { super.resetSubState(); if (subState != null && subState is MusicBeatSubstate) { - cast(subState, MusicBeatSubstate).parent = this; - cast(subState, MusicBeatSubstate).onSubstateOpen(); + var subState:MusicBeatSubstate = cast subState; + subState.parent = this; + subState.onSubstateOpen(); } } } diff --git a/source/funkin/backend/MusicBeatSubstate.hx b/source/funkin/backend/MusicBeatSubstate.hx index d8ee8076..b8d26038 100644 --- a/source/funkin/backend/MusicBeatSubstate.hx +++ b/source/funkin/backend/MusicBeatSubstate.hx @@ -181,19 +181,19 @@ class MusicBeatSubstate extends FlxSubState implements IBeatReceiver @:dox(hide) public function stepHit(curStep:Int):Void { - for(e in members) if (e is IBeatReceiver) cast(e, IBeatReceiver).stepHit(curStep); + for(e in members) if (e is IBeatReceiver) ({var _:IBeatReceiver=cast e;_;}).stepHit(curStep); call("stepHit", [curStep]); } @:dox(hide) public function beatHit(curBeat:Int):Void { - for(e in members) if (e is IBeatReceiver) cast(e, IBeatReceiver).beatHit(curBeat); + for(e in members) if (e is IBeatReceiver) ({var _:IBeatReceiver=cast e;_;}).beatHit(curBeat); call("beatHit", [curBeat]); } @:dox(hide) public function measureHit(curMeasure:Int):Void { - for(e in members) if (e is IBeatReceiver) cast(e, IBeatReceiver).measureHit(curMeasure); + for(e in members) if (e is IBeatReceiver) ({var _:IBeatReceiver=cast e;_;}).measureHit(curMeasure); call("measureHit", [curMeasure]); } @@ -256,7 +256,8 @@ class MusicBeatSubstate extends FlxSubState implements IBeatReceiver public override function resetSubState() { if (subState != null && subState is MusicBeatSubstate) { - cast(subState, MusicBeatSubstate).parent = this; + var subState:MusicBeatSubstate = cast subState; + subState.parent = this; super.resetSubState(); if (subState != null) cast(subState, MusicBeatSubstate).onSubstateOpen(); diff --git a/source/funkin/backend/scripting/MultiThreadedScript.hx b/source/funkin/backend/scripting/MultiThreadedScript.hx index 3ba51f52..24754c7c 100644 --- a/source/funkin/backend/scripting/MultiThreadedScript.hx +++ b/source/funkin/backend/scripting/MultiThreadedScript.hx @@ -33,8 +33,8 @@ class MultiThreadedScript implements IFlxDestroyable implements IHScriptCustomBe if (parentScript != null) { if (script is HScript && parentScript is HScript) { - var hscript = cast(script, HScript); - var parentHScript = cast(parentScript, HScript); + var hscript:HScript = cast script; + var parentHScript:HScript = cast parentScript; hscript.interp.variables = parentHScript.interp.variables; hscript.interp.publicVariables = parentHScript.interp.publicVariables; diff --git a/source/funkin/backend/system/Conductor.hx b/source/funkin/backend/system/Conductor.hx index 8d4ef85a..f9758b94 100644 --- a/source/funkin/backend/system/Conductor.hx +++ b/source/funkin/backend/system/Conductor.hx @@ -181,7 +181,11 @@ class Conductor private static var __updateMeasure:Bool; private static function update() { - if (FlxG.state != null && FlxG.state is MusicBeatState && cast(FlxG.state, MusicBeatState).cancelConductorUpdate) return; + if (FlxG.state != null && FlxG.state is MusicBeatState) { + var state:MusicBeatState = cast FlxG.state; + if(state.cancelConductorUpdate) + return; + } __updateSongPos(FlxG.elapsed); @@ -233,7 +237,7 @@ class Conductor var state = FlxG.state; while(state != null) { if (state is IBeatReceiver && (state.subState == null || state.persistentUpdate)) { - var st = cast(state, IBeatReceiver); + var st:IBeatReceiver = cast state; if (curStep > oldStep) { for(i in oldStep...curStep) { st.stepHit(i+1); diff --git a/source/funkin/backend/system/framerate/SystemInfo.hx b/source/funkin/backend/system/framerate/SystemInfo.hx index a815e3b5..e736b7d2 100644 --- a/source/funkin/backend/system/framerate/SystemInfo.hx +++ b/source/funkin/backend/system/framerate/SystemInfo.hx @@ -91,7 +91,7 @@ class SystemInfo extends FramerateCategory { #end if(openfl.display3D.Context3D.__glMemoryTotalAvailable != -1) { - var vRAMBytes:UInt = cast(flixel.FlxG.stage.context3D.gl.getParameter(openfl.display3D.Context3D.__glMemoryTotalAvailable), UInt); + var vRAMBytes:UInt = cast flixel.FlxG.stage.context3D.gl.getParameter(openfl.display3D.Context3D.__glMemoryTotalAvailable); if (vRAMBytes == 1000 || vRAMBytes == 1 || vRAMBytes <= 0) Logs.trace('Unable to grab GPU VRAM', ERROR, RED); else diff --git a/source/funkin/backend/system/modules/CrashHandler.hx b/source/funkin/backend/system/modules/CrashHandler.hx index 124b915c..1debede9 100644 --- a/source/funkin/backend/system/modules/CrashHandler.hx +++ b/source/funkin/backend/system/modules/CrashHandler.hx @@ -20,10 +20,10 @@ class CrashHandler { public static function onUncaughtError(e:UncaughtErrorEvent) { var m:String = e.error; if (Std.isOfType(e.error, Error)) { - var err = cast(e.error, Error); + var err:Error = cast e.error; m = '${err.message}'; } else if (Std.isOfType(e.error, ErrorEvent)) { - var err = cast(e.error, ErrorEvent); + var err:ErrorEvent = cast e.error; m = '${err.text}'; } var stack = CallStack.exceptionStack(); diff --git a/source/funkin/backend/utils/MemoryUtil.hx b/source/funkin/backend/utils/MemoryUtil.hx index ac807088..6c27629e 100644 --- a/source/funkin/backend/utils/MemoryUtil.hx +++ b/source/funkin/backend/utils/MemoryUtil.hx @@ -151,25 +151,4 @@ class MemoryUtil { #end return "Unknown"; } - - private static var _nb:Int = 0; - private static var _nbD:Int = 0; - private static var _zombie:Dynamic; - - public static function destroyFlixelZombies() { - #if cpp - // Gc.enterGCFreeZone(); - - while ((_zombie = Gc.getNextZombie()) != null) { - _nb++; - if (_zombie is flixel.util.FlxDestroyUtil.IFlxDestroyable) { - flixel.util.FlxDestroyUtil.destroy(cast(_zombie, flixel.util.FlxDestroyUtil.IFlxDestroyable)); - _nbD++; - } - } - Sys.println('Zombies: ${_nb}; IFlxDestroyable Zombies: ${_nbD}'); - - // Gc.exitGCFreeZone(); - #end - } } \ No newline at end of file diff --git a/source/funkin/backend/utils/NativeAPI.hx b/source/funkin/backend/utils/NativeAPI.hx index 78f0b38d..45759231 100644 --- a/source/funkin/backend/utils/NativeAPI.hx +++ b/source/funkin/backend/utils/NativeAPI.hx @@ -113,8 +113,8 @@ class NativeAPI { if(backgroundColor == NONE) backgroundColor = BLACK; - var fg = cast(foregroundColor, Int); - var bg = cast(backgroundColor, Int); + var fg:Int = cast foregroundColor; + var bg:Int = cast backgroundColor; Windows.setConsoleColors((bg * 16) + fg); #elseif sys Sys.print("\x1b[0m"); diff --git a/source/funkin/backend/utils/XMLUtil.hx b/source/funkin/backend/utils/XMLUtil.hx index 6ff7c1d6..30bbc380 100644 --- a/source/funkin/backend/utils/XMLUtil.hx +++ b/source/funkin/backend/utils/XMLUtil.hx @@ -252,7 +252,7 @@ class XMLUtil { cast(sprite, IOffsetCompatible).addOffset(animData.name, animData.x, animData.y); if (sprite is FunkinSprite) { - var xmlSpr = cast(sprite, FunkinSprite); + var xmlSpr:FunkinSprite = cast sprite; var name = animData.name; switch(animData.animType) { case BEAT: diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index dc862cc4..5b065029 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -675,7 +675,8 @@ class Charter extends UIState { } for (group in [notesGroup, eventsGroup]) { - cast(group, FlxTypedGroup).forEach(function(s) { + var group:FlxTypedGroup = cast group; + group.forEach(function(s) { s.selected = false; if (gridActionType == NONE) { if (s is CharterNote) { @@ -740,21 +741,27 @@ class Charter extends UIState { selectionBox.bHeight = Std.int(Math.abs(mousePos.y - dragStartPos.y)); } else { if (FlxG.keys.pressed.SHIFT) { - for (group in [notesGroup, eventsGroup]) - for(n in cast(group, FlxTypedGroup)) + for (group in [notesGroup, eventsGroup]) { + var group:FlxTypedGroup = cast group; + for(n in group) if (n.handleSelection(selectionBox) && selection.contains(n)) selection.remove(n); + } } else if (FlxG.keys.pressed.CONTROL) { - for (group in [notesGroup, eventsGroup]) - for(n in cast(group, FlxTypedGroup)) + for (group in [notesGroup, eventsGroup]) { + var group:FlxTypedGroup = cast group; + for(n in group) if (n.handleSelection(selectionBox) && !selection.contains(n)) selection.push(n); + } } else { selection = []; - for (group in [notesGroup, eventsGroup]) - for(n in cast(group, FlxTypedGroup)) + for (group in [notesGroup, eventsGroup]) { + var group:FlxTypedGroup = cast group; + for(n in group) if (n.handleSelection(selectionBox)) selection.push(n); + } } selection = __fixSelection(selection); @@ -810,8 +817,14 @@ class Charter extends UIState { changePoint.put(); } - if (s is CharterNote) cast(s, CharterNote).snappedToStrumline = true; - if (s is UISprite) cast(s, UISprite).cursor = BUTTON; + if (s is CharterNote) { + var s:CharterNote = cast s; + s.snappedToStrumline = true; + } + if (s is UISprite) { + var s:UISprite = cast s; + s.cursor = BUTTON; + } } if (!(verticalChange == 0 && horizontalChange == 0)) { notesGroup.sortNotes(); eventsGroup.sortEvents(); @@ -1016,9 +1029,9 @@ class Charter extends UIState { if (selection.length <= 0) return []; notesGroup.autoSort = false; - for (objects in [notesGroup, eventsGroup]) { - var group = cast(objects, FlxTypedGroup); - var member = 0; + for (group in [notesGroup, eventsGroup]) { + var group:FlxTypedGroup = cast group; + var member:Int = 0; while(member < group.members.length) { var s = group.members[member]; if (selection.contains(s)) @@ -1375,7 +1388,7 @@ class Charter extends UIState { var note:CharterNote = cast s; CNote(note.step - minStep, note.id, note.strumLineID, note.susLength, note.type); } else if (s is CharterEvent) { - var event = cast(s,CharterEvent); + var event:CharterEvent = cast s; CEvent(event.step - minStep, [for (event in event.events) Reflect.copy(event)]); } ]; @@ -1957,9 +1970,9 @@ typedef SelectionDragChange = { public inline function loop(onNote:CharterNote->Void, ?onEvent:CharterEvent->Void, ?draggableOnly:Bool = true) { for (s in this) { if (s is CharterNote && onNote != null && (draggableOnly ? s.draggable: true)) - onNote(cast(s, CharterNote)); + onNote(cast s); else if (s is CharterEvent && onEvent != null && (draggableOnly ? s.draggable: true)) - onEvent(cast(s, CharterEvent)); + onEvent(cast s); } } } diff --git a/source/funkin/editors/charter/CharterEvent.hx b/source/funkin/editors/charter/CharterEvent.hx index af8996a4..1a0abe81 100644 --- a/source/funkin/editors/charter/CharterEvent.hx +++ b/source/funkin/editors/charter/CharterEvent.hx @@ -63,7 +63,7 @@ class CharterEvent extends UISliceSprite implements ICharterSelectable { generateDefaultIcon(event.name); case "Camera Movement": // custom icon for camera movement - var state = cast(FlxG.state, Charter); + var state:Charter = cast FlxG.state; if (event.params != null && event.params[0] != null && event.params[0] >= 0 && event.params[0] < state.strumLines.length) { // camera movement, use health icon var icon = Character.getIconFromCharName(state.strumLines.members[event.params[0]].strumLine.characters[0]); diff --git a/source/funkin/editors/charter/CharterNoteGroup.hx b/source/funkin/editors/charter/CharterNoteGroup.hx index 4c9a1d87..c2c2e388 100644 --- a/source/funkin/editors/charter/CharterNoteGroup.hx +++ b/source/funkin/editors/charter/CharterNoteGroup.hx @@ -33,7 +33,7 @@ class CharterNoteGroup extends FlxTypedGroup { noteFunc(__loopSprite); } for(c in Charter.selection.copy()) - if (c != null && c is CharterNote) noteFunc(cast (c, CharterNote)); + if (c != null && c is CharterNote) noteFunc(cast c); __currentlyLooping = oldCur; } diff --git a/source/funkin/editors/charter/CharterNoteHoverer.hx b/source/funkin/editors/charter/CharterNoteHoverer.hx index e20000a2..3ef2e543 100644 --- a/source/funkin/editors/charter/CharterNoteHoverer.hx +++ b/source/funkin/editors/charter/CharterNoteHoverer.hx @@ -47,7 +47,7 @@ class CharterNoteHoverer extends CharterNote { for (s in Charter.selection) { if (s != null && s.draggable && s is CharterNote) { - var draggingNote:CharterNote = cast(s, CharterNote); + var draggingNote:CharterNote = cast s; y = (draggingNote.step + verticalChange); if (!FlxG.keys.pressed.SHIFT) y -= ((draggingNote.step + verticalChange) diff --git a/source/funkin/editors/ui/UIFileExplorer.hx b/source/funkin/editors/ui/UIFileExplorer.hx index 7cc16320..a122dcec 100644 --- a/source/funkin/editors/ui/UIFileExplorer.hx +++ b/source/funkin/editors/ui/UIFileExplorer.hx @@ -55,8 +55,10 @@ class UIFileExplorer extends UISliceSprite { if (uiElement != null) { uiElement.alpha = alpha; - if (uiElement is UIButton) - cast(uiElement, UIButton).selectable = selectable; + if (uiElement is UIButton) { + var uiElement:UIButton = cast uiElement; + uiElement.selectable = selectable; + } } } diff --git a/source/funkin/editors/ui/UITopMenu.hx b/source/funkin/editors/ui/UITopMenu.hx index ae78469d..c4b0471d 100644 --- a/source/funkin/editors/ui/UITopMenu.hx +++ b/source/funkin/editors/ui/UITopMenu.hx @@ -21,9 +21,12 @@ class UITopMenu extends UISliceSprite { public override function update(elapsed:Float) { anyMenuOpened = false; - for(c in members) if (cast(c, UITopMenuButton).curMenu.contextMenuOpened()) { - anyMenuOpened = true; - break; + for(c in members) { + var c:UITopMenuButton = cast c; + if (c.curMenu.contextMenuOpened()) { + anyMenuOpened = true; + break; + } } super.update(elapsed); diff --git a/source/funkin/editors/ui/UIUtil.hx b/source/funkin/editors/ui/UIUtil.hx index 7f9de548..ac445a05 100644 --- a/source/funkin/editors/ui/UIUtil.hx +++ b/source/funkin/editors/ui/UIUtil.hx @@ -5,7 +5,7 @@ import funkin.editors.ui.UIContextMenu.UIContextMenuOption; class UIUtil { public static function follow(spr:FlxSprite, target:FlxSprite, x:Float = 0, y:Float = 0) { - spr.cameras = target is UISprite ? cast(target, UISprite).__lastDrawCameras : target.cameras; + spr.cameras = target is UISprite ? ({var _:UISprite = cast target;_;}).__lastDrawCameras : target.cameras; spr.setPosition(target.x + x, target.y + y); spr.scrollFactor.set(target.scrollFactor.x, target.scrollFactor.y); } diff --git a/source/funkin/game/Character.hx b/source/funkin/game/Character.hx index d043c040..f35dbc8d 100644 --- a/source/funkin/game/Character.hx +++ b/source/funkin/game/Character.hx @@ -436,7 +436,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset public static function getXMLFromCharName(character:OneOfTwo):Access { var char:Character = null; if (character is Character) { - char = cast(character, Character); + char = cast character; character = char.curCharacter; } diff --git a/source/funkin/game/Note.hx b/source/funkin/game/Note.hx index 21e70a6e..60aab276 100644 --- a/source/funkin/game/Note.hx +++ b/source/funkin/game/Note.hx @@ -213,7 +213,7 @@ class Note extends FlxSprite public var strumRelativePos:Bool = true; override function drawComplex(camera:FlxCamera) { - var downscrollCam = (camera is HudCamera ? cast(camera, HudCamera).downscroll : false); + var downscrollCam = (camera is HudCamera ? ({var _:HudCamera=cast camera;_;}).downscroll : false); flipY = (isSustainNote && flipSustain) && (downscrollCam != (__strum != null && __strum.getScrollSpeed(this) < 0)); if (downscrollCam) { frameOffset.y += __notePosFrameOffset.y * 2; diff --git a/source/funkin/menus/ui/Alphabet.hx b/source/funkin/menus/ui/Alphabet.hx index 663fa1b1..dfc86584 100644 --- a/source/funkin/menus/ui/Alphabet.hx +++ b/source/funkin/menus/ui/Alphabet.hx @@ -41,7 +41,7 @@ class Alphabet extends FlxSpriteGroup private override function set_color(c:Int):Int { for(e in group.members) { if (e is AlphaCharacter) { - var char = cast(e, AlphaCharacter); + var char:AlphaCharacter = cast e; char.setColor(c, isBold); } } From 2be2c68c9b9268df7c7f9dc0a445f8890ce98992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Sun, 20 Oct 2024 01:39:50 +0200 Subject: [PATCH 16/16] updating the win title on mod switch why did we never do this?? --- source/funkin/backend/system/Main.hx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/funkin/backend/system/Main.hx b/source/funkin/backend/system/Main.hx index cad2266e..6705b93c 100644 --- a/source/funkin/backend/system/Main.hx +++ b/source/funkin/backend/system/Main.hx @@ -166,6 +166,8 @@ class Main extends Sprite } public static function refreshAssets() { + WindowUtils.resetTitle(); + FlxSoundTray.volumeChangeSFX = Paths.sound('menu/volume'); FlxSoundTray.volumeUpChangeSFX = null; FlxSoundTray.volumeDownChangeSFX = null;