@defold-typescript/types 0.39.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/api-availability.json +4024 -716
  2. package/api-migrations.json +27 -0
  3. package/api-signatures.json +18118 -10264
  4. package/api-targets.json +448 -11
  5. package/examples/translations.json +619 -148
  6. package/fixtures/messages_doc.json +96 -0
  7. package/generated/b2d.d.ts +680 -4
  8. package/generated/b2d_body.d.ts +29 -103
  9. package/generated/b2d_chain.d.ts +5 -6
  10. package/generated/b2d_fixture.d.ts +34 -38
  11. package/generated/b2d_joint.d.ts +503 -25
  12. package/generated/b2d_shape.d.ts +199 -14
  13. package/generated/b2d_world.d.ts +57 -63
  14. package/generated/buffer.d.ts +33 -29
  15. package/generated/builtin-messages.d.ts +7 -1
  16. package/generated/bullet3d.d.ts +91 -0
  17. package/generated/bullet3d_collision_object.d.ts +433 -0
  18. package/generated/bullet3d_constraint.d.ts +818 -0
  19. package/generated/bullet3d_rigid_body.d.ts +429 -0
  20. package/generated/bullet3d_shape.d.ts +123 -0
  21. package/generated/bullet3d_world.d.ts +492 -0
  22. package/generated/camera.d.ts +31 -34
  23. package/generated/collectionfactory.d.ts +26 -27
  24. package/generated/collectionproxy.d.ts +22 -6
  25. package/generated/compute.d.ts +12 -238
  26. package/generated/crash.d.ts +24 -10
  27. package/generated/editor-vm/http.d.ts +90 -7
  28. package/generated/editor-vm/image.d.ts +7 -7
  29. package/generated/editor-vm/json.d.ts +11 -0
  30. package/generated/editor-vm/localization.d.ts +7 -7
  31. package/generated/editor-vm/tilemap_tiles.d.ts +56 -10
  32. package/generated/editor-vm/zip.d.ts +28 -0
  33. package/generated/editor.d.ts +1496 -430
  34. package/generated/factory.d.ts +21 -25
  35. package/generated/font.d.ts +64 -22
  36. package/generated/go.d.ts +243 -186
  37. package/generated/graphics.d.ts +374 -84
  38. package/generated/gui.d.ts +282 -492
  39. package/generated/html5.d.ts +5 -3
  40. package/generated/http.d.ts +31 -36
  41. package/generated/image.d.ts +127 -85
  42. package/generated/json.d.ts +34 -16
  43. package/generated/kinds/gui-script.d.ts +8 -0
  44. package/generated/kinds/render-script.d.ts +8 -0
  45. package/generated/kinds/script.d.ts +8 -0
  46. package/generated/label.d.ts +77 -7
  47. package/generated/liveupdate.d.ts +13 -10
  48. package/generated/material.d.ts +312 -360
  49. package/generated/model.d.ts +72 -42
  50. package/generated/particlefx.d.ts +19 -28
  51. package/generated/physics.d.ts +378 -144
  52. package/generated/profiler.d.ts +14 -24
  53. package/generated/render.d.ts +294 -297
  54. package/generated/resource.d.ts +753 -641
  55. package/generated/socket.d.ts +131 -134
  56. package/generated/sound.d.ts +65 -34
  57. package/generated/sprite.d.ts +39 -17
  58. package/generated/sys.d.ts +237 -182
  59. package/generated/tilemap.d.ts +21 -16
  60. package/generated/timer.d.ts +34 -21
  61. package/generated/versions/defold-1.12.4/b2d_body.d.ts +0 -7
  62. package/generated/versions/defold-1.12.4/buffer.d.ts +18 -17
  63. package/generated/versions/defold-1.12.4/camera.d.ts +23 -23
  64. package/generated/versions/defold-1.12.4/collectionfactory.d.ts +21 -19
  65. package/generated/versions/defold-1.12.4/collectionproxy.d.ts +2 -2
  66. package/generated/versions/defold-1.12.4/crash.d.ts +2 -2
  67. package/generated/versions/defold-1.12.4/factory.d.ts +15 -16
  68. package/generated/versions/defold-1.12.4/go.d.ts +15 -17
  69. package/generated/versions/defold-1.12.4/gui.d.ts +111 -193
  70. package/generated/versions/defold-1.12.4/html5.d.ts +4 -2
  71. package/generated/versions/defold-1.12.4/http.d.ts +4 -15
  72. package/generated/versions/defold-1.12.4/image.d.ts +38 -46
  73. package/generated/versions/defold-1.12.4/index.d.ts +2 -0
  74. package/generated/versions/defold-1.12.4/json.d.ts +10 -6
  75. package/generated/versions/defold-1.12.4/label.d.ts +2 -3
  76. package/generated/versions/defold-1.12.4/liveupdate.d.ts +5 -3
  77. package/generated/versions/defold-1.12.4/model.d.ts +34 -13
  78. package/generated/versions/defold-1.12.4/particlefx.d.ts +2 -5
  79. package/generated/versions/defold-1.12.4/physics.d.ts +82 -78
  80. package/generated/versions/defold-1.12.4/profiler.d.ts +3 -6
  81. package/generated/versions/defold-1.12.4/render.d.ts +160 -132
  82. package/generated/versions/defold-1.12.4/resource.d.ts +212 -209
  83. package/generated/versions/defold-1.12.4/socket.d.ts +45 -61
  84. package/generated/versions/defold-1.12.4/sound.d.ts +11 -11
  85. package/generated/versions/defold-1.12.4/sprite.d.ts +24 -6
  86. package/generated/versions/defold-1.12.4/sys.d.ts +45 -68
  87. package/generated/versions/defold-1.12.4/tilemap.d.ts +18 -11
  88. package/generated/versions/defold-1.12.4/timer.d.ts +5 -3
  89. package/generated/versions/defold-1.12.4/vmath.d.ts +5 -26
  90. package/generated/versions/defold-1.12.4/window.d.ts +1 -16
  91. package/generated/versions/defold-1.13.0/b2d_body.d.ts +10 -55
  92. package/generated/versions/defold-1.13.0/b2d_fixture.d.ts +25 -25
  93. package/generated/versions/defold-1.13.0/b2d_shape.d.ts +188 -5
  94. package/generated/versions/defold-1.13.0/b2d_world.d.ts +16 -10
  95. package/generated/versions/defold-1.13.0/buffer.d.ts +18 -17
  96. package/generated/versions/defold-1.13.0/camera.d.ts +27 -27
  97. package/generated/versions/defold-1.13.0/collectionfactory.d.ts +21 -19
  98. package/generated/versions/defold-1.13.0/collectionproxy.d.ts +2 -2
  99. package/generated/versions/defold-1.13.0/compute.d.ts +1 -70
  100. package/generated/versions/defold-1.13.0/crash.d.ts +2 -2
  101. package/generated/versions/defold-1.13.0/editor-vm/tilemap_tiles.d.ts +3 -3
  102. package/generated/versions/defold-1.13.0/editor.d.ts +34 -24
  103. package/generated/versions/defold-1.13.0/factory.d.ts +15 -16
  104. package/generated/versions/defold-1.13.0/go.d.ts +15 -17
  105. package/generated/versions/defold-1.13.0/graphics.d.ts +121 -37
  106. package/generated/versions/defold-1.13.0/gui.d.ts +111 -193
  107. package/generated/versions/defold-1.13.0/html5.d.ts +4 -2
  108. package/generated/versions/defold-1.13.0/http.d.ts +4 -15
  109. package/generated/versions/defold-1.13.0/image.d.ts +38 -46
  110. package/generated/versions/defold-1.13.0/index.d.ts +2 -0
  111. package/generated/versions/defold-1.13.0/json.d.ts +10 -6
  112. package/generated/versions/defold-1.13.0/label.d.ts +2 -3
  113. package/generated/versions/defold-1.13.0/liveupdate.d.ts +7 -5
  114. package/generated/versions/defold-1.13.0/material.d.ts +69 -107
  115. package/generated/versions/defold-1.13.0/model.d.ts +34 -13
  116. package/generated/versions/defold-1.13.0/particlefx.d.ts +2 -5
  117. package/generated/versions/defold-1.13.0/physics.d.ts +82 -78
  118. package/generated/versions/defold-1.13.0/profiler.d.ts +3 -6
  119. package/generated/versions/defold-1.13.0/render.d.ts +160 -132
  120. package/generated/versions/defold-1.13.0/resource.d.ts +217 -210
  121. package/generated/versions/defold-1.13.0/socket.d.ts +45 -61
  122. package/generated/versions/defold-1.13.0/sound.d.ts +11 -11
  123. package/generated/versions/defold-1.13.0/sprite.d.ts +24 -6
  124. package/generated/versions/defold-1.13.0/sys.d.ts +45 -68
  125. package/generated/versions/defold-1.13.0/tilemap.d.ts +18 -11
  126. package/generated/versions/defold-1.13.0/timer.d.ts +5 -3
  127. package/generated/versions/defold-1.13.0/vmath.d.ts +5 -26
  128. package/generated/versions/defold-1.13.0/window.d.ts +1 -16
  129. package/generated/versions/defold-1.13.1/b2d.d.ts +33 -0
  130. package/generated/versions/defold-1.13.1/b2d_body.d.ts +636 -0
  131. package/generated/versions/defold-1.13.1/b2d_chain.d.ts +106 -0
  132. package/generated/versions/defold-1.13.1/b2d_fixture.d.ts +157 -0
  133. package/generated/versions/defold-1.13.1/b2d_joint.d.ts +823 -0
  134. package/generated/versions/defold-1.13.1/b2d_shape.d.ts +400 -0
  135. package/generated/versions/defold-1.13.1/b2d_world.d.ts +320 -0
  136. package/generated/versions/defold-1.13.1/buffer.d.ts +189 -0
  137. package/generated/versions/defold-1.13.1/camera.d.ts +303 -0
  138. package/generated/versions/defold-1.13.1/collectionfactory.d.ts +151 -0
  139. package/generated/versions/defold-1.13.1/collectionproxy.d.ts +93 -0
  140. package/generated/versions/defold-1.13.1/compute.d.ts +237 -0
  141. package/generated/versions/defold-1.13.1/crash.d.ts +143 -0
  142. package/generated/versions/defold-1.13.1/editor-vm/http.d.ts +56 -0
  143. package/generated/versions/defold-1.13.1/editor-vm/image.d.ts +48 -0
  144. package/generated/versions/defold-1.13.1/editor-vm/json.d.ts +10 -0
  145. package/generated/versions/defold-1.13.1/editor-vm/localization.d.ts +42 -0
  146. package/generated/versions/defold-1.13.1/editor-vm/tilemap_tiles.d.ts +80 -0
  147. package/generated/versions/defold-1.13.1/editor-vm/zip.d.ts +10 -0
  148. package/generated/versions/defold-1.13.1/editor-vm/zlib.d.ts +24 -0
  149. package/generated/versions/defold-1.13.1/editor.d.ts +1121 -0
  150. package/generated/versions/defold-1.13.1/factory.d.ts +124 -0
  151. package/generated/versions/defold-1.13.1/font.d.ts +81 -0
  152. package/generated/versions/defold-1.13.1/go.d.ts +1107 -0
  153. package/generated/versions/defold-1.13.1/graphics.d.ts +411 -0
  154. package/generated/versions/defold-1.13.1/gui.d.ts +2353 -0
  155. package/generated/versions/defold-1.13.1/html5.d.ts +55 -0
  156. package/generated/versions/defold-1.13.1/http.d.ts +77 -0
  157. package/generated/versions/defold-1.13.1/image.d.ts +131 -0
  158. package/generated/versions/defold-1.13.1/index.d.ts +57 -0
  159. package/generated/versions/defold-1.13.1/json.d.ts +80 -0
  160. package/generated/versions/defold-1.13.1/kinds/editor-script.d.ts +14 -0
  161. package/generated/versions/defold-1.13.1/label.d.ts +93 -0
  162. package/generated/versions/defold-1.13.1/liveupdate.d.ts +142 -0
  163. package/generated/versions/defold-1.13.1/material.d.ts +408 -0
  164. package/generated/versions/defold-1.13.1/model.d.ts +272 -0
  165. package/generated/versions/defold-1.13.1/msg.d.ts +10 -0
  166. package/generated/versions/defold-1.13.1/particlefx.d.ts +163 -0
  167. package/generated/versions/defold-1.13.1/physics.d.ts +559 -0
  168. package/generated/versions/defold-1.13.1/profiler.d.ts +235 -0
  169. package/generated/versions/defold-1.13.1/render.d.ts +1190 -0
  170. package/generated/versions/defold-1.13.1/resource.d.ts +1523 -0
  171. package/generated/versions/defold-1.13.1/socket.d.ts +784 -0
  172. package/generated/versions/defold-1.13.1/sound.d.ts +292 -0
  173. package/generated/versions/defold-1.13.1/sprite.d.ts +175 -0
  174. package/generated/versions/defold-1.13.1/sys.d.ts +678 -0
  175. package/generated/versions/defold-1.13.1/tilemap.d.ts +208 -0
  176. package/generated/versions/defold-1.13.1/timer.d.ts +125 -0
  177. package/generated/versions/defold-1.13.1/types.d.ts +61 -0
  178. package/generated/versions/defold-1.13.1/vmath.d.ts +774 -0
  179. package/generated/versions/defold-1.13.1/window.d.ts +183 -0
  180. package/generated/versions/defold-1.13.1/zlib.d.ts +41 -0
  181. package/generated/vmath.d.ts +6 -26
  182. package/generated/window.d.ts +71 -71
  183. package/identity-vocabulary.json +561 -0
  184. package/index.d.ts +8 -0
  185. package/package.json +13 -2
  186. package/scripts/example-store-io.ts +12 -1
  187. package/scripts/extension-goldens.ts +1 -0
  188. package/scripts/fidelity-baseline.json +146 -46
  189. package/scripts/generate-api-availability.ts +90 -12
  190. package/scripts/generate-api-signatures.ts +14 -3
  191. package/scripts/import-defold-release.ts +85 -24
  192. package/scripts/prose-constants.ts +157 -0
  193. package/scripts/regen.ts +396 -78
  194. package/scripts/shared-handle-methods.ts +53 -0
  195. package/scripts/signature-store-fs.ts +1 -0
  196. package/scripts/sync-api-docs.ts +16 -5
  197. package/src/api-availability.ts +0 -0
  198. package/src/api-doc.ts +201 -3
  199. package/src/api-identity.ts +252 -0
  200. package/src/component-properties.d.ts +33 -0
  201. package/src/core-types.ts +28 -3
  202. package/src/correction-pins.ts +49 -0
  203. package/src/custom-messages.d.ts +4 -3
  204. package/src/doc-comment.ts +139 -23
  205. package/src/doc-corrections.ts +108 -0
  206. package/src/editor-vm-globals.d.ts +5 -2
  207. package/src/emit-dts.ts +2474 -281
  208. package/src/emit-messages.ts +52 -0
  209. package/src/engine-globals.d.ts +2 -2
  210. package/src/example-store.ts +125 -14
  211. package/src/field-correction-coverage.ts +204 -0
  212. package/src/fnv1a.ts +16 -0
  213. package/src/go-overloads.d.ts +33 -13
  214. package/src/index-base-table.ts +145 -0
  215. package/src/index-slot-classifications.ts +588 -0
  216. package/src/index.ts +39 -2
  217. package/src/library-index-slot-classifications.ts +332 -0
  218. package/src/lifecycle.ts +61 -199
  219. package/src/luals-type-expr.ts +354 -0
  220. package/src/msg-overloads.d.ts +0 -1
  221. package/src/param-correction-provenance.ts +64 -0
  222. package/src/return-correction-provenance.ts +58 -16
  223. package/src/script-api.ts +3 -1
  224. package/src/sys-overloads.d.ts +48 -0
  225. package/src/vmath-overloads.d.ts +27 -1
  226. package/src/window-event-guard.d.ts +6 -9
  227. package/url-parameters.json +1 -2
