@defold-typescript/types 0.44.1 → 0.46.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 (45) hide show
  1. package/examples/translations.json +34 -34
  2. package/generated/b2d_fixture.d.ts +23 -1
  3. package/generated/b2d_shape.d.ts +22 -1
  4. package/generated/compute.d.ts +29 -2
  5. package/generated/go.d.ts +2 -2
  6. package/generated/gui.d.ts +5 -7
  7. package/generated/material.d.ts +98 -8
  8. package/generated/model.d.ts +11 -5
  9. package/generated/particlefx.d.ts +5 -7
  10. package/generated/render.d.ts +12 -18
  11. package/generated/sys.d.ts +8 -10
  12. package/generated/versions/defold-1.12.4/go.d.ts +2 -2
  13. package/generated/versions/defold-1.12.4/gui.d.ts +5 -7
  14. package/generated/versions/defold-1.12.4/particlefx.d.ts +5 -7
  15. package/generated/versions/defold-1.12.4/render.d.ts +12 -18
  16. package/generated/versions/defold-1.12.4/sys.d.ts +8 -10
  17. package/generated/versions/defold-1.12.4/window.d.ts +13 -15
  18. package/generated/versions/defold-1.13.0/b2d_fixture.d.ts +23 -1
  19. package/generated/versions/defold-1.13.0/b2d_shape.d.ts +22 -1
  20. package/generated/versions/defold-1.13.0/compute.d.ts +29 -2
  21. package/generated/versions/defold-1.13.0/go.d.ts +2 -2
  22. package/generated/versions/defold-1.13.0/gui.d.ts +5 -7
  23. package/generated/versions/defold-1.13.0/material.d.ts +98 -8
  24. package/generated/versions/defold-1.13.0/model.d.ts +11 -5
  25. package/generated/versions/defold-1.13.0/particlefx.d.ts +5 -7
  26. package/generated/versions/defold-1.13.0/render.d.ts +12 -18
  27. package/generated/versions/defold-1.13.0/sys.d.ts +8 -10
  28. package/generated/versions/defold-1.13.0/window.d.ts +13 -15
  29. package/generated/versions/defold-1.13.1/b2d_fixture.d.ts +23 -1
  30. package/generated/versions/defold-1.13.1/b2d_shape.d.ts +22 -1
  31. package/generated/versions/defold-1.13.1/compute.d.ts +29 -2
  32. package/generated/versions/defold-1.13.1/go.d.ts +2 -2
  33. package/generated/versions/defold-1.13.1/gui.d.ts +5 -7
  34. package/generated/versions/defold-1.13.1/material.d.ts +98 -8
  35. package/generated/versions/defold-1.13.1/model.d.ts +11 -5
  36. package/generated/versions/defold-1.13.1/particlefx.d.ts +5 -7
  37. package/generated/versions/defold-1.13.1/render.d.ts +12 -18
  38. package/generated/versions/defold-1.13.1/sys.d.ts +8 -10
  39. package/generated/versions/defold-1.13.1/window.d.ts +13 -15
  40. package/generated/window.d.ts +13 -15
  41. package/hsm/async.d.ts +19 -1
  42. package/hsm/debug.d.ts +15 -1
  43. package/hsm/defold.d.ts +21 -1
  44. package/hsm/index.d.ts +222 -94
  45. package/package.json +3 -1
