Skip to content

Commit f6deda2

Browse files
committed
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
1 parent 3297bef commit f6deda2

File tree

2 files changed

+51
-29
lines changed

2 files changed

+51
-29
lines changed

source/funkin/backend/FunkinSprite.hx

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,31 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
328328
lastAnimContext = Context;
329329
}
330330

331-
public function getAnim(name:String):OneOfTwo<FlxAnimation, FlxSymbolAnimation> {
331+
public inline function addAnim(name:String, prefix:String, frameRate:Float = 24, ?looped:Bool, ?forced:Bool, ?indices:Array<Int>, x:Float = 0, y:Float = 0, animType:XMLAnimType = NONE)
332+
{
333+
return XMLUtil.addAnimToSprite(this, {
334+
name: name,
335+
anim: prefix,
336+
fps: frameRate,
337+
loop: looped == null ? animType == LOOP : looped,
338+
animType: animType,
339+
x: x,
340+
y: y,
341+
indices: indices,
342+
forced: forced
343+
});
344+
}
345+
346+
public inline function removeAnim(name:String)
347+
{
348+
if (animateAtlas != null)
349+
@:privateAccess animateAtlas.anim.animsMap.remove(name);
350+
else
351+
animation.remove(name);
352+
}
353+
354+
public function getAnim(name:String):OneOfTwo<FlxAnimation, FlxSymbolAnimation>
355+
{
332356
if(animateAtlas != null)
333357
return animateAtlas.anim.getByName(name);
334358
return animation.getByName(name);
@@ -341,7 +365,7 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
341365
return FlxPoint.weak(0, 0);
342366
}
343367

344-
public inline function hasAnimation(AnimName:String):Bool @:privateAccess
368+
public inline function hasAnim(AnimName:String):Bool @:privateAccess
345369
return animateAtlas != null ? (animateAtlas.anim.animsMap.exists(AnimName)
346370
|| animateAtlas.anim.symbolDictionary.exists(AnimName)) : animation.exists(AnimName);
347371

@@ -364,21 +388,15 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
364388
return animateAtlas != null ? animateAtlas.anim.reversed : animation.curAnim != null ? animation.curAnim.reversed : false;
365389
}
366390

367-
public inline function removeAnimation(name:String) {
368-
if (animateAtlas != null)
369-
@:privateAccess animateAtlas.anim.animsMap.remove(name);
370-
else
371-
animation.remove(name);
372-
}
373-
374391
public inline function getNameList():Array<String> {
375392
if (animateAtlas != null)
376393
return [for (name in @:privateAccess animateAtlas.anim.animsMap.keys()) name];
377394
else
378395
return animation.getNameList();
379396
}
380397

381-
public inline function stopAnimation() {
398+
public inline function stopAnim()
399+
{
382400
if (animateAtlas != null)
383401
animateAtlas.anim.pause();
384402
else
@@ -393,6 +411,11 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
393411
public inline function isAnimAtEnd() {
394412
return animateAtlas != null ? animateAtlas.anim.isAtEnd : (animation.curAnim != null ? animation.curAnim.isAtEnd : false);
395413
}
414+
415+
// Backwards compat (the names used to be all different and it sucked, please lets use the same format in the future) - Nex
416+
public inline function hasAnimation(AnimName:String) return hasAnim(AnimName);
417+
public inline function removeAnimation(name:String) return removeAnim(name);
418+
public inline function stopAnimation() return stopAnim();
396419
#end
397420

398421
// Getter / Setters

source/funkin/backend/utils/XMLUtil.hx

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,17 @@ class XMLUtil {
164164
if(node.hasNode.anim) {
165165
for(anim in node.nodes.anim)
166166
addXMLAnimation(spr, anim);
167-
} else {
168-
if (spr.frames != null && spr.frames.frames != null) {
169-
addAnimToSprite(spr, {
170-
name: "idle",
171-
anim: null,
172-
fps: 24,
173-
loop: spr.spriteAnimType == LOOP,
174-
animType: spr.spriteAnimType,
175-
x: 0,
176-
y: 0,
177-
indices: [for(i in 0...spr.frames.frames.length) i]
178-
});
179-
}
167+
} else if (spr.frames != null && spr.frames.frames != null) {
168+
addAnimToSprite(spr, {
169+
name: "idle",
170+
anim: null,
171+
fps: 24,
172+
loop: spr.spriteAnimType == LOOP,
173+
animType: spr.spriteAnimType,
174+
x: 0,
175+
y: 0,
176+
indices: [for(i in 0...spr.frames.frames.length) i]
177+
});
180178
}
181179

182180
return spr;
@@ -238,16 +236,17 @@ class XMLUtil {
238236
if(animData.anim == null)
239237
return MISSING_PROPERTY;
240238

241-
if (animData.indices.length > 0)
239+
if (animData.indices != null && animData.indices.length > 0)
242240
animateAnim.addBySymbolIndices(animData.name, animData.anim, animData.indices, animData.fps, animData.loop);
243241
else
244242
animateAnim.addBySymbol(animData.name, animData.anim, animData.fps, animData.loop);
245243
} else {
246-
if (animData.anim == null && animData.indices.length > 0)
247-
sprite.animation.add(animData.name, animData.indices, animData.fps, animData.loop);
248-
else if (animData.indices.length > 0)
249-
sprite.animation.addByIndices(animData.name, animData.anim, animData.indices, "", animData.fps, animData.loop);
250-
else
244+
if (animData.indices != null && animData.indices.length > 0) {
245+
if (animData.anim == null)
246+
sprite.animation.add(animData.name, animData.indices, animData.fps, animData.loop);
247+
else
248+
sprite.animation.addByIndices(animData.name, animData.anim, animData.indices, "", animData.fps, animData.loop);
249+
} else
251250
sprite.animation.addByPrefix(animData.name, animData.anim, animData.fps, animData.loop);
252251
}
253252

0 commit comments

Comments
 (0)