@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
@@ -17,7 +17,7 @@ declare global {
17
17
  * require "builtins.scripts.socket"
18
18
  * ```
19
19
  *
20
- * LuaSocket is Copyright © 2004-2007 Diego Nehab. All rights reserved.
20
+ * LuaSocket is Copyright © 2004-2007 Diego Nehab. All rights reserved.
21
21
  * LuaSocket is free software, released under the MIT license (same license as the Lua core).
22
22
  */
23
23
  namespace socket {
@@ -635,17 +635,23 @@ declare global {
635
635
  * @example
636
636
  * ```ts
637
637
  * // Perform operations on an open socket c:
638
- * // create a try function that closes 'c' on error
639
- * const try_ = socket.newtry(() => c.close());
640
- * // do everything reassured c will be closed
641
- * try_(c.send("hello there?\r\n"));
642
- * const answer = try_(c.receive());
643
- * // ...
644
- * try_(c.send("good bye\r\n"));
645
- * c.close();
638
+ * const [c] = socket.connect("localhost", 80);
639
+ * if (c !== undefined) {
640
+ * // create a try function that closes 'c' on error
641
+ * const try_ = socket.newtry(() => c.close());
642
+ * // do everything reassured c will be closed
643
+ * const [sent, sendError, lastByte] = c.send("hello there?\r\n");
644
+ * try_(sent, sendError, lastByte);
645
+ * const [line, receiveError, partial] = c.receive();
646
+ * const answer = try_(line, receiveError, partial);
647
+ * // ...
648
+ * const [byeSent, byeError, byeLastByte] = c.send("good bye\r\n");
649
+ * try_(byeSent, byeError, byeLastByte);
650
+ * c.close();
651
+ * }
646
652
  * ```
647
653
  */
648
- function newtry(finalizer: () => void): (...args: unknown[]) => unknown;
654
+ function newtry(finalizer?: () => void): <T>(value: T | undefined, ...rest: T extends { readonly __tstlMultiReturn: unknown } ? [boxedMultiReturn: never] : unknown[]) => T;
649
655
  /**
650
656
  * Converts a function that throws exceptions into a safe function. This function only catches exceptions thrown by try functions. It does not catch normal Lua errors.
651
657
  * Beware that if your function performs some illegal operation that raises an error, the protected function will catch the error and return it as a string. This is because try functions uses errors as the mechanism to throw exceptions.
@@ -656,17 +662,20 @@ declare global {
656
662
  * ```ts
657
663
  * const dostuff = socket.protect(() => {
658
664
  * let try_ = socket.newtry();
659
- * const c = try_(socket.connect("myserver.com", 80));
665
+ * const [conn, connectError] = socket.connect("myserver.com", 80);
666
+ * const c = try_(conn, connectError);
660
667
  * try_ = socket.newtry(() => c.close());
661
- * try_(c.send("hello?\r\n"));
662
- * const answer = try_(c.receive());
668
+ * const [sent, sendError, lastByte] = c.send("hello?\r\n");
669
+ * try_(sent, sendError, lastByte);
670
+ * const [line, receiveError, partial] = c.receive();
671
+ * const answer = try_(line, receiveError, partial);
663
672
  * c.close();
664
673
  * });
665
674
  *
666
675
  * const [n, error] = dostuff();
667
676
  * ```
668
677
  */
669
- function protect(func: (...args: unknown[]) => unknown): (arg0: unknown) => void;
678
+ function protect(func: (...args: unknown[]) => unknown): (...args: unknown[]) => LuaMultiReturn<[unknown, string | undefined]>;
670
679
  /**
671
680
  * The function returns a list with the sockets ready for reading, a list with the sockets ready for writing and an error message. The error message is "timeout" if a timeout condition was met and nil otherwise. The returned tables are doubly keyed both by integers and also by the sockets themselves, to simplify the test if a specific socket has changed status.
672
681
  * `Recvt` and `sendt` parameters can be empty tables or `nil`. Non-socket values (or values with non-numeric indices) in these arrays will be silently ignored.
@@ -694,13 +703,19 @@ declare global {
694
703
  * @param retN - argument N.
695
704
  * @example
696
705
  * ```ts
706
+ * const line = "250 OK";
707
+ *
697
708
  * // Instead of doing the following with dummy variables:
698
- * // get the status code and separator from SMTP server reply
699
- * const [dummy1, dummy2, code, sep] = string.find(line, "^(%d%d%d)(.?)");
709
+ * {
710
+ * // get the status code and separator from SMTP server reply
711
+ * const [dummy1, dummy2, code, sep] = string.find(line, "^(%d%d%d)(.?)");
712
+ * }
700
713
  *
701
714
  * // You can skip a number of variables:
702
- * // get the status code and separator from SMTP server reply
703
- * const [code, sep] = socket.skip(2, string.find(line, "^(%d%d%d)(.?)"));
715
+ * {
716
+ * // get the status code and separator from SMTP server reply
717
+ * const [code, sep] = socket.skip(2, string.find(line, "^(%d%d%d)(.?)"));
718
+ * }
704
719
  * ```
705
720
  */
706
721
  function skip(d: number, ret1?: unknown, ret2?: unknown, retN?: unknown): LuaMultiReturn<[unknown, unknown, unknown]>;
@@ -83,7 +83,7 @@ declare global {
83
83
  * square root of the mean (average) value of the squared function of
84
84
  * the instantaneous values.
85
85
  * For instance: for a sinewave signal with a peak gain of -1.94 dB (0.8 linear),
86
- * the RMS is `0.8 &times; 1/sqrt(2)` which is about 0.566.
86
+ * the RMS is `0.8 × 1/sqrt(2)` which is about 0.566.
87
87
  * Note the returned value might be an approximation and in particular
88
88
  * the effective window might be larger than specified.
89
89
  *
@@ -193,16 +193,17 @@ declare global {
193
193
  * sound.play("#sound", { delay: 1, gain: 0.9, pan: -1.0 });
194
194
  *
195
195
  * // Using the callback argument, you can chain several sounds together:
196
- * function sound_done(self, message_id, message, sender) {
196
+ * function sound_done(self: unknown, message_id: unknown, message: unknown, sender: unknown) {
197
197
  * // play 'boom' sound fx when the countdown has completed
198
- * if (message_id === hash("sound_done") && message.play_id === self.countdown_id) {
198
+ * const { play_id } = message as { play_id: number };
199
+ * if (message_id === hash("sound_done") && play_id === (self as { countdown_id: number }).countdown_id) {
199
200
  * sound.play("#boom", undefined, sound_done);
200
201
  * }
201
202
  * }
202
203
  *
203
204
  * export default defineScript({
204
- * init(self) {
205
- * self.countdown_id = sound.play("#countdown", undefined, sound_done);
205
+ * init() {
206
+ * return { countdown_id: sound.play("#countdown", undefined, sound_done) };
206
207
  * },
207
208
  * });
208
209
  * ```
@@ -52,7 +52,7 @@ declare global {
52
52
  * });
