Skip to content

Commit

Permalink
a lot of cosmetic things
Browse files Browse the repository at this point in the history
  • Loading branch information
KoloInDaCrib committed Nov 15, 2024
1 parent 5518835 commit 68e2a80
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 25 deletions.
2 changes: 1 addition & 1 deletion source/funkin/ui/debug/char/CharCreatorCharacter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class CharCreatorCharacter extends Bopper
var data = generatedParams.files[1].bytes.toString();
this.frames = FlxAtlasFrames.fromSpriteSheetPacker(img, data);

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

Expand Down
13 changes: 5 additions & 8 deletions source/funkin/ui/debug/char/CharCreatorState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,22 @@ class CharCreatorState extends UIState
{
menubarOptionGameplay.onChange = function(_) switchToPage(Gameplay);
menubarOptionCharSelect.onChange = function(_) switchToPage(CharacterSelect);
menubarItemExport.onClick = _ -> exportStuff();
menubarItemExport.onClick = _ -> this.exportAll();
}

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

var params:WizardGenerateParams;

function wizardComplete(params:WizardGenerateParams):Void
{
// clear da pages sorry chat
remove(selectedPage);
selectedPage = null;
this.params = params;

var allPages = [for (k => p in pages) p];
while (allPages.length > 0)
Expand Down Expand Up @@ -162,12 +165,6 @@ class CharCreatorState extends UIState
selectedPage.fillUpBottomBar(bottomBarLeftBox, bottomBarMiddleBox, bottomBarRightBox);
selectedPage.fillUpPageSettings(menubarMenuSettings);
}

function exportStuff():Void
{
if (Std.isOfType(selectedPage, CharCreatorSelectPage)) this.exportPlayableCharacter();
else if (Std.isOfType(selectedPage, CharCreatorGameplayPage)) this.exportCharacter();
}
}

enum CharCreatorPage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,43 @@ class CharCreatorImportExportHandler
gameplayPage.currentCharacter.fromCharacterData(CharacterRegistry.fetchCharacterData(charId));
}

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

var zipEntries = [];
if (state.params.generateCharacter) exportCharacter(state, zipEntries);
if (state.params.generatePlayerData) exportPlayableCharacter(state, zipEntries);

FileUtil.saveFilesAsZIP(zipEntries);
}

for (file in gameplayPage.currentCharacter.files)
public static function exportCharacter(state:CharCreatorState, zipEntries:Array<haxe.zip.Entry>):Void
{
var gameplayPage:CharCreatorGameplayPage = cast state.pages[Gameplay];

if (gameplayPage.currentCharacter.renderType != funkin.data.character.CharacterData.CharacterRenderType.AnimateAtlas)
{
// skip if the file is in a character path
if (CharCreatorUtil.isPathProvided(file.name, "images/characters"))
for (file in gameplayPage.currentCharacter.files)
{
continue;
// skip if the file is in a character path
if (CharCreatorUtil.isPathProvided(file.name, "images/characters"))
{
continue;
}

zipEntries.push(FileUtil.makeZIPEntryFromBytes('images/characters/${Path.withoutDirectory(file.name)}', file.bytes));
}
}
else
{
// no check needed there's no zip files in assets folder

zipEntries.push(FileUtil.makeZIPEntryFromBytes('images/characters/${Path.withoutDirectory(file.name)}', file.bytes));
for (file in FileUtil.readZIPFromBytes(gameplayPage.currentCharacter.files[0].bytes))
{
var zipName = gameplayPage.currentCharacter.files[0].name.replace(".zip", "");

zipEntries.push(FileUtil.makeZIPEntryFromBytes('images/characters/${Path.withoutDirectory(zipName)}/${Path.withoutDirectory(file.fileName)}',
file.data));
}
}

// if the icon path isn't absolute, in the proper folder AND there already was an xml file (if we added one), then we don't save files and replace the typedef's id field
Expand All @@ -67,14 +89,12 @@ class CharCreatorImportExportHandler

// we push this later in case we use a pre-existing icon
zipEntries.push(FileUtil.makeZIPEntry('${gameplayPage.currentCharacter.characterId}.json', gameplayPage.currentCharacter.toJSON()));
FileUtil.saveFilesAsZIP(zipEntries);
}

public static function exportPlayableCharacter(state:CharCreatorState):Void
public static function exportPlayableCharacter(state:CharCreatorState, zipEntries:Array<haxe.zip.Entry>):Void
{
var selectPage:CharCreatorSelectPage = cast state.pages[CharacterSelect];

var zipEntries = [];
var charID = selectPage.data.importedCharacter ?? selectPage.data.characterID;

// for (file in selectPage.iconFiles)
// {
Expand All @@ -87,7 +107,7 @@ class CharCreatorImportExportHandler
// zipEntries.push(FileUtil.makeZIPEntryFromBytes('images/freeplay/icons/${Path.withoutDirectory(file.name)}', file.bytes));
// }

zipEntries.push(FileUtil.makeZIPEntry('${selectPage.data.characterID}.json', selectPage.toJSON()));
FileUtil.saveFilesAsZIP(zipEntries);
zipEntries.push(FileUtil.makeZIPEntry('data/players/${charID}.json', selectPage.toJSON()));
if (selectPage.nametagFile != null) zipEntries.push(FileUtil.makeZIPEntryFromBytes('images/charSelect${charID}Nametag.png', selectPage.nametagFile.bytes));
}
}
77 changes: 75 additions & 2 deletions source/funkin/ui/debug/char/pages/CharCreatorSelectPage.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import funkin.data.freeplay.player.PlayerData;
import funkin.data.freeplay.player.PlayerRegistry;
import funkin.graphics.adobeanimate.FlxAtlasSprite;
import funkin.graphics.FunkinSprite;
import funkin.graphics.shaders.MosaicEffect;
import funkin.ui.debug.char.animate.CharSelectAtlasSprite;
import funkin.ui.debug.char.pages.subpages.CharSelectIndexSubPage;
import funkin.ui.debug.char.components.dialogs.*;
Expand All @@ -36,6 +37,9 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage
var data:WizardGenerateParams;

