From b078c2329028f3eb96b48237b2b8c28cd1d232e5 Mon Sep 17 00:00:00 2001 From: RblSb Date: Sat, 4 Nov 2023 23:43:55 +0300 Subject: [PATCH 1/2] Type Dynamic callbacks in Assets --- Sources/kha/Assets.hx | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Sources/kha/Assets.hx b/Sources/kha/Assets.hx index 7f2fbd395..641b1a400 100644 --- a/Sources/kha/Assets.hx +++ b/Sources/kha/Assets.hx @@ -5,6 +5,29 @@ import haxe.Unserializer; using StringTools; +typedef AssetData = { + name: String, + files: Array, + file_sizes: Array, + type: String, + // image + ?original_width: Int, + ?original_height: Int, + // shader + ?inputs: Array, + ?outputs: Array, + ?uniforms: Array, + ?types: Array<{ + name: String, + members: Array, + }> +} + +private typedef AssetShaderVar = { + type: String, + name: String +} + @:build(kha.internal.AssetsBuilder.build("image")) private class ImageList { public function new() {} @@ -76,8 +99,8 @@ class Assets { Additionally by default all sounds are decompressed. The uncompressSoundsFilter can be used to avoid that. Uncompressed sounds can still be played using Audio.stream which is recommended for music. */ - public static function loadEverything(callback: Void->Void, filter: Dynamic->Bool = null, uncompressSoundsFilter: Dynamic->Bool = null, - ?failed: AssetError->Void): Void { + public static function loadEverything(callback: ()->Void, filter: (item:AssetData)->Bool = null, uncompressSoundsFilter: (soundItem:AssetData)->Bool = null, + ?failed: (err:AssetError)->Void): Void { final lists: Array = [ImageList, SoundList, BlobList, FontList, VideoList]; final listInstances: Array = [images, sounds, blobs, fonts, videos]; var fileCount = 0; From 2b8b6406667fe8f3875198e5a60087b55a249353 Mon Sep 17 00:00:00 2001 From: RblSb Date: Thu, 9 Nov 2023 06:58:27 +0300 Subject: [PATCH 2/2] Move to abstract --- Sources/kha/Assets.hx | 46 +++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/Sources/kha/Assets.hx b/Sources/kha/Assets.hx index 641b1a400..605433ac6 100644 --- a/Sources/kha/Assets.hx +++ b/Sources/kha/Assets.hx @@ -5,27 +5,31 @@ import haxe.Unserializer; using StringTools; -typedef AssetData = { - name: String, - files: Array, - file_sizes: Array, - type: String, - // image - ?original_width: Int, - ?original_height: Int, - // shader - ?inputs: Array, - ?outputs: Array, - ?uniforms: Array, - ?types: Array<{ - name: String, - members: Array, - }> +private typedef AssetDataObject = { + /** File name, given by khamake, used as identifier in `Assets.someList.get()` function **/ + var name: String; + + /** List of file paths, unified by khamake to single file with `name`. **/ + var files: Array; + + /** File sizes in bytes **/ + var file_sizes: Array; + + /** Can be `image`, `sound`, `blob`, `font` and `video` **/ + var type: String; + + /** Original file width (only for images) **/ + var ?original_width: Int; + + /** Original file height (only for images) **/ + var ?original_height: Int; } -private typedef AssetShaderVar = { - type: String, - name: String +@:forward(name, files, file_sizes, type, original_width, original_height) +private abstract AssetData(AssetDataObject) from AssetDataObject { + @:op(a.b) function _get(key: String): Dynamic { + return Reflect.getProperty(this, key); + } } @:build(kha.internal.AssetsBuilder.build("image")) @@ -99,8 +103,8 @@ class Assets { Additionally by default all sounds are decompressed. The uncompressSoundsFilter can be used to avoid that. Uncompressed sounds can still be played using Audio.stream which is recommended for music. */ - public static function loadEverything(callback: ()->Void, filter: (item:AssetData)->Bool = null, uncompressSoundsFilter: (soundItem:AssetData)->Bool = null, - ?failed: (err:AssetError)->Void): Void { + public static function loadEverything(callback: () -> Void, ?filter: (item: AssetData) -> Bool, ?uncompressSoundsFilter: (soundItem: AssetData) -> Bool, + ?failed: (err: AssetError) -> Void): Void { final lists: Array = [ImageList, SoundList, BlobList, FontList, VideoList]; final listInstances: Array = [images, sounds, blobs, fonts, videos]; var fileCount = 0;