Skip to content

Commit

Permalink
fix some multisparrow stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed Nov 1, 2024
1 parent d8f3e6a commit 9bf898a
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 55 deletions.
4 changes: 2 additions & 2 deletions source/funkin/ui/debug/char/CharCreatorCharacter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ class CharCreatorCharacter extends Bopper
}
}

public function addAnimation(name:String, prefix:String, offsets:Array<Float>, indices:Array<Int>, animPath:String = "", frameRate:Int = 24,
looped:Bool = false, flipX:Bool = false, flipY:Bool = false)
public function addAnimation(name:String, prefix:String, offsets:Array<Float>, indices:Array<Int>, frameRate:Int = 24, looped:Bool = false,
flipX:Bool = false, flipY:Bool = false)
{
if (getAnimationData(name) != null) return true; // i mean i guess???

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,13 @@ class AddAnimDialog extends DefaultPageDialog

var shouldDoIndices:Bool = (indices.length > 0 && !indices.contains(null));
var animAdded:Bool = char.addAnimation(charAnimName.text, charAnimPrefix.text, [charAnimOffsetX.pos, charAnimOffsetY.pos],
(shouldDoIndices ? indices : []), charAnimPath.text, Std.int(charAnimFramerate.pos), charAnimLooped.selected, charAnimFlipX.selected,
charAnimFlipY.selected);
(shouldDoIndices ? indices : []), Std.int(charAnimFramerate.pos), charAnimLooped.selected, charAnimFlipX.selected, charAnimFlipY.selected);

if (!animAdded) return;
char.playAnimation(charAnimName.text);

cast(page, CharCreatorGameplayPage).ghostCharacter.addAnimation(charAnimName.text, charAnimPrefix.text, [charAnimOffsetX.pos, charAnimOffsetY.pos],
(shouldDoIndices ? indices : []), charAnimPath.text, Std.int(charAnimFramerate.pos), charAnimLooped.selected, charAnimFlipX.selected,
charAnimFlipY.selected);
(shouldDoIndices ? indices : []), Std.int(charAnimFramerate.pos), charAnimLooped.selected, charAnimFlipX.selected, charAnimFlipY.selected);

updateDropdown();
charAnimDropdown.selectedIndex = charAnimDropdown.dataSource.size - 1;
Expand Down
83 changes: 58 additions & 25 deletions source/funkin/ui/debug/char/components/wizard/AddCharFilesDialog.hx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ class AddCharFilesDialog extends DefaultWizardDialog

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

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

Expand All @@ -57,9 +58,18 @@ class AddCharFilesDialog extends DefaultWizardDialog
if (addAssetsBox.disabled) return true;

var uploadBoxes:Array<UploadAssetsBox> = [];
for (box in addAssetsBox.childComponents)
for (unsafeBox in addAssetsBox.childComponents)
{
if (Std.isOfType(box, UploadAssetsBox)) uploadBoxes.push(cast box);
if (!Std.isOfType(unsafeBox, UploadAssetsBox))
{
continue;
}
var box:UploadAssetsBox = cast unsafeBox;
if (box.daField.text == null || box.daField.text.length == 0)
{
continue;
}
uploadBoxes.push(box);
}

// check if the files even exist
Expand All @@ -77,31 +87,44 @@ class AddCharFilesDialog extends DefaultWizardDialog
switch (params.renderType)
{
case "sparrow" | "multisparrow":
var imgPath = uploadBoxes[0].daField.text;
var xmlPath = uploadBoxes[0].daField.text.replace(".png", ".xml");
var files = [];
for (uploadBox in uploadBoxes)
{
var imgPath = uploadBox.daField.text;
var xmlPath = uploadBox.daField.text.replace(".png", ".xml");

// checking if we even have the correct file types in the correct places
if (Path.extension(imgPath) != "png" || Path.extension(xmlPath) != "xml") return false;
// checking if we even have the correct file types in the correct places
if (Path.extension(imgPath) != "png" || Path.extension(xmlPath) != "xml") return false;

// testing if we could actually use these
var imgBytes = CharCreatorUtil.gimmeTheBytes(imgPath);
var xmlBytes = CharCreatorUtil.gimmeTheBytes(xmlPath);
// testing if we could actually use these
var imgBytes = CharCreatorUtil.gimmeTheBytes(imgPath);
var xmlBytes = CharCreatorUtil.gimmeTheBytes(xmlPath);

var tempSprite = new FlxSprite();
try
{
var bitmap = BitmapData.fromBytes(imgBytes);
tempSprite.frames = FlxAtlasFrames.fromSparrow(bitmap, xmlBytes.toString());
}
catch (e)
{
tempSprite.destroy();
return false;
}
var tempSprite = new FlxSprite();
try
{
var bitmap = BitmapData.fromBytes(imgBytes);
tempSprite.frames = FlxAtlasFrames.fromSparrow(bitmap, xmlBytes.toString());
}
catch (e)
{
tempSprite.destroy();
return false;
}

tempSprite.destroy(); // fuck this guy i hate him
params.files = [
{name: imgPath, bytes: imgBytes}, {name: xmlPath, bytes: xmlBytes}];
tempSprite.destroy(); // fuck this guy i hate him
files = files.concat([
{
name: imgPath,
bytes: imgBytes
},
{
name: xmlPath,
bytes: xmlBytes
}
]);
}
params.files = files;

return true;

Expand Down Expand Up @@ -186,6 +209,16 @@ class AddCharFilesDialog extends DefaultWizardDialog

return false;
}

