Skip to content

Commit b41602f

Browse files
betpowoNexIsDumb
andauthored
extend <solid> functionality in stages (#633)
* extend <solid> 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 <[email protected]>
1 parent e13486d commit b41602f

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

source/funkin/backend/utils/XMLUtil.hx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@ class XMLUtil {
7070
/**
7171
* Overrides a sprite based on a XML node.
7272
*/
73-
public static function loadSpriteFromXML(spr:FunkinSprite, node:Access, parentFolder:String = "", defaultAnimType:XMLAnimType = BEAT):FunkinSprite {
73+
public static function loadSpriteFromXML(spr:FunkinSprite, node:Access, parentFolder:String = "", defaultAnimType:XMLAnimType = BEAT, loadGraphic:Bool = true):FunkinSprite {
7474
if (parentFolder == null) parentFolder = "";
7575

7676
spr.name = node.getAtt("name");
7777
spr.antialiasing = true;
78-
spr.loadSprite(Paths.image('$parentFolder${node.getAtt("sprite").getDefault(spr.name)}', null, true));
78+
if (loadGraphic)
79+
spr.loadSprite(Paths.image('$parentFolder${node.getAtt("sprite").getDefault(spr.name)}', null, true));
7980

8081
spr.spriteAnimType = defaultAnimType;
8182
if (node.has.type) {
@@ -185,10 +186,10 @@ class XMLUtil {
185186
/**
186187
* Creates a new sprite based on a XML node.
187188
*/
188-
public static inline function createSpriteFromXML(node:Access, parentFolder:String = "", defaultAnimType:XMLAnimType = BEAT, ?cl:Class<FunkinSprite>, ?args:Array<Dynamic>):FunkinSprite {
189+
public static inline function createSpriteFromXML(node:Access, parentFolder:String = "", defaultAnimType:XMLAnimType = BEAT, ?cl:Class<FunkinSprite>, ?args:Array<Dynamic>, loadGraphic:Bool = true):FunkinSprite {
189190
if(cl == null) cl = FunkinSprite;
190191
if(args == null) args = [];
191-
return loadSpriteFromXML(Type.createInstance(cl, args), node, parentFolder, defaultAnimType);
192+
return loadSpriteFromXML(Type.createInstance(cl, args), node, parentFolder, defaultAnimType, loadGraphic);
192193
}
193194

194195
public static function extractAnimFromXML(anim:Access, animType:XMLAnimType = NONE, loop:Bool = false):AnimData {

source/funkin/game/Stage.hx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,28 @@ class Stage extends FlxBasic implements IBeatReceiver {
9393
case "box" | "solid":
9494
if (!node.has.name || !node.has.width || !node.has.height) continue;
9595

96-
var spr = new FlxSprite(
96+
var spr = new FunkinSprite(
9797
(node.has.x) ? Std.parseFloat(node.att.x).getDefault(0) : 0,
9898
(node.has.y) ? Std.parseFloat(node.att.y).getDefault(0) : 0
9999
);
100100

101-
(node.name == "solid" ? spr.makeSolid : spr.makeGraphic)(
101+
// 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
102+
var toRemove = ["x", "y", "width", "height", "color"];
103+
var isSolid = node.name == "solid";
104+
105+
(isSolid ? spr.makeSolid : spr.makeGraphic)(
102106
Std.parseInt(node.att.width),
103107
Std.parseInt(node.att.height),
104108
(node.has.color) ? CoolUtil.getColorFromDynamic(node.att.color) : -1
105109
);
106110

111+
if (isSolid) toRemove.push("updateHitbox"); // makesolid already calls updateHitbox - Nex
112+
for (a in toRemove) node.x.remove(a);
113+
XMLUtil.loadSpriteFromXML(spr, node, "", NONE, false);
114+
115+
if (!node.has.zoomfactor && PlayState.instance != null)
116+
spr.initialZoom = PlayState.instance.defaultCamZoom;
117+
107118
stageSprites.set(node.getAtt("name"), spr);
108119
state.add(spr);
109120
spr;
@@ -318,4 +329,4 @@ typedef StageCharPosInfo = {
318329
var y:Float;
319330
var flip:Bool;
320331
var scroll:Float;
321-
}
332+
}

0 commit comments

Comments
 (0)