@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.
- package/api-availability.json +117 -0
- package/api-signatures.json +586 -480
- package/examples/translations.json +356 -180
- package/generated/b2d_body.d.ts +7 -4
- package/generated/b2d_shape.d.ts +23 -1
- package/generated/buffer.d.ts +34 -19
- package/generated/camera.d.ts +3 -2
- package/generated/collectionfactory.d.ts +17 -12
- package/generated/collectionproxy.d.ts +2 -2
- package/generated/compute.d.ts +1 -1
- package/generated/factory.d.ts +2 -1
- package/generated/go.d.ts +150 -91
- package/generated/graphics.d.ts +54 -0
- package/generated/gui.d.ts +117 -71
- package/generated/html5.d.ts +4 -2
- package/generated/http.d.ts +8 -2
- package/generated/image.d.ts +24 -15
- package/generated/kinds/gui-script.d.ts +1 -0
- package/generated/kinds/render-script.d.ts +1 -0
- package/generated/kinds/script.d.ts +1 -0
- package/generated/material.d.ts +1 -1
- package/generated/model.d.ts +41 -7
- package/generated/particlefx.d.ts +1 -1
- package/generated/physics.d.ts +29 -20
- package/generated/profiler.d.ts +10 -3
- package/generated/render.d.ts +293 -111
- package/generated/resource.d.ts +243 -226
- package/generated/socket.d.ts +33 -18
- package/generated/sound.d.ts +6 -5
- package/generated/sprite.d.ts +9 -1
- package/generated/sys.d.ts +44 -27
- package/generated/tilemap.d.ts +25 -19
- package/generated/timer.d.ts +33 -24
- package/generated/versions/defold-1.12.4/buffer.d.ts +34 -19
- package/generated/versions/defold-1.12.4/camera.d.ts +3 -2
- package/generated/versions/defold-1.12.4/collectionfactory.d.ts +17 -12
- package/generated/versions/defold-1.12.4/collectionproxy.d.ts +1 -1
- package/generated/versions/defold-1.12.4/factory.d.ts +2 -1
- package/generated/versions/defold-1.12.4/go.d.ts +150 -91
- package/generated/versions/defold-1.12.4/graphics.d.ts +2 -0
- package/generated/versions/defold-1.12.4/gui.d.ts +109 -69
- package/generated/versions/defold-1.12.4/html5.d.ts +4 -2
- package/generated/versions/defold-1.12.4/http.d.ts +8 -2
- package/generated/versions/defold-1.12.4/image.d.ts +24 -15
- package/generated/versions/defold-1.12.4/index.d.ts +1 -0
- package/generated/versions/defold-1.12.4/model.d.ts +41 -7
- package/generated/versions/defold-1.12.4/particlefx.d.ts +1 -1
- package/generated/versions/defold-1.12.4/physics.d.ts +29 -20
- package/generated/versions/defold-1.12.4/profiler.d.ts +10 -3
- package/generated/versions/defold-1.12.4/render.d.ts +292 -110
- package/generated/versions/defold-1.12.4/resource.d.ts +243 -226
- package/generated/versions/defold-1.12.4/socket.d.ts +33 -18
- package/generated/versions/defold-1.12.4/sound.d.ts +6 -5
- package/generated/versions/defold-1.12.4/sprite.d.ts +9 -1
- package/generated/versions/defold-1.12.4/sys.d.ts +44 -27
- package/generated/versions/defold-1.12.4/tilemap.d.ts +25 -19
- package/generated/versions/defold-1.12.4/timer.d.ts +33 -24
- package/generated/versions/defold-1.12.4/vmath.d.ts +18 -10
- package/generated/versions/defold-1.12.4/window.d.ts +5 -3
- package/generated/versions/defold-1.13.0/b2d_body.d.ts +7 -4
- package/generated/versions/defold-1.13.0/b2d_shape.d.ts +23 -1
- package/generated/versions/defold-1.13.0/buffer.d.ts +34 -19
- package/generated/versions/defold-1.13.0/camera.d.ts +3 -2
- package/generated/versions/defold-1.13.0/collectionfactory.d.ts +17 -12
- package/generated/versions/defold-1.13.0/collectionproxy.d.ts +1 -1
- package/generated/versions/defold-1.13.0/compute.d.ts +1 -1
- package/generated/versions/defold-1.13.0/factory.d.ts +2 -1
- package/generated/versions/defold-1.13.0/go.d.ts +150 -91
- package/generated/versions/defold-1.13.0/graphics.d.ts +50 -0
- package/generated/versions/defold-1.13.0/gui.d.ts +109 -69
- package/generated/versions/defold-1.13.0/html5.d.ts +4 -2
- package/generated/versions/defold-1.13.0/http.d.ts +8 -2
- package/generated/versions/defold-1.13.0/image.d.ts +24 -15
- package/generated/versions/defold-1.13.0/index.d.ts +1 -0
- package/generated/versions/defold-1.13.0/material.d.ts +1 -1
- package/generated/versions/defold-1.13.0/model.d.ts +41 -7
- package/generated/versions/defold-1.13.0/particlefx.d.ts +1 -1
- package/generated/versions/defold-1.13.0/physics.d.ts +29 -20
- package/generated/versions/defold-1.13.0/profiler.d.ts +10 -3
- package/generated/versions/defold-1.13.0/render.d.ts +293 -111
- package/generated/versions/defold-1.13.0/resource.d.ts +243 -226
- package/generated/versions/defold-1.13.0/socket.d.ts +33 -18
- package/generated/versions/defold-1.13.0/sound.d.ts +6 -5
- package/generated/versions/defold-1.13.0/sprite.d.ts +9 -1
- package/generated/versions/defold-1.13.0/sys.d.ts +44 -27
- package/generated/versions/defold-1.13.0/tilemap.d.ts +25 -19
- package/generated/versions/defold-1.13.0/timer.d.ts +33 -24
- package/generated/versions/defold-1.13.0/vmath.d.ts +18 -10
- package/generated/versions/defold-1.13.0/window.d.ts +5 -3
- package/generated/vmath.d.ts +18 -10
- package/generated/window.d.ts +5 -3
- package/index.d.ts +1 -0
- package/package.json +2 -1
- package/scripts/generate-api-signatures.ts +2 -1
- package/scripts/prose-constants.ts +96 -0
- package/scripts/regen.ts +6 -2
- package/src/api-doc.ts +8 -0
- package/src/component-properties.d.ts +33 -0
- package/src/core-types.ts +4 -2
- package/src/custom-messages.d.ts +4 -3
- package/src/doc-comment.ts +247 -43
- package/src/emit-dts.ts +958 -57
- package/src/engine-globals.d.ts +2 -2
- package/src/example-store.ts +26 -0
- package/src/go-overloads.d.ts +11 -10
- package/src/index.ts +9 -0
- package/src/param-correction-provenance.ts +67 -0
- package/src/render-overloads.d.ts +15 -17
- package/src/script-api.ts +3 -1
package/generated/socket.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ declare global {
|
|
|
17
17
|
* require "builtins.scripts.socket"
|
|
18
18
|
* ```
|
|
19
19
|
*
|
|
20
|
-
* LuaSocket is Copyright
|
|
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
|
-
*
|
|
639
|
-
*
|
|
640
|
-
*
|
|
641
|
-
* try_(c.
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
*
|
|
645
|
-
* c.
|
|
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
|
|
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
|
|
665
|
+
* const [conn, connectError] = socket.connect("myserver.com", 80);
|
|
666
|
+
* const c = try_(conn, connectError);
|
|
660
667
|
* try_ = socket.newtry(() => c.close());
|
|
661
|
-
*
|
|
662
|
-
*
|
|
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): (
|
|
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
|
-
*
|
|
699
|
-
*
|
|
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
|
-
*
|
|
703
|
-
*
|
|
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]>;
|
package/generated/sound.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
*
|
|
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(
|
|
205
|
-
*
|
|
205
|
+
* init() {
|
|
206
|
+
* return { countdown_id: sound.play("#countdown", undefined, sound_done) };
|
|
206
207
|
* },
|
|
207
208
|
* });
|
|
208
209
|
* ```
|
package/generated/sprite.d.ts
CHANGED
|
@@ -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:
|
|
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);
|
package/generated/sys.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
57
|
-
*
|
|
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():
|
|
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
|
-
*
|
|
263
|
-
*
|
|
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
|
-
*
|
|
267
|
-
*
|
|
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
|
-
*
|
|
447
|
-
*
|
|
448
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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 ===
|
|
471
|
+
* } else if (request_id === first_asset) {
|
|
459
472
|
* // result.buffer contains data from my_level_asset.bin
|
|
460
|
-
* } else if (request_id ===
|
|
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(
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
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:
|
package/generated/tilemap.d.ts
CHANGED
|
@@ -55,8 +55,10 @@ declare global {
|
|
|
55
55
|
* @returns index of the tile
|
|
56
56
|
* @example
|
|
57
57
|
* ```ts
|
|
58
|
-
*
|
|
59
|
-
*
|
|
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
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
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
|
|
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
|
-
*
|
|
159
|
-
*
|
|
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
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
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;
|
package/generated/timer.d.ts
CHANGED
|
@@ -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
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
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
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
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
|
|
66
|
-
*
|
|
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
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
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
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
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
|
*/
|
|
@@ -6,6 +6,7 @@ declare global {
|
|
|
6
6
|
* Functions for manipulating buffers and streams
|
|
7
7
|
*/
|
|
8
8
|
namespace buffer {
|
|
9
|
+
type ValueType = typeof buffer.VALUE_TYPE_FLOAT32 | typeof buffer.VALUE_TYPE_INT16 | typeof buffer.VALUE_TYPE_INT32 | typeof buffer.VALUE_TYPE_INT64 | typeof buffer.VALUE_TYPE_INT8 | typeof buffer.VALUE_TYPE_UINT16 | typeof buffer.VALUE_TYPE_UINT32 | typeof buffer.VALUE_TYPE_UINT64 | typeof buffer.VALUE_TYPE_UINT8;
|
|
9
10
|
/**
|
|
10
11
|
* Float, single precision, 4 bytes
|
|
11
12
|
*/
|
|
@@ -56,11 +57,15 @@ declare global {
|
|
|
56
57
|
* @example
|
|
57
58
|
* ```ts
|
|
58
59
|
* // How to copy elements (e.g. vertices) from one buffer to another
|
|
60
|
+
* const element_count = 64;
|
|
61
|
+
* const srcbuffer = resource.get_buffer("/src.bufferc");
|
|
62
|
+
* const dstbuffer = resource.get_buffer("/dst.bufferc");
|
|
63
|
+
*
|
|
59
64
|
* // copy entire buffer
|
|
60
|
-
* buffer.copy_buffer(dstbuffer, 0, srcbuffer, 0,
|
|
65
|
+
* buffer.copy_buffer(dstbuffer, 0, srcbuffer, 0, element_count);
|
|
61
66
|
*
|
|
62
67
|
* // copy last 10 elements to the front of another buffer
|
|
63
|
-
* buffer.copy_buffer(dstbuffer, 0, srcbuffer,
|
|
68
|
+
* buffer.copy_buffer(dstbuffer, 0, srcbuffer, element_count - 10, 10);
|
|
64
69
|
* ```
|
|
65
70
|
*/
|
|
66
71
|
function copy_buffer(dst: Opaque<"buffer">, dstoffset: number, src: Opaque<"buffer">, srcoffset: number, count: number): void;
|
|
@@ -77,13 +82,16 @@ declare global {
|
|
|
77
82
|
* @example
|
|
78
83
|
* ```ts
|
|
79
84
|
* // How to update a texture of a sprite:
|
|
85
|
+
* const srcbuffer = resource.get_buffer("/src.bufferc");
|
|
86
|
+
* const dstbuffer = resource.get_buffer("/dst.bufferc");
|
|
87
|
+
*
|
|
80
88
|
* // copy entire stream
|
|
81
89
|
* const srcstream = buffer.get_stream(srcbuffer, hash("xyz"));
|
|
82
90
|
* const dststream = buffer.get_stream(dstbuffer, hash("xyz"));
|
|
83
|
-
* buffer.copy_stream(dststream, 0, srcstream, 0, srcstream.length);
|
|
91
|
+
* buffer.copy_stream(dststream, 0, srcstream, 0, srcstream.length());
|
|
84
92
|
* ```
|
|
85
93
|
*/
|
|
86
|
-
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;
|
|
87
95
|
/**
|
|
88
96
|
* Create a new data buffer containing a specified set of streams. A data buffer
|
|
89
97
|
* can contain one or more streams with typed data. This is useful for managing
|
|
@@ -103,24 +111,27 @@ declare global {
|
|
|
103
111
|
* ```ts
|
|
104
112
|
* // How to create and initialize a buffer
|
|
105
113
|
* export default defineScript({
|
|
106
|
-
* init(
|
|
114
|
+
* init() {
|
|
107
115
|
* const size = 128;
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
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;
|
|
117
127
|
* }
|
|
118
128
|
* }
|
|
129
|
+
* return { image, imagestream };
|
|
119
130
|
* },
|
|
120
131
|
* });
|
|
121
132
|
* ```
|
|
122
133
|
*/
|
|
123
|
-
function create(element_count: number, declaration: { name?: Hash | string; type?:
|
|
134
|
+
function create(element_count: number, declaration: { name?: Hash | string; type?: buffer.ValueType; count?: number }[]): Opaque<"buffer">;
|
|
124
135
|
/**
|
|
125
136
|
* Get a copy of all the bytes from a specified stream as a Lua string.
|
|
126
137
|
*
|
|
@@ -128,7 +139,7 @@ declare global {
|
|
|
128
139
|
* @param stream_name - the name of the stream
|
|
129
140
|
* @returns the buffer data as a Lua string
|
|
130
141
|
*/
|
|
131
|
-
function get_bytes(buffer: Opaque<"buffer">, stream_name: Hash): string;
|
|
142
|
+
function get_bytes(buffer: Opaque<"buffer">, stream_name: Hash | string): string;
|
|
132
143
|
/**
|
|
133
144
|
* Get a named metadata entry from a buffer along with its type.
|
|
134
145
|
*
|
|
@@ -137,12 +148,14 @@ declare global {
|
|
|
137
148
|
* @example
|
|
138
149
|
* ```ts
|
|
139
150
|
* // How to get a metadata entry from a buffer
|
|
151
|
+
* const buf = resource.get_buffer("/my.bufferc");
|
|
152
|
+
*
|
|
140
153
|
* // retrieve a metadata entry named "somefloats" and its numeric type
|
|
141
154
|
* const [values, type] = buffer.get_metadata(buf, hash("somefloats"));
|
|
142
155
|
* if (values) print(`${values.length} values in 'somefloats'`);
|
|
143
156
|
* ```
|
|
144
157
|
*/
|
|
145
|
-
function get_metadata(buf: Opaque<"buffer">, metadata_name: Hash | string): LuaMultiReturn<[number[] | undefined,
|
|
158
|
+
function get_metadata(buf: Opaque<"buffer">, metadata_name: Hash | string): LuaMultiReturn<[number[] | undefined, buffer.ValueType | undefined]>;
|
|
146
159
|
/**
|
|
147
160
|
* Get a specified stream from a buffer.
|
|
148
161
|
*
|
|
@@ -150,7 +163,7 @@ declare global {
|
|
|
150
163
|
* @param stream_name - the stream name
|
|
151
164
|
* @returns the data stream
|
|
152
165
|
*/
|
|
153
|
-
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> };
|
|
154
167
|
/**
|
|
155
168
|
* Creates or updates a metadata array entry on a buffer.
|
|
156
169
|
* The value type and count given when updating the entry should match those used when first creating it.
|
|
@@ -162,6 +175,8 @@ declare global {
|
|
|
162
175
|
* @example
|
|
163
176
|
* ```ts
|
|
164
177
|
* // How to set a metadata entry on a buffer
|
|
178
|
+
* const buf = resource.get_buffer("/my.bufferc");
|
|
179
|
+
*
|
|
165
180
|
* // create a new metadata entry with three floats
|
|
166
181
|
* buffer.set_metadata(buf, hash("somefloats"), [1.5, 3.2, 7.9], buffer.VALUE_TYPE_FLOAT32);
|
|
167
182
|
* // ...
|
|
@@ -169,7 +184,7 @@ declare global {
|
|
|
169
184
|
* buffer.set_metadata(buf, hash("somefloats"), [-2.5, 10.0, 32.2], buffer.VALUE_TYPE_FLOAT32);
|
|
170
185
|
* ```
|
|
171
186
|
*/
|
|
172
|
-
function set_metadata(buf: Opaque<"buffer">, metadata_name: Hash | string, values: number[], value_type:
|
|
187
|
+
function set_metadata(buf: Opaque<"buffer">, metadata_name: Hash | string, values: number[], value_type: buffer.ValueType): void;
|
|
173
188
|
}
|
|
174
189
|
}
|
|
175
190
|
|
|
@@ -45,6 +45,7 @@ declare global {
|
|
|
45
45
|
* @returns a table with all camera URLs
|
|
46
46
|
* @example
|
|
47
47
|
* ```ts
|
|
48
|
+
* const predicate = render.predicate([hash("my_tag")]);
|
|
48
49
|
* for (const camera_id of camera.get_cameras()) {
|
|
49
50
|
* render.set_camera(camera_id);
|
|
50
51
|
* render.draw(predicate);
|
|
@@ -125,7 +126,7 @@ declare global {
|
|
|
125
126
|
* export default defineScript({
|
|
126
127
|
* on_input(self, action_id, action) {
|
|
127
128
|
* if (action_id === hash("touch")) {
|
|
128
|
-
* if (action.pressed) {
|
|
129
|
+
* if (action.pressed && action.screen_x !== undefined && action.screen_y !== undefined) {
|
|
129
130
|
* const perspective_camera = msg.url("#perspective_camera");
|
|
130
131
|
* const random_z = math.random(
|
|
131
132
|
* camera.get_near_z(perspective_camera) + 0.01,
|
|
@@ -157,7 +158,7 @@ declare global {
|
|
|
157
158
|
* export default defineScript({
|
|
158
159
|
* on_input(self, action_id, action) {
|
|
159
160
|
* if (action_id === hash("touch")) {
|
|
160
|
-
* if (action.pressed) {
|
|
161
|
+
* if (action.pressed && action.screen_x !== undefined && action.screen_y !== undefined) {
|
|
161
162
|
* const world_position = camera.screen_xy_to_world(action.screen_x, action.screen_y);
|
|
162
163
|
* go.set_position(world_position, "/go1");
|
|
163
164
|
* }
|