From bb58e08c29a30a93e858b1d6c6bdcd0183b8021f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Thu, 19 Sep 2024 21:41:46 +0200 Subject: [PATCH 1/4] XMLImportedScriptInfo + importStageSprites way better and clean --- source/funkin/backend/scripting/Script.hx | 2 +- source/funkin/game/Stage.hx | 72 ++++++++++++++++------- 2 files changed, 52 insertions(+), 22 deletions(-) diff --git a/source/funkin/backend/scripting/Script.hx b/source/funkin/backend/scripting/Script.hx index 7d141349..c92f0faa 100644 --- a/source/funkin/backend/scripting/Script.hx +++ b/source/funkin/backend/scripting/Script.hx @@ -284,7 +284,7 @@ class Script extends FlxBasic implements IFlxDestroyable { public function get(variable:String):Dynamic {return null;} /** - * Gets the variable `variable` from the script's variables. + * Sets the variable `variable` from the script's variables. * @param variable Name of the variable. * @return Variable (or null if it doesn't exists) */ diff --git a/source/funkin/game/Stage.hx b/source/funkin/game/Stage.hx index bcfef901..f0fd76f0 100644 --- a/source/funkin/game/Stage.hx +++ b/source/funkin/game/Stage.hx @@ -19,13 +19,15 @@ class Stage extends FlxBasic implements IBeatReceiver { public var stageScript:Script; public var state:FlxState; public var characterPoses:Map = []; - public var xmlImportedScripts:Map = []; + public var xmlImportedScripts:Array = []; private var spritesParentFolder = ""; - public function getSprite(name:String) { + public function getSprite(name:String) return stageSprites[name]; - } + + public function setStagesSprites(script:Script) + for (k=>e in stageSprites) script.set(k, e); public function new(stage:String, ?state:FlxState) { super(); @@ -138,20 +140,7 @@ class Stage extends FlxBasic implements IBeatReceiver { PlayState.instance.add(PlayState.instance.comboGroup); PlayState.instance.comboGroup; case "use-extension" | "extension" | "ext": - if (!node.has.script || PlayState.instance == null) continue; - - 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 at ${path} does not exist.', ERROR); - else { - xmlImportedScripts.set(path, node.getAtt("isShortLived") == "true"); - PlayState.instance.scripts.add(daScript); - daScript.load(); - } - + if (XMLImportedScriptInfo.prepeareInfos(node, this) == null) continue; null; default: null; } @@ -193,15 +182,20 @@ class Stage extends FlxBasic implements IBeatReceiver { if (PlayState.instance == null) return; - for (k=>e in stageSprites) - stageScript.set(k, e); + setStagesSprites(stageScript); + + // i know this for gets run twice under, but its better like this in case a script modifies the short lived ones, i dont wanna save them in an array; more dynamic like this - Nex + for (info in xmlImportedScripts) if (info.importStageSprites) { + var script = info.getScript(); + if (script != null) setStagesSprites(script); + } // idk lemme check anyways just in case scripts did smth - Nex if (event != null) PlayState.instance.scripts.event("onPostStageCreation", event); // shortlived scripts destroy when the stage finishes setting up - Nex - for (p=>b in xmlImportedScripts) if (b) { - var script = PlayState.instance.scripts.getByPath(p); + for (info in xmlImportedScripts) if (info.shortLived) { + var script = info.getScript(); if (script == null) continue; PlayState.instance.scripts.remove(script); @@ -318,4 +312,40 @@ typedef StageCharPosInfo = { var y:Float; var flip:Bool; var scroll:Float; +} + +class XMLImportedScriptInfo { + public var path:String; + public var shortLived:Bool = false; + 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 prepeareInfos(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) { + Logs.trace('Script at ${path} does not exist.', ERROR); + return null; + } + + var infos = new XMLImportedScriptInfo(daScript.path); + infos.shortLived = node.getAtt("isShortLived") == "true"; + infos.importStageSprites = node.getAtt("importStageSprites") == "true"; + + if (stage != null) stage.xmlImportedScripts.push(infos); + PlayState.instance.scripts.add(daScript); + daScript.load(); + + return infos; + } } \ No newline at end of file From 6d8479839711953488b6e0365b804cd937d3f129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Thu, 19 Sep 2024 22:16:30 +0200 Subject: [PATCH 2/4] my fucking grammar ass + some new stage stuff --- source/funkin/game/PlayState.hx | 10 +++++++++- source/funkin/game/Stage.hx | 15 +++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index b36628b7..4e125724 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -243,7 +243,7 @@ class PlayState extends MusicBeatState /** * Current stage name */ - public var curStage:String = ""; + public var curStage(get, set):String; /** * Interval at which Girlfriend dances. @@ -526,6 +526,14 @@ class PlayState extends MusicBeatState return this.maxHealth = v; } + private inline function get_curStage() + return stage == null ? "" : stage.stageName; + + private inline function set_curStage(name:String) { + if (stage != null) stage.stageName = name; + return name; + } + @:dox(hide) override public function create() { Note.__customNoteTypeExists = []; diff --git a/source/funkin/game/Stage.hx b/source/funkin/game/Stage.hx index f0fd76f0..f9a2fb49 100644 --- a/source/funkin/game/Stage.hx +++ b/source/funkin/game/Stage.hx @@ -13,6 +13,7 @@ import haxe.io.Path; using StringTools; class Stage extends FlxBasic implements IBeatReceiver { + public var stageName:String = ""; public var stageXML:Access; public var stagePath:String; public var stageSprites:Map = []; @@ -37,11 +38,8 @@ class Stage extends FlxBasic implements IBeatReceiver { this.state = state; stagePath = Paths.xml('stages/$stage'); - try { - if (Assets.exists(stagePath)) stageXML = new Access(Xml.parse(Assets.getText(stagePath)).firstElement()); - } catch(e) { - Logs.trace('Couldn\'t load stage "$stage": ${e.message}', ERROR); - } + try if (Assets.exists(stagePath)) stageXML = new Access(Xml.parse(Assets.getText(stagePath)).firstElement()) + catch(e) Logs.trace('Couldn\'t load stage "$stage": ${e.message}', ERROR); if (PlayState.instance != null) { stageScript = Script.create(Paths.script('data/stages/$stage')); @@ -51,12 +49,13 @@ class Stage extends FlxBasic implements IBeatReceiver { var event = null; if (stageXML != null) { + stageName = stageXML.getAtt("name").getDefault(stage); + if (PlayState.instance != null) { var parsed:Null; if(stageXML.has.startCamPosX && (parsed = Std.parseFloat(stageXML.att.startCamPosX)) != null) PlayState.instance.camFollow.x = parsed; if(stageXML.has.startCamPosY && (parsed = Std.parseFloat(stageXML.att.startCamPosY)) != null) PlayState.instance.camFollow.y = parsed; if(stageXML.has.zoom && (parsed = Std.parseFloat(stageXML.att.zoom)) != null) PlayState.instance.defaultCamZoom = parsed; - PlayState.instance.curStage = stageXML.has.name ? stageXML.att.name : stage; } if (stageXML.has.folder) { spritesParentFolder = stageXML.att.folder; @@ -140,7 +139,7 @@ class Stage extends FlxBasic implements IBeatReceiver { PlayState.instance.add(PlayState.instance.comboGroup); PlayState.instance.comboGroup; case "use-extension" | "extension" | "ext": - if (XMLImportedScriptInfo.prepeareInfos(node, this) == null) continue; + if (XMLImportedScriptInfo.prepareInfos(node, this) == null) continue; null; default: null; } @@ -325,7 +324,7 @@ class XMLImportedScriptInfo { public function getScript():Script return PlayState.instance == null ? null : PlayState.instance.scripts.getByPath(path); - public static function prepeareInfos(node:Access, ?stage:Stage):XMLImportedScriptInfo { + 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/"); From d6ebd27b43924aef4d1c7ca25d299ed51f07f112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Thu, 19 Sep 2024 23:31:52 +0200 Subject: [PATCH 3/4] loadBefore --- source/funkin/game/Stage.hx | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/source/funkin/game/Stage.hx b/source/funkin/game/Stage.hx index f9a2fb49..c942e2c8 100644 --- a/source/funkin/game/Stage.hx +++ b/source/funkin/game/Stage.hx @@ -64,11 +64,8 @@ class Stage extends FlxBasic implements IBeatReceiver { var elems = []; for(node in stageXML.elements) { - if (node.name == "high-memory" && !Options.lowMemoryMode) - for(e in node.elements) - elems.push(e); - else - elems.push(node); + if (node.name == "high-memory" && !Options.lowMemoryMode) for(e in node.elements) __pushNcheckNode(elems, e); + else __pushNcheckNode(elems, node); } if (PlayState.instance != null) { @@ -139,7 +136,7 @@ class Stage extends FlxBasic implements IBeatReceiver { PlayState.instance.add(PlayState.instance.comboGroup); PlayState.instance.comboGroup; case "use-extension" | "extension" | "ext": - if (XMLImportedScriptInfo.prepareInfos(node, this) == null) continue; + if (__shouldLoadBefore(node) || XMLImportedScriptInfo.prepareInfos(node, this) == null) continue; null; default: null; } @@ -202,6 +199,15 @@ 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); + } + + @: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; @@ -316,6 +322,7 @@ typedef StageCharPosInfo = { 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) @@ -333,13 +340,16 @@ class XMLImportedScriptInfo { var path = Paths.script(folder + node.getAtt("script")); var daScript = Script.create(path); if (daScript is DummyScript) { - Logs.trace('Script at ${path} does not exist.', ERROR); + 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); From 8ee60adfcffeaca4669e5ec15bcc496309b4f743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:57:55 +0200 Subject: [PATCH 4/4] scriptInfo --- source/funkin/game/Stage.hx | 1 + 1 file changed, 1 insertion(+) diff --git a/source/funkin/game/Stage.hx b/source/funkin/game/Stage.hx index c942e2c8..7687d897 100644 --- a/source/funkin/game/Stage.hx +++ b/source/funkin/game/Stage.hx @@ -353,6 +353,7 @@ class XMLImportedScriptInfo { if (stage != null) stage.xmlImportedScripts.push(infos); PlayState.instance.scripts.add(daScript); + daScript.set("scriptInfo", infos); daScript.load(); return infos;