@defold-typescript/types 0.25.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api-availability.json +333 -306
- package/api-signatures.json +1312 -0
- package/api-targets.json +351 -2
- package/examples/translations.json +1984 -0
- package/fixtures/messages_doc.json +880 -0
- package/generated/collectionproxy.d.ts +22 -0
- package/generated/editor-vm/http.d.ts +2 -2
- package/generated/editor-vm/image.d.ts +48 -0
- package/generated/editor.d.ts +27 -8
- package/generated/gui.d.ts +35 -6
- package/generated/kinds/editor-script.d.ts +1 -0
- package/generated/material.d.ts +4 -0
- package/generated/versions/defold-1.12.4/liveupdate.d.ts +22 -22
- package/generated/versions/defold-1.12.4/physics.d.ts +78 -75
- package/generated/versions/defold-1.12.4/render.d.ts +75 -55
- package/generated/versions/defold-1.12.4/resource.d.ts +187 -175
- package/generated/versions/defold-1.13.0/b2d.d.ts +33 -0
- package/generated/versions/defold-1.13.0/b2d_body.d.ts +676 -0
- package/generated/versions/defold-1.13.0/b2d_chain.d.ts +106 -0
- package/generated/versions/defold-1.13.0/b2d_fixture.d.ts +155 -0
- package/generated/versions/defold-1.13.0/b2d_joint.d.ts +823 -0
- package/generated/versions/defold-1.13.0/b2d_shape.d.ts +215 -0
- package/generated/versions/defold-1.13.0/b2d_world.d.ts +314 -0
- package/generated/versions/defold-1.13.0/buffer.d.ts +176 -0
- package/generated/versions/defold-1.13.0/camera.d.ts +302 -0
- package/generated/versions/defold-1.13.0/collectionfactory.d.ts +146 -0
- package/generated/versions/defold-1.13.0/collectionproxy.d.ts +71 -0
- package/generated/versions/defold-1.13.0/compute.d.ts +306 -0
- package/generated/versions/defold-1.13.0/crash.d.ts +143 -0
- package/generated/versions/defold-1.13.0/editor-vm/http.d.ts +56 -0
- package/generated/versions/defold-1.13.0/editor-vm/json.d.ts +10 -0
- package/generated/versions/defold-1.13.0/editor-vm/localization.d.ts +42 -0
- package/generated/versions/defold-1.13.0/editor-vm/tilemap_tiles.d.ts +80 -0
- package/generated/versions/defold-1.13.0/editor-vm/zip.d.ts +10 -0
- package/generated/versions/defold-1.13.0/editor-vm/zlib.d.ts +24 -0
- package/generated/versions/defold-1.13.0/editor.d.ts +1092 -0
- package/generated/versions/defold-1.13.0/factory.d.ts +123 -0
- package/generated/versions/defold-1.13.0/font.d.ts +81 -0
- package/generated/versions/defold-1.13.0/go.d.ts +1054 -0
- package/generated/versions/defold-1.13.0/graphics.d.ts +321 -0
- package/generated/versions/defold-1.13.0/gui.d.ts +2370 -0
- package/generated/versions/defold-1.13.0/html5.d.ts +53 -0
- package/generated/versions/defold-1.13.0/http.d.ts +84 -0
- package/generated/versions/defold-1.13.0/iac.d.ts +18 -0
- package/generated/versions/defold-1.13.0/iap.d.ts +60 -0
- package/generated/versions/defold-1.13.0/image.d.ts +139 -0
- package/generated/versions/defold-1.13.0/index.d.ts +48 -0
- package/generated/versions/defold-1.13.0/json.d.ts +76 -0
- package/generated/versions/defold-1.13.0/kinds/editor-script.d.ts +13 -0
- package/generated/versions/defold-1.13.0/label.d.ts +94 -0
- package/generated/versions/defold-1.13.0/liveupdate.d.ts +140 -0
- package/generated/versions/defold-1.13.0/material.d.ts +444 -0
- package/generated/versions/defold-1.13.0/model.d.ts +246 -0
- package/generated/versions/defold-1.13.0/msg.d.ts +10 -0
- package/generated/versions/defold-1.13.0/particlefx.d.ts +166 -0
- package/generated/versions/defold-1.13.0/physics.d.ts +548 -0
- package/generated/versions/defold-1.13.0/profiler.d.ts +233 -0
- package/generated/versions/defold-1.13.0/push.d.ts +66 -0
- package/generated/versions/defold-1.13.0/render.d.ts +1185 -0
- package/generated/versions/defold-1.13.0/resource.d.ts +1530 -0
- package/generated/versions/defold-1.13.0/socket.d.ts +795 -0
- package/generated/versions/defold-1.13.0/sound.d.ts +291 -0
- package/generated/versions/defold-1.13.0/sprite.d.ts +157 -0
- package/generated/versions/defold-1.13.0/sys.d.ts +695 -0
- package/generated/versions/defold-1.13.0/tilemap.d.ts +195 -0
- package/generated/versions/defold-1.13.0/timer.d.ts +114 -0
- package/generated/versions/defold-1.13.0/types.d.ts +61 -0
- package/generated/versions/defold-1.13.0/vmath.d.ts +806 -0
- package/generated/versions/defold-1.13.0/webview.d.ts +68 -0
- package/generated/versions/defold-1.13.0/window.d.ts +198 -0
- package/generated/versions/defold-1.13.0/zlib.d.ts +40 -0
- package/index.d.ts +4 -81
- package/package.json +11 -3
- package/scripts/import-defold-release.ts +28 -1
- package/scripts/sync-api-docs.ts +4 -3
- package/src/api-availability.ts +0 -0
- package/src/emit-dts.ts +6 -0
- package/src/example-store.ts +5 -0
- package/src/index.ts +3 -0
- package/scripts/lua-types-signature-index.ts +0 -151
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/** @noSelfInFile */
|
|
2
|
+
import type { Hash, Opaque } from "../../../src/core-types";
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
/**
|
|
6
|
+
* Functions for manipulating buffers and streams
|
|
7
|
+
*/
|
|
8
|
+
namespace buffer {
|
|
9
|
+
/**
|
|
10
|
+
* Float, single precision, 4 bytes
|
|
11
|
+
*/
|
|
12
|
+
const VALUE_TYPE_FLOAT32: number & { readonly __brand: "buffer.VALUE_TYPE_FLOAT32" };
|
|
13
|
+
/**
|
|
14
|
+
* Signed integer, 2 bytes
|
|
15
|
+
*/
|
|
16
|
+
const VALUE_TYPE_INT16: number & { readonly __brand: "buffer.VALUE_TYPE_INT16" };
|
|
17
|
+
/**
|
|
18
|
+
* Signed integer, 4 bytes
|
|
19
|
+
*/
|
|
20
|
+
const VALUE_TYPE_INT32: number & { readonly __brand: "buffer.VALUE_TYPE_INT32" };
|
|
21
|
+
/**
|
|
22
|
+
* Signed integer, 8 bytes
|
|
23
|
+
*/
|
|
24
|
+
const VALUE_TYPE_INT64: number & { readonly __brand: "buffer.VALUE_TYPE_INT64" };
|
|
25
|
+
/**
|
|
26
|
+
* Signed integer, 1 byte
|
|
27
|
+
*/
|
|
28
|
+
const VALUE_TYPE_INT8: number & { readonly __brand: "buffer.VALUE_TYPE_INT8" };
|
|
29
|
+
/**
|
|
30
|
+
* Unsigned integer, 2 bytes
|
|
31
|
+
*/
|
|
32
|
+
const VALUE_TYPE_UINT16: number & { readonly __brand: "buffer.VALUE_TYPE_UINT16" };
|
|
33
|
+
/**
|
|
34
|
+
* Unsigned integer, 4 bytes
|
|
35
|
+
*/
|
|
36
|
+
const VALUE_TYPE_UINT32: number & { readonly __brand: "buffer.VALUE_TYPE_UINT32" };
|
|
37
|
+
/**
|
|
38
|
+
* Unsigned integer, 8 bytes
|
|
39
|
+
*/
|
|
40
|
+
const VALUE_TYPE_UINT64: number & { readonly __brand: "buffer.VALUE_TYPE_UINT64" };
|
|
41
|
+
/**
|
|
42
|
+
* Unsigned integer, 1 byte
|
|
43
|
+
*/
|
|
44
|
+
const VALUE_TYPE_UINT8: number & { readonly __brand: "buffer.VALUE_TYPE_UINT8" };
|
|
45
|
+
/**
|
|
46
|
+
* Copy all data streams from one buffer to another, element wise.
|
|
47
|
+
* Each of the source streams must have a matching stream in the
|
|
48
|
+
* destination buffer. The streams must match in both type and size.
|
|
49
|
+
* The source and destination buffer can be the same.
|
|
50
|
+
*
|
|
51
|
+
* @param dst - the destination buffer
|
|
52
|
+
* @param dstoffset - the offset to start copying data to
|
|
53
|
+
* @param src - the source data buffer
|
|
54
|
+
* @param srcoffset - the offset to start copying data from
|
|
55
|
+
* @param count - the number of elements to copy
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* // How to copy elements (e.g. vertices) from one buffer to another
|
|
59
|
+
* // copy entire buffer
|
|
60
|
+
* buffer.copy_buffer(dstbuffer, 0, srcbuffer, 0, srcbuffer.length);
|
|
61
|
+
*
|
|
62
|
+
* // copy last 10 elements to the front of another buffer
|
|
63
|
+
* buffer.copy_buffer(dstbuffer, 0, srcbuffer, srcbuffer.length - 10, 10);
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
function copy_buffer(dst: Opaque<"buffer">, dstoffset: number, src: Opaque<"buffer">, srcoffset: number, count: number): void;
|
|
67
|
+
/**
|
|
68
|
+
* Copy a specified amount of data from one stream to another.
|
|
69
|
+
* The value type and size must match between source and destination streams.
|
|
70
|
+
* The source and destination streams can be the same.
|
|
71
|
+
*
|
|
72
|
+
* @param dst - the destination stream
|
|
73
|
+
* @param dstoffset - the offset to start copying data to (measured in value type)
|
|
74
|
+
* @param src - the source data stream
|
|
75
|
+
* @param srcoffset - the offset to start copying data from (measured in value type)
|
|
76
|
+
* @param count - the number of values to copy (measured in value type)
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* // How to update a texture of a sprite:
|
|
80
|
+
* // copy entire stream
|
|
81
|
+
* const srcstream = buffer.get_stream(srcbuffer, hash("xyz"));
|
|
82
|
+
* const dststream = buffer.get_stream(dstbuffer, hash("xyz"));
|
|
83
|
+
* buffer.copy_stream(dststream, 0, srcstream, 0, srcstream.length);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
function copy_stream(dst: Opaque<"bufferstream"> & { [index: number]: number }, dstoffset: number, src: Opaque<"bufferstream"> & { [index: number]: number }, srcoffset: number, count: number): void;
|
|
87
|
+
/**
|
|
88
|
+
* Create a new data buffer containing a specified set of streams. A data buffer
|
|
89
|
+
* can contain one or more streams with typed data. This is useful for managing
|
|
90
|
+
* compound data, for instance a vertex buffer could contain separate streams for
|
|
91
|
+
* vertex position, color, normal etc.
|
|
92
|
+
*
|
|
93
|
+
* @param element_count - The number of elements the buffer should hold
|
|
94
|
+
* @param declaration - A table where each entry (table) describes a stream
|
|
95
|
+
*
|
|
96
|
+
* - hash | string `name`: The name of the stream
|
|
97
|
+
*
|
|
98
|
+
* - constant `type`: The data type of the stream
|
|
99
|
+
*
|
|
100
|
+
* - number `count`: The number of values each element should hold
|
|
101
|
+
* @returns the new buffer
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* // How to create and initialize a buffer
|
|
105
|
+
* export default defineScript({
|
|
106
|
+
* init(self) {
|
|
107
|
+
* const size = 128;
|
|
108
|
+
* self.image = buffer.create(size * size, [{ name: hash("rgb"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);
|
|
109
|
+
* self.imagestream = buffer.get_stream(self.image, hash("rgb"));
|
|
110
|
+
*
|
|
111
|
+
* for (let y = 0; y < self.height; y++) {
|
|
112
|
+
* for (let x = 0; x < self.width; x++) {
|
|
113
|
+
* const index = y * self.width * 3 + x * 3;
|
|
114
|
+
* self.imagestream[index + 0] = self.r;
|
|
115
|
+
* self.imagestream[index + 1] = self.g;
|
|
116
|
+
* self.imagestream[index + 2] = self.b;
|
|
117
|
+
* }
|
|
118
|
+
* }
|
|
119
|
+
* },
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
function create(element_count: number, declaration: { name?: Hash | string; type?: Opaque<"constant">; count?: number }): Opaque<"buffer">;
|
|
124
|
+
/**
|
|
125
|
+
* Get a copy of all the bytes from a specified stream as a Lua string.
|
|
126
|
+
*
|
|
127
|
+
* @param buffer - the source buffer
|
|
128
|
+
* @param stream_name - the name of the stream
|
|
129
|
+
* @returns the buffer data as a Lua string
|
|
130
|
+
*/
|
|
131
|
+
function get_bytes(buffer: Opaque<"buffer">, stream_name: Hash): string;
|
|
132
|
+
/**
|
|
133
|
+
* Get a named metadata entry from a buffer along with its type.
|
|
134
|
+
*
|
|
135
|
+
* @param buf - the buffer to get the metadata from
|
|
136
|
+
* @param metadata_name - name of the metadata entry
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* // How to get a metadata entry from a buffer
|
|
140
|
+
* // retrieve a metadata entry named "somefloats" and its numeric type
|
|
141
|
+
* const [values, type] = buffer.get_metadata(buf, hash("somefloats"));
|
|
142
|
+
* if (values) print(`${values.length} values in 'somefloats'`);
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
function get_metadata(buf: Opaque<"buffer">, metadata_name: Hash | string): LuaMultiReturn<[number[] | undefined, Opaque<"constant"> | undefined]>;
|
|
146
|
+
/**
|
|
147
|
+
* Get a specified stream from a buffer.
|
|
148
|
+
*
|
|
149
|
+
* @param buffer - the buffer to get the stream from
|
|
150
|
+
* @param stream_name - the stream name
|
|
151
|
+
* @returns the data stream
|
|
152
|
+
*/
|
|
153
|
+
function get_stream(buffer: Opaque<"buffer">, stream_name: Hash | string): Opaque<"bufferstream"> & { [index: number]: number };
|
|
154
|
+
/**
|
|
155
|
+
* Creates or updates a metadata array entry on a buffer.
|
|
156
|
+
* The value type and count given when updating the entry should match those used when first creating it.
|
|
157
|
+
*
|
|
158
|
+
* @param buf - the buffer to set the metadata on
|
|
159
|
+
* @param metadata_name - name of the metadata entry
|
|
160
|
+
* @param values - actual metadata, an array of numeric values
|
|
161
|
+
* @param value_type - type of values when stored
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* // How to set a metadata entry on a buffer
|
|
165
|
+
* // create a new metadata entry with three floats
|
|
166
|
+
* buffer.set_metadata(buf, hash("somefloats"), [1.5, 3.2, 7.9], buffer.VALUE_TYPE_FLOAT32);
|
|
167
|
+
* // ...
|
|
168
|
+
* // update to a new set of values
|
|
169
|
+
* buffer.set_metadata(buf, hash("somefloats"), [-2.5, 10.0, 32.2], buffer.VALUE_TYPE_FLOAT32);
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
function set_metadata(buf: Opaque<"buffer">, metadata_name: Hash | string, values: number[], value_type: Opaque<"constant">): void;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export {};
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/** @noSelfInFile */
|
|
2
|
+
import type { Matrix4, Url, Vector3 } from "../../../src/core-types";
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
/**
|
|
6
|
+
* Messages to control camera components and camera focus.
|
|
7
|
+
*/
|
|
8
|
+
namespace camera {
|
|
9
|
+
/**
|
|
10
|
+
* Computes zoom so the original display area covers the entire window while preserving aspect ratio.
|
|
11
|
+
* Equivalent to using max(window_width/width, window_height/height).
|
|
12
|
+
* The result is multiplied by the user-controlled orthographic zoom.
|
|
13
|
+
*/
|
|
14
|
+
const ORTHO_MODE_AUTO_COVER: number & { readonly __brand: "camera.ORTHO_MODE_AUTO_COVER" };
|
|
15
|
+
/**
|
|
16
|
+
* Computes zoom so the original display area (game.project width/height) fits inside the window
|
|
17
|
+
* while preserving aspect ratio. Equivalent to using min(window_width/width, window_height/height).
|
|
18
|
+
* The result is multiplied by the user-controlled orthographic zoom.
|
|
19
|
+
*/
|
|
20
|
+
const ORTHO_MODE_AUTO_FIT: number & { readonly __brand: "camera.ORTHO_MODE_AUTO_FIT" };
|
|
21
|
+
/**
|
|
22
|
+
* Uses the manually set orthographic zoom value (camera.set_orthographic_zoom).
|
|
23
|
+
*/
|
|
24
|
+
const ORTHO_MODE_FIXED: number & { readonly __brand: "camera.ORTHO_MODE_FIXED" };
|
|
25
|
+
/**
|
|
26
|
+
* Gets the effective aspect ratio of the camera. If auto aspect ratio is enabled,
|
|
27
|
+
* returns the aspect ratio calculated from the current render target dimensions.
|
|
28
|
+
* Otherwise returns the manually set aspect ratio.
|
|
29
|
+
*
|
|
30
|
+
* @param camera - camera id
|
|
31
|
+
* @returns the effective aspect ratio.
|
|
32
|
+
*/
|
|
33
|
+
function get_aspect_ratio(camera?: Url | number): number;
|
|
34
|
+
/**
|
|
35
|
+
* Returns whether auto aspect ratio is enabled. When enabled, the camera automatically
|
|
36
|
+
* calculates aspect ratio from render target dimensions. When disabled, uses the
|
|
37
|
+
* manually set aspect ratio value.
|
|
38
|
+
*
|
|
39
|
+
* @param camera - camera id
|
|
40
|
+
* @returns true if auto aspect ratio is enabled
|
|
41
|
+
*/
|
|
42
|
+
function get_auto_aspect_ratio(camera?: Url | number): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* This function returns a table with all the camera URLs that have been
|
|
45
|
+
* registered in the render context.
|
|
46
|
+
*
|
|
47
|
+
* @returns a table with all camera URLs
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* for (const camera_id of camera.get_cameras()) {
|
|
51
|
+
* render.set_camera(camera_id);
|
|
52
|
+
* render.draw(predicate);
|
|
53
|
+
* render.set_camera();
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
function get_cameras(): Url[];
|
|
58
|
+
/**
|
|
59
|
+
* get enabled
|
|
60
|
+
*
|
|
61
|
+
* @param camera - camera id
|
|
62
|
+
* @returns true if the camera is enabled
|
|
63
|
+
*/
|
|
64
|
+
function get_enabled(camera?: Url | number): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* get far z
|
|
67
|
+
*
|
|
68
|
+
* @param camera - camera id
|
|
69
|
+
* @returns the far z.
|
|
70
|
+
*/
|
|
71
|
+
function get_far_z(camera?: Url | number): number;
|
|
72
|
+
/**
|
|
73
|
+
* get field of view
|
|
74
|
+
*
|
|
75
|
+
* @param camera - camera id
|
|
76
|
+
* @returns the field of view.
|
|
77
|
+
*/
|
|
78
|
+
function get_fov(camera?: Url | number): number;
|
|
79
|
+
/**
|
|
80
|
+
* get near z
|
|
81
|
+
*
|
|
82
|
+
* @param camera - camera id
|
|
83
|
+
* @returns the near z.
|
|
84
|
+
*/
|
|
85
|
+
function get_near_z(camera?: Url | number): number;
|
|
86
|
+
/**
|
|
87
|
+
* Gets the orthographic zoom calculated from the current window and project dimensions
|
|
88
|
+
* in auto-fit and auto-cover modes. Returns 1.0 in fixed mode.
|
|
89
|
+
*
|
|
90
|
+
* @param camera - camera id
|
|
91
|
+
* @returns the calculated orthographic auto zoom.
|
|
92
|
+
*/
|
|
93
|
+
function get_orthographic_auto_zoom(camera?: Url | number): number;
|
|
94
|
+
/**
|
|
95
|
+
* get orthographic zoom mode
|
|
96
|
+
*
|
|
97
|
+
* @param camera - camera id
|
|
98
|
+
* @returns one of camera.ORTHO_MODE_FIXED, camera.ORTHO_MODE_AUTO_FIT or
|
|
99
|
+
* camera.ORTHO_MODE_AUTO_COVER
|
|
100
|
+
*/
|
|
101
|
+
function get_orthographic_mode(camera?: Url | number): number;
|
|
102
|
+
/**
|
|
103
|
+
* Gets the positive user-controlled orthographic zoom multiplier. In auto-fit and auto-cover
|
|
104
|
+
* modes, this value is multiplied with camera.get_orthographic_auto_zoom(camera).
|
|
105
|
+
*
|
|
106
|
+
* @param camera - camera id
|
|
107
|
+
* @returns the positive zoom multiplier when the camera uses orthographic projection.
|
|
108
|
+
*/
|
|
109
|
+
function get_orthographic_zoom(camera?: Url | number): number;
|
|
110
|
+
/**
|
|
111
|
+
* get projection matrix
|
|
112
|
+
*
|
|
113
|
+
* @param camera - camera id
|
|
114
|
+
* @returns the projection matrix.
|
|
115
|
+
*/
|
|
116
|
+
function get_projection(camera?: Url | number): Matrix4;
|
|
117
|
+
/**
|
|
118
|
+
* get view matrix
|
|
119
|
+
*
|
|
120
|
+
* @param camera - camera id
|
|
121
|
+
* @returns the view matrix.
|
|
122
|
+
*/
|
|
123
|
+
function get_view(camera?: Url | number): Matrix4;
|
|
124
|
+
/**
|
|
125
|
+
* Converts a screen-space 2D point with view depth to a 3D world point.
|
|
126
|
+
* z is the view depth in world units measured from the camera plane along the camera forward axis.
|
|
127
|
+
* If a camera isn't specified, the last enabled camera is used.
|
|
128
|
+
*
|
|
129
|
+
* @param pos - Screen-space position (x, y) with z as view depth in world units
|
|
130
|
+
* @param camera - optional camera id
|
|
131
|
+
* @returns the world coordinate
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* // Place objects at the touch point with a random Z position, keeping them
|
|
135
|
+
* // within the visible view zone.
|
|
136
|
+
* export default defineScript({
|
|
137
|
+
* on_input(self, action_id, action) {
|
|
138
|
+
* if (action_id === hash("touch")) {
|
|
139
|
+
* if (action.pressed) {
|
|
140
|
+
* const perspective_camera = msg.url("#perspective_camera");
|
|
141
|
+
* const random_z = math.random(
|
|
142
|
+
* camera.get_near_z(perspective_camera) + 0.01,
|
|
143
|
+
* camera.get_far_z(perspective_camera) - 0.01,
|
|
144
|
+
* );
|
|
145
|
+
* const world_position = camera.screen_to_world(
|
|
146
|
+
* vmath.vector3(action.screen_x, action.screen_y, random_z),
|
|
147
|
+
* perspective_camera,
|
|
148
|
+
* );
|
|
149
|
+
* go.set_position(world_position, "/go1");
|
|
150
|
+
* }
|
|
151
|
+
* }
|
|
152
|
+
* },
|
|
153
|
+
* });
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
function screen_to_world(pos: Vector3, camera?: Url | number): Vector3;
|
|
157
|
+
/**
|
|
158
|
+
* Converts 2D screen coordinates (x,y) to the 3D world-space point on the camera's near plane for that pixel.
|
|
159
|
+
* If a camera isn't specified, the last enabled camera is used.
|
|
160
|
+
*
|
|
161
|
+
* @param x - X coordinate on screen.
|
|
162
|
+
* @param y - Y coordinate on screen.
|
|
163
|
+
* @param camera - optional camera id
|
|
164
|
+
* @returns the world coordinate on the camera near plane
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* // Place objects at the touch point.
|
|
168
|
+
* export default defineScript({
|
|
169
|
+
* on_input(self, action_id, action) {
|
|
170
|
+
* if (action_id === hash("touch")) {
|
|
171
|
+
* if (action.pressed) {
|
|
172
|
+
* const world_position = camera.screen_xy_to_world(action.screen_x, action.screen_y);
|
|
173
|
+
* go.set_position(world_position, "/go1");
|
|
174
|
+
* }
|
|
175
|
+
* }
|
|
176
|
+
* },
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
function screen_xy_to_world(x: number, y: number, camera?: Url | number): Vector3;
|
|
181
|
+
/**
|
|
182
|
+
* Sets the manual aspect ratio for the camera. This value is only used when
|
|
183
|
+
* auto aspect ratio is disabled. To disable auto aspect ratio and use this
|
|
184
|
+
* manual value, call camera.set_auto_aspect_ratio(camera, false).
|
|
185
|
+
*
|
|
186
|
+
* @param camera - camera id
|
|
187
|
+
* @param aspect_ratio - the manual aspect ratio value.
|
|
188
|
+
*/
|
|
189
|
+
function set_aspect_ratio(camera: Url | number | undefined, aspect_ratio: number): void;
|
|
190
|
+
/**
|
|
191
|
+
* Enables or disables automatic aspect ratio calculation. When enabled (true),
|
|
192
|
+
* the camera automatically calculates aspect ratio from render target dimensions.
|
|
193
|
+
* When disabled (false), uses the manually set aspect ratio value.
|
|
194
|
+
*
|
|
195
|
+
* @param camera - camera id
|
|
196
|
+
* @param auto_aspect_ratio - true to enable auto aspect ratio
|
|
197
|
+
*/
|
|
198
|
+
function set_auto_aspect_ratio(camera: Url | number | undefined, auto_aspect_ratio: boolean): void;
|
|
199
|
+
/**
|
|
200
|
+
* set far z
|
|
201
|
+
*
|
|
202
|
+
* @param camera - camera id
|
|
203
|
+
* @param far_z - the far z.
|
|
204
|
+
*/
|
|
205
|
+
function set_far_z(camera: Url | number | undefined, far_z: number): void;
|
|
206
|
+
/**
|
|
207
|
+
* set field of view
|
|
208
|
+
*
|
|
209
|
+
* @param camera - camera id
|
|
210
|
+
* @param fov - the field of view.
|
|
211
|
+
*/
|
|
212
|
+
function set_fov(camera: Url | number | undefined, fov: number): void;
|
|
213
|
+
/**
|
|
214
|
+
* set near z
|
|
215
|
+
*
|
|
216
|
+
* @param camera - camera id
|
|
217
|
+
* @param near_z - the near z.
|
|
218
|
+
*/
|
|
219
|
+
function set_near_z(camera: Url | number | undefined, near_z: number): void;
|
|
220
|
+
/**
|
|
221
|
+
* set orthographic zoom mode
|
|
222
|
+
*
|
|
223
|
+
* @param camera - camera id
|
|
224
|
+
* @param mode - camera.ORTHO_MODE_FIXED, camera.ORTHO_MODE_AUTO_FIT or camera.ORTHO_MODE_AUTO_COVER
|
|
225
|
+
*/
|
|
226
|
+
function set_orthographic_mode(camera: Url | number | undefined, mode: number): void;
|
|
227
|
+
/**
|
|
228
|
+
* Sets the positive user-controlled orthographic zoom multiplier. In auto-fit and auto-cover
|
|
229
|
+
* modes, this value is multiplied with camera.get_orthographic_auto_zoom(camera).
|
|
230
|
+
*
|
|
231
|
+
* @param camera - camera id
|
|
232
|
+
* @param orthographic_zoom - the positive zoom multiplier when the camera uses orthographic projection.
|
|
233
|
+
*/
|
|
234
|
+
function set_orthographic_zoom(camera: Url | number | undefined, orthographic_zoom: number): void;
|
|
235
|
+
/**
|
|
236
|
+
* Converts a 3D world position to screen-space coordinates with view depth.
|
|
237
|
+
* Returns a vector3 where x and y are in screen pixels and z is the view depth in world units
|
|
238
|
+
* measured from the camera plane along the camera forward axis. The returned z can be used with
|
|
239
|
+
* camera.screen_to_world to reconstruct the world position on the same pixel ray.
|
|
240
|
+
* If a camera isn't specified, the last enabled camera is used.
|
|
241
|
+
*
|
|
242
|
+
* @param world_pos - World-space position
|
|
243
|
+
* @param camera - optional camera id
|
|
244
|
+
* @returns Screen position (x,y in pixels, z is view depth)
|
|
245
|
+
* @example
|
|
246
|
+
* ```ts
|
|
247
|
+
* // Convert a game object position into a screen position.
|
|
248
|
+
* go.update_world_transform("/go1");
|
|
249
|
+
* const world_pos = go.get_world_position("/go1");
|
|
250
|
+
* const screen_pos = camera.world_to_screen(world_pos);
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
function world_to_screen(world_pos: Vector3, camera?: Url | number): Vector3;
|
|
254
|
+
interface properties {
|
|
255
|
+
/**
|
|
256
|
+
* The ratio between the frustum width and height. Used when calculating the
|
|
257
|
+
* projection of a perspective camera.
|
|
258
|
+
* The type of the property is number.
|
|
259
|
+
*/
|
|
260
|
+
aspect_ratio: unknown;
|
|
261
|
+
/**
|
|
262
|
+
* Camera frustum far plane.
|
|
263
|
+
* The type of the property is float.
|
|
264
|
+
*/
|
|
265
|
+
far_z: unknown;
|
|
266
|
+
/**
|
|
267
|
+
* Vertical field of view of the camera.
|
|
268
|
+
* The type of the property is float.
|
|
269
|
+
*/
|
|
270
|
+
fov: unknown;
|
|
271
|
+
/**
|
|
272
|
+
* Camera frustum near plane.
|
|
273
|
+
* The type of the property is float.
|
|
274
|
+
*/
|
|
275
|
+
near_z: unknown;
|
|
276
|
+
/**
|
|
277
|
+
* READ ONLY The zoom calculated from the current window and project dimensions
|
|
278
|
+
* in auto fit and auto cover modes. The value is 1.0 in fixed mode.
|
|
279
|
+
* The type of the property is float.
|
|
280
|
+
*/
|
|
281
|
+
orthographic_auto_zoom: unknown;
|
|
282
|
+
/**
|
|
283
|
+
* Positive zoom multiplier when using an orthographic projection. In auto fit and auto cover
|
|
284
|
+
* modes, this value is multiplied with the calculated orthographic_auto_zoom value.
|
|
285
|
+
* The type of the property is float.
|
|
286
|
+
*/
|
|
287
|
+
orthographic_zoom: unknown;
|
|
288
|
+
/**
|
|
289
|
+
* READ ONLY The calculated projection matrix of the camera.
|
|
290
|
+
* The type of the property is matrix4.
|
|
291
|
+
*/
|
|
292
|
+
projection: unknown;
|
|
293
|
+
/**
|
|
294
|
+
* READ ONLY The calculated view matrix of the camera.
|
|
295
|
+
* The type of the property is matrix4.
|
|
296
|
+
*/
|
|
297
|
+
view: unknown;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export {};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/** @noSelfInFile */
|
|
2
|
+
import type { Hash, Opaque, Quaternion, Url, Vector3 } from "../../../src/core-types";
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
/**
|
|
6
|
+
* Functions for controlling collection factory components which are
|
|
7
|
+
* used to dynamically spawn collections into the runtime.
|
|
8
|
+
*/
|
|
9
|
+
namespace collectionfactory {
|
|
10
|
+
/**
|
|
11
|
+
* loaded
|
|
12
|
+
*/
|
|
13
|
+
const STATUS_LOADED: number & { readonly __brand: "collectionfactory.STATUS_LOADED" };
|
|
14
|
+
/**
|
|
15
|
+
* loading
|
|
16
|
+
*/
|
|
17
|
+
const STATUS_LOADING: number & { readonly __brand: "collectionfactory.STATUS_LOADING" };
|
|
18
|
+
/**
|
|
19
|
+
* unloaded
|
|
20
|
+
*/
|
|
21
|
+
const STATUS_UNLOADED: number & { readonly __brand: "collectionfactory.STATUS_UNLOADED" };
|
|
22
|
+
/**
|
|
23
|
+
* The URL identifies the collectionfactory component that should do the spawning.
|
|
24
|
+
* Spawning is instant, but spawned game objects get their first update calls the following frame. The supplied parameters for position, rotation and scale
|
|
25
|
+
* will be applied to the whole collection when spawned.
|
|
26
|
+
* Script properties in the created game objects can be overridden through
|
|
27
|
+
* a properties-parameter table. The table should contain game object ids
|
|
28
|
+
* (hash) as keys and property tables as values to be used when initiating each
|
|
29
|
+
* spawned game object.
|
|
30
|
+
* See go.property for more information on script properties.
|
|
31
|
+
* The function returns a table that contains a key for each game object
|
|
32
|
+
* id (hash), as addressed if the collection file was top level, and the
|
|
33
|
+
* corresponding spawned instance id (hash) as value with a unique path
|
|
34
|
+
* prefix added to each instance.
|
|
35
|
+
* Calling collectionfactory.create create on a collection factory that is marked as dynamic without having loaded resources
|
|
36
|
+
* using collectionfactory.load will synchronously load and create resources which may affect application performance.
|
|
37
|
+
*
|
|
38
|
+
* @param url - the collection factory component to be used
|
|
39
|
+
* @param position - position to assign to the newly spawned collection
|
|
40
|
+
* @param rotation - rotation to assign to the newly spawned collection
|
|
41
|
+
* @param properties - table of script properties to propagate to any new game object instances
|
|
42
|
+
* @param scale - uniform scaling to apply to the newly spawned collection (must be greater than 0).
|
|
43
|
+
* @returns a table mapping the id:s from the collection to the new instance id:s
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* // How to spawn a collection of game objects:
|
|
47
|
+
* export default defineScript({
|
|
48
|
+
* init(self) {
|
|
49
|
+
* // Spawn a small group of enemies.
|
|
50
|
+
* const pos = vmath.vector3(100, 12.5, 0);
|
|
51
|
+
* const rot = vmath.quat_rotation_z(Math.PI / 2);
|
|
52
|
+
* const scale = 0.5;
|
|
53
|
+
* const props = {
|
|
54
|
+
* [hash("/enemy_leader")]: { health: 1000.0 },
|
|
55
|
+
* [hash("/enemy_1")]: { health: 200.0 },
|
|
56
|
+
* [hash("/enemy_2")]: { health: 400.0, color: hash("green") },
|
|
57
|
+
* };
|
|
58
|
+
*
|
|
59
|
+
* self.enemy_ids = collectionfactory.create("#enemyfactory", pos, rot, props, scale);
|
|
60
|
+
* // enemy_ids now map to the spawned instance ids:
|
|
61
|
+
* //
|
|
62
|
+
* // pprint(self.enemy_ids)
|
|
63
|
+
* //
|
|
64
|
+
* // DEBUG:SCRIPT:
|
|
65
|
+
* // {
|
|
66
|
+
* // hash: [/enemy_leader] = hash: [/collection0/enemy_leader],
|
|
67
|
+
* // hash: [/enemy_1] = hash: [/collection0/enemy_1],
|
|
68
|
+
* // hash: [/enemy_2] = hash: [/collection0/enemy_2]
|
|
69
|
+
* // }
|
|
70
|
+
*
|
|
71
|
+
* // Send "attack" message to the leader. First look up its instance id.
|
|
72
|
+
* const leader_id = self.enemy_ids[hash("/enemy_leader")];
|
|
73
|
+
* msg.post(leader_id, "attack");
|
|
74
|
+
* },
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* // How to delete a spawned collection:
|
|
78
|
+
* go.delete(self.enemy_ids);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
function create(url: string | Hash | Url, position?: Vector3, rotation?: Quaternion, properties?: Record<string | number, unknown>, scale?: number | Vector3): LuaMap<Hash, Hash>;
|
|
82
|
+
/**
|
|
83
|
+
* This returns status of the collection factory.
|
|
84
|
+
* Calling this function when the factory is not marked as dynamic loading always returns COMP_COLLECTION_FACTORY_STATUS_LOADED.
|
|
85
|
+
*
|
|
86
|
+
* @param url - the collection factory component to get status from
|
|
87
|
+
* @returns status of the collection factory component
|
|
88
|
+
*
|
|
89
|
+
* - `collectionfactory.STATUS_UNLOADED`
|
|
90
|
+
*
|
|
91
|
+
* - `collectionfactory.STATUS_LOADING`
|
|
92
|
+
*
|
|
93
|
+
* - `collectionfactory.STATUS_LOADED`
|
|
94
|
+
*/
|
|
95
|
+
function get_status(url?: string | Hash | Url): Opaque<"constant">;
|
|
96
|
+
/**
|
|
97
|
+
* Resources loaded are referenced by the collection factory component until the existing (parent) collection is destroyed or collectionfactory.unload is called.
|
|
98
|
+
* Calling this function when the factory is not marked as dynamic loading does nothing.
|
|
99
|
+
*
|
|
100
|
+
* @param url - the collection factory component to load
|
|
101
|
+
* @param complete_function - function to call when resources are loaded.
|
|
102
|
+
*
|
|
103
|
+
* `self`
|
|
104
|
+
* object The current object.
|
|
105
|
+
* `url`
|
|
106
|
+
* url url of the collection factory component
|
|
107
|
+
* `result`
|
|
108
|
+
* boolean True if resource were loaded successfully
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* // How to load resources of a collection factory prototype.
|
|
112
|
+
* collectionfactory.load("#factory", (self, url, result) => {});
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
function load(url?: string | Hash | Url, complete_function?: (self: unknown, url: unknown, result: unknown) => void): void;
|
|
116
|
+
/**
|
|
117
|
+
* Changes the prototype for the collection factory.
|
|
118
|
+
* Setting the prototype to "nil" will revert back to the original prototype.
|
|
119
|
+
*
|
|
120
|
+
* @param url - the collection factory component
|
|
121
|
+
* @param prototype - the path to the new prototype, or `nil`
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* // How to unload the previous prototype's resources, and then spawn a new collection:
|
|
125
|
+
* collectionfactory.unload("#factory"); // unload the previous resources
|
|
126
|
+
* collectionfactory.set_prototype("#factory", "/main/levels/level1.collectionc");
|
|
127
|
+
* const ids = collectionfactory.create("#factory", go.get_world_position(), vmath.quat());
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
function set_prototype(url?: string | Hash | Url, prototype?: string): void;
|
|
131
|
+
/**
|
|
132
|
+
* This decreases the reference count for each resource loaded with collectionfactory.load. If reference is zero, the resource is destroyed.
|
|
133
|
+
* Calling this function when the factory is not marked as dynamic loading does nothing.
|
|
134
|
+
*
|
|
135
|
+
* @param url - the collection factory component to unload
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* // How to unload resources of a collection factory prototype loaded with collectionfactory.load:
|
|
139
|
+
* collectionfactory.unload("#factory");
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
function unload(url?: string | Hash | Url): void;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export {};
|