From b41602ff375e8ffdcf8d218ffe355ed40b87c39f Mon Sep 17 00:00:00 2001 From: Betopia <73242725+betpowo@users.noreply.github.com> Date: Fri, 4 Jul 2025 21:23:32 -0400 Subject: [PATCH] extend functionality in stages (#633) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * extend functionality in stages adds support for scroll(x/y), zoomfactor, and alpha to solids made in a stage xml . because Why not * better --------- Co-authored-by: ⍚~Nex <87421482+NexIsDumb@users.noreply.github.com> --- source/funkin/backend/utils/XMLUtil.hx | 9 +++++---- source/funkin/game/Stage.hx | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/source/funkin/backend/utils/XMLUtil.hx b/source/funkin/backend/utils/XMLUtil.hx index a074f97d..237d382e 100644 --- a/source/funkin/backend/utils/XMLUtil.hx +++ b/source/funkin/backend/utils/XMLUtil.hx @@ -70,12 +70,13 @@ class XMLUtil { /** * Overrides a sprite based on a XML node. */ - public static function loadSpriteFromXML(spr:FunkinSprite, node:Access, parentFolder:String = "", defaultAnimType:XMLAnimType = BEAT):FunkinSprite { + public static function loadSpriteFromXML(spr:FunkinSprite, node:Access, parentFolder:String = "", defaultAnimType:XMLAnimType = BEAT, loadGraphic:Bool = true):FunkinSprite { if (parentFolder == null) parentFolder = ""; spr.name = node.getAtt("name"); spr.antialiasing = true; - spr.loadSprite(Paths.image('$parentFolder${node.getAtt("sprite").getDefault(spr.name)}', null, true)); + if (loadGraphic) + spr.loadSprite(Paths.image('$parentFolder${node.getAtt("sprite").getDefault(spr.name)}', null, true)); spr.spriteAnimType = defaultAnimType; if (node.has.type) { @@ -185,10 +186,10 @@ class XMLUtil { /** * Creates a new sprite based on a XML node. */ - public static inline function createSpriteFromXML(node:Access, parentFolder:String = "", defaultAnimType:XMLAnimType = BEAT, ?cl:Class, ?args:Array):FunkinSprite { + public static inline function createSpriteFromXML(node:Access, parentFolder:String = "", defaultAnimType:XMLAnimType = BEAT, ?cl:Class, ?args:Array, loadGraphic:Bool = true):FunkinSprite { if(cl == null) cl = FunkinSprite; if(args == null) args = []; - return loadSpriteFromXML(Type.createInstance(cl, args), node, parentFolder, defaultAnimType); + return loadSpriteFromXML(Type.createInstance(cl, args), node, parentFolder, defaultAnimType, loadGraphic); } public static function extractAnimFromXML(anim:Access, animType:XMLAnimType = NONE, loop:Bool = false):AnimData { diff --git a/source/funkin/game/Stage.hx b/source/funkin/game/Stage.hx index d2a52880..2ec902b2 100644 --- a/source/funkin/game/Stage.hx +++ b/source/funkin/game/Stage.hx @@ -93,17 +93,28 @@ class Stage extends FlxBasic implements IBeatReceiver { case "box" | "solid": if (!node.has.name || !node.has.width || !node.has.height) continue; - var spr = new FlxSprite( + var spr = new FunkinSprite( (node.has.x) ? Std.parseFloat(node.att.x).getDefault(0) : 0, (node.has.y) ? Std.parseFloat(node.att.y).getDefault(0) : 0 ); - (node.name == "solid" ? spr.makeSolid : spr.makeGraphic)( + // just to make sure, its better to apply these before it gets inside of xmlUtil (because of mainly updateHitbox i guess), so im removing them before it gets passed - Nex + var toRemove = ["x", "y", "width", "height", "color"]; + var isSolid = node.name == "solid"; + + (isSolid ? spr.makeSolid : spr.makeGraphic)( Std.parseInt(node.att.width), Std.parseInt(node.att.height), (node.has.color) ? CoolUtil.getColorFromDynamic(node.att.color) : -1 ); + if (isSolid) toRemove.push("updateHitbox"); // makesolid already calls updateHitbox - Nex + for (a in toRemove) node.x.remove(a); + XMLUtil.loadSpriteFromXML(spr, node, "", NONE, false); + + if (!node.has.zoomfactor && PlayState.instance != null) + spr.initialZoom = PlayState.instance.defaultCamZoom; + stageSprites.set(node.getAtt("name"), spr); state.add(spr); spr; @@ -318,4 +329,4 @@ typedef StageCharPosInfo = { var y:Float; var flip:Bool; var scroll:Float; -} \ No newline at end of file +}