Initial support for libraries using asset bundles
This commit is contained in:
@@ -3,6 +3,7 @@ package lime.tools;
|
|||||||
enum AssetType
|
enum AssetType
|
||||||
{
|
{
|
||||||
BINARY;
|
BINARY;
|
||||||
|
BUNDLE;
|
||||||
FONT;
|
FONT;
|
||||||
IMAGE;
|
IMAGE;
|
||||||
MANIFEST;
|
MANIFEST;
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ class Assets
|
|||||||
{
|
{
|
||||||
public static var cache:AssetCache = new AssetCache();
|
public static var cache:AssetCache = new AssetCache();
|
||||||
public static var onChange = new Event<Void->Void>();
|
public static var onChange = new Event<Void->Void>();
|
||||||
|
|
||||||
|
private static var bundlePaths = new Map<String, String>();
|
||||||
private static var defaultRootPath:String;
|
private static var defaultRootPath:String;
|
||||||
private static var libraries(default, null) = new Map<String, AssetLibrary>();
|
private static var libraries(default, null) = new Map<String, AssetLibrary>();
|
||||||
private static var libraryPaths = new Map<String, String>();
|
private static var libraryPaths = new Map<String, String>();
|
||||||
@@ -406,47 +408,77 @@ class Assets
|
|||||||
var path = id;
|
var path = id;
|
||||||
var rootPath = null;
|
var rootPath = null;
|
||||||
|
|
||||||
if (libraryPaths.exists(id))
|
if (bundlePaths.exists(id))
|
||||||
{
|
{
|
||||||
path = libraryPaths[id];
|
AssetBundle.loadFromFile(bundlePaths.get(id)).onComplete(function(bundle)
|
||||||
rootPath = (defaultRootPath != "" ? defaultRootPath + "/" : "") + Path.directory(path);
|
{
|
||||||
|
if (bundle == null)
|
||||||
|
{
|
||||||
|
promise.error("Cannot load bundle for library \"" + id + "\"");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var library = AssetLibrary.fromBundle(bundle);
|
||||||
|
|
||||||
|
if (library == null)
|
||||||
|
{
|
||||||
|
promise.error("Cannot open library \"" + id + "\"");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
libraries.set(id, library);
|
||||||
|
library.onChange.add(onChange.dispatch);
|
||||||
|
promise.completeWith(library.load());
|
||||||
|
}
|
||||||
|
}).onError(function(_)
|
||||||
|
{
|
||||||
|
promise.error("There is no asset library with an ID of \"" + id + "\"");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (StringTools.endsWith(path, ".bundle"))
|
if (libraryPaths.exists(id))
|
||||||
{
|
{
|
||||||
rootPath = path;
|
path = libraryPaths[id];
|
||||||
path += "/library.json";
|
rootPath = (defaultRootPath != "" ? defaultRootPath + "/" : "") + Path.directory(path);
|
||||||
}
|
|
||||||
|
|
||||||
rootPath = (defaultRootPath != "" ? defaultRootPath + "/" : "") + Path.directory(path);
|
|
||||||
path = __cacheBreak(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
AssetManifest.loadFromFile(path, rootPath).onComplete(function(manifest)
|
|
||||||
{
|
|
||||||
if (manifest == null)
|
|
||||||
{
|
|
||||||
promise.error("Cannot parse asset manifest for library \"" + id + "\"");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var library = AssetLibrary.fromManifest(manifest);
|
|
||||||
|
|
||||||
if (library == null)
|
|
||||||
{
|
|
||||||
promise.error("Cannot open library \"" + id + "\"");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
libraries.set(id, library);
|
if (StringTools.endsWith(path, ".bundle"))
|
||||||
library.onChange.add(onChange.dispatch);
|
{
|
||||||
promise.completeWith(library.load());
|
rootPath = path;
|
||||||
|
path += "/library.json";
|
||||||
|
}
|
||||||
|
|
||||||
|
rootPath = (defaultRootPath != "" ? defaultRootPath + "/" : "") + Path.directory(path);
|
||||||
|
path = __cacheBreak(path);
|
||||||
}
|
}
|
||||||
}).onError(function(_)
|
|
||||||
{
|
AssetManifest.loadFromFile(path, rootPath).onComplete(function(manifest)
|
||||||
promise.error("There is no asset library with an ID of \"" + id + "\"");
|
{
|
||||||
});
|
if (manifest == null)
|
||||||
|
{
|
||||||
|
promise.error("Cannot parse asset manifest for library \"" + id + "\"");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var library = AssetLibrary.fromManifest(manifest);
|
||||||
|
|
||||||
|
if (library == null)
|
||||||
|
{
|
||||||
|
promise.error("Cannot open library \"" + id + "\"");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
libraries.set(id, library);
|
||||||
|
library.onChange.add(onChange.dispatch);
|
||||||
|
promise.completeWith(library.load());
|
||||||
|
}
|
||||||
|
}).onError(function(_)
|
||||||
|
{
|
||||||
|
promise.error("There is no asset library with an ID of \"" + id + "\"");
|
||||||
|
});
|
||||||
|
}
|
||||||
#end
|
#end
|
||||||
|
|
||||||
return promise.future;
|
return promise.future;
|
||||||
|
|||||||
@@ -74,7 +74,9 @@ import sys.FileSystem;
|
|||||||
library = AssetLibrary.fromManifest (manifest);
|
library = AssetLibrary.fromManifest (manifest);
|
||||||
Assets.registerLibrary ("::library::", library);
|
Assets.registerLibrary ("::library::", library);
|
||||||
::else::Assets.libraryPaths["::library::"] = rootPath + "::resourceName::";
|
::else::Assets.libraryPaths["::library::"] = rootPath + "::resourceName::";
|
||||||
::end::::end::::end::::end::
|
::end::::end::::if (type == "bundle")::
|
||||||
|
Assets.bundlePaths["::library::"] = rootPath + "::resourceName::";
|
||||||
|
::end::::end::::end::
|
||||||
|
|
||||||
::foreach libraries::::if (preload)::library = Assets.getLibrary ("::name::");
|
::foreach libraries::::if (preload)::library = Assets.getLibrary ("::name::");
|
||||||
if (library != null) preloadLibraries.push (library);
|
if (library != null) preloadLibraries.push (library);
|
||||||
|
|||||||
Reference in New Issue
Block a user