From 1dc7c513e4aa7c2a134bb4062800cf7ca992b592 Mon Sep 17 00:00:00 2001 From: Ilia Glazkov Date: Thu, 22 Jan 2015 15:22:43 -0800 Subject: [PATCH] Support custom prefix (root) for resources URLs in html5. Allow users to specify custom resources root in lime.embed. --- lime/app/Config.hx | 3 ++- lime/system/System.hx | 5 +++-- templates/haxe/ApplicationMain.hx | 4 +++- templates/haxe/DefaultAssetLibrary.hx | 7 +++++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lime/app/Config.hx b/lime/app/Config.hx index f1b01affd..ea1aa3c8a 100644 --- a/lime/app/Config.hx +++ b/lime/app/Config.hx @@ -9,6 +9,7 @@ typedef Config = { @:optional var depthBuffer:Bool; #if (js && html5) @:optional var element:js.html.HtmlElement; + @:optional var assetsPrefix:String; #end @:optional var fps:Int; @:optional var fullscreen:Bool; @@ -20,4 +21,4 @@ typedef Config = { @:optional var vsync:Bool; @:optional var width:Int; -} \ No newline at end of file +} diff --git a/lime/system/System.hx b/lime/system/System.hx index b81a2920d..409c12ef0 100644 --- a/lime/system/System.hx +++ b/lime/system/System.hx @@ -29,7 +29,7 @@ class System { #if (js && html5) @:keep @:expose("lime.embed") - public static function embed (element:Dynamic, width:Null = null, height:Null = null, background:String = null) { + public static function embed (element:Dynamic, width:Null = null, height:Null = null, background:String = null, assetsPrefix:String = null) { var htmlElement:HtmlElement = null; @@ -82,6 +82,7 @@ class System { ApplicationMain.config.element = htmlElement; ApplicationMain.config.width = width; ApplicationMain.config.height = height; + ApplicationMain.config.assetsPrefix = assetsPrefix; ApplicationMain.create (); #end @@ -402,4 +403,4 @@ class System { } -#end \ No newline at end of file +#end diff --git a/templates/haxe/ApplicationMain.hx b/templates/haxe/ApplicationMain.hx index cfdcdeb22..206fd92d2 100644 --- a/templates/haxe/ApplicationMain.hx +++ b/templates/haxe/ApplicationMain.hx @@ -32,6 +32,8 @@ class ApplicationMain { ::else::types.push (null);::end:: ::end::::end:: + urls = [for (url in urls) Assets.getPath(url)]; + preloader.load (urls, types); #end @@ -95,4 +97,4 @@ class ApplicationMain { #end -} \ No newline at end of file +} diff --git a/templates/haxe/DefaultAssetLibrary.hx b/templates/haxe/DefaultAssetLibrary.hx index 6de3c49c7..fafa1dc33 100644 --- a/templates/haxe/DefaultAssetLibrary.hx +++ b/templates/haxe/DefaultAssetLibrary.hx @@ -57,6 +57,13 @@ class DefaultAssetLibrary extends AssetLibrary { type.set (id, AssetType.$$upper(::type::)); ::end::::end:: + var assetsPrefix = ApplicationMain.config.assetsPrefix; + if (assetsPrefix != null) { + for (k in path.keys()) { + path.set(k, assetsPrefix + path[k]); + } + } + #else #if openfl