@defold-typescript/types 0.39.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 (87) hide show
  1. package/api-availability.json +117 -0
  2. package/api-signatures.json +262 -237
  3. package/examples/translations.json +81 -81
  4. package/generated/b2d_shape.d.ts +23 -1
  5. package/generated/buffer.d.ts +18 -15
  6. package/generated/camera.d.ts +2 -2
  7. package/generated/collectionfactory.d.ts +12 -10
  8. package/generated/collectionproxy.d.ts +1 -1
  9. package/generated/compute.d.ts +1 -1
  10. package/generated/go.d.ts +9 -5
  11. package/generated/graphics.d.ts +52 -0
  12. package/generated/gui.d.ts +53 -32
  13. package/generated/html5.d.ts +3 -1
  14. package/generated/http.d.ts +4 -2
  15. package/generated/image.d.ts +24 -15
  16. package/generated/kinds/gui-script.d.ts +1 -0
  17. package/generated/kinds/render-script.d.ts +1 -0
  18. package/generated/kinds/script.d.ts +1 -0
  19. package/generated/material.d.ts +1 -1
  20. package/generated/model.d.ts +32 -3
  21. package/generated/physics.d.ts +13 -11
  22. package/generated/profiler.d.ts +1 -1
  23. package/generated/render.d.ts +72 -15
  24. package/generated/resource.d.ts +100 -69
  25. package/generated/socket.d.ts +23 -13
  26. package/generated/sound.d.ts +3 -3
  27. package/generated/sprite.d.ts +9 -1
  28. package/generated/sys.d.ts +34 -23
  29. package/generated/versions/defold-1.12.4/buffer.d.ts +18 -15
  30. package/generated/versions/defold-1.12.4/camera.d.ts +2 -2
  31. package/generated/versions/defold-1.12.4/collectionfactory.d.ts +12 -10
  32. package/generated/versions/defold-1.12.4/go.d.ts +9 -5
  33. package/generated/versions/defold-1.12.4/gui.d.ts +47 -31
  34. package/generated/versions/defold-1.12.4/html5.d.ts +3 -1
  35. package/generated/versions/defold-1.12.4/http.d.ts +4 -2
  36. package/generated/versions/defold-1.12.4/image.d.ts +24 -15
  37. package/generated/versions/defold-1.12.4/index.d.ts +1 -0
  38. package/generated/versions/defold-1.12.4/model.d.ts +32 -3
  39. package/generated/versions/defold-1.12.4/physics.d.ts +13 -11
  40. package/generated/versions/defold-1.12.4/profiler.d.ts +1 -1
  41. package/generated/versions/defold-1.12.4/render.d.ts +72 -15
  42. package/generated/versions/defold-1.12.4/resource.d.ts +100 -69
  43. package/generated/versions/defold-1.12.4/socket.d.ts +23 -13
  44. package/generated/versions/defold-1.12.4/sound.d.ts +3 -3
  45. package/generated/versions/defold-1.12.4/sprite.d.ts +9 -1
  46. package/generated/versions/defold-1.12.4/sys.d.ts +34 -23
  47. package/generated/versions/defold-1.12.4/vmath.d.ts +5 -5
  48. package/generated/versions/defold-1.13.0/b2d_shape.d.ts +23 -1
  49. package/generated/versions/defold-1.13.0/buffer.d.ts +18 -15
  50. package/generated/versions/defold-1.13.0/camera.d.ts +2 -2
  51. package/generated/versions/defold-1.13.0/collectionfactory.d.ts +12 -10
  52. package/generated/versions/defold-1.13.0/compute.d.ts +1 -1
  53. package/generated/versions/defold-1.13.0/go.d.ts +9 -5
  54. package/generated/versions/defold-1.13.0/graphics.d.ts +48 -0
  55. package/generated/versions/defold-1.13.0/gui.d.ts +47 -31
  56. package/generated/versions/defold-1.13.0/html5.d.ts +3 -1
  57. package/generated/versions/defold-1.13.0/http.d.ts +4 -2
  58. package/generated/versions/defold-1.13.0/image.d.ts +24 -15
  59. package/generated/versions/defold-1.13.0/index.d.ts +1 -0
  60. package/generated/versions/defold-1.13.0/material.d.ts +1 -1
  61. package/generated/versions/defold-1.13.0/model.d.ts +32 -3
  62. package/generated/versions/defold-1.13.0/physics.d.ts +13 -11
  63. package/generated/versions/defold-1.13.0/profiler.d.ts +1 -1
  64. package/generated/versions/defold-1.13.0/render.d.ts +72 -15
  65. package/generated/versions/defold-1.13.0/resource.d.ts +100 -69
  66. package/generated/versions/defold-1.13.0/socket.d.ts +23 -13
  67. package/generated/versions/defold-1.13.0/sound.d.ts +3 -3
  68. package/generated/versions/defold-1.13.0/sprite.d.ts +9 -1
  69. package/generated/versions/defold-1.13.0/sys.d.ts +34 -23
  70. package/generated/versions/defold-1.13.0/vmath.d.ts +5 -5
  71. package/generated/vmath.d.ts +5 -5
  72. package/index.d.ts +1 -0
  73. package/package.json +1 -1
  74. package/scripts/generate-api-signatures.ts +2 -1
  75. package/scripts/prose-constants.ts +96 -0
  76. package/scripts/regen.ts +6 -2
  77. package/src/component-properties.d.ts +33 -0
  78. package/src/core-types.ts +4 -2
  79. package/src/custom-messages.d.ts +4 -3
  80. package/src/doc-comment.ts +35 -12
  81. package/src/emit-dts.ts +457 -47
  82. package/src/engine-globals.d.ts +2 -2
  83. package/src/go-overloads.d.ts +11 -10
  84. package/src/index.ts +4 -0
  85. package/src/param-correction-provenance.ts +67 -0
  86. package/src/render-overloads.d.ts +15 -0
  87. package/src/script-api.ts +3 -1