@@ -108,7 +108,16 @@ declare global {
108
108
  * vmath.vector4 | vmath.matrix4 the value(s) of the constant. If the constant is an array, the value will be a table of vmath.vector4 or vmath.matrix4 if the type is `material.CONSTANT_TYPE_USER_MATRIX4`.
109
109
  * @example
110
110
  * ```ts
111
- * const constants = material.get_constants(resource.material("/my_material.materialc"));
111
+ * // Get the shader constants from a material specified as a resource property
112
+ * export default defineScript({
113
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
114
+ * // registration from this field, and only this field types the property onto `self`.
115
+ * properties: { my_material: resource.material() },
116
+ *
117
+ * init(self) {
118
+ * const constants = material.get_constants(self.my_material);
119
+ * },
120
+ * });
112
121
  * ```
113
122
  */
114
123
  function get_constants(path: Hash | string): { name: Hash; type: number; value: Vector4 | Matrix4 }[];
@@ -159,7 +168,16 @@ declare global {
159
168
  * number the max anisotropy of the texture sampler
160
169
  * @example
161
170
  * ```ts
162
- * const samplers = material.get_samplers(resource.material("/my_material.materialc"));
171
+ * // Get the texture samplers from a material specified as a resource property
172
+ * export default defineScript({
173
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
174
+ * // registration from this field, and only this field types the property onto `self`.
175
+ * properties: { my_material: resource.material() },
176
+ *
177
+ * init(self) {
178
+ * const samplers = material.get_samplers(self.my_material);
179
+ * },
180
+ * });
163
181
  * ```
164
182
  */
165
183
  function get_samplers(path: Hash | string): { name: Hash; u_wrap: number; v_wrap: number; min_filter: number; mag_filter: number; max_anisotropy: number }[];
@@ -201,7 +219,16 @@ declare global {
201
219
  * - `graphics.TEXTURE_USAGE_FLAG_COLOR`
202
220
  * @example
203
221
  * ```ts
204
- * const textures = material.get_textures(resource.material("/my_material.materialc"));
222
+ * // Get the textures from a material specified as a resource property
223
+ * export default defineScript({
224
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
225
+ * // registration from this field, and only this field types the property onto `self`.
226
+ * properties: { my_material: resource.material() },
227
+ *
228
+ * init(self) {
229
+ * const textures = material.get_textures(self.my_material);
230
+ * },
231
+ * });
205
232
  * ```
206
233
  */
207
234
  function get_textures(path: Hash | string): { path: Hash; handle: Hash; width: number; height: number; depth: number; mipmaps: number; type: number; flags: number }[];
@@ -253,7 +280,16 @@ declare global {
253
280
  * - `graphics.SEMANTIC_TYPE_MORPH_TARGET_WEIGHTS`
254
281
  * @example
255
282
  * ```ts
256
- * const vertex_attributes = material.get_vertex_attributes(resource.material("/my_material.materialc"));
283
+ * // Get the vertex attributes from a material specified as a resource property
284
+ * export default defineScript({
285
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
286
+ * // registration from this field, and only this field types the property onto `self`.
287
+ * properties: { my_material: resource.material() },
288
+ *
289
+ * init(self) {
290
+ * const vertex_attributes = material.get_vertex_attributes(self.my_material);
291
+ * },
292
+ * });
257
293
  * ```
258
294
  */
259
295
  function get_vertex_attributes(path: Hash | string): { name: Hash; value: Vector4 | Vector3 | Matrix4 | number | number[]; normalize: boolean; data_type: number; coordinate_space: number; semantic_type: number }[];
@@ -288,7 +324,27 @@ declare global {
288
324
  * vmath.vector4 | vmath.vector3 | vmath.matrix4 | number | table the value(s) of the constant. If the shader constant is an array, the amount of values to update depends on how many values that are passed in the 'value' field.
289
325
  * @example
290
326
  * ```ts
291
- * material.set_constants(resource.material("/my_material.materialc"), { tint: { value: vmath.vector4(1, 0, 0, 1) } });
327
+ * // Set a shader constant in a material specified as a resource property
328
+ * export default defineScript({
329
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
330
+ * // registration from this field, and only this field types the property onto `self`.
331
+ * properties: { my_material: resource.material() },
332
+ *
333
+ * init() {
334
+ * return { my_view_proj: vmath.matrix4() };
335
+ * },
336
+ *
337
+ * update(self) {
338
+ * // update the 'tint' constant
339
+ * material.set_constants(self.my_material, {
340
+ * tint: { value: vmath.vector4(1, 0, 0, 1) },
341
+ * });
342
+ * // change the type of the 'view_proj' constant to CONSTANT_TYPE_USER_MATRIX4 so the renderer can set our custom data
343
+ * material.set_constants(self.my_material, {
344
+ * view_proj: { value: self.my_view_proj, type: material.CONSTANT_TYPE_USER_MATRIX4 },
345
+ * });
346
+ * },
347
+ * });
292
348
  * ```
293
349
  */
294
350
  function set_constants(path: Hash | string, constants: Record<string, { type?: number; value?: Vector4 | Vector3 | Matrix4 | number | (Vector4 | Matrix4)[] }>): void;
@@ -337,7 +393,18 @@ declare global {
337
393
  * number the max anisotropy of the texture sampler
338
394
  * @example
339
395
  * ```ts
340
- * material.set_samplers(resource.material("/my_material.materialc"), { texture_sampler: { u_wrap: graphics.TEXTURE_WRAP_REPEAT, v_wrap: graphics.TEXTURE_WRAP_MIRRORED_REPEAT } });
396
+ * // Configures a sampler in a material specified as a resource property
397
+ * export default defineScript({
398
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
399
+ * // registration from this field, and only this field types the property onto `self`.
400
+ * properties: { my_material: resource.material() },
401
+ *
402
+ * init(self) {
403
+ * material.set_samplers(self.my_material, {
404
+ * texture_sampler: { u_wrap: graphics.TEXTURE_WRAP_REPEAT, v_wrap: graphics.TEXTURE_WRAP_MIRRORED_REPEAT },
405
+ * });
406
+ * },
407
+ * });
341
408
  * ```
342
409
  */
343
410
  function set_samplers(path: Hash | string, samplers: Record<string, { u_wrap?: number; v_wrap?: number; min_filter?: number; mag_filter?: number; max_anisotropy?: number }>): void;
@@ -348,7 +415,18 @@ declare global {
348
415
  * @param textures - A table keyed by sampler name with texture resources as values.
349
416
  * @example
350
417
  * ```ts
351
- * material.set_textures(resource.material("/my_material.materialc"), { my_texture: resource.texture() });
418
+ * // Set a texture in a material from a resource
419
+ * export default defineScript({
420
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
421
+ * // registrations from this field, and only this field types them onto `self`.
422
+ * properties: { my_material: resource.material(), my_texture: resource.texture() },
423
+ *
424
+ * init(self) {
425
+ * material.set_textures(self.my_material, {
426
+ * my_texture: self.my_texture,
427
+ * });
428
+ * },
429
+ * });
352
430
  * ```
353
431
  */
354
432
  function set_textures(path: Hash | string, textures: LuaMap<string, Hash> | Record<string, Hash>): void;
@@ -398,7 +476,19 @@ declare global {
398
476
  * - `graphics.SEMANTIC_TYPE_MORPH_TARGET_WEIGHTS`
399
477
  * @example
400
478
  * ```ts
401
- * material.set_vertex_attributes(resource.material("/my_material.materialc"), { tint_attribute: { value: vmath.vector4(1, 0, 0, 1), semantic_type: graphics.SEMANTIC_TYPE_COLOR } });
479
+ * // Configures a vertex attribute in a material specified as a resource property
480
+ * export default defineScript({
481
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
482
+ * // registration from this field, and only this field types the property onto `self`.
483
+ * properties: { my_material: resource.material() },
484
+ *
485
+ * init(self) {
486
+ * material.set_vertex_attributes(self.my_material, {
487
+ * tint_attribute: { value: vmath.vector4(1, 0, 0, 1), semantic_type: graphics.SEMANTIC_TYPE_COLOR },
488
+ * weights: { value: vmath.vector4(0, 1, 0, 0), semantic_type: graphics.SEMANTIC_TYPE_NONE },
489
+ * });
490
+ * },
491
+ * });
402
492
  * ```
403
493
  */
404
494
  function set_vertex_attributes(path: Hash | string, attributes: Record<string, { value?: Vector4 | Vector3 | Matrix4 | number | number[]; normalize?: boolean; data_type?: number; coordinate_space?: number; semantic_type?: number }>): void;
@@ -33,10 +33,14 @@ declare global {
33
33
  * @returns array of weight values, or empty table if the model has no morph targets
34
34
  * @example
35
35
  * ```ts
36
- * const weights = model.get_blend_weights("#model");
37
- * weights[1] = 0.75;
38
- * weights[2] = 0.25;
39
- * model.set_blend_weights("#model", weights);
36
+ * const w = model.get_blend_weights("#model");
37
+ * w.forEach((weight, i) => {
38
+ * print(i + 1, weight);
39
+ * });
40
+ * // change the data in the table and then set the weights again
41
+ * w[0] = 0.75;
42
+ * w[1] = 0.25;
43
+ * model.set_blend_weights("#model", w);
40
44
  * ```
41
45
  */
42
46
  function get_blend_weights(url: string | Hash | Url): number[];
@@ -197,8 +201,10 @@ declare global {
197
201
  * @param weights - array of weight values (1-based indices). Omit or pass `nil` to clear the override and return morphs to animation only
198
202
  * @example
199
203
  * ```ts
204
+ * // set the weights for the first 4 morph targets
200
205
  * model.set_blend_weights("#model", [0, 1, 0.5, 0]);
201
- * model.set_blend_weights("#model");
206
+ * // clear the override, animation will continue if the weights are driven by an animation
207
+ * model.set_blend_weights("#model"); // clear script override
202
208
  * ```
203
209
  */
204
210
  function set_blend_weights(url: string | Hash | Url, weights?: number[]): void;
@@ -50,15 +50,13 @@ declare global {
50
50
  * // How to play a particle fx when a game object is created.
51
51
  * // The callback receives the hash of the path to the particlefx, the hash of the id
52
52
  * // of the emitter, and the new state of the emitter as particlefx.EMITTER_STATE_.
53
- * function emitter_state_change(self: unknown, id: unknown, emitter: unknown, state: unknown) {
54
- * if (emitter === hash("exhaust") && state === particlefx.EMITTER_STATE_POSTSPAWN) {
55
- * // exhaust is done spawning particles...
56
- * }
57
- * }
58
- *
59
53
  * export default defineScript({
60
54
  * init(self) {
61
- * particlefx.play("#particlefx", emitter_state_change);
55
+ * particlefx.play("#particlefx", (self, id, emitter, state) => {
56
+ * if (emitter === hash("exhaust") && state === particlefx.EMITTER_STATE_POSTSPAWN) {
57
+ * // exhaust is done spawning particles...
58
+ * }
59
+ * });
62
60
  * },
63
61
  * });
64
62
  * ```
@@ -70,11 +70,16 @@ declare global {
70
70
  * @example
71
71
  * Then use the constant buffer when drawing a predicate:
72
72
  * ```ts
73
- * function draw_tinted(self: { my_pred: Opaque<"render_predicate"> }) {
74
- * const constants = render.constant_buffer();
75
- * constants.tint = vmath.vector4(1, 1, 1, 1);
76
- * render.draw(self.my_pred, { constants });
77
- * }
73
+ * export default defineRenderScript({
74
+ * init() {
75
+ * return { my_pred: render.predicate([hash("my_tag")]) };
76
+ * },
77
+ *
78
+ * update(self, dt) {
79
+ * const constants = render.constant_buffer();
80
+ * render.draw(self.my_pred, { constants });
81
+ * },
82
+ * });
78
83
  * ```
79
84
  * @example
80
85
  * The constant buffer also supports array values by specifying constants in a table:
@@ -449,13 +454,13 @@ declare global {
449
454
  * ```
450
455
  * @example
451
456
  * ```ts
452
- * // Or enable a render target by resource id:
453
457
  * export default defineRenderScript({
454
458
  * init() {
455
459
  * return { my_pred: render.predicate([hash("my_tag")]) };
456
460
  * },
457
461
  *
458
462
  * update(self, dt) {
463
+ * // enable render target by resource id
459
464
  * render.set_render_target("my_rt_resource");
460
465
  * render.draw(self.my_pred);
461
466
  * render.set_render_target(render.RENDER_TARGET_DEFAULT);
@@ -469,7 +474,6 @@ declare global {
469
474
  * ```
470
475
  * @example
471
476
  * ```ts
472
- * // Or bind a texture handle directly:
473
477
  * export default defineRenderScript({
474
478
  * init() {
475
479
  * return { my_texture_handle: resource.get_texture_info("/main/my_texture.texturec").handle };
@@ -512,15 +516,10 @@ declare global {
512
516
  * ```ts
513
517
  * export default defineRenderScript({
514
518
  * init() {
515
- * // render target buffer parameters
516
519
  * const color_params = {
517
520
  * format: graphics.TEXTURE_FORMAT_RGBA,
518
521
  * width: render.get_window_width(),
519
522
  * height: render.get_window_height(),
520
- * min_filter: graphics.TEXTURE_FILTER_LINEAR,
521
- * mag_filter: graphics.TEXTURE_FILTER_LINEAR,
522
- * u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,
523
- * v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,
524
523
  * };
525
524
  * return {
526
525
  * target_right: render.render_target("right", {
@@ -554,15 +553,10 @@ declare global {
554
553
  * ```ts
555
554
  * export default defineRenderScript({
556
555
  * init() {
557
- * // render target buffer parameters
558
556
  * const color_params = {
559
557
  * format: graphics.TEXTURE_FORMAT_RGBA,
560
558
  * width: render.get_window_width(),
561
559
  * height: render.get_window_height(),
562
- * min_filter: graphics.TEXTURE_FILTER_LINEAR,
563
- * mag_filter: graphics.TEXTURE_FILTER_LINEAR,
564
- * u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,
565
- * v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,
566
560
  * };
567
561
  * return {
568
562
  * target_right: render.render_target("right", {
@@ -1003,13 +997,13 @@ declare global {
1003
997
  * ```
1004
998
  * @example
1005
999
  * ```ts
1006
- * // Or set the render target by a render target resource identifier:
1007
1000
  * export default defineRenderScript({
1008
1001
  * init() {
1009
1002
  * return { my_pred: render.predicate([hash("my_tag")]) };
1010
1003
  * },
1011
1004
  *
1012
1005
  * update(self, dt) {
1006
+ * // set render target by a render target resource identifier
1013
1007
  * render.set_render_target("my_rt_resource");
1014
1008
  *
1015
1009
  * // draw a predicate to the render target
@@ -605,22 +605,20 @@ declare global {
605
605
  * string The stack traceback.
606
606
  * @example
607
607
  * ```ts
608
- * // Install error handler that just prints the errors
609
- * function my_error_handler(source: unknown, message: unknown, traceback: unknown) {
610
- * print(source); //> lua
611
- * print(message); //> main/my.script:10: attempt to perform arithmetic on a string value
612
- * print(traceback); //> stack traceback:
613
- * //> main/test.script:10: in function 'boom'
614
- * //> main/test.script:15: in function <main/my.script:13>
615
- * }
616
- *
617
608
  * function boom() {
618
609
  * return 10 + "string";
619
610
  * }
620
611
  *
621
612
  * export default defineScript({
622
613
  * init() {
623
- * sys.set_error_handler(my_error_handler);
614
+ * // Install error handler that just prints the errors
615
+ * sys.set_error_handler((source, message, traceback) => {
616
+ * print(source); //> lua
617
+ * print(message); //> main/my.script:10: attempt to perform arithmetic on a string value
618
+ * print(traceback); //> stack traceback:
619
+ * //> main/test.script:10: in function 'boom'
620
+ * //> main/test.script:15: in function <main/my.script:13>
621
+ * });
624
622
  * boom();
625
623
  * },
626
624
  * });
@@ -127,23 +127,21 @@ declare global {
127
127
  * - number `height`: The height of a resize event. nil otherwise.
128
128
  * @example
129
129
  * ```ts
130
- * function window_callback(self: unknown, event: unknown, data: Record<string | number, unknown>) {
131
- * if (event === window.WINDOW_EVENT_FOCUS_LOST) {
132
- * print("window.WINDOW_EVENT_FOCUS_LOST");
133
- * } else if (event === window.WINDOW_EVENT_FOCUS_GAINED) {
134
- * print("window.WINDOW_EVENT_FOCUS_GAINED");
135
- * } else if (event === window.WINDOW_EVENT_ICONFIED) {
136
- * print("window.WINDOW_EVENT_ICONFIED");
137
- * } else if (event === window.WINDOW_EVENT_DEICONIFIED) {
138
- * print("window.WINDOW_EVENT_DEICONIFIED");
139
- * } else if (event === window.WINDOW_EVENT_RESIZED) {
140
- * print("Window resized: ", data.width, data.height);
141
- * }
142
- * }
143
- *
144
130
  * export default defineScript({
145
131
  * init() {
146
- * window.set_listener(window_callback);
132
+ * window.set_listener((self, event, data) => {
133
+ * if (event === window.WINDOW_EVENT_FOCUS_LOST) {
134
+ * print("window.WINDOW_EVENT_FOCUS_LOST");
135
+ * } else if (event === window.WINDOW_EVENT_FOCUS_GAINED) {
136
+ * print("window.WINDOW_EVENT_FOCUS_GAINED");
137
+ * } else if (event === window.WINDOW_EVENT_ICONFIED) {
138
+ * print("window.WINDOW_EVENT_ICONFIED");
139
+ * } else if (event === window.WINDOW_EVENT_DEICONIFIED) {
140
+ * print("window.WINDOW_EVENT_DEICONIFIED");
141
+ * } else if (event === window.WINDOW_EVENT_RESIZED) {
142
+ * print("Window resized: ", data.width, data.height);
143
+ * }
144
+ * });
147
145
  * },
148
146
  * });
149
147
  * ```
@@ -142,23 +142,21 @@ declare global {
142
142
  * @param callback - A callback which receives info about window events. Pass an empty function or `nil` if you no longer wish to receive callbacks.
143
143
  * @example
144
144
  * ```ts
145
- * function window_callback(self: unknown, event: unknown, data: Record<string | number, unknown>) {
146
- * if (event === window.WINDOW_EVENT_FOCUS_LOST) {
147
- * print("window.WINDOW_EVENT_FOCUS_LOST");
148
- * } else if (event === window.WINDOW_EVENT_FOCUS_GAINED) {
149
- * print("window.WINDOW_EVENT_FOCUS_GAINED");
150
- * } else if (event === window.WINDOW_EVENT_ICONIFIED) {
151
- * print("window.WINDOW_EVENT_ICONIFIED");
152
- * } else if (event === window.WINDOW_EVENT_DEICONIFIED) {
153
- * print("window.WINDOW_EVENT_DEICONIFIED");
154
- * } else if (event === window.WINDOW_EVENT_RESIZED) {
155
- * print("Window resized: ", data.width, data.height);
156
- * }
157
- * }
158
- *
159
145
  * export default defineScript({
160
146
  * init() {
161
- * window.set_listener(window_callback);
147
+ * window.set_listener((self, event, data) => {
148
+ * if (event === window.WINDOW_EVENT_FOCUS_LOST) {
149
+ * print("window.WINDOW_EVENT_FOCUS_LOST");
150
+ * } else if (event === window.WINDOW_EVENT_FOCUS_GAINED) {
151
+ * print("window.WINDOW_EVENT_FOCUS_GAINED");
152
+ * } else if (event === window.WINDOW_EVENT_ICONIFIED) {
153
+ * print("window.WINDOW_EVENT_ICONIFIED");
154
+ * } else if (event === window.WINDOW_EVENT_DEICONIFIED) {
155
+ * print("window.WINDOW_EVENT_DEICONIFIED");
156
+ * } else if (event === window.WINDOW_EVENT_RESIZED) {
157
+ * print("Window resized: ", data.width, data.height);
158
+ * }
159
+ * });
162
160
  * },
163
161
  * });
164
162
  * ```
package/hsm/async.d.ts CHANGED
@@ -1,8 +1,26 @@
1
1
  // Generated from packages/hsm/src/async.ts by `bun run --cwd packages/hsm declarations`; do not edit.
2
2
  import type { EventObject, TaskStart } from "./index";
3
- /** @noSelf */
3
+ /**
4
+ * The second argument of a `sequence` function: a wait that leaving the state cancels, and a flag
5
+ * that tells the state was left.
6
+ * @noSelf
7
+ */
4
8
  export interface SequenceSignal {
9
+ /**
10
+ * Turns `true` once the state is left. Check it after awaiting anything other than `wait`: such
11
+ * a promise can still resolve after the state is left, and the code after it then runs.
12
+ */
5
13
  readonly aborted: boolean;
14
+ /**
15
+ * Resolves after `seconds`, counted by `timer.delay` rather than by `update(dt)`. A wait still
16
+ * pending when the state is left never resolves, so the code after it does not run.
17
+ */
6
18
  readonly wait: (seconds: number) => Promise<void>;
7
19
  }
20
+ /**
21
+ * Turns an `async` function into a state's `task`. The function gets the context and a
22
+ * `SequenceSignal`, and the event it returns is sent to the machine; one returned after the state
23
+ * is left is ignored. An error thrown inside it leaves the machine where it is and is raised
24
+ * again from a timer callback, so it shows in the engine console.
25
+ */
8
26
  export declare function sequence<Ctx, E extends EventObject>(run: (ctx: Ctx, signal: SequenceSignal) => Promise<NoInfer<E> | void>): TaskStart<Ctx, E>;
package/hsm/debug.d.ts CHANGED
@@ -1,7 +1,21 @@
1
1
  // Generated from packages/hsm/src/debug.ts by `bun run --cwd packages/hsm declarations`; do not edit.
2
2
  import type { EventObject, MachineInstance } from "./index";
3
- /** @noSelf */
3
+ /**
4
+ * Returned by `inspect`. Keep it on `self` and call its `draw` from `update`.
5
+ * @noSelf
6
+ */
4
7
  export interface MachineInspector {
8
+ /**
9
+ * Draws the label and the active leaves as debug text, 40 units above `target`'s world
10
+ * position. Each call also advances the frame number the console lines show. In a release
11
+ * build it does nothing.
12
+ */
5
13
  readonly draw: (target: Hash | Url | string) => void;
6
14
  }
15
+ /**
16
+ * Prints one line when it is called, then one line for each move `instance` makes, each starting
17
+ * with `hsm` and the label. Call it once after `start`. A label another `inspect` call already
18
+ * used gets an ordinal, such as `enemy#2`. In a release build it registers nothing and returns an
19
+ * inspector whose `draw` does nothing, so the calls can stay in shipped code.
20
+ */
7
21
  export declare function inspect<Ctx, E extends EventObject, P extends string>(instance: MachineInstance<Ctx, E, P>, label: string): MachineInspector;
package/hsm/defold.d.ts CHANGED
@@ -1,10 +1,30 @@
1
1
  // Generated from packages/hsm/src/defold.ts by `bun run --cwd packages/hsm declarations`; do not edit.
2
+ /**
3
+ * The event `messageEvents` builds from the Defold message `K`, for a machine's event union. It
4
+ * holds the message id as `type`, the payload fields declared through `BuiltinMessages` and
5
+ * `CustomMessages`, and the `sender`.
6
+ */
2
7
  export type MessageEvent<K extends MessageId> = K extends MessageId ? {
8
+ /** The message id. A payload field named `type` never overrides it. */
3
9
  readonly type: K;
10
+ /** The URL the message came from. A payload field named `sender` never overrides it. */
4
11
  readonly sender: Url;
5
12
  } & Omit<MessagePayload<K>, "type" | "sender"> : never;
6
- /** @noSelf */
13
+ /**
14
+ * Returned by `messageEvents`. Build it once at module scope: it hashes the ids when it is
15
+ * created.
16
+ * @noSelf
17
+ */
7
18
  export interface MessageEventMapper<K extends MessageId> {
19
+ /**
20
+ * Turns the parameters of `on_message` into the event for that message, a new table on each
21
+ * call. Returns `undefined` for a message id that `messageEvents` was not given.
22
+ */
8
23
  readonly toEvent: (message_id: Hash, message: Record<string | number, unknown>, sender: Url) => MessageEvent<K> | undefined;
9
24
  }
25
+ /**
26
+ * Builds a mapper that turns the Defold messages listed in `ids` into typed machine events of
27
+ * the shape `{ type: id, ...payload, sender }`. Call it once at module scope: the ids are hashed
28
+ * here.
29
+ */
10
30
  export declare function messageEvents<const K extends MessageId>(ids: readonly K[]): MessageEventMapper<K>;