@defold-typescript/types 0.51.0 → 0.52.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 (130) hide show
  1. package/api-availability.json +4 -58
  2. package/api-signatures.json +878 -1356
  3. package/api-targets.json +15 -5
  4. package/examples/translations.json +4 -56
  5. package/generated/b2d_world.d.ts +10 -10
  6. package/generated/buffer.d.ts +9 -9
  7. package/generated/bullet3d_collision_object.d.ts +1 -1
  8. package/generated/bullet3d_constraint.d.ts +109 -7
  9. package/generated/bullet3d_shape.d.ts +2 -2
  10. package/generated/go.d.ts +114 -220
  11. package/generated/graphics.d.ts +1 -0
  12. package/generated/gui.d.ts +148 -371
  13. package/generated/http.d.ts +2 -2
  14. package/generated/image.d.ts +55 -3
  15. package/generated/kinds/gui-script.d.ts +2 -0
  16. package/generated/kinds/render-script.d.ts +14 -15
  17. package/generated/liveupdate.d.ts +5 -1
  18. package/generated/material.d.ts +3 -3
  19. package/generated/particlefx.d.ts +20 -1
  20. package/generated/physics.d.ts +45 -1
  21. package/generated/render-script-modules/b2d.d.ts +711 -0
  22. package/generated/render-script-modules/bullet3d.d.ts +73 -0
  23. package/generated/render-script-modules/collectionfactory.d.ts +25 -0
  24. package/generated/render-script-modules/collectionproxy.d.ts +39 -0
  25. package/generated/render-script-modules/factory.d.ts +25 -0
  26. package/generated/render-script-modules/go.d.ts +436 -0
  27. package/generated/render-script-modules/label.d.ts +105 -0
  28. package/generated/render-script-modules/model.d.ts +89 -0
  29. package/generated/render-script-modules/particlefx.d.ts +59 -0
  30. package/generated/render-script-modules/physics.d.ts +333 -0
  31. package/generated/render-script-modules/resource.d.ts +1233 -0
  32. package/generated/render-script-modules/sound.d.ts +227 -0
  33. package/generated/render-script-modules/sprite.d.ts +68 -0
  34. package/generated/render-script-modules/tilemap.d.ts +43 -0
  35. package/generated/render.d.ts +134 -8
  36. package/generated/resource.d.ts +31 -10
  37. package/generated/sprite.d.ts +49 -1
  38. package/generated/sys.d.ts +70 -6
  39. package/generated/versions/defold-1.12.4/buffer.d.ts +8 -8
  40. package/generated/versions/defold-1.12.4/go.d.ts +115 -343
  41. package/generated/versions/defold-1.12.4/graphics.d.ts +1 -0
  42. package/generated/versions/defold-1.12.4/gui.d.ts +151 -513
  43. package/generated/versions/defold-1.12.4/http.d.ts +2 -2
  44. package/generated/versions/defold-1.12.4/image.d.ts +82 -2
  45. package/generated/versions/defold-1.12.4/index.d.ts +1 -0
  46. package/generated/versions/defold-1.12.4/liveupdate.d.ts +4 -0
  47. package/generated/versions/defold-1.12.4/particlefx.d.ts +22 -1
  48. package/generated/versions/defold-1.12.4/physics.d.ts +45 -1
  49. package/generated/versions/defold-1.12.4/render.d.ts +78 -2
  50. package/generated/versions/defold-1.12.4/resource.d.ts +43 -10
  51. package/generated/versions/defold-1.12.4/sprite.d.ts +58 -1
  52. package/generated/versions/defold-1.12.4/sys.d.ts +101 -6
  53. package/generated/versions/defold-1.12.4/vmath.d.ts +0 -24
  54. package/generated/versions/defold-1.13.0/buffer.d.ts +8 -8
  55. package/generated/versions/defold-1.13.0/go.d.ts +115 -370
  56. package/generated/versions/defold-1.13.0/graphics.d.ts +1 -0
  57. package/generated/versions/defold-1.13.0/gui.d.ts +151 -513
  58. package/generated/versions/defold-1.13.0/http.d.ts +2 -2
  59. package/generated/versions/defold-1.13.0/image.d.ts +82 -2
  60. package/generated/versions/defold-1.13.0/index.d.ts +1 -0
  61. package/generated/versions/defold-1.13.0/liveupdate.d.ts +4 -0
  62. package/generated/versions/defold-1.13.0/material.d.ts +3 -1
  63. package/generated/versions/defold-1.13.0/particlefx.d.ts +22 -1
  64. package/generated/versions/defold-1.13.0/physics.d.ts +45 -1
  65. package/generated/versions/defold-1.13.0/render.d.ts +142 -4
  66. package/generated/versions/defold-1.13.0/resource.d.ts +43 -10
  67. package/generated/versions/defold-1.13.0/sprite.d.ts +58 -1
  68. package/generated/versions/defold-1.13.0/sys.d.ts +101 -6
  69. package/generated/versions/defold-1.13.0/vmath.d.ts +0 -24
  70. package/generated/versions/defold-1.13.1/buffer.d.ts +8 -8
  71. package/generated/versions/defold-1.13.1/go.d.ts +115 -370
  72. package/generated/versions/defold-1.13.1/graphics.d.ts +1 -0
  73. package/generated/versions/defold-1.13.1/gui.d.ts +151 -529
  74. package/generated/versions/defold-1.13.1/http.d.ts +2 -2
  75. package/generated/versions/defold-1.13.1/image.d.ts +82 -2
  76. package/generated/versions/defold-1.13.1/index.d.ts +2 -0
  77. package/generated/versions/defold-1.13.1/liveupdate.d.ts +4 -0
  78. package/generated/versions/defold-1.13.1/material.d.ts +3 -1
  79. package/generated/versions/defold-1.13.1/particlefx.d.ts +22 -1
  80. package/generated/versions/defold-1.13.1/physics.d.ts +45 -1
  81. package/generated/versions/defold-1.13.1/render.d.ts +142 -4
  82. package/generated/versions/defold-1.13.1/resource.d.ts +43 -10
  83. package/generated/versions/defold-1.13.1/sprite.d.ts +58 -1
  84. package/generated/versions/defold-1.13.1/sys.d.ts +101 -6
  85. package/generated/versions/defold-1.13.1/vmath.d.ts +0 -24
  86. package/generated/versions/defold-1.13.2/b2d_world.d.ts +10 -10
  87. package/generated/versions/defold-1.13.2/buffer.d.ts +9 -9
  88. package/generated/versions/defold-1.13.2/bullet3d_collision_object.d.ts +1 -1
  89. package/generated/versions/defold-1.13.2/bullet3d_constraint.d.ts +109 -7
  90. package/generated/versions/defold-1.13.2/bullet3d_shape.d.ts +2 -2
  91. package/generated/versions/defold-1.13.2/go.d.ts +114 -220
  92. package/generated/versions/defold-1.13.2/graphics.d.ts +1 -0
  93. package/generated/versions/defold-1.13.2/gui.d.ts +148 -371
  94. package/generated/versions/defold-1.13.2/http.d.ts +2 -2
  95. package/generated/versions/defold-1.13.2/image.d.ts +55 -3
  96. package/generated/versions/defold-1.13.2/index.d.ts +2 -0
  97. package/generated/versions/defold-1.13.2/liveupdate.d.ts +5 -1
  98. package/generated/versions/defold-1.13.2/material.d.ts +3 -3
  99. package/generated/versions/defold-1.13.2/particlefx.d.ts +20 -1
  100. package/generated/versions/defold-1.13.2/physics.d.ts +45 -1
  101. package/generated/versions/defold-1.13.2/render.d.ts +123 -7
  102. package/generated/versions/defold-1.13.2/resource.d.ts +31 -10
  103. package/generated/versions/defold-1.13.2/sprite.d.ts +49 -1
  104. package/generated/versions/defold-1.13.2/sys.d.ts +70 -6
  105. package/generated/versions/defold-1.13.2/vmath.d.ts +0 -24
  106. package/generated/vmath.d.ts +0 -24
  107. package/identity-vocabulary.json +52 -7
  108. package/index.d.ts +2 -0
  109. package/package.json +2 -1
  110. package/scripts/generate-api-availability.ts +1 -21
  111. package/scripts/generate-api-signatures.ts +75 -14
  112. package/scripts/materialize-version.ts +48 -7
  113. package/scripts/regen.ts +214 -19
  114. package/scripts/signature-store-fs.ts +1 -0
  115. package/scripts/target-version.ts +26 -0
  116. package/src/api-doc.ts +26 -0
  117. package/src/component-properties.d.ts +89 -0
  118. package/src/core-types.ts +42 -15
  119. package/src/doc-corrections.ts +53 -5
  120. package/src/emit-dts.ts +758 -198
  121. package/src/engine-globals.d.ts +5 -1
  122. package/src/go-overloads.d.ts +68 -13
  123. package/src/gui-overloads.d.ts +489 -0
  124. package/src/gui-texture-removal.d.ts +41 -0
  125. package/src/index.ts +2 -0
  126. package/src/lifecycle.ts +30 -21
  127. package/src/msg-overloads.d.ts +25 -13
  128. package/src/signature-store.ts +50 -0
  129. package/src/timers.d.ts +2 -1
  130. package/src/vmath-overloads.d.ts +26 -0
