@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
@@ -5,7 +5,18 @@ declare global {
5
5
  namespace b2d {
6
6
  type b2Body = Opaque<"b2Body">;
7
7
  type b2World = Opaque<"b2World">;
8
+ /**
9
+ * Get the Box2D body from a collision object
10
+ *
11
+ * @param url - the url to the game object collision component
12
+ * @returns the body if successful. Otherwise `nil`.
13
+ */
8
14
  function get_body(url: string | Hash | Url): Opaque<"b2Body">;
15
+ /**
16
+ * Get the Box2D world from the current collection
17
+ *
18
+ * @returns the world if successful. Otherwise `nil`.
19
+ */
9
20
  function get_world(): Opaque<"b2World">;
10
21
  }
11
22
  }
@@ -3,21 +3,163 @@ import type { Hash, Opaque } from "../src/core-types";
3
3
 
4
4
  declare global {
5
5
  namespace buffer {
6
+ /**
7
+ * Float, single precision, 4 bytes
8
+ */
6
9
  const VALUE_TYPE_FLOAT32: number & { readonly __brand: "buffer.VALUE_TYPE_FLOAT32" };
10
+ /**
11
+ * Signed integer, 2 bytes
12
+ */
7
13
  const VALUE_TYPE_INT16: number & { readonly __brand: "buffer.VALUE_TYPE_INT16" };
14
+ /**
15
+ * Signed integer, 4 bytes
16
+ */
8
17
  const VALUE_TYPE_INT32: number & { readonly __brand: "buffer.VALUE_TYPE_INT32" };
18
+ /**
19
+ * Signed integer, 8 bytes
20
+ */
9
21
  const VALUE_TYPE_INT64: number & { readonly __brand: "buffer.VALUE_TYPE_INT64" };
22
+ /**
23
+ * Signed integer, 1 byte
24
+ */
10
25
  const VALUE_TYPE_INT8: number & { readonly __brand: "buffer.VALUE_TYPE_INT8" };
26
+ /**
27
+ * Unsigned integer, 2 bytes
28
+ */
11
29
  const VALUE_TYPE_UINT16: number & { readonly __brand: "buffer.VALUE_TYPE_UINT16" };
30
+ /**
31
+ * Unsigned integer, 4 bytes
32
+ */
12
33
  const VALUE_TYPE_UINT32: number & { readonly __brand: "buffer.VALUE_TYPE_UINT32" };
34
+ /**
35
+ * Unsigned integer, 8 bytes
36
+ */
13
37
  const VALUE_TYPE_UINT64: number & { readonly __brand: "buffer.VALUE_TYPE_UINT64" };
38
+ /**
39
+ * Unsigned integer, 1 byte
40
+ */
14
41
  const VALUE_TYPE_UINT8: number & { readonly __brand: "buffer.VALUE_TYPE_UINT8" };
42
+ /**
43
+ * Copy all data streams from one buffer to another, element wise.
44
+ * Each of the source streams must have a matching stream in the
45
+ * destination buffer. The streams must match in both type and size.
46
+ * The source and destination buffer can be the same.
47
+ *
48
+ * @param dst - the destination buffer
49
+ * @param dstoffset - the offset to start copying data to
50
+ * @param src - the source data buffer
51
+ * @param srcoffset - the offset to start copying data from
52
+ * @param count - the number of elements to copy
53
+ * @example
54
+ * ```lua
55
+ * How to copy elements (e.g. vertices) from one buffer to another
56
+ * -- copy entire buffer
57
+ * buffer.copy_buffer(dstbuffer, 0, srcbuffer, 0, #srcbuffer)
58
+ *
59
+ * -- copy last 10 elements to the front of another buffer
60
+ * buffer.copy_buffer(dstbuffer, 0, srcbuffer, #srcbuffer - 10, 10)
61
+ * ```
62
+ */
15
63
  function copy_buffer(dst: Opaque<"buffer">, dstoffset: number, src: Opaque<"buffer">, srcoffset: number, count: number): void;
64
+ /**
65
+ * Copy a specified amount of data from one stream to another.
66
+ * The value type and size must match between source and destination streams.
67
+ * The source and destination streams can be the same.
68
+ *
69
+ * @param dst - the destination stream
70
+ * @param dstoffset - the offset to start copying data to (measured in value type)
71
+ * @param src - the source data stream
72
+ * @param srcoffset - the offset to start copying data from (measured in value type)
73
+ * @param count - the number of values to copy (measured in value type)
74
+ * @example
75
+ * ```lua
76
+ * How to update a texture of a sprite:
77
+ * -- copy entire stream
78
+ * local srcstream = buffer.get_stream(srcbuffer, hash("xyz"))
79
+ * local dststream = buffer.get_stream(dstbuffer, hash("xyz"))
80
+ * buffer.copy_stream(dststream, 0, srcstream, 0, #srcstream)
81
+ * ```
82
+ */
16
83
  function copy_stream(dst: Opaque<"bufferstream">, dstoffset: number, src: Opaque<"bufferstream">, srcoffset: number, count: number): void;
84
+ /**
85
+ * Create a new data buffer containing a specified set of streams. A data buffer
86
+ * can contain one or more streams with typed data. This is useful for managing
87
+ * compound data, for instance a vertex buffer could contain separate streams for
88
+ * vertex position, color, normal etc.
89
+ *
90
+ * @param element_count - The number of elements the buffer should hold
91
+ * @param declaration - A table where each entry (table) describes a stream
92
+ - hash | string `name`: The name of the stream
93
+ - constant `type`: The data type of the stream
94
+ - number `count`: The number of values each element should hold
95
+ * @returns the new buffer
96
+ * @example
97
+ * ```lua
98
+ * How to create and initialize a buffer
99
+ * function init(self)
100
+ * local size = 128
101
+ * self.image = buffer.create( size * size, { {name=hash("rgb"), type=buffer.VALUE_TYPE_UINT8, count=3 } })
102
+ * self.imagestream = buffer.get_stream(self.image, hash("rgb"))
103
+ *
104
+ * for y=0,self.height-1 do
105
+ * for x=0,self.width-1 do
106
+ * local index = y * self.width * 3 + x * 3 + 1
107
+ * self.imagestream[index + 0] = self.r
108
+ * self.imagestream[index + 1] = self.g
109
+ * self.imagestream[index + 2] = self.b
110
+ * end
111
+ * end
112
+ * ```
113
+ */
17
114
  function create(element_count: number, declaration: { name?: Hash | string; type?: Opaque<"constant">; count?: number }): Opaque<"buffer">;
115
+ /**
116
+ * Get a copy of all the bytes from a specified stream as a Lua string.
117
+ *
118
+ * @param buffer - the source buffer
119
+ * @param stream_name - the name of the stream
120
+ * @returns the buffer data as a Lua string
121
+ */
18
122
  function get_bytes(buffer: Opaque<"buffer">, stream_name: Hash): string;
123
+ /**
124
+ * Get a named metadata entry from a buffer along with its type.
125
+ *
126
+ * @param buf - the buffer to get the metadata from
127
+ * @param metadata_name - name of the metadata entry
128
+ * @example
129
+ * ```lua
130
+ * How to get a metadata entry from a buffer
131
+ * -- retrieve a metadata entry named "somefloats" and its nomeric type
132
+ * local values, type = buffer.get_metadata(buf, hash("somefloats"))
133
+ * if metadata then print(#metadata.." values in 'somefloats'") end
134
+ * ```
135
+ */
19
136
  function get_metadata(buf: Opaque<"buffer">, metadata_name: Hash | string): LuaMultiReturn<[number[] | unknown, Opaque<"constant"> | unknown]>;
137
+ /**
138
+ * Get a specified stream from a buffer.
139
+ *
140
+ * @param buffer - the buffer to get the stream from
141
+ * @param stream_name - the stream name
142
+ * @returns the data stream
143
+ */
20
144
  function get_stream(buffer: Opaque<"buffer">, stream_name: Hash | string): Opaque<"bufferstream">;
145
+ /**
146
+ * Creates or updates a metadata array entry on a buffer.
147
+ * The value type and count given when updating the entry should match those used when first creating it.
148
+ *
149
+ * @param buf - the buffer to set the metadata on
150
+ * @param metadata_name - name of the metadata entry
151
+ * @param values - actual metadata, an array of numeric values
152
+ * @param value_type - type of values when stored
153
+ * @example
154
+ * ```lua
155
+ * How to set a metadata entry on a buffer
156
+ * -- create a new metadata entry with three floats
157
+ * buffer.set_metadata(buf, hash("somefloats"), {1.5, 3.2, 7.9}, buffer.VALUE_TYPE_FLOAT32)
158
+ * -- ...
159
+ * -- update to a new set of values
160
+ * buffer.set_metadata(buf, hash("somefloats"), {-2.5, 10.0, 32.2}, buffer.VALUE_TYPE_FLOAT32)
161
+ * ```
162
+ */
21
163
  function set_metadata(buf: Opaque<"buffer">, metadata_name: Hash | string, values: number[], value_type: Opaque<"constant">): void;
22
164
  }
23
165
  }
