From e01cc817ef15bdbaa1341af8ed8a4735794e81d5 Mon Sep 17 00:00:00 2001 From: Andreas Schaafsma Date: Fri, 11 Apr 2025 23:54:05 +0200 Subject: [PATCH] enable loading multiple manifests --- .../src/ManifestResources.hx | 64 +++++++++++-------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/standalone-openfl-app/src/ManifestResources.hx b/standalone-openfl-app/src/ManifestResources.hx index 04eee418..0696fb2c 100644 --- a/standalone-openfl-app/src/ManifestResources.hx +++ b/standalone-openfl-app/src/ManifestResources.hx @@ -1,5 +1,6 @@ package; +#if sys import haxe.io.Path; import lime.utils.AssetLibrary; import lime.utils.AssetManifest; @@ -8,33 +9,42 @@ import sys.FileSystem; @:access(lime.utils.Assets) @:keep class ManifestResources { - public static var preloadLibraries:Array = []; - public static var preloadLibraryNames:Array = []; - public static var rootPath:String; + public static var preloadLibraries:Array = []; + public static var preloadLibraryNames:Array = []; + public static var rootPath:String; - public static function init(config:Dynamic):Void { - rootPath = ""; + public static function init(config:Dynamic):Void { + rootPath = ""; - #if sys - var manifestPath = Path.join(["manifest", "data.json"]); - if (!FileSystem.exists(manifestPath)) { - trace("Manifest file not found: " + manifestPath); - return; - } - #end + var manifestDirPath = Path.join(["manifest"]); + var manifests = FileSystem.readDirectory(manifestDirPath); + for (manifest in manifests) { + if (StringTools.endsWith(manifest, ".json")) { + var manifestPath = Path.join([manifestDirPath, manifest]); + loadManifest(manifestPath); + } + } + } - try { - var manifest = AssetManifest.fromFile(manifestPath); - if (manifest != null) { - var library = AssetLibrary.fromManifest(manifest); - if (library != null) { - preloadLibraries.push(library); - preloadLibraryNames.push("default"); - LimeAssets.registerLibrary("default", library); - } - } - } catch (e:Dynamic) { - trace("Error loading asset manifest: " + e); - } - } -} \ No newline at end of file + public static function loadManifest(manifestPath) { + if (!FileSystem.exists(manifestPath)) { + trace("Manifest file not found: " + manifestPath); + return; + } + + try { + var manifest = AssetManifest.fromFile(manifestPath); + if (manifest != null) { + var library = AssetLibrary.fromManifest(manifest); + if (library != null) { + preloadLibraries.push(library); + preloadLibraryNames.push("default"); + LimeAssets.registerLibrary("default", library); + } + } + } catch (e:Dynamic) { + trace("Error loading asset manifest: " + e); + } + } +} +#end