Skip to content

Commit

Permalink
more rank anims updating work + rank anims export
Browse files Browse the repository at this point in the history
  • Loading branch information
KoloInDaCrib committed Dec 3, 2024
1 parent ae2818f commit c9fc9e1
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import haxe.ui.containers.dialogs.CollapsibleDialog;

class DefaultPageDialog extends CollapsibleDialog
{
var page:CharCreatorDefaultPage = null;
public var page:CharCreatorDefaultPage = null;

override public function new(page:CharCreatorDefaultPage)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ import funkin.data.freeplay.player.PlayerData;
import funkin.data.freeplay.player.PlayerRegistry;
import funkin.play.scoring.Scoring.ScoringRank;
import funkin.graphics.adobeanimate.FlxAtlasSprite;
import funkin.ui.debug.char.animate.CharSelectAtlasSprite;
import funkin.graphics.FunkinSprite;
import funkin.ui.debug.char.pages.CharCreatorResultsPage;
import flixel.FlxSprite;

@:build(haxe.ui.macros.ComponentMacros.build("assets/exclude/data/ui/char-creator/dialogs/results/results-anim-dialog.xml"))
@:access(funkin.ui.debug.char.pages.CharCreatorResultsPage)
class ResultsAnimDialog extends DefaultPageDialog
{
public var currentRank(get, never):ScoringRank;

var rankAnimationDataMap:Map<ScoringRank, Array<PlayerResultsAnimationData>> = [];
public var rankAnimationDataMap:Map<ScoringRank, Array<PlayerResultsAnimationData>> = [];
public var previousRank:ScoringRank;

var rankAnimationBox:AddRankAnimationDataBox;

var previousRank:ScoringRank;

override public function new(daPage:CharCreatorResultsPage)
{
super(daPage);
Expand All @@ -34,7 +35,7 @@ class ResultsAnimDialog extends DefaultPageDialog
rankAnimationDataMap.set(rank, playerAnimations);
}

rankAnimationBox = new AddRankAnimationDataBox(daPage);
rankAnimationBox = new AddRankAnimationDataBox(this);
rankAnimationView.addComponent(rankAnimationBox);

rankDropdown.selectedIndex = 0;
Expand Down Expand Up @@ -89,10 +90,10 @@ private class AddRankAnimationDataBox extends HBox

var page:CharCreatorResultsPage;

public function new(daPage:CharCreatorResultsPage)
public function new(daDialog:ResultsAnimDialog)
{
super();
page = daPage;
page = cast (daDialog.page, CharCreatorResultsPage);

styleString = "border:1px solid $normal-border-color";
percentWidth = 100;
Expand All @@ -111,7 +112,10 @@ private class AddRankAnimationDataBox extends HBox
var parentList = this.parentComponent;
if (parentList == null) return;

parentList.addComponentAt(createNewBox(), parentList.childComponents.length - 1); // considering this box is last
var newBox = createNewBox();
daDialog.rankAnimationDataMap[daDialog.previousRank].push(newBox.animData);

parentList.addComponentAt(newBox, parentList.childComponents.length - 1); // considering this box is last
removeButton.disabled = false;
}

Expand All @@ -121,7 +125,17 @@ private class AddRankAnimationDataBox extends HBox
if (parentList == null) return;

parentList.removeComponentAt(parentList.childComponents.length - 2);
if (parentList.childComponents.length <= 2) removeButton.disabled = true;

var daData = page.currentAnims.pop();
var daDataSprite = cast (daData.sprite, FlxSprite);

daDataSprite.kill();
page.remove(daDataSprite, true);
daDataSprite.destroy();

daDialog.rankAnimationDataMap[daDialog.previousRank].pop();

if (parentList.childComponents.length < 2) removeButton.disabled = true;
}

addComponent(addButton);
Expand All @@ -140,7 +154,7 @@ private class AddRankAnimationDataBox extends HBox
parentList.addComponentAt(createNewBox(animData), parentList.childComponents.length - 1);
}

removeButton.disabled = parentList.childComponents.length <= 2;
removeButton.disabled = parentList.childComponents.length < 2;
}

function clearAnimationData():Void
Expand All @@ -160,20 +174,108 @@ private class AddRankAnimationDataBox extends HBox
if (parentList == null) return newBox;

newBox.ID = parentList.childComponents.length - 1;
if (page.currentAnims.length <= newBox.ID)
{
page.currentAnims.push(
{
sprite: null,
delay: newBox.animData.delay
});
}

newBox.onOffsetsChange = function() {
var obj = page.currentAnims[newBox.ID];
if (obj == null) return;
if (obj?.sprite == null) return;
cast(obj.sprite, FlxSprite).setPosition(newBox.animOffsetX.pos, newBox.animOffsetY.pos);
copyData(data, newBox.animData);
}

newBox.animZIndex.onChange = function(_) {
var obj = page.currentAnims[newBox.ID];
if (obj?.sprite == null) return;

cast(obj.sprite, FlxSprite).zIndex = Std.int(newBox.animZIndex.pos);
page.refresh();
copyData(data, newBox.animData);
}