@@ -88,10 +88,10 @@ declare global {
88
88
  * // copy entire stream
89
89
  * const srcstream = buffer.get_stream(srcbuffer, hash("xyz"));
90
90
  * const dststream = buffer.get_stream(dstbuffer, hash("xyz"));
91
- * buffer.copy_stream(dststream, 0, srcstream, 0, srcstream.length);
91
+ * buffer.copy_stream(dststream, 0, srcstream, 0, srcstream.length());
92
92
  * ```
93
93
  */
94
- function copy_stream(dst: Opaque<"bufferstream"> & { [index: number]: number }, dstoffset: number, src: Opaque<"bufferstream"> & { [index: number]: number }, srcoffset: number, count: number): void;
94
+ function copy_stream(dst: Opaque<"bufferstream"> & { [index: number]: number; length: LuaLengthMethod<number> }, dstoffset: number, src: Opaque<"bufferstream"> & { [index: number]: number; length: LuaLengthMethod<number> }, srcoffset: number, count: number): void;
95
95
  /**
96
96
  * Create a new data buffer containing a specified set of streams. A data buffer
97
97
  * can contain one or more streams with typed data. This is useful for managing
@@ -111,24 +111,27 @@ declare global {
111
111
  * ```ts
112
112
  * // How to create and initialize a buffer
113
113
  * export default defineScript({
114
- * init(self) {
114
+ * init() {
115
115
  * const size = 128;
116
- * self.image = buffer.create(size * size, [{ name: hash("rgb"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);
117
- * self.imagestream = buffer.get_stream(self.image, hash("rgb"));
118
- *
119
- * for (let y = 0; y < self.height; y++) {
120
- * for (let x = 0; x < self.width; x++) {
121
- * const index = y * self.width * 3 + x * 3;
122
- * self.imagestream[index + 0] = self.r;
123
- * self.imagestream[index + 1] = self.g;
124
- * self.imagestream[index + 2] = self.b;
116
+ * const [width, height] = [size, size];
117
+ * const [r, g, b] = [0xff, 0x80, 0x10];
118
+ * const image = buffer.create(size * size, [{ name: hash("rgb"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);
119
+ * const imagestream = buffer.get_stream(image, hash("rgb"));
120
+ *
121
+ * for (let y = 0; y < height; y++) {
122
+ * for (let x = 0; x < width; x++) {
123
+ * const index = y * width * 3 + x * 3;
124
+ * imagestream[index + 0] = r;
125
+ * imagestream[index + 1] = g;
126
+ * imagestream[index + 2] = b;
125
127
  * }
126
128
  * }
129
+ * return { image, imagestream };
127
130
  * },
128
131
  * });
129
132
  * ```
130
133
  */
131
- function create(element_count: number, declaration: { name?: Hash | string; type?: Opaque<"constant">; count?: number }): Opaque<"buffer">;
134
+ function create(element_count: number, declaration: { name?: Hash | string; type?: buffer.ValueType; count?: number }[]): Opaque<"buffer">;
132
135
  /**
133
136
  * Get a copy of all the bytes from a specified stream as a Lua string.
134
137
  *
@@ -136,7 +139,7 @@ declare global {
136
139
  * @param stream_name - the name of the stream
137
140
  * @returns the buffer data as a Lua string
138
141
  */
139
- function get_bytes(buffer: Opaque<"buffer">, stream_name: Hash): string;
142
+ function get_bytes(buffer: Opaque<"buffer">, stream_name: Hash | string): string;
140
143
  /**
141
144
  * Get a named metadata entry from a buffer along with its type.
142
145
  *
@@ -160,7 +163,7 @@ declare global {
160
163
  * @param stream_name - the stream name
161
164
  * @returns the data stream
162
165
  */
163
- function get_stream(buffer: Opaque<"buffer">, stream_name: Hash | string): Opaque<"bufferstream"> & { [index: number]: number };
166
+ function get_stream(buffer: Opaque<"buffer">, stream_name: Hash | string): Opaque<"bufferstream"> & { [index: number]: number; length: LuaLengthMethod<number> };
164
167
  /**
165
168
  * Creates or updates a metadata array entry on a buffer.
166
169
  * The value type and count given when updating the entry should match those used when first creating it.
@@ -126,7 +126,7 @@ declare global {
126
126
  * export default defineScript({
127
127
  * on_input(self, action_id, action) {
128
128
  * if (action_id === hash("touch")) {
129
- * if (action.pressed) {
129
+ * if (action.pressed && action.screen_x !== undefined && action.screen_y !== undefined) {
130
130
  * const perspective_camera = msg.url("#perspective_camera");
131
131
  * const random_z = math.random(
132
132
  * camera.get_near_z(perspective_camera) + 0.01,
@@ -158,7 +158,7 @@ declare global {
158
158
  * export default defineScript({
159
159
  * on_input(self, action_id, action) {
160
160
  * if (action_id === hash("touch")) {
161
- * if (action.pressed) {
161
+ * if (action.pressed && action.screen_x !== undefined && action.screen_y !== undefined) {
162
162
  * const world_position = camera.screen_xy_to_world(action.screen_x, action.screen_y);
163
163
  * go.set_position(world_position, "/go1");
164
164
  * }
@@ -46,18 +46,17 @@ declare global {
46
46
  * ```ts
47
47
  * // How to spawn a collection of game objects:
48
48
  * export default defineScript({
49
- * init(self) {
49
+ * init() {
50
50
  * // Spawn a small group of enemies.
51
51
  * const pos = vmath.vector3(100, 12.5, 0);
52
52
  * const rot = vmath.quat_rotation_z(Math.PI / 2);
53
53
  * const scale = 0.5;
54
- * const props = {
55
- * [hash("/enemy_leader")]: { health: 1000.0 },
56
- * [hash("/enemy_1")]: { health: 200.0 },
57
- * [hash("/enemy_2")]: { health: 400.0, color: hash("green") },
58
- * };
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") });
59
58
  *
60
- * self.enemy_ids = collectionfactory.create("#enemyfactory", pos, rot, props, scale);
59
+ * const enemy_ids = collectionfactory.create("#enemyfactory", pos, rot, props, scale);
61
60
  * // enemy_ids now map to the spawned instance ids:
62
61
  * //
63
62
  * // pprint(self.enemy_ids)
@@ -70,8 +69,11 @@ declare global {
70
69
  * // }
71
70
  *
72
71
  * // Send "attack" message to the leader. First look up its instance id.
73
- * const leader_id = self.enemy_ids[hash("/enemy_leader")];
74
- * 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 };
75
77
  * },
76
78
  * });
77
79
  *
@@ -81,7 +83,7 @@ declare global {
81
83
  * }
82
84
  * ```
83
85
  */
84
- 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>;
85
87
  /**
86
88
  * This returns status of the collection factory.
87
89
  * Calling this function when the factory is not marked as dynamic loading always returns COMP_COLLECTION_FACTORY_STATUS_LOADED.
@@ -323,7 +323,7 @@ declare global {
323
323
  * go.delete(ids, true);
324
324
  * ```
325
325
  */
326
- 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;
327
327
  /**
328
328
  * This function can check for game objects in any collection by specifying
329
329
  * the collection name in the URL.
@@ -351,6 +351,10 @@ declare global {
351
351
  * @example
352
352
  * ```ts
353
353
  * export default defineScript({
354
+ * init() {
355
+ * return { some_value: 0 };
356
+ * },
357
+ *
354
358
  * final(self) {
355
359
  * // report finalization
356
360
  * msg.post("my_friend_instance", "im_dead", { my_stats: self.some_value });
@@ -766,7 +770,7 @@ declare global {
766
770
  * self.velocity = vmath.vector3();
767
771
  * } else {
768
772
  * // update velocity
769
- * self.velocity = vmath.vector3(action.value * self.max_speed, 0, 0);
773
+ * self.velocity = vmath.vector3((action.value ?? 0) * self.max_speed, 0, 0);
770
774
  * }
771
775
  * }
772
776
  * },
@@ -808,12 +812,12 @@ declare global {
808
812
  * init() {
809
813
  * // store the url of instance "a" for later use, by specifying undefined as socket we
810
814
  * // automatically use our own socket
811
- * 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 };
812
816
  * },
813
817
  *
814
818
  * on_message(self, message_id, message, sender) {
815
819
  * // check message and sender
816
- * 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") {
817
821
  * // use the data in some way
818
822
  * self.important_value = message.important_value;
819
823
  * }
@@ -855,7 +859,7 @@ declare global {
855
859
  * self.velocity = vmath.vector3();
856
860
  * } else {
857
861
  * // update velocity
858
- * self.velocity = vmath.vector3(action.value * self.max_speed, 0, 0);
862
+ * self.velocity = vmath.vector3((action.value ?? 0) * self.max_speed, 0, 0);
859
863
  * }
860
864
  * }
861
865
  * },
@@ -1,5 +1,5 @@
1
1
  /** @noSelfInFile */
2
- import type { Hash, Opaque, Quaternion, Url, Vector, Vector3, Vector4 } from "../../../src/core-types";
2
+ import type { Hash, Matrix4, Opaque, Quaternion, Url, Vector, Vector3, Vector4 } from "../../../src/core-types";
3
3
 
4
4
  declare global {
5
5
  /**
@@ -624,15 +624,15 @@ declare global {
624
624
  * const node = gui.get_node("my_node");
625
625
  * // animate to new position
626
626
  * const pos = vmath.vector3(100, 100, 0);
627
- * gui.animate(node, "position", pos, go.EASING_LINEAR, 2);
627
+ * gui.animate(node, "position", pos, gui.EASING_LINEAR, 2);
628
628
  * // ...
629
629
  * // cancel animation of the x component.
630
630
  * gui.cancel_animations(node, "position.x");
631
631
  *
632
632
  * // Cancels all property animations on a node in a single call:
633
633
  * // animate to new position and scale
634
- * gui.animate(node, "position", vmath.vector3(100, 100, 0), go.EASING_LINEAR, 5);
635
- * gui.animate(node, "scale", vmath.vector3(0.5), go.EASING_LINEAR, 5);
634
+ * gui.animate(node, "position", vmath.vector3(100, 100, 0), gui.EASING_LINEAR, 5);
635
+ * gui.animate(node, "scale", vmath.vector3(0.5), gui.EASING_LINEAR, 5);
636
636
  * // ...
637
637
  * // cancel positioning and scaling at once
638
638
  * gui.cancel_animations(node);
@@ -713,6 +713,10 @@ declare global {
713
713
  * @example
714
714
  * ```ts
715
715
  * export default defineScript({
716
+ * init() {
717
+ * return { some_value: 0 };
718
+ * },
719
+ *
716
720
  * final(self) {
717
721
  * // report finalization
718
722
  * msg.post("my_friend_instance", "im_dead", { my_stats: self.some_value });
@@ -760,7 +764,7 @@ declare global {
760
764
  * @param node - node to get the property for
761
765
  * @param property - the property to retrieve
762
766
  * @param options - optional options table (only applicable for material constants)
763
- * - `index` number index into array property (1 based)
767
+ * - `index` number zero-based index into array property; the transpiler emits Defold's 1-based index
764
768
  * @example
765
769
  * ```ts
766
770
  * // Get properties on existing nodes:
@@ -1382,12 +1386,14 @@ declare global {
1382
1386
  * const size = 4;
1383
1387
  * const pos = vmath.vector3(200, 200, 0);
1384
1388
  * const path = "/assets/images/logo_4x4.astc";
1385
- * const buffer = sys.load_resource(path);
1386
- * const n = gui.new_box_node(pos, vmath.vector3(size, size, 0));
1387
- * // size is read from the .astc buffer
1388
- * // flip is not supported
1389
- * gui.new_texture(path, 0, 0, "astc", buffer, false);
1390
- * gui.set_texture(n, path);
1389
+ * const [data] = sys.load_resource(path);
1390
+ * if (data !== undefined) {
1391
+ * const n = gui.new_box_node(pos, vmath.vector3(size, size, 0));
1392
+ * // size is read from the .astc buffer
1393
+ * // flip is not supported
1394
+ * gui.new_texture(path, 0, 0, "astc", data, false);
1395
+ * gui.set_texture(n, path);
1396
+ * }
1391
1397
  * ```
1392
1398
  */
1393
1399
  function new_texture(texture_id: string | Hash, width: number, height: number, type: string | Opaque<"constant">, buffer: string, flip?: boolean): LuaMultiReturn<[boolean, number]>;
@@ -1532,6 +1538,10 @@ declare global {
1532
1538
  * @example
1533
1539
  * ```ts
1534
1540
  * export default defineGuiScript({
1541
+ * init(): { my_value: number | undefined } {
1542
+ * return { my_value: undefined };
1543
+ * },
1544
+ *
1535
1545
  * on_input(self, action_id, action) {
1536
1546
  * // check for input
1537
1547
  * if (action_id === hash("my_action")) {
@@ -1565,6 +1575,10 @@ declare global {
1565
1575
  * @example
1566
1576
  * ```ts
1567
1577
  * export default defineGuiScript({
1578
+ * init() {
1579
+ * return { my_original_color: gui.get_color(gui.get_node("my_node")) };
1580
+ * },
1581
+ *
1568
1582
  * on_reload(self) {
1569
1583
  * // restore some color (or similar)
1570
1584
  * gui.set_color(gui.get_node("my_node"), self.my_original_color);
@@ -1747,13 +1761,13 @@ declare global {
1747
1761
  * @param property - the property to set
1748
1762
  * @param value - the property to set
1749
1763
  * @param options - optional options table (only applicable for material constants)
1750
- * - `index` number index into array property (1 based)
1764
+ * - `index` number zero-based index into array property; the transpiler emits Defold's 1-based index
1751
1765
  * - `key` hash name of internal property
1752
1766
  * @example
1753
1767
  * ```ts
1754
1768
  * // Updates the position property on an existing node:
1755
1769
  * const node = gui.get_node("my_box_node");
1756
- * const node_position = gui.get(node, "position");
1770
+ * const node_position = gui.get(node, "position") as Vector3;
1757
1771
  * gui.set(node, "position.x", node_position.x + 128);
1758
1772
  *
1759
1773
  * // Updates the rotation property on an existing node:
@@ -1770,23 +1784,23 @@ declare global {
1770
1784
  * // matrix4 is also supported
1771
1785
  * gui.set(node, "light_matrix", vmath.matrix4());
1772
1786
  * // update a constant in an array at position 4. the array is specified in the shader as:
1773
- * // uniform vec4 tint_array[4]; // lua is 1 based, shader is 0 based
1774
- * gui.set(node, "tint_array", vmath.vector4(1, 0, 0, 1), { index: 4 });
1787
+ * // uniform vec4 tint_array[4]; // TypeScript and the shader are both 0 based
1788
+ * gui.set(node, "tint_array", vmath.vector4(1, 0, 0, 1), { index: 3 });
1775
1789
  * // update a matrix constant in an array at position 4. the array is specified in the shader as:
1776
1790
  * // uniform mat4 light_matrix_array[4];
1777
- * gui.set(node, "light_matrix_array", vmath.matrix4(), { index: 4 });
1791
+ * gui.set(node, "light_matrix_array", vmath.matrix4(), { index: 3 });
1778
1792
  * // update a sub-element in a constant
1779
1793
  * gui.set(node, "tint.x", 1);
1780
1794
  * // update a sub-element in an array constant at position 4
1781
- * gui.set(node, "tint_array.x", 1, { index: 4 });
1795
+ * gui.set(node, "tint_array.x", 1, { index: 3 });
1782
1796
  *
1783
1797
  * // Set a named property
1784
1798
  * export default defineGuiScript({
1785
1799
  * on_message(self, message_id, message) {
1786
- * if (message_id === hash("set_font")) {
1800
+ * if (message_id === hash("set_font") && types.is_hash(message.font)) {
1787
1801
  * gui.set(msg.url(), "fonts", message.font, { key: "my_font_name" });
1788
1802
  * gui.set_font(gui.get_node("text"), "my_font_name");
1789
- * } else if (message_id === hash("set_texture")) {
1803
+ * } else if (message_id === hash("set_texture") && types.is_hash(message.texture)) {
1790
1804
  * gui.set(msg.url(), "textures", message.texture, { key: "my_texture" });
1791
1805
  * gui.set_texture(gui.get_node("box"), "my_texture");
1792
1806
  * gui.play_flipbook(gui.get_node("box"), "logo_256");
@@ -1795,7 +1809,7 @@ declare global {
1795
1809
  * });
1796
1810
  * ```
1797
1811
  */
1798
- function set(node: Opaque<"node"> | Url, property: string | Hash | gui.Property, value: number | Vector4 | Vector3 | Quaternion, options?: { index?: number; key?: Hash }): void;
1812
+ function set(node: Opaque<"node"> | Url, property: string | Hash | gui.Property, value: number | Vector4 | Vector3 | Quaternion | Matrix4 | Hash, options?: { index?: number; key?: string | Hash }): void;
1799
1813
  /**
1800
1814
  * Sets the adjust mode on a node.
1801
1815
  * The adjust mode defines how the node will adjust itself to screen
@@ -2101,7 +2115,7 @@ declare global {
2101
2115
  * @param node - node to set the rotation for
2102
2116
  * @param rotation - new rotation
2103
2117
  */
2104
- function set_rotation(node: Opaque<"node">, rotation: Quaternion | Vector4): void;
2118
+ function set_rotation(node: Opaque<"node">, rotation: Quaternion | Vector4 | Vector3): void;
2105
2119
  /**
2106
2120
  * Sets how the safe area is applied to this gui scene.
2107
2121
  *
@@ -2334,15 +2348,17 @@ declare global {
2334
2348
  * // in a counting fashion. It is assumed that the gui component receives messages
2335
2349
  * // from the game when a new score is to be shown.
2336
2350
  * export default defineGuiScript({
2337
- * init(self) {
2338
- * // fetch the score text node for later use (assumes it is called "score")
2339
- * self.score_node = gui.get_node("score");
2340
- * // keep track of the current score counted up so far
2341
- * self.current_score = 0;
2342
- * // keep track of the target score we should count up to
2343
- * self.target_score = 0;
2344
- * // how fast we will update the score, in score/second
2345
- * self.score_update_speed = 1;
2351
+ * init() {
2352
+ * return {
2353
+ * // fetch the score text node for later use (assumes it is called "score")
2354
+ * score_node: gui.get_node("score"),
2355
+ * // keep track of the current score counted up so far
2356
+ * current_score: 0,
2357
+ * // keep track of the target score we should count up to
2358
+ * target_score: 0,
2359
+ * // how fast we will update the score, in score/second
2360
+ * score_update_speed: 1,
2361
+ * };
2346
2362
  * },
2347
2363
  *
2348
2364
  * update(self, dt) {
@@ -2361,7 +2377,7 @@ declare global {
2361
2377
  *
2362
2378
  * on_message(self, message_id, message) {
2363
2379
  * // check the message
2364
- * if (message_id === hash("set_score")) {
2380
+ * if (message_id === hash("set_score") && typeof message.score === "number") {
2365
2381
  * self.target_score = message.score;
2366
2382
  * }
2367
2383
  * },
@@ -18,7 +18,9 @@ declare global {
18
18
  * const res = html5.run("10 + 20"); // returns the string "30"
19
19
  * print(res);
20
20
  * const res_num = tonumber(res); // convert to number
21
- * print(res_num - 20); // prints 10
21
+ * if (res_num !== undefined) {
22
+ * print(res_num - 20); // prints 10
23
+ * }
22
24
  * ```
23
25
  */
24
26
  function run(code: string): string;
@@ -1,4 +1,6 @@
1
1
  /** @noSelfInFile */
2
+ import type { Hash } from "../../../src/core-types";
3
+
2
4
  declare global {
3
5
  /**
4
6
  * Functions for performing HTTP and HTTPS requests.
@@ -65,7 +67,7 @@ declare global {
65
67
  * "http://www.google.com",
66
68
  * "GET",
67
69
  * (self, _id, response) => {
68
- * if (response.bytes_total !== undefined) {
70
+ * if (response.bytes_received !== undefined && response.bytes_total !== undefined) {
69
71
  * update_my_progress_bar(self, response.bytes_received / response.bytes_total);
70
72
  * } else {
71
73
  * print(response.status);
@@ -81,7 +83,7 @@ declare global {
81
83
  * });
82
84
  * ```
83
85
  */
84
- function request(url: string, method: string, callback: (self: unknown, id: unknown, response: unknown) => void, headers?: LuaMap<string, string>, post_data?: string, options?: { timeout?: number; path?: string; ignore_cache?: boolean; chunked_transfer?: boolean; report_progress?: boolean }): void;
86
+ function request(url: string, method: string, callback: (self: unknown, id: Hash, response: { status: number; response?: string; headers?: LuaMap<string, string>; path?: string; error?: string; bytes_received?: number; bytes_total?: number; range_start?: number; range_end?: number; document_size?: number }) => void, headers?: LuaMap<string, string> | Record<string, string>, post_data?: string, options?: { timeout?: number; path?: string; ignore_cache?: boolean; chunked_transfer?: boolean; report_progress?: boolean }): void;
85
87
  }
86
88
  }
87
89
 
@@ -43,8 +43,10 @@ declare global {
43
43
  * ```ts
44
44
  * // How to get the block size and dimensions from a .astc file
45
45
  * const [s] = sys.load_resource("/assets/cat.astc");
46
- * const header = image.get_astc_header(s);
47
- * pprint(s);
46
+ * if (s !== undefined) {
47
+ * const header = image.get_astc_header(s);
48
+ * pprint(s);
49
+ * }
48
50
  * ```
49
51
  */
50
52
  function get_astc_header(buffer: string): { width: number; height: number; depth: number; block_size_x: number; block_size_y: number; block_size_z: number } | undefined;
@@ -80,8 +82,10 @@ declare global {
80
82
  * // How to load an image from an URL and create a GUI texture from it:
81
83
  * const imgurl = "http://www.site.com/image.png";
82
84
  * http.request(imgurl, "GET", (self, id, response) => {
83
- * const img = image.load(response.response);
84
- * const tx = gui.new_texture("image_node", img.width, img.height, img.type, img.buffer);
85
+ * const img = response.response !== undefined ? image.load(response.response) : undefined;
86
+ * if (img !== undefined) {
87
+ * const tx = gui.new_texture("image_node", img.width, img.height, img.type, img.buffer);
88
+ * }
85
89
  * });
86
90
  * ```
87
91
  */
@@ -118,17 +122,22 @@ declare global {
118
122
  * // Load an image from an URL as a buffer and create a texture resource from it:
119
123
  * const imgurl = "http://www.site.com/image.png";
120
124
  * http.request(imgurl, "GET", (self, id, response) => {
121
- * const img = image.load_buffer(response.response, { flip_vertically: true });
122
- * const tparams = {
123
- * width: img.width,
124
- * height: img.height,
125
- * type: graphics.TEXTURE_TYPE_2D,
126
- * format: graphics.TEXTURE_FORMAT_RGBA,
127
- * };
128
- *
129
- * const my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams, img.buffer);
130
- * // Apply the texture to a model
131
- * go.set("/go1#model", "texture0", my_texture_id);
125
+ * const img =
126
+ * response.response !== undefined
127
+ * ? image.load_buffer(response.response, { flip_vertically: true })
128
+ * : undefined;
129
+ * if (img !== undefined) {
130
+ * const tparams = {
131
+ * width: img.width,
132
+ * height: img.height,
133
+ * type: graphics.TEXTURE_TYPE_2D,
134
+ * format: graphics.TEXTURE_FORMAT_RGBA,
135
+ * };
136
+ *
137
+ * const my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams, img.buffer);
138
+ * // Apply the texture to a model
139
+ * go.set("/go1#model", "texture0", my_texture_id);
140
+ * }
132
141
  * });
133
142
  * ```
134
143
  */
@@ -42,6 +42,7 @@ import "../../../src/message-guard";
42
42
  import "../../../src/window-event-guard";
43
43
  import "../../../src/scene-addresses";
44
44
  import "../../../src/go-overloads";
45
+ import "../../../src/component-properties";
45
46
  import "../../../src/render-overloads";
46
47
  import "../../../src/vmath-overloads";
47
48
 
@@ -72,11 +72,12 @@ declare global {
72
72
  * const game = { data: { weapons: { Sword: { damage: 10 } } } };
73
73
  *
74
74
  * export default defineScript({
75
- * init(self) {
75
+ * init() {
76
76
  * if (model.get_mesh_enabled("#model", "Sword")) {
77
77
  * // set properties specific for the sword
78
- * self.weapon_properties = game.data.weapons["Sword"];
78
+ * return { weapon_properties: game.data.weapons["Sword"] };
79
79
  * }
80
+ * return { weapon_properties: undefined };
80
81
  * },
81
82
  * });
82
83
  * ```
@@ -202,7 +203,35 @@ declare global {
202
203
  /**
203
204
  * The texture hash id of the model. Used for getting/setting model texture for unit 0-7
204
205
  */
205
- textureN: Hash;
206
+ texture0: Hash;
207
+ /**
208
+ * The texture hash id of the model. Used for getting/setting model texture for unit 0-7
209
+ */
210
+ texture1: Hash;
211
+ /**
212
+ * The texture hash id of the model. Used for getting/setting model texture for unit 0-7
213
+ */
214
+ texture2: Hash;
215
+ /**
216
+ * The texture hash id of the model. Used for getting/setting model texture for unit 0-7
217
+ */
218
+ texture3: Hash;
219
+ /**
220
+ * The texture hash id of the model. Used for getting/setting model texture for unit 0-7
221
+ */
222
+ texture4: Hash;
223
+ /**
224
+ * The texture hash id of the model. Used for getting/setting model texture for unit 0-7
225
+ */
226
+ texture5: Hash;
227
+ /**
228
+ * The texture hash id of the model. Used for getting/setting model texture for unit 0-7
229
+ */
230
+ texture6: Hash;
231
+ /**
232
+ * The texture hash id of the model. Used for getting/setting model texture for unit 0-7
233
+ */
234
+ texture7: Hash;
206
235
  }
207
236
  }
208
237
  }
@@ -72,7 +72,7 @@ declare global {
72
72
  * init(self) {
73
73
  * let gravity = physics.get_gravity();
74
74
  * // Inverse gravity!
75
- * gravity = -gravity;
75
+ * gravity = vmath.vector3(-gravity.x, -gravity.y, -gravity.z);
76
76
  * physics.set_gravity(gravity);
77
77
  * },
78
78
  * });
@@ -208,8 +208,8 @@ declare global {
208
208
  *
209
209
  * // How to perform a ray cast synchronously:
210
210
  * export default defineScript({
211
- * init(self) {
212
- * self.groups = [hash("world"), hash("enemy")];
211
+ * init() {
212
+ * return { groups: [hash("world"), hash("enemy")] };
213
213
  * },
214
214
  *
215
215
  * update(self, dt) {
@@ -249,8 +249,8 @@ declare global {
249
249
  * ```ts
250
250
  * // How to perform a ray cast asynchronously:
251
251
  * export default defineScript({
252
- * init(self) {
253
- * self.my_groups = [hash("my_group1"), hash("my_group2")];
252
+ * init() {
253
+ * return { my_groups: [hash("my_group1"), hash("my_group2")] };
254
254
  * },
255
255
  *
256
256
  * update(self, dt) {
@@ -416,9 +416,10 @@ declare global {
416
416
  * @example
417
417
  * ```ts
418
418
  * export default defineScript({
419
- * init(self) {
420
- * self.fliph = true; // set on some condition
421
- * physics.set_hflip("#collisionobject", self.fliph);
419
+ * init() {
420
+ * const fliph = true; // set on some condition
421
+ * physics.set_hflip("#collisionobject", fliph);
422
+ * return { fliph };
422
423
  * },
423
424
  * });
424
425
  * ```
@@ -490,9 +491,10 @@ declare global {
490
491
  * @example
491
492
  * ```ts
492
493
  * export default defineScript({
493
- * init(self) {
494
- * self.flipv = true; // set on some condition
495
- * physics.set_vflip("#collisionobject", self.flipv);
494
+ * init() {
495
+ * const flipv = true; // set on some condition
496
+ * physics.set_vflip("#collisionobject", flipv);
497
+ * return { flipv };
496
498
  * },
497
499
  * });
498
500
  * ```
@@ -129,7 +129,7 @@ declare global {
129
129
  * ```ts
130
130
  * // Show the last recorded frame
131
131
  * const recorded_frame_count = profiler.recorded_frame_count();
132
- * profiler.view_recorded_frame(recorded_frame_count);
132
+ * profiler.view_recorded_frame({ frame: recorded_frame_count });
133
133
  * ```
134
134
  */
135
135
  function recorded_frame_count(): number;