var nametag:FlxSprite;
var nametagShader:MosaicEffect = new MosaicEffect();
var nametagFile:WizardFile;

var gf:CharSelectAtlasSprite;
var bf:CharSelectAtlasSprite;

Expand Down Expand Up @@ -85,6 +89,21 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage
initForeground();

nametag = new FlxSprite();
if (data.importedPlayerData != null) nametag.loadGraphic(Paths.image('charSelect/'
+ (data.importedPlayerData == "bf" ? "boyfriend" : data.importedPlayerData)
+ "Nametag"));
nametag.updateHitbox();

nametag.scale.set(0.77, 0.77);
updateNametagPos();

nametag.shader = nametagShader; // truly a sight to behold
setNametagShaderBlockSize(0, 1, 1);
setNametagShaderBlockSize(1, nametag.width / 27, nametag.height / 26);
setNametagShaderBlockSize(2, nametag.width / 10, nametag.height / 10);

setNametagShaderBlockSize(3, 1, 1);

add(nametag);

dialogMap = new Map<PlayCharDialogType, DefaultPageDialog>();
Expand Down Expand Up @@ -151,7 +170,8 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage
if (idx >= array.length) idx = 0;
else if (idx < 0) idx = array.length - 1;

(useGF ? gf : bf).playAnimation(array[idx]);
(useGF ? gf : bf).stopAnimation();
(useGF ? gf : bf).playAnimation(array[idx]);
(useGF ? gfAnimLabel : bfAnimLabel).text = (useGF ? "GF" : "Player") + " Anim: " + array[idx];
}

Expand All @@ -166,11 +186,16 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage
var openFile = new MenuItem();
openFile.text = "Load from File";

var openNametag = new MenuItem();
openNametag.text = "Load Nametag Image";

// additions
menu.addComponent(pixelStuff);
pixelStuff.addComponent(openFile);
pixelStuff.addComponent(openPos);

menu.addComponent(openNametag);

var settingsDialog = new MenuCheckBox();
settingsDialog.text = "Playable Character Settings";
menu.addComponent(settingsDialog);
Expand Down Expand Up @@ -198,11 +223,48 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage
});
}

openNametag.onClick = function(_) {
FileUtil.browseForBinaryFile("Load Nametag Image", [FileUtil.FILE_EXTENSION_INFO_PNG], function(_) {
if (_?.fullPath == null) return;

nametagFile = {name: _.fullPath, bytes: FileUtil.readBytesFromPath(_.fullPath)}

nametag.loadGraphic(openfl.display.BitmapData.fromBytes(nametagFile.bytes));
nametag.updateHitbox();

updateNametagPos();

setNametagShaderBlockSize(0, 1, 1);
setNametagShaderBlockSize(1, nametag.width / 27, nametag.height / 26);
setNametagShaderBlockSize(2, nametag.width / 10, nametag.height / 10);
setNametagShaderBlockSize(3, 1, 1);
});
}

settingsDialog.onClick = function(_) {
dialogMap[SettingsDialog].hidden = !settingsDialog.selected;
}
}

function updateNametagPos()
{
nametag.x -= (nametag.getMidpoint().x - 1008);
nametag.y -= (nametag.getMidpoint().y - 100);
}

function setNametagShaderBlockSize(frame:Int, ?forceX:Float, ?forceY:Float)
{
var daX:Float = 10 * FlxG.random.int(1, 4);
var daY:Float = 10 * FlxG.random.int(1, 4);

if (forceX != null) daX = forceX;
if (forceY != null) daY = forceY;

new flixel.util.FlxTimer().start(frame / 30, _ -> {
nametagShader.setBlockSize(daX, daY);
});
}

function initBackground():Void
{
var bg:FlxSprite = new FlxSprite(-153, -140);
Expand Down Expand Up @@ -304,7 +366,18 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage

if (handleInput)
{
if (FlxG.keys.justPressed.B) {}
if (FlxG.keys.justPressed.SPACE)
{
gf.stopAnimation();
gf.playAnimation(gfAnimLabel.text.split(" Anim: ")[1], true, true);

bf.stopAnimation();
bf.playAnimation(bfAnimLabel.text.split(" Anim: ")[1], true, true);
}

// perhaps gonan find a better keybind for this idk
if (FlxG.keys.justPressed.W) changeCharAnim(-1, FlxG.keys.pressed.SHIFT);
if (FlxG.keys.justPressed.S) changeCharAnim(1, FlxG.keys.pressed.SHIFT);
}
}

Expand Down

0 comments on commit 68e2a80

Please sign in to comment.