@defold-typescript/types 0.4.3 → 0.5.1

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 (42) hide show
  1. package/generated/b2d.d.ts +11 -0
  2. package/generated/buffer.d.ts +142 -0
  3. package/generated/collectionfactory.d.ts +118 -0
  4. package/generated/collectionproxy.d.ts +52 -0
  5. package/generated/crash.d.ts +109 -0
  6. package/generated/factory.d.ts +94 -0
  7. package/generated/go.d.ts +880 -0
  8. package/generated/graphics.d.ts +108 -0
  9. package/generated/gui.d.ts +1892 -0
  10. package/generated/http.d.ts +50 -0
  11. package/generated/iac.d.ts +7 -0
  12. package/generated/iap.d.ts +41 -0
  13. package/generated/image.d.ts +95 -0
  14. package/generated/json.d.ts +59 -0
  15. package/generated/label.d.ts +64 -0
  16. package/generated/liveupdate.d.ts +96 -0
  17. package/generated/model.d.ts +156 -0
  18. package/generated/msg.d.ts +56 -0
  19. package/generated/particlefx.d.ts +122 -0
  20. package/generated/physics.d.ts +451 -0
  21. package/generated/profiler.d.ts +188 -0
  22. package/generated/push.d.ts +48 -0
  23. package/generated/render.d.ts +944 -0
  24. package/generated/resource.d.ts +1227 -0
  25. package/generated/socket.d.ts +125 -0
  26. package/generated/sound.d.ts +246 -0
  27. package/generated/sprite.d.ts +111 -0
  28. package/generated/sys.d.ts +513 -0
  29. package/generated/tilemap.d.ts +151 -0
  30. package/generated/timer.d.ts +93 -0
  31. package/generated/vmath.d.ts +914 -0
  32. package/generated/webview.d.ts +50 -0
  33. package/generated/window.d.ts +141 -0
  34. package/generated/zlib.d.ts +28 -0
  35. package/index.d.ts +1 -0
  36. package/package.json +1 -1
  37. package/src/api-doc.ts +10 -1
  38. package/src/doc-comment.ts +119 -0
  39. package/src/emit-dts.ts +63 -2
  40. package/src/engine-globals.d.ts +12 -0
  41. package/src/index.ts +1 -0
  42. package/src/lifecycle.ts +45 -16
@@ -1,6 +1,56 @@
1
1
  /** @noSelfInFile */
2
2
  declare global {
3
3
  namespace http {
4
+ /**
5
+ * Perform a HTTP/HTTPS request.
6
+ * If no timeout value is passed, the configuration value "network.http_timeout" is used. If that is not set, the timeout value is `0` (which blocks indefinitely).
7
+ *
8
+ * @param url - target url
9
+ * @param method - HTTP/HTTPS method, e.g. "GET", "PUT", "POST" etc.
10
+ * @param callback - response callback function
11
+ `self`
12
+ object The script instance
13
+ `id`
14
+ hash Internal message identifier. Do not use!
15
+ `response`
16
+ table The response data. Contains the fields:
17
+ - number `status`: the status of the response
18
+ - string `response`: the response data (if not saved on disc)
19
+ - table `headers`: all the returned headers (if status is 200 or 206)
20
+ - string `path`: the stored path (if saved to disc)
21
+ - string `error`: if any unforeseen errors occurred (e.g. file I/O)
22
+ - number `bytes_received`: the amount of bytes received/sent for a request, only if option `report_progress` is true
23
+ - number `bytes_total`: the total amount of bytes for a request, only if option `report_progress` is true
24
+ - number `range_start`: the start offset into the requested file
25
+ - number `range_end`: the end offset into the requested file (inclusive)
26
+ - number `document_size`: the full size of the requested file
27
+ * @param headers - optional table with custom headers
28
+ * @param post_data - optional data to send
29
+ * @param options - optional table with request parameters. Supported entries:
30
+ - number `timeout`: timeout in seconds
31
+ - string `path`: path on disc where to download the file. Only overwrites the path if status is 200. Path should be absolute
32
+ - boolean `ignore_cache`: don't return cached data if we get a 304. Not available in HTML5 build
33
+ - boolean `chunked_transfer`: use chunked transfer encoding for https requests larger than 16kb. Defaults to true. Not available in HTML5 build
34
+ - boolean `report_progress`: when it is true, the amount of bytes sent and/or received for a request will be passed into the callback function
35
+ * @example
36
+ * ```lua
37
+ * Basic HTTP-GET request. The callback receives a table with the response
38
+ * in the fields status, the response (the data) and headers (a table).
39
+ * local function http_result(self, _, response)
40
+ * if response.bytes_total ~= nil then
41
+ * update_my_progress_bar(self, response.bytes_received / response.bytes_total)
42
+ * else
43
+ * print(response.status)
44
+ * print(response.response)
45
+ * pprint(response.headers)
46
+ * end
47
+ * end
48
+ *
49
+ * function init(self)
50
+ * http.request("http://www.google.com", "GET", http_result, nil, nil, { report_progress = true })
51
+ * end
52
+ * ```
53
+ */
4
54
  function request(url: string, method: string, callback: (self: unknown, id: unknown, response: unknown) => void, headers?: Record<string | number, unknown>, post_data?: string, options?: { timeout?: number; path?: string; ignore_cache?: boolean; chunked_transfer?: boolean; report_progress?: boolean }): void;
5
55
  }
6
56
  }
