Improve base path logic

This commit is contained in:
Joshua Granick
2017-02-21 20:14:24 -08:00
parent 21ce05da52
commit 268b86e973
2 changed files with 56 additions and 10 deletions

View File

@@ -660,7 +660,16 @@ class AssetLibrary {
size = hasSize ? asset.size : 100;
id = asset.id;
paths.set (id, basePath + asset.path);
if (basePath != "") {
paths.set (id, basePath + "/" + asset.path);
} else {
paths.set (id, asset.path);
}
sizes.set (id, size);
types.set (id, asset.type);

View File

@@ -1,6 +1,7 @@
package lime.utils;
import haxe.io.Path;
import haxe.Serializer;
import haxe.Unserializer;
import lime.app.Future;
@@ -37,11 +38,11 @@ class AssetManifest {
}
public static function fromBytes (bytes:Bytes):AssetManifest {
public static function fromBytes (bytes:Bytes, basePath:String = null):AssetManifest {
if (bytes != null) {
return parse (bytes.getString (0, bytes.length));
return parse (bytes.getString (0, bytes.length), basePath);
} else {
@@ -52,32 +53,62 @@ class AssetManifest {
}
public static function fromFile (path:String):AssetManifest {
public static function fromFile (path:String, basePath:String = null):AssetManifest {
return fromBytes (Bytes.fromFile (path));
if (path == null) return null;
if (basePath == null) {
if (path.indexOf ("?") > -1) {
basePath = Path.directory (path.substr (0, path.indexOf ("?")));
} else {
basePath = Path.directory (path);
}
}
return fromBytes (Bytes.fromFile (path), basePath);
}
public static function loadFromBytes (bytes:Bytes):Future<AssetManifest> {
public static function loadFromBytes (bytes:Bytes, basePath:String = null):Future<AssetManifest> {
return Future.withValue (fromBytes (bytes));
return Future.withValue (fromBytes (bytes, basePath));
}
public static function loadFromFile (path:String):Future<AssetManifest> {
public static function loadFromFile (path:String, basePath:String = null):Future<AssetManifest> {
return Bytes.loadFromFile (path).then (function (bytes) {
return Future.withValue (fromBytes (bytes));
if (basePath == null) {
if (path.indexOf ("?") > -1) {
basePath = Path.directory (path.substr (0, path.indexOf ("?")));
} else {
basePath = Path.directory (path);
}
}
return Future.withValue (fromBytes (bytes, basePath));
});
}
public static function parse (data:String):AssetManifest {
public static function parse (data:String, basePath:String = null):AssetManifest {
if (data == null || data == "") return null;
@@ -91,6 +122,12 @@ class AssetManifest {
manifest.libraryArgs = manifestData.libraryArgs;
manifest.assets = Unserializer.run (manifestData.assets);
if (basePath != null) {
manifest.basePath = basePath;
}
return manifest;
#else