Skip to content

Commit

Permalink
export images, etc. as well if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed Nov 2, 2024
1 parent 2cd0ae7 commit 6135565
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
22 changes: 17 additions & 5 deletions source/funkin/ui/debug/char/CharCreatorCharacter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<WizardFile>;

public var characterName:String = "Unknown";
public var characterType:CharacterType = BF;
Expand Down Expand Up @@ -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<CharacterData>(true);
return writer.write(toCharacterData(), ' ');
}

/**
Expand All @@ -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:
Expand All @@ -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
Expand Down
19 changes: 17 additions & 2 deletions source/funkin/ui/debug/char/CharCreatorState.hx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
9 changes: 9 additions & 0 deletions source/funkin/ui/debug/char/util/CharCreatorUtil.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package funkin.ui.debug.char.util;

import haxe.io.Path;
import haxe.ui.core.Screen;
import haxe.ui.focus.FocusManager;

Expand Down Expand Up @@ -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;
}
}

0 comments on commit 6135565

Please sign in to comment.