@defold-typescript/types 0.38.0 → 0.40.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 (109) hide show
  1. package/api-availability.json +117 -0
  2. package/api-signatures.json +586 -480
  3. package/examples/translations.json +356 -180
  4. package/generated/b2d_body.d.ts +7 -4
  5. package/generated/b2d_shape.d.ts +23 -1
  6. package/generated/buffer.d.ts +34 -19
  7. package/generated/camera.d.ts +3 -2
  8. package/generated/collectionfactory.d.ts +17 -12
  9. package/generated/collectionproxy.d.ts +2 -2
  10. package/generated/compute.d.ts +1 -1
  11. package/generated/factory.d.ts +2 -1
  12. package/generated/go.d.ts +150 -91
  13. package/generated/graphics.d.ts +54 -0
  14. package/generated/gui.d.ts +117 -71
  15. package/generated/html5.d.ts +4 -2
  16. package/generated/http.d.ts +8 -2
  17. package/generated/image.d.ts +24 -15
  18. package/generated/kinds/gui-script.d.ts +1 -0
  19. package/generated/kinds/render-script.d.ts +1 -0
  20. package/generated/kinds/script.d.ts +1 -0
  21. package/generated/material.d.ts +1 -1
  22. package/generated/model.d.ts +41 -7
  23. package/generated/particlefx.d.ts +1 -1
  24. package/generated/physics.d.ts +29 -20
  25. package/generated/profiler.d.ts +10 -3
  26. package/generated/render.d.ts +293 -111
  27. package/generated/resource.d.ts +243 -226
  28. package/generated/socket.d.ts +33 -18
  29. package/generated/sound.d.ts +6 -5
  30. package/generated/sprite.d.ts +9 -1
  31. package/generated/sys.d.ts +44 -27
  32. package/generated/tilemap.d.ts +25 -19
  33. package/generated/timer.d.ts +33 -24
  34. package/generated/versions/defold-1.12.4/buffer.d.ts +34 -19
  35. package/generated/versions/defold-1.12.4/camera.d.ts +3 -2
  36. package/generated/versions/defold-1.12.4/collectionfactory.d.ts +17 -12
  37. package/generated/versions/defold-1.12.4/collectionproxy.d.ts +1 -1
  38. package/generated/versions/defold-1.12.4/factory.d.ts +2 -1
  39. package/generated/versions/defold-1.12.4/go.d.ts +150 -91
  40. package/generated/versions/defold-1.12.4/graphics.d.ts +2 -0
  41. package/generated/versions/defold-1.12.4/gui.d.ts +109 -69
  42. package/generated/versions/defold-1.12.4/html5.d.ts +4 -2
  43. package/generated/versions/defold-1.12.4/http.d.ts +8 -2
  44. package/generated/versions/defold-1.12.4/image.d.ts +24 -15
  45. package/generated/versions/defold-1.12.4/index.d.ts +1 -0
  46. package/generated/versions/defold-1.12.4/model.d.ts +41 -7
  47. package/generated/versions/defold-1.12.4/particlefx.d.ts +1 -1
  48. package/generated/versions/defold-1.12.4/physics.d.ts +29 -20
  49. package/generated/versions/defold-1.12.4/profiler.d.ts +10 -3
  50. package/generated/versions/defold-1.12.4/render.d.ts +292 -110
  51. package/generated/versions/defold-1.12.4/resource.d.ts +243 -226
  52. package/generated/versions/defold-1.12.4/socket.d.ts +33 -18
  53. package/generated/versions/defold-1.12.4/sound.d.ts +6 -5
  54. package/generated/versions/defold-1.12.4/sprite.d.ts +9 -1
  55. package/generated/versions/defold-1.12.4/sys.d.ts +44 -27
  56. package/generated/versions/defold-1.12.4/tilemap.d.ts +25 -19
  57. package/generated/versions/defold-1.12.4/timer.d.ts +33 -24
  58. package/generated/versions/defold-1.12.4/vmath.d.ts +18 -10
  59. package/generated/versions/defold-1.12.4/window.d.ts +5 -3
  60. package/generated/versions/defold-1.13.0/b2d_body.d.ts +7 -4
  61. package/generated/versions/defold-1.13.0/b2d_shape.d.ts +23 -1
  62. package/generated/versions/defold-1.13.0/buffer.d.ts +34 -19
  63. package/generated/versions/defold-1.13.0/camera.d.ts +3 -2
  64. package/generated/versions/defold-1.13.0/collectionfactory.d.ts +17 -12
  65. package/generated/versions/defold-1.13.0/collectionproxy.d.ts +1 -1
  66. package/generated/versions/defold-1.13.0/compute.d.ts +1 -1
  67. package/generated/versions/defold-1.13.0/factory.d.ts +2 -1
  68. package/generated/versions/defold-1.13.0/go.d.ts +150 -91
  69. package/generated/versions/defold-1.13.0/graphics.d.ts +50 -0
  70. package/generated/versions/defold-1.13.0/gui.d.ts +109 -69
  71. package/generated/versions/defold-1.13.0/html5.d.ts +4 -2
  72. package/generated/versions/defold-1.13.0/http.d.ts +8 -2
  73. package/generated/versions/defold-1.13.0/image.d.ts +24 -15
  74. package/generated/versions/defold-1.13.0/index.d.ts +1 -0
  75. package/generated/versions/defold-1.13.0/material.d.ts +1 -1
  76. package/generated/versions/defold-1.13.0/model.d.ts +41 -7
  77. package/generated/versions/defold-1.13.0/particlefx.d.ts +1 -1
  78. package/generated/versions/defold-1.13.0/physics.d.ts +29 -20
  79. package/generated/versions/defold-1.13.0/profiler.d.ts +10 -3
  80. package/generated/versions/defold-1.13.0/render.d.ts +293 -111
  81. package/generated/versions/defold-1.13.0/resource.d.ts +243 -226
  82. package/generated/versions/defold-1.13.0/socket.d.ts +33 -18
  83. package/generated/versions/defold-1.13.0/sound.d.ts +6 -5
  84. package/generated/versions/defold-1.13.0/sprite.d.ts +9 -1
  85. package/generated/versions/defold-1.13.0/sys.d.ts +44 -27
  86. package/generated/versions/defold-1.13.0/tilemap.d.ts +25 -19
  87. package/generated/versions/defold-1.13.0/timer.d.ts +33 -24
  88. package/generated/versions/defold-1.13.0/vmath.d.ts +18 -10
  89. package/generated/versions/defold-1.13.0/window.d.ts +5 -3
  90. package/generated/vmath.d.ts +18 -10
  91. package/generated/window.d.ts +5 -3
  92. package/index.d.ts +1 -0
  93. package/package.json +2 -1
  94. package/scripts/generate-api-signatures.ts +2 -1
  95. package/scripts/prose-constants.ts +96 -0
  96. package/scripts/regen.ts +6 -2
  97. package/src/api-doc.ts +8 -0
  98. package/src/component-properties.d.ts +33 -0
  99. package/src/core-types.ts +4 -2
  100. package/src/custom-messages.d.ts +4 -3
  101. package/src/doc-comment.ts +247 -43
  102. package/src/emit-dts.ts +958 -57
  103. package/src/engine-globals.d.ts +2 -2
  104. package/src/example-store.ts +26 -0
  105. package/src/go-overloads.d.ts +11 -10
  106. package/src/index.ts +9 -0
  107. package/src/param-correction-provenance.ts +67 -0
  108. package/src/render-overloads.d.ts +15 -17
  109. package/src/script-api.ts +3 -1
