diff --git a/source/funkin/game/Character.hx b/source/funkin/game/Character.hx index f36088e8b..f902d39a0 100644 --- a/source/funkin/game/Character.hx +++ b/source/funkin/game/Character.hx @@ -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 function playSingAnim(direction:Int, suffix:String = "", Context:PlayAnimContext = SING, Force:Bool = true, Reversed:Bool = false, Frame:Int = 0) + public inline function getSingAnim(direction:Int, suffix:String = ""):String { - var anims = ["singLEFT", "singDOWN", "singUP", "singRIGHT"]; + return anims[direction] + suffix; + } - var event = EventManager.get(DirectionAnimEvent).recycle(anims[direction] + suffix, direction, suffix, Context, Reversed, Frame, Force); + /** + * 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 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); diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index f585e89f7..fdbe04440 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -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);