Skip to content

Commit

Permalink
make import export handler
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed Nov 2, 2024
1 parent 6135565 commit 886c332
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
25 changes: 2 additions & 23 deletions source/funkin/ui/debug/char/CharCreatorState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ class CharCreatorState extends UIState
function setupUICallbacks()
{
menubarOptionGameplay.onChange = function(_) switchToPage(Gameplay);
menubarItemExport.onClick = _ -> exportCharacter();
menubarItemExport.onClick = _ -> this.exportCharacter();
}

function handleShortcuts():Void
{
if (FlxG.keys.pressed.CONTROL && FlxG.keys.justPressed.S) exportCharacter();
if (FlxG.keys.pressed.CONTROL && FlxG.keys.justPressed.S) this.exportCharacter();
}

function wizardComplete(params:WizardGenerateParams)
Expand Down Expand Up @@ -160,27 +160,6 @@ class CharCreatorState extends UIState
selectedPage.fillUpBottomBar(bottomBarLeftBox, bottomBarMiddleBox, bottomBarRightBox);
selectedPage.fillUpPageSettings(menubarMenuSettings);
}

function exportCharacter():Void
{
var gameplayPage:CharCreatorGameplayPage = cast pages[Gameplay];

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);
}
}

enum CharCreatorPage
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package funkin.ui.debug.char.handlers;

import haxe.io.Path;
import funkin.ui.debug.char.pages.CharCreatorGameplayPage;
import funkin.ui.debug.char.CharCreatorState;
import funkin.util.FileUtil;

@:access(funkin.ui.debug.char.CharCreatorState)
class CharCreatorImportExportHandler
{
public static function importCharacter(state:CharCreatorState):Void {}

public static function exportCharacter(state:CharCreatorState):Void
{
var gameplayPage:CharCreatorGameplayPage = cast state.pages[Gameplay];

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);
}
}
1 change: 1 addition & 0 deletions source/funkin/ui/debug/char/import.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import funkin.ui.debug.char.util.GhostUtil;

#if !macro
using funkin.ui.debug.char.handlers.CharCreatorStartupWizard;
using funkin.ui.debug.char.handlers.CharCreatorImportExportHandler;
#end

0 comments on commit 886c332

Please sign in to comment.