@@ -3,13 +3,131 @@ import type { Hash, Opaque, Quaternion, Url, Vector3 } from "../src/core-types";
3
3
 
4
4
  declare global {
5
5
  namespace collectionfactory {
6
+ /**
7
+ * loaded
8
+ */
6
9
  const STATUS_LOADED: number & { readonly __brand: "collectionfactory.STATUS_LOADED" };
10
+ /**
11
+ * loading
12
+ */
7
13
  const STATUS_LOADING: number & { readonly __brand: "collectionfactory.STATUS_LOADING" };
14
+ /**
15
+ * unloaded
16
+ */
8
17
  const STATUS_UNLOADED: number & { readonly __brand: "collectionfactory.STATUS_UNLOADED" };
18
+ /**
19
+ * The URL identifies the collectionfactory component that should do the spawning.
20
+ * Spawning is instant, but spawned game objects get their first update calls the following frame. The supplied parameters for position, rotation and scale
21
+ * will be applied to the whole collection when spawned.
22
+ * Script properties in the created game objects can be overridden through
23
+ * a properties-parameter table. The table should contain game object ids
24
+ * (hash) as keys and property tables as values to be used when initiating each
25
+ * spawned game object.
26
+ * See go.property for more information on script properties.
27
+ * The function returns a table that contains a key for each game object
28
+ * id (hash), as addressed if the collection file was top level, and the
29
+ * corresponding spawned instance id (hash) as value with a unique path
30
+ * prefix added to each instance.
31
+ * Calling collectionfactory.create create on a collection factory that is marked as dynamic without having loaded resources
32
+ * using collectionfactory.load will synchronously load and create resources which may affect application performance.
33
+ *
34
+ * @param url - the collection factory component to be used
35
+ * @param position - position to assign to the newly spawned collection
36
+ * @param rotation - rotation to assign to the newly spawned collection
37
+ * @param properties - table of script properties to propagate to any new game object instances
38
+ * @param scale - uniform scaling to apply to the newly spawned collection (must be greater than 0).
39
+ * @returns a table mapping the id:s from the collection to the new instance id:s
40
+ * @example
41
+ * ```lua
42
+ * How to spawn a collection of game objects:
43
+ * function init(self)
44
+ * -- Spawn a small group of enemies.
45
+ * local pos = vmath.vector3(100, 12.5, 0)
46
+ * local rot = vmath.quat_rotation_z(math.pi / 2)
47
+ * local scale = 0.5
48
+ * local props = {}
49
+ * props[hash("/enemy_leader")] = { health = 1000.0 }
50
+ * props[hash("/enemy_1")] = { health = 200.0 }
51
+ * props[hash("/enemy_2")] = { health = 400.0, color = hash("green") }
52
+ *
53
+ * local self.enemy_ids = collectionfactory.create("#enemyfactory", pos, rot, props, scale)
54
+ * -- enemy_ids now map to the spawned instance ids:
55
+ * --
56
+ * -- pprint(self.enemy_ids)
57
+ * --
58
+ * -- DEBUG:SCRIPT:
59
+ * -- {
60
+ * -- hash: [/enemy_leader] = hash: [/collection0/enemy_leader],
61
+ * -- hash: [/enemy_1] = hash: [/collection0/enemy_1],
62
+ * -- hash: [/enemy_2] = hash: [/collection0/enemy_2]
63
+ * -- }
64
+ *
65
+ * -- Send "attack" message to the leader. First look up its instance id.
66
+ * local leader_id = self.enemy_ids[hash("/enemy_leader")]
67
+ * msg.post(leader_id, "attack")
68
+ * end
69
+ *
70
+ * How to delete a spawned collection:
71
+ * go.delete(self.enemy_ids)
72
+ * ```
73
+ */
9
74
  function create(url: string | Hash | Url, position?: Vector3, rotation?: Quaternion, properties?: Record<string | number, unknown>, scale?: number | Vector3): Record<string | number, unknown>;
75
+ /**
76
+ * This returns status of the collection factory.
77
+ * Calling this function when the factory is not marked as dynamic loading always returns COMP_COLLECTION_FACTORY_STATUS_LOADED.
78
+ *
79
+ * @param url - the collection factory component to get status from
80
+ * @returns status of the collection factory component
81
+ - `collectionfactory.STATUS_UNLOADED`
82
+ - `collectionfactory.STATUS_LOADING`
83
+ - `collectionfactory.STATUS_LOADED`
84
+ */
10
85
  function get_status(url?: string | Hash | Url): Opaque<"constant">;
86
+ /**
87
+ * Resources loaded are referenced by the collection factory component until the existing (parent) collection is destroyed or collectionfactory.unload is called.
88
+ * Calling this function when the factory is not marked as dynamic loading does nothing.
89
+ *
90
+ * @param url - the collection factory component to load
91
+ * @param complete_function - function to call when resources are loaded.
92
+ `self`
93
+ object The current object.
94
+ `url`
95
+ url url of the collection factory component
96
+ `result`
97
+ boolean True if resource were loaded successfully
98
+ * @example
99
+ * ```lua
100
+ * How to load resources of a collection factory prototype.
101
+ * collectionfactory.load("#factory", function(self, url, result) end)
102
+ * ```
103
+ */
11
104
  function load(url?: string | Hash | Url, complete_function?: (self: unknown, url: unknown, result: unknown) => void): void;
105
+ /**
106
+ * Changes the prototype for the collection factory.
107
+ * Setting the prototype to "nil" will revert back to the original prototype.
108
+ *
109
+ * @param url - the collection factory component
110
+ * @param prototype - the path to the new prototype, or `nil`
111
+ * @example
112
+ * ```lua
113
+ * How to unload the previous prototypes resources, and then spawn a new collection
114
+ * collectionfactory.unload("#factory") -- unload the previous resources
115
+ * collectionfactory.set_prototype("#factory", "/main/levels/level1.collectionc")
116
+ * local ids = collectionfactory.create("#factory", go.get_world_position(), vmath.quat())
117
+ * ```
118
+ */
12
119
  function set_prototype(url?: string | Hash | Url, prototype?: string): void;
120
+ /**
121
+ * This decreases the reference count for each resource loaded with collectionfactory.load. If reference is zero, the resource is destroyed.
122
+ * Calling this function when the factory is not marked as dynamic loading does nothing.
123
+ *
124
+ * @param url - the collection factory component to unload
125
+ * @example
126
+ * ```lua
127
+ * How to unload resources of a collection factory prototype loaded with collectionfactory.load
128
+ * collectionfactory.unload("#factory")
129
+ * ```
130
+ */
13
131
  function unload(url?: string | Hash | Url): void;
14
132
  }
15
133
  }
