From 929dd2b01573653822a143da3404007c65bc3221 Mon Sep 17 00:00:00 2001 From: Joseph Cloutier Date: Sat, 24 Feb 2024 18:29:23 -0500 Subject: [PATCH 1/7] Use class reification for readability. --- src/lime/_internal/macros/AssetsMacro.hx | 270 +++++------------------ 1 file changed, 59 insertions(+), 211 deletions(-) diff --git a/src/lime/_internal/macros/AssetsMacro.hx b/src/lime/_internal/macros/AssetsMacro.hx index a9aae1f08..cc7310b84 100644 --- a/src/lime/_internal/macros/AssetsMacro.hx +++ b/src/lime/_internal/macros/AssetsMacro.hx @@ -30,7 +30,9 @@ class AssetsMacro if (fields != null) { #if !display - var constructor = macro + var definition = macro class Temp + { + public function new(?length:Int, ?bytesData:haxe.io.BytesData) { var bytes = haxe.Resource.getBytes(resourceName); #if html5 @@ -40,25 +42,10 @@ class AssetsMacro #else super(bytes.length, bytes.b); #end - }; + } + }; - var args = [ - {name: "length", opt: true, type: macro:Int}, - {name: "bytesData", opt: true, type: macro:haxe.io.BytesData} - ]; - fields.push( - { - name: "new", - access: [APublic], - kind: FFun( - { - args: args, - expr: constructor, - params: [], - ret: null - }), - pos: Context.currentPos() - }); + fields.push(definition.fields[0]); #end } @@ -72,29 +59,16 @@ class AssetsMacro if (fields != null) { #if !display - var constructor = macro + var definition = macro class Temp + { + public function new(?length:Int, ?bytesData:haxe.io.BytesData) { var bytes = haxe.Resource.getBytes(resourceName); super(bytes.b, bytes.length); - }; + } + }; - var args = [ - {name: "length", opt: true, type: macro:Int}, - {name: "bytesData", opt: true, type: macro:haxe.io.BytesData} - ]; - fields.push( - { - name: "new", - access: [APublic], - kind: FFun( - { - args: args, - expr: constructor, - params: [], - ret: null - }), - pos: Context.currentPos() - }); + fields.push(definition.fields[0]); #end } @@ -108,35 +82,18 @@ class AssetsMacro if (fields != null) { #if !display - var constructor = macro + var definition = macro class Temp + { + public function new(?length:Int = 0) { super(); var bytes = haxe.Resource.getBytes(resourceName); __fromBytes(bytes); - }; - - var args = [ - { - name: "length", - opt: true, - type: macro:Int, - value: macro 0 } - ]; - fields.push( - { - name: "new", - access: [APublic], - kind: FFun( - { - args: args, - expr: constructor, - params: [], - ret: null - }), - pos: Context.currentPos() - }); + }; + + fields.push(definition.fields[0]); #end } @@ -200,14 +157,12 @@ class AssetsMacro resourceType = "image/gif"; } - var fieldValue = {pos: position, expr: EConst(CString(resourceType))}; - fields.push( - { - kind: FVar(macro:String, fieldValue), - name: "resourceType", - access: [APrivate, AStatic], - pos: position - }); + var definition = macro class Temp + { + private static var resourceType:String = $v{ resourceType }; + }; + + fields.push(definition.fields[0]); var base64 = Base64.encode(bytes); Context.addResource(resourceName, Bytes.ofString(base64)); @@ -217,14 +172,12 @@ class AssetsMacro Context.addResource(resourceName, bytes); } - var fieldValue = {pos: position, expr: EConst(CString(resourceName))}; - fields.push( - { - kind: FVar(macro:String, fieldValue), - name: "resourceName", - access: [APrivate, AStatic], - pos: position - }); + var definition = macro class Temp + { + private static var resourceName:String = $v{ resourceName }; + }; + + fields.push(definition.fields[0]); return fields; @@ -294,35 +247,20 @@ class AssetsMacro } } - var fieldValue = {pos: position, expr: EConst(CString(resourceName))}; - fields.push( - { - kind: FVar(macro:String, fieldValue), - name: "resourceName", - access: [APublic, AStatic], - pos: position - }); + var definition = macro class Temp + { + private static var resourceName:String = $v{ resourceName }; - var constructor = macro + public function new() { super(); __fromBytes(haxe.Resource.getBytes(resourceName)); - }; + } + }; - fields.push( - { - name: "new", - access: [APublic], - kind: FFun( - { - args: [], - expr: constructor, - params: [], - ret: null - }), - pos: Context.currentPos() - }); + fields.push(definition.fields[0]); + fields.push(definition.fields[1]); return fields; } @@ -342,7 +280,12 @@ class AssetsMacro if (fields != null) { #if !display - var constructor = macro + var definition = macro class Temp + { + public function new(?buffer:lime.graphics.ImageBuffer, + ?offsetX:Int, ?offsetY:Int, ?width:Int, ?height:Int, + ?color:Null, ?type:lime.graphics.ImageType + #if html5 , ?onload:Dynamic = true #end) { #if html5 super(); @@ -376,85 +319,18 @@ class AssetsMacro __fromBytes(haxe.Resource.getBytes(resourceName), null); #end - }; - - var args = [ - { - name: "buffer", - opt: true, - type: macro:lime.graphics.ImageBuffer, - value: null - }, - { - name: "offsetX", - opt: true, - type: macro:Int, - value: null - }, - { - name: "offsetY", - opt: true, - type: macro:Int, - value: null - }, - { - name: "width", - opt: true, - type: macro:Int, - value: null - }, - { - name: "height", - opt: true, - type: macro:Int, - value: null - }, - { - name: "color", - opt: true, - type: macro:Null, - value: null - }, - { - name: "type", - opt: true, - type: macro:lime.graphics.ImageType, - value: null } - ]; + + #if html5 + public static var preload:js.html.Image; + #end + }; #if html5 - args.push( - { - name: "onload", - opt: true, - type: macro:Dynamic, - value: null - }); - fields.push( - { - kind: FVar(macro:js.html.Image, null), - name: "preload", - doc: null, - meta: [], - access: [APublic, AStatic], - pos: Context.currentPos() - }); + fields.push(definition.fields[1]); #end - fields.push( - { - name: "new", - access: [APublic], - kind: FFun( - { - args: args, - expr: constructor, - params: [], - ret: null - }), - pos: Context.currentPos() - }); + fields.push(definition.fields[0]); #end } @@ -468,48 +344,20 @@ class AssetsMacro if (fields != null) { #if (openfl && !html5 && !display) // CFFILoader.h(248) : NOT Implemented:api_buffer_data - - var constructor = macro + var definition = macro class Temp + { + public function new(?stream:openfl.net.URLRequest, + ?context:openfl.media.SoundLoaderContext, + ?forcePlayAsMusic:Bool = false) { super(); var byteArray = openfl.utils.ByteArray.fromBytes(haxe.Resource.getBytes(resourceName)); loadCompressedDataFromByteArray(byteArray, byteArray.length, forcePlayAsMusic); - }; - - var args = [ - { - name: "stream", - opt: true, - type: macro:openfl.net.URLRequest, - value: null - }, - { - name: "context", - opt: true, - type: macro:openfl.media.SoundLoaderContext, - value: null - }, - { - name: "forcePlayAsMusic", - opt: true, - type: macro:Bool, - value: macro false } - ]; - fields.push( - { - name: "new", - access: [APublic], - kind: FFun( - { - args: args, - expr: constructor, - params: [], - ret: null - }), - pos: Context.currentPos() - }); + }; + + fields.push(definition.fields[0]); #end } From 81e129f8047abfbc08544e4ec81b6e03b49e6e3c Mon Sep 17 00:00:00 2001 From: Joseph Cloutier Date: Sat, 24 Feb 2024 18:58:49 -0500 Subject: [PATCH 2/7] Replace `#if !display` in `AssetsMacro`. And while I'm at it, the `if` statement doesn't need to span the whole function. It can be a simple guard clause. --- src/lime/_internal/macros/AssetsMacro.hx | 202 +++++++++++------------ 1 file changed, 92 insertions(+), 110 deletions(-) diff --git a/src/lime/_internal/macros/AssetsMacro.hx b/src/lime/_internal/macros/AssetsMacro.hx index cc7310b84..d3f79ca9d 100644 --- a/src/lime/_internal/macros/AssetsMacro.hx +++ b/src/lime/_internal/macros/AssetsMacro.hx @@ -26,28 +26,24 @@ class AssetsMacro macro public static function embedBytes():Array { var fields = embedData(":file"); + if (fields == null) return null; - if (fields != null) + var definition = macro class Temp { - #if !display - var definition = macro class Temp + public function new(?length:Int, ?bytesData:haxe.io.BytesData) { - public function new(?length:Int, ?bytesData:haxe.io.BytesData) - { - var bytes = haxe.Resource.getBytes(resourceName); - #if html5 - super(bytes.b.buffer); - #elseif hl - super(bytes.b, bytes.length); - #else - super(bytes.length, bytes.b); - #end - } - }; + var bytes = haxe.Resource.getBytes(resourceName); + #if html5 + super(bytes.b.buffer); + #elseif hl + super(bytes.b, bytes.length); + #else + super(bytes.length, bytes.b); + #end + } + }; - fields.push(definition.fields[0]); - #end - } + fields.push(definition.fields[0]); return fields; } @@ -55,22 +51,18 @@ class AssetsMacro macro public static function embedBytesHL():Array { var fields = embedData(":file"); + if (fields == null) return null; - if (fields != null) + var definition = macro class Temp { - #if !display - var definition = macro class Temp + public function new(?length:Int, ?bytesData:haxe.io.BytesData) { - public function new(?length:Int, ?bytesData:haxe.io.BytesData) - { - var bytes = haxe.Resource.getBytes(resourceName); - super(bytes.b, bytes.length); - } - }; + var bytes = haxe.Resource.getBytes(resourceName); + super(bytes.b, bytes.length); + } + }; - fields.push(definition.fields[0]); - #end - } + fields.push(definition.fields[0]); return fields; } @@ -78,31 +70,28 @@ class AssetsMacro macro public static function embedByteArray():Array { var fields = embedData(":file"); + if (fields == null) return null; - if (fields != null) + var definition = macro class Temp { - #if !display - var definition = macro class Temp + public function new(?length:Int = 0) { - public function new(?length:Int = 0) - { - super(); + super(); - var bytes = haxe.Resource.getBytes(resourceName); - __fromBytes(bytes); - } - }; + var bytes = haxe.Resource.getBytes(resourceName); + __fromBytes(bytes); + } + }; - fields.push(definition.fields[0]); - #end - } + fields.push(definition.fields[0]); return fields; } private static function embedData(metaName:String, encode:Bool = false):Array { - #if !display + if (Context.defined("display")) return null; + var classType = Context.getLocalClass().get(); var metaData = classType.meta.get(); var position = Context.currentPos(); @@ -186,13 +175,14 @@ class AssetsMacro } } } - #end return null; } macro public static function embedFont():Array { + if (Context.defined("display")) return Context.getBuildFields(); + var fields = null; var classType = Context.getLocalClass().get(); @@ -203,7 +193,6 @@ class AssetsMacro var path = ""; var glyphs = "32-255"; - #if !display for (meta in metaData) { if (meta.name == ":font") @@ -264,7 +253,6 @@ class AssetsMacro return fields; } - #end return fields; } @@ -276,63 +264,59 @@ class AssetsMacro #else var fields = embedData(":image"); #end + if (fields == null) return null; - if (fields != null) + var definition = macro class Temp { - #if !display - var definition = macro class Temp + public function new(?buffer:lime.graphics.ImageBuffer, + ?offsetX:Int, ?offsetY:Int, ?width:Int, ?height:Int, + ?color:Null, ?type:lime.graphics.ImageType + #if html5 , ?onload:Dynamic = true #end) { - public function new(?buffer:lime.graphics.ImageBuffer, - ?offsetX:Int, ?offsetY:Int, ?width:Int, ?height:Int, - ?color:Null, ?type:lime.graphics.ImageType - #if html5 , ?onload:Dynamic = true #end) - { - #if html5 - super(); - - if (preload != null) - { - var buffer = new lime.graphics.ImageBuffer(); - buffer.__srcImage = preload; - buffer.width = preload.width; - buffer.width = preload.height; - - __fromImageBuffer(buffer); - } - else - { - __fromBase64(haxe.Resource.getString(resourceName), resourceType, function(image) - { - if (preload == null) - { - preload = image.buffer.__srcImage; - } - - if (onload != null) - { - onload(image); - } - }); - } - #else - super(); - - __fromBytes(haxe.Resource.getBytes(resourceName), null); - #end - } - #if html5 - public static var preload:js.html.Image; + super(); + + if (preload != null) + { + var buffer = new lime.graphics.ImageBuffer(); + buffer.__srcImage = preload; + buffer.width = preload.width; + buffer.width = preload.height; + + __fromImageBuffer(buffer); + } + else + { + __fromBase64(haxe.Resource.getString(resourceName), resourceType, function(image) + { + if (preload == null) + { + preload = image.buffer.__srcImage; + } + + if (onload != null) + { + onload(image); + } + }); + } + #else + super(); + + __fromBytes(haxe.Resource.getBytes(resourceName), null); #end - }; + } #if html5 - fields.push(definition.fields[1]); + public static var preload:js.html.Image; #end + }; - fields.push(definition.fields[0]); - #end - } + #if html5 + fields.push(definition.fields[1]); + #end + + fields.push(definition.fields[0]); return fields; } @@ -340,26 +324,24 @@ class AssetsMacro macro public static function embedSound():Array { var fields = embedData(":sound"); + if (fields == null) return null; - if (fields != null) + #if (openfl && !html5) // CFFILoader.h(248) : NOT Implemented:api_buffer_data + var definition = macro class Temp { - #if (openfl && !html5 && !display) // CFFILoader.h(248) : NOT Implemented:api_buffer_data - var definition = macro class Temp + public function new(?stream:openfl.net.URLRequest, + ?context:openfl.media.SoundLoaderContext, + ?forcePlayAsMusic:Bool = false) { - public function new(?stream:openfl.net.URLRequest, - ?context:openfl.media.SoundLoaderContext, - ?forcePlayAsMusic:Bool = false) - { - super(); + super(); - var byteArray = openfl.utils.ByteArray.fromBytes(haxe.Resource.getBytes(resourceName)); - loadCompressedDataFromByteArray(byteArray, byteArray.length, forcePlayAsMusic); - } - }; + var byteArray = openfl.utils.ByteArray.fromBytes(haxe.Resource.getBytes(resourceName)); + loadCompressedDataFromByteArray(byteArray, byteArray.length, forcePlayAsMusic); + } + }; - fields.push(definition.fields[0]); - #end - } + fields.push(definition.fields[0]); + #end return fields; } From c11ae61a1b4442af75bd75a8554d37165284a24c Mon Sep 17 00:00:00 2001 From: Joseph Cloutier Date: Sat, 24 Feb 2024 19:05:51 -0500 Subject: [PATCH 3/7] Replace `#if html5` in `AssetsMacro`. --- src/lime/_internal/macros/AssetsMacro.hx | 122 ++++++++++++----------- 1 file changed, 63 insertions(+), 59 deletions(-) diff --git a/src/lime/_internal/macros/AssetsMacro.hx b/src/lime/_internal/macros/AssetsMacro.hx index d3f79ca9d..ae0993252 100644 --- a/src/lime/_internal/macros/AssetsMacro.hx +++ b/src/lime/_internal/macros/AssetsMacro.hx @@ -28,18 +28,16 @@ class AssetsMacro var fields = embedData(":file"); if (fields == null) return null; + var superCall = Context.defined("html5") ? macro super(bytes.b.buffer) + : Context.defined("hl") ? macro super(bytes.b, bytes.length) + : macro super(bytes.length, bytes.b); + var definition = macro class Temp { public function new(?length:Int, ?bytesData:haxe.io.BytesData) { var bytes = haxe.Resource.getBytes(resourceName); - #if html5 - super(bytes.b.buffer); - #elseif hl - super(bytes.b, bytes.length); - #else - super(bytes.length, bytes.b); - #end + $superCall; } }; @@ -217,10 +215,11 @@ class AssetsMacro if (path != null && path != "") { - #if html5 - Sys.command("haxelib", ["run", "lime", "generate", "-font-hash", sys.FileSystem.fullPath(path)]); - path += ".hash"; - #end + if (Context.defined("html5")) + { + Sys.command("haxelib", ["run", "lime", "generate", "-font-hash", sys.FileSystem.fullPath(path)]); + path += ".hash"; + } var bytes = File.getBytes(path); var resourceName = "LIME_font_" + (classType.pack.length > 0 ? classType.pack.join("_") + "_" : "") + classType.name; @@ -259,64 +258,69 @@ class AssetsMacro macro public static function embedImage():Array { - #if html5 - var fields = embedData(":image", true); - #else - var fields = embedData(":image"); - #end + var fields = embedData(":image", Context.defined("html5")); if (fields == null) return null; - var definition = macro class Temp + var definition:TypeDefinition; + if (Context.defined("html5")) { - public function new(?buffer:lime.graphics.ImageBuffer, - ?offsetX:Int, ?offsetY:Int, ?width:Int, ?height:Int, - ?color:Null, ?type:lime.graphics.ImageType - #if html5 , ?onload:Dynamic = true #end) + definition = macro class Temp { - #if html5 - super(); + public static var preload:js.html.Image; - if (preload != null) + public function new(?buffer:lime.graphics.ImageBuffer, + ?offsetX:Int, ?offsetY:Int, ?width:Int, ?height:Int, + ?color:Null, ?type:lime.graphics.ImageType, + ?onload:Dynamic = true) { - var buffer = new lime.graphics.ImageBuffer(); - buffer.__srcImage = preload; - buffer.width = preload.width; - buffer.width = preload.height; + super(); - __fromImageBuffer(buffer); - } - else - { - __fromBase64(haxe.Resource.getString(resourceName), resourceType, function(image) + if (preload != null) { - if (preload == null) - { - preload = image.buffer.__srcImage; - } + var buffer = new lime.graphics.ImageBuffer(); + buffer.__srcImage = preload; + buffer.width = preload.width; + buffer.width = preload.height; - if (onload != null) + __fromImageBuffer(buffer); + } + else + { + __fromBase64(haxe.Resource.getString(resourceName), resourceType, function(image) { - onload(image); - } - }); + if (preload == null) + { + preload = image.buffer.__srcImage; + } + + if (onload != null) + { + onload(image); + } + }); + } } - #else - super(); + }; + } + else + { + definition = macro class Temp + { + public function new(?buffer:lime.graphics.ImageBuffer, + ?offsetX:Int, ?offsetY:Int, ?width:Int, ?height:Int, + ?color:Null, ?type:lime.graphics.ImageType) + { + super(); - __fromBytes(haxe.Resource.getBytes(resourceName), null); - #end - } + __fromBytes(haxe.Resource.getBytes(resourceName), null); + } + }; + } - #if html5 - public static var preload:js.html.Image; - #end - }; - - #if html5 - fields.push(definition.fields[1]); - #end - - fields.push(definition.fields[0]); + for (field in definition.fields) + { + fields.push(field); + } return fields; } @@ -324,9 +328,10 @@ class AssetsMacro macro public static function embedSound():Array { var fields = embedData(":sound"); - if (fields == null) return null; + // CFFILoader.h(248) : NOT Implemented:api_buffer_data + if (fields == null || Context.defined("html5") || !Context.defined("openfl")) + return null; - #if (openfl && !html5) // CFFILoader.h(248) : NOT Implemented:api_buffer_data var definition = macro class Temp { public function new(?stream:openfl.net.URLRequest, @@ -341,7 +346,6 @@ class AssetsMacro }; fields.push(definition.fields[0]); - #end return fields; } From 3b04a053b76e4ab2ecb85c0b8cdebe96689538fa Mon Sep 17 00:00:00 2001 From: Joseph Cloutier Date: Sat, 24 Feb 2024 19:11:32 -0500 Subject: [PATCH 4/7] Simplify `AssetsMacro.embedData()`. --- src/lime/_internal/macros/AssetsMacro.hx | 142 +++++++++++------------ 1 file changed, 69 insertions(+), 73 deletions(-) diff --git a/src/lime/_internal/macros/AssetsMacro.hx b/src/lime/_internal/macros/AssetsMacro.hx index ae0993252..3a290ded3 100644 --- a/src/lime/_internal/macros/AssetsMacro.hx +++ b/src/lime/_internal/macros/AssetsMacro.hx @@ -91,86 +91,82 @@ class AssetsMacro if (Context.defined("display")) return null; var classType = Context.getLocalClass().get(); - var metaData = classType.meta.get(); + var metaData = classType.meta; var position = Context.currentPos(); var fields = Context.getBuildFields(); - for (meta in metaData) + for (meta in metaData.extract(metaName)) { - if (meta.name == metaName) + if (meta.params.length == 0) continue; + + switch (meta.params[0].expr) { - if (meta.params.length > 0) - { - switch (meta.params[0].expr) + case EConst(CString("" | null)): + return null; + + case EConst(CString(filePath)): + var path = filePath; + + if (!FileSystem.exists(filePath)) { - case EConst(CString(filePath)): - var path = filePath; - - if (path == "") return null; - if (path == null) return null; - - if (!FileSystem.exists(filePath)) - { - path = Context.resolvePath(filePath); - } - - if (!FileSystem.exists(path) || FileSystem.isDirectory(path)) - { - return null; - } - - var bytes = File.getBytes(path); - var resourceName = "__ASSET__" - + metaName - + "_" - + (classType.pack.length > 0 ? classType.pack.join("_") + "_" : "") - + classType.name; - - if (Context.getResources().exists(resourceName)) - { - return null; - } - - if (encode) - { - var resourceType = "image/png"; - - if (bytes.get(0) == 0xFF && bytes.get(1) == 0xD8) - { - resourceType = "image/jpg"; - } - else if (bytes.get(0) == 0x47 && bytes.get(1) == 0x49 && bytes.get(2) == 0x46) - { - resourceType = "image/gif"; - } - - var definition = macro class Temp - { - private static var resourceType:String = $v{ resourceType }; - }; - - fields.push(definition.fields[0]); - - var base64 = Base64.encode(bytes); - Context.addResource(resourceName, Bytes.ofString(base64)); - } - else - { - Context.addResource(resourceName, bytes); - } - - var definition = macro class Temp - { - private static var resourceName:String = $v{ resourceName }; - }; - - fields.push(definition.fields[0]); - - return fields; - - default: + path = Context.resolvePath(filePath); } - } + + if (!FileSystem.exists(path) || FileSystem.isDirectory(path)) + { + return null; + } + + var bytes = File.getBytes(path); + var resourceName = "__ASSET__" + + metaName + + "_" + + (classType.pack.length > 0 ? classType.pack.join("_") + "_" : "") + + classType.name; + + if (Context.getResources().exists(resourceName)) + { + return null; + } + + if (encode) + { + var resourceType = "image/png"; + + if (bytes.get(0) == 0xFF && bytes.get(1) == 0xD8) + { + resourceType = "image/jpg"; + } + else if (bytes.get(0) == 0x47 && bytes.get(1) == 0x49 && bytes.get(2) == 0x46) + { + resourceType = "image/gif"; + } + + var definition = macro class Temp + { + private static var resourceType:String = $v{ resourceType }; + }; + + fields.push(definition.fields[0]); + + var base64 = Base64.encode(bytes); + Context.addResource(resourceName, Bytes.ofString(base64)); + } + else + { + Context.addResource(resourceName, bytes); + } + + var definition = macro class Temp + { + private static var resourceName:String = $v{ resourceName }; + }; + + fields.push(definition.fields[0]); + + return fields; + + default: } } From 95cef7261605e7b3918f7c6131e3fa2e88c14612 Mon Sep 17 00:00:00 2001 From: Joseph Cloutier Date: Sat, 24 Feb 2024 19:13:49 -0500 Subject: [PATCH 5/7] Inline `resourceName` and `resourceType`. Sure they're private, but even then they shouldn't be writable. --- src/lime/_internal/macros/AssetsMacro.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lime/_internal/macros/AssetsMacro.hx b/src/lime/_internal/macros/AssetsMacro.hx index 3a290ded3..206f4b6a4 100644 --- a/src/lime/_internal/macros/AssetsMacro.hx +++ b/src/lime/_internal/macros/AssetsMacro.hx @@ -144,7 +144,7 @@ class AssetsMacro var definition = macro class Temp { - private static var resourceType:String = $v{ resourceType }; + private static inline var resourceType:String = $v{ resourceType }; }; fields.push(definition.fields[0]); @@ -159,7 +159,7 @@ class AssetsMacro var definition = macro class Temp { - private static var resourceName:String = $v{ resourceName }; + private static inline var resourceName:String = $v{ resourceName }; }; fields.push(definition.fields[0]); From adcccc863fef30f190076f7af7dc9e1e0fca26d2 Mon Sep 17 00:00:00 2001 From: Joseph Cloutier Date: Sat, 24 Feb 2024 19:25:37 -0500 Subject: [PATCH 6/7] Remove `embedBytesHL()` function. This was likely added when `#if hl` began to fail, hiding the problem. With the issue fixed, there's no more need for a workaround. --- src/haxe/io/Bytes.hx | 2 +- src/lime/_internal/macros/AssetsMacro.hx | 19 ------------------- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/src/haxe/io/Bytes.hx b/src/haxe/io/Bytes.hx index ac2c2bb5e..5134e72fa 100644 --- a/src/haxe/io/Bytes.hx +++ b/src/haxe/io/Bytes.hx @@ -945,7 +945,7 @@ class Bytes } #elseif hl #if !macro -@:autoBuild(lime._internal.macros.AssetsMacro.embedBytesHL()) // Enable @:bytes embed metadata +@:autoBuild(lime._internal.macros.AssetsMacro.embedBytes()) // Enable @:bytes embed metadata #end @:coreApi class Bytes diff --git a/src/lime/_internal/macros/AssetsMacro.hx b/src/lime/_internal/macros/AssetsMacro.hx index 206f4b6a4..5a0dbc727 100644 --- a/src/lime/_internal/macros/AssetsMacro.hx +++ b/src/lime/_internal/macros/AssetsMacro.hx @@ -46,25 +46,6 @@ class AssetsMacro return fields; } - macro public static function embedBytesHL():Array - { - var fields = embedData(":file"); - if (fields == null) return null; - - var definition = macro class Temp - { - public function new(?length:Int, ?bytesData:haxe.io.BytesData) - { - var bytes = haxe.Resource.getBytes(resourceName); - super(bytes.b, bytes.length); - } - }; - - fields.push(definition.fields[0]); - - return fields; - } - macro public static function embedByteArray():Array { var fields = embedData(":file"); From 2fd8817ed6543fe0630e9a4fb3c9eca9a83e60d2 Mon Sep 17 00:00:00 2001 From: Joseph Cloutier Date: Sat, 24 Feb 2024 19:39:05 -0500 Subject: [PATCH 7/7] Exclude `AssetMacro` from doc builds. --- src/lime/_internal/macros/AssetsMacro.hx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lime/_internal/macros/AssetsMacro.hx b/src/lime/_internal/macros/AssetsMacro.hx index 5a0dbc727..5871daa80 100644 --- a/src/lime/_internal/macros/AssetsMacro.hx +++ b/src/lime/_internal/macros/AssetsMacro.hx @@ -15,8 +15,11 @@ import sys.FileSystem; class AssetsMacro { - #if !macro - macro public static function cacheVersion() {} + #if (!macro || display) + macro public static function cacheVersion() + { + return macro 0; + } #else macro public static function cacheVersion() {