@@ -10,7 +10,6 @@ declare global {
10
10
  * Constructor-like function with two purposes:
11
11
  *
12
12
  * - Load the specified resource as part of loading the script
13
- *
14
13
  * - Return a hash to the run-time version of the resource
15
14
  *
16
15
  * This function can only be called within go.property function calls.
@@ -21,9 +20,11 @@ declare global {
21
20
  * Load an atlas and set it to a sprite:
22
21
  * ```ts
23
22
  * // Load an atlas and set it to a sprite:
24
- * go.property("my_atlas", resource.atlas("/atlas.atlas"));
25
- *
26
23
  * export default defineScript({
24
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
25
+ * // registration from this field, and only this field types the property onto `self`.
26
+ * properties: { my_atlas: resource.atlas("/atlas.atlas") },
27
+ *
27
28
  * init(self) {
28
29
  * go.set("#sprite", "image", self.my_atlas);
29
30
  * },
@@ -33,9 +34,11 @@ declare global {
33
34
  * Load an atlas and set it to a gui:
34
35
  * ```ts
35
36
  * // Load an atlas and set it to a gui:
36
- * go.property("my_atlas", resource.atlas("/atlas.atlas"));
37
- *
38
37
  * export default defineScript({
38
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
39
+ * // registration from this field, and only this field types the property onto `self`.
40
+ * properties: { my_atlas: resource.atlas("/atlas.atlas") },
41
+ *
39
42
  * init(self) {
40
43
  * go.set("#gui", "textures", self.my_atlas, { key: "my_atlas" });
41
44
  * },
@@ -47,7 +50,6 @@ declare global {
47
50
  * Constructor-like function with two purposes:
48
51
  *
49
52
  * - Load the specified resource as part of loading the script
50
- *
51
53
  * - Return a hash to the run-time version of the resource
52
54
  *
53
55
  * This function can only be called within go.property function calls.
@@ -57,9 +59,11 @@ declare global {
57
59
  * @example
58
60
  * ```ts
59
61
  * // Set a unique buffer it to a sprite:
60
- * go.property("my_buffer", resource.buffer("/cube.buffer"));
61
- *
62
62
  * export default defineScript({
63
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
64
+ * // registration from this field, and only this field types the property onto `self`.
65
+ * properties: { my_buffer: resource.buffer("/cube.buffer") },
66
+ *
63
67
  * init(self) {
64
68
  * go.set("#mesh", "vertices", self.my_buffer);
65
69
  * },
@@ -144,18 +148,23 @@ declare global {
144
148
  *
145
149
  * - `indices`
146
150
  * table a list of the indices of the geometry in the form {i0, i1, i2, ..., in}. Each tripe in the list represents a triangle.
151
+ *
152
+ * **⚠️ `frame_start` is 1-based; passed to Defold unchanged.** **⚠️ `frame_end` is 1-based; passed to Defold unchanged.** **⚠️ `frame_start` is 1-based; passed to Defold unchanged.** **⚠️ `frame_end` is 1-based; passed to Defold unchanged.** **⚠️ `frames` is 1-based; passed to Defold unchanged.** **0️⃣ `indices` is 0-based; passed to Defold unchanged.**
147
153
  * @returns Returns the atlas resource path
148
154
  * @example
149
155
  * ```ts
150
156
  * // Create a backing texture and an atlas
151
157
  * export default defineScript({
152
158
  * init() {
159
+ * // the engine registers a texture format only when the driver supports it
160
+ * const format = graphics.TEXTURE_FORMAT_RGBA;
161
+ * if (format === undefined) return;
153
162
  * // create an empty texture
154
163
  * const tparams = {
155
164
  * width: 128,
156
165
  * height: 128,
157
166
  * type: graphics.TEXTURE_TYPE_2D,
158
- * format: graphics.TEXTURE_FORMAT_RGBA,
167
+ * format,
159
168
  * };
160
169
  * const my_texture_id = resource.create_texture("/my_texture.texturec", tparams);
161
170
  *
@@ -186,7 +195,7 @@ declare global {
186
195
  * indices: [0, 1, 2, 0, 2, 3],
187
196
  * },
188
197
  * ],
189
- * };
198
+ * } satisfies Parameters<typeof resource.create_atlas>[1];
190
199
  * const my_atlas_id = resource.create_atlas("/my_atlas.texturesetc", aparams);
191
200
  *
192
201
  * // assign the atlas to the 'sprite' component on the same go
@@ -195,7 +204,7 @@ declare global {
195
204
  * });
196
205
  * ```
197
206
  */
198
- function create_atlas(path: string, table: { texture?: string | Hash; animations?: { id?: string; width?: number; height?: number; frame_start?: number; frame_end?: number; playback?: Opaque<"constant">; fps?: number; flip_vertical?: boolean; flip_horizontal?: boolean }[]; geometries?: { id?: string; width?: number; height?: number; pivot_x?: number; pivot_y?: number; rotated?: boolean }[]; vertices?: number[]; uvs?: number[]; indices?: number[] }): Hash;
207
+ function create_atlas(path: string, table: { texture: string | Hash; animations: [{ id: string; width: number; height: number; playback?: go.Playback; fps?: number; flip_vertical?: boolean; flip_horizontal?: boolean } & ({ frames: [number, ...number[]] } | { frame_start: number; frame_end: number }), ...({ id: string; width: number; height: number; playback?: go.Playback; fps?: number; flip_vertical?: boolean; flip_horizontal?: boolean } & ({ frames: [number, ...number[]] } | { frame_start: number; frame_end: number }))[]]; geometries: [{ id?: string; width?: number; height?: number; pivot_x?: number; pivot_y?: number; rotated?: boolean; vertices: number[]; uvs: number[]; indices: number[] }, ...{ id?: string; width?: number; height?: number; pivot_x?: number; pivot_y?: number; rotated?: boolean; vertices: number[]; uvs: number[]; indices: number[] }[]]; vertices?: number[]; uvs?: number[]; indices?: number[] }): Hash;
199
208
  /**
200
209
  * This function creates a new buffer resource that can be used in the same way as any buffer created during build time.
201
210
  * The function requires a valid buffer created from either buffer.create or another pre-existing buffer resource.
@@ -244,9 +253,9 @@ declare global {
244
253
  * const stream = buffer.get_stream(buffer_handle, hash("position"));
245
254
  *
246
255
  * // transfer vertex data to buffer
247
- * for (let k = 0; k < positions.length; k++) {
248
- * stream[k] = positions[k];
249
- * }
256
+ * positions.forEach((value, k) => {
257
+ * stream[k] = value;
258
+ * });
250
259
  *
251
260
  * const my_buffer = resource.create_buffer("/my_buffer.bufferc", { buffer: buffer_handle });
252
261
  * go.set("/go#mesh", "vertices", my_buffer);
@@ -268,7 +277,7 @@ declare global {
268
277
  * });
269
278
  * ```
270
279
  */
271
- function create_buffer(path: string, table?: { buffer?: Opaque<"buffer">; transfer_ownership?: boolean }): Hash;
280
+ function create_buffer(path: string, table: { buffer: Opaque<"buffer">; transfer_ownership?: boolean }): Hash;
272
281
  /**
273
282
  * Creates a sound data resource
274
283
  * Supported formats are .oggc, .opusc and .wavc
@@ -288,6 +297,11 @@ declare global {
288
297
  * export default defineScript({
289
298
  * init() {
290
299
  * // create a new sound resource, given the initial chunk of the file
300
+ * const [data] = sys.load_resource("/sounds/music_header.oggc");
301
+ * if (data === undefined) {
302
+ * return;
303
+ * }
304
+ * const filesize = 1048576;
291
305
  * const relative_path = "/a/unique/resource/name.oggc";
292
306
  * const hash = resource.create_sound_data(relative_path, { data, filesize, partial: true });
293
307
  * go.set("#music", "sound", hash); // override the previous sound resource
@@ -296,7 +310,7 @@ declare global {
296
310
  * });
297
311
  * ```
298
312
  */
299
- function create_sound_data(path: string, options?: { data?: string; filesize?: number; partial?: boolean }): Hash;
313
+ function create_sound_data(path: string, options: { data: string | Opaque<"buffer">; filesize?: number; partial?: boolean }): Hash;
300
314
  /**
301
315
  * Creates a new texture resource that can be used in the same way as any texture created during build time.
302
316
  * The path used for creating the texture must be unique, trying to create a resource at a path that is already
@@ -312,13 +326,9 @@ declare global {
312
326
  * number The texture type. Supported values:
313
327
  *
314
328
  * - `graphics.TEXTURE_TYPE_2D`
315
- *
316
329
  * - `graphics.TEXTURE_TYPE_IMAGE_2D`
317
- *
318
330
  * - `graphics.TEXTURE_TYPE_3D`
319
- *
320
331
  * - `graphics.TEXTURE_TYPE_IMAGE_3D`
321
- *
322
332
  * - `graphics.TEXTURE_TYPE_CUBE_MAP`
323
333
  *
324
334
  * `width`
@@ -331,68 +341,46 @@ declare global {
331
341
  * number The texture format, note that some of these formats might not be supported by the running device. Supported values:
332
342
  *
333
343
  * - `graphics.TEXTURE_FORMAT_LUMINANCE`
334
- *
335
344
  * - `graphics.TEXTURE_FORMAT_RGB`
336
- *
337
345
  * - `graphics.TEXTURE_FORMAT_RGBA`
338
346
  *
339
347
  * These constants might not be available on the device:
340
348
  *
341
349
  * - `graphics.TEXTURE_FORMAT_RGB_PVRTC_2BPPV1`
342
- *
343
350
  * - `graphics.TEXTURE_FORMAT_RGB_PVRTC_4BPPV1`
344
- *
345
351
  * - `graphics.TEXTURE_FORMAT_RGBA_PVRTC_2BPPV1`
346
- *
347
352
  * - `graphics.TEXTURE_FORMAT_RGBA_PVRTC_4BPPV1`
348
- *
349
353
  * - `graphics.TEXTURE_FORMAT_RGB_ETC1`
350
- *
351
354
  * - `graphics.TEXTURE_FORMAT_RGBA_ETC2`
352
- *
353
355
  * - `graphics.TEXTURE_FORMAT_RGBA_ASTC_4X4`
354
- *
355
356
  * - `graphics.TEXTURE_FORMAT_RGB_BC1`
356
- *
357
357
  * - `graphics.TEXTURE_FORMAT_RGBA_BC3`
358
- *
359
358
  * - `graphics.TEXTURE_FORMAT_R_BC4`
360
- *
361
359
  * - `graphics.TEXTURE_FORMAT_RG_BC5`
362
- *
363
360
  * - `graphics.TEXTURE_FORMAT_RGBA_BC7`
364
- *
365
361
  * - `graphics.TEXTURE_FORMAT_RGB16F`
366
- *
367
362
  * - `graphics.TEXTURE_FORMAT_RGB32F`
368
- *
369
363
  * - `graphics.TEXTURE_FORMAT_RGBA16F`
370
- *
371
364
  * - `graphics.TEXTURE_FORMAT_RGBA32F`
372
- *
373
365
  * - `graphics.TEXTURE_FORMAT_R16F`
374
- *
375
366
  * - `graphics.TEXTURE_FORMAT_RG16F`
376
- *
377
367
  * - `graphics.TEXTURE_FORMAT_R32F`
378
- *
379
368
  * - `graphics.TEXTURE_FORMAT_RG32F`
380
369
  *
381
370
  * You can test if the device supports these values by checking if a specific enum is nil or not:
382
371
  *
383
- * `if graphics.TEXTURE_FORMAT_RGBA16F ~= nil then
384
- * -- it is safe to use this format
385
- * end
386
- * `
372
+ * ```ts
373
+ * if (graphics.TEXTURE_FORMAT_RGBA16F !== undefined) {
374
+ * // it is safe to use this format
375
+ * }
376
+ * ```
387
377
  *
388
378
  * `flags`
389
379
  * number Texture creation flags that can be used to dictate how the texture is created. The default value is graphics.TEXTURE_USAGE_FLAG_SAMPLE, which means that the texture can be sampled from a shader.
390
380
  * These flags may or may not be supported on the running device and/or the underlying graphics API and is simply used internally as a 'hint' when creating the texture. There is no guarantee that any of these will have any effect. Supported values:
391
381
  *
392
382
  * - `graphics.TEXTURE_USAGE_FLAG_SAMPLE` - The texture can be sampled from a shader (default)
393
- *
394
383
  * - `graphics.TEXTURE_USAGE_FLAG_MEMORYLESS` - The texture can be used as a memoryless texture, i.e only transient memory for the texture is used during rendering
395
- *
396
384
  * - `graphics.TEXTURE_USAGE_FLAG_STORAGE` - The texture can be used as a storage texture, which is required for a shader to write to the texture
397
385
  *
398
386
  * `max_mipmaps`
@@ -402,15 +390,14 @@ declare global {
402
390
  * Creating an empty texture with no buffer data is not supported as a core feature. Defaults to graphics.COMPRESSION_TYPE_DEFAULT, i.e no compression. Supported values:
403
391
  *
404
392
  * - `COMPRESSION_TYPE_DEFAULT`
405
- *
406
393
  * - `COMPRESSION_TYPE_BASIS_UASTC`
407
394
  * @param buffer - optional buffer of precreated pixel data
408
395
  * @returns The path to the resource.
409
396
  * 3D Textures are currently only supported on OpenGL and Vulkan adapters. To check if your device supports 3D textures, use:
410
- * ```lua
411
- * if graphics.TEXTURE_TYPE_3D ~= nil then
412
- * -- Device and graphics adapter support 3D textures
413
- * end
397
+ * ```ts
398
+ * if (graphics.TEXTURE_TYPE_3D !== undefined) {
399
+ * // Device and graphics adapter support 3D textures
400
+ * }
414
401
  * ```
415
402
  * @example
416
403
  * How to create an 128x128 RGBA texture resource and assign it to a model
@@ -418,11 +405,14 @@ declare global {
418
405
  * // How to create an 128x128 RGBA texture resource and assign it to a model
419
406
  * export default defineScript({
420
407
  * init() {
408
+ * // the engine registers a texture format only when the driver supports it
409
+ * const format = graphics.TEXTURE_FORMAT_RGBA;
410
+ * if (format === undefined) return;
421
411
  * const tparams = {
422
412
  * width: 128,
423
413
  * height: 128,
424
414
  * type: graphics.TEXTURE_TYPE_2D,
425
- * format: graphics.TEXTURE_FORMAT_RGBA,
415
+ * format,
426
416
  * };
427
417
  * const my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams);
428
418
  * go.set("#model", "texture0", my_texture_id);
@@ -435,6 +425,9 @@ declare global {
435
425
  * // How to create an 128x128 floating point texture (RGBA32F) resource from a buffer object
436
426
  * export default defineScript({
437
427
  * init() {
428
+ * // the engine registers a texture format only when the driver supports it
429
+ * const format = graphics.TEXTURE_FORMAT_RGBA32F;
430
+ * if (format === undefined) return;
438
431
  * // Create a new buffer with 4 components and FLOAT32 type
439
432
  * const tbuffer = buffer.create(128 * 128, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);
440
433
  * const tstream = buffer.get_stream(tbuffer, hash("rgba"));
@@ -455,7 +448,7 @@ declare global {
455
448
  * width: 128,
456
449
  * height: 128,
457
450
  * type: graphics.TEXTURE_TYPE_2D,
458
- * format: graphics.TEXTURE_FORMAT_RGBA32F,
451
+ * format,
459
452
  * };
460
453
  *
461
454
  * // Note that we pass the buffer as the last argument here!
@@ -477,8 +470,8 @@ declare global {
477
470
  * width: 32,
478
471
  * height: 32,
479
472
  * depth: 32,
480
- * format: resource.TEXTURE_FORMAT_RGBA32F,
481
- * flags: resource.TEXTURE_USAGE_FLAG_STORAGE + resource.TEXTURE_USAGE_FLAG_SAMPLE,
473
+ * format: graphics.TEXTURE_FORMAT_RGBA32F,
474
+ * flags: graphics.TEXTURE_USAGE_FLAG_STORAGE + graphics.TEXTURE_USAGE_FLAG_SAMPLE,
482
475
  * });
483
476
  *
484
477
  * // pass the backing texture to the render script
@@ -490,16 +483,20 @@ declare global {
490
483
  * How to create 512x512 texture array with 5 pages.
491
484
  * ```ts
492
485
  * // How to create 512x512 texture array with 5 pages.
493
- * const new_tex = resource.create_texture("/runtime/example_array.texturec", {
494
- * type: graphics.TEXTURE_TYPE_2D_ARRAY,
495
- * width: 512,
496
- * height: 512,
497
- * page_count: 5,
498
- * format: graphics.TEXTURE_FORMAT_RGB,
499
- * });
486
+ * // the engine registers a texture format only when the driver supports it
487
+ * const format = graphics.TEXTURE_FORMAT_RGB;
488
+ * if (format !== undefined) {
489
+ * const new_tex = resource.create_texture("/runtime/example_array.texturec", {
490
+ * type: graphics.TEXTURE_TYPE_2D_ARRAY,
491
+ * width: 512,
492
+ * height: 512,
493
+ * page_count: 5,
494
+ * format,
495
+ * });
496
+ * }
500
497
  * ```
501
498
  */
502
- function create_texture(path: string, table: { type?: number; width?: number; height?: number; depth?: number; format?: number; flags?: number; max_mipmaps?: number; compression_type?: number; page_count?: number }, buffer?: Opaque<"buffer">): Hash;
499
+ function create_texture(path: string, table: { type: number; width: number; height: number; depth?: number; format: number; flags?: number; max_mipmaps?: number; compression_type?: number; page_count?: number }, buffer?: Opaque<"buffer">): Hash;
503
500
  /**
504
501
  * Creates a new texture resource that can be used in the same way as any texture created during build time.
505
502
  * The path used for creating the texture must be unique, trying to create a resource at a path that is already
@@ -518,13 +515,9 @@ declare global {
518
515
  * number The texture type. Supported values:
519
516
  *
520
517
  * - `graphics.TEXTURE_TYPE_2D`
521
- *
522
518
  * - `graphics.TEXTURE_TYPE_IMAGE_2D`
523
- *
524
519
  * - `graphics.TEXTURE_TYPE_3D`
525
- *
526
520
  * - `graphics.TEXTURE_TYPE_IMAGE_3D`
527
- *
528
521
  * - `graphics.TEXTURE_TYPE_CUBE_MAP`
529
522
  *
530
523
  * `width`
@@ -537,67 +530,45 @@ declare global {
537
530
  * number The texture format, note that some of these formats might not be supported by the running device. Supported values:
538
531
  *
539
532
  * - `graphics.TEXTURE_FORMAT_LUMINANCE`
540
- *
541
533
  * - `graphics.TEXTURE_FORMAT_RGB`
542
- *
543
534
  * - `graphics.TEXTURE_FORMAT_RGBA`
544
535
  *
545
536
  * These constants might not be available on the device:
546
537
  *
547
538
  * - `graphics.TEXTURE_FORMAT_RGB_PVRTC_2BPPV1`
548
- *
549
539
  * - `graphics.TEXTURE_FORMAT_RGB_PVRTC_4BPPV1`
550
- *
551
540
  * - `graphics.TEXTURE_FORMAT_RGBA_PVRTC_2BPPV1`
552
- *
553
541
  * - `graphics.TEXTURE_FORMAT_RGBA_PVRTC_4BPPV1`
554
- *
555
542
  * - `graphics.TEXTURE_FORMAT_RGB_ETC1`
556
- *
557
543
  * - `graphics.TEXTURE_FORMAT_RGBA_ETC2`
558
- *
559
544
  * - `graphics.TEXTURE_FORMAT_RGBA_ASTC_4X4`
560
- *
561
545
  * - `graphics.TEXTURE_FORMAT_RGB_BC1`
562
- *
563
546
  * - `graphics.TEXTURE_FORMAT_RGBA_BC3`
564
- *
565
547
  * - `graphics.TEXTURE_FORMAT_R_BC4`
566
- *
567
548
  * - `graphics.TEXTURE_FORMAT_RG_BC5`
568
- *
569
549
  * - `graphics.TEXTURE_FORMAT_RGBA_BC7`
570
- *
571
550
  * - `graphics.TEXTURE_FORMAT_RGB16F`
572
- *
573
551
  * - `graphics.TEXTURE_FORMAT_RGB32F`
574
- *
575
552
  * - `graphics.TEXTURE_FORMAT_RGBA16F`
576
- *
577
553
  * - `graphics.TEXTURE_FORMAT_RGBA32F`
578
- *
579
554
  * - `graphics.TEXTURE_FORMAT_R16F`
580
- *
581
555
  * - `graphics.TEXTURE_FORMAT_RG16F`
582
- *
583
556
  * - `graphics.TEXTURE_FORMAT_R32F`
584
- *
585
557
  * - `graphics.TEXTURE_FORMAT_RG32F`
586
558
  *
587
559
  * You can test if the device supports these values by checking if a specific enum is nil or not:
588
560
  *
589
- * `if graphics.TEXTURE_FORMAT_RGBA16F ~= nil then
590
- * -- it is safe to use this format
591
- * end
592
- * `
561
+ * ```ts
562
+ * if (graphics.TEXTURE_FORMAT_RGBA16F !== undefined) {
563
+ * // it is safe to use this format
564
+ * }
565
+ * ```
593
566
  *
594
567
  * `flags`
595
568
  * number Texture creation flags that can be used to dictate how the texture is created. Supported values:
596
569
  *
597
570
  * - `graphics.TEXTURE_USAGE_FLAG_SAMPLE` - The texture can be sampled from a shader (default)
598
- *
599
571
  * - `graphics.TEXTURE_USAGE_FLAG_MEMORYLESS` - The texture can be used as a memoryless texture, i.e only transient memory for the texture is used during rendering
600
- *
601
572
  * - `graphics.TEXTURE_USAGE_FLAG_STORAGE` - The texture can be used as a storage texture, which is required for a shader to write to the texture
602
573
  *
603
574
  * `max_mipmaps`
@@ -607,7 +578,6 @@ declare global {
607
578
  * Creating an empty texture with no buffer data is not supported as a core feature. Defaults to graphics.COMPRESSION_TYPE_DEFAULT, i.e no compression. Supported values:
608
579
  *
609
580
  * - `COMPRESSION_TYPE_DEFAULT`
610
- *
611
581
  * - `COMPRESSION_TYPE_BASIS_UASTC`
612
582
  * @param buffer - optional buffer of precreated pixel data
613
583
  * @param callback - callback function when texture is created (self, request_id, resource)
@@ -656,17 +626,20 @@ declare global {
656
626
  * });
657
627
  * ```
658
628
  * @example
659
- * Create a texture resource asyncronously without a callback
629
+ * Create a texture resource asynchronously with a callback that does nothing
660
630
  * ```ts
661
- * // Create a texture resource asyncronously without a callback
631
+ * // Create a texture resource asyncronously without handling its completion
662
632
  * export default defineScript({
663
633
  * init() {
634
+ * // the engine registers a texture format only when the driver supports it
635
+ * const format = graphics.TEXTURE_FORMAT_RGBA;
636
+ * if (format === undefined) return;
664
637
  * // Create a texture resource async
665
638
  * const tparams = {
666
639
  * width: 128,
667
640
  * height: 128,
668
641
  * type: graphics.TEXTURE_TYPE_2D,
669
- * format: graphics.TEXTURE_FORMAT_RGBA,
642
+ * format,
670
643
  * };
671
644
  *
672
645
  * // Create a new buffer with 4 components
@@ -684,7 +657,8 @@ declare global {
684
657
  * }
685
658
  * }
686
659
  * // create the texture
687
- * const [tpath, request_id] = resource.create_texture_async("/my_texture.texturec", tparams, tbuffer);
660
+ * // the binding requires a callback function, so pass one that does nothing
661
+ * const [tpath, request_id] = resource.create_texture_async("/my_texture.texturec", tparams, tbuffer, () => {});
688
662
  * // at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture
689
663
  * // that will be removed once the new texture has been updated
690
664
  * go.set("#model", "texture0", tpath);
@@ -692,12 +666,11 @@ declare global {
692
666
  * });
693
667
  * ```
694
668
  */
695
- function create_texture_async(path: string | Hash, table: { type?: number; width?: number; height?: number; depth?: number; format?: number; flags?: number; max_mipmaps?: number; compression_type?: number }, buffer?: Opaque<"buffer">, callback?: (...args: unknown[]) => unknown): LuaMultiReturn<[Hash, number]>;
669
+ function create_texture_async(path: string, table: { type: number; width: number; height: number; depth?: number; format: number; flags?: number; max_mipmaps?: number; compression_type?: number }, buffer: Opaque<"buffer"> | undefined, callback: (...args: unknown[]) => unknown): LuaMultiReturn<[Hash, number]>;
696
670
  /**
697
671
  * Constructor-like function with two purposes:
698
672
  *
699
673
  * - Load the specified resource as part of loading the script
700
- *
701
674
  * - Return a hash to the run-time version of the resource
702
675
  *
703
676
  * This function can only be called within go.property function calls.
@@ -708,9 +681,11 @@ declare global {
708
681
  * Load a font and set it to a label:
709
682
  * ```ts
710
683
  * // Load a font and set it to a label:
711
- * go.property("my_font", resource.font("/font.font"));
712
- *
713
684
  * export default defineScript({
685
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
686
+ * // registration from this field, and only this field types the property onto `self`.
687
+ * properties: { my_font: resource.font("/font.font") },
688
+ *
714
689
  * init(self) {
715
690
  * go.set("#label", "font", self.my_font);
716
691
  * },
@@ -720,9 +695,11 @@ declare global {
720
695
  * Load a font and set it to a gui:
721
696
  * ```ts
722
697
  * // Load a font and set it to a gui:
723
- * go.property("my_font", resource.font("/font.font"));
724
- *
725
698
  * export default defineScript({
699
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
700
+ * // registration from this field, and only this field types the property onto `self`.
701
+ * properties: { my_font: resource.font("/font.font") },
702
+ *
726
703
  * init(self) {
727
704
  * go.set("#gui", "fonts", self.my_font, { key: "my_font" });
728
705
  * },
@@ -737,16 +714,16 @@ declare global {
737
714
  * @returns A table with the following entries:
738
715
  *
739
716
  * - texture
740
- *
741
717
  * - geometries
742
- *
743
718
  * - animations
744
719
  *
745
720
  * Each animation entry also contains a `frames` table with indices into
746
721
  * `geometries`, preserving the frame-to-geometry mapping used by the atlas.
747
722
  * See resource.set_atlas for a detailed description of each field
723
+ *
724
+ * **⚠️ `frames` is 1-based; passed to Defold unchanged.** **0️⃣ `indices` is 0-based; passed to Defold unchanged.**
748
725
  */
749
- function get_atlas(path: Hash | string): { texture: string | Hash; animations: { id: string; width: number; height: number; frame_start: number; frame_end: number; playback: Opaque<"constant">; fps: number; flip_vertical: boolean; flip_horizontal: boolean }[]; geometries: { vertices: number[]; uvs: number[]; indices: number[] }[] };
726
+ function get_atlas(path: Hash | string): { texture: string | Hash; animations: { id: string; width: number; height: number; frame_start: number; frame_end: number; playback: go.Playback; fps: number; flip_vertical: boolean; flip_horizontal: boolean }[]; geometries: { vertices: number[]; uvs: number[]; indices: number[] }[] };
750
727
  /**
751
728
  * gets the buffer from a resource
752
729
  *
@@ -757,11 +734,11 @@ declare global {
757
734
  * // How to get the data from a buffer
758
735
  * export default defineScript({
759
736
  * init() {
760
- * const res_path = go.get("#mesh", "vertices");
737
+ * const res_path = go.get<mesh.properties>()("#mesh", "vertices");
761
738
  * const buf = resource.get_buffer(res_path);
762
739
  * const stream_positions = buffer.get_stream(buf, "position");
763
740
  *
764
- * for (let i = 0; i < stream_positions.length; i++) {
741
+ * for (let i = 0; i < stream_positions.length(); i++) {
765
742
  * print(i, stream_positions[i]);
766
743
  * }
767
744
  * },
@@ -791,26 +768,18 @@ declare global {
791
768
  * number The texture type. Supported values:
792
769
  *
793
770
  * - `graphics.TEXTURE_TYPE_2D`
794
- *
795
771
  * - `graphics.TEXTURE_TYPE_CUBE_MAP`
796
- *
797
772
  * - `graphics.TEXTURE_TYPE_2D_ARRAY`
798
773
  *
799
774
  * `buffer_type`
800
775
  * number The attachment buffer type. Supported values:
801
776
  *
802
777
  * - `resource.BUFFER_TYPE_COLOR0`
803
- *
804
778
  * - `resource.BUFFER_TYPE_COLOR1`
805
- *
806
779
  * - `resource.BUFFER_TYPE_COLOR2`
807
- *
808
780
  * - `resource.BUFFER_TYPE_COLOR3`
809
- *
810
781
  * - `resource.BUFFER_TYPE_DEPTH`
811
- *
812
782
  * - `resource.BUFFER_TYPE_STENCIL`
813
- *
814
783
  * - `texture`
815
784
  * hash The hashed path to the attachment texture resource. This field is only available if the render target passed in is a resource.
816
785
  * @example
@@ -861,24 +830,21 @@ declare global {
861
830
  * @returns a table with the following fields:
862
831
  *
863
832
  * - width
864
- *
865
833
  * - height
866
- *
867
834
  * - max_ascent
868
- *
869
835
  * - max_descent
870
836
  * @example
871
837
  * ```ts
872
838
  * export default defineScript({
873
839
  * init() {
874
- * const font = go.get("#label", "font");
840
+ * const font = go.get<label.properties>()("#label", "font");
875
841
  * const metrics = resource.get_text_metrics(font, "The quick brown fox\n jumps over the lazy dog");
876
842
  * pprint(metrics);
877
843
  * },
878
844
  * });
879
845
  * ```
880
846
  */
881
- function get_text_metrics(url: Hash, text: string, options?: { width?: number; leading?: number; tracking?: number; line_break?: boolean }): { width: number; height: number; max_ascent: number; max_descent: number };
847
+ function get_text_metrics(url: Hash | string, text: string, options?: { width?: number; leading?: number; tracking?: number; line_break?: boolean }): { width: number; height: number; max_ascent: number; max_descent: number };
882
848
  /**
883
849
  * Gets texture info from a texture resource path or a texture handle
884
850
  *
@@ -903,15 +869,10 @@ declare global {
903
869
  * number The texture type. Supported values:
904
870
  *
905
871
  * - `graphics.TEXTURE_TYPE_2D`
906
- *
907
872
  * - `graphics.TEXTURE_TYPE_2D_ARRAY`
908
- *
909
873
  * - `graphics.TEXTURE_TYPE_IMAGE_2D`
910
- *
911
874
  * - `graphics.TEXTURE_TYPE_3D`
912
- *
913
875
  * - `graphics.TEXTURE_TYPE_IMAGE_3D`
914
- *
915
876
  * - `graphics.TEXTURE_TYPE_CUBE_MAP`
916
877
  * @example
917
878
  * Create a new texture and get the metadata from it
@@ -919,12 +880,15 @@ declare global {
919
880
  * // Create a new texture and get the metadata from it
920
881
  * export default defineScript({
921
882
  * init() {
883
+ * // the engine registers a texture format only when the driver supports it
884
+ * const format = graphics.TEXTURE_FORMAT_RGBA;
885
+ * if (format === undefined) return;
922
886
  * // create an empty texture
923
887
  * const tparams = {
924
888
  * width: 128,
925
889
  * height: 128,
926
890
  * type: graphics.TEXTURE_TYPE_2D,
927
- * format: graphics.TEXTURE_FORMAT_RGBA,
891
+ * format,
928
892
  * };
929
893
  *
930
894
  * const my_texture_path = resource.create_texture("/my_texture.texturec", tparams);
@@ -968,9 +932,11 @@ declare global {
968
932
  * ```ts
969
933
  * // read custom resource data into buffer
970
934
  * const buffer = resource.load("/resources/datafile");
971
- *
972
- * // In order for the engine to include custom resources in the build process, you
973
- * // need to specify them in the "game.project" settings file:
935
+ * ```
936
+ * @example
937
+ * In order for the engine to include custom resources in the build process, you need
938
+ * to specify them in the "game.project" settings file:
939
+ * ```ts
974
940
  * // [project]
975
941
  * // title = My project
976
942
  * // version = 0.1
@@ -982,7 +948,6 @@ declare global {
982
948
  * Constructor-like function with two purposes:
983
949
  *
984
950
  * - Load the specified resource as part of loading the script
985
- *
986
951
  * - Return a hash to the run-time version of the resource
987
952
  *
988
953
  * This function can only be called within go.property function calls.
@@ -993,9 +958,11 @@ declare global {
993
958
  * Load a material and set it to a sprite:
994
959
  * ```ts
995
960
  * // Load a material and set it to a sprite:
996
- * go.property("my_material", resource.material("/material.material"));
997
- *
998
961
  * export default defineScript({
962
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
963
+ * // registration from this field, and only this field types the property onto `self`.
964
+ * properties: { my_material: resource.material("/material.material") },
965
+ *
999
966
  * init(self) {
1000
967
  * go.set("#sprite", "material", self.my_material);
1001
968
  * },
@@ -1005,9 +972,11 @@ declare global {
1005
972
  * Load a material resource and update a named material with the resource:
1006
973
  * ```ts
1007
974
  * // Load a material resource and update a named material with the resource:
1008
- * go.property("my_material", resource.material("/material.material"));
1009
- *
1010
975
  * export default defineScript({
976
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
977
+ * // registration from this field, and only this field types the property onto `self`.
978
+ * properties: { my_material: resource.material("/material.material") },
979
+ *
1011
980
  * init(self) {
1012
981
  * go.set("#gui", "materials", self.my_material, { key: "my_material" });
1013
982
  * },
@@ -1026,7 +995,6 @@ declare global {
1026
995
  * Constructor-like function with two purposes:
1027
996
  *
1028
997
  * - Load the specified resource as part of loading the script
1029
- *
1030
998
  * - Return a hash to the run-time version of the resource
1031
999
  *
1032
1000
  * This function can only be called within go.property function calls.
@@ -1036,9 +1004,11 @@ declare global {
1036
1004
  * @example
1037
1005
  * ```ts
1038
1006
  * // Set a render target color attachment as a model texture:
1039
- * go.property("my_render_target", resource.render_target("/rt.render_target"));
1040
- *
1041
1007
  * export default defineScript({
1008
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
1009
+ * // registration from this field, and only this field types the property onto `self`.
1010
+ * properties: { my_render_target: resource.render_target("/rt.render_target") },
1011
+ *
1042
1012
  * init(self) {
1043
1013
  * const rt_info = resource.get_render_target_info(self.my_render_target);
1044
1014
  * go.set("#model", "texture0", rt_info.attachments[0]!.texture!);
@@ -1057,7 +1027,7 @@ declare global {
1057
1027
  * // Assuming the folder "/res" is added to the project custom resources:
1058
1028
  * // load a texture resource and set it on a sprite
1059
1029
  * const buffer = resource.load("/res/new.texturec");
1060
- * resource.set(go.get("#sprite", "texture0"), buffer);
1030
+ * resource.set(go.get<sprite.properties>()("#sprite", "texture0"), buffer);
1061
1031
  * ```
1062
1032
  */
1063
1033
  function set(path: string | Hash, buffer: Opaque<"buffer">): void;
@@ -1121,6 +1091,8 @@ declare global {
1121
1091
  *
1122
1092
  * - `indices`
1123
1093
  * table a list of the indices of the geometry in the form {i0, i1, i2, ..., in}. Each tripe in the list represents a triangle.
1094
+ *
1095
+ * **⚠️ `frame_start` is 1-based; passed to Defold unchanged.** **⚠️ `frame_end` is 1-based; passed to Defold unchanged.** **⚠️ `frame_start` is 1-based; passed to Defold unchanged.** **⚠️ `frame_end` is 1-based; passed to Defold unchanged.** **⚠️ `frames` is 1-based; passed to Defold unchanged.** **0️⃣ `indices` is 0-based; passed to Defold unchanged.**
1124
1096
  * @example
1125
1097
  * Add a new animation to an existing atlas
1126
1098
  * ```ts
@@ -1136,9 +1108,25 @@ declare global {
1136
1108
  * frame_end: 6,
1137
1109
  * playback: go.PLAYBACK_LOOP_PINGPONG,
1138
1110
  * fps: 8,
1111
+ * flip_vertical: false,
1112
+ * flip_horizontal: false,
1139
1113
  * };
1140
- * data.animations.push(my_animation);
1141
- * resource.set_atlas("/main/my_atlas.a.texturesetc", data);
1114
+ * // set_atlas takes each animation's frames as a non-empty list
1115
+ * const animations = data.animations.flatMap((animation) => {
1116
+ * // an animation described by frame_start/frame_end passes through as-is
1117
+ * if (!("frames" in animation)) return [animation];
1118
+ * const [first, ...rest] = (animation.frames as number[] | undefined) ?? [];
1119
+ * return first === undefined ? [] : [{ ...animation, frames: [first, ...rest] as [number, ...number[]] }];
1120
+ * });
1121
+ * // set_atlas needs at least one animation and one geometry
1122
+ * const [first_geometry, ...geometries] = data.geometries;
1123
+ * if (first_geometry !== undefined) {
1124
+ * resource.set_atlas("/main/my_atlas.a.texturesetc", {
1125
+ * ...data,
1126
+ * animations: [my_animation, ...animations],
1127
+ * geometries: [first_geometry, ...geometries],
1128
+ * });
1129
+ * }
1142
1130
  * },
1143
1131
  * });
1144
1132
  * ```
@@ -1165,13 +1153,13 @@ declare global {
1165
1153
  * indices: [0, 1, 2, 0, 2, 3],
1166
1154
  * },
1167
1155
  * ],
1168
- * };
1156
+ * } satisfies Parameters<typeof resource.set_atlas>[1];
1169
1157
  * resource.set_atlas("/main/test.a.texturesetc", params);
1170
1158
  * },
1171
1159
  * });
