@defold-typescript/types 0.4.2 → 0.5.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.
@@ -3,33 +3,546 @@ import type { Opaque } from "../src/core-types";
3
3
 
4
4
  declare global {
5
5
  namespace sys {
6
+ /**
7
+ * network connected through other, non cellular, connection
8
+ */
6
9
  const NETWORK_CONNECTED: number & { readonly __brand: "sys.NETWORK_CONNECTED" };
10
+ /**
11
+ * network connected through mobile cellular
12
+ */
7
13
  const NETWORK_CONNECTED_CELLULAR: number & { readonly __brand: "sys.NETWORK_CONNECTED_CELLULAR" };
14
+ /**
15
+ * no network connection found
16
+ */
8
17
  const NETWORK_DISCONNECTED: number & { readonly __brand: "sys.NETWORK_DISCONNECTED" };
18
+ /**
19
+ * This function will raise a Lua error if an error occurs while deserializing the buffer.
20
+ *
21
+ * @param buffer - buffer to deserialize from
22
+ * @returns lua table with deserialized data
23
+ * @example
24
+ * ```lua
25
+ * Deserialize a lua table that was previously serialized:
26
+ * local buffer = sys.serialize(my_table)
27
+ * local table = sys.deserialize(buffer)
28
+ * ```
29
+ */
9
30
  function deserialize(buffer: string): Record<string | number, unknown>;
31
+ /**
32
+ * Check if a path exists
33
+ * Good for checking if a file exists before loading a large file
34
+ *
35
+ * @param path - path to check
36
+ * @returns `true` if the path exists, `false` otherwise
37
+ * @example
38
+ * ```lua
39
+ * Load data but return nil if path didn't exist
40
+ * if not sys.exists(path) then
41
+ * return nil
42
+ * end
43
+ * return sys.load(path) -- returns {} if it failed
44
+ * ```
45
+ */
10
46
  function exists(path: string): boolean;
47
+ /**
48
+ * Terminates the game application and reports the specified `code` to the OS.
49
+ *
50
+ * @param code - exit code to report to the OS, 0 means clean exit
51
+ * @example
52
+ * ```lua
53
+ * This examples demonstrates how to exit the application when some kind of quit messages is received (maybe from gui or similar):
54
+ * function on_message(self, message_id, message, sender)
55
+ * if message_id == hash("quit") then
56
+ * sys.exit(0)
57
+ * end
58
+ * end
59
+ * ```
60
+ */
11
61
  function exit(code: number): void;
62
+ /**
63
+ * Returns a table with application information for the requested app.
64
+ * On iOS, the `app_string` is an url scheme for the app that is queried. Your
65
+ * game needs to list the schemes that are queried in an `LSApplicationQueriesSchemes` array
66
+ * in a custom "Info.plist".
67
+ * On Android, the `app_string` is the package identifier for the app.
68
+ *
69
+ * @param app_string - platform specific string with application package or query, see above for details.
70
+ * @returns table with application information in the following fields:
71
+ `installed`
72
+ boolean `true` if the application is installed, `false` otherwise.
73
+ * @example
74
+ * ```lua
75
+ * Check if twitter is installed:
76
+ * sysinfo = sys.get_sys_info()
77
+ * twitter = {}
78
+ *
79
+ * if sysinfo.system_name == "Android" then
80
+ * twitter = sys.get_application_info("com.twitter.android")
81
+ * elseif sysinfo.system_name == "iPhone OS" then
82
+ * twitter = sys.get_application_info("twitter:")
83
+ * end
84
+ *
85
+ * if twitter.installed then
86
+ * -- twitter is installed!
87
+ * end
88
+ *
89
+ * Info.plist for the iOS app needs to list the schemes that are queried:
90
+ * ...
91
+ * <key>LSApplicationQueriesSchemes</key>
92
+ * <array>
93
+ * <string>twitter</string>
94
+ * </array>
95
+ * ...
96
+ * ```
97
+ */
12
98
  function get_application_info(app_string: string): { installed: boolean };
99
+ /**
100
+ * The path from which the application is run.
101
+ * This function will raise a Lua error if unable to get the application support path.
102
+ *
103
+ * @returns path to application executable
104
+ * @example
105
+ * ```lua
106
+ * Find a path where we can store data (the example path is on the macOS platform):
107
+ * -- macOS: /Applications/my_game.app
108
+ * local application_path = sys.get_application_path()
109
+ * print(application_path) --> /Applications/my_game.app
110
+ *
111
+ * -- Windows: C:\Program Files\my_game\my_game.exe
112
+ * print(application_path) --> C:\Program Files\my_game
113
+ *
114
+ * -- Linux: /home/foobar/my_game/my_game
115
+ * print(application_path) --> /home/foobar/my_game
116
+ *
117
+ * -- Android package name: com.foobar.my_game
118
+ * print(application_path) --> /data/user/0/com.foobar.my_game
119
+ *
120
+ * -- iOS: my_game.app
121
+ * print(application_path) --> /var/containers/Bundle/Applications/123456AB-78CD-90DE-12345678ABCD/my_game.app
122
+ *
123
+ * -- HTML5: http://www.foobar.com/my_game/
124
+ * print(application_path) --> http://www.foobar.com/my_game
125
+ * ```
126
+ */
13
127
  function get_application_path(): string;
128
+ /**
129
+ * Get boolean config value from the game.project configuration file with optional default value
130
+ *
131
+ * @param key - key to get value for. The syntax is SECTION.KEY
132
+ * @param default_value - (optional) default value to return if the value does not exist
133
+ * @returns config value as a boolean. default_value if the config key does not exist. false if no default value was supplied.
134
+ * @example
135
+ * ```lua
136
+ * Get user config value
137
+ * local vsync = sys.get_config_boolean("display.vsync", false)
138
+ * ```
139
+ */
14
140
  function get_config_boolean(key: string, default_value?: boolean): boolean;
141
+ /**
142
+ * Get integer config value from the game.project configuration file with optional default value
143
+ *
144
+ * @param key - key to get value for. The syntax is SECTION.KEY
145
+ * @param default_value - (optional) default value to return if the value does not exist
146
+ * @returns config value as an integer. default_value if the config key does not exist. 0 if no default value was supplied.
147
+ * @example
148
+ * ```lua
149
+ * Get user config value
150
+ * local speed = sys.get_config_int("my_game.speed", 20) -- with default value
151
+ *
152
+ * local testmode = sys.get_config_int("my_game.testmode") -- without default value
153
+ * if testmode ~= nil then
154
+ * -- do stuff
155
+ * end
156
+ * ```
157
+ */
15
158
  function get_config_int(key: string, default_value?: number): number;
159
+ /**
160
+ * Get number config value from the game.project configuration file with optional default value
161
+ *
162
+ * @param key - key to get value for. The syntax is SECTION.KEY
163
+ * @param default_value - (optional) default value to return if the value does not exist
164
+ * @returns config value as an number. default_value if the config key does not exist. 0 if no default value was supplied.
165
+ * @example
166
+ * ```lua
167
+ * Get user config value
168
+ * local speed = sys.get_config_number("my_game.speed", 20.0)
169
+ * ```
170
+ */
16
171
  function get_config_number(key: string, default_value?: number): number;
172
+ /**
173
+ * Get string config value from the game.project configuration file with optional default value
174
+ *
175
+ * @param key - key to get value for. The syntax is SECTION.KEY
176
+ * @param default_value - (optional) default value to return if the value does not exist
177
+ * @returns config value as a string. default_value if the config key does not exist. nil if no default value was supplied.
178
+ * @example
179
+ * ```lua
180
+ * Get user config value
181
+ * local text = sys.get_config_string("my_game.text", "default text"))
182
+ *
183
+ * Start the engine with a bootstrap config override and add a custom config value
184
+ * $ dmengine --config=bootstrap.main_collection=/mytest.collectionc --config=mygame.testmode=1
185
+ *
186
+ * Read the custom config value from the command line
187
+ * local testmode = sys.get_config_int("mygame.testmode")
188
+ * ```
189
+ */
17
190
  function get_config_string(key: string, default_value?: string): string;
191
+ /**
192
+ * Returns the current network connectivity status
193
+ * on mobile platforms.
194
+ * On desktop, this function always return `sys.NETWORK_CONNECTED`.
195
+ *
196
+ * @returns network connectivity status:
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
+ * @example
201
+ * ```lua
202
+ * Check if we are connected through a cellular connection
203
+ * if (sys.NETWORK_CONNECTED_CELLULAR == sys.get_connectivity()) then
204
+ * print("Connected via cellular, avoid downloading big files!")
205
+ * end
206
+ * ```
207
+ */
18
208
  function get_connectivity(): Opaque<"constant">;
209
+ /**
210
+ * Returns a table with engine information.
211
+ *
212
+ * @returns table with engine information in the following fields:
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
+ * @example
220
+ * ```lua
221
+ * How to retrieve engine information:
222
+ * -- Update version text label so our testers know what version we're running
223
+ * local engine_info = sys.get_engine_info()
224
+ * local version_str = "Defold " .. engine_info.version .. "\n" .. engine_info.version_sha1
225
+ * gui.set_text(gui.get_node("version"), version_str)
226
+ * ```
227
+ */
19
228
  function get_engine_info(): { version: string; version_sha1: string; is_debug: boolean };
229
+ /**
230
+ * Create a path to the host device for unit testing
231
+ * Useful for saving logs etc during development
232
+ *
233
+ * @param filename - file to read from
234
+ * @returns the path prefixed with the proper host mount
235
+ * @example
236
+ * ```lua
237
+ * Save data on the host
238
+ * local host_path = sys.get_host_path("logs/test.txt")
239
+ * sys.save(host_path, mytable)
240
+ *
241
+ * Load data from the host
242
+ * local host_path = sys.get_host_path("logs/test.txt")
243
+ * local table = sys.load(host_path)
244
+ * ```
245
+ */
20
246
  function get_host_path(filename: string): string;
247
+ /**
248
+ * Returns an array of tables with information on network interfaces.
249
+ *
250
+ * @returns an array of tables. Each table entry contain the following fields:
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
+ * @example
262
+ * ```lua
263
+ * How to get the IP address of interface "en0":
264
+ * ifaddrs = sys.get_ifaddrs()
265
+ * for _,interface in ipairs(ifaddrs) do
266
+ * if interface.name == "en0" then
267
+ * local ip = interface.address
268
+ * end
269
+ * end
270
+ * ```
271
+ */
21
272
  function get_ifaddrs(): { name: string; address: string; mac: string; up: boolean; running: boolean }[];
273
+ /**
274
+ * The save-file path is operating system specific and is typically located under the user's home directory.
275
+ * This function will raise a Lua error if unable to get the save file path.
276
+ *
277
+ * @param application_id - user defined id of the application, which helps define the location of the save-file
278
+ * @param file_name - file-name to get path for
279
+ * @returns path to save-file
280
+ * @example
281
+ * ```lua
282
+ * Find a path where we can store data:
283
+ * local my_file_path = sys.get_save_file("my_game", "my_file")
284
+ * -- macOS: /Users/foobar/Library/Application Support/my_game/my_file
285
+ * print(my_file_path) --> /Users/foobar/Library/Application Support/my_game/my_file
286
+ *
287
+ * -- Windows: C:\Users\foobar\AppData\Roaming\my_game\my_file
288
+ * print(my_file_path) --> C:\Users\foobar\AppData\Roaming\my_game\my_file
289
+ *
290
+ * -- Linux: $XDG_DATA_HOME/my_game/my_file or /home/foobar/.my_game/my_file
291
+ * -- Linux: Defaults to /home/foobar/.local/share/my_game/my_file if neither exist.
292
+ * print(my_file_path) --> /home/foobar/.local/share/my_game/my_file
293
+ *
294
+ * -- Android package name: com.foobar.packagename
295
+ * print(my_file_path) --> /data/data/0/com.foobar.packagename/files/my_file
296
+ *
297
+ * -- iOS: my_game.app
298
+ * print(my_file_path) --> /var/mobile/Containers/Data/Application/123456AB-78CD-90DE-12345678ABCD/my_game/my_file
299
+ *
300
+ * -- HTML5 path inside the IndexedDB: /data/.my_game/my_file or /.my_game/my_file
301
+ * print(my_file_path) --> /data/.my_game/my_file
302
+ * ```
303
+ */
22
304
  function get_save_file(application_id: string, file_name: string): string;
305
+ /**
306
+ * Returns a table with system information.
307
+ *
308
+ * @param options - optional options table
309
+ - ignore_secure boolean this flag ignores values might be secured by OS e.g. `device_ident`
310
+ * @returns table with system information in the following fields:
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
+ * @example
334
+ * ```lua
335
+ * How to get system information:
336
+ * local info = sys.get_sys_info()
337
+ * if info.system_name == "HTML5" then
338
+ * -- We are running in a browser.
339
+ * end
340
+ * ```
341
+ */
23
342
  function get_sys_info(options?: { ignore_secure?: boolean }): { device_model: string; manufacturer: string; system_name: string; system_version: string; api_version: string; language: string; device_language: string; territory: string; gmt_offset: number; device_ident: string; user_agent: string };
343
+ /**
344
+ * If the file exists, it must have been created by `sys.save` to be loaded.
345
+ * This function will raise a Lua error if an error occurs while loading the file.
346
+ *
347
+ * @param filename - file to read from
348
+ * @returns lua table, which is empty if the file could not be found
349
+ * @example
350
+ * ```lua
351
+ * Load data that was previously saved, e.g. an earlier game session:
352
+ * local my_file_path = sys.get_save_file("my_game", "my_file")
353
+ * local my_table = sys.load(my_file_path)
354
+ * if not next(my_table) then
355
+ * -- empty table
356
+ * end
357
+ * ```
358
+ */
24
359
  function load(filename: string): Record<string | number, unknown>;
360
+ /**
361
+ * Loads a custom resource. Specify the full filename of the resource that you want
362
+ * to load. When loaded, the file data is returned as a string.
363
+ * If loading fails, the function returns `nil` plus the error message.
364
+ * In order for the engine to include custom resources in the build process, you need
365
+ * to specify them in the "custom_resources" key in your "game.project" settings file.
366
+ * You can specify single resource files or directories. If a directory is included
367
+ * in the resource list, all files and directories in that directory is recursively
368
+ * included:
369
+ * For example "main/data/,assets/level_data.json".
370
+ *
371
+ * @param filename - resource to load, full path
372
+ * @example
373
+ * ```lua
374
+ * -- Load level data into a string
375
+ * local data, error = sys.load_resource("/assets/level_data.json")
376
+ * -- Decode json string to a Lua table
377
+ * if data then
378
+ * local data_table = json.decode(data)
379
+ * pprint(data_table)
380
+ * else
381
+ * print(error)
382
+ * end
383
+ * ```
384
+ */
25
385
  function load_resource(filename: string): LuaMultiReturn<[string | unknown, string | unknown]>;
386
+ /**
387
+ * Open URL in default application, typically a browser
388
+ *
389
+ * @param url - url to open
390
+ * @param attributes - table with attributes
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
+ * @returns a boolean indicating if the url could be opened or not
399
+ * @example
400
+ * ```lua
401
+ * Open an URL:
402
+ * local success = sys.open_url("http://www.defold.com", {target = "_blank"})
403
+ * if not success then
404
+ * -- could not open the url...
405
+ * end
406
+ * ```
407
+ */
26
408
  function open_url(url: string, attributes?: { target?: string }): boolean;
409
+ /**
410
+ * Reboots the game engine with a specified set of arguments.
411
+ * Arguments will be translated into command line arguments. Calling reboot
412
+ * function is equivalent to starting the engine with the same arguments.
413
+ * On startup the engine reads configuration from "game.project" in the
414
+ * project root.
415
+ *
416
+ * @param arg1 - argument 1
417
+ * @param arg2 - argument 2
418
+ * @param arg3 - argument 3
419
+ * @param arg4 - argument 4
420
+ * @param arg5 - argument 5
421
+ * @param arg6 - argument 6
422
+ * @example
423
+ * ```lua
424
+ * How to reboot engine with a specific bootstrap collection.
425
+ * local arg1 = '--config=bootstrap.main_collection=/my.collectionc'
426
+ * local arg2 = 'build/game.projectc'
427
+ * sys.reboot(arg1, arg2)
428
+ * ```
429
+ */
27
430
  function reboot(arg1?: string, arg2?: string, arg3?: string, arg4?: string, arg5?: string, arg6?: string): void;
431
+ /**
432
+ * The table can later be loaded by `sys.load`.
433
+ * Use `sys.get_save_file` to obtain a valid location for the file.
434
+ * Internally, this function uses a workspace buffer sized output file sized 512kb.
435
+ * This size reflects the output file size which must not exceed this limit.
436
+ * Additionally, the total number of rows that any one table may contain is limited to 65536
437
+ * (i.e. a 16 bit range). When tables are used to represent arrays, the values of
438
+ * keys are permitted to fall within a 32 bit range, supporting sparse arrays, however
439
+ * the limit on the total number of rows remains in effect.
440
+ * This function will raise a Lua error if an error occurs while saving the table.
441
+ *
442
+ * @param filename - file to write to
443
+ * @param table - lua table to save
444
+ * @example
445
+ * ```lua
446
+ * Save data:
447
+ * local my_table = {}
448
+ * table.insert(my_table, "my_value")
449
+ * local my_file_path = sys.get_save_file("my_game", "my_file")
450
+ * sys.save(my_file_path, my_table)
451
+ * ```
452
+ */
28
453
  function save(filename: string, table: Record<string | number, unknown>): void;
454
+ /**
455
+ * The buffer can later deserialized by `sys.deserialize`.
456
+ * This function has all the same limitations as `sys.save`.
457
+ * This function will raise a Lua error if an error occurs while serializing the table.
458
+ *
459
+ * @param table - lua table to serialize
460
+ * @returns serialized data buffer
461
+ * @example
462
+ * ```lua
463
+ * Serialize table:
464
+ * local my_table = {}
465
+ * table.insert(my_table, "my_value")
466
+ * local buffer = sys.serialize(my_table)
467
+ * ```
468
+ */
29
469
  function serialize(table: Record<string | number, unknown>): string;
470
+ /**
471
+ * Sets the host that is used to check for network connectivity against.
472
+ *
473
+ * @param host - hostname to check against
474
+ * @example
475
+ * ```lua
476
+ * sys.set_connectivity_host("www.google.com")
477
+ * ```
478
+ */
30
479
  function set_connectivity_host(host: string): void;
480
+ /**
481
+ * Set the Lua error handler function.
482
+ * The error handler is a function which is called whenever a lua runtime error occurs.
483
+ *
484
+ * @param error_handler - the function to be called on error
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
+ * @example
492
+ * ```lua
493
+ * Install error handler that just prints the errors
494
+ * local function my_error_handler(source, message, traceback)
495
+ * print(source) --> lua
496
+ * print(message) --> main/my.script:10: attempt to perform arithmetic on a string value
497
+ * print(traceback) --> stack traceback:
498
+ * --> main/test.script:10: in function 'boom'
499
+ * --> main/test.script:15: in function <main/my.script:13>
500
+ * end
501
+ *
502
+ * local function boom()
503
+ * return 10 + "string"
504
+ * end
505
+ *
506
+ * function init(self)
507
+ * sys.set_error_handler(my_error_handler)
508
+ * boom()
509
+ * end
510
+ * ```
511
+ */
31
512
  function set_error_handler(error_handler: (source: unknown, message: unknown, traceback: unknown) => void): void;
513
+ /**
514
+ * Set game update-frequency (frame cap). This option is equivalent to `display.update_frequency` in
515
+ * the "game.project" settings but set in run-time. If `Vsync` checked in "game.project", the rate will
516
+ * be clamped to a swap interval that matches any detected main monitor refresh rate. If `Vsync` is
517
+ * unchecked the engine will try to respect the rate in software using timers. There is no
518
+ * guarantee that the frame cap will be achieved depending on platform specifics and hardware settings.
519
+ *
520
+ * @param frequency - target frequency. 60 for 60 fps
521
+ * @example
522
+ * ```lua
523
+ * Setting the update frequency to 60 frames per second
524
+ * sys.set_update_frequency(60)
525
+ * ```
526
+ */
32
527
  function set_update_frequency(frequency: number): void;
528
+ /**
529
+ * Set the vsync swap interval. The interval with which to swap the front and back buffers
530
+ * in sync with vertical blanks (v-blank), the hardware event where the screen image is updated
531
+ * with data from the front buffer. A value of 1 swaps the buffers at every v-blank, a value of
532
+ * 2 swaps the buffers every other v-blank and so on. A value of 0 disables waiting for v-blank
533
+ * before swapping the buffers. Default value is 1.
534
+ * When setting the swap interval to 0 and having `vsync` disabled in
535
+ * "game.project", the engine will try to respect the set frame cap value from
536
+ * "game.project" in software instead.
537
+ * This setting may be overridden by driver settings.
538
+ *
539
+ * @param swap_interval - target swap interval.
540
+ * @example
541
+ * ```lua
542
+ * Setting the swap intervall to swap every v-blank
543
+ * sys.set_vsync_swap_interval(1)
544
+ * ```
545
+ */
33
546
  function set_vsync_swap_interval(swap_interval: number): void;
34
547
  }
35
548
  }