diff --git a/lime/tools/platforms/HTML5Platform.hx b/lime/tools/platforms/HTML5Platform.hx
index a2c35bf8e..6efe77783 100644
--- a/lime/tools/platforms/HTML5Platform.hx
+++ b/lime/tools/platforms/HTML5Platform.hx
@@ -174,6 +174,8 @@ class HTML5Platform extends PlatformTarget {
ModuleHelper.updateProject (project);
+ project.haxeflags.push ("-resource " + targetDirectory + "/obj/manifest@__ASSET_MANIFEST__");
+
var context = project.templateContext;
context.WIN_FLASHBACKGROUND = project.window.background != null ? StringTools.hex (project.window.background, 6) : "";
@@ -271,7 +273,7 @@ class HTML5Platform extends PlatformTarget {
FileHelper.recursiveCopyTemplate (project.templatePaths, "haxe", targetDirectory + "/haxe", context);
FileHelper.recursiveCopyTemplate (project.templatePaths, "html5/haxe", targetDirectory + "/haxe", context, true, false);
FileHelper.recursiveCopyTemplate (project.templatePaths, "html5/hxml", targetDirectory + "/haxe", context);
-
+
if (project.targetFlags.exists ("webgl")) {
FileHelper.recursiveCopyTemplate (project.templatePaths, "webgl/hxml", targetDirectory + "/haxe", context, true, false);
@@ -293,7 +295,7 @@ class HTML5Platform extends PlatformTarget {
}
- AssetHelper.createManifest (project, PathHelper.combine (destination, "manifest"));
+ AssetHelper.createManifest (project, PathHelper.combine (targetDirectory, "obj/manifest"));
}
diff --git a/templates/haxe/DefaultAssetLibrary.hx b/templates/haxe/DefaultAssetLibrary.hx
index efb850478..3deb1339c 100644
--- a/templates/haxe/DefaultAssetLibrary.hx
+++ b/templates/haxe/DefaultAssetLibrary.hx
@@ -1,6 +1,7 @@
package;
+import haxe.Resource;
import haxe.Timer;
import haxe.Unserializer;
import lime.utils.AssetLibrary;
@@ -19,62 +20,55 @@ import sys.FileSystem;
private var lastModified:Float;
+ private var rootPath:String;
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 () {
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 (assets != null)::::foreach assets::::if (embed)::classTypes.set ("::id::", __ASSET__::flatName::);::else::paths.set ("::id::", "::resourceName::");::end::
- types.set ("::id::", AssetType.$$upper(::type::));
- ::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]);
- }
- }
+ types.set ("::id::", AssetType.$$upper(::type::));::end::::end::
#else
- #if (windows || mac || linux)
+ if (ApplicationMain.config != null && Reflect.hasField (ApplicationMain.config, "assetsPrefix")) {
+
+ rootPath = Reflect.field (ApplicationMain.config, "assetsPrefix");
+
+ }
- var useManifest = false;
- ::if (assets != null)::::foreach assets::::if (type == "font")::
- classTypes.set ("::id::", __ASSET__::flatName::);
- types.set ("::id::", AssetType.$$upper(::type::));
- ::else::::if (embed)::
- classTypes.set ("::id::", __ASSET__::flatName::);
- types.set ("::id::", AssetType.$$upper(::type::));
+ if (rootPath == null) {
+
+ #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;
::end::::end::::end::::end::
@@ -82,9 +76,10 @@ import sys.FileSystem;
loadManifest ();
+ #if sys
if (false && Sys.args ().indexOf ("-livereload") > -1) {
- var path = FileSystem.fullPath ("manifest");
+ var path = FileSystem.fullPath (rootPath + "manifest");
if (FileSystem.exists (path)) {
@@ -109,69 +104,83 @@ import sys.FileSystem;
}
}
+ #end
}
- #else
-
- loadManifest ();
-
- #end
#end
}
- #if (!flash && !html5)
private function loadManifest ():Void {
- try {
+ var bytes = Resource.getBytes ("__ASSET_MANIFEST__");
+ var manifest;
+
+ if (bytes != null) {
- #if blackberry
- var manifest = AssetManifest.fromFile ("app/native/manifest");
- #elseif tizen
- var manifest = AssetManifest.fromFile ("../res/manifest");
- #elseif emscripten
- var manifest = AssetManifest.fromFile ("assets/manifest");
- #elseif (mac && java)
- var manifest = AssetManifest.fromFile ("../Resources/manifest");
- #elseif (ios || tvos)
- var manifest = AssetManifest.fromFile ("assets/manifest");
- #else
- var manifest = AssetManifest.fromFile ("manifest");
- #end
+ __fromManifest (AssetManifest.fromBytes (bytes));
+
+ } else {
+
+ // TODO: Make asynchronous
+
+ var manifest = AssetManifest.fromFile (rootPath + "manifest");
if (manifest != null) {
- for (asset in manifest.assets) {
-
- 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));
-
- }
-
- }
+ __fromManifest (manifest);
} else {
Log.warn ("Could not load asset manifest (bytes was null)");
}
-
- } catch (e:Dynamic) {
- Log.warn ('Could not load asset manifest (${e})');
+ //AssetManifest.loadFromFile (rootPath + "manifest").onComplete (function (manifest:AssetManifest) {
+ //
+ //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::
::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::
-::end::
-
-#else
+::if (assets != null)::::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::
::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::
-#if (windows || mac || linux || cpp)
+#else
-::if (assets != null)::
-::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 {}
+::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 (); }}
::end::::end::::end::
-::end::
-#end
#end
#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
\ No newline at end of file