@defold-typescript/types 0.44.1 → 0.45.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 (42) 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/index.d.ts +69 -90
  42. 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/index.d.ts CHANGED
@@ -23,13 +23,18 @@ export interface MachineInstance<Ctx, E extends EventObject, P extends string =
23
23
  readonly onMove: (listener: MoveListener<E, P>) => () => void;
24
24
  }
25
25
  export type MoveAction<Ctx, E extends EventObject, V extends E = E> = (ctx: Ctx, event: V, machine: MachineInstance<Ctx, E>) => void;
26
+ interface RuleList<Rule> {
27
+ readonly 0: Rule;
28
+ readonly [index: number]: Rule;
29
+ readonly length: number;
30
+ }
26
31
  /** @noSelf */
27
- export interface TransitionConfig<Ctx, E extends EventObject, V extends E = E> {
32
+ export interface TransitionConfig<Ctx, E extends EventObject, V extends E = E, To extends string = string> {
28
33
  /**
29
34
  * The full path of the state to move to. A `to` naming the state the rule is on exits and
30
35
  * re-enters it, restarting its timers and `task`; a `to` below it keeps it active.
31
36
  */
32
- readonly to?: string;
37
+ readonly to?: To;
33
38
  /**
34
39
  * The rule is taken only when this returns `true`. It must have no side effects: it is also
35
40
  * checked when the move does not happen, in guarded lists and on every `always` recheck.
@@ -51,10 +56,10 @@ export interface TransitionConfig<Ctx, E extends EventObject, V extends E = E> {
51
56
  /** Removed: a `to` naming the state the rule is on restarts it. */
52
57
  readonly reenter?: never;
53
58
  }
54
- export type TransitionSpec<Ctx, E extends EventObject, V extends E = E> = string | TransitionConfig<Ctx, E, V> | readonly [TransitionConfig<Ctx, E, V>, ...TransitionConfig<Ctx, E, V>[]];
59
+ export type TransitionSpec<Ctx, E extends EventObject, V extends E = E, To extends string = string> = To | TransitionConfig<Ctx, E, V, To> | RuleList<TransitionConfig<Ctx, E, V, To>>;
55
60
  /** @noSelf */
56
- export interface AlwaysConfig<Ctx> {
57
- readonly to: string;
61
+ export interface AlwaysConfig<Ctx, To extends string = string> {
62
+ readonly to: To;
58
63
  /** Checked on every recheck, so it must have no side effects. */
59
64
  readonly when?: (ctx: Ctx) => boolean;
60
65
  /** Renamed to `to`. */
@@ -62,11 +67,11 @@ export interface AlwaysConfig<Ctx> {
62
67
  /** Renamed to `when`. */
63
68
  readonly guard?: never;
64
69
  }
65
- export type AlwaysSpec<Ctx> = string | AlwaysConfig<Ctx> | readonly [AlwaysConfig<Ctx>, ...AlwaysConfig<Ctx>[]];
66
- export type OnConfig<Ctx, E extends EventObject> = {
70
+ export type AlwaysSpec<Ctx, To extends string = string> = To | AlwaysConfig<Ctx, To> | RuleList<AlwaysConfig<Ctx, To>>;
71
+ export type OnConfig<Ctx, E extends EventObject, To extends string = string> = {
67
72
  readonly [K in E["type"]]?: TransitionSpec<Ctx, E, Extract<E, {
68
73
  type: K;
69
- }>>;
74
+ }>, To>;
70
75
  };
71
76
  /**
72
77
  * Runs on every way in (`enter`) or out (`exit`) of the state: a move, `start` and `stop`. A hot
@@ -74,7 +79,7 @@ export type OnConfig<Ctx, E extends EventObject> = {
74
79
  * event; event data reaches `enter` through `ctx`, set in `run`.
75
80
  */
76
81
  export type StateHook<Ctx, E extends EventObject> = (ctx: Ctx, machine: MachineInstance<Ctx, E>) => void;
77
- export type UpdateHook<Ctx, E extends EventObject> = (ctx: Ctx, dt: number, machine: MachineInstance<Ctx, E>) => string | undefined;
82
+ export type UpdateHook<Ctx, E extends EventObject, To extends string = string> = (ctx: Ctx, dt: number, machine: MachineInstance<Ctx, E>) => To | undefined;
78
83
  /**
79
84
  * Starts work that lives as long as the state. `finish` sends one event and is ignored after the
80
85
  * first call or once the state is left. The returned cleanup runs on every way out.
@@ -82,98 +87,72 @@ export type UpdateHook<Ctx, E extends EventObject> = (ctx: Ctx, dt: number, mach
82
87
  */
83
88
  export type TaskStart<Ctx, E extends EventObject> = (ctx: Ctx, finish: (event: E) => void, machine: MachineInstance<Ctx, E>) => (() => void) | void;
84
89
  /** @noSelf */
85
- export interface StateConfig<Ctx, E extends EventObject> {
86
- readonly type?: "parallel";
87
- readonly initial?: string;
88
- readonly restoreDepth?: number | "all";
90
+ export interface Machine<Ctx, E extends EventObject, P extends string = string> {
91
+ readonly start: (ctx: Ctx) => MachineInstance<Ctx, E, P>;
92
+ }
93
+ type PathDepth = [never, 0, 1, 2, 3];
94
+ type NextCount = [never, 2, 3, 4, 5, 6];
95
+ type TreePathsBelow<T, D extends number> = {
96
+ [K in keyof T & string]: K | `${K}/${D extends 1 ? keyof T[K] extends never ? never : string : TreePathsBelow<T[K], PathDepth[D]>}`;
97
+ }[keyof T & string];
98
+ type TreePath<T> = `/${TreePathsBelow<T, 4>}`;
99
+ type SlotPathsBelow<T, D extends number> = unknown extends T ? string : {
100
+ [K in keyof T & string]: K | `${K}/${D extends 1 ? string : SlotPathsBelow<T[K], PathDepth[D]>}`;
101
+ }[keyof T & string];
102
+ type SlotPath<T> = `/${SlotPathsBelow<T, 4>}`;
103
+ type TreeOf<C> = C extends {
104
+ readonly states: infer Children;
105
+ } ? {
106
+ readonly [K in keyof Children]: TreeOf<Children[K]>;
107
+ } : unknown;
108
+ export type StatePath<C> = TreePath<TreeOf<C>>;
109
+ type TreeDepth<T, D extends number> = unknown extends T ? number : [D] extends [never] ? number : 1 | ({
110
+ [K in keyof T]: unknown extends T[K] ? never : TreeDepth<T[K], PathDepth[D]>;
111
+ }[keyof T] extends infer N ? N extends number ? number extends N ? number : NextCount[N] : never : never);
112
+ type AnyChild<Ctx, E extends EventObject, T, To extends string> = unknown extends T ? {
113
+ readonly [name: string]: StateNode<Ctx, E, unknown, string, To>;
114
+ } : unknown;
115
+ /** @noSelf */
116
+ interface StateBase<Ctx, E extends EventObject, T, Self extends string, To extends string> {
89
117
  readonly states?: {
90
- readonly [name: string]: StateConfig<Ctx, E>;
91
- };
92
- readonly on?: OnConfig<Ctx, E>;
93
- readonly after?: {
94
- readonly [seconds: number]: string;
95
- };
96
- readonly always?: AlwaysSpec<Ctx>;
118
+ readonly [K in keyof T]: StateNode<Ctx, E, T[K], `${Self}/${K & string}`, To>;
119
+ } & NoInfer<AnyChild<Ctx, E, T, To>>;
120
+ readonly on?: NoInfer<OnConfig<Ctx, E, To>>;
121
+ readonly after?: NoInfer<{
122
+ readonly [seconds: number]: To;
123
+ }>;
124
+ readonly always?: AlwaysSpec<Ctx, To>;
97
125
  readonly enter?: StateHook<Ctx, E>;
98
126
  readonly exit?: StateHook<Ctx, E>;
99
- readonly update?: UpdateHook<Ctx, E>;
127
+ readonly update?: NoInfer<UpdateHook<Ctx, E, To>>;
100
128
  /** Started on each entry; see `TaskStart`. */
101
129
  readonly task?: TaskStart<Ctx, E>;
102
130
  /** Renamed to `task`. */
103
131
  readonly invoke?: never;
104
132
  }
105
- export interface MachineConfig<Ctx, E extends EventObject> extends StateConfig<Ctx, E> {
106
- readonly initial: string;
107
- readonly states: {
108
- readonly [name: string]: StateConfig<Ctx, E>;
109
- };
110
- }
111
133
  /** @noSelf */
112
- export interface Machine<Ctx, E extends EventObject, P extends string = string> {
113
- readonly start: (ctx: Ctx) => MachineInstance<Ctx, E, P>;
134
+ interface CompoundState<Ctx, E extends EventObject, T, Self extends string, To extends string> extends StateBase<Ctx, E, T, Self, To> {
135
+ readonly type?: never;
136
+ readonly initial?: NoInfer<unknown extends T ? string : `${Self}/${keyof T & string}`>;
137
+ readonly restoreDepth?: NoInfer<TreeDepth<T, 4> | "all">;
114
138
  }
115
- type PathDepth = [never, 0, 1, 2, 3];
116
- type PathsBelow<S, D extends number> = S extends {
117
- readonly states: infer Children;
118
- } ? {
119
- [K in keyof Children & string]: K | `${K}/${D extends 1 ? Children[K] extends {
120
- readonly states: object;
121
- } ? string : never : PathsBelow<Children[K], PathDepth[D]>}`;
122
- }[keyof Children & string] : never;
123
- export type StatePath<C> = `/${PathsBelow<C, 4>}`;
124
- type NextCount = [never, 2, 3, 4, 5, 6];
125
- type RestoreCountBelow<Children, D extends number> = {
126
- [K in keyof Children]: RestoreCount<Children[K], D>;
127
- }[keyof Children];
128
- type RestoreCount<S, D extends number> = S extends {
129
- readonly states: infer Children;
130
- } ? [D] extends [never] ? number : S extends {
139
+ /** @noSelf */
140
+ interface ParallelState<Ctx, E extends EventObject, T, Self extends string, To extends string> extends StateBase<Ctx, E, T, Self, To> {
131
141
  readonly type: "parallel";
132
- } ? RestoreCountBelow<Children, PathDepth[D]> : 1 | (RestoreCountBelow<Children, PathDepth[D]> extends infer N ? N extends number ? number extends N ? number : NextCount[N] : never : never) : never;
133
- interface TransitionCheck<T> {
134
- readonly to?: T;
135
- readonly when?: unknown;
136
- readonly run?: unknown;
142
+ readonly initial?: never;
143
+ readonly restoreDepth?: never;
137
144
  }
138
- type SpecCheck<T> = T | TransitionCheck<T> | readonly TransitionCheck<T>[];
139
- type PathCheck<S, Self extends string, All extends string, Ev extends string> = {
140
- readonly type?: unknown;
141
- readonly initial?: S extends {
142
- readonly type: "parallel";
143
- } ? never : S extends {
144
- readonly states: infer Children;
145
- } ? `${Self}/${keyof Children & string}` : never;
146
- readonly restoreDepth?: S extends {
147
- readonly type: "parallel";
148
- } ? never : S extends {
149
- readonly states: object;
150
- } ? RestoreCount<S, 4> | "all" : never;
151
- readonly states?: S extends {
152
- readonly states: infer Children;
153
- } ? {
154
- readonly [K in keyof Children]: PathCheck<Children[K], `${Self}/${K & string}`, All, Ev>;
155
- } : unknown;
156
- readonly on?: S extends {
157
- readonly on: infer On;
158
- } ? {
159
- readonly [K in keyof On]: K extends Ev ? SpecCheck<All> : never;
160
- } : unknown;
161
- readonly after?: S extends {
162
- readonly after: infer After;
163
- } ? {
164
- readonly [K in keyof After]: All;
165
- } : unknown;
166
- readonly always?: S extends {
167
- readonly always: unknown;
168
- } ? SpecCheck<All> : unknown;
169
- readonly enter?: unknown;
170
- readonly exit?: unknown;
171
- readonly update?: unknown;
172
- readonly task?: unknown;
145
+ type StateNode<Ctx, E extends EventObject, T, Self extends string, To extends string> = CompoundState<Ctx, E, T, Self, To> | ParallelState<Ctx, E, T, Self, To>;
146
+ type RootState<Ctx, E extends EventObject, T> = CompoundState<Ctx, E, T, "", NoInfer<SlotPath<T>>> & {
147
+ readonly initial: string;
148
+ readonly states: object;
173
149
  };
174
- export interface MachineConfigError {
175
- readonly "hsm: an initial or a to names an unknown state path, or an on key an unknown event": never;
176
- }
177
- export type DefinedMachine<Ctx, E extends EventObject, C> = C extends PathCheck<C, "", StatePath<C>, E["type"]> ? Machine<Ctx, E, StatePath<C>> : MachineConfigError;
178
- export declare function defineMachine<Ctx, E extends EventObject>(key?: string): <const C extends MachineConfig<Ctx, E>>(config: C) => DefinedMachine<Ctx, E, C>;
150
+ export type StateConfig<Ctx, E extends EventObject> = StateNode<Ctx, E, unknown, string, string>;
151
+ export type MachineConfig<Ctx, E extends EventObject> = CompoundState<Ctx, E, unknown, string, string> & {
152
+ readonly initial: string;
153
+ readonly states: {
154
+ readonly [name: string]: StateConfig<Ctx, E>;
155
+ };
156
+ };
157
+ export declare function defineMachine<Ctx, E extends EventObject>(key?: string): <T>(config: RootState<Ctx, E, T>) => Machine<Ctx, E, TreePath<T>>;
179
158
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defold-typescript/types",
3
- "version": "0.44.1",
3
+ "version": "0.45.0",
4
4
  "description": "TypeScript types for the Defold engine's Lua APIs.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -85,7 +85,9 @@
85
85
  "!scripts/lua-types-signature-index.ts",
86
86
  "!scripts/fidelity-audit.ts",
87
87
  "!scripts/augmentation-namespaces.ts",
88
+ "!scripts/example-loose-types.ts",
88
89
  "!scripts/example-pins.ts",
90
+ "!scripts/example-scope-parity.ts",
89
91
  "!scripts/example-semantics.ts",
90
92
  "!scripts/example-surfaces.ts",
91
93
  "!scripts/example-typecheck.ts",