From f6deda2c84984202effdfc5f6b577c2d956aa7b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Sun, 8 Dec 2024 21:35:39 +0100 Subject: [PATCH] addAnim for FunkinSprite + better names so u dont have to manually add based if atlas or sparrow or else this behaves as both addByPrefix and addByIndices and like the xml animations --- source/funkin/backend/FunkinSprite.hx | 43 ++++++++++++++++++++------ source/funkin/backend/utils/XMLUtil.hx | 37 +++++++++++----------- 2 files changed, 51 insertions(+), 29 deletions(-) diff --git a/source/funkin/backend/FunkinSprite.hx b/source/funkin/backend/FunkinSprite.hx index b04cdffdf..2e4df83da 100644 --- a/source/funkin/backend/FunkinSprite.hx +++ b/source/funkin/backend/FunkinSprite.hx @@ -328,7 +328,31 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I lastAnimContext = Context; } - public function getAnim(name:String):OneOfTwo { + public inline function addAnim(name:String, prefix:String, frameRate:Float = 24, ?looped:Bool, ?forced:Bool, ?indices:Array, x:Float = 0, y:Float = 0, animType:XMLAnimType = NONE) + { + return XMLUtil.addAnimToSprite(this, { + name: name, + anim: prefix, + fps: frameRate, + loop: looped == null ? animType == LOOP : looped, + animType: animType, + x: x, + y: y, + indices: indices, + forced: forced + }); + } + + public inline function removeAnim(name:String) + { + if (animateAtlas != null) + @:privateAccess animateAtlas.anim.animsMap.remove(name); + else + animation.remove(name); + } + + public function getAnim(name:String):OneOfTwo + { if(animateAtlas != null) return animateAtlas.anim.getByName(name); return animation.getByName(name); @@ -341,7 +365,7 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I return FlxPoint.weak(0, 0); } - public inline function hasAnimation(AnimName:String):Bool @:privateAccess + public inline function hasAnim(AnimName:String):Bool @:privateAccess return animateAtlas != null ? (animateAtlas.anim.animsMap.exists(AnimName) || animateAtlas.anim.symbolDictionary.exists(AnimName)) : animation.exists(AnimName); @@ -364,13 +388,6 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I return animateAtlas != null ? animateAtlas.anim.reversed : animation.curAnim != null ? animation.curAnim.reversed : false; } - public inline function removeAnimation(name:String) { - if (animateAtlas != null) - @:privateAccess animateAtlas.anim.animsMap.remove(name); - else - animation.remove(name); - } - public inline function getNameList():Array { if (animateAtlas != null) return [for (name in @:privateAccess animateAtlas.anim.animsMap.keys()) name]; @@ -378,7 +395,8 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I return animation.getNameList(); } - public inline function stopAnimation() { + public inline function stopAnim() + { if (animateAtlas != null) animateAtlas.anim.pause(); else @@ -393,6 +411,11 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I public inline function isAnimAtEnd() { return animateAtlas != null ? animateAtlas.anim.isAtEnd : (animation.curAnim != null ? animation.curAnim.isAtEnd : false); } + + // Backwards compat (the names used to be all different and it sucked, please lets use the same format in the future) - Nex + public inline function hasAnimation(AnimName:String) return hasAnim(AnimName); + public inline function removeAnimation(name:String) return removeAnim(name); + public inline function stopAnimation() return stopAnim(); #end // Getter / Setters diff --git a/source/funkin/backend/utils/XMLUtil.hx b/source/funkin/backend/utils/XMLUtil.hx index afb8ae041..df5519859 100644 --- a/source/funkin/backend/utils/XMLUtil.hx +++ b/source/funkin/backend/utils/XMLUtil.hx @@ -164,19 +164,17 @@ class XMLUtil { if(node.hasNode.anim) { for(anim in node.nodes.anim) addXMLAnimation(spr, anim); - } else { - if (spr.frames != null && spr.frames.frames != null) { - addAnimToSprite(spr, { - name: "idle", - anim: null, - fps: 24, - loop: spr.spriteAnimType == LOOP, - animType: spr.spriteAnimType, - x: 0, - y: 0, - indices: [for(i in 0...spr.frames.frames.length) i] - }); - } + } else if (spr.frames != null && spr.frames.frames != null) { + addAnimToSprite(spr, { + name: "idle", + anim: null, + fps: 24, + loop: spr.spriteAnimType == LOOP, + animType: spr.spriteAnimType, + x: 0, + y: 0, + indices: [for(i in 0...spr.frames.frames.length) i] + }); } return spr; @@ -238,16 +236,17 @@ class XMLUtil { if(animData.anim == null) return MISSING_PROPERTY; - if (animData.indices.length > 0) + if (animData.indices != null && animData.indices.length > 0) animateAnim.addBySymbolIndices(animData.name, animData.anim, animData.indices, animData.fps, animData.loop); else animateAnim.addBySymbol(animData.name, animData.anim, animData.fps, animData.loop); } else { - if (animData.anim == null && animData.indices.length > 0) - sprite.animation.add(animData.name, animData.indices, animData.fps, animData.loop); - else if (animData.indices.length > 0) - sprite.animation.addByIndices(animData.name, animData.anim, animData.indices, "", animData.fps, animData.loop); - else + if (animData.indices != null && animData.indices.length > 0) { + if (animData.anim == null) + sprite.animation.add(animData.name, animData.indices, animData.fps, animData.loop); + else + sprite.animation.addByIndices(animData.name, animData.anim, animData.indices, "", animData.fps, animData.loop); + } else sprite.animation.addByPrefix(animData.name, animData.anim, animData.fps, animData.loop); }