@@ -1,6 +1,13 @@
1
1
  /** @noSelfInFile */
2
2
  declare global {
3
3
  namespace iac {
4
+ /**
5
+ * Sets the listener function for inter-app communication events.
6
+ *
7
+ * @param payload - The iac payload.
8
+ * @param type - The type of iac, an iac.TYPE_ enumeration. It can be one of the predefined constants below
9
+ - `iac.TYPE_INVOCATION`
10
+ */
4
11
  function set_listener(payload: Record<string | number, unknown>, type: number): void;
5
12
  }
6
13
  }
@@ -3,12 +3,53 @@ import type { Opaque } from "../src/core-types";
3
3
 
4
4
  declare global {
5
5
  namespace iap {
6
+ /**
7
+ * Acknowledge a transaction. [icon:attention] Calling iap.acknowledge is required on a successful transaction on Google Play unless iap.finish is called. The transaction.state field must equal iap.TRANS_STATE_PURCHASED.
8
+ *
9
+ * @param transaction - transaction table parameter as supplied in listener callback
10
+ */
6
11
  function acknowledge(transaction: Record<string | number, unknown>): void;
12
+ /**
13
+ * Purchase a product.
14
+ *
15
+ * @param id - product to buy
16
+ * @param options - optional parameters as properties. The following parameters can be set
17
+ */
7
18
  function buy(id: string, options: Record<string | number, unknown>): void;
19
+ /**
20
+ * Explicitly finish a product transaction. [icon:attention] Calling iap.finish is required on a successful transaction if `auto_finish_transactions` is disabled in project settings. Calling this function with `auto_finish_transactions` set will be ignored and a warning is printed. The `transaction.state` field must equal `iap.TRANS_STATE_PURCHASED`.
21
+ *
22
+ * @param transaction - transaction table parameter as supplied in listener callback
23
+ */
8
24
  function finish(transaction: Record<string | number, unknown>): void;
25
+ /**
26
+ * Get current iap provider
27
+ *
28
+ * @returns one of the following values
29
+ - `iap.PROVIDER_ID_GOOGLE`
30
+ - `iap.PROVIDER_ID_AMAZON`
31
+ - `iap.PROVIDER_ID_APPLE`
32
+ - `iap.PROVIDER_ID_FACEBOOK`
33
+ */
9
34
  function get_provider_id(): Opaque<"constant">;
35
+ /**
36
+ * Get a list of all avaliable iap products.
37
+ *
38
+ * @param ids - table (array) of identifiers to get products from
39
+ * @param callback - result callback taking the following parameters
40
+ */
10
41
  function list(ids: string[], callback: (...args: unknown[]) => unknown): void;
42
+ /**
43
+ * Restore previously purchased products.
44
+ *
45
+ * @returns value is `true` if current store supports handling restored transactions, otherwise `false`.
46
+ */
11
47
  function restore(): boolean;
48
+ /**
49
+ * Set the callback function to receive purchase transaction events.
50
+ *
51
+ * @param listener - listener callback function. Pass an empty function if you no longer wish to receive callbacks.
52
+ */
12
53
  function set_listener(listener: (...args: unknown[]) => unknown): void;
13
54
  }
14
55
  }
