diff --git a/source/funkin/ui/debug/char/CharCreatorCharacter.hx b/source/funkin/ui/debug/char/CharCreatorCharacter.hx index 7186e59418..77d42dc504 100644 --- a/source/funkin/ui/debug/char/CharCreatorCharacter.hx +++ b/source/funkin/ui/debug/char/CharCreatorCharacter.hx @@ -13,7 +13,6 @@ import flixel.math.FlxPoint.FlxCallbackPoint; // honestly these are kind of awes import flixel.FlxSprite; import haxe.io.Bytes; import haxe.io.Path; -import funkin.util.SerializerUtil; // literally just basecharacter but less functionality // like the removal of note event functions @@ -24,6 +23,7 @@ class CharCreatorCharacter extends Bopper public var generatedParams:WizardGenerateParams; public var characterId(get, never):String; public var renderType(get, never):String; + public var files(get, never):Array; public var characterName:String = "Unknown"; public var characterType:CharacterType = BF; @@ -254,9 +254,10 @@ class CharCreatorCharacter extends Bopper * Returns the `CharacterData` in bytes * @return Bytes */ - public function toBytes():Bytes + public function toJSON():String { - return Bytes.ofString(SerializerUtil.toJSON(toCharacterData())); + var writer = new json2object.JsonWriter(true); + return writer.write(toCharacterData(), ' '); } /** @@ -268,8 +269,14 @@ class CharCreatorCharacter extends Bopper return { version: CharacterRegistry.CHARACTER_DATA_VERSION, name: characterName, - assetPaths: generatedParams.files.filter((file) -> return file.name.endsWith(".png")) - .map((file) -> Path.normalize(file.name.substr(file.name.indexOf("images") + 7)).replace(".png", "")), + assetPaths: generatedParams.files.filter((file) -> return file.name.endsWith(".png") || file.name.endsWith(".zip")).map((file) -> { + var path = Path.withoutExtension(Path.normalize(file.name)); + if (!CharCreatorUtil.isCharacterPath(path)) + { + return 'characters/${Path.withoutDirectory(path)}'; + } + return path.substr(path.lastIndexOf("images") + 7); + }), flipX: characterFlipX, renderType: generatedParams.renderType, healthIcon: @@ -293,6 +300,11 @@ class CharCreatorCharacter extends Bopper return generatedParams.renderType; } + function get_files() + { + return generatedParams.files; + } + function get_characterOrigin():FlxPoint { var xPos = (width / 2); // Horizontal center diff --git a/source/funkin/ui/debug/char/CharCreatorState.hx b/source/funkin/ui/debug/char/CharCreatorState.hx index 945a76a253..7803b5f2e3 100644 --- a/source/funkin/ui/debug/char/CharCreatorState.hx +++ b/source/funkin/ui/debug/char/CharCreatorState.hx @@ -1,5 +1,6 @@ package funkin.ui.debug.char; +import haxe.io.Path; import haxe.ui.core.Screen; import haxe.ui.backend.flixel.UIState; import haxe.ui.containers.windows.WindowManager; @@ -8,7 +9,7 @@ import funkin.input.Cursor; import funkin.ui.debug.char.pages.*; import funkin.util.MouseUtil; import funkin.util.WindowUtil; -import funkin.util.SerializerUtil; +import funkin.util.FileUtil; import flixel.addons.display.FlxGridOverlay; import flixel.FlxCamera; import flixel.FlxSprite; @@ -164,7 +165,21 @@ class CharCreatorState extends UIState { var gameplayPage:CharCreatorGameplayPage = cast pages[Gameplay]; - funkin.util.FileUtil.saveFile(gameplayPage.currentCharacter.toBytes(), [funkin.util.FileUtil.FILE_FILTER_JSON]); + var zipEntries = []; + zipEntries.push(FileUtil.makeZIPEntry('${gameplayPage.currentCharacter.characterId}.json', gameplayPage.currentCharacter.toJSON())); + + for (file in gameplayPage.currentCharacter.files) + { + // skip if the file is in a character path + if (CharCreatorUtil.isCharacterPath(file.name)) + { + continue; + } + + zipEntries.push(FileUtil.makeZIPEntryFromBytes('images/characters/${Path.withoutDirectory(file.name)}', file.bytes)); + } + + FileUtil.saveFilesAsZIP(zipEntries); } } diff --git a/source/funkin/ui/debug/char/util/CharCreatorUtil.hx b/source/funkin/ui/debug/char/util/CharCreatorUtil.hx index 51b104413b..fc2e2a8e57 100644 --- a/source/funkin/ui/debug/char/util/CharCreatorUtil.hx +++ b/source/funkin/ui/debug/char/util/CharCreatorUtil.hx @@ -1,5 +1,6 @@ package funkin.ui.debug.char.util; +import haxe.io.Path; import haxe.ui.core.Screen; import haxe.ui.focus.FocusManager; @@ -32,4 +33,12 @@ class CharCreatorUtil text = text.substring(1, text.length); return text; } + + public static function isCharacterPath(path:String):Bool + { + var cwd = Path.addTrailingSlash(Path.normalize(sys.FileSystem.fullPath("."))); + path = Path.normalize(path); + path = path.replace(cwd, ""); + return !Path.isAbsolute(path) && path.indexOf("images/characters") != -1; + } }