Unify DefaultAssetLibrary around AssetManifest logic
This commit is contained in:
@@ -174,6 +174,8 @@ class HTML5Platform extends PlatformTarget {
|
|||||||
|
|
||||||
ModuleHelper.updateProject (project);
|
ModuleHelper.updateProject (project);
|
||||||
|
|
||||||
|
project.haxeflags.push ("-resource " + targetDirectory + "/obj/manifest@__ASSET_MANIFEST__");
|
||||||
|
|
||||||
var context = project.templateContext;
|
var context = project.templateContext;
|
||||||
|
|
||||||
context.WIN_FLASHBACKGROUND = project.window.background != null ? StringTools.hex (project.window.background, 6) : "";
|
context.WIN_FLASHBACKGROUND = project.window.background != null ? StringTools.hex (project.window.background, 6) : "";
|
||||||
@@ -293,7 +295,7 @@ class HTML5Platform extends PlatformTarget {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetHelper.createManifest (project, PathHelper.combine (destination, "manifest"));
|
AssetHelper.createManifest (project, PathHelper.combine (targetDirectory, "obj/manifest"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package;
|
package;
|
||||||
|
|
||||||
|
|
||||||
|
import haxe.Resource;
|
||||||
import haxe.Timer;
|
import haxe.Timer;
|
||||||
import haxe.Unserializer;
|
import haxe.Unserializer;
|
||||||
import lime.utils.AssetLibrary;
|
import lime.utils.AssetLibrary;
|
||||||
@@ -19,62 +20,55 @@ import sys.FileSystem;
|
|||||||
|
|
||||||
|
|
||||||
private var lastModified:Float;
|
private var lastModified:Float;
|
||||||
|
private var rootPath:String;
|
||||||
private var timer:Timer;
|
private var timer:Timer;
|
||||||
|
|
||||||
#if (windows && !cs)
|
|
||||||
private var rootPath = FileSystem.absolutePath (Path.directory (#if (haxe_ver >= 3.3) Sys.programPath () #else Sys.executablePath () #end)) + "/";
|
|
||||||
#else
|
|
||||||
private var rootPath = "";
|
|
||||||
#end
|
|
||||||
|
|
||||||
|
|
||||||
public function new () {
|
public function new () {
|
||||||
|
|
||||||
super ();
|
super ();
|
||||||
|
|
||||||
#if (openfl && !flash)
|
|
||||||
::if (assets != null)::
|
|
||||||
::foreach assets::::if (type == "font")::openfl.text.Font.registerFont (__ASSET__OPENFL__::flatName::);::end::
|
|
||||||
::end::::end::
|
|
||||||
#end
|
|
||||||
|
|
||||||
#if flash
|
#if flash
|
||||||
|
|
||||||
::if (assets != null)::::foreach assets::::if (embed)::classTypes.set ("::id::", __ASSET__::flatName::);::else::paths.set ("::id::", "::resourceName::");::end::
|
::if (assets != null)::::foreach assets::::if (embed)::classTypes.set ("::id::", __ASSET__::flatName::);::else::paths.set ("::id::", "::resourceName::");::end::
|
||||||
types.set ("::id::", AssetType.$$upper(::type::));
|
types.set ("::id::", AssetType.$$upper(::type::));::end::::end::
|
||||||
::end::::end::
|
|
||||||
|
|
||||||
#elseif html5
|
|
||||||
|
|
||||||
::if (assets != null)::var id;
|
|
||||||
::foreach assets::id = "::id::";
|
|
||||||
::if (embed)::preload.set (id, true);
|
|
||||||
::if (type == "font")::classTypes.set (id, __ASSET__::flatName::);::else::paths.set (id, ::if (resourceName == id)::id::else::"::resourceName::"::end::);::end::
|
|
||||||
::else::paths.set (id, ::if (resourceName == id)::id::else::"::resourceName::"::end::);::end::
|
|
||||||
types.set (id, AssetType.$$upper(::type::));
|
|
||||||
::end::::end::
|
|
||||||
|
|
||||||
var assetsPrefix = null;
|
|
||||||
if (ApplicationMain.config != null && Reflect.hasField (ApplicationMain.config, "assetsPrefix")) {
|
|
||||||
assetsPrefix = ApplicationMain.config.assetsPrefix;
|
|
||||||
}
|
|
||||||
if (assetsPrefix != null) {
|
|
||||||
for (k in paths.keys()) {
|
|
||||||
paths.set(k, assetsPrefix + paths[k]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#if (windows || mac || linux)
|
if (ApplicationMain.config != null && Reflect.hasField (ApplicationMain.config, "assetsPrefix")) {
|
||||||
|
|
||||||
var useManifest = false;
|
rootPath = Reflect.field (ApplicationMain.config, "assetsPrefix");
|
||||||
::if (assets != null)::::foreach assets::::if (type == "font")::
|
|
||||||
classTypes.set ("::id::", __ASSET__::flatName::);
|
}
|
||||||
types.set ("::id::", AssetType.$$upper(::type::));
|
|
||||||
::else::::if (embed)::
|
if (rootPath == null) {
|
||||||
classTypes.set ("::id::", __ASSET__::flatName::);
|
|
||||||
types.set ("::id::", AssetType.$$upper(::type::));
|
#if (ios || tvos)
|
||||||
|
rootPath = "assets/";
|
||||||
|
#elseif (windows && !cs)
|
||||||
|
rootPath = FileSystem.absolutePath (Path.directory (#if (haxe_ver >= 3.3) Sys.programPath () #else Sys.executablePath () #end)) + "/";
|
||||||
|
#else
|
||||||
|
rootPath = "";
|
||||||
|
#end
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (openfl && !display)
|
||||||
|
::if (assets != null)::::foreach assets::::if (type == "font")::openfl.text.Font.registerFont (__ASSET__OPENFL__::flatName::);
|
||||||
|
::end::::end::::end::
|
||||||
|
#end
|
||||||
|
|
||||||
|
var useManifest = #if html5 true #else false #end;
|
||||||
|
var id;
|
||||||
|
::if (assets != null)::::foreach assets::id = "::id::";::if (type == "font")::
|
||||||
|
classTypes.set (id, __ASSET__::flatName::);
|
||||||
|
types.set (id, AssetType.$$upper(::type::)); ::else::::if (embed)::
|
||||||
|
#if html5
|
||||||
|
preload.set (id, true);
|
||||||
|
#elseif (desktop || cpp)
|
||||||
|
classTypes.set (id, __ASSET__::flatName::);
|
||||||
|
types.set (id, AssetType.$$upper(::type::));
|
||||||
|
#end
|
||||||
::else::useManifest = true;
|
::else::useManifest = true;
|
||||||
::end::::end::::end::::end::
|
::end::::end::::end::::end::
|
||||||
|
|
||||||
@@ -82,9 +76,10 @@ import sys.FileSystem;
|
|||||||
|
|
||||||
loadManifest ();
|
loadManifest ();
|
||||||
|
|
||||||
|
#if sys
|
||||||
if (false && Sys.args ().indexOf ("-livereload") > -1) {
|
if (false && Sys.args ().indexOf ("-livereload") > -1) {
|
||||||
|
|
||||||
var path = FileSystem.fullPath ("manifest");
|
var path = FileSystem.fullPath (rootPath + "manifest");
|
||||||
|
|
||||||
if (FileSystem.exists (path)) {
|
if (FileSystem.exists (path)) {
|
||||||
|
|
||||||
@@ -109,54 +104,33 @@ import sys.FileSystem;
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
loadManifest ();
|
|
||||||
|
|
||||||
#end
|
|
||||||
#end
|
#end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if (!flash && !html5)
|
|
||||||
private function loadManifest ():Void {
|
private function loadManifest ():Void {
|
||||||
|
|
||||||
try {
|
var bytes = Resource.getBytes ("__ASSET_MANIFEST__");
|
||||||
|
var manifest;
|
||||||
|
|
||||||
#if blackberry
|
if (bytes != null) {
|
||||||
var manifest = AssetManifest.fromFile ("app/native/manifest");
|
|
||||||
#elseif tizen
|
__fromManifest (AssetManifest.fromBytes (bytes));
|
||||||
var manifest = AssetManifest.fromFile ("../res/manifest");
|
|
||||||
#elseif emscripten
|
} else {
|
||||||
var manifest = AssetManifest.fromFile ("assets/manifest");
|
|
||||||
#elseif (mac && java)
|
// TODO: Make asynchronous
|
||||||
var manifest = AssetManifest.fromFile ("../Resources/manifest");
|
|
||||||
#elseif (ios || tvos)
|
var manifest = AssetManifest.fromFile (rootPath + "manifest");
|
||||||
var manifest = AssetManifest.fromFile ("assets/manifest");
|
|
||||||
#else
|
|
||||||
var manifest = AssetManifest.fromFile ("manifest");
|
|
||||||
#end
|
|
||||||
|
|
||||||
if (manifest != null) {
|
if (manifest != null) {
|
||||||
|
|
||||||
for (asset in manifest.assets) {
|
__fromManifest (manifest);
|
||||||
|
|
||||||
if (!classTypes.exists (asset.id)) {
|
|
||||||
|
|
||||||
#if (ios || tvos)
|
|
||||||
paths.set (asset.id, rootPath + "assets/" + asset.path);
|
|
||||||
#else
|
|
||||||
paths.set (asset.id, rootPath + asset.path);
|
|
||||||
#end
|
|
||||||
types.set (asset.id, cast (asset.type, AssetType));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -164,14 +138,49 @@ import sys.FileSystem;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e:Dynamic) {
|
//AssetManifest.loadFromFile (rootPath + "manifest").onComplete (function (manifest:AssetManifest) {
|
||||||
|
//
|
||||||
Log.warn ('Could not load asset manifest (${e})');
|
//if (manifest != null) {
|
||||||
|
//
|
||||||
|
//__fromManifest (manifest);
|
||||||
|
//
|
||||||
|
//} else {
|
||||||
|
//
|
||||||
|
//Log.warn ("Could not load asset manifest (bytes was null)");
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//__fromManifest (manifest);
|
||||||
|
//
|
||||||
|
//}).onError (function (e:Dynamic) {
|
||||||
|
//
|
||||||
|
//Log.warn ('Could not load asset manifest (${e})');
|
||||||
|
//
|
||||||
|
//});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private override function __fromManifest (manifest:AssetManifest):Void {
|
||||||
|
|
||||||
|
if (manifest.version == 1) {
|
||||||
|
|
||||||
|
for (asset in manifest.assets) {
|
||||||
|
|
||||||
|
if (!classTypes.exists (asset.id)) {
|
||||||
|
|
||||||
|
paths.set (asset.id, rootPath + asset.path);
|
||||||
|
types.set (asset.id, cast (asset.type, AssetType));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#end
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -183,33 +192,28 @@ import sys.FileSystem;
|
|||||||
::foreach assets::::if (embed)::::if (type == "image")::@:keep @:bind #if display private #end class __ASSET__::flatName:: extends flash.display.BitmapData { public function new () { super (0, 0, true, 0); } }::else::@:keep @:bind #if display private #end class __ASSET__::flatName:: extends ::flashClass:: { }::end::::end::
|
::foreach assets::::if (embed)::::if (type == "image")::@:keep @:bind #if display private #end class __ASSET__::flatName:: extends flash.display.BitmapData { public function new () { super (0, 0, true, 0); } }::else::@:keep @:bind #if display private #end class __ASSET__::flatName:: extends ::flashClass:: { }::end::::end::
|
||||||
::end::
|
::end::
|
||||||
|
|
||||||
#elseif html5
|
#elseif (desktop || cpp)
|
||||||
|
|
||||||
::foreach assets::::if (type == "font")::@:keep #if display private #end class __ASSET__::flatName:: extends lime.text.Font { public function new () { super (); name = "::fontName::"; } } ::end::
|
::if (assets != null)::::foreach assets::::if (embed)::::if (type == "image")::@:image("::sourcePath::") #if display private #end class __ASSET__::flatName:: extends lime.graphics.Image {}
|
||||||
::end::
|
::elseif (type == "sound")::@:file("::sourcePath::") #if display private #end class __ASSET__::flatName:: extends haxe.io.Bytes {}
|
||||||
|
::elseif (type == "music")::@:file("::sourcePath::") #if display private #end class __ASSET__::flatName:: extends haxe.io.Bytes {}
|
||||||
#else
|
::elseif (type == "font")::@:font("::sourcePath::") #if display private #end class __ASSET__::flatName:: extends lime.text.Font {}
|
||||||
|
::else::@:file("::sourcePath::") #if display private #end class __ASSET__::flatName:: extends haxe.io.Bytes {}::end::::end::::end::::end::
|
||||||
|
|
||||||
::if (assets != null)::::foreach assets::::if (!embed)::::if (type == "font")::@:keep #if display private #end class __ASSET__::flatName:: extends lime.text.Font { public function new () { __fontPath = #if (ios || tvos) "assets/" + #end "::targetPath::"; name = "::fontName::"; super (); }}
|
::if (assets != null)::::foreach assets::::if (!embed)::::if (type == "font")::@:keep #if display private #end class __ASSET__::flatName:: extends lime.text.Font { public function new () { __fontPath = #if (ios || tvos) "assets/" + #end "::targetPath::"; name = "::fontName::"; super (); }}
|
||||||
::end::::end::::end::::end::
|
::end::::end::::end::::end::
|
||||||
|
|
||||||
#if (windows || mac || linux || cpp)
|
#else
|
||||||
|
|
||||||
::if (assets != null)::
|
::if (assets != null)::::foreach assets::::if (type == "font")::@:keep #if display private #end class __ASSET__::flatName:: extends lime.text.Font { public function new () { #if !html5 __fontPath = "::targetPath::"; #end name = "::fontName::"; super (); }}
|
||||||
::foreach assets::::if (embed)::::if (type == "image")::@:image("::sourcePath::") #if display private #end class __ASSET__::flatName:: extends lime.graphics.Image {}
|
|
||||||
::elseif (type == "sound")::@:file("::sourcePath::") #if display private #end class __ASSET__::flatName:: extends haxe.io.Bytes {}
|
|
||||||
::elseif (type == "music")::@:file("::sourcePath::") #if display private #end class __ASSET__::flatName:: extends haxe.io.Bytes {}
|
|
||||||
::elseif (type == "font")::@:font("::sourcePath::") #if display private #end class __ASSET__::flatName:: extends lime.text.Font {}
|
|
||||||
::else::@:file("::sourcePath::") #if display private #end class __ASSET__::flatName:: extends haxe.io.Bytes {}
|
|
||||||
::end::::end::::end::
|
::end::::end::::end::
|
||||||
::end::
|
|
||||||
|
|
||||||
#end
|
|
||||||
#end
|
#end
|
||||||
|
|
||||||
#if (openfl && !flash)
|
#if (openfl && !flash)
|
||||||
::if (assets != null)::::foreach assets::::if (type == "font")::@:keep #if display private #end class __ASSET__OPENFL__::flatName:: extends openfl.text.Font { public function new () { ::if (embed)::var font = new __ASSET__::flatName:: (); src = font.src; name = font.name;::else::__fontPath = #if (ios || tvos) "assets/" + #end "::targetPath::"; name = "::fontName::";::end:: super (); }}
|
|
||||||
|
::if (assets != null)::::foreach assets::::if (type == "font")::@:keep #if display private #end class __ASSET__OPENFL__::flatName:: extends openfl.text.Font { public function new () { ::if (embed)::var font = new __ASSET__::flatName:: (); src = font.src; name = font.name;::else::#if !html5 __fontPath = #if (ios || tvos) "assets/" + #end "::targetPath::"; #end name = "::fontName::";::end:: super (); }}
|
||||||
::end::::end::::end::
|
::end::::end::::end::
|
||||||
#end
|
|
||||||
|
|
||||||
#end
|
#end
|
||||||
|
#end
|
||||||
Reference in New Issue
Block a user