@@ -3,10 +3,62 @@ import type { Hash, Url } from "../src/core-types";
3
3
 
4
4
  declare global {
5
5
  namespace collectionproxy {
6
+ /**
7
+ * It's impossible to change the collection if the collection is already loaded.
8
+ */
6
9
  const RESULT_ALREADY_LOADED: number & { readonly __brand: "collectionproxy.RESULT_ALREADY_LOADED" };
10
+ /**
11
+ * It's impossible to change the collection while the collection proxy is loading.
12
+ */
7
13
  const RESULT_LOADING: number & { readonly __brand: "collectionproxy.RESULT_LOADING" };
14
+ /**
15
+ * It's impossible to change the collection for a proxy that isn't excluded.
16
+ */
8
17
  const RESULT_NOT_EXCLUDED: number & { readonly __brand: "collectionproxy.RESULT_NOT_EXCLUDED" };
18
+ /**
19
+ * return an indexed table of resources for a collection proxy where the
20
+ * referenced collection has been excluded using LiveUpdate. Each entry is a
21
+ * hexadecimal string that represents the data of the specific resource.
22
+ * This representation corresponds with the filename for each individual
23
+ * resource that is exported when you bundle an application with LiveUpdate
24
+ * functionality.
25
+ *
26
+ * @param collectionproxy - the collectionproxy to check for resources.
27
+ * @returns the resources, or an empty list if the
28
+ collection was not excluded.
29
+ * @example
30
+ * ```lua
31
+ * local function print_resources(self, cproxy)
32
+ * local resources = collectionproxy.get_resources(cproxy)
33
+ * for _, v in ipairs(resources) do
34
+ * print("Resource: " .. v)
35
+ * end
36
+ * end
37
+ * ```
38
+ */
9
39
  function get_resources(collectionproxy: Url): Record<string | number, unknown>;
40
+ /**
41
+ * The collection should be loaded by the collection proxy.
42
+ * Setting the collection to "nil" will revert it back to the original collection.
43
+ * The collection proxy shouldn't be loaded and should have the 'Exclude' checkbox checked.
44
+ * This functionality is designed to simplify the management of Live Update resources.
45
+ *
46
+ * @param url - the collection proxy component
47
+ * @param prototype - the path to the new collection, or `nil`
48
+ * @example
49
+ * ```lua
50
+ * The example assume the script belongs to an instance with collection-proxy-component with id "proxy".
51
+ * local ok, error = collectionproxy.set_collection("/go#collectionproxy", "/LU/3.collectionc")
52
+ * if ok then
53
+ * print("The collection has been changed to /LU/3.collectionc")
54
+ * else
55
+ * print("Error changing collection to /LU/3.collectionc ", error)
56
+ * end
57
+ * msg.post("/go#collectionproxy", "load")
58
+ * msg.post("/go#collectionproxy", "init")
59
+ * msg.post("/go#collectionproxy", "enable")
60
+ * ```
61
+ */
10
62
  function set_collection(url?: string | Hash | Url, prototype?: string): LuaMultiReturn<[boolean, number]>;
11
63
  }
12
64
  }