@@ -54,7 +54,7 @@ declare global {
54
54
  /**
55
55
  * Script buffer containing the decompressed image data.
56
56
  */
57
- buffer: Opaque<"buffer">;
57
+ buffer: Opaque<"buffer"> & { length: LuaLengthMethod<number> };
58
58
  }
59
59
  /**
60
60
  * Image loading options
@@ -141,7 +141,59 @@ declare global {
141
141
  * });
142
142
  * ```
143
143
  */
144
- function load(buffer: string, options?: boolean | image.load_options): image.load_result | undefined;
144
+ function load(buffer: string): image.load_result | undefined;
145
+ /**
146
+ * Load image (PNG or JPEG) from buffer.
147
+ *
148
+ * @param buffer - image data buffer
149
+ * @param options - Optional loading parameters. A boolean is accepted for backwards compatibility and controls `premultiply_alpha`.
150
+ * @returns loaded image, or `nil` if loading fails
151
+ * @example
152
+ * ```ts
153
+ * // How to load an image from an URL and create a GUI texture from it:
154
+ * const imgurl = "http://www.site.com/image.png";
155
+ * http.request(imgurl, "GET", (self, id, response) => {
156
+ * const img = response.response !== undefined ? image.load(response.response) : undefined;
157
+ * if (img !== undefined) {
158
+ * const tx = gui.new_texture("image_node", img.width, img.height, img.type, img.buffer);
159
+ * }
160
+ * });
161
+ * ```
162
+ */
163
+ function load(buffer: string, options: boolean | image.load_options): image.load_result | undefined;
164
+ /**
165
+ * Load image (PNG or JPEG) from a string buffer.
166
+ *
167
+ * @param buffer - image data buffer
168
+ * @param options - Optional loading parameters. A boolean is accepted for backwards compatibility and controls `premultiply_alpha`.
169
+ * @returns loaded image, or `nil` if loading fails
170
+ * @example
171
+ * ```ts
172
+ * // Load an image from an URL as a buffer and create a texture resource from it:
173
+ * const imgurl = "http://www.site.com/image.png";
174
+ * http.request(imgurl, "GET", (self, id, response) => {
175
+ * const img =
176
+ * response.response !== undefined
177
+ * ? image.load_buffer(response.response, { flip_vertically: true })
178
+ * : undefined;
179
+ * // the engine registers a texture format only when the driver supports it
180
+ * const format = graphics.TEXTURE_FORMAT_RGBA;
181
+ * if (img !== undefined && format !== undefined) {
182
+ * const tparams = {
183
+ * width: img.width,
184
+ * height: img.height,
185
+ * type: graphics.TEXTURE_TYPE_2D,
186
+ * format,
187
+ * };
188
+ *
189
+ * const my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams, img.buffer);
190
+ * // Apply the texture to a model
191
+ * go.set("/go1#model", "texture0", my_texture_id);
192
+ * }
193
+ * });
194
+ * ```
195
+ */
196
+ function load_buffer(buffer: string): image.load_buffer_result | undefined;
145
197
  /**
146
198
  * Load image (PNG or JPEG) from a string buffer.
147
199
  *
@@ -174,7 +226,7 @@ declare global {
174
226
  * });
175
227
  * ```
176
228
  */
