diff --git a/source/funkin/play/character/MultiSparrowCharacter.hx b/source/funkin/play/character/MultiSparrowCharacter.hx index 20bfeb474..160bc1c5d 100644 --- a/source/funkin/play/character/MultiSparrowCharacter.hx +++ b/source/funkin/play/character/MultiSparrowCharacter.hx @@ -1,8 +1,8 @@ package funkin.play.character; +import flixel.graphics.frames.FlxFramesCollection; import funkin.modding.events.ScriptEvent; import funkin.util.assets.FlxAnimationUtil; -import flixel.graphics.frames.FlxFramesCollection; /** * For some characters which use Sparrow atlases, the spritesheets need to be split @@ -174,10 +174,10 @@ class MultiSparrowCharacter extends BaseCharacter trace('[MULTISPARROWCHAR] Successfully loaded ${animNames.length} animations for ${characterId}'); } - public override function playAnimation(name:String, restart:Bool = false):Void + public override function playAnimation(name:String, restart:Bool = false, ?ignoreOther:Bool = false):Void { loadFramesByAnimName(name); - super.playAnimation(name, restart); + super.playAnimation(name, restart, ignoreOther); } override function set_frames(value:FlxFramesCollection):FlxFramesCollection diff --git a/source/funkin/play/stage/Bopper.hx b/source/funkin/play/stage/Bopper.hx index 2d5cd9d3e..525ab0f91 100644 --- a/source/funkin/play/stage/Bopper.hx +++ b/source/funkin/play/stage/Bopper.hx @@ -1,5 +1,6 @@ package funkin.play.stage; +import flixel.FlxG; import flixel.FlxSprite; import funkin.modding.IScriptedClass.IPlayStateScriptedClass; import funkin.modding.events.ScriptEvent; @@ -42,6 +43,8 @@ class Bopper extends FlxSprite implements IPlayStateScriptedClass */ public var shouldBop:Bool = true; + public var finishCallbackMap:MapVoid> = new MapVoid>(); + function set_idleSuffix(value:String):String { this.idleSuffix = value; @@ -82,6 +85,11 @@ class Bopper extends FlxSprite implements IPlayStateScriptedClass { super(); this.danceEvery = danceEvery; + this.animation.finishCallback = function(name) + { + if (finishCallbackMap[name] != null) + finishCallbackMap[name](); + }; } function update_shouldAlternate():Void @@ -106,7 +114,7 @@ class Bopper extends FlxSprite implements IPlayStateScriptedClass /** * Called every `danceEvery` beats of the song. */ - public function dance(force:Bool = false):Void + public function dance(forceRestart:Bool = false):Void { if (this.animation == null) { @@ -122,17 +130,17 @@ class Bopper extends FlxSprite implements IPlayStateScriptedClass { if (hasDanced) { - playAnimation('danceRight$idleSuffix', force); + playAnimation('danceRight$idleSuffix', forceRestart); } else { - playAnimation('danceLeft$idleSuffix', force); + playAnimation('danceLeft$idleSuffix', forceRestart); } hasDanced = !hasDanced; } else { - playAnimation('idle$idleSuffix', force); + playAnimation('idle$idleSuffix', forceRestart); } } @@ -179,18 +187,39 @@ class Bopper extends FlxSprite implements IPlayStateScriptedClass } } + public var canPlayOtherAnims:Bool = true; + /** * @param name The name of the animation to play. * @param restart Whether to restart the animation if it is already playing. + * @param ignoreOther Whether to ignore all other animation inputs, until this one is done playing */ - public function playAnimation(name:String, restart:Bool = false):Void + public function playAnimation(name:String, restart:Bool = false, ?ignoreOther:Bool = false):Void { + if (ignoreOther == null) + ignoreOther = false; + + if (!canPlayOtherAnims) + return; + var correctName = correctAnimationName(name); if (correctName == null) return; this.animation.play(correctName, restart, false, 0); + if (ignoreOther) + { + canPlayOtherAnims = false; + + // doing it with this funny map, since overriding the animation.finishCallback is a bit messier IMO + finishCallbackMap[name] = function() + { + canPlayOtherAnims = true; + finishCallbackMap[name] = null; + }; + } + applyAnimationOffsets(correctName); }