function recursiveUploadBox():Void
{
var uploadBox = new UploadAssetsBox("Put the path to the Spritesheet Image here.", FileUtil.FILE_EXTENSION_INFO_PNG);
uploadBox.daField.onChange = _ -> {
uploadBox.daField.onChange = null;
recursiveUploadBox();
};
addAssetsBox.addComponent(uploadBox);
}
}

class UploadAssetsBox extends HBox
Expand Down
6 changes: 3 additions & 3 deletions source/funkin/ui/debug/char/pages/CharCreatorGameplayPage.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import haxe.ui.components.VerticalRule;
import funkin.data.stage.StageData;
import funkin.play.stage.Bopper;
import funkin.data.stage.StageData.StageDataCharacter;
import funkin.play.character.CharacterData;
import funkin.play.character.CharacterData.CharacterDataParser;
import funkin.data.character.CharacterData;
import funkin.data.character.CharacterRegistry;
import funkin.play.character.BaseCharacter.CharacterType;
import funkin.play.stage.StageProp;
import funkin.data.stage.StageRegistry;
Expand Down Expand Up @@ -251,7 +251,7 @@ class CharCreatorGameplayPage extends CharCreatorDefaultPage
}
else
{
var data:CharacterData = CharacterDataParser.fetchCharacterData(ghostId);
var data:CharacterData = CharacterRegistry.fetchCharacterData(ghostId);
if (data == null) return ghostId;

GhostUtil.copyFromCharacterData(ghostCharacter, data);
Expand Down
35 changes: 14 additions & 21 deletions source/funkin/ui/debug/char/util/GhostUtil.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package funkin.ui.debug.char.util;

import funkin.play.character.CharacterData;
import funkin.data.character.CharacterData;
import funkin.ui.debug.char.animate.CharSelectAtlasSprite;
import funkin.ui.debug.char.pages.CharCreatorGameplayPage;
import flixel.graphics.frames.FlxAtlasFrames;
Expand All @@ -20,7 +20,7 @@ class GhostUtil
switch (player.renderType)
{
case "sparrow" | "multisparrow":
if (ghost.generatedParams.files.length != 2) return; // img and data
if (ghost.generatedParams.files.length < 2) return; // img and data

var combinedFrames = null;
for (i in 0...Math.floor(ghost.generatedParams.files.length / 2))
Expand Down Expand Up @@ -64,7 +64,7 @@ class GhostUtil

for (anim in player.animations)
{
ghost.addAnimation(anim.name, anim.prefix, anim.offsets, anim.frameIndices, anim.assetPath, anim.frameRate, anim.looped, anim.flipX, anim.flipY);
ghost.addAnimation(anim.name, anim.prefix, anim.offsets, anim.frameIndices, anim.frameRate, anim.looped, anim.flipX, anim.flipY);
}
}

Expand All @@ -77,26 +77,19 @@ class GhostUtil

switch (data.renderType)
{
case "sparrow":
ghost.frames = Paths.getSparrowAtlas(data.assetPath);

case "packer":
ghost.frames = Paths.getPackerAtlas(data.assetPath);

case "multisparrow": // lemz if you're reading this pls don't forget to update this once you're finished reworking multisparrow chars, thanks!
var allAssetPaths:Array<String> = [];

for (anim in data.animations)
case "sparrow" | "multisparrow":
var combinedFrames = null;
for (i => assetPath in data.assetPaths)
{
if (anim.assetPath != null && !allAssetPaths.contains(anim.assetPath)) allAssetPaths.push(anim.assetPath);
if (combinedFrames == null) combinedFrames = Paths.getSparrowAtlas(assetPath);
else
combinedFrames.addAtlas(Paths.getSparrowAtlas(assetPath));
}

var combinedFrames = Paths.getSparrowAtlas(data.assetPath);
for (path in allAssetPaths)
combinedFrames.addAtlas(Paths.getSparrowAtlas(path));

ghost.frames = combinedFrames;

case "packer":
ghost.frames = Paths.getPackerAtlas(data.assetPaths[0]);

case "animateatlas": // TODO, gonna think of smth

default: // nuthin
Expand All @@ -108,8 +101,8 @@ class GhostUtil

for (anim in data.animations)
{
ghost.addAnimation(anim.name, anim.prefix, anim.offsets, anim.frameIndices ?? [], anim.assetPath ?? "", anim.frameRate ?? 24, anim.looped ?? false,
anim.flipX ?? false, anim.flipY ?? false);
ghost.addAnimation(anim.name, anim.prefix, anim.offsets, anim.frameIndices ?? [], anim.frameRate ?? 24, anim.looped ?? false, anim.flipX ?? false,
anim.flipY ?? false);
}
}
}

0 comments on commit 9bf898a

Please sign in to comment.