From de59b305ccc6e3ddaff54306b4cde563d1cc5d08 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Sat, 26 Oct 2024 23:46:05 +0200 Subject: [PATCH] Folder support for characters (WIP) --- source/funkin/backend/assets/Paths.hx | 52 ------------------- .../editors/character/CharacterSelection.hx | 51 +++++++++++++----- source/funkin/game/Character.hx | 24 ++++++--- 3 files changed, 55 insertions(+), 72 deletions(-) diff --git a/source/funkin/backend/assets/Paths.hx b/source/funkin/backend/assets/Paths.hx index 0fd0931b..2d17e592 100644 --- a/source/funkin/backend/assets/Paths.hx +++ b/source/funkin/backend/assets/Paths.hx @@ -257,58 +257,6 @@ class Paths content[k] = '$key$e'; } return content; - /* - if (!key.endsWith("/")) key = key + "/"; - - if (ModsFolder.currentModFolder == null && !scanSource) - return getFolderContent(key, false, addPath, true); - - var folderPath:String = scanSource ? getAssetsPath(key) : getLibraryPathForce(key, 'mods/${ModsFolder.currentModFolder}'); - var libThing = new LimeLibrarySymbol(folderPath); - var library = libThing.library; - - if (library is openfl.utils.AssetLibrary) { - var lib = cast(libThing.library, openfl.utils.AssetLibrary); - @:privateAccess - if (lib.__proxy != null) library = lib.__proxy; - } - - var content:Array = []; - #if MOD_SUPPORT - if (library is funkin.backend.assets.IModsAssetLibrary) { - // easy task, can immediately scan for files! - var lib = cast(library, funkin.backend.assets.IModsAssetLibrary); - content = lib.getFiles(libThing.symbolName); - if (addPath) - for(i in 0...content.length) - content[i] = '$folderPath${content[i]}'; - } else #end { - @:privateAccess - for(k=>e in library.paths) { - if (k.toLowerCase().startsWith(libThing.symbolName.toLowerCase())) { - if (addPath) { - if (libThing.libraryName != "") - content.push('${libThing.libraryName}:$k'); - else - content.push(k); - } else { - var barebonesFileName = k.substr(libThing.symbolName.length); - if (!barebonesFileName.contains("/")) - content.push(barebonesFileName); - } - } - } - } - - if (includeSource) { - var sourceResult = getFolderContent(key, false, addPath, true); - for(e in sourceResult) - if (!content.contains(e)) - content.push(e); - } - - return content; - */ } // Used in Script.hx diff --git a/source/funkin/editors/character/CharacterSelection.hx b/source/funkin/editors/character/CharacterSelection.hx index eb9a1e3a..3776b353 100644 --- a/source/funkin/editors/character/CharacterSelection.hx +++ b/source/funkin/editors/character/CharacterSelection.hx @@ -4,6 +4,7 @@ import funkin.game.Character; import funkin.options.OptionsScreen; import funkin.options.type.IconOption; import funkin.options.type.NewOption; +import funkin.options.type.TextOption; import funkin.options.type.OptionType; class CharacterSelection extends EditorTreeMenu @@ -13,21 +14,45 @@ class CharacterSelection extends EditorTreeMenu bgType = "charter"; super.create(); - var modsList:Array = Character.getList(true); + var isMods:Bool = true; + var modsList:Array = Character.getList(true, true); - var list:Array = [ - for (char in (modsList.length == 0 ? Character.getList(false) : modsList)) - new IconOption(char, "Press ACCEPT to edit this character.", Character.getIconFromCharName(char), - function() { - FlxG.switchState(new CharacterEditor(char)); - }) - ]; + if(modsList.length == 0) { + modsList = Character.getList(false, true); + isMods = false; + } - list.insert(0, new NewOption("New Character", "New Character", function() { - openSubState(new UIWarningSubstate("New Character: Feature Not Implemented!", "This feature isnt implemented yet. Please wait for more cne updates to have this functional.\n\n\n- Codename Devs", [ - {label: "Ok", color: 0xFFFF0000, onClick: function(t) {}} - ])); - })); + function generateList(modsList:Array, isMods:Bool, folderPath:String = ""):Array { + var list:Array = []; + + for(char in modsList) { + if(char.endsWith("/")) { + var folderName = CoolUtil.getFilename(char.substr(0, char.length-1)); + + list.push(new TextOption(folderName + " >", "Press ACCEPT to edit this folder.", function() { + var newModsList = Character.getList(isMods, true, char); + var newList:Array = generateList(newModsList, isMods, folderPath + folderName + "/"); + optionsTree.add(new OptionsScreen(folderPath + folderName, "Select a character to edit in " + folderPath + folderName + "/", newList)); + })); + } else { + list.push(new IconOption(char, "Press ACCEPT to edit this character.", Character.getIconFromCharName(folderPath + char, char), + function() { + FlxG.switchState(new CharacterEditor(folderPath + char)); + }) + ); + } + } + + list.insert(0, new NewOption("New Character", "New Character", function() { + openSubState(new UIWarningSubstate("New Character: Feature Not Implemented!", "This feature isnt implemented yet. Please wait for more cne updates to have this functional.\n\n\n- Codename Devs", [ + {label: "Ok", color: 0xFFFF0000, onClick: function(t) {}} + ])); + })); + + return list; + } + + var list = generateList(modsList, isMods); main = new OptionsScreen("Character Editor", "Select a character to edit", list); diff --git a/source/funkin/game/Character.hx b/source/funkin/game/Character.hx index 9f3834e7..84bc5094 100644 --- a/source/funkin/game/Character.hx +++ b/source/funkin/game/Character.hx @@ -1,5 +1,6 @@ package funkin.game; +import sys.FileSystem; import flixel.util.FlxSpriteUtil; import openfl.display.Graphics; import flixel.util.typeLimit.OneOfTwo; @@ -593,9 +594,10 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset return xml; } - public static function getIconFromCharName(?character:String) { + public static function getIconFromCharName(?character:String, ?defaultIcon:String = null) { if(character == null) return "face"; - var icon:String = character; + if(defaultIcon == null) defaultIcon = character; + var icon:String = defaultIcon; var xml:Access = getXMLFromCharName(character); if (xml != null && xml.x.exists("icon")) icon = xml.x.get("icon"); @@ -603,9 +605,17 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset return icon; } - public static function getList(?mods:Bool = false):Array - return [ - for (path in Paths.getFolderContent('data/characters/', true, mods ? MODS : BOTH)) - if (Path.extension(path) == "xml") CoolUtil.getFilename(path) - ]; + public static function getList(?mods:Bool = false, includeFolders:Bool = false, folder:String = 'data/characters/'):Array { + var list:Array = []; + if(includeFolders) { + for (path in Paths.getFolderDirectories(folder, true, mods ? MODS : BOTH)) { + if(!path.endsWith("/")) path += "/"; + list.push(path); + } + } + for (path in Paths.getFolderContent(folder, true, mods ? MODS : BOTH)) + if (Path.extension(path) == "xml") + list.push(CoolUtil.getFilename(path)); + return list; + } } \ No newline at end of file