newBox.animScale.onChange = function(_) {
var obj = page.currentAnims[newBox.ID];
if (obj?.sprite == null) return;
cast(obj.sprite, FlxSprite).scale.set(newBox.animScale.pos, newBox.animScale.pos);
copyData(data, newBox.animData);
}

var atlas = (Std.isOfType(obj.sprite, FlxAtlasSprite) ? cast(obj.sprite, FlxAtlasSprite) : null);
newBox.onLoopDataChange = function()
{
var obj = page.currentAnims[newBox.ID];
if (obj?.sprite == null) return;

var atlas = (Std.isOfType(obj.sprite, CharSelectAtlasSprite) ? cast(obj.sprite, CharSelectAtlasSprite) : null);
var sparrow = (Std.isOfType(obj.sprite, FunkinSprite) ? cast(obj.sprite, FunkinSprite) : null);

if (atlas != null) atlas.setPosition(newBox.animOffsetX.pos, newBox.animOffsetY.pos);
if (sparrow != null) sparrow.setPosition(newBox.animOffsetX.pos, newBox.animOffsetY.pos);
if (sparrow != null)
{
sparrow.animation.finishCallback = (_name:String) -> {
if (animation != null)
{
sparrow.animation.play('idle', true, false, newBox.animData.loopFrame ?? 0);
}
}
}
else if (atlas != null)
{
atlas.onAnimationFrame.removeAll();
atlas.onAnimationComplete.removeAll();

if (!(newBox.animData.looped ?? true))
{
atlas.onAnimationComplete.add((_name:String) -> {
if (atlas != null) atlas.anim.pause();
});
}
else if (newBox.animData.loopFrameLabel != null)
{
atlas.onAnimationComplete.add((_name:String) -> {
if (atlas != null) atlas.playAnimation(newBox.animData.loopFrameLabel ?? '', true, false, true); // unpauses this anim, since it's on PlayOnce!
});
}
else if (newBox.animData.loopFrame != null)
{
atlas.onAnimationComplete.add((_name:String) -> {
if (atlas != null)
{
atlas.anim.curFrame = newBox.animData.loopFrame ?? 0;
atlas.anim.play(); // unpauses this anim, since it's on PlayOnce!
}
});
}
}

copyData(data, newBox.animData);
}

return newBox;
}

function copyData(?oldData:PlayerResultsAnimationData, newData:PlayerResultsAnimationData) //this is how we update data
{
if (oldData != null)
{
oldData.renderType = newData.renderType;
oldData.assetPath = newData.assetPath;
oldData.offsets = newData.offsets.copy();
oldData.zIndex = newData.zIndex;
oldData.delay = newData.delay;
oldData.scale = newData.scale;
oldData.looped = newData.looped;
oldData.loopFrame = newData.loopFrame;
oldData.loopFrameLabel = newData.loopFrameLabel;
}

if (oldData == null) oldData = newData;

}
}

@:xml('
Expand Down Expand Up @@ -296,7 +398,10 @@ private class RankAnimationData extends VBox
}

animOffsetX.onChange = animOffsetY.onChange = _ -> onOffsetsChange();
animLooped.onChange = animLoopFrame.onChange = animLoopFrameLabel.onChange = _ -> onLoopDataChange();
}

public dynamic function onOffsetsChange() {}

public dynamic function onLoopDataChange() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package funkin.ui.debug.char.handlers;
import haxe.io.Path;
import funkin.data.character.CharacterRegistry;
import funkin.ui.debug.char.components.dialogs.freeplay.FreeplayDJSettingsDialog;
import funkin.ui.debug.char.components.dialogs.results.ResultsAnimDialog;
import funkin.ui.debug.char.pages.CharCreatorGameplayPage;
import funkin.ui.debug.char.pages.CharCreatorSelectPage;
import funkin.ui.debug.char.pages.CharCreatorFreeplayPage;
import funkin.ui.debug.char.pages.CharCreatorResultsPage;
import funkin.ui.debug.char.CharCreatorState;
import funkin.data.freeplay.player.PlayerData;
import funkin.data.freeplay.style.FreeplayStyleData;
import funkin.play.scoring.Scoring.ScoringRank;
import funkin.util.FileUtil;

using StringTools;
Expand Down Expand Up @@ -102,20 +105,10 @@ class CharCreatorImportExportHandler
public static function exportPlayableCharacter(state:CharCreatorState, zipEntries:Array<haxe.zip.Entry>):Void
{
var selectPage:CharCreatorSelectPage = cast state.pages[CharacterSelect];
var charID = selectPage.data.importedCharacter ?? selectPage.data.characterID;

var freeplayPage:CharCreatorFreeplayPage = cast state.pages[Freeplay];
var resultPage:CharCreatorResultsPage = cast state.pages[ResultScreen];

// for (file in selectPage.iconFiles)
// {
// // skip if the file is in a character path
// if (CharCreatorUtil.isPathProvided(file.name, "images/freeplay/icons"))
// {
// continue;
// }

// zipEntries.push(FileUtil.makeZIPEntryFromBytes('images/freeplay/icons/${Path.withoutDirectory(file.name)}', file.bytes));
// }
var charID = selectPage.data.importedCharacter ?? selectPage.data.characterID;

if (selectPage.data.charSelectFile != null)
{
Expand Down Expand Up @@ -181,8 +174,20 @@ class CharCreatorImportExportHandler
}
}