177
- function load_buffer(buffer: string, options?: boolean | image.load_options): image.load_buffer_result | undefined;
229
+ function load_buffer(buffer: string, options: boolean | image.load_options): image.load_buffer_result | undefined;
178
230
  }
179
231
  }
180
232
 
@@ -58,6 +58,8 @@ import "../../../src/scene-addresses";
58
58
  import "../../../src/go-overloads";
59
59
  import "../../../src/component-properties";
60
60
  import "../../../src/render-overloads";
61
+ import "../../../src/gui-overloads";
62
+ import "../../../src/gui-texture-removal";
61
63
  import "../../../src/vmath-overloads";
62
64
  import "../../../src/sys-overloads";
63
65
 
@@ -6,7 +6,7 @@ declare global {
6
6
  * Functions and constants to access resources.
7
7
  */
8
8
  namespace liveupdate {
9
- type LIVEUPDATE = typeof liveupdate.LIVEUPDATE_BUNDLED_RESOURCE_MISMATCH | typeof liveupdate.LIVEUPDATE_ENGINE_VERSION_MISMATCH | typeof liveupdate.LIVEUPDATE_FORMAT_ERROR | typeof liveupdate.LIVEUPDATE_INVAL | typeof liveupdate.LIVEUPDATE_INVALID_HEADER | typeof liveupdate.LIVEUPDATE_INVALID_RESOURCE | typeof liveupdate.LIVEUPDATE_IO_ERROR | typeof liveupdate.LIVEUPDATE_MEM_ERROR | typeof liveupdate.LIVEUPDATE_OK | typeof liveupdate.LIVEUPDATE_SCHEME_MISMATCH | typeof liveupdate.LIVEUPDATE_SIGNATURE_MISMATCH | typeof liveupdate.LIVEUPDATE_UNKNOWN | typeof liveupdate.LIVEUPDATE_VERSION_MISMATCH;
9
+ type LIVEUPDATE = typeof liveupdate.LIVEUPDATE_BUNDLED_RESOURCE_MISMATCH | typeof liveupdate.LIVEUPDATE_ENGINE_VERSION_MISMATCH | typeof liveupdate.LIVEUPDATE_FORMAT_ERROR | typeof liveupdate.LIVEUPDATE_INVAL | typeof liveupdate.LIVEUPDATE_INVALID_HEADER | typeof liveupdate.LIVEUPDATE_INVALID_RESOURCE | typeof liveupdate.LIVEUPDATE_IO_ERROR | typeof liveupdate.LIVEUPDATE_MEM_ERROR | typeof liveupdate.LIVEUPDATE_OK | typeof liveupdate.LIVEUPDATE_SCHEME_MISMATCH | typeof liveupdate.LIVEUPDATE_SIGNATURE_MISMATCH | typeof liveupdate.LIVEUPDATE_UNKNOWN | typeof liveupdate.LIVEUPDATE_VERSION_MISMATCH | typeof liveupdate.LIVEUPDATE_NOT_INITIALIZED;
10
10
  /**
11
11
  * Mismatch between between expected bundled resources and actual bundled resources. The manifest expects a resource to be in the bundle, but it was not found in the bundle. This is typically the case when a non-excluded resource was modified between publishing the bundle and publishing the manifest.
12
12
  */
@@ -39,6 +39,10 @@ declare global {
39
39
  * Memory wasn't allocated
40
40
  */
41
41
  const LIVEUPDATE_MEM_ERROR: number & { readonly __brand: "liveupdate.LIVEUPDATE_MEM_ERROR" };
42
+ /**
43
+ * Live update is not initialized. `liveupdate.add_mount` and `liveupdate.remove_mount` return it while live update is disabled.
44
+ */
45
+ const LIVEUPDATE_NOT_INITIALIZED: number & { readonly __brand: "liveupdate.LIVEUPDATE_NOT_INITIALIZED" };
42
46
  /**
43
47
  * Operation completed successfully.
44
48
  */
@@ -78,7 +78,7 @@ declare global {
78
78
  /**
79
79
  * Sampler texture type.
80
80
  */
81
- type: graphics.TEXTURE_TYPE;
81
+ type: graphics.TEXTURE_TYPE | 6 | 7 | 8 | 9 | 10;
82
82
  /**
83
83
  * Horizontal wrap mode.
84
84
  */
@@ -348,7 +348,7 @@ declare global {
348
348
  * Returns a table of all the textures from the material.
349
349
  *
350
350
  * @param path - The path to the resource
351
- * @returns material texture information
351
+ * @returns material texture information. Keyed by sampler slot from 1; a slot with no texture has no entry, so iterate with `for (const [slot, info] of textures)`.
352
352
  * @example
353
353
  * ```ts
354
354
  * // Get the textures from a material specified as a resource property
@@ -363,7 +363,7 @@ declare global {
363
363
  * });
364
364
  * ```
365
365
  */
366
- function get_textures(path: Hash | string): material.texture_info[];
366
+ function get_textures(path: Hash | string): LuaMap<number, material.texture_info>;
367
367
  /**
368
368
  * Returns a table of all the vertex attributes in the material. This function will return all the vertex attributes
369
369
  * that are used in the vertex shader of the material.
@@ -128,7 +128,26 @@ declare global {
128
128
  * });
129
129
  * ```
130
130
  */
131
- function stop(url: string | Hash | Url, options?: particlefx.stop_options): void;
131
+ function stop(url: string | Hash | Url): void;
132
+ /**
133
+ * Stops a particle FX component from playing.
134
+ * Stopping a particle FX does not remove already spawned particles.
135
+ * Which particle FX to stop is identified by the URL.
136
+ *
137
+ * @param url - the particle fx that should stop playing
138
+ * @param options - options used when stopping the particle fx
139
+ * @example
140
+ * ```ts
141
+ * // How to stop a particle fx when a game object is deleted and immediately also
142
+ * // clear any spawned particles:
143
+ * export default defineScript({
144
+ * final(self) {
145
+ * particlefx.stop("#particlefx", { clear: true });
146
+ * },
147
+ * });
148
+ * ```
149
+ */
150
+ function stop(url: string | Hash | Url, options: particlefx.stop_options): void;
132
151
  interface properties {
133
152
  /**
134
153
  * The animation used during rendering by an emitter in a particle FX component.
@@ -435,7 +435,51 @@ declare global {
435
435
  * });
436
436
  * ```
437
437
  */
438
- function raycast_async(from: Vector3, to: Vector3, groups: Hash[], request_id?: number): void;
438
+ function raycast_async(from: Vector3, to: Vector3, groups: Hash[]): void;
439
+ /**
440
+ * Ray casts are used to test for intersections against collision objects in the physics world.
441
+ * Collision objects of types kinematic, dynamic and static are tested against. Trigger objects
442
+ * do not intersect with ray casts.
443
+ * Which collision objects to hit is filtered by their collision groups and can be configured
444
+ * through `groups`.
445
+ * The actual ray cast will be performed during the physics-update.
446
+ *
447
+ * - If an object is hit, the result will be reported via a ray_cast_response message.
448
+ * - If there is no object hit, the result will be reported via a ray_cast_missed message.
449
+ *
450
+ * NOTE: Ray casts will ignore collision objects that contain the starting point of the ray. This is a limitation in Box2D.
451
+ *
452
+ * @param from - the world position of the start of the ray
453
+ * @param to - the world position of the end of the ray
454
+ * @param groups - a lua table containing the hashed groups for which to test collisions against
455
+ * @param request_id - a number in range [0,255]. It will be sent back in the response for identification, 0 by default
456
+ * @example
457
+ * ```ts
458
+ * // How to perform a ray cast asynchronously:
459
+ * export default defineScript({
460
+ * init() {
461
+ * return { my_groups: [hash("my_group1"), hash("my_group2")] };
462
+ * },
463
+ *
464
+ * update(self, dt) {
465
+ * // request ray cast
466
+ * const my_start = go.get_world_position();
467
+ * const my_end = vmath.vector3(my_start.x, my_start.y - 100, my_start.z);
468
+ * physics.raycast_async(my_start, my_end, self.my_groups);
469
+ * },
470
+ *
471
+ * on_message(self, message_id, message, sender) {
472
+ * // check for the response
473
+ * if (message_id === hash("ray_cast_response")) {
474
+ * // act on the hit
475
+ * } else if (message_id === hash("ray_cast_missed")) {
476
+ * // act on the miss
477
+ * }
478
+ * },
479
+ * });
480
+ * ```
481
+ */
482
+ function raycast_async(from: Vector3, to: Vector3, groups: Hash[], request_id: number): void;
439
483
  /**
440
484
  * Only one physics world event listener can be set at a time.
441
485
  *
@@ -59,7 +59,7 @@ declare global {
59
59
  */
60
60
  sort_order?: render.SORT;
61
61
  }
62
- type render_predicate = number;
62
+ type render_predicate = Opaque<"render_predicate">;
63
63
  type render_target = Opaque<"render_target">;
64
64
  /**
65
65
  * Render-target attachment parameters
@@ -114,6 +114,7 @@ declare global {
114
114
  }
115
115
  type texture = Opaque<"texture">;
116
116
  type ClearBufferKey = typeof graphics.BUFFER_TYPE_COLOR0_BIT | typeof graphics.BUFFER_TYPE_DEPTH_BIT | typeof graphics.BUFFER_TYPE_STENCIL_BIT;
117
+ type RenderTargetTextureType = typeof graphics.TEXTURE_TYPE_2D | typeof graphics.TEXTURE_TYPE_CUBE_MAP;
117
118
  type RenderTargetParams = render.render_target_params;
118
119
  type CONTEXT_EVENT = typeof render.CONTEXT_EVENT_CONTEXT_LOST | typeof render.CONTEXT_EVENT_CONTEXT_RESTORED;
119
120
  type FRUSTUM_PLANES = typeof render.FRUSTUM_PLANES_ALL | typeof render.FRUSTUM_PLANES_SIDES;
@@ -291,7 +292,7 @@ declare global {
291
292
  * });
292
293
  * ```
293
294
  */
294
- function disable_state(state: graphics.STATE): void;
295
+ function disable_state(state: graphics.State): void;
295
296
  /**
296
297
  * Disables a texture that has previourly been enabled.
297
298
  *
@@ -326,7 +327,7 @@ declare global {
326
327
  * });
327
328
  * ```
328
329
  */
329
- function disable_texture(binding: Opaque<"texture"> | string | Hash | number): void;
330
+ function disable_texture(binding: string | Hash | number): void;
330
331
  /**
331
332
  * Dispatches the currently enabled compute program. The dispatch call takes three arguments x,y,z which constitutes
332
333
  * the 'global working group' of the compute dispatch. Together with the 'local working group' specified in the compute shader
@@ -423,7 +424,56 @@ declare global {
423
424
  * }
424
425
  * ```
425
426
  */
426
- function draw(predicate: Opaque<"render_predicate">, options?: render.draw_options): void;
427
+ function draw(predicate: Opaque<"render_predicate">): void;
428
+ /**
429
+ * Draws all objects that match a specified predicate. An optional constant buffer can be
430
+ * provided to override the default constants. If no constants buffer is provided, a default
431
+ * system constants buffer is used containing constants as defined in materials and set through
432
+ * go.set (or particlefx.set_constant) on visual components.
433
+ *
434
+ * @param predicate - predicate to draw for
435
+ * @param options - optional draw options
436
+ * @example
437
+ * ```ts
438
+ * export default defineRenderScript({
439
+ * init() {
440
+ * // define a predicate matching anything with material tag "my_tag"
441
+ * return { my_pred: render.predicate([hash("my_tag")]) };
442
+ * },
443
+ *
444
+ * update(self, dt) {
445
+ * // draw everything in the my_pred predicate
446
+ * render.draw(self.my_pred);
447
+ * },
448
+ * });
449
+ * ```
450
+ * @example
451
+ * Draw predicate with constants:
452
+ * ```ts
453
+ * function draw_tinted(self: { my_pred: Opaque<"render_predicate"> }) {
454
+ * const constants = render.constant_buffer();
455
+ * constants.tint = vmath.vector4(1, 1, 1, 1);
456
+ * render.draw(self.my_pred, { constants });
457
+ * }
458
+ * ```
459
+ * @example
460
+ * Draw with predicate and frustum culling (without near+far planes):
461
+ * ```ts
462
+ * function draw_culled(self: { my_pred: Opaque<"render_predicate">; proj: Matrix4; view: Matrix4 }) {
463
+ * const frustum = self.proj.mul(self.view);
464
+ * render.draw(self.my_pred, { frustum });
465
+ * }
466
+ * ```
467
+ * @example
468
+ * Draw with predicate and frustum culling (with near+far planes):
469
+ * ```ts
470
+ * function draw_culled(self: { my_pred: Opaque<"render_predicate">; proj: Matrix4; view: Matrix4 }) {
471
+ * const frustum = self.proj.mul(self.view);
472
+ * render.draw(self.my_pred, { frustum, frustum_planes: render.FRUSTUM_PLANES_ALL });
473
+ * }
474
+ * ```
475
+ */
476
+ function draw(predicate: Opaque<"render_predicate">, options: render.draw_options): void;
427
477
  /**
428
478
  * Draws all 3d debug graphics such as lines drawn with "draw_line" messages and physics visualization.
429
479
  *
@@ -490,7 +540,7 @@ declare global {
490
540
  * });
491
541
  * ```
492
542
  */
493
- function enable_state(state: graphics.STATE): void;
543
+ function enable_state(state: graphics.State): void;
494
544
  /**
495
545
  * Sets the specified texture handle for a render target attachment or a regular texture
496
546
  * that should be used for rendering. The texture can be bound to either a texture unit
@@ -787,7 +837,7 @@ declare global {
787
837
  * render.set_blend_func_separate(graphics.BLEND_FACTOR_SRC_ALPHA, graphics.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, graphics.BLEND_FACTOR_ONE, graphics.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA);
788
838
  * ```
789
839
  */
790
- function set_blend_func_separate(source_factor_color: number, destination_factor_color: number, source_factor_alpha: number, destination_factor_alpha: number): void;
840
+ function set_blend_func_separate(source_factor_color: graphics.BlendFactor, destination_factor_color: graphics.BlendFactor, source_factor_alpha: graphics.BlendFactor, destination_factor_alpha: graphics.BlendFactor): void;
791
841
  /**
792
842
  * Sets the current render camera to be used for rendering. If a render camera
793
843
  * has been set by the render script, the renderer will be using its projection and view matrix
@@ -1033,7 +1083,73 @@ declare global {
1033
1083
  * });
1034
1084
  * ```
1035
1085
  */
1036
- function set_render_target(render_target?: Opaque<"render_target"> | string | Hash | typeof render.RENDER_TARGET_DEFAULT, options?: render.set_render_target_options): void;
1086
+ function set_render_target(render_target?: Opaque<"render_target"> | string | Hash | typeof render.RENDER_TARGET_DEFAULT): void;
1087
+ /**
1088
+ * Sets a render target. Subsequent draw operations will be to the
1089
+ * render target until it is replaced by a subsequent call to set_render_target.
1090
+ * This function supports render targets created by a render script, or a render target resource.
1091
+ *
1092
+ * @param render_target - render target to set. Omit it, pass `nil`, or use render.RENDER_TARGET_DEFAULT to set the default render target
1093
+ * @param options - optional render-target activation options
1094
+ * @example
1095
+ * How to set a render target and draw to it and then switch back to the default render target
1096
+ * The render target defines the depth/stencil buffers as transient, when set_render_target is called the next time the buffers may be invalidated and allow for optimisations depending on driver support
1097
+ * ```ts
1098
+ * // How to set a render target and draw to it and then switch back to the default render target
1099
+ * // The render target defines the depth/stencil buffers as transient, when set_render_target is called the next time the buffers may be invalidated and allow for optimisations depending on driver support
1100
+ * export default defineRenderScript({
1101
+ * init() {
1102
+ * // the engine registers a texture format only when the driver supports it
1103
+ * const format = graphics.TEXTURE_FORMAT_RGBA;
1104
+ * if (format === undefined) return undefined;
1105
+ * const color_params = {
1106
+ * format,
1107
+ * width: render.get_window_width(),
1108
+ * height: render.get_window_height(),
1109
+ * };
1110
+ * return {
1111
+ * my_render_target: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),
1112
+ * my_pred: render.predicate([hash("my_tag")]),
1113
+ * };
1114
+ * },
1115
+ *
1116
+ * update(self, dt) {
1117
+ * if (self === undefined) return;
1118
+ * // set render target so all drawing is done to it
1119
+ * render.set_render_target(self.my_render_target, {
1120
+ * transient: [graphics.BUFFER_TYPE_DEPTH_BIT, graphics.BUFFER_TYPE_STENCIL_BIT],
1121
+ * });
1122
+ *
1123
+ * // draw a predicate to the render target
1124
+ * render.draw(self.my_pred);
1125
+ *
1126
+ * // set default render target. This also invalidates the depth and stencil buffers of the current target (self.my_render_target)
1127
+ * // which can be an optimisation on some hardware
1128
+ * render.set_render_target(render.RENDER_TARGET_DEFAULT);
1129
+ * },
1130
+ * });
1131
+ * ```
1132
+ * @example
1133
+ * ```ts
1134
+ * export default defineRenderScript({
1135
+ * init() {
1136
+ * return { my_pred: render.predicate([hash("my_tag")]) };
1137
+ * },
1138
+ *
1139
+ * update(self, dt) {
1140
+ * // set render target by a render target resource identifier
1141
+ * render.set_render_target("my_rt_resource");
1142
+ *
1143
+ * // draw a predicate to the render target
1144
+ * render.draw(self.my_pred);
1145
+ *
1146
+ * // reset the render target to the default backbuffer
1147
+ * render.set_render_target(render.RENDER_TARGET_DEFAULT);
1148
+ * },
1149
+ * });
1150
+ * ```
1151
+ */
1152
+ function set_render_target(render_target: Opaque<"render_target"> | string | Hash | typeof render.RENDER_TARGET_DEFAULT | undefined, options: render.set_render_target_options): void;
1037
1153
  /**
1038
1154
  * Sets the render target size for a render target created from
1039
1155
  * either a render script, or from a render target resource.
@@ -130,7 +130,7 @@ declare global {
130
130
  /**
131
131
  * Buffer to bind to the resource.
132
132
  */
133
- buffer: Opaque<"buffer">;
133
+ buffer: Opaque<"buffer"> & { length: LuaLengthMethod<number> };
134
134
  /**
135
135
  * Whether the resource takes ownership of the buffer. The default is true.
136
136
  */
@@ -708,7 +708,7 @@ declare global {
708
708
  * });
709
709
  * ```
710
710
  */
711
- function create_sound_data(path: string, options: resource.sound_data_options): Hash;
711
+ function create_sound_data(path: string, options: resource.sound_data_options & ({ partial?: false } | ({ partial: true } & Required<Pick<resource.sound_data_options, "filesize">>))): Hash;
712
712
  /**
713
713
  * Creates a new texture resource that can be used in the same way as any texture created during build time.
714
714
  * The path used for creating the texture must be unique, trying to create a resource at a path that is already
@@ -836,7 +836,7 @@ declare global {
836
836
  * }
837
837
  * ```
838
838
  */
839
- function create_texture(path: string, table: resource.texture_creation_params, buffer?: Opaque<"buffer">): Hash;
839
+ function create_texture(path: string, table: resource.texture_creation_params, buffer?: Opaque<"buffer"> & { length: LuaLengthMethod<number> }): Hash;
840
840
  /**
841
841
  * Creates a new texture resource that can be used in the same way as any texture created during build time.
842
842
  * The path used for creating the texture must be unique, trying to create a resource at a path that is already
@@ -955,7 +955,7 @@ declare global {
955
955
  * });
956
956
  * ```
957
957
  */
958
- function create_texture_async(path: string, table: resource.texture_creation_params, buffer: Opaque<"buffer"> | undefined, callback: (self: unknown, request_id: number, result: resource.texture_creation_result) => void): LuaMultiReturn<[Hash, number]>;
958
+ function create_texture_async(path: string, table: resource.texture_creation_params, buffer: Opaque<"buffer"> & { length: LuaLengthMethod<number> } | undefined, callback: (self: unknown, request_id: number, result: resource.texture_creation_result) => void): LuaMultiReturn<[Hash, number]>;
959
959
  /**
960
960
  * Constructor-like function with two purposes:
961
961
  *
@@ -1024,7 +1024,7 @@ declare global {
1024
1024
  * });
1025
1025
  * ```
1026
1026
  */
1027
- function get_buffer(path: Hash | string): Opaque<"buffer">;
1027
+ function get_buffer(path: Hash | string): Opaque<"buffer"> & { length: LuaLengthMethod<number> };
1028
1028
  /**
1029
1029
  * Gets render target info from a render target resource path or a render target handle
1030
1030
  *
@@ -1080,7 +1080,28 @@ declare global {
1080
1080
  * });
1081
1081
  * ```
1082
1082
  */
1083
- function get_text_metrics(url: Hash | string, text: string, options?: resource.text_metrics_options): resource.text_metrics;
1083
+ function get_text_metrics(url: Hash | string, text: string): resource.text_metrics;
1084
+ /**
1085
+ * Gets the text metrics from a font. Rich text markup is measured using its
1086
+ * visible text and font sizes. If markup cannot be parsed, the text is measured literally.
1087
+ * Inline sprites reserve their specified dimensions, or one em by default.
1088
+ *
1089
+ * @param url - the font to get the (unscaled) metrics from
1090
+ * @param text - text to measure
1091
+ * @param options - optional text-metric options
1092
+ * @returns measured text metrics
1093
+ * @example
1094
+ * ```ts
1095
+ * export default defineScript({
1096
+ * init() {
1097
+ * const font = go.get<label.properties>()("#label", "font");
1098
+ * const metrics = resource.get_text_metrics(font, "The quick brown fox\n jumps over the lazy dog");
1099
+ * pprint(metrics);
1100
+ * },
1101
+ * });
1102
+ * ```
1103
+ */
1104
+ function get_text_metrics(url: Hash | string, text: string, options: resource.text_metrics_options): resource.text_metrics;
1084
1105
  /**
1085
1106
  * Gets texture info from a texture resource path or a texture handle
1086
1107
  *
@@ -1155,7 +1176,7 @@ declare global {
1155
1176
  * // custom_resources = resources/,assets/level_data.json
1156
1177
  * ```
1157
1178
  */
1158
- function load(path: string): Opaque<"buffer">;
1179
+ function load(path: string): Opaque<"buffer"> & { length: LuaLengthMethod<number> };
1159
1180
  /**
1160
1181
  * Constructor-like function with two purposes:
1161
1182
  *
@@ -1242,7 +1263,7 @@ declare global {
1242
1263
  * resource.set(go.get<sprite.properties>()("#sprite", "texture0"), buffer);
1243
1264
  * ```
1244
1265
  */
1245
- function set(path: string | Hash, buffer: Opaque<"buffer">): void;
1266
+ function set(path: string | Hash, buffer: Opaque<"buffer"> & { length: LuaLengthMethod<number> }): void;
1246
1267
  /**
1247
1268
  * Sets the data for a specific atlas resource. Setting new atlas data is specified by passing in
1248
1269
  * a texture path for the backing texture of the atlas, a list of geometries and a list of animations
@@ -1371,7 +1392,7 @@ declare global {
1371
1392
  * });
1372
1393
  * ```
1373
1394
  */
1374
- function set_buffer(path: Hash | string, buffer: Opaque<"buffer">, table?: resource.buffer_update_options): void;
1395
+ function set_buffer(path: Hash | string, buffer: Opaque<"buffer"> & { length: LuaLengthMethod<number> }, table?: resource.buffer_update_options): void;
1375
1396
  /**
1376
1397
  * Update internal sound resource (wavc/oggc/opusc) with new data
1377
1398
  *
@@ -1571,7 +1592,7 @@ declare global {
1571
1592
  * }
1572
1593
  * ```
1573
1594
  */
1574
- function set_texture(path: Hash | string, table: resource.texture_update_params, buffer: Opaque<"buffer">): void;
1595
+ function set_texture(path: Hash | string, table: resource.texture_update_params, buffer: Opaque<"buffer"> & { length: LuaLengthMethod<number> }): void;
1575
1596
  /**
1576
1597
  * Constructor-like function with two purposes:
1577
1598
  *
@@ -66,7 +66,55 @@ declare global {
66
66
  * });
67
67
  * ```
68
68
  */
69
- function play_flipbook(url: string | Hash | Url, id: string | Hash, complete_function?: (self: unknown, message_id: Hash, message: { current_tile: number; id: Hash }, sender: Url) => void, play_properties?: sprite.play_properties): void;
69
+ function play_flipbook(url: string | Hash | Url, id: string | Hash, complete_function?: (self: unknown, message_id: Hash, message: { current_tile: number; id: Hash }, sender: Url) => void): void;
70
+ /**
71
+ * Play an animation on a sprite component from its tile set
72
+ * An optional completion callback function can be provided that will be called when
73
+ * the animation has completed playing. If no function is provided,
74
+ * a animation_done message is sent to the script that started the animation.
75
+ *
76
+ * @param url - the sprite that should play the animation
77
+ * @param id - hashed id of the animation to play
78
+ * @param complete_function - function to call when the animation has completed.
79
+ *
80
+ * `self`
81
+ * script_instance The current script instance.
82
+ * `message_id`
83
+ * hash The name of the completion message, `"animation_done"`.
84
+ * `message`
85
+ * message.sprite.animation_done Information about the completion.
86
+ * `sender`
87
+ * url The invoker of the callback: the sprite component.
88
+ * @param play_properties - optional playback properties
89
+ * @example
90
+ * The following examples assumes that the model has id "sprite".
91
+ * How to play the "jump" animation followed by the "run" animation:
92
+ * ```ts
93
+ * const url = msg.url("#sprite");
94
+ *
95
+ * function anim_done(self: unknown, message_id: Hash, message: { id: Hash }) {
96
+ * if (message_id === hash("animation_done") && message.id === hash("jump")) {
97
+ * // jump animation done, chain with "run"
98
+ * sprite.play_flipbook(url, "run");
99
+ * }
100
+ * }
101
+ * ```
102
+ * @example
103
+ * ```ts
104
+ * export default defineScript({
105
+ * init() {
106
+ * const url = msg.url("#sprite");
107
+ * sprite.play_flipbook(url, "jump", (self, message_id, message) => {
108
+ * if (message_id === hash("animation_done") && message.id === hash("jump")) {
109
+ * // jump animation done, chain with "run"
110
+ * sprite.play_flipbook(url, "run");
111
+ * }
112
+ * });
113
+ * },
114
+ * });
115
+ * ```
116
+ */
117
+ function play_flipbook(url: string | Hash | Url, id: string | Hash, complete_function: ((self: unknown, message_id: Hash, message: { current_tile: number; id: Hash }, sender: Url) => void) | undefined, play_properties: sprite.play_properties): void;
70
118
  /**
71
119
  * Resets a shader constant for a sprite component.
72
120
  * The constant must be defined in the material assigned to the sprite.