@@ -7,6 +7,7 @@ declare global {
7
7
  * used to dynamically spawn collections into the runtime.
8
8
  */
9
9
  namespace collectionfactory {
10
+ type Status = typeof collectionfactory.STATUS_UNLOADED | typeof collectionfactory.STATUS_LOADING | typeof collectionfactory.STATUS_LOADED;
10
11
  /**
11
12
  * loaded
12
13
  */
@@ -45,18 +46,17 @@ declare global {
45
46
  * ```ts
46
47
  * // How to spawn a collection of game objects:
47
48
  * export default defineScript({
48
- * init(self) {
49
+ * init() {
49
50
  * // Spawn a small group of enemies.
50
51
  * const pos = vmath.vector3(100, 12.5, 0);
51
52
  * const rot = vmath.quat_rotation_z(Math.PI / 2);
52
53
  * const scale = 0.5;
53
- * const props = {
54
- * [hash("/enemy_leader")]: { health: 1000.0 },
55
- * [hash("/enemy_1")]: { health: 200.0 },
56
- * [hash("/enemy_2")]: { health: 400.0, color: hash("green") },
57
- * };
54
+ * const props = new LuaMap<Hash, Record<string, unknown>>();
55
+ * props.set(hash("/enemy_leader"), { health: 1000.0 });
56
+ * props.set(hash("/enemy_1"), { health: 200.0 });
57
+ * props.set(hash("/enemy_2"), { health: 400.0, color: hash("green") });
58
58
  *
59
- * self.enemy_ids = collectionfactory.create("#enemyfactory", pos, rot, props, scale);
59
+ * const enemy_ids = collectionfactory.create("#enemyfactory", pos, rot, props, scale);
60
60
  * // enemy_ids now map to the spawned instance ids:
61
61
  * //
62
62
  * // pprint(self.enemy_ids)
@@ -69,16 +69,21 @@ declare global {
69
69
  * // }
70
70
  *
71
71
  * // Send "attack" message to the leader. First look up its instance id.
72
- * const leader_id = self.enemy_ids[hash("/enemy_leader")];
73
- * msg.post(leader_id, "attack");
72
+ * const leader_id = enemy_ids.get(hash("/enemy_leader"));
73
+ * if (leader_id !== undefined) {
74
+ * msg.post(leader_id, "attack");
75
+ * }
76
+ * return { enemy_ids };
74
77
  * },
75
78
  * });
76
79
  *
77
80
  * // How to delete a spawned collection:
78
- * go.delete(self.enemy_ids);
81
+ * function delete_enemies(self: { enemy_ids: Hash[] }) {
82
+ * go.delete(self.enemy_ids);
83
+ * }
79
84
  * ```
80
85
  */
81
- function create(url: string | Hash | Url, position?: Vector3, rotation?: Quaternion, properties?: Record<string | number, unknown>, scale?: number | Vector3): LuaMap<Hash, Hash>;
86
+ function create(url: string | Hash | Url, position?: Vector3, rotation?: Quaternion, properties?: LuaMap<Hash, Record<string | number, unknown>> | Record<string, Record<string | number, unknown>>, scale?: number | Vector3): LuaMap<Hash, Hash>;
82
87
  /**
83
88
  * This returns status of the collection factory.
84
89
  * Calling this function when the factory is not marked as dynamic loading always returns COMP_COLLECTION_FACTORY_STATUS_LOADED.
@@ -92,7 +97,7 @@ declare global {
92
97
  *
93
98
  * - `collectionfactory.STATUS_LOADED`
94
99
  */
95
- function get_status(url?: string | Hash | Url): number & { readonly __brand: "collectionfactory.STATUS_UNLOADED" } | number & { readonly __brand: "collectionfactory.STATUS_LOADING" } | number & { readonly __brand: "collectionfactory.STATUS_LOADED" };
100
+ function get_status(url?: string | Hash | Url): collectionfactory.Status;
96
101
  /**
97
102
  * Resources loaded are referenced by the collection factory component until the existing (parent) collection is destroyed or collectionfactory.unload is called.
98
103
  * Calling this function when the factory is not marked as dynamic loading does nothing.
@@ -32,7 +32,7 @@ declare global {
32
32
  * collection was not excluded.
33
33
  * @example
34
34
  * ```ts
35
- * function print_resources(self, cproxy) {
35
+ * function print_resources(self: unknown, cproxy: Url) {
36
36
  * const resources = collectionproxy.get_resources(cproxy);
37
37
  * for (const v of resources) {
38
38
  * print(`Resource: ${v}`);
@@ -7,6 +7,7 @@ declare global {
7
7
  * dynamically spawn game objects into the runtime.
8
8
  */
9
9
  namespace factory {
10
+ type Status = typeof factory.STATUS_UNLOADED | typeof factory.STATUS_LOADING | typeof factory.STATUS_LOADED;
10
11
  /**
11
12
  * loaded
12
13
  */
@@ -71,7 +72,7 @@ declare global {
71
72
  *
72
73
  * - `factory.STATUS_LOADED`
73
74
  */
74
- function get_status(url?: string | Hash | Url): number & { readonly __brand: "factory.STATUS_UNLOADED" } | number & { readonly __brand: "factory.STATUS_LOADING" } | number & { readonly __brand: "factory.STATUS_LOADED" };
75
+ function get_status(url?: string | Hash | Url): factory.Status;
75
76
  /**
76
77
  * Resources are referenced by the factory component until the existing (parent) collection is destroyed or factory.unload is called.
77
78
  * Calling this function when the factory is not marked as dynamic loading does nothing.
@@ -8,6 +8,8 @@ declare global {
8
8
  * files.
9
9
  */
10
10
  namespace go {
11
+ export type Easing = typeof go.EASING_INBACK | typeof go.EASING_INBOUNCE | typeof go.EASING_INCIRC | typeof go.EASING_INCUBIC | typeof go.EASING_INELASTIC | typeof go.EASING_INEXPO | typeof go.EASING_INOUTBACK | typeof go.EASING_INOUTBOUNCE | typeof go.EASING_INOUTCIRC | typeof go.EASING_INOUTCUBIC | typeof go.EASING_INOUTELASTIC | typeof go.EASING_INOUTEXPO | typeof go.EASING_INOUTQUAD | typeof go.EASING_INOUTQUART | typeof go.EASING_INOUTQUINT | typeof go.EASING_INOUTSINE | typeof go.EASING_INQUAD | typeof go.EASING_INQUART | typeof go.EASING_INQUINT | typeof go.EASING_INSINE | typeof go.EASING_LINEAR | typeof go.EASING_OUTBACK | typeof go.EASING_OUTBOUNCE | typeof go.EASING_OUTCIRC | typeof go.EASING_OUTCUBIC | typeof go.EASING_OUTELASTIC | typeof go.EASING_OUTEXPO | typeof go.EASING_OUTINBACK | typeof go.EASING_OUTINBOUNCE | typeof go.EASING_OUTINCIRC | typeof go.EASING_OUTINCUBIC | typeof go.EASING_OUTINELASTIC | typeof go.EASING_OUTINEXPO | typeof go.EASING_OUTINQUAD | typeof go.EASING_OUTINQUART | typeof go.EASING_OUTINQUINT | typeof go.EASING_OUTINSINE | typeof go.EASING_OUTQUAD | typeof go.EASING_OUTQUART | typeof go.EASING_OUTQUINT | typeof go.EASING_OUTSINE;
12
+ export type Playback = typeof go.PLAYBACK_ONCE_FORWARD | typeof go.PLAYBACK_ONCE_BACKWARD | typeof go.PLAYBACK_ONCE_PINGPONG | typeof go.PLAYBACK_LOOP_FORWARD | typeof go.PLAYBACK_LOOP_BACKWARD | typeof go.PLAYBACK_LOOP_PINGPONG;
11
13
  /**
12
14
  * in-back
13
15
  */
@@ -243,14 +245,15 @@ declare global {
243
245
  *
244
246
  * hash The id of the animated property.
245
247
  * @example
248
+ * Animate the position of a game object to x = 10 during 1 second, then y = 20 during 1 second:
246
249
  * ```ts
247
- * // Animate the position of a game object to x = 10 during 1 second, then
248
- * // y = 20 during 1 second:
249
250
  * go.animate(go.get_id(), "position.x", go.PLAYBACK_ONCE_FORWARD, 10, go.EASING_LINEAR, 1, 0, () => {
250
251
  * go.animate(go.get_id(), "position.y", go.PLAYBACK_ONCE_FORWARD, 20, go.EASING_LINEAR, 1);
251
252
  * });
252
- *
253
- * // Animate the y position of a game object using a crazy custom easing curve:
253
+ * ```
254
+ * @example
255
+ * Animate the y position of a game object using a crazy custom easing curve:
256
+ * ```ts
254
257
  * const values = [
255
258
  * 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
256
259
  * 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -261,7 +264,7 @@ declare global {
261
264
  * go.animate("go", "position.y", go.PLAYBACK_LOOP_PINGPONG, 100, vec, 2.0);
262
265
  * ```
263
266
  */
264
- export function animate(url: SceneAddress | 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;
267
+ export function animate(url: SceneAddress | Hash | Url, property: string | Hash, playback: go.Playback, to: number | Vector3 | Vector4 | Quaternion, easing: Vector | go.Easing, duration: number, delay?: number, complete_function?: (self: unknown, url: unknown, property: unknown) => void): void;
265
268
  /**
266
269
  * By calling this function, all or specified stored property animations of the game object or component will be canceled.
267
270
  * See the properties guide for which properties can be animated and the animation guide for how to animate them.
@@ -269,14 +272,18 @@ declare global {
269
272
  * @param url - url of the game object or component
270
273
  * @param property - optional id of the property to cancel
271
274
  * @example
275
+ * Cancel the animation of the position of a game object:
272
276
  * ```ts
273
- * // Cancel the animation of the position of a game object:
274
277
  * go.cancel_animations(go.get_id(), "position");
275
- *
276
- * // Cancel all property animations of the current game object:
278
+ * ```
279
+ * @example
280
+ * Cancel all property animations of the current game object:
281
+ * ```ts
277
282
  * go.cancel_animations(".");
278
- *
279
- * // Cancel all property animations of the sprite component of the current game object:
283
+ * ```
284
+ * @example
285
+ * Cancel all property animations of the sprite component of the current game object:
286
+ * ```ts
280
287
  * go.cancel_animations("#sprite");
281
288
  * ```
282
289
  */
@@ -292,8 +299,8 @@ declare global {
292
299
  * @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
293
300
  * @param recursive - optional boolean, set to true to recursively delete child hiearchy in child to parent order
294
301
  * @example
302
+ * This example demonstrates how to delete game objects
295
303
  * ```ts
296
- * // This example demonstrates how to delete game objects:
297
304
  * // Delete the script's own game object.
298
305
  * go.delete();
299
306
  * // Delete a game object with the id "my_game_object".
@@ -302,20 +309,21 @@ declare global {
302
309
  * // Delete a list of game objects.
303
310
  * const ids = [hash("/my_object_1"), hash("/my_object_2"), hash("/my_object_3")];
304
311
  * go.delete(ids);
305
- *
306
- * // This example demonstrates how to delete game objects and their children
307
- * // (child-to-parent order):
312
+ * ```
313
+ * @example
314
+ * This example demonstrates how to delete a game objects and their children (child to parent order)
315
+ * ```ts
308
316
  * // Delete the script's own game object and its children.
309
317
  * go.delete(true);
310
318
  * // Delete a game object with the id "my_game_object" and its children.
311
- * const id2 = go.get_id("my_game_object");
312
- * go.delete(id2, true);
319
+ * const id = go.get_id("my_game_object");
320
+ * go.delete(id, true);
313
321
  * // Delete a list of game objects and their children.
314
- * const ids2 = [hash("/my_object_1"), hash("/my_object_2"), hash("/my_object_3")];
315
- * go.delete(ids2, true);
322
+ * const ids = [hash("/my_object_1"), hash("/my_object_2"), hash("/my_object_3")];
323
+ * go.delete(ids, true);
316
324
  * ```
317
325
  */
318
- function _delete(id?: SceneGameObjectAddress | Hash | Url | (SceneGameObjectAddress | Hash | Url)[], recursive?: boolean): void;
326
+ function _delete(id?: SceneGameObjectAddress | Hash | Url | (SceneGameObjectAddress | Hash | Url)[] | boolean, recursive?: boolean): void;
319
327
  /**
320
328
  * This function can check for game objects in any collection by specifying
321
329
  * the collection name in the URL.
@@ -323,11 +331,13 @@ declare global {
323
331
  * @param url - url of the game object to check
324
332
  * @returns true if the game object exists
325
333
  * @example
334
+ * Check if game object "my_game_object" exists in the current collection
326
335
  * ```ts
327
- * // Check if game object "my_game_object" exists in the current collection:
328
336
  * go.exists("/my_game_object");
329
- *
330
- * // Check if game object exists in another collection:
337
+ * ```
338
+ * @example
339
+ * Check if game object exists in another collection
340
+ * ```ts
331
341
  * go.exists("other_collection:/my_game_object");
332
342
  * ```
333
343
  */
@@ -341,6 +351,10 @@ declare global {
341
351
  * @example
342
352
  * ```ts
343
353
  * export default defineScript({
354
+ * init() {
355
+ * return { some_value: 0 };
356
+ * },
357
+ *
344
358
  * final(self) {
345
359
  * // report finalization
346
360
  * msg.post("my_friend_instance", "im_dead", { my_stats: self.some_value });
@@ -390,12 +404,14 @@ declare global {
390
404
  * @param id - optional id of the game object instance to get parent for, defaults to the instance containing the calling script
391
405
  * @returns parent instance or `nil`
392
406
  * @example
407
+ * Get parent of the instance containing the calling script:
393
408
  * ```ts
394
- * // Get parent of the instance containing the calling script:
395
409
  * const parent_id = go.get_parent();
396
- *
397
- * // Get parent of the instance with id "x":
398
- * const parent_id2 = go.get_parent("x");
410
+ * ```
411
+ * @example
412
+ * Get parent of the instance with id "x":
413
+ * ```ts
414
+ * const parent_id = go.get_parent("x");
399
415
  * ```
400
416
  */
401
417
  export function get_parent(id?: SceneGameObjectAddress | Hash | Url): Hash | undefined;
@@ -405,11 +421,13 @@ declare global {
405
421
  * @param id - optional id of the game object instance to get the position for, by default the instance of the calling script
406
422
  * @returns instance position
407
423
  * @example
424
+ * Get the position of the game object instance the script is attached to:
408
425
  * ```ts
409
- * // Get the position of the game object the script is attached to:
410
426
  * const p = go.get_position();
411
- *
412
- * // Get the position of another game object "my_gameobject":
427
+ * ```
428
+ * @example
429
+ * Get the position of another game object instance "my_gameobject":
430
+ * ```ts
413
431
  * const pos = go.get_position("my_gameobject");
414
432
  * ```
415
433
  */
@@ -420,12 +438,14 @@ declare global {
420
438
  * @param id - optional id of the game object instance to get the rotation for, by default the instance of the calling script
421
439
  * @returns instance rotation
422
440
  * @example
441
+ * Get the rotation of the game object instance the script is attached to:
423
442
  * ```ts
424
- * // Get the rotation of the game object the script is attached to:
425
443
  * const r = go.get_rotation();
426
- *
427
- * // Get the rotation of another game object with id "x":
428
- * const r2 = go.get_rotation("x");
444
+ * ```
445
+ * @example
446
+ * Get the rotation of another game object instance with id "x":
447
+ * ```ts
448
+ * const r = go.get_rotation("x");
429
449
  * ```
430
450
  */
431
451
  export function get_rotation(id?: SceneGameObjectAddress | Hash | Url): Quaternion;
@@ -435,12 +455,14 @@ declare global {
435
455
  * @param id - optional id of the game object instance to get the scale for, by default the instance of the calling script
436
456
  * @returns instance scale factor
437
457
  * @example
458
+ * Get the scale of the game object instance the script is attached to:
438
459
  * ```ts
439
- * // Get the scale of the game object the script is attached to:
440
460
  * const s = go.get_scale();
441
- *
442
- * // Get the scale of another game object with id "x":
443
- * const s2 = go.get_scale("x");
461
+ * ```
462
+ * @example
463
+ * Get the scale of another game object instance with id "x":
464
+ * ```ts
465
+ * const s = go.get_scale("x");
444
466
  * ```
445
467
  */
446
468
  export function get_scale(id?: SceneGameObjectAddress | Hash | Url): Vector3;
@@ -450,12 +472,14 @@ declare global {
450
472
  * @param id - optional id of the game object instance to get the uniform scale for, by default the instance of the calling script
451
473
  * @returns uniform instance scale factor
452
474
  * @example
475
+ * Get the scale of the game object instance the script is attached to:
453
476
  * ```ts
454
- * // Get the uniform scale of the game object the script is attached to:
455
477
  * const s = go.get_scale_uniform();
456
- *
457
- * // Get the uniform scale of another game object with id "x":
458
- * const s2 = go.get_scale_uniform("x");
478
+ * ```
479
+ * @example
480
+ * Get the uniform scale of another game object instance with id "x":
481
+ * ```ts
482
+ * const s = go.get_scale_uniform("x");
459
483
  * ```
460
484
  */
461
485
  export function get_scale_uniform(id?: SceneGameObjectAddress | Hash | Url): number;
@@ -467,12 +491,15 @@ declare global {
467
491
  * @param id - optional id of the game object instance to get the world position for, by default the instance of the calling script
468
492
  * @returns instance world position
469
493
  * @example
494
+ * Get the world position of the game object instance the script is attached to:
470
495
  * ```ts
471
- * // Get the world position of the game object the script is attached to:
472
496
  * const p = go.get_world_position();
473
- *
474
- * // Reach a sibling game object by its id — relative addressing, no socket prefix:
475
- * const p2 = go.get_world_position("x");
497
+ * ```
498
+ * @example
499
+ * Get the world position of another game object instance with id "x":
500
+ * ```ts
501
+ * // Relative addressing by id — no socket prefix:
502
+ * const p = go.get_world_position("x");
476
503
  * ```
477
504
  */
478
505
  export function get_world_position(id?: SceneGameObjectAddress | Hash | Url): Vector3;
@@ -484,12 +511,14 @@ declare global {
484
511
  * @param id - optional id of the game object instance to get the world rotation for, by default the instance of the calling script
485
512
  * @returns instance world rotation
486
513
  * @example
514
+ * Get the world rotation of the game object instance the script is attached to:
487
515
  * ```ts
488
- * // Get the world rotation of the game object the script is attached to:
489
516
  * const r = go.get_world_rotation();
490
- *
491
- * // Get the world rotation of another game object with id "x":
492
- * const r2 = go.get_world_rotation("x");
517
+ * ```
518
+ * @example
519
+ * Get the world rotation of another game object instance with id "x":
520
+ * ```ts
521
+ * const r = go.get_world_rotation("x");
493
522
  * ```
494
523
  */
495
524
  export function get_world_rotation(id?: SceneGameObjectAddress | Hash | Url): Quaternion;
@@ -503,12 +532,14 @@ declare global {
503
532
  * @param id - optional id of the game object instance to get the world scale for, by default the instance of the calling script
504
533
  * @returns instance world 3D scale factor
505
534
  * @example
535
+ * Get the world 3D scale of the game object instance the script is attached to:
506
536
  * ```ts
507
- * // Get the world 3D scale of the game object the script is attached to:
508
537
  * const s = go.get_world_scale();
509
- *
510
- * // Get the world scale of another game object "x":
511
- * const s2 = go.get_world_scale("x");
538
+ * ```
539
+ * @example
540
+ * Get the world scale of another game object instance "x":
541
+ * ```ts
542
+ * const s = go.get_world_scale("x");
512
543
  * ```
513
544
  */
514
545
  export function get_world_scale(id?: SceneGameObjectAddress | Hash | Url): Vector3;
@@ -520,12 +551,14 @@ declare global {
520
551
  * @param id - optional id of the game object instance to get the world scale for, by default the instance of the calling script
521
552
  * @returns instance world scale factor
522
553
  * @example
554
+ * Get the world scale of the game object instance the script is attached to:
523
555
  * ```ts
524
- * // Get the world uniform scale of the game object the script is attached to:
525
556
  * const s = go.get_world_scale_uniform();
526
- *
527
- * // Get the world uniform scale of another game object with id "x":
528
- * const s2 = go.get_world_scale_uniform("x");
557
+ * ```
558
+ * @example
559
+ * Get the world scale of another game object instance with id "x":
560
+ * ```ts
561
+ * const s = go.get_world_scale_uniform("x");
529
562
  * ```
530
563
  */
531
564
  export function get_world_scale_uniform(id?: SceneGameObjectAddress | Hash | Url): number;
@@ -536,12 +569,14 @@ declare global {
536
569
  * @param id - optional id of the game object instance to get the world transform for, by default the instance of the calling script
537
570
  * @returns instance world transform
538
571
  * @example
572
+ * Get the world transform of the game object instance the script is attached to:
539
573
  * ```ts
540
- * // Get the world transform of the game object the script is attached to:
541
574
  * const m = go.get_world_transform();
542
- *
543
- * // Get the world transform of another game object with id "x":
544
- * const m2 = go.get_world_transform("x");
575
+ * ```
576
+ * @example
577
+ * Get the world transform of another game object instance with id "x":
578
+ * ```ts
579
+ * const m = go.get_world_transform("x");
545
580
  * ```
546
581
  */
547
582
  export function get_world_transform(id?: SceneGameObjectAddress | Hash | Url): Matrix4;
@@ -735,7 +770,7 @@ declare global {
735
770
  * self.velocity = vmath.vector3();
736
771
  * } else {
737
772
  * // update velocity
738
- * self.velocity = vmath.vector3(action.value * self.max_speed, 0, 0);
773
+ * self.velocity = vmath.vector3((action.value ?? 0) * self.max_speed, 0, 0);
739
774
  * }
740
775
  * }
741
776
  * },
@@ -754,6 +789,9 @@ declare global {
754
789
  * @param message - a table containing the message data
755
790
  * @param sender - address of the sender
756
791
  * @example
792
+ * This example demonstrates how a game object instance, called "a", can communicate with another instance, called "b". It
793
+ * is assumed that both script components of the instances has id "script".
794
+ * Script of instance "a":
757
795
  * ```ts
758
796
  * // This example demonstrates how a game object instance, called "a", can communicate with another instance, called "b". It
759
797
  * // is assumed that both script components of the instances has id "script".
@@ -765,18 +803,21 @@ declare global {
765
803
  * msg.post("b#script", "my_data", { important_value: 1 });
766
804
  * },
767
805
  * });
768
- *
806
+ * ```
807
+ * @example
808
+ * Script of instance "b":
809
+ * ```ts
769
810
  * // b.script — Script of instance "b":
770
811
  * export default defineScript({
771
812
  * init() {
772
813
  * // store the url of instance "a" for later use, by specifying undefined as socket we
773
814
  * // automatically use our own socket
774
- * return { a_url: msg.url(undefined, go.get_id("a"), "script") };
815
+ * return { a_url: msg.url(undefined, go.get_id("a"), "script"), important_value: 0 };
775
816
  * },
776
817
  *
777
818
  * on_message(self, message_id, message, sender) {
778
819
  * // check message and sender
779
- * if (message_id === hash("my_data") && sender === self.a_url) {
820
+ * if (message_id === hash("my_data") && sender === self.a_url && typeof message.important_value === "number") {
780
821
  * // use the data in some way
781
822
  * self.important_value = message.important_value;
782
823
  * }
@@ -818,7 +859,7 @@ declare global {
818
859
  * self.velocity = vmath.vector3();
819
860
  * } else {
820
861
  * // update velocity
821
- * self.velocity = vmath.vector3(action.value * self.max_speed, 0, 0);
862
+ * self.velocity = vmath.vector3((action.value ?? 0) * self.max_speed, 0, 0);
822
863
  * }
823
864
  * }
824
865
  * },
@@ -843,14 +884,18 @@ declare global {
843
884
  * @param parent_id - optional id of the new parent game object, defaults to detaching game object from its parent
844
885
  * @param keep_world_transform - optional boolean, set to true to maintain the world transform when changing spaces. Defaults to false.
845
886
  * @example
887
+ * Attach myself to another instance "my_parent":
846
888
  * ```ts
847
- * // Attach myself to another instance "my_parent":
848
889
  * go.set_parent(go.get_id(), go.get_id("my_parent"));
849
- *
850
- * // Attach an instance "my_instance" to another instance "my_parent":
890
+ * ```
891
+ * @example
892
+ * Attach an instance "my_instance" to another instance "my_parent":
893
+ * ```ts
851
894
  * go.set_parent(go.get_id("my_instance"), go.get_id("my_parent"));
852
- *
853
- * // Detach an instance "my_instance" from its parent (if any):
895
+ * ```
896
+ * @example
897
+ * Detach an instance "my_instance" from its parent (if any):
898
+ * ```ts
854
899
  * go.set_parent(go.get_id("my_instance"));
855
900
  * ```
856
901
  */
@@ -861,14 +906,19 @@ declare global {
861
906
  * @param position - position to set
862
907
  * @param id - optional id of the game object instance to set the position for, by default the instance of the calling script
863
908
  * @example
909
+ * Set the position of the game object instance the script is attached to:
864
910
  * ```ts
865
911
  * // `p` is the desired position (a Vector3).
866
912
  * const p = vmath.vector3();
867
- *
868
- * // Set the position of the game object the script is attached to:
869
913
  * go.set_position(p);
914
+ * ```
915
+ * @example
916
+ * Set the position of another game object instance with id "x":
917
+ * ```ts
918
+ * // `p` is the desired position (a Vector3).
919
+ * const p = vmath.vector3();
870
920
  *
871
- * // Reach a sibling game object by its id — relative addressing, no socket prefix:
921
+ * // Relative addressing by id — no socket prefix:
872
922
  * go.set_position(p, "x");
873
923
  * ```
874
924
  */
@@ -879,14 +929,17 @@ declare global {
879
929
  * @param rotation - rotation to set
880
930
  * @param id - optional id of the game object instance to get the rotation for, by default the instance of the calling script
881
931
  * @example
932
+ * Set the rotation of the game object instance the script is attached to:
882
933
  * ```ts
883
934
  * // `r` is the desired rotation (a Quaternion).
884
935
  * const r = vmath.quat();
885
- *
886
- * // Set the rotation of the game object the script is attached to:
887
936
  * go.set_rotation(r);
888
- *
889
- * // Set the rotation of another game object with id "x":
937
+ * ```
938
+ * @example
939
+ * Set the rotation of another game object instance with id "x":
940
+ * ```ts
941
+ * // `r` is the desired rotation (a Quaternion).
942
+ * const r = vmath.quat();
890
943
  * go.set_rotation(r, "x");
891
944
  * ```
892
945
  */
@@ -898,14 +951,16 @@ declare global {
898
951
  * @param scale - vector or uniform scale factor, must be greater than 0
899
952
  * @param id - optional id of the game object instance to get the scale for, by default the instance of the calling script
900
953
  * @example
954
+ * Set the scale of the game object instance the script is attached to:
901
955
  * ```ts
902
- * // Set the scale of the game object the script is attached to:
903
956
  * const s = vmath.vector3(2.0, 1.0, 1.0);
904
957
  * go.set_scale(s);
905
- *
906
- * // Set the scale of another game object with id "obj_id":
907
- * const s2 = 1.2;
908
- * go.set_scale(s2, "obj_id");
958
+ * ```
959
+ * @example
960
+ * Set the scale of another game object instance with id "obj_id":
961
+ * ```ts
962
+ * const s = 1.2;
963
+ * go.set_scale(s, "obj_id");
909
964
  * ```
910
965
  */
911
966
  export function set_scale(scale: number | Vector3, id?: SceneGameObjectAddress | Hash | Url): void;
@@ -916,14 +971,16 @@ declare global {
916
971
  * @param scale - vector or uniform scale factor, must be greater than 0
917
972
  * @param id - optional id of the game object instance to get the scale for, by default the instance of the calling script
918
973
  * @example
974
+ * Set the scale of the game object instance the script is attached to:
919
975
  * ```ts
920
- * // Set the scale of the game object the script is attached to:
921
976
  * const s = vmath.vector3(2.0, 1.0, 5.0);
922
977
  * go.set_scale_xy(s); // z will not be set here, only x and y
923
- *
924
- * // Set the scale of another game object with id "obj_id":
925
- * const s2 = 1.2;
926
- * go.set_scale_xy(s2, "obj_id"); // z will not be set here, only x and y
978
+ * ```
979
+ * @example
980
+ * Set the scale of another game object instance with id "obj_id":
981
+ * ```ts
982
+ * const s = 1.2;
983
+ * go.set_scale_xy(s, "obj_id"); // z will not be set here, only x and y
927
984
  * ```
928
985
  */
929
986
  export function set_scale_xy(scale: number | Vector3, id?: SceneGameObjectAddress | Hash | Url): void;
@@ -961,11 +1018,13 @@ declare global {
961
1018
  *
962
1019
  * @param id - optional id of the game object instance to update
963
1020
  * @example
1021
+ * Update this game object's world transform:
964
1022
  * ```ts
965
- * // Update this game object's world transform:
966
1023
  * go.update_world_transform();
967
- *
968
- * // Update another game object's world transform:
1024
+ * ```
1025
+ * @example
1026
+ * Update another game object's world transform:
1027
+ * ```ts
969
1028
  * go.update_world_transform("/other");
970
1029
  * ```
971
1030
  */
@@ -4,6 +4,8 @@ declare global {
4
4
  * Graphics functions and constants.
5
5
  */
6
6
  namespace graphics {
7
+ type BufferType = typeof graphics.BUFFER_TYPE_COLOR0_BIT | typeof graphics.BUFFER_TYPE_COLOR1_BIT | typeof graphics.BUFFER_TYPE_COLOR2_BIT | typeof graphics.BUFFER_TYPE_COLOR3_BIT | typeof graphics.BUFFER_TYPE_DEPTH_BIT | typeof graphics.BUFFER_TYPE_STENCIL_BIT;
8
+ type State = typeof graphics.STATE_DEPTH_TEST | typeof graphics.STATE_STENCIL_TEST | typeof graphics.STATE_BLEND | typeof graphics.STATE_ALPHA_TEST | typeof graphics.STATE_CULL_FACE | typeof graphics.STATE_POLYGON_OFFSET_FILL;
7
9
  const BLEND_FACTOR_CONSTANT_ALPHA: number & { readonly __brand: "graphics.BLEND_FACTOR_CONSTANT_ALPHA" };
8
10
  const BLEND_FACTOR_CONSTANT_COLOR: number & { readonly __brand: "graphics.BLEND_FACTOR_CONSTANT_COLOR" };
9
11
  const BLEND_FACTOR_DST_ALPHA: number & { readonly __brand: "graphics.BLEND_FACTOR_DST_ALPHA" };