1172
1160
  * ```
1173
1161
  */
1174
- function set_atlas(path: Hash | string, table: { texture?: string | Hash; animations?: { id?: string; width?: number; height?: number; frame_start?: number; frame_end?: number; playback?: Opaque<"constant">; fps?: number; flip_vertical?: boolean; flip_horizontal?: boolean }[]; geometries?: { vertices?: number[]; uvs?: number[]; indices?: number[] }[]; vertices?: number[]; uvs?: number[]; indices?: number[] }): void;
1162
+ function set_atlas(path: Hash | string, table: { texture: string | Hash; animations: [{ id: string; width: number; height: number; playback?: go.Playback; fps?: number; flip_vertical?: boolean; flip_horizontal?: boolean } & ({ frames: [number, ...number[]] } | { frame_start: number; frame_end: number }), ...({ id: string; width: number; height: number; playback?: go.Playback; fps?: number; flip_vertical?: boolean; flip_horizontal?: boolean } & ({ frames: [number, ...number[]] } | { frame_start: number; frame_end: number }))[]]; geometries: [{ vertices: number[]; uvs: number[]; indices: number[] }, ...{ vertices: number[]; uvs: number[]; indices: number[] }[]]; vertices?: number[]; uvs?: number[]; indices?: number[] }): void;
1175
1163
  /**
1176
1164
  * Sets the buffer of a resource. By default, setting the resource buffer will either copy the data from the incoming buffer object
1177
1165
  * to the buffer stored in the destination resource, or make a new buffer object if the sizes between the source buffer and the destination buffer
@@ -1198,7 +1186,7 @@ declare global {
1198
1186
  *
1199
1187
  * export default defineScript({
1200
1188
  * init() {
1201
- * const res_path = go.get("#mesh", "vertices");
1189
+ * const res_path = go.get<mesh.properties>()("#mesh", "vertices");
1202
1190
  *
1203
1191
  * const positions = [
1204
1192
  * 1, -1, 0,
@@ -1239,13 +1227,9 @@ declare global {
1239
1227
  * number The texture type. Supported values:
1240
1228
  *
1241
1229
  * - `graphics.TEXTURE_TYPE_2D`
1242
- *
1243
1230
  * - `graphics.TEXTURE_TYPE_IMAGE_2D`
1244
- *
1245
1231
  * - `graphics.TEXTURE_TYPE_3D`
1246
- *
1247
1232
  * - `graphics.TEXTURE_TYPE_IMAGE_3D`
1248
- *
1249
1233
  * - `graphics.TEXTURE_TYPE_CUBE_MAP`
1250
1234
  *
1251
1235
  * `width`
@@ -1256,9 +1240,7 @@ declare global {
1256
1240
  * number The texture format, note that some of these formats are platform specific. Supported values:
1257
1241
  *
1258
1242
  * - `graphics.TEXTURE_FORMAT_LUMINANCE`
1259
- *
1260
1243
  * - `graphics.TEXTURE_FORMAT_RGB`
1261
- *
1262
1244
  * - `graphics.TEXTURE_FORMAT_RGBA`
1263
1245
  *
1264
1246
  * These constants might not be available on the device:
@@ -1284,10 +1266,11 @@ declare global {
1284
1266
  * - `graphics.TEXTURE_FORMAT_RG32F`
1285
1267
  * You can test if the device supports these values by checking if a specific enum is nil or not:
1286
1268
  *
1287
- * `if graphics.TEXTURE_FORMAT_RGBA16F ~= nil then
1288
- * -- it is safe to use this format
1289
- * end
1290
- * `
1269
+ * ```ts
1270
+ * if (graphics.TEXTURE_FORMAT_RGBA16F !== undefined) {
1271
+ * // it is safe to use this format
1272
+ * }
1273
+ * ```
1291
1274
  *
1292
1275
  * `x`
1293
1276
  * number optional x offset of the texture (in pixels)
@@ -1303,39 +1286,45 @@ declare global {
1303
1286
  * number optional specify the compression type for the data in the buffer object that holds the texture data. Defaults to graphics.COMPRESSION_TYPE_DEFAULT, i.e no compression. Supported values:
1304
1287
  *
1305
1288
  * - `COMPRESSION_TYPE_DEFAULT`
1306
- *
1307
1289
  * - `COMPRESSION_TYPE_BASIS_UASTC`
1290
+ *
1291
+ * **0️⃣ `page` is 0-based; passed to Defold unchanged.** **0️⃣ `mipmap` is 0-based; passed to Defold unchanged.**
1308
1292
  * @param buffer - The buffer of precreated pixel data
1309
1293
  * To update a cube map texture you need to pass in six times the amount of data via the buffer, since a cube map has six sides!
1310
1294
  * 3D Textures are currently only supported on OpenGL and Vulkan adapters. To check if your device supports 3D textures, use:
1311
- * ```lua
1312
- * if graphics.TEXTURE_TYPE_3D ~= nil then
1313
- * -- Device and graphics adapter support 3D textures
1314
- * end
1295
+ * ```ts
1296
+ * if (graphics.TEXTURE_TYPE_3D !== undefined) {
1297
+ * // Device and graphics adapter support 3D textures
1298
+ * }
1315
1299
  * ```