var resultPageDialog:ResultsAnimDialog = cast resultPage.dialogMap[RankAnims];

playerData.charSelect = new PlayerCharSelectData(selectPage.position);
playerData.results = null;
playerData.results =
{
music: null,
perfectGold: resultPageDialog.rankAnimationDataMap[PERFECT_GOLD],
perfect: resultPageDialog.rankAnimationDataMap[PERFECT],
excellent: resultPageDialog.rankAnimationDataMap[EXCELLENT],
great: resultPageDialog.rankAnimationDataMap[GREAT],
good: resultPageDialog.rankAnimationDataMap[GOOD],
loss: resultPageDialog.rankAnimationDataMap[SHIT],
};

playerData.unlocked = true;

zipEntries.push(FileUtil.makeZIPEntry('data/players/${charID}.json', playerData.serialize()));
Expand Down
13 changes: 7 additions & 6 deletions source/funkin/ui/debug/char/pages/CharCreatorResultsPage.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import haxe.ui.containers.menus.Menu;
import haxe.ui.containers.menus.MenuItem;
import haxe.ui.containers.menus.MenuCheckBox;
import funkin.graphics.adobeanimate.FlxAtlasSprite;
import funkin.ui.debug.char.animate.CharSelectAtlasSprite;
import funkin.graphics.FunkinSprite;
import funkin.ui.debug.char.components.dialogs.results.*;
import funkin.ui.debug.char.components.dialogs.DefaultPageDialog;
Expand Down Expand Up @@ -41,7 +42,7 @@ class CharCreatorResultsPage extends CharCreatorDefaultPage

var data:WizardGenerateParams;

var dialogMap:Map<ResultsDialogType, DefaultPageDialog>;
public var dialogMap:Map<ResultsDialogType, DefaultPageDialog>;

var rankMusicMap:Map<ScoringRank, ResultsMusic> = [];

Expand Down Expand Up @@ -158,7 +159,7 @@ class CharCreatorResultsPage extends CharCreatorDefaultPage
while (currentAnims.length > 0)
{
var data = currentAnims.shift();
var atlas = (Std.isOfType(data.sprite, FlxAtlasSprite) ? cast(data.sprite, FlxAtlasSprite) : null);
var atlas = (Std.isOfType(data.sprite, CharSelectAtlasSprite) ? cast(data.sprite, CharSelectAtlasSprite) : null);
var sparrow = (Std.isOfType(data.sprite, FunkinSprite) ? cast(data.sprite, FunkinSprite) : null);

if (atlas != null)
Expand Down Expand Up @@ -190,7 +191,7 @@ class CharCreatorResultsPage extends CharCreatorDefaultPage
switch (animData.renderType)
{
case 'animateatlas':
var animation:FlxAtlasSprite = new FlxAtlasSprite(offsets[0], offsets[1], Paths.animateAtlas(animPath, animLibrary));
var animation:CharSelectAtlasSprite = new CharSelectAtlasSprite(offsets[0], offsets[1], Paths.animateAtlas(animPath, animLibrary));
animation.zIndex = animData.zIndex ?? 500;

animation.scale.set(animData.scale ?? 1.0, animData.scale ?? 1.0);
Expand Down Expand Up @@ -374,7 +375,7 @@ class CharCreatorResultsPage extends CharCreatorDefaultPage

for (bs in currentAnims)
{
var atlas = (Std.isOfType(bs.sprite, FlxAtlasSprite) ? cast(bs.sprite, FlxAtlasSprite) : null);
var atlas = (Std.isOfType(bs.sprite, CharSelectAtlasSprite) ? cast(bs.sprite, CharSelectAtlasSprite) : null);
var sparrow = (Std.isOfType(bs.sprite, FunkinSprite) ? cast(bs.sprite, FunkinSprite) : null);
if (atlas == null && sparrow == null) continue;

Expand Down Expand Up @@ -542,7 +543,7 @@ class CharCreatorResultsPage extends CharCreatorDefaultPage
add(score);
}

function refresh():Void
public function refresh():Void
{
sort(SortUtil.byZIndex, FlxSort.ASCENDING);
}
Expand Down Expand Up @@ -597,7 +598,7 @@ private class ResultsMusic

typedef CharCreatorResultAnim =
{
var sprite:flixel.util.typeLimit.OneOfTwo<FlxAtlasSprite, FunkinSprite>;
var ?sprite:flixel.util.typeLimit.OneOfTwo<CharSelectAtlasSprite, FunkinSprite>;
var delay:Float;
}

Expand Down

0 comments on commit c9fc9e1

Please sign in to comment.