Skip to content

Commit

Permalink
use CharacterRenderType and fix animate atlas ghost and offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed Nov 2, 2024
1 parent 886c332 commit 6ad9d74
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 26 deletions.
15 changes: 9 additions & 6 deletions source/funkin/ui/debug/char/CharCreatorCharacter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import openfl.display.BitmapData;
import funkin.data.animation.AnimationData;
import funkin.play.character.BaseCharacter.CharacterType;
import funkin.data.character.CharacterData;
import funkin.data.character.CharacterData.CharacterRenderType;
import funkin.data.character.CharacterRegistry;
import funkin.ui.debug.char.animate.CharSelectAtlasSprite;
import funkin.play.stage.Bopper;
Expand All @@ -22,7 +23,7 @@ class CharCreatorCharacter extends Bopper
{
public var generatedParams:WizardGenerateParams;
public var characterId(get, never):String;
public var renderType(get, never):String;
public var renderType(get, never):CharacterRenderType;
public var files(get, never):Array<WizardFile>;

public var characterName:String = "Unknown";
Expand Down Expand Up @@ -52,7 +53,7 @@ class CharCreatorCharacter extends Bopper

switch (generatedParams.renderType)
{
case "sparrow" | "multisparrow":
case CharacterRenderType.Sparrow | CharacterRenderType.MultiSparrow:
if (generatedParams.files.length < 2) return; // img and data

var combinedFrames = null;
Expand All @@ -67,14 +68,14 @@ class CharCreatorCharacter extends Bopper
}
this.frames = combinedFrames;

case "packer":
case CharacterRenderType.Packer:
if (generatedParams.files.length != 2) return; // img and data

var img = BitmapData.fromBytes(generatedParams.files[0].bytes);
var data = generatedParams.files[1].bytes.toString();
this.frames = FlxAtlasFrames.fromSpriteSheetPacker(img, data);

case "atlas": // todo
case CharacterRenderType.AnimateAtlas: // todo
if (generatedParams.files.length != 1) return; // zip file with all the data
atlasCharacter = new CharSelectAtlasSprite(0, 0, generatedParams.files[0].bytes);

Expand Down Expand Up @@ -102,6 +103,7 @@ class CharCreatorCharacter extends Bopper
{
atlasCharacter.x = this.x;
atlasCharacter.y = this.y;
atlasCharacter.alpha = this.alpha;
atlasCharacter.flipX = this.flipX;
atlasCharacter.flipY = this.flipY;
atlasCharacter.moves = this.moves;
Expand All @@ -115,7 +117,7 @@ class CharCreatorCharacter extends Bopper
atlasCharacter.exists = this.exists;
atlasCharacter.camera = this.camera;
atlasCharacter.cameras = this.cameras;
atlasCharacter.offset.copyFrom(this.offset);
atlasCharacter.offset.set(animOffsets[0], animOffsets[1]);
atlasCharacter.origin.copyFrom(this.origin);
atlasCharacter.scale.copyFrom(this.scale);
atlasCharacter.scrollFactor.copyFrom(this.scrollFactor);
Expand All @@ -138,7 +140,7 @@ class CharCreatorCharacter extends Bopper
{
if (getAnimationData(name) != null) return true; // i mean i guess???

if (renderType != "atlas")
if (renderType != CharacterRenderType.AnimateAtlas)
{
if (indices.length > 0) animation.addByIndices(name, prefix, indices, "", frameRate, looped, flipX, flipY);
else
Expand Down Expand Up @@ -206,6 +208,7 @@ class CharCreatorCharacter extends Bopper
var loop:Bool = animData.looped;

atlasCharacter.playAnimation(prefix, restart, ignoreOther, loop);
applyAnimationOffsets(correctName);
}

public override function hasAnimation(name:String):Bool
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package funkin.ui.debug.char.components.dialogs;

import funkin.ui.debug.char.pages.CharCreatorGameplayPage.CharDialogType;
import funkin.data.character.CharacterData.CharacterRenderType;
import haxe.ui.containers.dialogs.CollapsibleDialog;
import haxe.ui.data.ArrayDataSource;

Expand All @@ -15,11 +16,11 @@ class AddAnimDialog extends DefaultPageDialog
linkedChar = char;

// dialog callback bs
charAnimFrames.disabled = charAnimFlipX.disabled = charAnimFlipY.disabled = charAnimFramerate.disabled = (char.renderType == "atlas");
charAnimFrames.tooltip = charAnimFlipX.tooltip = charAnimFlipY.tooltip = charAnimFramerate.tooltip = (char.renderType == "atlas" ? "Unavailable for Atlas Characters." : null);
charAnimFrames.disabled = charAnimFlipX.disabled = charAnimFlipY.disabled = charAnimFramerate.disabled = (char.renderType == CharacterRenderType.AnimateAtlas);
charAnimFrames.tooltip = charAnimFlipX.tooltip = charAnimFlipY.tooltip = charAnimFramerate.tooltip = (char.renderType == CharacterRenderType.AnimateAtlas ? "Unavailable for Atlas Characters." : null);

charAnimFrameList.dataSource = new ArrayDataSource();
if (char.renderType != "atlas")
if (char.renderType != CharacterRenderType.AnimateAtlas)
{
for (fname in char.frames.frames)
if (fname != null) charAnimFrameList.dataSource.add({name: fname.name});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import funkin.ui.debug.char.handlers.CharCreatorStartupWizard;
import funkin.util.FileUtil;
import flxanimate.data.AnimationData.AnimAtlas;
import flxanimate.data.SpriteMapData.AnimateAtlas;
import funkin.data.character.CharacterData.CharacterRenderType;
import flixel.graphics.frames.FlxAtlasFrames;
import flixel.FlxSprite;
import openfl.display.BitmapData;
Expand Down Expand Up @@ -38,15 +39,20 @@ class AddCharFilesDialog extends DefaultWizardDialog

switch (params.renderType)
{
case "sparrow":
case CharacterRenderType.Sparrow:
addAssetsBox.addComponent(new UploadAssetsBox("Put the path to the Spritesheet Image here.", FileUtil.FILE_EXTENSION_INFO_PNG));
case "multisparrow":

case CharacterRenderType.MultiSparrow:
recursiveUploadBox();
case "packer":

case CharacterRenderType.Packer:
addAssetsBox.addComponent(new UploadAssetsBox("Put the path to the Spritesheet Image here.", FileUtil.FILE_EXTENSION_INFO_PNG));

case "atlas":
case CharacterRenderType.AnimateAtlas:
addAssetsBox.addComponent(new UploadAssetsBox("Put the path to the Atlas .zip Data Here", FileUtil.FILE_EXTENSION_INFO_ZIP));

default:
// this should never happen, right?
}

stupidFuckingRenderCheck = params.renderType;
Expand Down Expand Up @@ -86,7 +92,7 @@ class AddCharFilesDialog extends DefaultWizardDialog
{
switch (params.renderType)
{
case "sparrow" | "multisparrow":
case CharacterRenderType.Sparrow | CharacterRenderType.MultiSparrow:
var files = [];
for (uploadBox in uploadBoxes)
{
Expand Down Expand Up @@ -128,7 +134,7 @@ class AddCharFilesDialog extends DefaultWizardDialog

return true;

case "packer": // essentially just sparrow...but different!
case CharacterRenderType.Packer: // essentially just sparrow...but different!
var imgPath = uploadBoxes[0].daField.text;
var txtPath = uploadBoxes[0].daField.text.replace(".png", ".txt");

Expand Down Expand Up @@ -157,7 +163,7 @@ class AddCharFilesDialog extends DefaultWizardDialog

return true;

case "atlas":
case CharacterRenderType.AnimateAtlas:
var zipPath = uploadBoxes[0].daField.text;

// checking if we even have the correct file types in the correct places
Expand Down Expand Up @@ -205,6 +211,9 @@ class AddCharFilesDialog extends DefaultWizardDialog

if (hasAnimData && hasSpritemapData && hasImageData) params.files.push({name: zipPath, bytes: zipBytes});
return hasAnimData && hasSpritemapData && hasImageData;

default:
return false;
}

return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
package funkin.ui.debug.char.components.wizard;

import funkin.data.character.CharacterData.CharacterRenderType;

@:build(haxe.ui.macros.ComponentMacros.build("assets/exclude/data/ui/char-creator/wizard/sprite-support.xml"))
class RenderWizardDialog extends DefaultWizardDialog
{
override public function new()
{
super(SELECT_CHAR_TYPE);

renderOptionSparrow.onChange = function(_) params.renderType = "sparrow";
renderOptionPacker.onChange = function(_) params.renderType = "packer";
renderOptionAtlas.onChange = function(_) params.renderType = "atlas";
renderOptionMulti.onChange = function(_) params.renderType = "multisparrow";
renderOptionSparrow.onChange = function(_) params.renderType = CharacterRenderType.Sparrow;
renderOptionPacker.onChange = function(_) params.renderType = CharacterRenderType.Packer;
renderOptionAtlas.onChange = function(_) params.renderType = CharacterRenderType.AnimateAtlas;
renderOptionMulti.onChange = function(_) params.renderType = CharacterRenderType.MultiSparrow;
}

override public function showDialog(modal:Bool = true)
{
super.showDialog(modal);
renderOptionSparrow.disabled = renderOptionPacker.disabled = renderOptionAtlas.disabled = renderOptionMulti.disabled = !params.generateCharacter;

renderOptionSparrow.selected = params.renderType == "sparrow";
renderOptionPacker.selected = params.renderType == "packer";
renderOptionAtlas.selected = params.renderType == "atlas";
renderOptionMulti.selected = params.renderType == "multisparrow";
renderOptionSparrow.selected = params.renderType == CharacterRenderType.Sparrow;
renderOptionPacker.selected = params.renderType == CharacterRenderType.Packer;
renderOptionAtlas.selected = params.renderType == CharacterRenderType.AnimateAtlas;
renderOptionMulti.selected = params.renderType == CharacterRenderType.MultiSparrow;
}

override public function isNextStepAvailable()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package funkin.ui.debug.char.handlers;

import funkin.data.character.CharacterData.CharacterRenderType;
import funkin.ui.debug.char.components.wizard.*;
import haxe.ui.containers.dialogs.Dialog;
import haxe.io.Bytes;
Expand All @@ -18,7 +19,7 @@ class CharCreatorStartupWizard
characterID: "",
generateCharacter: false,
generatePlayerData: false,
renderType: "sparrow",
renderType: CharacterRenderType.Sparrow,
files: []
}

Expand Down Expand Up @@ -58,7 +59,7 @@ typedef WizardGenerateParams =
var characterID:String;
var generateCharacter:Bool;
var generatePlayerData:Bool;
var renderType:String;
var renderType:CharacterRenderType;
var files:Array<WizardFile>;
}

Expand Down

0 comments on commit 6ad9d74

Please sign in to comment.