1316
1300
  * @example
1317
1301
  * How to set all pixels of an atlas
1318
1302
  * ```ts
1319
1303
  * // How to set all pixels of an atlas
1320
1304
  * export default defineScript({
1321
- * init(self) {
1322
- * self.height = 128;
1323
- * self.width = 128;
1324
- * self.buffer = buffer.create(self.width * self.height, [{ name: hash("rgb"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);
1325
- * self.stream = buffer.get_stream(self.buffer, hash("rgb"));
1326
- *
1327
- * for (let y = 0; y < self.height; y++) {
1328
- * for (let x = 0; x < self.width; x++) {
1329
- * const index = y * self.width * 3 + x * 3;
1330
- * self.stream[index + 0] = 0xff;
1331
- * self.stream[index + 1] = 0x80;
1332
- * self.stream[index + 2] = 0x10;
1305
+ * init() {
1306
+ * const height = 128;
1307
+ * const width = 128;
1308
+ * const buf = buffer.create(width * height, [{ name: hash("rgb"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);
1309
+ * const stream = buffer.get_stream(buf, hash("rgb"));
1310
+ *
1311
+ * for (let y = 0; y < height; y++) {
1312
+ * for (let x = 0; x < width; x++) {
1313
+ * const index = y * width * 3 + x * 3;
1314
+ * stream[index + 0] = 0xff;
1315
+ * stream[index + 1] = 0x80;
1316
+ * stream[index + 2] = 0x10;
1333
1317
  * }
1334
1318
  * }
1335
1319
  *
1336
- * const resource_path = go.get("#model", "texture0");
1337
- * const args = { width: self.width, height: self.height, type: graphics.TEXTURE_TYPE_2D, format: graphics.TEXTURE_FORMAT_RGB, num_mip_maps: 1 };
1338
- * resource.set_texture(resource_path, args, self.buffer);
1320
+ * // the engine registers a texture format only when the driver supports it
1321
+ * const format = graphics.TEXTURE_FORMAT_RGB;
1322
+ * if (format !== undefined) {
1323
+ * const resource_path = go.get<model.properties>()("#model", "texture0");
1324
+ * const args = { width, height, type: graphics.TEXTURE_TYPE_2D, format, num_mip_maps: 1 };
1325
+ * resource.set_texture(resource_path, args, buf);
1326
+ * }
1327
+ * return { buffer: buf, stream };
1339
1328
  * },
1340
1329
  * });
1341
1330
  * ```
