Folder support for characters (WIP)
This commit is contained in:
@@ -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<String> = [];
|
||||
#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
|
||||
|
||||
@@ -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<String> = Character.getList(true);
|
||||
var isMods:Bool = true;
|
||||
var modsList:Array<String> = Character.getList(true, true);
|
||||
|
||||
var list:Array<OptionType> = [
|
||||
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<String>, isMods:Bool, folderPath:String = ""):Array<OptionType> {
|
||||
var list:Array<OptionType> = [];
|
||||
|
||||
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<OptionType> = 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);
|
||||
|
||||
|
||||
@@ -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<String>
|
||||
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<String> {
|
||||
var list:Array<String> = [];
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user