Centralize AssetManifest base path logic (still need to improve this system)
This commit is contained in:
@@ -636,6 +636,7 @@ class AssetLibrary {
|
||||
private function __fromManifest (manifest:AssetManifest):Void {
|
||||
|
||||
var hasSize = (manifest.version >= 2);
|
||||
var basePath = manifest.basePath;
|
||||
var size, id;
|
||||
|
||||
for (asset in manifest.assets) {
|
||||
@@ -643,7 +644,7 @@ class AssetLibrary {
|
||||
size = hasSize ? asset.size : 100;
|
||||
id = asset.id;
|
||||
|
||||
paths.set (id, asset.path);
|
||||
paths.set (id, basePath + asset.path);
|
||||
sizes.set (id, size);
|
||||
types.set (id, asset.type);
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ class AssetManifest {
|
||||
|
||||
|
||||
public var assets:Array<Dynamic>;
|
||||
public var basePath:String;
|
||||
public var libraryArgs:Array<String>;
|
||||
public var libraryType:String;
|
||||
public var name:String;
|
||||
@@ -29,6 +30,7 @@ class AssetManifest {
|
||||
public function new () {
|
||||
|
||||
assets = [];
|
||||
basePath = "";
|
||||
libraryArgs = [];
|
||||
version = 2;
|
||||
|
||||
|
||||
@@ -474,7 +474,25 @@ class Assets {
|
||||
|
||||
loadText ("libraries/" + name + ".json").onComplete (function (data) {
|
||||
|
||||
var library = AssetLibrary.fromManifest (AssetManifest.parse (data));
|
||||
// TODO: Smarter base path logic
|
||||
var manifest = AssetManifest.parse (data);
|
||||
|
||||
if (manifest == null) {
|
||||
|
||||
promise.error ("[Assets] Cannot parse asset manifest for library \"" + name + "\"");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
#if (ios || tvos)
|
||||
if (manifest.basePath == "") {
|
||||
|
||||
manifest.basePath = "assets/";
|
||||
|
||||
}
|
||||
#end
|
||||
|
||||
var library = AssetLibrary.fromManifest (manifest);
|
||||
|
||||
if (library == null) {
|
||||
|
||||
|
||||
@@ -114,7 +114,9 @@ import sys.FileSystem;
|
||||
|
||||
if (bytes != null) {
|
||||
|
||||
__fromManifest (AssetManifest.fromBytes (bytes));
|
||||
var manifest = AssetManifest.fromBytes (bytes);
|
||||
manifest.basePath = rootPath;
|
||||
__fromManifest (manifest);
|
||||
|
||||
} else {
|
||||
|
||||
@@ -124,6 +126,7 @@ import sys.FileSystem;
|
||||
|
||||
if (manifest != null) {
|
||||
|
||||
manifest.basePath = rootPath;
|
||||
__fromManifest (manifest);
|
||||
|
||||
} else {
|
||||
@@ -157,23 +160,6 @@ import sys.FileSystem;
|
||||
}
|
||||
|
||||
|
||||
private override function __fromManifest (manifest:AssetManifest):Void {
|
||||
|
||||
super.__fromManifest (manifest);
|
||||
|
||||
if (rootPath != "") {
|
||||
|
||||
for (asset in manifest.assets) {
|
||||
|
||||
paths.set (asset.id, rootPath + asset.path);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user