Skip to content

Commit

Permalink
better characters' suffix anims
Browse files Browse the repository at this point in the history
  • Loading branch information
NexIsDumb committed May 31, 2024
1 parent b682bcf commit f259d62
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 19 additions & 3 deletions source/funkin/game/Character.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions source/funkin/game/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f259d62

Please sign in to comment.