enable loading multiple manifests

This commit is contained in:
Andreas Schaafsma 2025-04-11 23:54:05 +02:00
parent d73b8bb02e
commit e01cc817ef

View File

@ -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<AssetLibrary> = [];
public static var preloadLibraryNames:Array<String> = [];
public static var rootPath:String;
public static var preloadLibraries:Array<AssetLibrary> = [];
public static var preloadLibraryNames:Array<String> = [];
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);
}
}
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