better characters' suffix anims

This commit is contained in:
⍚~Nex
2024-05-31 19:40:28 +02:00
parent b682bcfb0b
commit f259d626cf
2 changed files with 21 additions and 5 deletions
+19 -3
View File
@@ -53,6 +53,8 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
public var shadowFrame:CharacterShadowFrame;
public var idleSuffix:String = "";
public var anims = ["singLEFT", "singDOWN", "singUP", "singRIGHT"]; // Not making these inline so theyre editable through scripts! - Nex
public inline function getCameraPosition()
{
var midpoint = getMidpoint();
@@ -65,11 +67,25 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
return new FlxPoint(event.x, event.y);
}
public inline function getSingAnim(direction:Int, suffix:String = ""):String
{
return anims[direction] + suffix;
}
/**
* Like `playSingAnim` but checks if the character has the animation with the suffix part, otherwhise tries to play the animation without the suffix part.
*/
public function playSafeSingAnim(direction:Int, suffix:String = "", Context:PlayAnimContext = SING, Force:Bool = true, Reversed:Bool = false, Frame:Int = 0)
{
var event = EventManager.get(DirectionAnimEvent).recycle(getSingAnim(direction, suffix), direction, suffix, Context, Reversed, Frame, Force);
script.call("onPlaySafeSingAnim", [event]);
if (!event.cancelled)
playSingAnim(event.direction, hasAnimation(event.animName) ? event.suffix : "", event.context, event.force, event.reversed, event.frame);
}
public function playSingAnim(direction:Int, suffix:String = "", Context:PlayAnimContext = SING, Force:Bool = true, Reversed:Bool = false, Frame:Int = 0)
{
var anims = ["singLEFT", "singDOWN", "singUP", "singRIGHT"];
var event = EventManager.get(DirectionAnimEvent).recycle(anims[direction] + suffix, direction, suffix, Context, Reversed, Frame, Force);
var event = EventManager.get(DirectionAnimEvent).recycle(getSingAnim(direction, suffix), direction, suffix, Context, Reversed, Frame, Force);
script.call("onPlaySingAnim", [event]);
if (!event.cancelled)
playAnim(event.animName, event.force, event.context, event.reversed, event.frame);
+2 -2
View File
@@ -1572,7 +1572,7 @@ class PlayState extends MusicBeatState
if (char == null) continue;
if(event.stunned) char.stunned = true;
char.playSingAnim(directionID, event.animSuffix, MISS, event.forceAnim);
char.playSafeSingAnim(directionID, event.animSuffix, MISS, event.forceAnim);
}
}
@@ -1653,7 +1653,7 @@ class PlayState extends MusicBeatState
if (!event.animCancelled)
for(char in event.characters)
if (char != null)
char.playSingAnim(event.direction, event.animSuffix, SING, event.forceAnim);
char.playSafeSingAnim(event.direction, event.animSuffix, SING, event.forceAnim);
if (event.note.__strum != null) {
if (!event.strumGlowCancelled) event.note.__strum.press(event.note.strumTime);