@defold-typescript/types 0.5.1 → 0.5.3
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/README.md +1 -1
- package/generated/buffer.d.ts +3 -3
- package/generated/collectionfactory.d.ts +9 -9
- package/generated/collectionproxy.d.ts +1 -1
- package/generated/factory.d.ts +9 -9
- package/generated/go.d.ts +12 -12
- package/generated/gui.d.ts +147 -147
- package/generated/http.d.ts +21 -21
- package/generated/iac.d.ts +1 -1
- package/generated/iap.d.ts +4 -4
- package/generated/image.d.ts +30 -30
- package/generated/json.d.ts +2 -2
- 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/model.d.ts +23 -23
- package/generated/particlefx.d.ts +13 -13
- package/generated/physics.d.ts +87 -87
- package/generated/profiler.d.ts +11 -11
- package/generated/render.d.ts +67 -67
- package/generated/resource.d.ts +372 -372
- package/generated/sound.d.ts +23 -23
- package/generated/sprite.d.ts +14 -14
- package/generated/sys.d.ts +57 -57
- package/generated/timer.d.ts +12 -12
- package/generated/window.d.ts +28 -28
- package/index.d.ts +4 -0
- package/package.json +1 -1
- package/scripts/regen.ts +1 -0
- package/src/doc-comment.ts +10 -2
- package/src/index.ts +2 -0
- package/src/message-dispatch.d.ts +23 -0
- package/src/message-guard.d.ts +16 -0
package/generated/sound.d.ts
CHANGED
|
@@ -152,28 +152,28 @@ declare global {
|
|
|
152
152
|
*
|
|
153
153
|
* @param url - the sound that should play
|
|
154
154
|
* @param play_properties - optional table with properties:
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
155
|
+
* `delay`
|
|
156
|
+
* number delay in seconds before the sound starts playing, default is 0.
|
|
157
|
+
* `gain`
|
|
158
|
+
* number sound gain between 0 and 1, default is 1. The final gain of the sound will be a combination of this gain, the group gain and the master gain.
|
|
159
|
+
* `pan`
|
|
160
|
+
* number sound pan between -1 and 1, default is 0. The final pan of the sound will be an addition of this pan and the sound pan.
|
|
161
|
+
* `speed`
|
|
162
|
+
* number sound speed where 1.0 is normal speed, 0.5 is half speed and 2.0 is double speed. Valid range is 0.0 to 50.0. The final speed of the sound will be a multiplication of this speed and the sound speed.
|
|
163
|
+
* `start_time`
|
|
164
|
+
* number start playback offset (seconds). Optional, mutually exclusive with `start_frame`.
|
|
165
|
+
* `start_frame`
|
|
166
|
+
* number start playback offset (frames/samples). Optional, mutually exclusive with `start_time`. If both are provided, `start_frame` is used.
|
|
167
167
|
* @param complete_function - function to call when the sound has finished playing or stopped manually via sound.stop.
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
168
|
+
* `self`
|
|
169
|
+
* object The current object.
|
|
170
|
+
* `message_id`
|
|
171
|
+
* hash The name of the completion message, which can be either `"sound_done"` if the sound has finished playing, or `"sound_stopped"` if it was stopped manually.
|
|
172
|
+
* `message`
|
|
173
|
+
* table Information about the completion:
|
|
174
|
+
* - number `play_id` - the sequential play identifier that was given by the sound.play function.
|
|
175
|
+
* `sender`
|
|
176
|
+
* url The invoker of the callback: the sound component.
|
|
177
177
|
* @returns The identifier for the sound voice
|
|
178
178
|
* @example
|
|
179
179
|
* ```lua
|
|
@@ -236,8 +236,8 @@ declare global {
|
|
|
236
236
|
*
|
|
237
237
|
* @param url - the sound component that should stop
|
|
238
238
|
* @param stop_properties - optional table with properties:
|
|
239
|
-
|
|
240
|
-
|
|
239
|
+
* `play_id`
|
|
240
|
+
* number the sequential play identifier that should be stopped (was given by the sound.play() function)
|
|
241
241
|
* @example
|
|
242
242
|
* ```lua
|
|
243
243
|
* Assuming the script belongs to an instance with a sound-component with id "sound", this will make the component stop all playing voices:
|
package/generated/sprite.d.ts
CHANGED
|
@@ -12,21 +12,21 @@ declare global {
|
|
|
12
12
|
* @param url - the sprite that should play the animation
|
|
13
13
|
* @param id - hashed id of the animation to play
|
|
14
14
|
* @param complete_function - function to call when the animation has completed.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
* `self`
|
|
16
|
+
* object The current object.
|
|
17
|
+
* `message_id`
|
|
18
|
+
* hash The name of the completion message, `"animation_done"`.
|
|
19
|
+
* `message`
|
|
20
|
+
* table Information about the completion:
|
|
21
|
+
* - number `current_tile` - the current tile of the sprite.
|
|
22
|
+
* - hash `id` - id of the animation that was completed.
|
|
23
|
+
* `sender`
|
|
24
|
+
* url The invoker of the callback: the sprite component.
|
|
25
25
|
* @param play_properties - optional table with properties:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
* `offset`
|
|
27
|
+
* number the normalized initial value of the animation cursor when the animation starts playing.
|
|
28
|
+
* `playback_rate`
|
|
29
|
+
* number the rate with which the animation will be played. Must be positive.
|
|
30
30
|
* @example
|
|
31
31
|
* ```lua
|
|
32
32
|
* The following examples assumes that the model has id "sprite".
|
package/generated/sys.d.ts
CHANGED
|
@@ -68,8 +68,8 @@ declare global {
|
|
|
68
68
|
*
|
|
69
69
|
* @param app_string - platform specific string with application package or query, see above for details.
|
|
70
70
|
* @returns table with application information in the following fields:
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
* `installed`
|
|
72
|
+
* boolean `true` if the application is installed, `false` otherwise.
|
|
73
73
|
* @example
|
|
74
74
|
* ```lua
|
|
75
75
|
* Check if twitter is installed:
|
|
@@ -194,9 +194,9 @@ declare global {
|
|
|
194
194
|
* On desktop, this function always return `sys.NETWORK_CONNECTED`.
|
|
195
195
|
*
|
|
196
196
|
* @returns network connectivity status:
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
197
|
+
* - `sys.NETWORK_DISCONNECTED` (no network connection is found)
|
|
198
|
+
* - `sys.NETWORK_CONNECTED_CELLULAR` (connected through mobile cellular)
|
|
199
|
+
* - `sys.NETWORK_CONNECTED` (otherwise, Wifi)
|
|
200
200
|
* @example
|
|
201
201
|
* ```lua
|
|
202
202
|
* Check if we are connected through a cellular connection
|
|
@@ -210,12 +210,12 @@ declare global {
|
|
|
210
210
|
* Returns a table with engine information.
|
|
211
211
|
*
|
|
212
212
|
* @returns table with engine information in the following fields:
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
213
|
+
* `version`
|
|
214
|
+
* string The current Defold engine version, i.e. "1.2.96"
|
|
215
|
+
* `version_sha1`
|
|
216
|
+
* string The SHA1 for the current engine build, i.e. "0060183cce2e29dbd09c85ece83cbb72068ee050"
|
|
217
|
+
* `is_debug`
|
|
218
|
+
* boolean If the engine is a debug or release version
|
|
219
219
|
* @example
|
|
220
220
|
* ```lua
|
|
221
221
|
* How to retrieve engine information:
|
|
@@ -248,16 +248,16 @@ declare global {
|
|
|
248
248
|
* Returns an array of tables with information on network interfaces.
|
|
249
249
|
*
|
|
250
250
|
* @returns an array of tables. Each table entry contain the following fields:
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
251
|
+
* `name`
|
|
252
|
+
* string Interface name
|
|
253
|
+
* `address`
|
|
254
|
+
* string IP address. might be `nil` if not available.
|
|
255
|
+
* `mac`
|
|
256
|
+
* string Hardware MAC address. might be nil if not available.
|
|
257
|
+
* `up`
|
|
258
|
+
* boolean `true` if the interface is up (available to transmit and receive data), `false` otherwise.
|
|
259
|
+
* `running`
|
|
260
|
+
* boolean `true` if the interface is running, `false` otherwise.
|
|
261
261
|
* @example
|
|
262
262
|
* ```lua
|
|
263
263
|
* How to get the IP address of interface "en0":
|
|
@@ -306,30 +306,30 @@ declare global {
|
|
|
306
306
|
* Returns a table with system information.
|
|
307
307
|
*
|
|
308
308
|
* @param options - optional options table
|
|
309
|
-
|
|
309
|
+
* - ignore_secure boolean this flag ignores values might be secured by OS e.g. `device_ident`
|
|
310
310
|
* @returns table with system information in the following fields:
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
311
|
+
* `device_model`
|
|
312
|
+
* string Only available on iOS and Android.
|
|
313
|
+
* `manufacturer`
|
|
314
|
+
* string Only available on iOS and Android.
|
|
315
|
+
* `system_name`
|
|
316
|
+
* string The system name: "Darwin", "Linux", "Windows", "HTML5", "Android" or "iPhone OS"
|
|
317
|
+
* `system_version`
|
|
318
|
+
* string The system OS version.
|
|
319
|
+
* `api_version`
|
|
320
|
+
* string The API version on the system.
|
|
321
|
+
* `language`
|
|
322
|
+
* string Two character ISO-639 format, i.e. "en".
|
|
323
|
+
* `device_language`
|
|
324
|
+
* string Two character ISO-639 format (i.e. "sr") and, if applicable, followed by a dash (-) and an ISO 15924 script code (i.e. "sr-Cyrl" or "sr-Latn"). Reflects the device preferred language.
|
|
325
|
+
* `territory`
|
|
326
|
+
* string Two character ISO-3166 format, i.e. "US".
|
|
327
|
+
* `gmt_offset`
|
|
328
|
+
* number The current offset from GMT (Greenwich Mean Time), in minutes.
|
|
329
|
+
* `device_ident`
|
|
330
|
+
* string This value secured by OS. "identifierForVendor" on iOS. "android_id" on Android. On Android, you need to add `READ_PHONE_STATE` permission to be able to get this data. We don't use this permission in Defold.
|
|
331
|
+
* `user_agent`
|
|
332
|
+
* string The HTTP user agent, i.e. "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 (KHTML, like Gecko) Version/10.0.3 Safari/602.4.8"
|
|
333
333
|
* @example
|
|
334
334
|
* ```lua
|
|
335
335
|
* How to get system information:
|
|
@@ -388,13 +388,13 @@ declare global {
|
|
|
388
388
|
*
|
|
389
389
|
* @param url - url to open
|
|
390
390
|
* @param attributes - table with attributes
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
391
|
+
* `target`
|
|
392
|
+
* - string : Optional. Specifies the target attribute or the name of the window. The following values are supported:
|
|
393
|
+
* - `_self` - (default value) URL replaces the current page.
|
|
394
|
+
* - `_blank` - URL is loaded into a new window, or tab.
|
|
395
|
+
* - `_parent` - URL is loaded into the parent frame.
|
|
396
|
+
* - `_top` - URL replaces any framesets that may be loaded.
|
|
397
|
+
* - `name` - The name of the window (Note: the name does not specify the title of the new window).
|
|
398
398
|
* @returns a boolean indicating if the url could be opened or not
|
|
399
399
|
* @example
|
|
400
400
|
* ```lua
|
|
@@ -482,12 +482,12 @@ declare global {
|
|
|
482
482
|
* The error handler is a function which is called whenever a lua runtime error occurs.
|
|
483
483
|
*
|
|
484
484
|
* @param error_handler - the function to be called on error
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
485
|
+
* `source`
|
|
486
|
+
* string The runtime context of the error. Currently, this is always `"lua"`.
|
|
487
|
+
* `message`
|
|
488
|
+
* string The source file, line number and error message.
|
|
489
|
+
* `traceback`
|
|
490
|
+
* string The stack traceback.
|
|
491
491
|
* @example
|
|
492
492
|
* ```lua
|
|
493
493
|
* Install error handler that just prints the errors
|
package/generated/timer.d.ts
CHANGED
|
@@ -33,12 +33,12 @@ declare global {
|
|
|
33
33
|
* @param delay - time interval in seconds
|
|
34
34
|
* @param repeating - true = repeat timer until cancel, false = one-shot timer
|
|
35
35
|
* @param callback - timer callback function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
* `self`
|
|
37
|
+
* object The current object
|
|
38
|
+
* `handle`
|
|
39
|
+
* number The handle of the timer
|
|
40
|
+
* `time_elapsed`
|
|
41
|
+
* number The elapsed time - on first trigger it is time since timer.delay call, otherwise time since last trigger
|
|
42
42
|
* @returns identifier for the create timer, returns timer.INVALID_TIMER_HANDLE if the timer can not be created
|
|
43
43
|
* @example
|
|
44
44
|
* ```lua
|
|
@@ -64,12 +64,12 @@ declare global {
|
|
|
64
64
|
*
|
|
65
65
|
* @param handle - the timer handle returned by timer.delay()
|
|
66
66
|
* @returns table or `nil` if timer is cancelled/completed. table with data in the following fields:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
* `time_remaining`
|
|
68
|
+
* number Time remaining until the next time a timer.delay() fires.
|
|
69
|
+
* `delay`
|
|
70
|
+
* number Time interval.
|
|
71
|
+
* `repeating`
|
|
72
|
+
* boolean true = repeat timer until cancel, false = one-shot timer.
|
|
73
73
|
* @example
|
|
74
74
|
* ```lua
|
|
75
75
|
* self.handle = timer.delay(1, true, function() print("print every second") end)
|
package/generated/window.d.ts
CHANGED
|
@@ -47,9 +47,9 @@ declare global {
|
|
|
47
47
|
* On platforms that does not support dimming, `window.DIMMING_UNKNOWN` is always returned.
|
|
48
48
|
*
|
|
49
49
|
* @returns The mode for screen dimming
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
* - `window.DIMMING_UNKNOWN`
|
|
51
|
+
* - `window.DIMMING_ON`
|
|
52
|
+
* - `window.DIMMING_OFF`
|
|
53
53
|
*/
|
|
54
54
|
function get_dim_mode(): Opaque<"constant">;
|
|
55
55
|
/**
|
|
@@ -70,16 +70,16 @@ declare global {
|
|
|
70
70
|
* this returns the full window size and zero insets.
|
|
71
71
|
*
|
|
72
72
|
* @returns safe area data
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
73
|
+
* `safe_area`
|
|
74
|
+
* table table containing these keys:
|
|
75
|
+
* - number `x`
|
|
76
|
+
* - number `y`
|
|
77
|
+
* - number `width`
|
|
78
|
+
* - number `height`
|
|
79
|
+
* - number `inset_left`
|
|
80
|
+
* - number `inset_top`
|
|
81
|
+
* - number `inset_right`
|
|
82
|
+
* - number `inset_bottom`
|
|
83
83
|
*/
|
|
84
84
|
function get_safe_area(): { safe_area: { x: number; y: number; width: number; height: number; inset_left: number; inset_top: number; inset_right: number; inset_bottom: number } };
|
|
85
85
|
/**
|
|
@@ -92,27 +92,27 @@ declare global {
|
|
|
92
92
|
* This function has no effect on platforms that does not support dimming.
|
|
93
93
|
*
|
|
94
94
|
* @param mode - The mode for screen dimming
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
* - `window.DIMMING_ON`
|
|
96
|
+
* - `window.DIMMING_OFF`
|
|
97
97
|
*/
|
|
98
98
|
function set_dim_mode(mode: Opaque<"constant">): void;
|
|
99
99
|
/**
|
|
100
100
|
* Sets a window event listener. Only one window event listener can be set at a time.
|
|
101
101
|
*
|
|
102
102
|
* @param callback - A callback which receives info about window events. Pass an empty function or `nil` if you no longer wish to receive callbacks.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
103
|
+
* `self`
|
|
104
|
+
* object The calling script
|
|
105
|
+
* `event`
|
|
106
|
+
* constant The type of event. Can be one of these:
|
|
107
|
+
* - `window.WINDOW_EVENT_FOCUS_LOST`
|
|
108
|
+
* - `window.WINDOW_EVENT_FOCUS_GAINED`
|
|
109
|
+
* - `window.WINDOW_EVENT_RESIZED`
|
|
110
|
+
* - `window.WINDOW_EVENT_ICONIFIED`
|
|
111
|
+
* - `window.WINDOW_EVENT_DEICONIFIED`
|
|
112
|
+
* `data`
|
|
113
|
+
* table The callback value `data` is a table which currently holds these values
|
|
114
|
+
* - number `width`: The width of a resize event. nil otherwise.
|
|
115
|
+
* - number `height`: The height of a resize event. nil otherwise.
|
|
116
116
|
* @example
|
|
117
117
|
* ```lua
|
|
118
118
|
* function window_callback(self, event, data)
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import "./generated/builtin-messages";
|
|
2
2
|
import "./src/msg-overloads";
|
|
3
|
+
import "./src/message-guard";
|
|
4
|
+
import "./src/message-dispatch";
|
|
3
5
|
import "./src/go-overloads";
|
|
4
6
|
import "./src/engine-globals";
|
|
5
7
|
import "./generated/b2d";
|
|
@@ -59,6 +61,8 @@ export {
|
|
|
59
61
|
type InputAction,
|
|
60
62
|
type InputTouch,
|
|
61
63
|
type RenderScriptHooks,
|
|
64
|
+
SCRIPT_HOOK_NAMES,
|
|
65
|
+
type ScriptHookName,
|
|
62
66
|
type ScriptHooks,
|
|
63
67
|
} from "./src/lifecycle";
|
|
64
68
|
export { type WrapOptions, wrapAsAmbientGlobal } from "./src/publish-dts";
|
package/package.json
CHANGED
package/scripts/regen.ts
CHANGED
|
@@ -209,6 +209,7 @@ export const RESTRICTED_NAMESPACES: Readonly<Record<string, string>> = {
|
|
|
209
209
|
const UNIVERSAL_EXTRA_IMPORTS: readonly string[] = [
|
|
210
210
|
"../builtin-messages",
|
|
211
211
|
"../../src/msg-overloads",
|
|
212
|
+
"../../src/message-guard",
|
|
212
213
|
"../../src/go-overloads",
|
|
213
214
|
];
|
|
214
215
|
|
package/src/doc-comment.ts
CHANGED
|
@@ -100,10 +100,18 @@ export function renderDocComment(parts: DocCommentParts): string[] {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
for (const param of params) {
|
|
103
|
-
|
|
103
|
+
const [first, ...rest] = param.doc.split("\n");
|
|
104
|
+
lines.push(` * @param ${param.name} - ${first}`);
|
|
105
|
+
for (const line of rest) {
|
|
106
|
+
lines.push(line === "" ? " *" : ` * ${line}`);
|
|
107
|
+
}
|
|
104
108
|
}
|
|
105
109
|
if (returns !== "") {
|
|
106
|
-
|
|
110
|
+
const [first, ...rest] = returns.split("\n");
|
|
111
|
+
lines.push(` * @returns ${first}`);
|
|
112
|
+
for (const line of rest) {
|
|
113
|
+
lines.push(line === "" ? " *" : ` * ${line}`);
|
|
114
|
+
}
|
|
107
115
|
}
|
|
108
116
|
if (example !== "") {
|
|
109
117
|
lines.push(" * @example");
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** @noSelfInFile */
|
|
2
|
+
import type { Hash, Url } from "./core-types";
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
// DU-style dispatcher built on `isMessage`'s receive-side narrowing
|
|
6
|
+
// (message-guard.d.ts): each handler key is a `BuiltinMessageId` and its
|
|
7
|
+
// `message` param narrows to that id's `BuiltinMessages` payload. It returns
|
|
8
|
+
// an `on_message` handler so it reads as `on_message: onMessage<Self>({ ... })`;
|
|
9
|
+
// `self` threads via the explicit type argument, mirroring `defineScript<Self>`.
|
|
10
|
+
// The transpiler lowers the call to a flat `message_id == hash("...")`
|
|
11
|
+
// if/elseif chain (message-dispatch-lowering.ts), keeping this package free of
|
|
12
|
+
// runtime Lua.
|
|
13
|
+
function onMessage<TSelf = Record<never, never>>(
|
|
14
|
+
handlers: Partial<{
|
|
15
|
+
[K in BuiltinMessageId]: (self: TSelf, message: BuiltinMessages[K], sender: Url) => void;
|
|
16
|
+
}>,
|
|
17
|
+
): (
|
|
18
|
+
self: TSelf,
|
|
19
|
+
message_id: Hash,
|
|
20
|
+
message: Record<string | number, unknown>,
|
|
21
|
+
sender: Url,
|
|
22
|
+
) => void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** @noSelfInFile */
|
|
2
|
+
import type { Hash } from "./core-types";
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
// Receive-side mirror of `msg.post`'s send-side narrowing (msg-overloads.d.ts).
|
|
6
|
+
// Defold delivers `message_id` as a pre-hashed `Hash`, so the literal a
|
|
7
|
+
// discriminated union would need is gone; re-introducing it here lets the
|
|
8
|
+
// untyped `message` record narrow to its `BuiltinMessages` payload. The
|
|
9
|
+
// transpiler lowers the call to `message_id == hash("...")`
|
|
10
|
+
// (message-guard-lowering.ts), keeping this package free of runtime Lua.
|
|
11
|
+
function isMessage<K extends BuiltinMessageId>(
|
|
12
|
+
message_id: Hash,
|
|
13
|
+
message: Record<string | number, unknown>,
|
|
14
|
+
expected: K,
|
|
15
|
+
): message is BuiltinMessages[K];
|
|
16
|
+
}
|