@defold-typescript/types 0.5.4 → 0.6.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 (59) hide show
  1. package/api-targets.json +1 -1
  2. package/generated/b2d.d.ts +3 -0
  3. package/generated/buffer.d.ts +44 -38
  4. package/generated/builtin-messages.d.ts +1 -1
  5. package/generated/camera.d.ts +3 -0
  6. package/generated/collectionfactory.d.ts +47 -40
  7. package/generated/collectionproxy.d.ts +23 -18
  8. package/generated/crash.d.ts +3 -0
  9. package/generated/factory.d.ts +32 -24
  10. package/generated/go.d.ts +293 -293
  11. package/generated/graphics.d.ts +3 -0
  12. package/generated/gui.d.ts +303 -283
  13. package/generated/http.d.ts +26 -16
  14. package/generated/iac.d.ts +3 -0
  15. package/generated/iap.d.ts +6 -3
  16. package/generated/image.d.ts +30 -26
  17. package/generated/json.d.ts +36 -32
  18. package/generated/kinds/gui-script.d.ts +7 -5
  19. package/generated/kinds/render-script.d.ts +7 -5
  20. package/generated/kinds/script.d.ts +7 -5
  21. package/generated/label.d.ts +16 -9
  22. package/generated/liveupdate.d.ts +29 -26
  23. package/generated/model.d.ts +57 -45
  24. package/generated/msg.d.ts +12 -9
  25. package/generated/particlefx.d.ts +50 -34
  26. package/generated/physics.d.ts +153 -133
  27. package/generated/profiler.d.ts +45 -41
  28. package/generated/push.d.ts +5 -2
  29. package/generated/render.d.ts +410 -349
  30. package/generated/resource.d.ts +619 -572
  31. package/generated/socket.d.ts +49 -33
  32. package/generated/sound.d.ts +83 -72
  33. package/generated/sprite.d.ts +36 -32
  34. package/generated/sys.d.ts +198 -189
  35. package/generated/tilemap.d.ts +43 -39
  36. package/generated/timer.d.ts +42 -36
  37. package/generated/vmath.d.ts +254 -229
  38. package/generated/webview.d.ts +3 -0
  39. package/generated/window.d.ts +23 -17
  40. package/generated/zlib.d.ts +15 -12
  41. package/index.d.ts +3 -1
  42. package/package.json +6 -2
  43. package/scripts/example-store-io.ts +18 -0
  44. package/scripts/fidelity-audit.ts +61 -1
  45. package/scripts/fidelity-baseline.json +10 -10
  46. package/scripts/ref-doc-delta.ts +143 -0
  47. package/scripts/regen.ts +23 -10
  48. package/src/core-types.ts +14 -0
  49. package/src/doc-comment.ts +2 -1
  50. package/src/emit-dts.ts +238 -18
  51. package/src/engine-globals.d.ts +2 -0
  52. package/src/example-store.ts +44 -0
  53. package/src/go-overloads.d.ts +73 -0
  54. package/src/index.ts +5 -0
  55. package/src/lifecycle.ts +157 -16
  56. package/src/message-dispatch.d.ts +21 -0
  57. package/src/message-guard.d.ts +19 -0
  58. package/src/msg-overloads.d.ts +20 -0
  59. package/src/publish-dts.ts +1 -1
@@ -2,6 +2,9 @@
2
2
  import type { Hash, Url } from "../src/core-types";
3
3
 
