@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
package/generated/go.d.ts CHANGED
@@ -2,6 +2,11 @@
2
2
  import type { Hash, Matrix4, Opaque, Quaternion, Url, Vector, Vector3, Vector4 } from "../src/core-types";
3
3
 
4
4
  declare global {
5
+ /**
6
+ * Functions, core hooks, messages and constants for manipulation of
7
+ * game objects. The "go" namespace is accessible from game object script
8
+ * files.
9
+ */
5
10
  namespace go {
6
11
  /**
7
12
  * in-back
@@ -226,27 +231,22 @@ declare global {
226
231
  * `property`
227
232
  * hash The id of the animated property.
228
233
  * @example
229
- * ```lua
230
- * Animate the position of a game object to x = 10 during 1 second, then y = 20 during 1 second:
231
- * local function x_done(self, url, property)
232
- * go.animate(go.get_id(), "position.y", go.PLAYBACK_ONCE_FORWARD, 20, go.EASING_LINEAR, 1)
233
- * end
234
- *
235
- * function init(self)
236
- * go.animate(go.get_id(), "position.x", go.PLAYBACK_ONCE_FORWARD, 10, go.EASING_LINEAR, 1, 0, x_done)
237
- * end
238
- *
239
- * Animate the y position of a game object using a crazy custom easing curve:
240
- * local values = { 0, 0, 0, 0, 0, 0, 0, 0,
241
- * 1, 1, 1, 1, 1, 1, 1, 1,
242
- * 0, 0, 0, 0, 0, 0, 0, 0,
243
- * 1, 1, 1, 1, 1, 1, 1, 1,
244
- * 0, 0, 0, 0, 0, 0, 0, 0,
245
- * 1, 1, 1, 1, 1, 1, 1, 1,
246
- * 0, 0, 0, 0, 0, 0, 0, 0,
247
- * 1, 1, 1, 1, 1, 1, 1, 1 }
248
- * local vec = vmath.vector(values)
249
- * go.animate("go", "position.y", go.PLAYBACK_LOOP_PINGPONG, 100, vec, 2.0)
234
+ * ```ts
235
+ * // Animate the position of a game object to x = 10 during 1 second, then
236
+ * // y = 20 during 1 second:
237
+ * go.animate(go.get_id(), "position.x", go.PLAYBACK_ONCE_FORWARD, 10, go.EASING_LINEAR, 1, 0, () => {
238
+ * go.animate(go.get_id(), "position.y", go.PLAYBACK_ONCE_FORWARD, 20, go.EASING_LINEAR, 1);
239
+ * });
240
+ *
241
+ * // Animate the y position of a game object using a crazy custom easing curve:
242
+ * const values = [
243
+ * 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
244
+ * 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
245
+ * 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
246
+ * 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
247
+ * ];
248
+ * const vec = vmath.vector(values);
249
+ * go.animate("go", "position.y", go.PLAYBACK_LOOP_PINGPONG, 100, vec, 2.0);
250
250
  * ```
251
251
  */
252
252
  export function animate(url: string | Hash | Url, property: string | Hash, playback: number & { readonly __brand: "go.PLAYBACK_ONCE_FORWARD" } | number & { readonly __brand: "go.PLAYBACK_ONCE_BACKWARD" } | number & { readonly __brand: "go.PLAYBACK_ONCE_PINGPONG" } | number & { readonly __brand: "go.PLAYBACK_LOOP_FORWARD" } | number & { readonly __brand: "go.PLAYBACK_LOOP_BACKWARD" } | number & { readonly __brand: "go.PLAYBACK_LOOP_PINGPONG" }, to: number | Vector3 | Vector4 | Quaternion, easing: Vector | number & { readonly __brand: "go.EASING_INBACK" } | number & { readonly __brand: "go.EASING_INBOUNCE" } | number & { readonly __brand: "go.EASING_INCIRC" } | number & { readonly __brand: "go.EASING_INCUBIC" } | number & { readonly __brand: "go.EASING_INELASTIC" } | number & { readonly __brand: "go.EASING_INEXPO" } | number & { readonly __brand: "go.EASING_INOUTBACK" } | number & { readonly __brand: "go.EASING_INOUTBOUNCE" } | number & { readonly __brand: "go.EASING_INOUTCIRC" } | number & { readonly __brand: "go.EASING_INOUTCUBIC" } | number & { readonly __brand: "go.EASING_INOUTELASTIC" } | number & { readonly __brand: "go.EASING_INOUTEXPO" } | number & { readonly __brand: "go.EASING_INOUTQUAD" } | number & { readonly __brand: "go.EASING_INOUTQUART" } | number & { readonly __brand: "go.EASING_INOUTQUINT" } | number & { readonly __brand: "go.EASING_INOUTSINE" } | number & { readonly __brand: "go.EASING_INQUAD" } | number & { readonly __brand: "go.EASING_INQUART" } | number & { readonly __brand: "go.EASING_INQUINT" } | number & { readonly __brand: "go.EASING_INSINE" } | number & { readonly __brand: "go.EASING_LINEAR" } | number & { readonly __brand: "go.EASING_OUTBACK" } | number & { readonly __brand: "go.EASING_OUTBOUNCE" } | number & { readonly __brand: "go.EASING_OUTCIRC" } | number & { readonly __brand: "go.EASING_OUTCUBIC" } | number & { readonly __brand: "go.EASING_OUTELASTIC" } | number & { readonly __brand: "go.EASING_OUTEXPO" } | number & { readonly __brand: "go.EASING_OUTINBACK" } | number & { readonly __brand: "go.EASING_OUTINBOUNCE" } | number & { readonly __brand: "go.EASING_OUTINCIRC" } | number & { readonly __brand: "go.EASING_OUTINCUBIC" } | number & { readonly __brand: "go.EASING_OUTINELASTIC" } | number & { readonly __brand: "go.EASING_OUTINEXPO" } | number & { readonly __brand: "go.EASING_OUTINQUAD" } | number & { readonly __brand: "go.EASING_OUTINQUART" } | number & { readonly __brand: "go.EASING_OUTINQUINT" } | number & { readonly __brand: "go.EASING_OUTINSINE" } | number & { readonly __brand: "go.EASING_OUTQUAD" } | number & { readonly __brand: "go.EASING_OUTQUART" } | number & { readonly __brand: "go.EASING_OUTQUINT" } | number & { readonly __brand: "go.EASING_OUTSINE" }, duration: number, delay?: number, complete_function?: (self: unknown, url: unknown, property: unknown) => void): void;
@@ -257,15 +257,15 @@ declare global {
257
257
  * @param url - url of the game object or component
258
258
  * @param property - optional id of the property to cancel
259
259
  * @example
260
- * ```lua
261
- * Cancel the animation of the position of a game object:
262
- * go.cancel_animations(go.get_id(), "position")
260
+ * ```ts
261
+ * // Cancel the animation of the position of a game object:
262
+ * go.cancel_animations(go.get_id(), "position");
263
263
  *
264
- * Cancel all property animations of the current game object:
265
- * go.cancel_animations(".")
264
+ * // Cancel all property animations of the current game object:
265
+ * go.cancel_animations(".");
266
266
  *
267
- * Cancel all property animations of the sprite component of the current game object:
268
- * go.cancel_animations("#sprite")
267
+ * // Cancel all property animations of the sprite component of the current game object:
268
+ * go.cancel_animations("#sprite");
269
269
  * ```
270
270
  */
271
271
  export function cancel_animations(url: string | Hash | Url, property?: string | Hash): void;
@@ -280,26 +280,27 @@ declare global {
280
280
  * @param id - optional id or table of id's of the instance(s) to delete, the instance of the calling script is deleted by default
281
281
  * @param recursive - optional boolean, set to true to recursively delete child hiearchy in child to parent order
282
282
  * @example
283
- * ```lua
284
- * This example demonstrates how to delete game objects
285
- * -- Delete the script game object
286
- * go.delete()
287
- * -- Delete a game object with the id "my_game_object".
288
- * local id = go.get_id("my_game_object") -- retrieve the id of the game object to be deleted
289
- * go.delete(id)
290
- * -- Delete a list of game objects.
291
- * local ids = { hash("/my_object_1"), hash("/my_object_2"), hash("/my_object_3") }
292
- * go.delete(ids)
293
- *
294
- * This example demonstrates how to delete a game objects and their children (child to parent order)
295
- * -- Delete the script game object and it's children
296
- * go.delete(true)
297
- * -- Delete a game object with the id "my_game_object" and it's children.
298
- * local id = go.get_id("my_game_object") -- retrieve the id of the game object to be deleted
299
- * go.delete(id, true)
300
- * -- Delete a list of game objects and their children.
301
- * local ids = { hash("/my_object_1"), hash("/my_object_2"), hash("/my_object_3") }
302
- * go.delete(ids, true)
283
+ * ```ts
284
+ * // This example demonstrates how to delete game objects:
285
+ * // Delete the script's own game object.
286
+ * go.delete();
287
+ * // Delete a game object with the id "my_game_object".
288
+ * const id = go.get_id("my_game_object");
289
+ * go.delete(id);
290
+ * // Delete a list of game objects.
291
+ * const ids = [hash("/my_object_1"), hash("/my_object_2"), hash("/my_object_3")];
292
+ * go.delete(ids);
293
+ *
294
+ * // This example demonstrates how to delete game objects and their children
295
+ * // (child-to-parent order):
296
+ * // Delete the script's own game object and its children.
297
+ * go.delete(true);
298
+ * // Delete a game object with the id "my_game_object" and its children.
299
+ * const id2 = go.get_id("my_game_object");
300
+ * go.delete(id2, true);
301
+ * // Delete a list of game objects and their children.
302
+ * const ids2 = [hash("/my_object_1"), hash("/my_object_2"), hash("/my_object_3")];
303
+ * go.delete(ids2, true);
303
304
  * ```
304
305
  */
305
306
  function _delete(id?: string | Hash | Url | (string | Hash | Url)[], recursive?: boolean): void;
@@ -310,12 +311,12 @@ declare global {
310
311
  * @param url - url of the game object to check
311
312
  * @returns true if the game object exists
312
313
  * @example
313
- * ```lua
314
- * Check if game object "my_game_object" exists in the current collection
315
- * go.exists("/my_game_object")
314
+ * ```ts
315
+ * // Check if game object "my_game_object" exists in the current collection:
316
+ * go.exists("/my_game_object");
316
317
  *
317
- * Check if game object exists in another collection
318
- * go.exists("other_collection:/my_game_object")
318
+ * // Check if game object exists in another collection:
319
+ * go.exists("other_collection:/my_game_object");
319
320
  * ```
320
321
  */
321
322
  export function exists(url: string | Hash | Url): boolean;
@@ -326,11 +327,13 @@ declare global {
326
327
  *
327
328
  * @param self - reference to the script state to be used for storing data
328
329
  * @example
329
- * ```lua
330
- * function final(self)
331
- * -- report finalization
332
- * msg.post("my_friend_instance", "im_dead", {my_stats = self.some_value})
333
- * end
330
+ * ```ts
331
+ * export default defineScript({
332
+ * final(self) {
333
+ * // report finalization
334
+ * msg.post("my_friend_instance", "im_dead", { my_stats: self.some_value });
335
+ * },
336
+ * });
334
337
  * ```
335
338
  */
336
339
  export function final(self: Opaque<"userdata">): void;
@@ -353,16 +356,17 @@ declare global {
353
356
  * @param path - path of the instance for which to return the id
354
357
  * @returns instance id
355
358
  * @example
356
- * ```lua
357
- * For the instance with path /my_sub_collection/my_instance, the following calls are equivalent:
358
- * local id = go.get_id() -- no path, defaults to the instance containing the calling script
359
- * print(id) --> hash: [/my_sub_collection/my_instance]
359
+ * ```ts
360
+ * // For the instance with path /my_sub_collection/my_instance, the following calls
361
+ * // are equivalent:
362
+ * const id = go.get_id(); // no path, defaults to the instance containing the calling script
363
+ * print(id); // => hash: [/my_sub_collection/my_instance]
360
364
  *
361
- * local id = go.get_id("/my_sub_collection/my_instance") -- absolute path
362
- * print(id) --> hash: [/my_sub_collection/my_instance]
365
+ * const id2 = go.get_id("/my_sub_collection/my_instance"); // absolute path
366
+ * print(id2); // => hash: [/my_sub_collection/my_instance]
363
367
  *
364
- * local id = go.get_id("my_instance") -- relative path
365
- * print(id) --> hash: [/my_sub_collection/my_instance]
368
+ * const id3 = go.get_id("my_instance"); // relative path
369
+ * print(id3); // => hash: [/my_sub_collection/my_instance]
366
370
  * ```
367
371
  */
368
372
  export function get_id(path?: string): Hash;
@@ -372,12 +376,12 @@ declare global {
372
376
  * @param id - optional id of the game object instance to get parent for, defaults to the instance containing the calling script
373
377
  * @returns parent instance or `nil`
374
378
  * @example
375
- * ```lua
376
- * Get parent of the instance containing the calling script:
377
- * local parent_id = go.get_parent()
379
+ * ```ts
380
+ * // Get parent of the instance containing the calling script:
381
+ * const parent_id = go.get_parent();
378
382
  *
379
- * Get parent of the instance with id "x":
380
- * local parent_id = go.get_parent("x")
383
+ * // Get parent of the instance with id "x":
384
+ * const parent_id2 = go.get_parent("x");
381
385
  * ```
382
386
  */
383
387
  export function get_parent(id?: string | Hash | Url): Hash | unknown;
@@ -387,12 +391,12 @@ declare global {
387
391
  * @param id - optional id of the game object instance to get the position for, by default the instance of the calling script
388
392
  * @returns instance position
389
393
  * @example
390
- * ```lua
391
- * Get the position of the game object instance the script is attached to:
392
- * local p = go.get_position()
394
+ * ```ts
395
+ * // Get the position of the game object the script is attached to:
396
+ * const p = go.get_position();
393
397
  *
394
- * Get the position of another game object instance "my_gameobject":
395
- * local pos = go.get_position("my_gameobject")
398
+ * // Get the position of another game object "my_gameobject":
399
+ * const pos = go.get_position("my_gameobject");
396
400
  * ```
397
401
  */
398
402
  export function get_position(id?: string | Hash | Url): Vector3;
@@ -402,12 +406,12 @@ declare global {
402
406
  * @param id - optional id of the game object instance to get the rotation for, by default the instance of the calling script
403
407
  * @returns instance rotation
404
408
  * @example
405
- * ```lua
406
- * Get the rotation of the game object instance the script is attached to:
407
- * local r = go.get_rotation()
409
+ * ```ts
410
+ * // Get the rotation of the game object the script is attached to:
411
+ * const r = go.get_rotation();
408
412
  *
409
- * Get the rotation of another game object instance with id "x":
410
- * local r = go.get_rotation("x")
413
+ * // Get the rotation of another game object with id "x":
414
+ * const r2 = go.get_rotation("x");
411
415
  * ```
412
416
  */
413
417
  export function get_rotation(id?: string | Hash | Url): Quaternion;
@@ -417,12 +421,12 @@ declare global {
417
421
  * @param id - optional id of the game object instance to get the scale for, by default the instance of the calling script
418
422
  * @returns instance scale factor
419
423
  * @example
420
- * ```lua
421
- * Get the scale of the game object instance the script is attached to:
422
- * local s = go.get_scale()
424
+ * ```ts
425
+ * // Get the scale of the game object the script is attached to:
426
+ * const s = go.get_scale();
423
427
  *
424
- * Get the scale of another game object instance with id "x":
425
- * local s = go.get_scale("x")
428
+ * // Get the scale of another game object with id "x":
429
+ * const s2 = go.get_scale("x");
426
430
  * ```
427
431
  */
428
432
  export function get_scale(id?: string | Hash | Url): Vector3;
@@ -432,12 +436,12 @@ declare global {
432
436
  * @param id - optional id of the game object instance to get the uniform scale for, by default the instance of the calling script
433
437
  * @returns uniform instance scale factor
434
438
  * @example
435
- * ```lua
436
- * Get the scale of the game object instance the script is attached to:
437
- * local s = go.get_scale_uniform()
439
+ * ```ts
440
+ * // Get the uniform scale of the game object the script is attached to:
441
+ * const s = go.get_scale_uniform();
438
442
  *
439
- * Get the uniform scale of another game object instance with id "x":
440
- * local s = go.get_scale_uniform("x")
443
+ * // Get the uniform scale of another game object with id "x":
444
+ * const s2 = go.get_scale_uniform("x");
441
445
  * ```
442
446
  */
443
447
  export function get_scale_uniform(id?: string | Hash | Url): number;
@@ -449,12 +453,12 @@ declare global {
449
453
  * @param id - optional id of the game object instance to get the world position for, by default the instance of the calling script
450
454
  * @returns instance world position
451
455
  * @example
452
- * ```lua
453
- * Get the world position of the game object instance the script is attached to:
454
- * local p = go.get_world_position()
456
+ * ```ts
457
+ * // Get the world position of the game object the script is attached to:
458
+ * const p = go.get_world_position();
455
459
  *
456
- * Get the world position of another game object instance with id "x":
457
- * local p = go.get_world_position("x")
460
+ * // Get the world position of another game object with id "x":
461
+ * const p2 = go.get_world_position("x");
458
462
  * ```
459
463
  */
460
464
  export function get_world_position(id?: string | Hash | Url): Vector3;
@@ -466,12 +470,12 @@ declare global {
466
470
  * @param id - optional id of the game object instance to get the world rotation for, by default the instance of the calling script
467
471
  * @returns instance world rotation
468
472
  * @example
469
- * ```lua
470
- * Get the world rotation of the game object instance the script is attached to:
471
- * local r = go.get_world_rotation()
473
+ * ```ts
474
+ * // Get the world rotation of the game object the script is attached to:
475
+ * const r = go.get_world_rotation();
472
476
  *
473
- * Get the world rotation of another game object instance with id "x":
474
- * local r = go.get_world_rotation("x")
477
+ * // Get the world rotation of another game object with id "x":
478
+ * const r2 = go.get_world_rotation("x");
475
479
  * ```
476
480
  */
477
481
  export function get_world_rotation(id?: string | Hash | Url): Quaternion;
@@ -485,12 +489,12 @@ declare global {
485
489
  * @param id - optional id of the game object instance to get the world scale for, by default the instance of the calling script
486
490
  * @returns instance world 3D scale factor
487
491
  * @example
488
- * ```lua
489
- * Get the world 3D scale of the game object instance the script is attached to:
490
- * local s = go.get_world_scale()
492
+ * ```ts
493
+ * // Get the world 3D scale of the game object the script is attached to:
494
+ * const s = go.get_world_scale();
491
495
  *
492
- * Get the world scale of another game object instance "x":
493
- * local s = go.get_world_scale("x")
496
+ * // Get the world scale of another game object "x":
497
+ * const s2 = go.get_world_scale("x");
494
498
  * ```
495
499
  */
496
500
  export function get_world_scale(id?: string | Hash | Url): Vector3;
@@ -502,12 +506,12 @@ declare global {
502
506
  * @param id - optional id of the game object instance to get the world scale for, by default the instance of the calling script
503
507
  * @returns instance world scale factor
504
508
  * @example
505
- * ```lua
506
- * Get the world scale of the game object instance the script is attached to:
507
- * local s = go.get_world_scale_uniform()
509
+ * ```ts
510
+ * // Get the world uniform scale of the game object the script is attached to:
511
+ * const s = go.get_world_scale_uniform();
508
512
  *
509
- * Get the world scale of another game object instance with id "x":
510
- * local s = go.get_world_scale_uniform("x")
513
+ * // Get the world uniform scale of another game object with id "x":
514
+ * const s2 = go.get_world_scale_uniform("x");
511
515
  * ```
512
516
  */
513
517
  export function get_world_scale_uniform(id?: string | Hash | Url): number;
@@ -518,12 +522,12 @@ declare global {
518
522
  * @param id - optional id of the game object instance to get the world transform for, by default the instance of the calling script
519
523
  * @returns instance world transform
520
524
  * @example
521
- * ```lua
522
- * Get the world transform of the game object instance the script is attached to:
523
- * local m = go.get_world_transform()
525
+ * ```ts
526
+ * // Get the world transform of the game object the script is attached to:
527
+ * const m = go.get_world_transform();
524
528
  *
525
- * Get the world transform of another game object instance with id "x":
526
- * local m = go.get_world_transform("x")
529
+ * // Get the world transform of another game object with id "x":
530
+ * const m2 = go.get_world_transform("x");
527
531
  * ```
528
532
  */
529
533
  export function get_world_transform(id?: string | Hash | Url): Matrix4;
@@ -533,11 +537,13 @@ declare global {
533
537
  *
534
538
  * @param self - reference to the script state to be used for storing data
535
539
  * @example
536
- * ```lua
537
- * function init(self)
538
- * -- set up useful data
539
- * self.my_value = 1
540
- * end
540
+ * ```ts
541
+ * export default defineScript({
542
+ * init() {
543
+ * // set up useful data
544
+ * return { my_value: 1 };
545
+ * },
546
+ * });
541
547
  * ```
542
548
  */
543
549
  export function init(self: Opaque<"userdata">): void;
@@ -649,32 +655,38 @@ declare global {
649
655
  * @param action - a table containing the input data, see above for a description
650
656
  * @returns optional boolean to signal if the input should be consumed (not passed on to others) or not, default is false
651
657
  * @example
652
- * ```lua
653
- * This example demonstrates how a game object instance can be moved as a response to user input.
654
- * function init(self)
655
- * -- acquire input focus
656
- * msg.post(".", "acquire_input_focus")
657
- * -- maximum speed the instance can be moved
658
- * self.max_speed = 2
659
- * -- velocity of the instance, initially zero
660
- * self.velocity = vmath.vector3()
661
- * end
662
- *
663
- * function update(self, dt)
664
- * -- move the instance
665
- * go.set_position(go.get_position() + dt * self.velocity)
666
- * end
667
- *
668
- * function on_input(self, action_id, action)
669
- * -- check for movement input
670
- * if action_id == hash("right") then
671
- * if action.released then -- reset velocity if input was released
672
- * self.velocity = vmath.vector3()
673
- * else -- update velocity
674
- * self.velocity = vmath.vector3(action.value * self.max_speed, 0, 0)
675
- * end
676
- * end
677
- * end
658
+ * ```ts
659
+ * // This example demonstrates how a game object instance can be moved as a response to user input.
660
+ * export default defineScript({
661
+ * init() {
662
+ * // acquire input focus
663
+ * msg.post(".", "acquire_input_focus");
664
+ * return {
665
+ * // maximum speed the instance can be moved
666
+ * max_speed: 2,
667
+ * // velocity of the instance, initially zero
668
+ * velocity: vmath.vector3(),
669
+ * };
670
+ * },
671
+ *
672
+ * update(self, dt) {
673
+ * // move the instance
674
+ * go.set_position(go.get_position().add(self.velocity.mul(dt)));
675
+ * },
676
+ *
677
+ * on_input(self, action_id, action) {
678
+ * // check for movement input
679
+ * if (action_id === hash("right")) {
680
+ * if (action.released) {
681
+ * // reset velocity if input was released
682
+ * self.velocity = vmath.vector3();
683
+ * } else {
684
+ * // update velocity
685
+ * self.velocity = vmath.vector3(action.value * self.max_speed, 0, 0);
686
+ * }
687
+ * }
688
+ * },
689
+ * });
678
690
  * ```
679
691
  */
680
692
  export function on_input(self: Opaque<"userdata">, action_id: Hash, action: Record<string | number, unknown>): boolean | unknown;
@@ -689,29 +701,34 @@ declare global {
689
701
  * @param message - a table containing the message data
690
702
  * @param sender - address of the sender
691
703
  * @example
692
- * ```lua
693
- * This example demonstrates how a game object instance, called "a", can communicate with another instance, called "b". It
694
- * is assumed that both script components of the instances has id "script".
695
- * Script of instance "a":
696
- * function init(self)
697
- * -- let b know about some important data
698
- * msg.post("b#script", "my_data", {important_value = 1})
699
- * end
700
- *
701
- * Script of instance "b":
702
- * function init(self)
703
- * -- store the url of instance "a" for later use, by specifying nil as socket we
704
- * -- automatically use our own socket
705
- * self.a_url = msg.url(nil, go.get_id("a"), "script")
706
- * end
707
- *
708
- * function on_message(self, message_id, message, sender)
709
- * -- check message and sender
710
- * if message_id == hash("my_data") and sender == self.a_url then
711
- * -- use the data in some way
712
- * self.important_value = message.important_value
713
- * end
714
- * end
704
+ * ```ts
705
+ * // This example demonstrates how a game object instance, called "a", can communicate with another instance, called "b". It
706
+ * // is assumed that both script components of the instances has id "script".
707
+ *
708
+ * // a.script — Script of instance "a":
709
+ * export default defineScript({
710
+ * init() {
711
+ * // let b know about some important data
712
+ * msg.post("b#script", "my_data", { important_value: 1 });
713
+ * },
714
+ * });
715
+ *
716
+ * // b.script Script of instance "b":
717
+ * export default defineScript({
718
+ * init() {
719
+ * // store the url of instance "a" for later use, by specifying undefined as socket we
720
+ * // automatically use our own socket
721
+ * return { a_url: msg.url(undefined, go.get_id("a"), "script") };
722
+ * },
723
+ *
724
+ * on_message(self, message_id, message, sender) {
725
+ * // check message and sender
726
+ * if (message_id === hash("my_data") && sender === self.a_url) {
727
+ * // use the data in some way
728
+ * self.important_value = message.important_value;
729
+ * }
730
+ * },
731
+ * });
715
732
  * ```
716
733
  */
717
734
  export function on_message(self: Opaque<"userdata">, message_id: Hash, message: Record<string | number, unknown>, sender: Url): void;
@@ -721,67 +738,46 @@ declare global {
721
738
  *
722
739
  * @param self - reference to the script state to be used for storing data
723
740
  * @example
724
- * ```lua
725
- * This example demonstrates how to tweak the speed of a game object instance that is moved on user input.
726
- * function init(self)
727
- * -- acquire input focus
728
- * msg.post(".", "acquire_input_focus")
729
- * -- maximum speed the instance can be moved, this value is tweaked in the on_reload function below
730
- * self.max_speed = 2
731
- * -- velocity of the instance, initially zero
732
- * self.velocity = vmath.vector3()
733
- * end
734
- *
735
- * function update(self, dt)
736
- * -- move the instance
737
- * go.set_position(go.get_position() + dt * self.velocity)
738
- * end
739
- *
740
- * function on_input(self, action_id, action)
741
- * -- check for movement input
742
- * if action_id == hash("right") then
743
- * if action.released then -- reset velocity if input was released
744
- * self.velocity = vmath.vector3()
745
- * else -- update velocity
746
- * self.velocity = vmath.vector3(action.value * self.max_speed, 0, 0)
747
- * end
748
- * end
749
- * end
750
- *
751
- * function on_reload(self)
752
- * -- edit this value and reload the script component
753
- * self.max_speed = 100
754
- * end
741
+ * ```ts
742
+ * // This example demonstrates how to tweak the speed of a game object instance that is moved on user input.
743
+ * export default defineScript({
744
+ * init() {
745
+ * // acquire input focus
746
+ * msg.post(".", "acquire_input_focus");
747
+ * return {
748
+ * // maximum speed the instance can be moved, this value is tweaked in the on_reload function below
749
+ * max_speed: 2,
750
+ * // velocity of the instance, initially zero
751
+ * velocity: vmath.vector3(),
752
+ * };
753
+ * },
754
+ *
755
+ * update(self, dt) {
756
+ * // move the instance
757
+ * go.set_position(go.get_position().add(self.velocity.mul(dt)));
758
+ * },
759
+ *
760
+ * on_input(self, action_id, action) {
761
+ * // check for movement input
762
+ * if (action_id === hash("right")) {
763
+ * if (action.released) {
764
+ * // reset velocity if input was released
765
+ * self.velocity = vmath.vector3();
766
+ * } else {
767
+ * // update velocity
768
+ * self.velocity = vmath.vector3(action.value * self.max_speed, 0, 0);
769
+ * }
770
+ * }
771
+ * },
772
+ *
773
+ * on_reload(self) {
774
+ * // edit this value and reload the script component
775
+ * self.max_speed = 100;
776
+ * },
777
+ * });
755
778
  * ```
756
779
  */
757
780
  export function on_reload(self: Opaque<"userdata">): void;
758
- /**
759
- * This function defines a property which can then be used in the script through the self-reference.
760
- * The properties defined this way are automatically exposed in the editor in game objects and collections which use the script.
761
- * Note that you can only use this function outside any callback-functions like init and update.
762
- *
763
- * @param name - the id of the property
764
- * @param value - default value of the property. In the case of a url, only the empty constructor msg.url() is allowed. In the case of a resource one of the resource constructors (eg resource.atlas(), resource.font() etc) is expected.
765
- * @example
766
- * ```lua
767
- * This example demonstrates how to define a property called "health" in a script.
768
- * The health is decreased whenever someone sends a message called "take_damage" to the script.
769
- * go.property("health", 100)
770
- *
771
- * function init(self)
772
- * -- prints 100 to the output
773
- * print(self.health)
774
- * end
775
- *
776
- * function on_message(self, message_id, message, sender)
777
- * if message_id == hash("take_damage") then
778
- * self.health = self.health - message.damage
779
- * print("Ouch! My health is now: " .. self.health)
780
- * end
781
- * end
782
- * ```
783
- */
784
- export function property(name: string, value: number | Hash | Url | Vector3 | Vector4 | Quaternion | Opaque<"resource"> | boolean): void;
785
781
  /**
786
782
  * Sets the parent for a game object instance. This means that the instance will exist in the geometrical space of its parent,
787
783
  * like a basic transformation hierarchy or scene graph. If no parent is specified, the instance will be detached from any parent and exist in world
@@ -794,15 +790,15 @@ declare global {
794
790
  * @param parent_id - optional id of the new parent game object, defaults to detaching game object from its parent
795
791
  * @param keep_world_transform - optional boolean, set to true to maintain the world transform when changing spaces. Defaults to false.
796
792
  * @example
797
- * ```lua
798
- * Attach myself to another instance "my_parent":
799
- * go.set_parent(go.get_id(),go.get_id("my_parent"))
793
+ * ```ts
794
+ * // Attach myself to another instance "my_parent":
795
+ * go.set_parent(go.get_id(), go.get_id("my_parent"));
800
796
  *
801
- * Attach an instance "my_instance" to another instance "my_parent":
802
- * go.set_parent(go.get_id("my_instance"),go.get_id("my_parent"))
797
+ * // Attach an instance "my_instance" to another instance "my_parent":
798
+ * go.set_parent(go.get_id("my_instance"), go.get_id("my_parent"));
803
799
  *
804
- * Detach an instance "my_instance" from its parent (if any):
805
- * go.set_parent(go.get_id("my_instance"))
800
+ * // Detach an instance "my_instance" from its parent (if any):
801
+ * go.set_parent(go.get_id("my_instance"));
806
802
  * ```
807
803
  */
808
804
  export function set_parent(id?: string | Hash | Url, parent_id?: string | Hash | Url, keep_world_transform?: boolean): void;
@@ -812,14 +808,15 @@ declare global {
812
808
  * @param position - position to set
813
809
  * @param id - optional id of the game object instance to set the position for, by default the instance of the calling script
814
810
  * @example
815
- * ```lua
816
- * Set the position of the game object instance the script is attached to:
817
- * local p = ...
818
- * go.set_position(p)
819
- *
820
- * Set the position of another game object instance with id "x":
821
- * local p = ...
822
- * go.set_position(p, "x")
811
+ * ```ts
812
+ * // `p` is the desired position (a Vector3).
813
+ * const p = vmath.vector3();
814
+ *
815
+ * // Set the position of the game object the script is attached to:
816
+ * go.set_position(p);
817
+ *
818
+ * // Set the position of another game object with id "x":
819
+ * go.set_position(p, "x");
823
820
  * ```
824
821
  */
825
822
  export function set_position(position: Vector3, id?: string | Hash | Url): void;
@@ -829,14 +826,15 @@ declare global {
829
826
  * @param rotation - rotation to set
830
827
  * @param id - optional id of the game object instance to get the rotation for, by default the instance of the calling script
831
828
  * @example
832
- * ```lua
833
- * Set the rotation of the game object instance the script is attached to:
834
- * local r = ...
835
- * go.set_rotation(r)
836
- *
837
- * Set the rotation of another game object instance with id "x":
838
- * local r = ...
839
- * go.set_rotation(r, "x")
829
+ * ```ts
830
+ * // `r` is the desired rotation (a Quaternion).
831
+ * const r = vmath.quat();
832
+ *
833
+ * // Set the rotation of the game object the script is attached to:
834
+ * go.set_rotation(r);
835
+ *
836
+ * // Set the rotation of another game object with id "x":
837
+ * go.set_rotation(r, "x");
840
838
  * ```
841
839
  */
842
840
  export function set_rotation(rotation: Quaternion, id?: string | Hash | Url): void;
@@ -847,14 +845,14 @@ declare global {
847
845
  * @param scale - vector or uniform scale factor, must be greater than 0
848
846
  * @param id - optional id of the game object instance to get the scale for, by default the instance of the calling script
849
847
  * @example
850
- * ```lua
851
- * Set the scale of the game object instance the script is attached to:
852
- * local s = vmath.vector3(2.0, 1.0, 1.0)
853
- * go.set_scale(s)
854
- *
855
- * Set the scale of another game object instance with id "obj_id":
856
- * local s = 1.2
857
- * go.set_scale(s, "obj_id")
848
+ * ```ts
849
+ * // Set the scale of the game object the script is attached to:
850
+ * const s = vmath.vector3(2.0, 1.0, 1.0);
851
+ * go.set_scale(s);
852
+ *
853
+ * // Set the scale of another game object with id "obj_id":
854
+ * const s2 = 1.2;
855
+ * go.set_scale(s2, "obj_id");
858
856
  * ```
859
857
  */
860
858
  export function set_scale(scale: number | Vector3, id?: string | Hash | Url): void;
@@ -865,14 +863,14 @@ declare global {
865
863
  * @param scale - vector or uniform scale factor, must be greater than 0
866
864
  * @param id - optional id of the game object instance to get the scale for, by default the instance of the calling script
867
865
  * @example
868
- * ```lua
869
- * Set the scale of the game object instance the script is attached to:
870
- * local s = vmath.vector3(2.0, 1.0, 5.0)
871
- * go.set_scale_xy(s) -- z will not be set here, only x and y
872
- *
873
- * Set the scale of another game object instance with id "obj_id":
874
- * local s = 1.2
875
- * go.set_scale_xy(s, "obj_id") -- z will not be set here, only x and y
866
+ * ```ts
867
+ * // Set the scale of the game object the script is attached to:
868
+ * const s = vmath.vector3(2.0, 1.0, 5.0);
869
+ * go.set_scale_xy(s); // z will not be set here, only x and y
870
+ *
871
+ * // Set the scale of another game object with id "obj_id":
872
+ * const s2 = 1.2;
873
+ * go.set_scale_xy(s2, "obj_id"); // z will not be set here, only x and y
876
874
  * ```
877
875
  */
878
876
  export function set_scale_xy(scale: number | Vector3, id?: string | Hash | Url): void;
@@ -883,17 +881,19 @@ declare global {
883
881
  * @param self - reference to the script state to be used for storing data
884
882
  * @param dt - the time-step of the frame update
885
883
  * @example
886
- * ```lua
887
- * This example demonstrates how to move a game object instance through the script component:
888
- * function init(self)
889
- * -- set initial velocity to be 1 along world x-axis
890
- * self.my_velocity = vmath.vector3(1, 0, 0)
891
- * end
892
- *
893
- * function update(self, dt)
894
- * -- move the game object instance
895
- * go.set_position(go.get_position() + dt * self.my_velocity)
896
- * end
884
+ * ```ts
885
+ * // This example demonstrates how to move a game object instance through the script component:
886
+ * export default defineScript({
887
+ * init() {
888
+ * // set initial velocity to be 1 along world x-axis
889
+ * return { my_velocity: vmath.vector3(1, 0, 0) };
890
+ * },
891
+ *
892
+ * update(self, dt) {
893
+ * // move the game object instance
894
+ * go.set_position(go.get_position().add(self.my_velocity.mul(dt)));
895
+ * },
896
+ * });
897
897
  * ```
898
898
  */
899
899
  export function update(self: Opaque<"userdata">, dt: number): void;
@@ -908,12 +908,12 @@ declare global {
908
908
  *
909
909
  * @param id - optional id of the game object instance to update
910
910
  * @example
911
- * ```lua
912
- * Update this game object's world transform:
913
- * go.update_world_transform()
911
+ * ```ts
912
+ * // Update this game object's world transform:
913
+ * go.update_world_transform();
914
914
  *
915
- * Update another game object's world transform:
916
- * go.update_world_transform("/other")
915
+ * // Update another game object's world transform:
916
+ * go.update_world_transform("/other");
917
917
  * ```
918
918
  */
919
919
  export function update_world_transform(id?: string | Hash | Url): void;
@@ -924,11 +924,11 @@ declare global {
924
924
  * @param url - url of the game object which coordinate system convert to
925
925
  * @returns converted position
926
926
  * @example
927
- * ```lua
928
- * Convert position of "test" game object into coordinate space of "child" object.
929
- * local test_pos = go.get_world_position("/test")
930
- * local child_pos = go.get_world_position("/child")
931
- * local new_position = go.world_to_local_position(test_pos, "/child")
927
+ * ```ts
928
+ * // Convert position of "test" game object into coordinate space of "child" object.
929
+ * const test_pos = go.get_world_position("/test");
930
+ * const child_pos = go.get_world_position("/child");
931
+ * const new_position = go.world_to_local_position(test_pos, "/child");
932
932
  * ```
933
933
  */
934
934
  export function world_to_local_position(position: Vector3, url: string | Hash | Url): Vector3;
@@ -939,11 +939,11 @@ declare global {
939
939
  * @param url - url of the game object which coordinate system convert to
940
940
  * @returns converted transformation
941
941
  * @example
942
- * ```lua
943
- * Convert transformation of "test" game object into coordinate space of "child" object.
944
- * local test_transform = go.get_world_transform("/test")
945
- * local child_transform = go.get_world_transform("/child")
946
- * local result_transform = go.world_to_local_transform(test_transform, "/child")
942
+ * ```ts
943
+ * // Convert transform of "test" game object into coordinate space of "child" object.
944
+ * const test_transform = go.get_world_transform("/test");
945
+ * const child_transform = go.get_world_transform("/child");
946
+ * const result_transform = go.world_to_local_transform(test_transform, "/child");
947
947
  * ```
948
948
  */
949
949
  export function world_to_local_transform(transformation: Matrix4, url: string | Hash | Url): Matrix4;