@@ -3,12 +3,107 @@ import type { Opaque } from "../src/core-types";
3
3
 
4
4
  declare global {
5
5
  namespace image {
6
+ /**
7
+ * luminance image type
8
+ */
6
9
  const TYPE_LUMINANCE: number & { readonly __brand: "image.TYPE_LUMINANCE" };
10
+ /**
11
+ * luminance image type
12
+ */
7
13
  const TYPE_LUMINANCE_ALPHA: number & { readonly __brand: "image.TYPE_LUMINANCE_ALPHA" };
14
+ /**
15
+ * RGB image type
16
+ */
8
17
  const TYPE_RGB: number & { readonly __brand: "image.TYPE_RGB" };
18
+ /**
19
+ * RGBA image type
20
+ */
9
21
  const TYPE_RGBA: number & { readonly __brand: "image.TYPE_RGBA" };
22
+ /**
23
+ * get the header of an .astc buffer
24
+ *
25
+ * @param buffer - .astc file data buffer
26
+ * @returns header or `nil` if buffer is not a valid .astc. The header has these fields:
27
+ - number `width`: image width
28
+ - number `height`: image height
29
+ - number `depth`: image depth
30
+ - number `block_size_x`: block size x
31
+ - number `block_size_y`: block size y
32
+ - number `block_size_z`: block size z
33
+ * @example
34
+ * ```lua
35
+ * How to get the block size and dimensions from a .astc file
36
+ * local s = sys.load_resource("/assets/cat.astc")
37
+ * local header = image.get_astc_header(s)
38
+ * pprint(s)
39
+ * ```
40
+ */
10
41
  function get_astc_header(buffer: string): { width: number; height: number; depth: number; block_size_x: number; block_size_y: number; block_size_z: number } | unknown;
42
+ /**
43
+ * Load image (PNG or JPEG) from buffer.
44
+ *
45
+ * @param buffer - image data buffer
46
+ * @param options - An optional table containing parameters for loading the image. Supported entries:
47
+ `premultiply_alpha`
48
+ boolean True if alpha should be premultiplied into the color components. Defaults to `false`.
49
+ `flip_vertically`
50
+ boolean True if the image contents should be flipped vertically. Defaults to `false`.
51
+ * @returns object or `nil` if loading fails. The object is a table with the following fields:
52
+ - number `width`: image width
53
+ - number `height`: image height
54
+ - constant `type`: image type
55
+ - `image.TYPE_RGB`
56
+ - `image.TYPE_RGBA`
57
+ - `image.TYPE_LUMINANCE`
58
+ - `image.TYPE_LUMINANCE_ALPHA`
59
+ - string `buffer`: the raw image data
60
+ * @example
61
+ * ```lua
62
+ * How to load an image from an URL and create a GUI texture from it:
63
+ * local imgurl = "http://www.site.com/image.png"
64
+ * http.request(imgurl, "GET", function(self, id, response)
65
+ * local img = image.load(response.response)
66
+ * local tx = gui.new_texture("image_node", img.width, img.height, img.type, img.buffer)
67
+ * end)
68
+ * ```
69
+ */
11
70
  function load(buffer: string, options?: { premultiply_alpha?: boolean; flip_vertically?: boolean }): { width: number; height: number; type: Opaque<"constant">; buffer: string } | unknown;
71
+ /**
72
+ * Load image (PNG or JPEG) from a string buffer.
73
+ *
74
+ * @param buffer - image data buffer
75
+ * @param options - An optional table containing parameters for loading the image. Supported entries:
76
+ `premultiply_alpha`
77
+ boolean True if alpha should be premultiplied into the color components. Defaults to `false`.
78
+ `flip_vertically`
79
+ boolean True if the image contents should be flipped vertically. Defaults to `false`.
80
+ * @returns object or `nil` if loading fails. The object is a table with the following fields:
81
+ - number `width`: image width
82
+ - number `height`: image height
83
+ - constant `type`: image type
84
+ - `image.TYPE_RGB`
85
+ - `image.TYPE_RGBA`
86
+ - `image.TYPE_LUMINANCE`
87
+ - `image.TYPE_LUMINANCE_ALPHA`
88
+ - buffer `buffer`: the script buffer that holds the decompressed image data. See buffer.create how to use the buffer.
89
+ * @example
90
+ * ```lua
91
+ * Load an image from an URL as a buffer and create a texture resource from it:
92
+ * local imgurl = "http://www.site.com/image.png"
93
+ * http.request(imgurl, "GET", function(self, id, response)
94
+ * local img = image.load_buffer(response.response, { flip_vertically = true })
95
+ * local tparams = {
96
+ * width = img.width,
97
+ * height = img.height,
98
+ * type = graphics.TEXTURE_TYPE_2D,
99
+ * format = graphics.TEXTURE_FORMAT_RGBA }
100
+ *
101
+ * local my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams, img.buffer)
102
+ * -- Apply the texture to a model
103
+ * go.set("/go1#model", "texture0", my_texture_id)
104
+ * end)
105
+ * ```
106
+ */
12
107
  function load_buffer(buffer: string, options?: { premultiply_alpha?: boolean; flip_vertically?: boolean }): { width: number; height: number; type: Opaque<"constant">; buffer: Opaque<"buffer"> } | unknown;
13
108
  }
14
109
  }