@@ -1,29 +1,138 @@
1
1
  /** @noSelfInFile */
2
2
  declare global {
3
3
  namespace crash {
4
+ /**
5
+ * android build fingerprint
6
+ */
4
7
  const SYSFIELD_ANDROID_BUILD_FINGERPRINT: number & { readonly __brand: "crash.SYSFIELD_ANDROID_BUILD_FINGERPRINT" };
8
+ /**
9
+ * system device language as reported by sys.get_sys_info
10
+ */
5
11
  const SYSFIELD_DEVICE_LANGUAGE: number & { readonly __brand: "crash.SYSFIELD_DEVICE_LANGUAGE" };
12
+ /**
13
+ * device model as reported by sys.get_sys_info
14
+ */
6
15
  const SYSFIELD_DEVICE_MODEL: number & { readonly __brand: "crash.SYSFIELD_DEVICE_MODEL" };
16
+ /**
17
+ * engine version as hash
18
+ */
7
19
  const SYSFIELD_ENGINE_HASH: number & { readonly __brand: "crash.SYSFIELD_ENGINE_HASH" };
20
+ /**
21
+ * engine version as release number
22
+ */
8
23
  const SYSFIELD_ENGINE_VERSION: number & { readonly __brand: "crash.SYSFIELD_ENGINE_VERSION" };
24
+ /**
25
+ * system language as reported by sys.get_sys_info
26
+ */
9
27
  const SYSFIELD_LANGUAGE: number & { readonly __brand: "crash.SYSFIELD_LANGUAGE" };
28
+ /**
29
+ * device manufacturer as reported by sys.get_sys_info
30
+ */
10
31
  const SYSFIELD_MANUFACTURER: number & { readonly __brand: "crash.SYSFIELD_MANUFACTURER" };
32
+ /**
33
+ * The max number of sysfields.
34
+ */
11
35
  const SYSFIELD_MAX: number & { readonly __brand: "crash.SYSFIELD_MAX" };
36
+ /**
37
+ * system name as reported by sys.get_sys_info
38
+ */
12
39
  const SYSFIELD_SYSTEM_NAME: number & { readonly __brand: "crash.SYSFIELD_SYSTEM_NAME" };
40
+ /**
41
+ * system version as reported by sys.get_sys_info
42
+ */
13
43
  const SYSFIELD_SYSTEM_VERSION: number & { readonly __brand: "crash.SYSFIELD_SYSTEM_VERSION" };
44
+ /**
45
+ * system territory as reported by sys.get_sys_info
46
+ */
14
47
  const SYSFIELD_TERRITORY: number & { readonly __brand: "crash.SYSFIELD_TERRITORY" };
48
+ /**
49
+ * The max number of user fields.
50
+ */
15
51
  const USERFIELD_MAX: number & { readonly __brand: "crash.USERFIELD_MAX" };
52
+ /**
53
+ * The max size of a single user field.
54
+ */
16
55
  const USERFIELD_SIZE: number & { readonly __brand: "crash.USERFIELD_SIZE" };
56
+ /**
57
+ * A table is returned containing the addresses of the call stack.
58
+ *
59
+ * @param handle - crash dump handle
60
+ * @returns table containing the backtrace
61
+ */
17
62
  function get_backtrace(handle: number): Record<string | number, unknown>;
63
+ /**
64
+ * The format of read text blob is platform specific
65
+ * and not guaranteed
66
+ * but can be useful for manual inspection.
67
+ *
68
+ * @param handle - crash dump handle
69
+ * @returns string with the platform specific data
70
+ */
18
71
  function get_extra_data(handle: number): string;
72
+ /**
73
+ * The function returns a table containing entries with sub-tables that
74
+ * have fields 'name' and 'address' set for all loaded modules.
75
+ *
76
+ * @param handle - crash dump handle
77
+ * @returns module table
78
+ */
19
79
  function get_modules(handle: number): Record<string | number, unknown>;
80
+ /**
81
+ * read signal number from a crash report
82
+ *
83
+ * @param handle - crash dump handle
84
+ * @returns signal number
85
+ */
20
86
  function get_signum(handle: number): number;
87
+ /**
88
+ * reads a system field from a loaded crash dump
89
+ *
90
+ * @param handle - crash dump handle
91
+ * @param index - system field enum. Must be less than crash.SYSFIELD_MAX
92
+ * @returns value recorded in the crash dump, or `nil` if it didn't exist
93
+ */
21
94
  function get_sys_field(handle: number, index: number): string | unknown;
95
+ /**
96
+ * reads user field from a loaded crash dump
97
+ *
98
+ * @param handle - crash dump handle
99
+ * @param index - user data slot index
100
+ * @returns user data value recorded in the crash dump
101
+ */
22
102
  function get_user_field(handle: number, index: number): string;
103
+ /**
104
+ * The crash dump will be removed from disk upon a successful
105
+ * load, so loading is one-shot.
106
+ *
107
+ * @returns handle to the loaded dump, or `nil` if no dump was found
108
+ */
23
109
  function load_previous(): number | unknown;
110
+ /**
111
+ * releases a previously loaded crash dump
112
+ *
113
+ * @param handle - handle to loaded crash dump
114
+ */
24
115
  function release(handle: number): void;
116
+ /**
117
+ * Crashes occuring before the path is set will be stored to a default engine location.
118
+ *
119
+ * @param path - file path to use
120
+ */
25
121
  function set_file_path(path: string): void;
122
+ /**
123
+ * Store a user value that will get written to a crash dump when
124
+ * a crash occurs. This can be user id:s, breadcrumb data etc.
125
+ * There are 32 slots indexed from 0. Each slot stores at most 255 characters.
126
+ *
127
+ * @param index - slot index. 0-indexed
128
+ * @param value - string value to store
129
+ */
26
130
  function set_user_field(index: number, value: string): void;
131
+ /**
132
+ * Performs the same steps as if a crash had just occured but
133
+ * allows the program to continue.
134
+ * The generated dump can be read by crash.load_previous
135
+ */
27
136
  function write_dump(): void;
28
137
  }
29
138
  }
