From 353aa42f5b46122b2115b7be0ca54ed416adb47f Mon Sep 17 00:00:00 2001 From: CheemsAndFriends <granchinvictor@gmail.com> Date: Wed, 28 Aug 2024 02:48:56 +0200 Subject: [PATCH] Fixes for the atlasSprite bizz --- assets | 2 +- .../graphics/adobeanimate/FlxAtlasSprite.hx | 32 ++++++- source/funkin/ui/charSelect/CharSelectGF.hx | 34 +------- .../funkin/ui/charSelect/CharSelectPlayer.hx | 85 +++++-------------- .../ui/charSelect/CharSelectSubState.hx | 17 ++-- source/funkin/ui/freeplay/AlbumRoll.hx | 4 +- source/funkin/ui/freeplay/FreeplayState.hx | 3 + 7 files changed, 66 insertions(+), 111 deletions(-) diff --git a/assets b/assets index 0e4392bcb..f986e5281 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 0e4392bcb0ed1dbb496764cff074635c20c91389 +Subproject commit f986e52819c5fd2e47f4d8d3297f326351682675 diff --git a/source/funkin/graphics/adobeanimate/FlxAtlasSprite.hx b/source/funkin/graphics/adobeanimate/FlxAtlasSprite.hx index fdb53e30e..9a9ba7036 100644 --- a/source/funkin/graphics/adobeanimate/FlxAtlasSprite.hx +++ b/source/funkin/graphics/adobeanimate/FlxAtlasSprite.hx @@ -9,6 +9,7 @@ import flixel.system.FlxAssets.FlxGraphicAsset; import openfl.display.BitmapData; import openfl.utils.Assets; import flixel.math.FlxPoint; +import flxanimate.animate.FlxKeyFrame; /** * A sprite which provides convenience functions for rendering a texture atlas with animations. @@ -121,6 +122,12 @@ class FlxAtlasSprite extends FlxAnimate return false; } + var _completeAnim:Bool = false; + + var fr:FlxKeyFrame = null; + + var looping:Bool = false; + /** * Plays an animation. * @param id A string ID of the animation to play. @@ -174,6 +181,8 @@ class FlxAtlasSprite extends FlxAnimate } }); + looping = loop; + // Prevent other animations from playing if `ignoreOther` is true. if (ignoreOther) canPlayOtherAnims = false; @@ -182,6 +191,9 @@ class FlxAtlasSprite extends FlxAnimate trace('Playing animation $id'); this.anim.play(id, restart, false, startFrame); goToFrameLabel(id); + + fr = anim.getFrameLabel(id); + anim.curFrame += startFrame; this.currentAnimation = id; } @@ -259,7 +271,21 @@ class FlxAtlasSprite extends FlxAnimate if (currentAnimation != null) { onAnimationFrame.dispatch(currentAnimation, frame); - if (isLoopComplete()) onAnimationLoopComplete.dispatch(currentAnimation); + + if (fr != null && frame > (fr.index + fr.duration - 1) || isLoopFinished()) + { + anim.pause(); + _onAnimationComplete(); + if (looping) + { + anim.curFrame = (fr != null) ? fr.index : 0; + anim.resume(); + } + else + { + anim.curFrame--; + } + } } } @@ -267,7 +293,9 @@ class FlxAtlasSprite extends FlxAnimate { if (currentAnimation != null) { - onAnimationComplete.dispatch(currentAnimation); + if (looping) onAnimationLoopComplete.dispatch(currentAnimation); + else + onAnimationComplete.dispatch(currentAnimation); } } diff --git a/source/funkin/ui/charSelect/CharSelectGF.hx b/source/funkin/ui/charSelect/CharSelectGF.hx index 44a9a6088..cb4eda8be 100644 --- a/source/funkin/ui/charSelect/CharSelectGF.hx +++ b/source/funkin/ui/charSelect/CharSelectGF.hx @@ -29,39 +29,12 @@ class CharSelectGF extends FlxAtlasSprite public function new() { super(0, 0, Paths.animateAtlas("charSelect/gfChill")); - anim.play(""); + list = anim.curSymbol.getFrameLabelNames(); switchGF("bf"); } - var _addedCallback:String = ""; - - override public function playAnimation(id:String, restart:Bool = false, ignoreOther:Bool = false, loop:Bool = false, startFrame:Int = 0):Void - { - if (id == null) id = "idle"; - // var fr = anim.getFrameLabel("confirm"); - // fr.removeCallbacks(); - // fr.add(() -> trace("HEY")); - - if (id != _addedCallback) - { - var next = list[list.indexOf(_addedCallback) + 1]; - if (next != null) anim.getFrameLabel(next).removeCallbacks(); - - var index:Int = list.indexOf(id); - - _addedCallback = list[index]; - if (index != -1 && index + 1 < list.length) - { - var lb = anim.getFrameLabel(list[index + 1]); - @:privateAccess - lb.add(() -> playAnimation(list[index], true, false, false)); - } - } - super.playAnimation(id, restart, ignoreOther, loop, startFrame); - } - override public function update(elapsed:Float) { super.update(elapsed); @@ -190,9 +163,8 @@ class CharSelectGF extends FlxAtlasSprite animInInfo = FramesJSFLParser.parse(Paths.file("images/charSelect/" + str + "AnimInfo/" + str + "In.txt")); animOutInfo = FramesJSFLParser.parse(Paths.file("images/charSelect/" + str + "AnimInfo/" + str + "Out.txt")); - anim.play(""); - playAnimation("idle", true, false, false); - addFrameCallback(getNextFrameLabel("idle"), () -> playAnimation("idle", true, false, false)); + playAnimation("idle", true, false, true); + // addFrameCallback(getNextFrameLabel("idle"), () -> playAnimation("idle", true, false, false)); updateHitbox(); } diff --git a/source/funkin/ui/charSelect/CharSelectPlayer.hx b/source/funkin/ui/charSelect/CharSelectPlayer.hx index 8a5d57530..07c82d038 100644 --- a/source/funkin/ui/charSelect/CharSelectPlayer.hx +++ b/source/funkin/ui/charSelect/CharSelectPlayer.hx @@ -2,82 +2,33 @@ package funkin.ui.charSelect; import flixel.FlxSprite; import funkin.graphics.adobeanimate.FlxAtlasSprite; +import flxanimate.animate.FlxKeyFrame; class CharSelectPlayer extends FlxAtlasSprite { + var desLp:FlxKeyFrame = null; + public function new(x:Float, y:Float) { super(x, y, Paths.animateAtlas("charSelect/bfChill")); + desLp = anim.getFrameLabel("deselect loop start"); + onAnimationComplete.add(function(animLabel:String) { - if (hasAnimation("slidein idle point")) playAnimation("slidein idle point", true, false, false); - else - playAnimation("idle"); + switch (animLabel) + { + case "slidein": + if (hasAnimation("slidein idle point")) playAnimation("slidein idle point", true, false, false); + else + playAnimation("idle", true, false, true); + case "slidein idle point": + playAnimation("idle", true, false, true); + } }); - } - var _addedCall = false; - - override public function playAnimation(id:String, restart:Bool = false, ignoreOther:Bool = false, loop:Bool = false, startFrame:Int = 0):Void - { - if (id == null || id == "") id = "idle"; - switch (id) - { - case "idle", "slidein idle point": - if (!_addedCall) - { - var fr = anim.getFrameLabel("idle end"); - if (fr != null) fr.add(() -> { - playAnimation("idle", true, false, false); - }); - } - _addedCall = true; - - case "select": - if (_addedCall) - { - anim.getFrameLabel("idle end").removeCallbacks(); - _addedCall = false; - } - - var fr = anim.getFrameLabel("deselect"); - - fr.add(() -> { - anim.pause(); - anim.curFrame--; - }); - - _addedCall = true; - - case "deselect": - var og = anim.getFrameLabel("deselect"); - if (_addedCall) - { - og.removeCallbacks(); - _addedCall = false; - } - - var fr = anim.getFrameLabel("deselect loop end"); - - fr.removeCallbacks(); - fr.add(() -> playAnimation("deselect loop start", true, false, false)); - - _addedCall = true; - - case "slidein", "slideout": - if (_addedCall) - { - anim.getFrameLabel("deselect loop end").removeCallbacks(); - _addedCall = false; - } - default: - if (_addedCall) - { - anim.getFrameLabel("idle end").removeCallbacks(); - _addedCall = false; - } - } - super.playAnimation(id, restart, ignoreOther, loop, startFrame); + onAnimationFrame.add(function(animLabel:String, frame:Int) { + if (animLabel == "deselect" && desLp != null && frame >= desLp.index) playAnimation("deselect loop start", true, false, true); + }); } public function updatePosition(str:String) @@ -104,6 +55,8 @@ class CharSelectPlayer extends FlxAtlasSprite playAnimation("slidein", true, false, false); + desLp = anim.getFrameLabel("deselect loop start"); + updateHitbox(); updatePosition(str); diff --git a/source/funkin/ui/charSelect/CharSelectSubState.hx b/source/funkin/ui/charSelect/CharSelectSubState.hx index 2b577dd95..9aed0ef02 100644 --- a/source/funkin/ui/charSelect/CharSelectSubState.hx +++ b/source/funkin/ui/charSelect/CharSelectSubState.hx @@ -499,12 +499,8 @@ class CharSelectSubState extends MusicBeatSubState { ease: FlxEase.quartInOut, onComplete: (_) -> { - var fr = playerChill.anim.getFrameLabel("deselect loop end"); - if (fr != null) fr.removeCallbacks(); - @:privateAccess - playerChill._addedCall = false; - playerChill.playAnimation("idle"); - gfChill.playAnimation("idle"); + playerChill.playAnimation("idle", true, false, true); + gfChill.playAnimation("idle", true, false, true); } }); pressedSelect = false; @@ -645,20 +641,23 @@ class CharSelectSubState extends MusicBeatSubState nametag.switchChar(value); playerChill.visible = false; playerChillOut.visible = true; - playerChillOut.anim.goToFrameLabel("slideout"); + playerChillOut.playAnimation("slideout"); + var index = playerChillOut.anim.getFrameLabel("slideout").index; playerChillOut.onAnimationFrame.add((_, frame:Int) -> { - if (frame == playerChillOut.anim.getFrameLabel("slideout").index + 1) + if (frame == index + 1) { playerChill.visible = true; playerChill.switchChar(value); gfChill.switchGF(value); } - if (frame == playerChillOut.anim.getFrameLabel("slideout").index + 2) + if (frame == index + 2) { playerChillOut.switchChar(value); playerChillOut.visible = false; + playerChillOut.onAnimationFrame.removeAll(); } }); + return value; } diff --git a/source/funkin/ui/freeplay/AlbumRoll.hx b/source/funkin/ui/freeplay/AlbumRoll.hx index 36dba0054..64b86120c 100644 --- a/source/funkin/ui/freeplay/AlbumRoll.hx +++ b/source/funkin/ui/freeplay/AlbumRoll.hx @@ -60,7 +60,7 @@ class AlbumRoll extends FlxSpriteGroup { super(); - newAlbumArt = new FlxAtlasSprite(640, 350, Paths.animateAtlas("freeplay/albumRoll/freeplayAlbum")); + newAlbumArt = new FlxAtlasSprite(640, 360, Paths.animateAtlas("freeplay/albumRoll/freeplayAlbum")); newAlbumArt.visible = false; newAlbumArt.onAnimationComplete.add(onAlbumFinish); @@ -79,7 +79,7 @@ class AlbumRoll extends FlxSpriteGroup // Play the idle animation for the current album. if (animName != "idle") { - // newAlbumArt.playAnimation('idle', true); + newAlbumArt.playAnimation('idle', true); } } diff --git a/source/funkin/ui/freeplay/FreeplayState.hx b/source/funkin/ui/freeplay/FreeplayState.hx index 63767d28e..d30bb3e8c 100644 --- a/source/funkin/ui/freeplay/FreeplayState.hx +++ b/source/funkin/ui/freeplay/FreeplayState.hx @@ -643,6 +643,9 @@ class FreeplayState extends MusicBeatSubState // when boyfriend hits dat shiii albumRoll.playIntro(); + var daSong = grpCapsules.members[curSelected].songData; + albumRoll.albumId = daSong?.albumId; + FlxTween.tween(grpDifficulties, {x: 90}, 0.6, {ease: FlxEase.quartOut});