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 <87421482+NexIsDumb@users.noreply.github.com>
This commit is contained in:
Betopia
2025-07-05 03:23:32 +02:00
committed by GitHub
co-authored by ⍚~Nex
parent e13486dec0
commit b41602ff37
2 changed files with 19 additions and 7 deletions
+5 -4
View File
@@ -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<FunkinSprite>, ?args:Array<Dynamic>):FunkinSprite {
public static inline function createSpriteFromXML(node:Access, parentFolder:String = "", defaultAnimType:XMLAnimType = BEAT, ?cl:Class<FunkinSprite>, ?args:Array<Dynamic>, 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 {
+14 -3
View File
@@ -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;
}
}