53
53
  * ```
54
54
  */
55
- function play_flipbook(url: string | Hash | Url, id: string | Hash, complete_function?: (self: unknown, message_id: unknown, message: unknown, sender: unknown) => void, play_properties?: { offset?: number; playback_rate?: number }): void;
55
+ function play_flipbook(url: string | Hash | Url, id: string | Hash, complete_function?: (self: unknown, message_id: Hash, message: { current_tile: number; id: Hash }, sender: Url) => void, play_properties?: { offset?: number; playback_rate?: number }): void;
56
56
  /**
57
57
  * Resets a shader constant for a sprite component.
58
58
  * The constant must be defined in the material assigned to the sprite.
@@ -79,6 +79,10 @@ declare global {
79
79
  * // How to flip a sprite so it faces the horizontal movement (it is assumed that
80
80
  * // the sprite component has id "sprite" and the original animation faces right):
81
81
  * export default defineScript({
82
+ * init() {
83
+ * return { velocity: vmath.vector3() };
84
+ * },
85
+ *
82
86
  * update(self, dt) {
83
87
  * // calculate self.velocity somehow
84
88
  * sprite.set_hflip("#sprite", self.velocity.x < 0);
@@ -100,6 +104,10 @@ declare global {
100
104
  * // assumed that the sprite component has id "sprite" and the original animation
101
105
  * // is up-right):
102
106
  * export default defineScript({
107
+ * init() {
108
+ * return { up_side_down: false };
109
+ * },
110
+ *
103
111
  * update(self, dt) {
104
112
  * // calculate self.up_side_down somehow, then:
105
113
  * sprite.set_vflip("#sprite", self.up_side_down);
@@ -1,5 +1,5 @@
1
1
  /** @noSelfInFile */
2
- import type { Opaque } from "../../../src/core-types";
2
+ import type { Hash, Opaque } from "../../../src/core-types";
3
3
 
4
4
  declare global {
5
5
  /**
@@ -7,6 +7,7 @@ declare global {
7
7
  * error handling and debugging.
8
8
  */
9
9
  namespace sys {
10
+ type NetworkConnectivity = typeof sys.NETWORK_DISCONNECTED | typeof sys.NETWORK_CONNECTED_CELLULAR | typeof sys.NETWORK_CONNECTED;
10
11
  /**
11
12
  * network connected through other, non cellular, connection
12
13
  */
@@ -39,6 +40,7 @@ declare global {
39
40
  * @example
40
41
  * ```ts