@@ -3,13 +3,107 @@ import type { Hash, Opaque, Quaternion, Url, Vector3 } from "../src/core-types";
3
3
 
4
4
  declare global {
5
5
  namespace factory {
6
+ /**
7
+ * loaded
8
+ */
6
9
  const STATUS_LOADED: number & { readonly __brand: "factory.STATUS_LOADED" };
10
+ /**
11
+ * loading
12
+ */
7
13
  const STATUS_LOADING: number & { readonly __brand: "factory.STATUS_LOADING" };
14
+ /**
15
+ * unloaded
16
+ */
8
17
  const STATUS_UNLOADED: number & { readonly __brand: "factory.STATUS_UNLOADED" };
18
+ /**
19
+ * The URL identifies which factory should create the game object.
20
+ * If the game object is created inside of the frame (e.g. from an update callback), the game object will be created instantly, but none of its component will be updated in the same frame.
21
+ * Properties defined in scripts in the created game object can be overridden through the properties-parameter below.
22
+ * See go.property for more information on script properties.
23
+ * Calling factory.create on a factory that is marked as dynamic without having loaded resources
24
+ * using factory.load will synchronously load and create resources which may affect application performance.
25
+ *
26
+ * @param url - the factory that should create a game object.
27
+ * @param position - the position of the new game object, the position of the game object calling `factory.create()` is used by default, or if the value is `nil`.
28
+ * @param rotation - the rotation of the new game object, the rotation of the game object calling `factory.create()` is used by default, or if the value is `nil`.
29
+ * @param properties - the properties defined in a script attached to the new game object.
30
+ * @param scale - the scale of the new game object (must be greater than 0), the scale of the game object containing the factory is used by default, or if the value is `nil`
31
+ * @returns the global id of the spawned game object
32
+ * @example
33
+ * ```lua
34
+ * How to create a new game object:
35
+ * function init(self)
36
+ * -- create a new game object and provide property values
37
+ * self.my_created_object = factory.create("#factory", nil, nil, {my_value = 1})
38
+ * -- communicate with the object
39
+ * msg.post(self.my_created_object, "hello")
40
+ * end
41
+ *
42
+ * And then let the new game object have a script attached:
43
+ * go.property("my_value", 0)
44
+ *
45
+ * function init(self)
46
+ * -- do something with self.my_value which is now one
47
+ * end
48
+ * ```
49
+ */
9
50
  function create(url: string | Hash | Url, position?: Vector3, rotation?: Quaternion, properties?: Record<string | number, unknown>, scale?: number | Vector3): Hash;
51
+ /**
52
+ * This returns status of the factory.
53
+ * Calling this function when the factory is not marked as dynamic loading always returns
54
+ * factory.STATUS_LOADED.
55
+ *
56
+ * @param url - the factory component to get status from
57
+ * @returns status of the factory component
58
+ - `factory.STATUS_UNLOADED`
59
+ - `factory.STATUS_LOADING`
60
+ - `factory.STATUS_LOADED`
61
+ */
10
62
  function get_status(url?: string | Hash | Url): Opaque<"constant">;
63
+ /**
64
+ * Resources are referenced by the factory component until the existing (parent) collection is destroyed or factory.unload is called.
65
+ * Calling this function when the factory is not marked as dynamic loading does nothing.
66
+ *
67
+ * @param url - the factory component to load
68
+ * @param complete_function - function to call when resources are loaded.
69
+ `self`
70
+ object The current object.
71
+ `url`
72
+ url url of the factory component
73
+ `result`
74
+ boolean True if resources were loaded successfully
75
+ * @example
76
+ * ```lua
77
+ * How to load resources of a factory prototype.
78
+ * factory.load("#factory", function(self, url, result) end)
79
+ * ```
80
+ */
11
81
  function load(url?: string | Hash | Url, complete_function?: (self: unknown, url: unknown, result: unknown) => void): void;
82
+ /**
83
+ * Changes the prototype for the factory.
84
+ *
85
+ * @param url - the factory component
86
+ * @param prototype - the path to the new prototype, or `nil`
87
+ * @example
88
+ * ```lua
89
+ * How to unload the previous prototypes resources, and then spawn a new game object
90
+ * factory.unload("#factory") -- unload the previous resources
91
+ * factory.set_prototype("#factory", "/main/levels/enemyA.goc")
92
+ * local id = factory.create("#factory", go.get_world_position(), vmath.quat())
93
+ * ```
94
+ */
12
95
  function set_prototype(url?: string | Hash | Url, prototype?: string): void;
96
+ /**
97
+ * This decreases the reference count for each resource loaded with factory.load. If reference is zero, the resource is destroyed.
98
+ * Calling this function when the factory is not marked as dynamic loading does nothing.
99
+ *
100
+ * @param url - the factory component to unload
101
+ * @example
102
+ * ```lua
103
+ * How to unload resources of a factory prototype loaded with factory.load
104
+ * factory.unload("#factory")
105
+ * ```
106
+ */
13
107
  function unload(url?: string | Hash | Url): void;
14
108
  }
15
109
  }