From d33dd96cdc88bd30d7f6bc8948d39fe534bea1b4 Mon Sep 17 00:00:00 2001 From: MattTuttle Date: Thu, 15 Jan 2015 14:05:41 -0600 Subject: [PATCH] Enabling asset embedding for lime native (bytes/text/image working) --- lime/graphics/TextFormat.hx | 7 ++++++- lime/utils/ByteArray.hx | 2 +- templates/haxe/DefaultAssetLibrary.hx | 27 ++++++++++++--------------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lime/graphics/TextFormat.hx b/lime/graphics/TextFormat.hx index 248d9ae4e..fb5f4187b 100644 --- a/lime/graphics/TextFormat.hx +++ b/lime/graphics/TextFormat.hx @@ -192,11 +192,16 @@ class TextFormat { } + @:access(lime.graphics.Font) public function fromString (font:Font, size:Int, text:String):Array { #if (cpp || neko || nodejs) - return lime_text_from_string (handle, font.handle, size, text); + return lime_text_from_string (handle, font.__handle, size, text); + + #else + + return null; #end diff --git a/lime/utils/ByteArray.hx b/lime/utils/ByteArray.hx index f9aa59a4d..ad8af56c5 100644 --- a/lime/utils/ByteArray.hx +++ b/lime/utils/ByteArray.hx @@ -28,7 +28,7 @@ import cpp.NativeArray; import sys.io.File; #end -@:autoBuild(openfl.Assets.embedFile()) +@:autoBuild(lime.Assets.embedFile()) class ByteArray #if !js extends Bytes implements ArrayAccess implements IDataInput implements IMemoryRange #end { diff --git a/templates/haxe/DefaultAssetLibrary.hx b/templates/haxe/DefaultAssetLibrary.hx index c53b58761..6de3c49c7 100644 --- a/templates/haxe/DefaultAssetLibrary.hx +++ b/templates/haxe/DefaultAssetLibrary.hx @@ -67,13 +67,12 @@ class DefaultAssetLibrary extends AssetLibrary { #if (windows || mac || linux) - /*var useManifest = false; + var useManifest = false; ::if (assets != null)::::foreach assets::::if (embed):: className.set ("::id::", __ASSET__::flatName::); type.set ("::id::", AssetType.$$upper(::type::)); ::else::useManifest = true; - ::end::::end::::end::*/ - var useManifest = true; + ::end::::end::::end:: if (useManifest) { @@ -222,10 +221,8 @@ class DefaultAssetLibrary extends AssetLibrary { #else - //return null; - //if (className.exists(id)) return cast (Type.createInstance (className.get (id), []), ByteArray); - //else - return ByteArray.readFile (path.get (id)); + if (className.exists(id)) return cast (Type.createInstance (className.get (id), []), ByteArray); + else return ByteArray.readFile (path.get (id)); #end @@ -665,14 +662,14 @@ class DefaultAssetLibrary extends AssetLibrary { #if (windows || mac || linux) -//::if (assets != null):: -//::foreach assets::::if (embed)::::if (type == "image")::@:bitmap("::sourcePath::") class __ASSET__::flatName:: extends openfl.display.BitmapData {} -//::elseif (type == "sound")::@:sound("::sourcePath::") class __ASSET__::flatName:: extends openfl.media.Sound {} -//::elseif (type == "music")::@:sound("::sourcePath::") class __ASSET__::flatName:: extends openfl.media.Sound {} -//::elseif (type == "font")::@:font("::sourcePath::") class __ASSET__::flatName:: extends openfl.text.Font {} -//::else::@:file("::sourcePath::") class __ASSET__::flatName:: extends lime.utils.ByteArray {} -//::end::::end::::end:: -//::end:: +::if (assets != null):: +::foreach assets::::if (embed)::::if (type == "image")::@:bitmap("::sourcePath::") class __ASSET__::flatName:: extends lime.graphics.Image {} +::elseif (type == "sound")::@:sound("::sourcePath::") class __ASSET__::flatName:: extends lime.audio.AudioSource {} +::elseif (type == "music")::@:sound("::sourcePath::") class __ASSET__::flatName:: extends lime.audio.AudioSource {} +::elseif (type == "font")::@:font("::sourcePath::") class __ASSET__::flatName:: extends lime.graphics.Font {} +::else::@:file("::sourcePath::") class __ASSET__::flatName:: extends lime.utils.ByteArray {} +::end::::end::::end:: +::end:: #end