diff --git a/source/funkin/backend/assets/IModsAssetLibrary.hx b/source/funkin/backend/assets/IModsAssetLibrary.hx index 5c90b185..a080189b 100644 --- a/source/funkin/backend/assets/IModsAssetLibrary.hx +++ b/source/funkin/backend/assets/IModsAssetLibrary.hx @@ -23,6 +23,7 @@ using StringTools; interface IModsAssetLibrary { public var prefix:String; + public var modName:String; public var libName:String; #if MOD_SUPPORT diff --git a/source/funkin/backend/assets/ModsFolder.hx b/source/funkin/backend/assets/ModsFolder.hx index 33458fe0..fc37ed52 100644 --- a/source/funkin/backend/assets/ModsFolder.hx +++ b/source/funkin/backend/assets/ModsFolder.hx @@ -41,6 +41,11 @@ class ModsFolder { */ public static var addonsPath:String = "./addons/"; + /** + * If accessing a file as assets/data/global/LIB_mymod.hx should redirect to mymod:assets/data/global.hx + */ + public static var useLibFile:Bool = true; + /** * Whenever its the first time mods has been reloaded. */ @@ -72,12 +77,12 @@ class ModsFolder { * @param modName Name of the mod * @param force Whenever the mod should be reloaded if it has already been loaded */ - public static function loadModLib(path:String, force:Bool = false) { + public static function loadModLib(path:String, force:Bool = false, ?modName:String) { #if MOD_SUPPORT if (FileSystem.exists('$path.zip')) - return loadLibraryFromZip('$path'.toLowerCase(), '$path.zip', force); + return loadLibraryFromZip('$path'.toLowerCase(), '$path.zip', force, modName); else - return loadLibraryFromFolder('$path'.toLowerCase(), '$path', force); + return loadLibraryFromFolder('$path'.toLowerCase(), '$path', force, modName); #else return null; @@ -111,12 +116,12 @@ class ModsFolder { } #if MOD_SUPPORT - public static function loadLibraryFromFolder(libName:String, folder:String, force:Bool = false) { - return prepareModLibrary(libName, new ModsFolderLibrary(folder, libName), force); + public static function loadLibraryFromFolder(libName:String, folder:String, force:Bool = false, ?modName:String) { + return prepareModLibrary(libName, new ModsFolderLibrary(folder, libName, modName), force); } - public static function loadLibraryFromZip(libName:String, zipPath:String, force:Bool = false) { - return prepareModLibrary(libName, new ZipFolderLibrary(zipPath, libName), force); + public static function loadLibraryFromZip(libName:String, zipPath:String, force:Bool = false, ?modName:String) { + return prepareModLibrary(libName, new ZipFolderLibrary(zipPath, libName, modName), force); } #end } \ No newline at end of file diff --git a/source/funkin/backend/assets/ModsFolderLibrary.hx b/source/funkin/backend/assets/ModsFolderLibrary.hx index 69f87693..ed608bda 100644 --- a/source/funkin/backend/assets/ModsFolderLibrary.hx +++ b/source/funkin/backend/assets/ModsFolderLibrary.hx @@ -17,14 +17,19 @@ using StringTools; class ModsFolderLibrary extends AssetLibrary implements IModsAssetLibrary { public var folderPath:String; + public var modName:String; public var libName:String; public var useImageCache:Bool = true; public var prefix = 'assets/'; - public function new(folderPath:String, libName:String) { + public function new(folderPath:String, libName:String, ?modName:String) { this.folderPath = folderPath; this.libName = libName; this.prefix = 'assets/$libName/'; + if(modName == null) + this.modName = libName; + else + this.modName = modName; super(); } @@ -133,6 +138,15 @@ class ModsFolderLibrary extends AssetLibrary implements IModsAssetLibrary { private function __parseAsset(asset:String):Bool { if (!asset.startsWith(prefix)) return false; _parsedAsset = asset.substr(prefix.length); + if(ModsFolder.useLibFile) { + var file = new haxe.io.Path(_parsedAsset); + if(file.file.startsWith("LIB_")) { + var library = file.file.substr(4); + if(library != modName) return false; + + _parsedAsset = file.dir + "." + file.ext; + } + } return true; } #end diff --git a/source/funkin/backend/assets/Paths.hx b/source/funkin/backend/assets/Paths.hx index 7f847670..495d5577 100644 --- a/source/funkin/backend/assets/Paths.hx +++ b/source/funkin/backend/assets/Paths.hx @@ -164,7 +164,7 @@ class Paths inline static public function getPackerAtlasAlt(key:String) return FlxAtlasFrames.fromSpriteSheetPacker('$key.png', '$key.txt'); - inline static public function getAssetsRoot():String + inline static public function getAssetsRoot():String return ModsFolder.currentModFolder != null ? '${ModsFolder.modsPath}${ModsFolder.currentModFolder}' : './assets'; /** diff --git a/source/funkin/backend/assets/ScriptedAssetLibrary.hx b/source/funkin/backend/assets/ScriptedAssetLibrary.hx index 972f74e2..0b72a426 100644 --- a/source/funkin/backend/assets/ScriptedAssetLibrary.hx +++ b/source/funkin/backend/assets/ScriptedAssetLibrary.hx @@ -21,8 +21,8 @@ class ScriptedAssetLibrary extends ModsFolderLibrary { public var scriptName:String; private static var nullValue:Dynamic = {}; - public function new(scriptName:String, args:Array = null, folderPath:String="./assets/", libName:String="assets") { - super(folderPath, libName); + public function new(scriptName:String, args:Array = null, folderPath:String="./assets/", libName:String="assets", ?modName:String) { + super(folderPath, libName, modName); this.scriptName = scriptName; script = Script.create(Paths.script("data/library/" + scriptName)); @@ -107,6 +107,14 @@ class ScriptedAssetLibrary extends ModsFolderLibrary { return super.getAssetPath(); } + public override function list(type:String) { + var result:Dynamic = script.call("list", [type]); + if(result != null) { + return result == nullValue ? null : result; + } + return super.list(type); + } + private override function __isCacheValid(cache:Map, asset:String, isLocalCache:Bool = false) { var result:Dynamic = script.call("__isCacheValid", [cache, asset, isLocalCache]); if(result != null) { diff --git a/source/funkin/backend/assets/ZipFolderLibrary.hx b/source/funkin/backend/assets/ZipFolderLibrary.hx index 7465482e..21e425d8 100644 --- a/source/funkin/backend/assets/ZipFolderLibrary.hx +++ b/source/funkin/backend/assets/ZipFolderLibrary.hx @@ -27,6 +27,7 @@ import funkin.backend.utils.SysZip.SysZipEntry; class ZipFolderLibrary extends AssetLibrary implements IModsAssetLibrary { public var zipPath:String; + public var modName:String; public var libName:String; public var useImageCache:Bool = false; public var prefix = 'assets/'; @@ -34,10 +35,15 @@ class ZipFolderLibrary extends AssetLibrary implements IModsAssetLibrary { public var zip:SysZip; public var assets:Map = []; - public function new(zipPath:String, libName:String) { + public function new(zipPath:String, libName:String, ?modName:String) { this.zipPath = zipPath; this.libName = libName; + if(modName == null) + this.modName = libName; + else + this.modName = modName; + zip = SysZip.openFromFile(zipPath); zip.read(); for(entry in zip.entries) @@ -77,7 +83,18 @@ class ZipFolderLibrary extends AssetLibrary implements IModsAssetLibrary { public function __parseAsset(asset:String):Bool { if (!asset.startsWith(prefix)) return false; - _parsedAsset = asset.substr(prefix.length).toLowerCase(); + _parsedAsset = asset.substr(prefix.length); + if(ModsFolder.useLibFile) { + var file = new haxe.io.Path(_parsedAsset); + if(file.file.startsWith("LIB_")) { + var library = file.file.substr(4); + if(library != modName) return false; + + _parsedAsset = file.dir + "." + file.ext; + } + } + + _parsedAsset = _parsedAsset.toLowerCase(); return true; } diff --git a/source/funkin/backend/system/CommandLineHandler.hx b/source/funkin/backend/system/CommandLineHandler.hx index d00af9a5..9be7928c 100644 --- a/source/funkin/backend/system/CommandLineHandler.hx +++ b/source/funkin/backend/system/CommandLineHandler.hx @@ -11,13 +11,14 @@ class CommandLineHandler { break; case "-h" | "-help" | "help": Sys.println("-- Codename Engine Command Line help --"); - Sys.println("-help | Show this help"); + Sys.println("-help | Show this help"); #if MOD_SUPPORT - Sys.println("-mod [mod name] | Load a specific mod"); - Sys.println("-modfolder [path] | Sets the mod folder path"); + Sys.println("-mod [mod name] | Load a specific mod"); + Sys.println("-modfolder [path] | Sets the mod folder path"); + Sys.println("-addonsfolder [path] | Sets the addons folder path"); #end - Sys.println("-nocolor | Disables colors in the terminal"); - Sys.println("-nogpubitmap | Forces GPU only bitmaps off"); + Sys.println("-nocolor | Disables colors in the terminal"); + Sys.println("-nogpubitmap | Forces GPU only bitmaps off"); Sys.exit(0); #if MOD_SUPPORT case "-m" | "-mod" | "-currentmod": @@ -41,6 +42,18 @@ class CommandLineHandler { Sys.println('[ERROR] Mod folder at "${arg}" does not exist.'); Sys.exit(0); } + case "-addonsfolder": + i++; + var arg = cmd[i]; + if (arg == null) { + Sys.println("[ERROR] You need to specify the addon folder path"); + Sys.exit(0); + } else if (FileSystem.exists(arg)) { + funkin.backend.assets.ModsFolder.addonsPath = arg; + } else { + Sys.println('[ERROR] Addons folder at "${arg}" does not exist.'); + Sys.exit(0); + } #end case "-nocolor": Main.noTerminalColor = true; diff --git a/source/funkin/backend/system/Main.hx b/source/funkin/backend/system/Main.hx index 088c8619..79ef9adc 100644 --- a/source/funkin/backend/system/Main.hx +++ b/source/funkin/backend/system/Main.hx @@ -136,6 +136,7 @@ class Main extends Sprite trace("Used cne test / cne build. Switching into source assets."); #if MOD_SUPPORT ModsFolder.modsPath = './${pathBack}mods/'; + ModsFolder.addonsPath = './${pathBack}addons/'; #end Paths.assetsTree.__defaultLibraries.push(ModsFolder.loadLibraryFromFolder('assets', './${pathBack}assets/', true)); #elseif USE_ADAPTED_ASSETS diff --git a/source/funkin/backend/system/MainState.hx b/source/funkin/backend/system/MainState.hx index ba67513d..f2284350 100644 --- a/source/funkin/backend/system/MainState.hx +++ b/source/funkin/backend/system/MainState.hx @@ -33,11 +33,11 @@ class MainState extends FlxState { #if MOD_SUPPORT if (ModsFolder.currentModFolder != null) - Paths.assetsTree.addLibrary(ModsFolder.loadModLib('${ModsFolder.modsPath}${ModsFolder.currentModFolder}')); + Paths.assetsTree.addLibrary(ModsFolder.loadModLib('${ModsFolder.modsPath}${ModsFolder.currentModFolder}', ModsFolder.currentModFolder)); if (FileSystem.exists(ModsFolder.addonsPath) && FileSystem.isDirectory(ModsFolder.addonsPath)) for(addon in [for(dir in FileSystem.readDirectory(ModsFolder.addonsPath)) if (FileSystem.isDirectory('${ModsFolder.addonsPath}$dir')) dir]) - Paths.assetsTree.addLibrary(ModsFolder.loadModLib('${ModsFolder.addonsPath}$addon')); + Paths.assetsTree.addLibrary(ModsFolder.loadModLib('${ModsFolder.addonsPath}$addon', addon)); #end Main.refreshAssets(); diff --git a/source/funkin/backend/system/framerate/AssetTreeInfo.hx b/source/funkin/backend/system/framerate/AssetTreeInfo.hx index 3f8c0388..b886abb4 100644 --- a/source/funkin/backend/system/framerate/AssetTreeInfo.hx +++ b/source/funkin/backend/system/framerate/AssetTreeInfo.hx @@ -22,9 +22,9 @@ class AssetTreeInfo extends FramerateCategory { } if (l is ScriptedAssetLibrary) - text += '${Type.getClassName(Type.getClass(l))} - ${cast(l, ScriptedAssetLibrary).scriptName} (${cast(l, ScriptedAssetLibrary).libName} | ${cast(l, ScriptedAssetLibrary).prefix})\n'; + text += '${Type.getClassName(Type.getClass(l))} - ${cast(l, ScriptedAssetLibrary).scriptName} (${cast(l, ScriptedAssetLibrary).modName} | ${cast(l, ScriptedAssetLibrary).libName} | ${cast(l, ScriptedAssetLibrary).prefix})\n'; else if (l is IModsAssetLibrary) - text += '${Type.getClassName(Type.getClass(l))} - ${cast(l, IModsAssetLibrary).libName} (${cast(l, IModsAssetLibrary).prefix})\n'; + text += '${Type.getClassName(Type.getClass(l))} - ${cast(l, IModsAssetLibrary).modName} - ${cast(l, IModsAssetLibrary).libName} (${cast(l, IModsAssetLibrary).prefix})\n'; else text += Std.string(e) + "\n"; }