4
4
  declare global {
5
+ /**
6
+ * Functions for passing messages and constructing URL objects.
7
+ */
5
8
  namespace msg {
6
9
  /**
7
10
  * This is equivalent to `msg.url(nil)` or `msg.url("#")`, which creates an url to the current
@@ -49,16 +52,16 @@ declare global {
49
52
  * @param fragment - fragment of the URL
50
53
  * @returns a new URL
51
54
  * @example
52
- * ```lua
53
- * local my_socket = "main" -- specify by valid name
54
- * local my_path = hash("/my_collection/my_gameobject") -- specify as string or hash
55
- * local my_fragment = "component" -- specify as string or hash
56
- * local my_url = msg.url(my_socket, my_path, my_fragment)
55
+ * ```ts
56
+ * const my_socket = "main"; // specify by valid name
57
+ * const my_path = hash("/my_collection/my_gameobject"); // specify as string or hash
58
+ * const my_fragment = "component"; // specify as string or hash
59
+ * const my_url = msg.url(my_socket, my_path, my_fragment);
57
60
  *
58
- * print(my_url) --> url: [main:/my_collection/my_gameobject#component]
59
- * print(my_url.socket) --> 786443 (internal numeric value)
60
- * print(my_url.path) --> hash: [/my_collection/my_gameobject]
61
- * print(my_url.fragment) --> hash: [component]
61
+ * print(my_url); // => url: [main:/my_collection/my_gameobject#component]
62
+ * print(my_url.socket); // => 786443 (internal numeric value)
63
+ * print(my_url.path); // => hash: [/my_collection/my_gameobject]
64
+ * print(my_url.fragment); // => hash: [component]
62
65
  * ```
63
66
  */
64
67
  function url(socket?: string | Hash, path?: string | Hash, fragment?: string | Hash): Url;
@@ -2,6 +2,10 @@
2
2
  import type { Hash, Url, Vector4 } from "../src/core-types";
3
3
 
4
4
  declare global {
5
+ /**
6
+ * Functions and properties for controlling particle effect component playback and
7
+ * shader constants.
8
+ */
5
9
  namespace particlefx {
6
10
  /**
7
11
  * The emitter is not spawning any particles, but has particles that are still alive.
@@ -40,19 +44,21 @@ declare global {
40
44
  * - `particlefx.EMITTER_STATE_SPAWNING`
41
45
  * - `particlefx.EMITTER_STATE_POSTSPAWN`
42
46
  * @example
43
- * ```lua
44
- * How to play a particle fx when a game object is created.
45
- * The callback receives the hash of the path to the particlefx, the hash of the id
46
- * of the emitter, and the new state of the emitter as particlefx.EMITTER_STATE_.
47
- * local function emitter_state_change(self, id, emitter, state)
48
- * if emitter == hash("exhaust") and state == particlefx.EMITTER_STATE_POSTSPAWN then
49
- * -- exhaust is done spawning particles...
50
- * end
51
- * end
47
+ * ```ts
48
+ * // How to play a particle fx when a game object is created.
49
+ * // The callback receives the hash of the path to the particlefx, the hash of the id
50
+ * // of the emitter, and the new state of the emitter as particlefx.EMITTER_STATE_.
51
+ * function emitter_state_change(self, id, emitter, state) {
52
+ * if (emitter === hash("exhaust") && state === particlefx.EMITTER_STATE_POSTSPAWN) {
53
+ * // exhaust is done spawning particles...
54
+ * }
55
+ * }
52
56
  *
53
- * function init(self)
54
- * particlefx.play("#particlefx", emitter_state_change)
55
- * end
57
+ * export default defineScript({
58
+ * init(self) {
59
+ * particlefx.play("#particlefx", emitter_state_change);
60
+ * },
61
+ * });
56
62
  * ```
57
63
  */
58
64
  function play(url: string | Hash | Url, emitter_state_function?: (self: unknown, id: unknown, emitter: unknown, state: unknown) => void): void;
@@ -66,14 +72,18 @@ declare global {
66
72
  * @param emitter - the id of the emitter
67
73
  * @param constant - the name of the constant
68
74
  * @example
69
- * ```lua
70
- * The following examples assumes that the particle FX has id "particlefx", it
71
- * contains an emitter with the id "emitter" and that the default-material in builtins is used, which defines the constant "tint".
72
- * If you assign a custom material to the sprite, you can reset the constants defined there in the same manner.
73
- * How to reset the tinting of particles from an emitter:
74
- * function init(self)
75
- * particlefx.reset_constant("#particlefx", "emitter", "tint")
76
- * end
75
+ * ```ts
76
+ * // The following examples assume that the particle FX has id "particlefx", it
77
+ * // contains an emitter with the id "emitter" and that the default-material in
78
+ * // builtins is used, which defines the constant "tint".
79
+ * // If you assign a custom material to the sprite, you can reset the constants
80
+ * // defined there in the same manner.
81
+ * // How to reset the tinting of particles from an emitter:
82
+ * export default defineScript({
83
+ * init(self) {
84
+ * particlefx.reset_constant("#particlefx", "emitter", "tint");
85
+ * },
86
+ * });
77
87
  * ```
78
88
  */
79
89
  function reset_constant(url: string | Hash | Url, emitter: string | Hash, constant: string | Hash): void;
@@ -89,14 +99,18 @@ declare global {
89
99
  * @param constant - the name of the constant
90
100
  * @param value - the value of the constant
91
101
  * @example
92
- * ```lua
93
- * The following examples assumes that the particle FX has id "particlefx", it
94
- * contains an emitter with the id "emitter" and that the default-material in builtins is used, which defines the constant "tint".
95
- * If you assign a custom material to the sprite, you can reset the constants defined there in the same manner.
96
- * How to tint particles from an emitter red:
97
- * function init(self)
98
- * particlefx.set_constant("#particlefx", "emitter", "tint", vmath.vector4(1, 0, 0, 1))
99
- * end
102
+ * ```ts
103
+ * // The following examples assume that the particle FX has id "particlefx", it
104
+ * // contains an emitter with the id "emitter" and that the default-material in
105
+ * // builtins is used, which defines the constant "tint".
106
+ * // If you assign a custom material to the sprite, you can reset the constants
107
+ * // defined there in the same manner.
108
+ * // How to tint particles from an emitter red:
109
+ * export default defineScript({
110
+ * init(self) {
111
+ * particlefx.set_constant("#particlefx", "emitter", "tint", vmath.vector4(1, 0, 0, 1));
112
+ * },
113
+ * });
100
114
  * ```
101
115
  */
102
116
  function set_constant(url: string | Hash | Url, emitter: string | Hash, constant: string | Hash, value: Vector4): void;
@@ -109,12 +123,14 @@ declare global {
109
123
  * @param options - Options when stopping the particle fx. Supported options:
110
124
  * - boolean `clear`: instantly clear spawned particles
111
125
  * @example
112
- * ```lua
113
- * How to stop a particle fx when a game object is deleted and immediately also clear
114
- * any spawned particles:
115
- * function final(self)
116
- * particlefx.stop("#particlefx", { clear = true })
117
- * end
126
+ * ```ts
127
+ * // How to stop a particle fx when a game object is deleted and immediately also
128
+ * // clear any spawned particles:
129
+ * export default defineScript({
130
+ * final(self) {
131
+ * particlefx.stop("#particlefx", { clear: true });
132
+ * },
133
+ * });
118
134
  * ```
119
135
  */
120
136
  function stop(url: string | Hash | Url, options?: { clear?: boolean }): void;
@@ -2,6 +2,11 @@
2
2
  import type { Hash, Url, Vector3 } from "../src/core-types";
3
3
 
4
4
  declare global {
5
+ /**
6
+ * Functions and messages for collision object physics interaction
7
+ * with other objects (collisions and ray-casting) and control of
8
+ * physical behaviors.
9
+ */
5
10
  namespace physics {
6
11
  /**
7
12
  * The following properties are available when connecting a joint of `JOINT_TYPE_FIXED` type:
@@ -62,13 +67,15 @@ declare global {
62
67
  *
63
68
  * @returns gravity vector of collection
64
69
  * @example
65
- * ```lua
66
- * function init(self)
67
- * local gravity = physics.get_gravity()
68
- * -- Inverse gravity!
69
- * gravity = -gravity
70
- * physics.set_gravity(gravity)
71
- * end
70
+ * ```ts
71
+ * export default defineScript({
72
+ * init(self) {
73
+ * let gravity = physics.get_gravity();
74
+ * // Inverse gravity!
75
+ * gravity = -gravity;
76
+ * physics.set_gravity(gravity);
77
+ * },
78
+ * });
72
79
  * ```
73
80
  */
74
81
  function get_gravity(): Vector3;
@@ -178,25 +185,27 @@ declare global {
178
185
  * boolean Set to `true` to return all ray cast hits. If `false`, it will only return the closest hit.
179
186
  * @returns It returns a list. If missed it returns `nil`. See ray_cast_response for details on the returned values.
180
187
  * @example
181
- * ```lua
182
- * How to perform a ray cast synchronously:
183
- * function init(self)
184
- * self.groups = {hash("world"), hash("enemy")}
185
- * end
188
+ * ```ts
189
+ * // How to perform a ray cast synchronously:
190
+ * export default defineScript({
191
+ * init(self) {
192
+ * self.groups = [hash("world"), hash("enemy")];
193
+ * },
186
194
  *
187
- * function update(self, dt)
188
- * -- request ray cast
189
- * local result = physics.raycast(from, to, self.groups, {all=true})
190
- * if result ~= nil then
191
- * -- act on the hit (see 'ray_cast_response')
192
- * for _,result in ipairs(results) do
193
- * handle_result(result)
194
- * end
195
- * end
196
- * end
195
+ * update(self, dt) {
196
+ * // request ray cast
197
+ * const result = physics.raycast(from, to, self.groups, { all: true });
198
+ * if (result !== undefined) {
199
+ * // act on the hit (see 'ray_cast_response')
200
+ * for (const result of results) {
201
+ * handle_result(result);
202
+ * }
203
+ * }
204
+ * },
205
+ * });
197
206
  * ```
198
207
  */
199
- function raycast(from: Vector3, to: Vector3, groups: Record<string | number, unknown>, options?: { all?: boolean }): Record<string | number, unknown> | unknown;
208
+ function raycast(from: Vector3, to: Vector3, groups: Hash[], options?: { all?: boolean }): Record<string | number, unknown> | unknown;
200
209
  /**
201
210
  * Ray casts are used to test for intersections against collision objects in the physics world.
202
211
  * Collision objects of types kinematic, dynamic and static are tested against. Trigger objects
@@ -213,28 +222,30 @@ declare global {
213
222
  * @param groups - a lua table containing the hashed groups for which to test collisions against
214
223
  * @param request_id - a number in range [0,255]. It will be sent back in the response for identification, 0 by default
215
224
  * @example
216
- * ```lua
217
- * How to perform a ray cast asynchronously:
218
- * function init(self)
219
- * self.my_groups = {hash("my_group1"), hash("my_group2")}
220
- * end
225
+ * ```ts
226
+ * // How to perform a ray cast asynchronously:
227
+ * export default defineScript({
228
+ * init(self) {
229
+ * self.my_groups = [hash("my_group1"), hash("my_group2")];
230
+ * },
221
231
  *
222
- * function update(self, dt)
223
- * -- request ray cast
224
- * physics.raycast_async(my_start, my_end, self.my_groups)
225
- * end
232
+ * update(self, dt) {
233
+ * // request ray cast
234
+ * physics.raycast_async(my_start, my_end, self.my_groups);
235
+ * },
226
236
  *
227
- * function on_message(self, message_id, message, sender)
228
- * -- check for the response
229
- * if message_id == hash("ray_cast_response") then
230
- * -- act on the hit
231
- * elseif message_id == hash("ray_cast_missed") then
232
- * -- act on the miss
233
- * end
234
- * end
237
+ * on_message(self, message_id, message, sender) {
238
+ * // check for the response
239
+ * if (message_id === hash("ray_cast_response")) {
240
+ * // act on the hit
241
+ * } else if (message_id === hash("ray_cast_missed")) {
242
+ * // act on the miss
243
+ * }
244
+ * },
245
+ * });
235
246
  * ```
236
247
  */
237
- function raycast_async(from: Vector3, to: Vector3, groups: Record<string | number, unknown>, request_id?: number): void;
248
+ function raycast_async(from: Vector3, to: Vector3, groups: Hash[], request_id?: number): void;
238
249
  /**
239
250
  * Only one physics world event listener can be set at a time.
240
251
  *
@@ -251,82 +262,85 @@ declare global {
251
262
  * `data`
252
263
  * table The callback value data is a table that contains event-related data. See the documentation for details on the messages.
253
264
  * @example
254
- * ```lua
255
- * local function physics_world_listener(self, events)
256
- * for _,event in ipairs(events):
257
- * local event_type = event['type']
258
- * if event_type == hash("contact_point_event") then
259
- * pprint(event)
260
- * -- {
261
- * -- distance = 2.1490633487701,
262
- * -- applied_impulse = 0
263
- * -- a = { --[[0x113f7c6c0]]
264
- * -- group = hash: [box],
265
- * -- id = hash: [/box]
266
- * -- mass = 0,
267
- * -- normal = vmath.vector3(0.379, 0.925, -0),
268
- * -- position = vmath.vector3(517.337, 235.068, 0),
269
- * -- instance_position = vmath.vector3(480, 144, 0),
270
- * -- relative_velocity = vmath.vector3(-0, -0, -0),
271
- * -- },
272
- * -- b = { --[[0x113f7c840]]
273
- * -- group = hash: [circle],
274
- * -- id = hash: [/circle]
275
- * -- mass = 0,
276
- * -- normal = vmath.vector3(-0.379, -0.925, 0),
277
- * -- position = vmath.vector3(517.337, 235.068, 0),
278
- * -- instance_position = vmath.vector3(-0.0021, 0, -0.0022),
279
- * -- relative_velocity = vmath.vector3(0, 0, 0),
280
- * -- },
281
- * -- }
282
- * elseif event == hash("collision_event") then
283
- * pprint(event)
284
- * -- {
285
- * -- a = {
286
- * -- group = hash: [default],
287
- * -- position = vmath.vector3(183, 666, 0),
288
- * -- id = hash: [/go1]
289
- * -- },
290
- * -- b = {
291
- * -- group = hash: [default],
292
- * -- position = vmath.vector3(185, 704.05865478516, 0),
293
- * -- id = hash: [/go2]
294
- * -- }
295
- * -- }
296
- * elseif event == hash("trigger_event") then
297
- * pprint(event)
298
- * -- {
299
- * -- enter = true,
300
- * -- b = {
301
- * -- group = hash: [default],
302
- * -- id = hash: [/go2]
303
- * -- },
304
- * -- a = {
305
- * -- group = hash: [default],
306
- * -- id = hash: [/go1]
307
- * -- }
308
- * -- },
309
- * elseif event == hash("ray_cast_response") then
310
- * pprint(event)
311
- * --{
312
- * -- group = hash: [default],
313
- * -- request_id = 0,
314
- * -- position = vmath.vector3(249.92222595215, 249.92222595215, 0),
315
- * -- fraction = 0.68759721517563,
316
- * -- normal = vmath.vector3(0, 1, 0),
317
- * -- id = hash: [/go]
318
- * -- }
319
- * elseif event == hash("ray_cast_missed") then
320
- * pprint(event)
321
- * -- {
322
- * -- request_id = 0
323
- * --},
324
- * end
325
- * end
265
+ * ```ts
266
+ * function physics_world_listener(self, events) {
267
+ * for (const event of events) {
268
+ * const event_type = event["type"];
269
+ * if (event_type === hash("contact_point_event")) {
270
+ * pprint(event);
271
+ * // {
272
+ * // distance = 2.1490633487701,
273
+ * // applied_impulse = 0
274
+ * // a = { --[[0x113f7c6c0]]
275
+ * // group = hash: [box],
276
+ * // id = hash: [/box]
277
+ * // mass = 0,
278
+ * // normal = vmath.vector3(0.379, 0.925, -0),
279
+ * // position = vmath.vector3(517.337, 235.068, 0),
280
+ * // instance_position = vmath.vector3(480, 144, 0),
281
+ * // relative_velocity = vmath.vector3(-0, -0, -0),
282
+ * // },
283
+ * // b = { --[[0x113f7c840]]
284
+ * // group = hash: [circle],
285
+ * // id = hash: [/circle]
286
+ * // mass = 0,
287
+ * // normal = vmath.vector3(-0.379, -0.925, 0),
288
+ * // position = vmath.vector3(517.337, 235.068, 0),
289
+ * // instance_position = vmath.vector3(-0.0021, 0, -0.0022),
290
+ * // relative_velocity = vmath.vector3(0, 0, 0),
291
+ * // },
292
+ * // }
293
+ * } else if (event === hash("collision_event")) {
294
+ * pprint(event);
295
+ * // {
296
+ * // a = {
297
+ * // group = hash: [default],
298
+ * // position = vmath.vector3(183, 666, 0),
299
+ * // id = hash: [/go1]
300
+ * // },
301
+ * // b = {
302
+ * // group = hash: [default],
303
+ * // position = vmath.vector3(185, 704.05865478516, 0),
304
+ * // id = hash: [/go2]
305
+ * // }
306
+ * // }
307
+ * } else if (event === hash("trigger_event")) {
308
+ * pprint(event);
309
+ * // {
310
+ * // enter = true,
311
+ * // b = {
312
+ * // group = hash: [default],
313
+ * // id = hash: [/go2]
314
+ * // },
315
+ * // a = {
316
+ * // group = hash: [default],
317
+ * // id = hash: [/go1]
318
+ * // }
319
+ * // },
320
+ * } else if (event === hash("ray_cast_response")) {
321
+ * pprint(event);
322
+ * // {
323
+ * // group = hash: [default],
324
+ * // request_id = 0,
325
+ * // position = vmath.vector3(249.92222595215, 249.92222595215, 0),
326
+ * // fraction = 0.68759721517563,
327
+ * // normal = vmath.vector3(0, 1, 0),
328
+ * // id = hash: [/go]
329
+ * // }
330
+ * } else if (event === hash("ray_cast_missed")) {
331
+ * pprint(event);
332
+ * // {
333
+ * // request_id = 0
334
+ * // },
335
+ * }
336
+ * }
337
+ * }
326
338
  *
327
- * function init(self)
328
- * physics.set_event_listener(physics_world_listener)
329
- * end
339
+ * export default defineScript({
340
+ * init(self) {
341
+ * physics.set_event_listener(physics_world_listener);
342
+ * },
343
+ * });
330
344
  * ```
331
345
  */
332
346
  function set_event_listener(callback?: (self: unknown, events: unknown) => void): void;
@@ -337,11 +351,13 @@ declare global {
337
351
  *
338
352
  * @param gravity - the new gravity vector
339
353
  * @example
340
- * ```lua
341
- * function init(self)
342
- * -- Set "upside down" gravity for this collection.
343
- * physics.set_gravity(vmath.vector3(0, 10.0, 0))
344
- * end
354
+ * ```ts
355
+ * export default defineScript({
356
+ * init(self) {
357
+ * // Set "upside down" gravity for this collection.
358
+ * physics.set_gravity(vmath.vector3(0, 10.0, 0));
359
+ * },
360
+ * });
345
361
  * ```
346
362
  */
347
363
  function set_gravity(gravity: Vector3): void;
@@ -364,11 +380,13 @@ declare global {
364
380
  * @param url - the collision object that should flip its shapes
365
381
  * @param flip - `true` if the collision object should flip its shapes, `false` if not
366
382
  * @example
367
- * ```lua
368
- * function init(self)
369
- * self.fliph = true -- set on some condition
370
- * physics.set_hflip("#collisionobject", self.fliph)
371
- * end
383
+ * ```ts
384
+ * export default defineScript({
385
+ * init(self) {
386
+ * self.fliph = true; // set on some condition
387
+ * physics.set_hflip("#collisionobject", self.fliph);
388
+ * },
389
+ * });
372
390
  * ```
373
391
  */
374
392
  function set_hflip(url: string | Hash | Url, flip: boolean): void;
@@ -432,11 +450,13 @@ declare global {
432
450
  * @param url - the collision object that should flip its shapes
433
451
  * @param flip - `true` if the collision object should flip its shapes, `false` if not
434
452
  * @example
435
- * ```lua
436
- * function init(self)
437
- * self.flipv = true -- set on some condition
438
- * physics.set_vflip("#collisionobject", self.flipv)
439
- * end
453
+ * ```ts
454
+ * export default defineScript({
455
+ * init(self) {
456
+ * self.flipv = true; // set on some condition
457
+ * physics.set_vflip("#collisionobject", self.flipv);
458
+ * },
459
+ * });
440
460
  * ```
441
461
  */
442
462
  function set_vflip(url: string | Hash | Url, flip: boolean): void;
@@ -447,8 +467,8 @@ declare global {
447
467
  * @param collisionobject - the collision object whose mass needs to be updated.
448
468
  * @param mass - the new mass value to set for the collision object.
449
469
  * @example
450
- * ```lua
451
- * physics.update_mass("#collisionobject", 14)
470
+ * ```ts
471
+ * physics.update_mass("#collisionobject", 14);
452
472
  * ```
453
473
  */
454
474
  function update_mass(collisionobject: string | Hash | Url, mass: number): void;