@@ -1,8 +1,67 @@
1
1
  /** @noSelfInFile */
2
2
  declare global {
3
3
  namespace json {
4
+ /**
5
+ * Represents the null primitive from a json file
6
+ */
4
7
  const _null: unknown;
8
+ /**
9
+ * Decode a string of JSON data into a Lua table.
10
+ * A Lua error is raised for syntax errors.
11
+ *
12
+ * @param json - json data
13
+ * @param options - table with decode options
14
+ - boolean `decode_null_as_userdata`: wether to decode a JSON null value as json.null or nil (default is nil)
15
+ * @returns decoded json
16
+ * @example
17
+ * ```lua
18
+ * Converting a string containing JSON data into a Lua table:
19
+ * function init(self)
20
+ * local jsonstring = '{"persons":[{"name":"John Doe"},{"name":"Darth Vader"}]}'
21
+ * local data = json.decode(jsonstring)
22
+ * pprint(data)
23
+ * end
24
+ *
25
+ * Results in the following printout:
26
+ * {
27
+ * persons = {
28
+ * 1 = {
29
+ * name = John Doe,
30
+ * }
31
+ * 2 = {
32
+ * name = Darth Vader,
33
+ * }
34
+ * }
35
+ * }
36
+ * ```
37
+ */
5
38
  export function decode(json: string, options?: { decode_null_as_userdata?: boolean }): Record<string | number, unknown>;
39
+ /**
40
+ * Encode a lua table to a JSON string.
41
+ * A Lua error is raised for syntax errors.
42
+ *
43
+ * @param tbl - lua table to encode
44
+ * @param options - table with encode options
45
+ - string `encode_empty_table_as_object`: wether to encode an empty table as an JSON object or array (default is object)
46
+ * @returns encoded json
47
+ * @example
48
+ * ```lua
49
+ * Convert a lua table to a JSON string:
50
+ * function init(self)
51
+ * local tbl = {
52
+ * persons = {
53
+ * { name = "John Doe"},
54
+ * { name = "Darth Vader"}
55
+ * }
56
+ * }
57
+ * local jsonstring = json.encode(tbl)
58
+ * pprint(jsonstring)
59
+ * end
60
+ *
61
+ * Results in the following printout:
62
+ * {"persons":[{"name":"John Doe"},{"name":"Darth Vader"}]}
63
+ * ```
64
+ */
6
65
  export function encode(tbl: Record<string | number, unknown>, options?: { encode_empty_table_as_object?: string }): string;
7
66
  export { _null as null };
8
67
  }
@@ -3,18 +3,82 @@ import type { Hash, Url, Vector3, Vector4 } from "../src/core-types";
3
3
 
4
4
  declare global {
5
5
  namespace label {
6
+ /**
7
+ * Gets the text from a label component
8
+ *
9
+ * @param url - the label to get the text from
10
+ * @returns the label text
11
+ * @example
12
+ * ```lua
13
+ * function init(self)
14
+ * local text = label.get_text("#label")
15
+ * print(text)
16
+ * end
17
+ * ```
18
+ */
6
19
  function get_text(url: string | Hash | Url): string;
20
+ /**
21
+ * Sets the text of a label component
22
+ * This method uses the message passing that means the value will be set after `dispatch messages` step.
23
+ * More information is available in the Application Lifecycle manual.
24
+ *
25
+ * @param url - the label that should have a constant set
26
+ * @param text - the text
27
+ * @example
28
+ * ```lua
29
+ * function init(self)
30
+ * label.set_text("#label", "Hello World!")
31
+ * end
32
+ * ```
33
+ */
7
34
  function set_text(url: string | Hash | Url, text: string | number): void;
8
35
  interface properties {
36
+ /**
37
+ * The color of the label. The type of the property is vector4.
38
+ */
9
39
  color: Vector4;
40
+ /**
41
+ * The font used when rendering the label. The type of the property is hash.
42
+ */
10
43
  font: Hash;
44
+ /**
45
+ * The leading of the label. This value is used to scale the line spacing of text.
46
+ * The type of the property is number.
47
+ */
11
48
  leading: number;
49
+ /**
50
+ * The line break of the label.
51
+ * This value is used to adjust the vertical spacing of characters in the text.
52
+ * The type of the property is boolean.
53
+ */
12
54
  line_break: boolean;
55
+ /**
56
+ * The material used when rendering the label. The type of the property is hash.
57
+ */
13
58
  material: Hash;
59
+ /**
60
+ * The outline color of the label. The type of the property is vector4.
61
+ */
14
62
  outline: Vector4;
63
+ /**
64
+ * The scale of the label. The type of the property is number (uniform)
65
+ * or vector3 (non uniform).
66
+ */
15
67
  scale: number | Vector3;
68
+ /**
69
+ * The shadow color of the label. The type of the property is vector4.
70
+ */
16
71
  shadow: Vector4;
72
+ /**
73
+ * Returns the size of the label. The size will constrain the text if line break is enabled.
74
+ * The type of the property is vector3.
75
+ */
17
76
  size: Vector3;
77
+ /**
78
+ * The tracking of the label.
79
+ * This value is used to adjust the vertical spacing of characters in the text.
80
+ * The type of the property is number.
81
+ */
18
82
  tracking: number;
19
83
  }
20
84
  }
@@ -1,21 +1,117 @@
1
1
  /** @noSelfInFile */
2
2
  declare global {
3
3
  namespace liveupdate {
4
+ /**
5
+ * Mismatch between between expected bundled resources and actual bundled resources. The manifest expects a resource to be in the bundle, but it was not found in the bundle. This is typically the case when a non-excluded resource was modified between publishing the bundle and publishing the manifest.
6
+ */
4
7
  const LIVEUPDATE_BUNDLED_RESOURCE_MISMATCH: number & { readonly __brand: "liveupdate.LIVEUPDATE_BUNDLED_RESOURCE_MISMATCH" };
8
+ /**
9
+ * Mismatch between running engine version and engine versions supported by manifest.
10
+ */
5
11
  const LIVEUPDATE_ENGINE_VERSION_MISMATCH: number & { readonly __brand: "liveupdate.LIVEUPDATE_ENGINE_VERSION_MISMATCH" };
12
+ /**
13
+ * Failed to parse manifest data buffer. The manifest was probably produced by a different engine version.
14
+ */
6
15
  const LIVEUPDATE_FORMAT_ERROR: number & { readonly __brand: "liveupdate.LIVEUPDATE_FORMAT_ERROR" };
16
+ /**
17
+ * Argument was invalid
18
+ */
7
19
  const LIVEUPDATE_INVAL: number & { readonly __brand: "liveupdate.LIVEUPDATE_INVAL" };
20
+ /**
21
+ * The handled resource is invalid.
22
+ */
8
23
  const LIVEUPDATE_INVALID_HEADER: number & { readonly __brand: "liveupdate.LIVEUPDATE_INVALID_HEADER" };
24
+ /**
25
+ * The header of the resource is invalid.
26
+ */
9
27
  const LIVEUPDATE_INVALID_RESOURCE: number & { readonly __brand: "liveupdate.LIVEUPDATE_INVALID_RESOURCE" };
28
+ /**
29
+ * I/O operation failed
30
+ */
10
31
  const LIVEUPDATE_IO_ERROR: number & { readonly __brand: "liveupdate.LIVEUPDATE_IO_ERROR" };
32
+ /**
33
+ * Memory wasn't allocated
34
+ */
11
35
  const LIVEUPDATE_MEM_ERROR: number & { readonly __brand: "liveupdate.LIVEUPDATE_MEM_ERROR" };
36
+ /**
37
+ * LIVEUPDATE_OK
38
+ */
12
39
  const LIVEUPDATE_OK: number & { readonly __brand: "liveupdate.LIVEUPDATE_OK" };
40
+ /**
41
+ * Mismatch between scheme used to load resources. Resources are loaded with a different scheme than from manifest, for example over HTTP or directly from file. This is typically the case when running the game directly from the editor instead of from a bundle.
42
+ */
13
43
  const LIVEUPDATE_SCHEME_MISMATCH: number & { readonly __brand: "liveupdate.LIVEUPDATE_SCHEME_MISMATCH" };
44
+ /**
45
+ * Mismatch between expected and actual integrity data for legacy liveupdate verification.
46
+ */
14
47
  const LIVEUPDATE_SIGNATURE_MISMATCH: number & { readonly __brand: "liveupdate.LIVEUPDATE_SIGNATURE_MISMATCH" };
48
+ /**
49
+ * Unspecified error
50
+ */
15
51
  const LIVEUPDATE_UNKNOWN: number & { readonly __brand: "liveupdate.LIVEUPDATE_UNKNOWN" };
52
+ /**
53
+ * Mismatch between manifest expected version and actual version.
54
+ */
16
55
  const LIVEUPDATE_VERSION_MISMATCH: number & { readonly __brand: "liveupdate.LIVEUPDATE_VERSION_MISMATCH" };
56
+ /**
57
+ * Adds a resource mount to the resource system.
58
+ * The mounts are persisted between sessions.
59
+ * After the mount succeeded, the resources are available to load. (i.e. no reboot required)
60
+ *
61
+ * @param name - Unique name of the mount
62
+ * @param uri - The uri of the mount, including the scheme. Currently supported schemes are 'zip' and 'archive'.
63
+ * @param priority - Priority of mount. Larger priority takes prescedence
64
+ * @param callback - Callback after the asynchronous request completed
65
+ * @returns The result of the request
66
+ * @example
67
+ * ```lua
68
+ * Add multiple mounts. Higher priority takes precedence.
69
+ * liveupdate.add_mount("common", "zip:/path/to/common_stuff.zip", 10, function (result) end) -- base pack
70
+ * liveupdate.add_mount("levelpack_1", "zip:/path/to/levels_1_to_20.zip", 20, function (result) end) -- level pack
71
+ * liveupdate.add_mount("season_pack_1", "zip:/path/to/easter_pack_1.zip", 30, function (result) end) -- season pack, overriding content in the other packs
72
+ * ```
73
+ */
17
74
  function add_mount(name: string, uri: string, priority: number, callback: (...args: unknown[]) => unknown): number;
75
+ /**
76
+ * Get an array of the current mounts
77
+ * This can be used to determine if a new mount is needed or not
78
+ *
79
+ * @returns Array of mounts
80
+ * @example
81
+ * ```lua
82
+ * Output the current resource mounts
83
+ * pprint("MOUNTS", liveupdate.get_mounts())
84
+ *
85
+ * Give an output like:
86
+ * DEBUG:SCRIPT: MOUNTS,
87
+ * { --[[0x119667bf0]]
88
+ * 1 = { --[[0x119667c50]]
89
+ * name = "liveupdate",
90
+ * uri = "zip:/device/path/to/acchives/liveupdate.zip",
91
+ * priority = 5
92
+ * },
93
+ * 2 = { --[[0x119667d50]]
94
+ * name = "_base",
95
+ * uri = "archive:build/default/game.dmanifest",
96
+ * priority = -10
97
+ * }
98
+ * }
99
+ * ```
100
+ */
18
101
  function get_mounts(): Record<string | number, unknown>;
102
+ /**
103
+ * Remove a mount the resource system.
104
+ * The remaining mounts are persisted between sessions.
105
+ * Removing a mount does not affect any loaded resources.
106
+ *
107
+ * @param name - Unique name of the mount
108
+ * @returns The result of the call
109
+ * @example
110
+ * ```lua
111
+ * Add multiple mounts. Higher priority takes precedence.
112
+ * liveupdate.remove_mount("season_pack_1")
113
+ * ```
114
+ */
19
115
  function remove_mount(name: string): number;
20
116
  }
21
117
  }
@@ -3,18 +3,174 @@ import type { Hash, Opaque, Url } from "../src/core-types";
3
3
 
4
4
  declare global {
5
5
  namespace model {
6
+ /**
7
+ * Cancels all animation on a model component.
8
+ *
9
+ * @param url - the model for which to cancel the animation
10
+ */
6
11
  function cancel(url: string | Hash | Url): void;
12
+ /**
13
+ * Get AABB of the whole model in local coordinate space.
14
+ * AABB information return as a table with `min` and `max` fields, where `min` and `max` has type `vmath.vector3`.
15
+ *
16
+ * @param url - the model
17
+ * @returns A table containing AABB of the model. If model has no meshes - return vmath.vector3(0,0,0) for min and max fields.
18
+ * @example
19
+ * ```lua
20
+ * model.get_aabb("#model") -> { min = vmath.vector3(-2.5, -3.0, 0), max = vmath.vector3(1.5, 5.5, 0) }
21
+ * model.get_aabb("#empty") -> { min = vmath.vector3(0, 0, 0), max = vmath.vector3(0, 0, 0) }
22
+ * ```
23
+ */
7
24
  function get_aabb(url: string | Hash | Url): Record<string | number, unknown>;
25
+ /**
26
+ * Gets the id of the game object that corresponds to a model skeleton bone.
27
+ * The returned game object can be used for parenting and transform queries.
28
+ * This function has complexity `O(n)`, where `n` is the number of bones in the model skeleton.
29
+ * Game objects corresponding to a model skeleton bone can not be individually deleted.
30
+ *
31
+ * @param url - the model to query
32
+ * @param bone_id - id of the corresponding bone
33
+ * @returns id of the game object
34
+ * @example
35
+ * ```lua
36
+ * The following examples assumes that the model component has id "model".
37
+ * How to parent the game object of the calling script to the "right_hand" bone of the model in a player game object:
38
+ * function init(self)
39
+ * local parent = model.get_go("player#model", "right_hand")
40
+ * msg.post(".", "set_parent", {parent_id = parent})
41
+ * end
42
+ * ```
43
+ */
8
44
  function get_go(url: string | Hash | Url, bone_id: string | Hash): Hash;
45
+ /**
46
+ * Get AABB of all meshes.
47
+ * AABB information return as a table with `min` and `max` fields, where `min` and `max` has type `vmath.vector3`.
48
+ *
49
+ * @param url - the model
50
+ * @returns A table containing info about all AABB in the format
51
+ * @example
52
+ * ```lua
53
+ * model.get_mesh_aabb("#model") -> { hash("Sword") = { min = vmath.vector3(-0.5, -0.5, 0), max = vmath.vector3(0.5, 0.5, 0) }, hash("Shield") = { min = vmath.vector3(-0.5, -0.5, -0.5), max = vmath.vector3(0.5, 0.5, 0.5) } }
54
+ * ```
55
+ */
9
56
  function get_mesh_aabb(url: string | Hash | Url): Record<string | number, unknown>;
57
+ /**
58
+ * Get the enabled state of a mesh
59
+ *
60
+ * @param url - the model
61
+ * @param mesh_id - the id of the mesh
62
+ * @returns true if the mesh is visible, false otherwise
63
+ * @example
64
+ * ```lua
65
+ * function init(self)
66
+ * if model.get_mesh_enabled("#model", "Sword") then
67
+ * -- set properties specific for the sword
68
+ * self.weapon_properties = game.data.weapons["Sword"]
69
+ * end
70
+ * end
71
+ * ```
72
+ */
10
73
  function get_mesh_enabled(url: string | Hash | Url, mesh_id: string | Hash | Url): boolean;
74
+ /**
75
+ * Plays an animation on a model component with specified playback
76
+ * mode and parameters.
77
+ * An optional completion callback function can be provided that will be called when
78
+ * the animation has completed playing. If no function is provided,
79
+ * a model_animation_done message is sent to the script that started the animation.
80
+ * The callback is not called (or message sent) if the animation is
81
+ * cancelled with model.cancel. The callback is called (or message sent) only for
82
+ * animations that play with the following playback modes:
83
+ * - `go.PLAYBACK_ONCE_FORWARD`
84
+ * - `go.PLAYBACK_ONCE_BACKWARD`
85
+ * - `go.PLAYBACK_ONCE_PINGPONG`
86
+ *
87
+ * @param url - the model for which to play the animation
88
+ * @param anim_id - id of the animation to play
89
+ * @param playback - playback mode of the animation
90
+ - `go.PLAYBACK_ONCE_FORWARD`
91
+ - `go.PLAYBACK_ONCE_BACKWARD`
92
+ - `go.PLAYBACK_ONCE_PINGPONG`
93
+ - `go.PLAYBACK_LOOP_FORWARD`
94
+ - `go.PLAYBACK_LOOP_BACKWARD`
95
+ - `go.PLAYBACK_LOOP_PINGPONG`
96
+ * @param play_properties - optional table with properties
97
+ Play properties table:
98
+ `blend_duration`
99
+ number Duration of a linear blend between the current and new animation.
100
+ `offset`
101
+ number The normalized initial value of the animation cursor when the animation starts playing.
102
+ `playback_rate`
103
+ number The rate with which the animation will be played. Must be positive.
104
+ * @param complete_function - function to call when the animation has completed.
105
+ `self`
106
+ object The current object.
107
+ `message_id`
108
+ hash The name of the completion message, `"model_animation_done"`.
109
+ `message`
110
+ table Information about the completion:
111
+ - hash `animation_id` - the animation that was completed.
112
+ - constant `playback` - the playback mode for the animation.
113
+ `sender`
114
+ url The invoker of the callback: the model component.
115
+ * @example
116
+ * ```lua
117
+ * The following examples assumes that the model has id "model".
118
+ * How to play the "jump" animation followed by the "run" animation:
119
+ * local function anim_done(self, message_id, message, sender)
120
+ * if message_id == hash("model_animation_done") then
121
+ * if message.animation_id == hash("jump") then
122
+ * -- open animation done, chain with "run"
123
+ * local properties = { blend_duration = 0.2 }
124
+ * model.play_anim(url, "run", go.PLAYBACK_LOOP_FORWARD, properties, anim_done)
125
+ * end
126
+ * end
127
+ * end
128
+ *
129
+ * function init(self)
130
+ * local url = msg.url("#model")
131
+ * local play_properties = { blend_duration = 0.1 }
132
+ * -- first blend during 0.1 sec into the jump, then during 0.2 s into the run animation
133
+ * model.play_anim(url, "jump", go.PLAYBACK_ONCE_FORWARD, play_properties, anim_done)
134
+ * end
135
+ * ```
136
+ */
11
137
  function play_anim(url: string | Hash | Url, anim_id: string | Hash, playback: Opaque<"constant">, play_properties?: { blend_duration?: number; offset?: number; playback_rate?: number }, complete_function?: (self: unknown, message_id: unknown, message: unknown, sender: unknown) => void): void;
138
+ /**
139
+ * Enable or disable visibility of a mesh
140
+ *
141
+ * @param url - the model
142
+ * @param mesh_id - the id of the mesh
143
+ * @param enabled - true if the mesh should be visible, false if it should be hideen
144
+ * @example
145
+ * ```lua
146
+ * function init(self)
147
+ * model.set_mesh_enabled("#model", "Sword", false) -- hide the sword
148
+ * model.set_mesh_enabled("#model", "Axe", true) -- show the axe
149
+ * end
150
+ * ```
151
+ */
12
152
  function set_mesh_enabled(url: string | Hash | Url, mesh_id: string | Hash | Url, enabled: boolean): void;
13
153
  interface properties {
154
+ /**
155
+ * The current animation set on the component. The type of the property is hash.
156
+ */
14
157
  animation: Hash;
158
+ /**
159
+ * The normalized animation cursor. The type of the property is number.
160
+ * Please note that model events may not fire as expected when the cursor is manipulated directly.
161
+ */
15
162
  cursor: number;
163
+ /**
164
+ * The material used when rendering the model. The type of the property is hash.
165
+ */
16
166
  material: Hash;
167
+ /**
168
+ * The animation playback rate. A multiplier to the animation playback rate. The type of the property is number.
169
+ */
17
170
  playback_rate: number;
171
+ /**
172
+ * The texture hash id of the model. Used for getting/setting model texture for unit 0-7
173
+ */
18
174
  textureN: Hash;
19
175
  }
20
176
  }