Skip to content

Commit

Permalink
play animations when changing rank
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed Nov 19, 2024
1 parent ca95bec commit b34df43
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ResultsAnimDialog extends DefaultPageDialog
rankDropdown.onChange = function(_) {
if (previousRank == currentRank) return;

daPage.stopTimers();
updateRankAnimations(previousRank);

for (atlas in characterAtlasAnimationsMap[previousRank])
atlas.sprite.visible = false;
Expand All @@ -76,12 +76,27 @@ class ResultsAnimDialog extends DefaultPageDialog

rankAnimationBox.useAnimationData(rankAnimationDataMap[currentRank]);
previousRank = currentRank;

daPage.playAnimation();
}

rankAnimationBox.useAnimationData(rankAnimationDataMap[currentRank]);
previousRank = currentRank;
}

function updateRankAnimations(rank:ScoringRank):Void
{
var parentList = rankAnimationBox.parentComponent;
if (parentList == null) return;

var animations = [
for (animData in parentList.childComponents)
if (Std.isOfType(animData, RankAnimationData)) cast(animData, RankAnimationData).animData
];

rankAnimationDataMap.set(rank, animations);
}

function createAnimations(rank:ScoringRank, playerAnimations:Array<PlayerResultsAnimationData>):Void
{
var atlasAnimations = [];
Expand Down Expand Up @@ -322,6 +337,24 @@ private class AddRankAnimationDataBox extends HBox
')
private class RankAnimationData extends VBox
{
public var animData(get, never):PlayerResultsAnimationData;

function get_animData():PlayerResultsAnimationData
{
return {
renderType: animRenderType.selectedItem.value,
assetPath: animAssetPath.text,
offsets: [animOffsetX.value, animOffsetY.value],
zIndex: animZIndex.value,
delay: animDelay.value,
scale: animScale.value,
startFrameLabel: animStartFrameLabel.text,
looped: animLooped.selected,
loopFrame: animLoopFrame.value,
loopFrameLabel: animLoopFrameLabel.text,
};
}

public function new(?data:PlayerResultsAnimationData)
{
super();
Expand Down
59 changes: 33 additions & 26 deletions source/funkin/ui/debug/char/pages/CharCreatorResultsPage.hx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class CharCreatorResultsPage extends CharCreatorDefaultPage
initFunkinUI();

refresh();

playAnimation();
}

override public function fillUpPageSettings(menu:Menu):Void
Expand All @@ -62,35 +64,40 @@ class CharCreatorResultsPage extends CharCreatorDefaultPage

if (FlxG.keys.justPressed.SPACE)
{
stopTimers();

refresh(); // just to be sure

var animDialog:ResultsAnimDialog = cast dialogMap[RankAnims];

for (atlas in animDialog.characterAtlasAnimations)
{
atlas.sprite.visible = false;
animTimers.push(new FlxTimer().start(atlas.delay, _ -> {
if (atlas.sprite == null) return;
atlas.sprite.visible = true;
atlas.sprite.anim.play('', true);
}));
}

for (sprite in animDialog.characterSparrowAnimations)
{
sprite.sprite.visible = false;
animTimers.push(new FlxTimer().start(sprite.delay, _ -> {
if (sprite.sprite == null) return;
sprite.sprite.visible = true;
sprite.sprite.animation.play('idle', true);
}));
}
playAnimation();
}
}

public function playAnimation():Void
{
stopTimers();

refresh(); // just to be sure

var animDialog:ResultsAnimDialog = cast dialogMap[RankAnims];

for (atlas in animDialog.characterAtlasAnimations)
{
atlas.sprite.visible = false;
animTimers.push(new FlxTimer().start(atlas.delay, _ -> {
if (atlas.sprite == null) return;
atlas.sprite.visible = true;
atlas.sprite.anim.play('', true);
}));
}

for (sprite in animDialog.characterSparrowAnimations)
{
sprite.sprite.visible = false;
animTimers.push(new FlxTimer().start(sprite.delay, _ -> {
if (sprite.sprite == null) return;
sprite.sprite.visible = true;
sprite.sprite.animation.play('idle', true);
}));
}
}

public function stopTimers():Void
function stopTimers():Void
{
while (animTimers.length > 0)
{
Expand Down

0 comments on commit b34df43

Please sign in to comment.