@@ -1344,26 +1333,31 @@ declare global {
1344
1333
  * ```ts
1345
1334
  * // How to update a specific region of an atlas by using the x,y values. Assumes the already set atlas is a 128x128 texture.
1346
1335
  * export default defineScript({
1347
- * init(self) {
1348
- * self.x = 16;
1349
- * self.y = 16;
1350
- * self.height = 128 - self.x * 2;
1351
- * self.width = 128 - self.y * 2;
1352
- * self.buffer = buffer.create(self.width * self.height, [{ name: hash("rgb"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);
1353
- * self.stream = buffer.get_stream(self.buffer, hash("rgb"));
1354
- *
1355
- * for (let y = 0; y < self.height; y++) {
1356
- * for (let x = 0; x < self.width; x++) {
1357
- * const index = y * self.width * 3 + x * 3;
1358
- * self.stream[index + 0] = 0xff;
1359
- * self.stream[index + 1] = 0x80;
1360
- * self.stream[index + 2] = 0x10;
1336
+ * init() {
1337
+ * const x = 16;
1338
+ * const y = 16;
1339
+ * const height = 128 - x * 2;
1340
+ * const width = 128 - y * 2;
1341
+ * const buf = buffer.create(width * height, [{ name: hash("rgb"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);
1342
+ * const stream = buffer.get_stream(buf, hash("rgb"));
1343
+ *
1344
+ * for (let row = 0; row < height; row++) {
1345
+ * for (let col = 0; col < width; col++) {
1346
+ * const index = row * width * 3 + col * 3;
1347
+ * stream[index + 0] = 0xff;
1348
+ * stream[index + 1] = 0x80;
1349
+ * stream[index + 2] = 0x10;
1361
1350
  * }
1362
1351
  * }
1363
1352
  *
1364
- * const resource_path = go.get("#model", "texture0");
1365
- * const args = { width: self.width, height: self.height, x: self.x, y: self.y, type: graphics.TEXTURE_TYPE_2D, format: graphics.TEXTURE_FORMAT_RGB, num_mip_maps: 1 };
1366
- * resource.set_texture(resource_path, args, self.buffer);
1353
+ * // the engine registers a texture format only when the driver supports it
1354
+ * const format = graphics.TEXTURE_FORMAT_RGB;
1355
+ * if (format !== undefined) {
1356
+ * const resource_path = go.get<model.properties>()("#model", "texture0");
1357
+ * const args = { width, height, x, y, type: graphics.TEXTURE_TYPE_2D, format, num_mip_maps: 1 };
1358
+ * resource.set_texture(resource_path, args, buf);
1359
+ * }
1360
+ * return { buffer: buf, stream };
1367
1361
  * },
1368
1362
  * });
1369
1363
  * ```
@@ -1371,17 +1365,22 @@ declare global {
1371
1365
  * Update a texture from a buffer resource
1372
1366
  * ```ts
1373
1367
  * // Update a texture from a buffer resource
1374
- * go.property("my_buffer", resource.buffer("/my_default_buffer.buffer"));
1375
- *
1376
1368
  * export default defineScript({
1369
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
1370
+ * // registration from this field, and only this field types the property onto `self`.
1371
+ * properties: { my_buffer: resource.buffer("/my_default_buffer.buffer") },
1372
+ *
1377
1373
  * init(self) {
1378
- * const resource_path = go.get("#model", "texture0");
1374
+ * // the engine registers a texture format only when the driver supports it
1375
+ * const format = graphics.TEXTURE_FORMAT_RGB;
1376
+ * if (format === undefined) return;
1377
+ * const resource_path = go.get<model.properties>()("#model", "texture0");
1379
1378
  * // the "my_buffer" resource is expected to hold 128 * 128 * 3 bytes!
1380
1379
  * const args = {
1381
1380
  * width: 128,
1382
1381
  * height: 128,
1383
1382
  * type: graphics.TEXTURE_TYPE_2D,
1384
- * format: graphics.TEXTURE_FORMAT_RGB,
1383
+ * format,
1385
1384
  * };
1386
1385
  * // Note that the extra resource.get_buffer call is a requirement here
1387
1386
  * // since the "self.my_buffer" is just pointing to a buffer resource path
@@ -1419,7 +1418,7 @@ declare global {
1419
1418
  * width: 8,
1420
1419
  * height: 8,
1421
1420
  * depth: 8,
1422
- * format: resource.TEXTURE_FORMAT_RGBA32F,
1421
+ * format: graphics.TEXTURE_FORMAT_RGBA32F,
1423
1422
  * };
1424
1423
  *
1425
1424
  * // This expects that the texture resource "/my_3d_texture.texturec" already exists
@@ -1434,7 +1433,9 @@ declare global {
1434
1433
  * // Update texture 2nd array page with loaded texture from png
1435
1434
  * const tex_path = "/bundle_resources/page_02.png";
1436
1435
  * const [data] = sys.load_resource(tex_path);
1437
- * if (data !== undefined) {
1436
+ * // the engine registers a texture format only when the driver supports it
1437
+ * const format = graphics.TEXTURE_FORMAT_RGB;
1438
+ * if (data !== undefined && format !== undefined) {
1438
1439
  * const buf = image.load_buffer(data);
1439
1440
  * if (buf !== undefined) {
1440
1441
  * // new_tex is the resource handle of a texture created via resource.create_texture
@@ -1443,7 +1444,7 @@ declare global {
1443
1444
  * width: buf.width,
1444
1445
  * height: buf.height,
1445
1446
  * page_count: 2,
1446
- * format: graphics.TEXTURE_FORMAT_RGB,
1447
+ * format,
1447
1448
  * });
1448
1449
  * resource.set_texture(
1449
1450
  * new_tex,
@@ -1452,7 +1453,7 @@ declare global {
1452
1453
  * width: buf.width,
1453
1454
  * height: buf.height,
1454
1455
  * page: 1,
1455
- * format: graphics.TEXTURE_FORMAT_RGB,
1456
+ * format,
1456
1457
  * },
1457
1458
  * buf.buffer,
1458
1459
  * );
@@ -1461,12 +1462,11 @@ declare global {
1461
1462
  * }
1462
1463
  * ```
1463
1464
  */
1464
- function set_texture(path: Hash | string, table: { type?: number; width?: number; height?: number; format?: number; x?: number; y?: number; z?: number; page?: number; mipmap?: number; compression_type?: number }, buffer: Opaque<"buffer">): void;
1465
+ function set_texture(path: Hash | string, table: { type: number; width: number; height: number; format: number; x?: number; y?: number; z?: number; page?: number; mipmap?: number; compression_type?: number }, buffer: Opaque<"buffer">): void;
1465
1466
  /**
1466
1467
  * Constructor-like function with two purposes:
1467
1468
  *
1468
1469
  * - Load the specified resource as part of loading the script
1469
- *
1470
1470
  * - Return a hash to the run-time version of the resource
1471
1471
  *
1472
1472
  * This function can only be called within go.property function calls.
@@ -1476,9 +1476,11 @@ declare global {
1476
1476
  * @example
1477
1477
  * ```ts
1478
1478
  * // Load a texture and set it to a model:
1479
- * go.property("my_texture", resource.texture("/texture.png"));
1480
- *
1481
1479
  * export default defineScript({
1480
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
1481
+ * // registration from this field, and only this field types the property onto `self`.
1482
+ * properties: { my_texture: resource.texture("/texture.png") },
1483
+ *
1482
1484
  * init(self) {
1483
1485
  * go.set("#model", "texture0", self.my_texture);
1484
1486
  * },
@@ -1490,7 +1492,6 @@ declare global {
1490
1492
  * Constructor-like function with two purposes:
1491
1493
  *
1492
1494
  * - Load the specified resource as part of loading the script
1493
- *
1494
1495
  * - Return a hash to the run-time version of the resource
1495
1496
  *
1496
1497
  * This function can only be called within go.property function calls.
@@ -1500,9 +1501,11 @@ declare global {
1500
1501
  * @example
1501
1502
  * ```ts
1502
1503
  * // Load tile source and set it to a tile map:
1503
- * go.property("my_tile_source", resource.tile_source("/tilesource.tilesource"));
1504
- *
1505
1504
  * export default defineScript({
1505
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
1506
+ * // registration from this field, and only this field types the property onto `self`.
1507
+ * properties: { my_tile_source: resource.tile_source("/tilesource.tilesource") },
1508
+ *
1506
1509
  * init(self) {
1507
1510
  * go.set("#tilemap", "tile_source", self.my_tile_source);
1508
1511
  * },