41
42
  * // Deserialize a table that was previously serialized:
43
+ * const my_table = { score: 100, level: 3 };
42
44
  * const buffer = sys.serialize(my_table);
43
45
  * const table = sys.deserialize(buffer);
44
46
  * ```
@@ -53,10 +55,12 @@ declare global {
53
55
  * @example
54
56
  * ```ts
55
57
  * // Load data but return nil if path didn't exist
56
- * if (!sys.exists(path)) {
57
- * return undefined;
58
+ * function load_data(path: string) {
59
+ * if (!sys.exists(path)) {
60
+ * return undefined;
61
+ * }
62
+ * return sys.load(path); // returns {} if it failed
58
63
  * }
59
- * return sys.load(path); // returns {} if it failed
60
64
  * ```
61
65
  */
62
66
  function exists(path: string): boolean;
@@ -94,7 +98,7 @@ declare global {
94
98
  * ```ts
95
99
  * // Check if twitter is installed:
96
100
  * const sysinfo = sys.get_sys_info();
97
- * let twitter = {};
101
+ * let twitter: { installed?: boolean } = {};
98
102
  *
99
103
  * if (sysinfo.system_name === "Android") {
100
104
  * twitter = sys.get_application_info("com.twitter.android");
@@ -228,7 +232,7 @@ declare global {
228
232
  * }
229
233
  * ```
230
234
  */
231
- function get_connectivity(): number & { readonly __brand: "sys.NETWORK_DISCONNECTED" } | number & { readonly __brand: "sys.NETWORK_CONNECTED_CELLULAR" } | number & { readonly __brand: "sys.NETWORK_CONNECTED" };
235
+ function get_connectivity(): sys.NetworkConnectivity;
232
236
  /**
233
237
  * Returns a table with engine information.
234
238
  *
@@ -259,12 +263,17 @@ declare global {
259
263
  * @example
260
264
  * ```ts
261
265
  * // Save data on the host
262
- * const host_path = sys.get_host_path("logs/test.txt");
263
- * sys.save(host_path, mytable);
266
+ * {
267
+ * const mytable = { score: 100, level: 3 };
268
+ * const host_path = sys.get_host_path("logs/test.txt");
269
+ * sys.save(host_path, mytable);
270
+ * }
264
271
  *
265
272
  * // Load data from the host
266
- * const host_path = sys.get_host_path("logs/test.txt");
267
- * const table = sys.load(host_path);
273
+ * {
274
+ * const host_path = sys.get_host_path("logs/test.txt");
275
+ * const table = sys.load(host_path);
276
+ * }
268
277
  * ```
269
278
  */
270
279
  function get_host_path(filename: string): string;
@@ -443,31 +452,39 @@ declare global {
443
452
  * @example
444
453
  * ```ts
445
454
  * // Load binary data from a custom project resource and update a texture resource:
446
- * function my_callback(self, request_id, result) {
447
- * if (result.status === resource.REQUEST_STATUS_FINISHED) {
448
- * resource.set_texture("/my_texture", {}, result.buf); // texture args
455
+ * {
456
+ * function my_callback(self: unknown, request_id: unknown, result: unknown) {
457
+ * const { status, buf } = result as { status: number; buf: Opaque<"buffer"> };
458
+ * if (status === sys.REQUEST_STATUS_FINISHED) {
459
+ * resource.set_texture("/my_texture", {}, buf); // texture args
460
+ * }
449
461
  * }
450
- * }
451
462
  *
452
- * const my_request = sys.load_buffer_async("/assets/my_level_data.bin", my_callback);
463
+ * const my_request = sys.load_buffer_async("/assets/my_level_data.bin", my_callback);
464
+ * }
453
465
  *
454
466
  * // Load binary data from non-custom resource files on disk:
455
- * function my_callback(self, request_id, result) {
456
- * if (result.status !== sys.REQUEST_STATUS_FINISHED) {
467
+ * function my_callback(self: unknown, request_id: unknown, result: unknown) {
468
+ * const { first_asset, second_asset } = self as { first_asset: Hash; second_asset: Hash };
469
+ * if ((result as { status: number }).status !== sys.REQUEST_STATUS_FINISHED) {
457
470
  * // uh oh! File could not be found, do something graceful
458
- * } else if (request_id === self.first_asset) {
471
+ * } else if (request_id === first_asset) {
459
472
  * // result.buffer contains data from my_level_asset.bin
460
- * } else if (request_id === self.second_asset) {
473
+ * } else if (request_id === second_asset) {
461
474
  * // result.buffer contains data from 'my_level.bin'
462
475
  * }
463
476
  * }
464
477
  *
465
478
  * export default defineScript({
466
- * init(self) {
467
- * self.first_asset = hash("folder_next_to_binary/my_level_asset.bin");
468
- * self.second_asset = hash("/some_absolute_path/my_level.bin");
469
- * self.first_request = sys.load_buffer_async(self.first_asset, my_callback);
470
- * self.second_request = sys.load_buffer_async(self.second_asset, my_callback);
479
+ * init() {
480
+ * const first_path = "folder_next_to_binary/my_level_asset.bin";
481
+ * const second_path = "/some_absolute_path/my_level.bin";
482
+ * return {
483
+ * first_asset: hash(first_path),
484
+ * second_asset: hash(second_path),
485
+ * first_request: sys.load_buffer_async(first_path, my_callback),
486
+ * second_request: sys.load_buffer_async(second_path, my_callback),
487
+ * };
471
488
  * },
472
489
  * });
473
490
  * ```
@@ -566,7 +583,7 @@ declare global {
566
583
  * sys.save(my_file_path, my_table);
567
584
  * ```
568
585
  */
569
- function save(filename: string, table: Record<string | number, unknown>): void;
586
+ function save(filename: string, table: Record<string | number, unknown> | readonly unknown[]): void;
570
587
  /**
571
588
  * The buffer can later deserialized by `sys.deserialize`.
572
589
  * This function has all the same limitations as `sys.save`.
@@ -582,7 +599,7 @@ declare global {
582
599
  * const buffer = sys.serialize(my_table);
583
600
  * ```
584
601
  */
585
- function serialize(table: Record<string | number, unknown>): string;
602
+ function serialize(table: Record<string | number, unknown> | readonly unknown[]): string;
586
603
  /**
587
604
  * Sets the host that is used to check for network connectivity against.
588
605
  *
@@ -623,7 +640,7 @@ declare global {
623
640
  * @example
624
641
  * ```ts
625
642
  * // Install error handler that just prints the errors
626
- * function my_error_handler(source, message, traceback) {
643
+ * function my_error_handler(source: unknown, message: unknown, traceback: unknown) {
627
644
  * print(source); //> lua
628
645
  * print(message); //> main/my.script:10: attempt to perform arithmetic on a string value
629
646
  * print(traceback); //> stack traceback:
@@ -55,8 +55,10 @@ declare global {
55
55
  * @returns index of the tile
56
56
  * @example
57
57
  * ```ts
58
- * // get the tile under the player.
59
- * const tileno = tilemap.get_tile("/level#tilemap", "foreground", self.player_x, self.player_y);
58
+ * function tile_under_player(self: { player_x: number; player_y: number }) {
59
+ * // get the tile under the player.
60
+ * const tileno = tilemap.get_tile("/level#tilemap", "foreground", self.player_x, self.player_y);
61
+ * }
60
62
  * ```
61
63
  */
62
64
  function get_tile(url: string | Hash | Url, layer: string | Hash, x: number, y: number): number;
@@ -74,15 +76,17 @@ declare global {
74
76
  * @returns index of the tile
75
77
  * @example
76
78
  * ```ts
77
- * // get the tile under the player.
78
- * const tile_info = tilemap.get_tile_info("/level#tilemap", "foreground", self.player_x, self.player_y);
79
- * pprint(tile_info);
80
- * // {
81
- * // index = 0,
82
- * // h_flip = false,
83
- * // v_flip = true,
84
- * // rotate_90 = false
85
- * // }
79
+ * function tile_info_under_player(self: { player_x: number; player_y: number }) {
80
+ * // get the tile under the player.
81
+ * const tile_info = tilemap.get_tile_info("/level#tilemap", "foreground", self.player_x, self.player_y);
82
+ * pprint(tile_info);
83
+ * // {
84
+ * // index = 0,
85
+ * // h_flip = false,
86
+ * // v_flip = true,
87
+ * // rotate_90 = false
88
+ * // }
89
+ * }
86
90
  * ```
87
91
  */
88
92
  function get_tile_info(url: string | Hash | Url, layer: string | Hash, x: number, y: number): { index: number; h_flip: boolean; v_flip: boolean; rotate_90: boolean };
@@ -103,7 +107,7 @@ declare global {
103
107
  * let count = 0;
104
108
  * for (let row_index = bottom; row_index <= bottom + rows_count - 1; row_index++) {
105
109
  * for (let column_index = left; column_index <= left + columns_count - 1; column_index++) {
106
- * tile = tiles[row_index][column_index];
110
+ * tile = tiles.get(row_index)?.get(column_index) ?? 0;
107
111
  * count = count + 1;
108
112
  * }
109
113
  * }
@@ -155,14 +159,16 @@ declare global {
155
159
  * @param transform_bitmask - optional flip and/or rotation should be applied to the tile
156
160
  * @example
157
161
  * ```ts
158
- * // Clear the tile under the player.
159
- * tilemap.set_tile("/level#tilemap", "foreground", self.player_x, self.player_y, 0);
162
+ * function set_tiles(self: { player_x: number; player_y: number }, x: number, y: number) {
163
+ * // Clear the tile under the player.
164
+ * tilemap.set_tile("/level#tilemap", "foreground", self.player_x, self.player_y, 0);
160
165
  *
161
- * // Set tile with different combination of flip and rotation
162
- * tilemap.set_tile("#tilemap", "layer1", x, y, 0, tilemap.H_FLIP + tilemap.V_FLIP + tilemap.ROTATE_90);
163
- * tilemap.set_tile("#tilemap", "layer1", x, y, 0, tilemap.H_FLIP + tilemap.ROTATE_270);
164
- * tilemap.set_tile("#tilemap", "layer1", x, y, 0, tilemap.V_FLIP + tilemap.H_FLIP);
165
- * tilemap.set_tile("#tilemap", "layer1", x, y, 0, tilemap.ROTATE_180);
166
+ * // Set tile with different combination of flip and rotation
167
+ * tilemap.set_tile("#tilemap", "layer1", x, y, 0, tilemap.H_FLIP + tilemap.V_FLIP + tilemap.ROTATE_90);
168
+ * tilemap.set_tile("#tilemap", "layer1", x, y, 0, tilemap.H_FLIP + tilemap.ROTATE_270);
169
+ * tilemap.set_tile("#tilemap", "layer1", x, y, 0, tilemap.V_FLIP + tilemap.H_FLIP);
170
+ * tilemap.set_tile("#tilemap", "layer1", x, y, 0, tilemap.ROTATE_180);
171
+ * }
166
172
  * ```
167
173
  */
168
174
  function set_tile(url: string | Hash | Url, layer: string | Hash, x: number, y: number, tile: number, transform_bitmask?: number): void;
@@ -20,11 +20,13 @@ declare global {
20
20
  * @returns if the timer was active, false if the timer is already cancelled / complete
21
21
  * @example
22
22
  * ```ts
23
- * self.handle = timer.delay(1, true, () => print("print every second"));
24
- * // ...
25
- * const result = timer.cancel(self.handle);
26
- * if (!result) {
27
- * print("the timer is already cancelled");
23
+ * function cancel_ticking(self: { handle: number }) {
24
+ * self.handle = timer.delay(1, true, () => print("print every second"));
25
+ * // ...
26
+ * const result = timer.cancel(self.handle);
27
+ * if (!result) {
28
+ * print("the timer is already cancelled");
29
+ * }
28
30
  * }
29
31
  * ```
30
32
  */
@@ -54,16 +56,19 @@ declare global {
54
56
  * timer.delay(1, false, () => print("print in one second"));
55
57
  *
56
58
  * // Repetitive timer which canceled after 10 calls
57
- * function call_every_second(self, handle, time_elapsed) {
58
- * self.counter = self.counter + 1;
59
- * print("Call #", self.counter);
60
- * if (self.counter === 10) {
61
- * timer.cancel(handle); // cancel timer after 10 calls
59
+ * function call_every_second(self: unknown, handle: unknown, time_elapsed: unknown) {
60
+ * const state = self as { counter: number };
61
+ * state.counter = state.counter + 1;
62
+ * print("Call #", state.counter);
63
+ * if (state.counter === 10) {
64
+ * timer.cancel(handle as number); // cancel timer after 10 calls
62
65
  * }
63
66
  * }
64
67
  *
65
- * self.counter = 0;
66
- * timer.delay(1, true, call_every_second);
68
+ * function start_counting(self: { counter: number }) {
69
+ * self.counter = 0;
70
+ * timer.delay(1, true, call_every_second);
71
+ * }
67
72
  * ```
68
73
  */
69
74
  function delay(delay: number, repeating: boolean, callback: (self: unknown, handle: unknown, time_elapsed: unknown) => void): number;
@@ -81,13 +86,15 @@ declare global {
81
86
  * boolean true = repeat timer until cancel, false = one-shot timer.
82
87
  * @example
83
88
  * ```ts
84
- * self.handle = timer.delay(1, true, () => print("print every second"));
85
- * // ...
86
- * const result = timer.get_info(self.handle);
87
- * if (!result) {
88
- * print("the timer is already cancelled or complete");
89
- * } else {
90
- * pprint(result); // delay, time_remaining, repeating
89
+ * function report_ticking(self: { handle: number }) {
90
+ * self.handle = timer.delay(1, true, () => print("print every second"));
91
+ * // ...
92
+ * const result = timer.get_info(self.handle);
93
+ * if (!result) {
94
+ * print("the timer is already cancelled or complete");
95
+ * } else {
96
+ * pprint(result); // delay, time_remaining, repeating
97
+ * }
91
98
  * }
92
99
  * ```
93
100
  */
@@ -99,11 +106,13 @@ declare global {
99
106
  * @returns if the timer was active, false if the timer is already cancelled / complete
100
107
  * @example
101
108
  * ```ts
102
- * self.handle = timer.delay(1, true, () => print("print every second or manually by timer.trigger"));
103
- * // ...
104
- * const result = timer.trigger(self.handle);
105
- * if (!result) {
106
- * print("the timer is already cancelled or complete");
109
+ * function trigger_ticking(self: { handle: number }) {
110
+ * self.handle = timer.delay(1, true, () => print("print every second or manually by timer.trigger"));
111
+ * // ...
112
+ * const result = timer.trigger(self.handle);
113
+ * if (!result) {
114
+ * print("the timer is already cancelled or complete");
115
+ * }
107
116
  * }
108
117
  * ```
109
118
  */
@@ -49,7 +49,7 @@ declare global {
49
49
  function conj(q1: Quaternion): Quaternion;
50
50
  /**
51
51
  * Given two linearly independent vectors P and Q, the cross product,
52
- * P &#x00D7; Q, is a vector that is perpendicular to both P and Q and
52
+ * P × Q, is a vector that is perpendicular to both P and Q and
53
53
  * therefore normal to the plane containing them.
54
54
  * If the two vectors have the same direction (or have the exact
55
55
  * opposite direction from one another, i.e. are not linearly independent)
@@ -70,8 +70,8 @@ declare global {
70
70
  function cross(v1: Vector3, v2: Vector3): Vector3;
71
71
  /**
72
72
  * The returned value is a scalar defined as:
73
- * `P &#x22C5; Q = |P| |Q| cos &#x03B8;`
74
- * where &#x03B8; is the angle between the vectors P and Q.
73
+ * `P ⋅ Q = |P| |Q| cos θ`
74
+ * where θ is the angle between the vectors P and Q.
75
75
  *
76
76
  * - If the dot product is positive then the angle between the vectors is below 90 degrees.
77
77
  *
@@ -84,6 +84,9 @@ declare global {
84
84
  * @returns dot product
85
85
  * @example
86
86
  * ```ts
87
+ * const vector1 = vmath.vector3(1, 0, 0);
88
+ * const vector2 = vmath.vector3(0, 1, 0);
89
+ *
87
90
  * if (vmath.dot(vector1, vector2) === 0) {
88
91
  * // The two vectors are perpendicular (at right-angles to each other)
89
92
  * // ...
@@ -119,12 +122,14 @@ declare global {
119
122
  * @returns length
120
123
  * @example
121
124
  * ```ts
122
- * if (vmath.length(self.velocity) < max_velocity) {
123
- * // The speed (velocity vector) is below max.
125
+ * function below_max_speed(self: { velocity: Vector3 }, max_velocity: number) {
126
+ * if (vmath.length(self.velocity) < max_velocity) {
127
+ * // The speed (velocity vector) is below max.
124
128
  *
125
- * // TODO: max_velocity can be expressed as squared
126
- * // so we can compare with length_sqr() instead.
127
- * // ...
129
+ * // TODO: max_velocity can be expressed as squared
130
+ * // so we can compare with length_sqr() instead.
131
+ * // ...
132
+ * }
128
133
  * }
129
134
  * ```
130
135
  */
@@ -136,6 +141,9 @@ declare global {
136
141
  * @returns squared length
137
142
  * @example
138
143
  * ```ts
144
+ * const vector1 = vmath.vector3(1, 0, 0);
145
+ * const vector2 = vmath.vector3(0, 2, 0);
146
+ *
139
147
  * if (vmath.length_sqr(vector1) < vmath.length_sqr(vector2)) {
140
148
  * // Vector 1 has less magnitude than vector 2
141
149
  * // ...
@@ -429,8 +437,8 @@ declare global {
429
437
  /**
430
438
  * Calculates the extent the projection of the first vector onto the second.
431
439
  * The returned value is a scalar p defined as:
432
- * `p = |P| cos &#x03B8; / |Q|`
433
- * where &#x03B8; is the angle between the vectors P and Q.
440
+ * `p = |P| cos θ / |Q|`
441
+ * where θ is the angle between the vectors P and Q.
434
442
  *
435
443
  * @param v1 - vector to be projected on the second
436
444
  * @param v2 - vector onto which the first will be projected, must not have zero length
@@ -5,6 +5,8 @@ declare global {
5
5
  * and screen dimming.
6
6
  */
7
7
  namespace window {
8
+ type DimModeState = typeof window.DIMMING_UNKNOWN | typeof window.DIMMING_ON | typeof window.DIMMING_OFF;
9
+ type DimModeStateSettable = typeof window.DIMMING_ON | typeof window.DIMMING_OFF;
8
10
  /**
9
11
  * Dimming mode is used to control whether or not a mobile device should dim the screen after a period without user interaction.
10
12
  */
@@ -56,7 +58,7 @@ declare global {
56
58
  *
57
59
  * - `window.DIMMING_OFF`
58
60
  */
59
- function get_dim_mode(): number & { readonly __brand: "window.DIMMING_UNKNOWN" } | number & { readonly __brand: "window.DIMMING_ON" } | number & { readonly __brand: "window.DIMMING_OFF" };
61
+ function get_dim_mode(): window.DimModeState;
60
62
  /**
61
63
  * This returns the content scale of the current display.
62
64
  *
@@ -111,7 +113,7 @@ declare global {
111
113
  *
112
114
  * - `window.DIMMING_OFF`
113
115
  */
114
- function set_dim_mode(mode: number & { readonly __brand: "window.DIMMING_ON" } | number & { readonly __brand: "window.DIMMING_OFF" }): void;
116
+ function set_dim_mode(mode: window.DimModeStateSettable): void;
115
117
  /**
116
118
  * Sets a window event listener. Only one window event listener can be set at a time.
117
119
  *
@@ -140,7 +142,7 @@ declare global {
140
142
  * - number `height`: The height of a resize event. nil otherwise.
141
143
  * @example
142
144
  * ```ts
143
- * function window_callback(self, event, data) {
145
+ * function window_callback(self: unknown, event: unknown, data: Record<string | number, unknown>) {
144
146
  * if (event === window.WINDOW_EVENT_FOCUS_LOST) {
145
147
  * print("window.WINDOW_EVENT_FOCUS_LOST");
146
148
  * } else if (event === window.WINDOW_EVENT_FOCUS_GAINED) {
@@ -49,7 +49,7 @@ declare global {
49
49
  function conj(q1: Quaternion): Quaternion;
50
50
  /**
51
51
  * Given two linearly independent vectors P and Q, the cross product,
52
- * P &#x00D7; Q, is a vector that is perpendicular to both P and Q and
52
+ * P × Q, is a vector that is perpendicular to both P and Q and
53
53
  * therefore normal to the plane containing them.
54
54
  * If the two vectors have the same direction (or have the exact
55
55
  * opposite direction from one another, i.e. are not linearly independent)
@@ -70,8 +70,8 @@ declare global {
70
70
  function cross(v1: Vector3, v2: Vector3): Vector3;
71
71
  /**
72
72
  * The returned value is a scalar defined as:
73
- * `P &#x22C5; Q = |P| |Q| cos &#x03B8;`
74
- * where &#x03B8; is the angle between the vectors P and Q.
73
+ * `P ⋅ Q = |P| |Q| cos θ`
74
+ * where θ is the angle between the vectors P and Q.
75
75
  *
76
76
  * - If the dot product is positive then the angle between the vectors is below 90 degrees.
77
77
  *
@@ -84,6 +84,9 @@ declare global {
84
84
  * @returns dot product
85
85
  * @example
86
86
  * ```ts
87
+ * const vector1 = vmath.vector3(1, 0, 0);
88
+ * const vector2 = vmath.vector3(0, 1, 0);
89
+ *
87
90
  * if (vmath.dot(vector1, vector2) === 0) {
88
91
  * // The two vectors are perpendicular (at right-angles to each other)
89
92
  * // ...
@@ -119,12 +122,14 @@ declare global {
119
122
  * @returns length
120
123
  * @example
121
124
  * ```ts
122
- * if (vmath.length(self.velocity) < max_velocity) {
123
- * // The speed (velocity vector) is below max.
125
+ * function below_max_speed(self: { velocity: Vector3 }, max_velocity: number) {
126
+ * if (vmath.length(self.velocity) < max_velocity) {
127
+ * // The speed (velocity vector) is below max.
124
128
  *
125
- * // TODO: max_velocity can be expressed as squared
126
- * // so we can compare with length_sqr() instead.
127
- * // ...
129
+ * // TODO: max_velocity can be expressed as squared
130
+ * // so we can compare with length_sqr() instead.
131
+ * // ...
132
+ * }
128
133
  * }
129
134
  * ```
130
135
  */
@@ -136,6 +141,9 @@ declare global {
136
141
  * @returns squared length
137
142
  * @example
138
143
  * ```ts
144
+ * const vector1 = vmath.vector3(1, 0, 0);
145
+ * const vector2 = vmath.vector3(0, 2, 0);
146
+ *
139
147
  * if (vmath.length_sqr(vector1) < vmath.length_sqr(vector2)) {
140
148
  * // Vector 1 has less magnitude than vector 2
141
149
  * // ...
@@ -429,8 +437,8 @@ declare global {
429
437
  /**
430
438
  * Calculates the extent the projection of the first vector onto the second.
431
439
  * The returned value is a scalar p defined as:
432
- * `p = |P| cos &#x03B8; / |Q|`
433
- * where &#x03B8; is the angle between the vectors P and Q.
440
+ * `p = |P| cos θ / |Q|`
441
+ * where θ is the angle between the vectors P and Q.
434
442
  *
435
443
  * @param v1 - vector to be projected on the second
436
444
  * @param v2 - vector onto which the first will be projected, must not have zero length