@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.
- package/generated/b2d.d.ts +11 -0
- package/generated/buffer.d.ts +142 -0
- package/generated/collectionfactory.d.ts +118 -0
- package/generated/collectionproxy.d.ts +52 -0
- package/generated/crash.d.ts +109 -0
- package/generated/factory.d.ts +94 -0
- package/generated/go.d.ts +880 -0
- package/generated/graphics.d.ts +108 -0
- package/generated/gui.d.ts +1892 -0
- package/generated/http.d.ts +50 -0
- package/generated/iac.d.ts +7 -0
- package/generated/iap.d.ts +41 -0
- package/generated/image.d.ts +95 -0
- package/generated/json.d.ts +59 -0
- package/generated/label.d.ts +64 -0
- package/generated/liveupdate.d.ts +96 -0
- package/generated/model.d.ts +156 -0
- package/generated/msg.d.ts +56 -0
- package/generated/particlefx.d.ts +122 -0
- package/generated/physics.d.ts +451 -0
- package/generated/profiler.d.ts +188 -0
- package/generated/push.d.ts +48 -0
- package/generated/render.d.ts +944 -0
- package/generated/resource.d.ts +1227 -0
- package/generated/socket.d.ts +125 -0
- package/generated/sound.d.ts +246 -0
- package/generated/sprite.d.ts +111 -0
- package/generated/sys.d.ts +513 -0
- package/generated/tilemap.d.ts +151 -0
- package/generated/timer.d.ts +93 -0
- package/generated/vmath.d.ts +914 -0
- package/generated/webview.d.ts +50 -0
- package/generated/window.d.ts +141 -0
- package/generated/zlib.d.ts +28 -0
- package/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/api-doc.ts +10 -1
- package/src/doc-comment.ts +119 -0
- package/src/emit-dts.ts +63 -2
- package/src/engine-globals.d.ts +12 -0
- package/src/index.ts +1 -0
- package/src/lifecycle.ts +45 -16
package/generated/go.d.ts
CHANGED
|
@@ -3,91 +3,971 @@ import type { Hash, Matrix4, Opaque, Quaternion, Url, Vector, Vector3, Vector4 }
|
|
|
3
3
|
|
|
4
4
|
declare global {
|
|
5
5
|
namespace go {
|
|
6
|
+
/**
|
|
7
|
+
* in-back
|
|
8
|
+
*/
|
|
6
9
|
export const EASING_INBACK: number & { readonly __brand: "go.EASING_INBACK" };
|
|
10
|
+
/**
|
|
11
|
+
* in-bounce
|
|
12
|
+
*/
|
|
7
13
|
export const EASING_INBOUNCE: number & { readonly __brand: "go.EASING_INBOUNCE" };
|
|
14
|
+
/**
|
|
15
|
+
* in-circlic
|
|
16
|
+
*/
|
|
8
17
|
export const EASING_INCIRC: number & { readonly __brand: "go.EASING_INCIRC" };
|
|
18
|
+
/**
|
|
19
|
+
* in-cubic
|
|
20
|
+
*/
|
|
9
21
|
export const EASING_INCUBIC: number & { readonly __brand: "go.EASING_INCUBIC" };
|
|
22
|
+
/**
|
|
23
|
+
* in-elastic
|
|
24
|
+
*/
|
|
10
25
|
export const EASING_INELASTIC: number & { readonly __brand: "go.EASING_INELASTIC" };
|
|
26
|
+
/**
|
|
27
|
+
* in-exponential
|
|
28
|
+
*/
|
|
11
29
|
export const EASING_INEXPO: number & { readonly __brand: "go.EASING_INEXPO" };
|
|
30
|
+
/**
|
|
31
|
+
* in-out-back
|
|
32
|
+
*/
|
|
12
33
|
export const EASING_INOUTBACK: number & { readonly __brand: "go.EASING_INOUTBACK" };
|
|
34
|
+
/**
|
|
35
|
+
* in-out-bounce
|
|
36
|
+
*/
|
|
13
37
|
export const EASING_INOUTBOUNCE: number & { readonly __brand: "go.EASING_INOUTBOUNCE" };
|
|
38
|
+
/**
|
|
39
|
+
* in-out-circlic
|
|
40
|
+
*/
|
|
14
41
|
export const EASING_INOUTCIRC: number & { readonly __brand: "go.EASING_INOUTCIRC" };
|
|
42
|
+
/**
|
|
43
|
+
* in-out-cubic
|
|
44
|
+
*/
|
|
15
45
|
export const EASING_INOUTCUBIC: number & { readonly __brand: "go.EASING_INOUTCUBIC" };
|
|
46
|
+
/**
|
|
47
|
+
* in-out-elastic
|
|
48
|
+
*/
|
|
16
49
|
export const EASING_INOUTELASTIC: number & { readonly __brand: "go.EASING_INOUTELASTIC" };
|
|
50
|
+
/**
|
|
51
|
+
* in-out-exponential
|
|
52
|
+
*/
|
|
17
53
|
export const EASING_INOUTEXPO: number & { readonly __brand: "go.EASING_INOUTEXPO" };
|
|
54
|
+
/**
|
|
55
|
+
* in-out-quadratic
|
|
56
|
+
*/
|
|
18
57
|
export const EASING_INOUTQUAD: number & { readonly __brand: "go.EASING_INOUTQUAD" };
|
|
58
|
+
/**
|
|
59
|
+
* in-out-quartic
|
|
60
|
+
*/
|
|
19
61
|
export const EASING_INOUTQUART: number & { readonly __brand: "go.EASING_INOUTQUART" };
|
|
62
|
+
/**
|
|
63
|
+
* in-out-quintic
|
|
64
|
+
*/
|
|
20
65
|
export const EASING_INOUTQUINT: number & { readonly __brand: "go.EASING_INOUTQUINT" };
|
|
66
|
+
/**
|
|
67
|
+
* in-out-sine
|
|
68
|
+
*/
|
|
21
69
|
export const EASING_INOUTSINE: number & { readonly __brand: "go.EASING_INOUTSINE" };
|
|
70
|
+
/**
|
|
71
|
+
* in-quadratic
|
|
72
|
+
*/
|
|
22
73
|
export const EASING_INQUAD: number & { readonly __brand: "go.EASING_INQUAD" };
|
|
74
|
+
/**
|
|
75
|
+
* in-quartic
|
|
76
|
+
*/
|
|
23
77
|
export const EASING_INQUART: number & { readonly __brand: "go.EASING_INQUART" };
|
|
78
|
+
/**
|
|
79
|
+
* in-quintic
|
|
80
|
+
*/
|
|
24
81
|
export const EASING_INQUINT: number & { readonly __brand: "go.EASING_INQUINT" };
|
|
82
|
+
/**
|
|
83
|
+
* in-sine
|
|
84
|
+
*/
|
|
25
85
|
export const EASING_INSINE: number & { readonly __brand: "go.EASING_INSINE" };
|
|
86
|
+
/**
|
|
87
|
+
* linear interpolation
|
|
88
|
+
*/
|
|
26
89
|
export const EASING_LINEAR: number & { readonly __brand: "go.EASING_LINEAR" };
|
|
90
|
+
/**
|
|
91
|
+
* out-back
|
|
92
|
+
*/
|
|
27
93
|
export const EASING_OUTBACK: number & { readonly __brand: "go.EASING_OUTBACK" };
|
|
94
|
+
/**
|
|
95
|
+
* out-bounce
|
|
96
|
+
*/
|
|
28
97
|
export const EASING_OUTBOUNCE: number & { readonly __brand: "go.EASING_OUTBOUNCE" };
|
|
98
|
+
/**
|
|
99
|
+
* out-circlic
|
|
100
|
+
*/
|
|
29
101
|
export const EASING_OUTCIRC: number & { readonly __brand: "go.EASING_OUTCIRC" };
|
|
102
|
+
/**
|
|
103
|
+
* out-cubic
|
|
104
|
+
*/
|
|
30
105
|
export const EASING_OUTCUBIC: number & { readonly __brand: "go.EASING_OUTCUBIC" };
|
|
106
|
+
/**
|
|
107
|
+
* out-elastic
|
|
108
|
+
*/
|
|
31
109
|
export const EASING_OUTELASTIC: number & { readonly __brand: "go.EASING_OUTELASTIC" };
|
|
110
|
+
/**
|
|
111
|
+
* out-exponential
|
|
112
|
+
*/
|
|
32
113
|
export const EASING_OUTEXPO: number & { readonly __brand: "go.EASING_OUTEXPO" };
|
|
114
|
+
/**
|
|
115
|
+
* out-in-back
|
|
116
|
+
*/
|
|
33
117
|
export const EASING_OUTINBACK: number & { readonly __brand: "go.EASING_OUTINBACK" };
|
|
118
|
+
/**
|
|
119
|
+
* out-in-bounce
|
|
120
|
+
*/
|
|
34
121
|
export const EASING_OUTINBOUNCE: number & { readonly __brand: "go.EASING_OUTINBOUNCE" };
|
|
122
|
+
/**
|
|
123
|
+
* out-in-circlic
|
|
124
|
+
*/
|
|
35
125
|
export const EASING_OUTINCIRC: number & { readonly __brand: "go.EASING_OUTINCIRC" };
|
|
126
|
+
/**
|
|
127
|
+
* out-in-cubic
|
|
128
|
+
*/
|
|
36
129
|
export const EASING_OUTINCUBIC: number & { readonly __brand: "go.EASING_OUTINCUBIC" };
|
|
130
|
+
/**
|
|
131
|
+
* out-in-elastic
|
|
132
|
+
*/
|
|
37
133
|
export const EASING_OUTINELASTIC: number & { readonly __brand: "go.EASING_OUTINELASTIC" };
|
|
134
|
+
/**
|
|
135
|
+
* out-in-exponential
|
|
136
|
+
*/
|
|
38
137
|
export const EASING_OUTINEXPO: number & { readonly __brand: "go.EASING_OUTINEXPO" };
|
|
138
|
+
/**
|
|
139
|
+
* out-in-quadratic
|
|
140
|
+
*/
|
|
39
141
|
export const EASING_OUTINQUAD: number & { readonly __brand: "go.EASING_OUTINQUAD" };
|
|
142
|
+
/**
|
|
143
|
+
* out-in-quartic
|
|
144
|
+
*/
|
|
40
145
|
export const EASING_OUTINQUART: number & { readonly __brand: "go.EASING_OUTINQUART" };
|
|
146
|
+
/**
|
|
147
|
+
* out-in-quintic
|
|
148
|
+
*/
|
|
41
149
|
export const EASING_OUTINQUINT: number & { readonly __brand: "go.EASING_OUTINQUINT" };
|
|
150
|
+
/**
|
|
151
|
+
* out-in-sine
|
|
152
|
+
*/
|
|
42
153
|
export const EASING_OUTINSINE: number & { readonly __brand: "go.EASING_OUTINSINE" };
|
|
154
|
+
/**
|
|
155
|
+
* out-quadratic
|
|
156
|
+
*/
|
|
43
157
|
export const EASING_OUTQUAD: number & { readonly __brand: "go.EASING_OUTQUAD" };
|
|
158
|
+
/**
|
|
159
|
+
* out-quartic
|
|
160
|
+
*/
|
|
44
161
|
export const EASING_OUTQUART: number & { readonly __brand: "go.EASING_OUTQUART" };
|
|
162
|
+
/**
|
|
163
|
+
* out-quintic
|
|
164
|
+
*/
|
|
45
165
|
export const EASING_OUTQUINT: number & { readonly __brand: "go.EASING_OUTQUINT" };
|
|
166
|
+
/**
|
|
167
|
+
* out-sine
|
|
168
|
+
*/
|
|
46
169
|
export const EASING_OUTSINE: number & { readonly __brand: "go.EASING_OUTSINE" };
|
|
170
|
+
/**
|
|
171
|
+
* loop backward
|
|
172
|
+
*/
|
|
47
173
|
export const PLAYBACK_LOOP_BACKWARD: number & { readonly __brand: "go.PLAYBACK_LOOP_BACKWARD" };
|
|
174
|
+
/**
|
|
175
|
+
* loop forward
|
|
176
|
+
*/
|
|
48
177
|
export const PLAYBACK_LOOP_FORWARD: number & { readonly __brand: "go.PLAYBACK_LOOP_FORWARD" };
|
|
178
|
+
/**
|
|
179
|
+
* ping pong loop
|
|
180
|
+
*/
|
|
49
181
|
export const PLAYBACK_LOOP_PINGPONG: number & { readonly __brand: "go.PLAYBACK_LOOP_PINGPONG" };
|
|
182
|
+
/**
|
|
183
|
+
* no playback
|
|
184
|
+
*/
|
|
50
185
|
export const PLAYBACK_NONE: number & { readonly __brand: "go.PLAYBACK_NONE" };
|
|
186
|
+
/**
|
|
187
|
+
* once backward
|
|
188
|
+
*/
|
|
51
189
|
export const PLAYBACK_ONCE_BACKWARD: number & { readonly __brand: "go.PLAYBACK_ONCE_BACKWARD" };
|
|
190
|
+
/**
|
|
191
|
+
* once forward
|
|
192
|
+
*/
|
|
52
193
|
export const PLAYBACK_ONCE_FORWARD: number & { readonly __brand: "go.PLAYBACK_ONCE_FORWARD" };
|
|
194
|
+
/**
|
|
195
|
+
* once ping pong
|
|
196
|
+
*/
|
|
53
197
|
export const PLAYBACK_ONCE_PINGPONG: number & { readonly __brand: "go.PLAYBACK_ONCE_PINGPONG" };
|
|
198
|
+
/**
|
|
199
|
+
* This is only supported for numerical properties. If the node property is already being
|
|
200
|
+
* animated, that animation will be canceled and replaced by the new one.
|
|
201
|
+
* If a `complete_function` (lua function) is specified, that function will be called when the animation has completed.
|
|
202
|
+
* By starting a new animation in that function, several animations can be sequenced together. See the examples for more information.
|
|
203
|
+
* If you call `go.animate()` from a game object's `final()` function,
|
|
204
|
+
* any passed `complete_function` will be ignored and never called upon animation completion.
|
|
205
|
+
* See the properties guide for which properties can be animated and the animation guide for how
|
|
206
|
+
* them.
|
|
207
|
+
*
|
|
208
|
+
* @param url - url of the game object or component having the property
|
|
209
|
+
* @param property - id of the property to animate
|
|
210
|
+
* @param playback - playback mode of the animation
|
|
211
|
+
- `go.PLAYBACK_ONCE_FORWARD`
|
|
212
|
+
- `go.PLAYBACK_ONCE_BACKWARD`
|
|
213
|
+
- `go.PLAYBACK_ONCE_PINGPONG`
|
|
214
|
+
- `go.PLAYBACK_LOOP_FORWARD`
|
|
215
|
+
- `go.PLAYBACK_LOOP_BACKWARD`
|
|
216
|
+
- `go.PLAYBACK_LOOP_PINGPONG`
|
|
217
|
+
* @param to - target property value
|
|
218
|
+
* @param easing - easing to use during animation. Either specify a constant, see the animation guide for a complete list, or a vmath.vector with a curve
|
|
219
|
+
* @param duration - duration of the animation in seconds
|
|
220
|
+
* @param delay - delay before the animation starts in seconds
|
|
221
|
+
* @param complete_function - optional function to call when the animation has completed
|
|
222
|
+
`self`
|
|
223
|
+
object The current object.
|
|
224
|
+
`url`
|
|
225
|
+
url The game object or component instance for which the property is animated.
|
|
226
|
+
`property`
|
|
227
|
+
hash The id of the animated property.
|
|
228
|
+
* @example
|
|
229
|
+
* ```lua
|
|
230
|
+
* Animate the position of a game object to x = 10 during 1 second, then y = 20 during 1 second:
|
|
231
|
+
* local function x_done(self, url, property)
|
|
232
|
+
* go.animate(go.get_id(), "position.y", go.PLAYBACK_ONCE_FORWARD, 20, go.EASING_LINEAR, 1)
|
|
233
|
+
* end
|
|
234
|
+
*
|
|
235
|
+
* function init(self)
|
|
236
|
+
* go.animate(go.get_id(), "position.x", go.PLAYBACK_ONCE_FORWARD, 10, go.EASING_LINEAR, 1, 0, x_done)
|
|
237
|
+
* end
|
|
238
|
+
*
|
|
239
|
+
* Animate the y position of a game object using a crazy custom easing curve:
|
|
240
|
+
* local values = { 0, 0, 0, 0, 0, 0, 0, 0,
|
|
241
|
+
* 1, 1, 1, 1, 1, 1, 1, 1,
|
|
242
|
+
* 0, 0, 0, 0, 0, 0, 0, 0,
|
|
243
|
+
* 1, 1, 1, 1, 1, 1, 1, 1,
|
|
244
|
+
* 0, 0, 0, 0, 0, 0, 0, 0,
|
|
245
|
+
* 1, 1, 1, 1, 1, 1, 1, 1,
|
|
246
|
+
* 0, 0, 0, 0, 0, 0, 0, 0,
|
|
247
|
+
* 1, 1, 1, 1, 1, 1, 1, 1 }
|
|
248
|
+
* local vec = vmath.vector(values)
|
|
249
|
+
* go.animate("go", "position.y", go.PLAYBACK_LOOP_PINGPONG, 100, vec, 2.0)
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
54
252
|
export function animate(url: string | Hash | Url, property: string | Hash, playback: number & { readonly __brand: "go.PLAYBACK_ONCE_FORWARD" } | number & { readonly __brand: "go.PLAYBACK_ONCE_BACKWARD" } | number & { readonly __brand: "go.PLAYBACK_ONCE_PINGPONG" } | number & { readonly __brand: "go.PLAYBACK_LOOP_FORWARD" } | number & { readonly __brand: "go.PLAYBACK_LOOP_BACKWARD" } | number & { readonly __brand: "go.PLAYBACK_LOOP_PINGPONG" }, to: number | Vector3 | Vector4 | Quaternion, easing: Vector | number & { readonly __brand: "go.EASING_INBACK" } | number & { readonly __brand: "go.EASING_INBOUNCE" } | number & { readonly __brand: "go.EASING_INCIRC" } | number & { readonly __brand: "go.EASING_INCUBIC" } | number & { readonly __brand: "go.EASING_INELASTIC" } | number & { readonly __brand: "go.EASING_INEXPO" } | number & { readonly __brand: "go.EASING_INOUTBACK" } | number & { readonly __brand: "go.EASING_INOUTBOUNCE" } | number & { readonly __brand: "go.EASING_INOUTCIRC" } | number & { readonly __brand: "go.EASING_INOUTCUBIC" } | number & { readonly __brand: "go.EASING_INOUTELASTIC" } | number & { readonly __brand: "go.EASING_INOUTEXPO" } | number & { readonly __brand: "go.EASING_INOUTQUAD" } | number & { readonly __brand: "go.EASING_INOUTQUART" } | number & { readonly __brand: "go.EASING_INOUTQUINT" } | number & { readonly __brand: "go.EASING_INOUTSINE" } | number & { readonly __brand: "go.EASING_INQUAD" } | number & { readonly __brand: "go.EASING_INQUART" } | number & { readonly __brand: "go.EASING_INQUINT" } | number & { readonly __brand: "go.EASING_INSINE" } | number & { readonly __brand: "go.EASING_LINEAR" } | number & { readonly __brand: "go.EASING_OUTBACK" } | number & { readonly __brand: "go.EASING_OUTBOUNCE" } | number & { readonly __brand: "go.EASING_OUTCIRC" } | number & { readonly __brand: "go.EASING_OUTCUBIC" } | number & { readonly __brand: "go.EASING_OUTELASTIC" } | number & { readonly __brand: "go.EASING_OUTEXPO" } | number & { readonly __brand: "go.EASING_OUTINBACK" } | number & { readonly __brand: "go.EASING_OUTINBOUNCE" } | number & { readonly __brand: "go.EASING_OUTINCIRC" } | number & { readonly __brand: "go.EASING_OUTINCUBIC" } | number & { readonly __brand: "go.EASING_OUTINELASTIC" } | number & { readonly __brand: "go.EASING_OUTINEXPO" } | number & { readonly __brand: "go.EASING_OUTINQUAD" } | number & { readonly __brand: "go.EASING_OUTINQUART" } | number & { readonly __brand: "go.EASING_OUTINQUINT" } | number & { readonly __brand: "go.EASING_OUTINSINE" } | number & { readonly __brand: "go.EASING_OUTQUAD" } | number & { readonly __brand: "go.EASING_OUTQUART" } | number & { readonly __brand: "go.EASING_OUTQUINT" } | number & { readonly __brand: "go.EASING_OUTSINE" }, duration: number, delay?: number, complete_function?: (self: unknown, url: unknown, property: unknown) => void): void;
|
|
253
|
+
/**
|
|
254
|
+
* By calling this function, all or specified stored property animations of the game object or component will be canceled.
|
|
255
|
+
* See the properties guide for which properties can be animated and the animation guide for how to animate them.
|
|
256
|
+
*
|
|
257
|
+
* @param url - url of the game object or component
|
|
258
|
+
* @param property - optional id of the property to cancel
|
|
259
|
+
* @example
|
|
260
|
+
* ```lua
|
|
261
|
+
* Cancel the animation of the position of a game object:
|
|
262
|
+
* go.cancel_animations(go.get_id(), "position")
|
|
263
|
+
*
|
|
264
|
+
* Cancel all property animations of the current game object:
|
|
265
|
+
* go.cancel_animations(".")
|
|
266
|
+
*
|
|
267
|
+
* Cancel all property animations of the sprite component of the current game object:
|
|
268
|
+
* go.cancel_animations("#sprite")
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
55
271
|
export function cancel_animations(url: string | Hash | Url, property?: string | Hash): void;
|
|
272
|
+
/**
|
|
273
|
+
* Delete one or more game objects identified by id. Deletion is asynchronous meaning that
|
|
274
|
+
* the game object(s) are scheduled for deletion which will happen at the end of the current
|
|
275
|
+
* frame. Note that game objects scheduled for deletion will be counted against
|
|
276
|
+
* `max_instances` in "game.project" until they are actually removed.
|
|
277
|
+
* Deleting a game object containing a particle FX component emitting particles will not immediately stop the particle FX from emitting particles. You need to manually stop the particle FX using `particlefx.stop()`.
|
|
278
|
+
* Deleting a game object containing a sound component that is playing will not immediately stop the sound from playing. You need to manually stop the sound using `sound.stop()`.
|
|
279
|
+
*
|
|
280
|
+
* @param id - optional id or table of id's of the instance(s) to delete, the instance of the calling script is deleted by default
|
|
281
|
+
* @param recursive - optional boolean, set to true to recursively delete child hiearchy in child to parent order
|
|
282
|
+
* @example
|
|
283
|
+
* ```lua
|
|
284
|
+
* This example demonstrates how to delete game objects
|
|
285
|
+
* -- Delete the script game object
|
|
286
|
+
* go.delete()
|
|
287
|
+
* -- Delete a game object with the id "my_game_object".
|
|
288
|
+
* local id = go.get_id("my_game_object") -- retrieve the id of the game object to be deleted
|
|
289
|
+
* go.delete(id)
|
|
290
|
+
* -- Delete a list of game objects.
|
|
291
|
+
* local ids = { hash("/my_object_1"), hash("/my_object_2"), hash("/my_object_3") }
|
|
292
|
+
* go.delete(ids)
|
|
293
|
+
*
|
|
294
|
+
* This example demonstrates how to delete a game objects and their children (child to parent order)
|
|
295
|
+
* -- Delete the script game object and it's children
|
|
296
|
+
* go.delete(true)
|
|
297
|
+
* -- Delete a game object with the id "my_game_object" and it's children.
|
|
298
|
+
* local id = go.get_id("my_game_object") -- retrieve the id of the game object to be deleted
|
|
299
|
+
* go.delete(id, true)
|
|
300
|
+
* -- Delete a list of game objects and their children.
|
|
301
|
+
* local ids = { hash("/my_object_1"), hash("/my_object_2"), hash("/my_object_3") }
|
|
302
|
+
* go.delete(ids, true)
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
56
305
|
function _delete(id?: string | Hash | Url | (string | Hash | Url)[], recursive?: boolean): void;
|
|
306
|
+
/**
|
|
307
|
+
* This function can check for game objects in any collection by specifying
|
|
308
|
+
* the collection name in the URL.
|
|
309
|
+
*
|
|
310
|
+
* @param url - url of the game object to check
|
|
311
|
+
* @returns true if the game object exists
|
|
312
|
+
* @example
|
|
313
|
+
* ```lua
|
|
314
|
+
* Check if game object "my_game_object" exists in the current collection
|
|
315
|
+
* go.exists("/my_game_object")
|
|
316
|
+
*
|
|
317
|
+
* Check if game object exists in another collection
|
|
318
|
+
* go.exists("other_collection:/my_game_object")
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
57
321
|
export function exists(url: string | Hash | Url): boolean;
|
|
322
|
+
/**
|
|
323
|
+
* This is a callback-function, which is called by the engine when a script component is finalized (destroyed). It can
|
|
324
|
+
* be used to e.g. take some last action, report the finalization to other game object instances, delete spawned objects
|
|
325
|
+
* or release user input focus (see release_input_focus).
|
|
326
|
+
*
|
|
327
|
+
* @param self - reference to the script state to be used for storing data
|
|
328
|
+
* @example
|
|
329
|
+
* ```lua
|
|
330
|
+
* function final(self)
|
|
331
|
+
* -- report finalization
|
|
332
|
+
* msg.post("my_friend_instance", "im_dead", {my_stats = self.some_value})
|
|
333
|
+
* end
|
|
334
|
+
* ```
|
|
335
|
+
*/
|
|
58
336
|
export function final(self: Opaque<"userdata">): void;
|
|
337
|
+
/**
|
|
338
|
+
* This is a callback-function, which is called by the engine at fixed intervals to update the state of a script
|
|
339
|
+
* component. The function will be called if 'Fixed Update Frequency' is enabled in the Engine section of game.project.
|
|
340
|
+
* It can for instance be used to update game logic with the physics simulation if using a fixed timestep for the
|
|
341
|
+
* physics (enabled by ticking 'Use Fixed Timestep' in the Physics section of game.project).
|
|
342
|
+
*
|
|
343
|
+
* @param self - reference to the script state to be used for storing data
|
|
344
|
+
* @param dt - the time-step of the frame update
|
|
345
|
+
*/
|
|
59
346
|
export function fixed_update(self: Opaque<"userdata">, dt: number): void;
|
|
347
|
+
/**
|
|
348
|
+
* Returns or constructs an instance identifier. The instance id is a hash
|
|
349
|
+
* of the absolute path to the instance.
|
|
350
|
+
* - If `path` is specified, it can either be absolute or relative to the instance of the calling script.
|
|
351
|
+
* - If `path` is not specified, the id of the game object instance the script is attached to will be returned.
|
|
352
|
+
*
|
|
353
|
+
* @param path - path of the instance for which to return the id
|
|
354
|
+
* @returns instance id
|
|
355
|
+
* @example
|
|
356
|
+
* ```lua
|
|
357
|
+
* For the instance with path /my_sub_collection/my_instance, the following calls are equivalent:
|
|
358
|
+
* local id = go.get_id() -- no path, defaults to the instance containing the calling script
|
|
359
|
+
* print(id) --> hash: [/my_sub_collection/my_instance]
|
|
360
|
+
*
|
|
361
|
+
* local id = go.get_id("/my_sub_collection/my_instance") -- absolute path
|
|
362
|
+
* print(id) --> hash: [/my_sub_collection/my_instance]
|
|
363
|
+
*
|
|
364
|
+
* local id = go.get_id("my_instance") -- relative path
|
|
365
|
+
* print(id) --> hash: [/my_sub_collection/my_instance]
|
|
366
|
+
* ```
|
|
367
|
+
*/
|
|
60
368
|
export function get_id(path?: string): Hash;
|
|
369
|
+
/**
|
|
370
|
+
* Get the parent for a game object instance.
|
|
371
|
+
*
|
|
372
|
+
* @param id - optional id of the game object instance to get parent for, defaults to the instance containing the calling script
|
|
373
|
+
* @returns parent instance or `nil`
|
|
374
|
+
* @example
|
|
375
|
+
* ```lua
|
|
376
|
+
* Get parent of the instance containing the calling script:
|
|
377
|
+
* local parent_id = go.get_parent()
|
|
378
|
+
*
|
|
379
|
+
* Get parent of the instance with id "x":
|
|
380
|
+
* local parent_id = go.get_parent("x")
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
61
383
|
export function get_parent(id?: string | Hash | Url): Hash | unknown;
|
|
384
|
+
/**
|
|
385
|
+
* The position is relative the parent (if any). Use go.get_world_position to retrieve the global world position.
|
|
386
|
+
*
|
|
387
|
+
* @param id - optional id of the game object instance to get the position for, by default the instance of the calling script
|
|
388
|
+
* @returns instance position
|
|
389
|
+
* @example
|
|
390
|
+
* ```lua
|
|
391
|
+
* Get the position of the game object instance the script is attached to:
|
|
392
|
+
* local p = go.get_position()
|
|
393
|
+
*
|
|
394
|
+
* Get the position of another game object instance "my_gameobject":
|
|
395
|
+
* local pos = go.get_position("my_gameobject")
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
62
398
|
export function get_position(id?: string | Hash | Url): Vector3;
|
|
399
|
+
/**
|
|
400
|
+
* The rotation is relative to the parent (if any). Use go.get_world_rotation to retrieve the global world rotation.
|
|
401
|
+
*
|
|
402
|
+
* @param id - optional id of the game object instance to get the rotation for, by default the instance of the calling script
|
|
403
|
+
* @returns instance rotation
|
|
404
|
+
* @example
|
|
405
|
+
* ```lua
|
|
406
|
+
* Get the rotation of the game object instance the script is attached to:
|
|
407
|
+
* local r = go.get_rotation()
|
|
408
|
+
*
|
|
409
|
+
* Get the rotation of another game object instance with id "x":
|
|
410
|
+
* local r = go.get_rotation("x")
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
63
413
|
export function get_rotation(id?: string | Hash | Url): Quaternion;
|
|
414
|
+
/**
|
|
415
|
+
* The scale is relative the parent (if any). Use go.get_world_scale to retrieve the global world 3D scale factor.
|
|
416
|
+
*
|
|
417
|
+
* @param id - optional id of the game object instance to get the scale for, by default the instance of the calling script
|
|
418
|
+
* @returns instance scale factor
|
|
419
|
+
* @example
|
|
420
|
+
* ```lua
|
|
421
|
+
* Get the scale of the game object instance the script is attached to:
|
|
422
|
+
* local s = go.get_scale()
|
|
423
|
+
*
|
|
424
|
+
* Get the scale of another game object instance with id "x":
|
|
425
|
+
* local s = go.get_scale("x")
|
|
426
|
+
* ```
|
|
427
|
+
*/
|
|
64
428
|
export function get_scale(id?: string | Hash | Url): Vector3;
|
|
429
|
+
/**
|
|
430
|
+
* The uniform scale is relative the parent (if any). If the underlying scale vector is non-uniform the min element of the vector is returned as the uniform scale factor.
|
|
431
|
+
*
|
|
432
|
+
* @param id - optional id of the game object instance to get the uniform scale for, by default the instance of the calling script
|
|
433
|
+
* @returns uniform instance scale factor
|
|
434
|
+
* @example
|
|
435
|
+
* ```lua
|
|
436
|
+
* Get the scale of the game object instance the script is attached to:
|
|
437
|
+
* local s = go.get_scale_uniform()
|
|
438
|
+
*
|
|
439
|
+
* Get the uniform scale of another game object instance with id "x":
|
|
440
|
+
* local s = go.get_scale_uniform("x")
|
|
441
|
+
* ```
|
|
442
|
+
*/
|
|
65
443
|
export function get_scale_uniform(id?: string | Hash | Url): number;
|
|
444
|
+
/**
|
|
445
|
+
* The function will return the world position calculated at the end of the previous frame.
|
|
446
|
+
* To recalculate it within the current frame, use go.update_world_transform on the instance before calling this.
|
|
447
|
+
* Use go.get_position to retrieve the position relative to the parent.
|
|
448
|
+
*
|
|
449
|
+
* @param id - optional id of the game object instance to get the world position for, by default the instance of the calling script
|
|
450
|
+
* @returns instance world position
|
|
451
|
+
* @example
|
|
452
|
+
* ```lua
|
|
453
|
+
* Get the world position of the game object instance the script is attached to:
|
|
454
|
+
* local p = go.get_world_position()
|
|
455
|
+
*
|
|
456
|
+
* Get the world position of another game object instance with id "x":
|
|
457
|
+
* local p = go.get_world_position("x")
|
|
458
|
+
* ```
|
|
459
|
+
*/
|
|
66
460
|
export function get_world_position(id?: string | Hash | Url): Vector3;
|
|
461
|
+
/**
|
|
462
|
+
* The function will return the world rotation calculated at the end of the previous frame.
|
|
463
|
+
* To recalculate it within the current frame, use go.update_world_transform on the instance before calling this.
|
|
464
|
+
* Use go.get_rotation to retrieve the rotation relative to the parent.
|
|
465
|
+
*
|
|
466
|
+
* @param id - optional id of the game object instance to get the world rotation for, by default the instance of the calling script
|
|
467
|
+
* @returns instance world rotation
|
|
468
|
+
* @example
|
|
469
|
+
* ```lua
|
|
470
|
+
* Get the world rotation of the game object instance the script is attached to:
|
|
471
|
+
* local r = go.get_world_rotation()
|
|
472
|
+
*
|
|
473
|
+
* Get the world rotation of another game object instance with id "x":
|
|
474
|
+
* local r = go.get_world_rotation("x")
|
|
475
|
+
* ```
|
|
476
|
+
*/
|
|
67
477
|
export function get_world_rotation(id?: string | Hash | Url): Quaternion;
|
|
478
|
+
/**
|
|
479
|
+
* The function will return the world 3D scale factor calculated at the end of the previous frame.
|
|
480
|
+
* To recalculate it within the current frame, use go.update_world_transform on the instance before calling this.
|
|
481
|
+
* Use go.get_scale to retrieve the 3D scale factor relative to the parent.
|
|
482
|
+
* This vector is derived by decomposing the transformation matrix and should be used with care.
|
|
483
|
+
* For most cases it should be fine to use go.get_world_scale_uniform instead.
|
|
484
|
+
*
|
|
485
|
+
* @param id - optional id of the game object instance to get the world scale for, by default the instance of the calling script
|
|
486
|
+
* @returns instance world 3D scale factor
|
|
487
|
+
* @example
|
|
488
|
+
* ```lua
|
|
489
|
+
* Get the world 3D scale of the game object instance the script is attached to:
|
|
490
|
+
* local s = go.get_world_scale()
|
|
491
|
+
*
|
|
492
|
+
* Get the world scale of another game object instance "x":
|
|
493
|
+
* local s = go.get_world_scale("x")
|
|
494
|
+
* ```
|
|
495
|
+
*/
|
|
68
496
|
export function get_world_scale(id?: string | Hash | Url): Vector3;
|
|
497
|
+
/**
|
|
498
|
+
* The function will return the world scale factor calculated at the end of the previous frame.
|
|
499
|
+
* To recalculate it within the current frame, use go.update_world_transform on the instance before calling this.
|
|
500
|
+
* Use go.get_scale_uniform to retrieve the scale factor relative to the parent.
|
|
501
|
+
*
|
|
502
|
+
* @param id - optional id of the game object instance to get the world scale for, by default the instance of the calling script
|
|
503
|
+
* @returns instance world scale factor
|
|
504
|
+
* @example
|
|
505
|
+
* ```lua
|
|
506
|
+
* Get the world scale of the game object instance the script is attached to:
|
|
507
|
+
* local s = go.get_world_scale_uniform()
|
|
508
|
+
*
|
|
509
|
+
* Get the world scale of another game object instance with id "x":
|
|
510
|
+
* local s = go.get_world_scale_uniform("x")
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
69
513
|
export function get_world_scale_uniform(id?: string | Hash | Url): number;
|
|
514
|
+
/**
|
|
515
|
+
* The function will return the world transform matrix calculated at the end of the previous frame.
|
|
516
|
+
* To recalculate it within the current frame, use go.update_world_transform on the instance before calling this.
|
|
517
|
+
*
|
|
518
|
+
* @param id - optional id of the game object instance to get the world transform for, by default the instance of the calling script
|
|
519
|
+
* @returns instance world transform
|
|
520
|
+
* @example
|
|
521
|
+
* ```lua
|
|
522
|
+
* Get the world transform of the game object instance the script is attached to:
|
|
523
|
+
* local m = go.get_world_transform()
|
|
524
|
+
*
|
|
525
|
+
* Get the world transform of another game object instance with id "x":
|
|
526
|
+
* local m = go.get_world_transform("x")
|
|
527
|
+
* ```
|
|
528
|
+
*/
|
|
70
529
|
export function get_world_transform(id?: string | Hash | Url): Matrix4;
|
|
530
|
+
/**
|
|
531
|
+
* This is a callback-function, which is called by the engine when a script component is initialized. It can be used
|
|
532
|
+
* to set the initial state of the script.
|
|
533
|
+
*
|
|
534
|
+
* @param self - reference to the script state to be used for storing data
|
|
535
|
+
* @example
|
|
536
|
+
* ```lua
|
|
537
|
+
* function init(self)
|
|
538
|
+
* -- set up useful data
|
|
539
|
+
* self.my_value = 1
|
|
540
|
+
* end
|
|
541
|
+
* ```
|
|
542
|
+
*/
|
|
71
543
|
export function init(self: Opaque<"userdata">): void;
|
|
544
|
+
/**
|
|
545
|
+
* This is a callback-function, which is called by the engine at the end of the frame to update the state of a script
|
|
546
|
+
* component. Use it to make final adjustments to the game object instance.
|
|
547
|
+
*
|
|
548
|
+
* @param self - reference to the script state to be used for storing data
|
|
549
|
+
* @param dt - the time-step of the frame update
|
|
550
|
+
*/
|
|
72
551
|
export function late_update(self: Opaque<"userdata">, dt: number): void;
|
|
552
|
+
/**
|
|
553
|
+
* This is a callback-function, which is called by the engine when user input is sent to the game object instance of the script.
|
|
554
|
+
* It can be used to take action on the input, e.g. move the instance according to the input.
|
|
555
|
+
* For an instance to obtain user input, it must first acquire input focus
|
|
556
|
+
* through the message `acquire_input_focus`.
|
|
557
|
+
* Any instance that has obtained input will be put on top of an
|
|
558
|
+
* input stack. Input is sent to all listeners on the stack until the
|
|
559
|
+
* end of stack is reached, or a listener returns `true`
|
|
560
|
+
* to signal that it wants input to be consumed.
|
|
561
|
+
* See the documentation of acquire_input_focus for more
|
|
562
|
+
* information.
|
|
563
|
+
* The `action` parameter is a table containing data about the input mapped to the
|
|
564
|
+
* `action_id`.
|
|
565
|
+
* For mapped actions it specifies the value of the input and if it was just pressed or released.
|
|
566
|
+
* Actions are mapped to input in an input_binding-file.
|
|
567
|
+
* Mouse movement is specifically handled and uses `nil` as its `action_id`.
|
|
568
|
+
* The `action` only contains positional parameters in this case, such as x and y of the pointer.
|
|
569
|
+
* Here is a brief description of the available table fields:
|
|
570
|
+
* Field
|
|
571
|
+
* Description
|
|
572
|
+
* `value`
|
|
573
|
+
* The amount of input given by the user. This is usually 1 for buttons and 0-1 for analogue inputs. This is not present for mouse movement and text input.
|
|
574
|
+
* `pressed`
|
|
575
|
+
* If the input was pressed this frame. This is not present for mouse movement and text input.
|
|
576
|
+
* `released`
|
|
577
|
+
* If the input was released this frame. This is not present for mouse movement and text input.
|
|
578
|
+
* `repeated`
|
|
579
|
+
* If the input was repeated this frame. This is similar to how a key on a keyboard is repeated when you hold it down. This is not present for mouse movement and text input.
|
|
580
|
+
* `x`
|
|
581
|
+
* The x value of a pointer device, if present. This is not present for gamepad, key and text input.
|
|
582
|
+
* `y`
|
|
583
|
+
* The y value of a pointer device, if present. This is not present for gamepad, key and text input.
|
|
584
|
+
* `screen_x`
|
|
585
|
+
* The screen space x value of a pointer device, if present. This is not present for gamepad, key and text input.
|
|
586
|
+
* `screen_y`
|
|
587
|
+
* The screen space y value of a pointer device, if present. This is not present for gamepad, key and text input.
|
|
588
|
+
* `dx`
|
|
589
|
+
* The change in x value of a pointer device, if present. This is not present for gamepad, key and text input.
|
|
590
|
+
* `dy`
|
|
591
|
+
* The change in y value of a pointer device, if present. This is not present for gamepad, key and text input.
|
|
592
|
+
* `screen_dx`
|
|
593
|
+
* The change in screen space x value of a pointer device, if present. This is not present for gamepad, key and text input.
|
|
594
|
+
* `screen_dy`
|
|
595
|
+
* The change in screen space y value of a pointer device, if present. This is not present for gamepad, key and text input.
|
|
596
|
+
* `gamepad`
|
|
597
|
+
* The index of the gamepad device that provided the input. See table below about gamepad input.
|
|
598
|
+
* `touch`
|
|
599
|
+
* List of touch input, one element per finger, if present. See table below about touch input
|
|
600
|
+
* `text`
|
|
601
|
+
* Text input from a (virtual) keyboard or similar.
|
|
602
|
+
* `marked_text`
|
|
603
|
+
* Sequence of entered symbols while entering a symbol combination, for example Japanese Kana.
|
|
604
|
+
* Gamepad specific fields:
|
|
605
|
+
* Field
|
|
606
|
+
* Description
|
|
607
|
+
* `gamepad`
|
|
608
|
+
* The index of the gamepad device that provided the input.
|
|
609
|
+
* `userid`
|
|
610
|
+
* Id of the user associated with the controller. Usually only relevant on consoles.
|
|
611
|
+
* `gamepad_unknown`
|
|
612
|
+
* True if the inout originated from an unknown/unmapped gamepad.
|
|
613
|
+
* `gamepad_name`
|
|
614
|
+
* Name of the gamepad
|
|
615
|
+
* `gamepad_axis`
|
|
616
|
+
* List of gamepad axis values. For raw gamepad input only.
|
|
617
|
+
* `gamepadhats`
|
|
618
|
+
* List of gamepad hat values. For raw gamepad input only.
|
|
619
|
+
* `gamepad_buttons`
|
|
620
|
+
* List of gamepad button values. For raw gamepad input only.
|
|
621
|
+
* Touch input table:
|
|
622
|
+
* Field
|
|
623
|
+
* Description
|
|
624
|
+
* `id`
|
|
625
|
+
* A number identifying the touch input during its duration.
|
|
626
|
+
* `pressed`
|
|
627
|
+
* True if the finger was pressed this frame.
|
|
628
|
+
* `released`
|
|
629
|
+
* True if the finger was released this frame.
|
|
630
|
+
* `tap_count`
|
|
631
|
+
* Number of taps, one for single, two for double-tap, etc
|
|
632
|
+
* `x`
|
|
633
|
+
* The x touch location.
|
|
634
|
+
* `y`
|
|
635
|
+
* The y touch location.
|
|
636
|
+
* `dx`
|
|
637
|
+
* The change in x value.
|
|
638
|
+
* `dy`
|
|
639
|
+
* The change in y value.
|
|
640
|
+
* `acc_x`
|
|
641
|
+
* Accelerometer x value (if present).
|
|
642
|
+
* `acc_y`
|
|
643
|
+
* Accelerometer y value (if present).
|
|
644
|
+
* `acc_z`
|
|
645
|
+
* Accelerometer z value (if present).
|
|
646
|
+
*
|
|
647
|
+
* @param self - reference to the script state to be used for storing data
|
|
648
|
+
* @param action_id - id of the received input action, as mapped in the input_binding-file
|
|
649
|
+
* @param action - a table containing the input data, see above for a description
|
|
650
|
+
* @returns optional boolean to signal if the input should be consumed (not passed on to others) or not, default is false
|
|
651
|
+
* @example
|
|
652
|
+
* ```lua
|
|
653
|
+
* This example demonstrates how a game object instance can be moved as a response to user input.
|
|
654
|
+
* function init(self)
|
|
655
|
+
* -- acquire input focus
|
|
656
|
+
* msg.post(".", "acquire_input_focus")
|
|
657
|
+
* -- maximum speed the instance can be moved
|
|
658
|
+
* self.max_speed = 2
|
|
659
|
+
* -- velocity of the instance, initially zero
|
|
660
|
+
* self.velocity = vmath.vector3()
|
|
661
|
+
* end
|
|
662
|
+
*
|
|
663
|
+
* function update(self, dt)
|
|
664
|
+
* -- move the instance
|
|
665
|
+
* go.set_position(go.get_position() + dt * self.velocity)
|
|
666
|
+
* end
|
|
667
|
+
*
|
|
668
|
+
* function on_input(self, action_id, action)
|
|
669
|
+
* -- check for movement input
|
|
670
|
+
* if action_id == hash("right") then
|
|
671
|
+
* if action.released then -- reset velocity if input was released
|
|
672
|
+
* self.velocity = vmath.vector3()
|
|
673
|
+
* else -- update velocity
|
|
674
|
+
* self.velocity = vmath.vector3(action.value * self.max_speed, 0, 0)
|
|
675
|
+
* end
|
|
676
|
+
* end
|
|
677
|
+
* end
|
|
678
|
+
* ```
|
|
679
|
+
*/
|
|
73
680
|
export function on_input(self: Opaque<"userdata">, action_id: Hash, action: Record<string | number, unknown>): boolean | unknown;
|
|
681
|
+
/**
|
|
682
|
+
* This is a callback-function, which is called by the engine whenever a message has been sent to the script component.
|
|
683
|
+
* It can be used to take action on the message, e.g. send a response back to the sender of the message.
|
|
684
|
+
* The `message` parameter is a table containing the message data. If the message is sent from the engine, the
|
|
685
|
+
* documentation of the message specifies which data is supplied.
|
|
686
|
+
*
|
|
687
|
+
* @param self - reference to the script state to be used for storing data
|
|
688
|
+
* @param message_id - id of the received message
|
|
689
|
+
* @param message - a table containing the message data
|
|
690
|
+
* @param sender - address of the sender
|
|
691
|
+
* @example
|
|
692
|
+
* ```lua
|
|
693
|
+
* This example demonstrates how a game object instance, called "a", can communicate with another instance, called "b". It
|
|
694
|
+
* is assumed that both script components of the instances has id "script".
|
|
695
|
+
* Script of instance "a":
|
|
696
|
+
* function init(self)
|
|
697
|
+
* -- let b know about some important data
|
|
698
|
+
* msg.post("b#script", "my_data", {important_value = 1})
|
|
699
|
+
* end
|
|
700
|
+
*
|
|
701
|
+
* Script of instance "b":
|
|
702
|
+
* function init(self)
|
|
703
|
+
* -- store the url of instance "a" for later use, by specifying nil as socket we
|
|
704
|
+
* -- automatically use our own socket
|
|
705
|
+
* self.a_url = msg.url(nil, go.get_id("a"), "script")
|
|
706
|
+
* end
|
|
707
|
+
*
|
|
708
|
+
* function on_message(self, message_id, message, sender)
|
|
709
|
+
* -- check message and sender
|
|
710
|
+
* if message_id == hash("my_data") and sender == self.a_url then
|
|
711
|
+
* -- use the data in some way
|
|
712
|
+
* self.important_value = message.important_value
|
|
713
|
+
* end
|
|
714
|
+
* end
|
|
715
|
+
* ```
|
|
716
|
+
*/
|
|
74
717
|
export function on_message(self: Opaque<"userdata">, message_id: Hash, message: Record<string | number, unknown>, sender: Url): void;
|
|
718
|
+
/**
|
|
719
|
+
* This is a callback-function, which is called by the engine when the script component is reloaded, e.g. from the editor.
|
|
720
|
+
* It can be used for live development, e.g. to tweak constants or set up the state properly for the instance.
|
|
721
|
+
*
|
|
722
|
+
* @param self - reference to the script state to be used for storing data
|
|
723
|
+
* @example
|
|
724
|
+
* ```lua
|
|
725
|
+
* This example demonstrates how to tweak the speed of a game object instance that is moved on user input.
|
|
726
|
+
* function init(self)
|
|
727
|
+
* -- acquire input focus
|
|
728
|
+
* msg.post(".", "acquire_input_focus")
|
|
729
|
+
* -- maximum speed the instance can be moved, this value is tweaked in the on_reload function below
|
|
730
|
+
* self.max_speed = 2
|
|
731
|
+
* -- velocity of the instance, initially zero
|
|
732
|
+
* self.velocity = vmath.vector3()
|
|
733
|
+
* end
|
|
734
|
+
*
|
|
735
|
+
* function update(self, dt)
|
|
736
|
+
* -- move the instance
|
|
737
|
+
* go.set_position(go.get_position() + dt * self.velocity)
|
|
738
|
+
* end
|
|
739
|
+
*
|
|
740
|
+
* function on_input(self, action_id, action)
|
|
741
|
+
* -- check for movement input
|
|
742
|
+
* if action_id == hash("right") then
|
|
743
|
+
* if action.released then -- reset velocity if input was released
|
|
744
|
+
* self.velocity = vmath.vector3()
|
|
745
|
+
* else -- update velocity
|
|
746
|
+
* self.velocity = vmath.vector3(action.value * self.max_speed, 0, 0)
|
|
747
|
+
* end
|
|
748
|
+
* end
|
|
749
|
+
* end
|
|
750
|
+
*
|
|
751
|
+
* function on_reload(self)
|
|
752
|
+
* -- edit this value and reload the script component
|
|
753
|
+
* self.max_speed = 100
|
|
754
|
+
* end
|
|
755
|
+
* ```
|
|
756
|
+
*/
|
|
75
757
|
export function on_reload(self: Opaque<"userdata">): void;
|
|
758
|
+
/**
|
|
759
|
+
* This function defines a property which can then be used in the script through the self-reference.
|
|
760
|
+
* The properties defined this way are automatically exposed in the editor in game objects and collections which use the script.
|
|
761
|
+
* Note that you can only use this function outside any callback-functions like init and update.
|
|
762
|
+
*
|
|
763
|
+
* @param name - the id of the property
|
|
764
|
+
* @param value - default value of the property. In the case of a url, only the empty constructor msg.url() is allowed. In the case of a resource one of the resource constructors (eg resource.atlas(), resource.font() etc) is expected.
|
|
765
|
+
* @example
|
|
766
|
+
* ```lua
|
|
767
|
+
* This example demonstrates how to define a property called "health" in a script.
|
|
768
|
+
* The health is decreased whenever someone sends a message called "take_damage" to the script.
|
|
769
|
+
* go.property("health", 100)
|
|
770
|
+
*
|
|
771
|
+
* function init(self)
|
|
772
|
+
* -- prints 100 to the output
|
|
773
|
+
* print(self.health)
|
|
774
|
+
* end
|
|
775
|
+
*
|
|
776
|
+
* function on_message(self, message_id, message, sender)
|
|
777
|
+
* if message_id == hash("take_damage") then
|
|
778
|
+
* self.health = self.health - message.damage
|
|
779
|
+
* print("Ouch! My health is now: " .. self.health)
|
|
780
|
+
* end
|
|
781
|
+
* end
|
|
782
|
+
* ```
|
|
783
|
+
*/
|
|
76
784
|
export function property(name: string, value: number | Hash | Url | Vector3 | Vector4 | Quaternion | Opaque<"resource"> | boolean): void;
|
|
785
|
+
/**
|
|
786
|
+
* Sets the parent for a game object instance. This means that the instance will exist in the geometrical space of its parent,
|
|
787
|
+
* like a basic transformation hierarchy or scene graph. If no parent is specified, the instance will be detached from any parent and exist in world
|
|
788
|
+
* space.
|
|
789
|
+
* This function will generate a `set_parent` message. It is not until the message has been processed that the change actually takes effect. This
|
|
790
|
+
* typically happens later in the same frame or the beginning of the next frame. Refer to the manual to learn how messages are processed by the
|
|
791
|
+
* engine.
|
|
792
|
+
*
|
|
793
|
+
* @param id - optional id of the game object instance to set parent for, defaults to the instance containing the calling script
|
|
794
|
+
* @param parent_id - optional id of the new parent game object, defaults to detaching game object from its parent
|
|
795
|
+
* @param keep_world_transform - optional boolean, set to true to maintain the world transform when changing spaces. Defaults to false.
|
|
796
|
+
* @example
|
|
797
|
+
* ```lua
|
|
798
|
+
* Attach myself to another instance "my_parent":
|
|
799
|
+
* go.set_parent(go.get_id(),go.get_id("my_parent"))
|
|
800
|
+
*
|
|
801
|
+
* Attach an instance "my_instance" to another instance "my_parent":
|
|
802
|
+
* go.set_parent(go.get_id("my_instance"),go.get_id("my_parent"))
|
|
803
|
+
*
|
|
804
|
+
* Detach an instance "my_instance" from its parent (if any):
|
|
805
|
+
* go.set_parent(go.get_id("my_instance"))
|
|
806
|
+
* ```
|
|
807
|
+
*/
|
|
77
808
|
export function set_parent(id?: string | Hash | Url, parent_id?: string | Hash | Url, keep_world_transform?: boolean): void;
|
|
809
|
+
/**
|
|
810
|
+
* The position is relative to the parent (if any). The global world position cannot be manually set.
|
|
811
|
+
*
|
|
812
|
+
* @param position - position to set
|
|
813
|
+
* @param id - optional id of the game object instance to set the position for, by default the instance of the calling script
|
|
814
|
+
* @example
|
|
815
|
+
* ```lua
|
|
816
|
+
* Set the position of the game object instance the script is attached to:
|
|
817
|
+
* local p = ...
|
|
818
|
+
* go.set_position(p)
|
|
819
|
+
*
|
|
820
|
+
* Set the position of another game object instance with id "x":
|
|
821
|
+
* local p = ...
|
|
822
|
+
* go.set_position(p, "x")
|
|
823
|
+
* ```
|
|
824
|
+
*/
|
|
78
825
|
export function set_position(position: Vector3, id?: string | Hash | Url): void;
|
|
826
|
+
/**
|
|
827
|
+
* The rotation is relative to the parent (if any). The global world rotation cannot be manually set.
|
|
828
|
+
*
|
|
829
|
+
* @param rotation - rotation to set
|
|
830
|
+
* @param id - optional id of the game object instance to get the rotation for, by default the instance of the calling script
|
|
831
|
+
* @example
|
|
832
|
+
* ```lua
|
|
833
|
+
* Set the rotation of the game object instance the script is attached to:
|
|
834
|
+
* local r = ...
|
|
835
|
+
* go.set_rotation(r)
|
|
836
|
+
*
|
|
837
|
+
* Set the rotation of another game object instance with id "x":
|
|
838
|
+
* local r = ...
|
|
839
|
+
* go.set_rotation(r, "x")
|
|
840
|
+
* ```
|
|
841
|
+
*/
|
|
79
842
|
export function set_rotation(rotation: Quaternion, id?: string | Hash | Url): void;
|
|
843
|
+
/**
|
|
844
|
+
* The scale factor is relative to the parent (if any). The global world scale factor cannot be manually set.
|
|
845
|
+
* See manual to know how physics affected when setting scale from this function.
|
|
846
|
+
*
|
|
847
|
+
* @param scale - vector or uniform scale factor, must be greater than 0
|
|
848
|
+
* @param id - optional id of the game object instance to get the scale for, by default the instance of the calling script
|
|
849
|
+
* @example
|
|
850
|
+
* ```lua
|
|
851
|
+
* Set the scale of the game object instance the script is attached to:
|
|
852
|
+
* local s = vmath.vector3(2.0, 1.0, 1.0)
|
|
853
|
+
* go.set_scale(s)
|
|
854
|
+
*
|
|
855
|
+
* Set the scale of another game object instance with id "obj_id":
|
|
856
|
+
* local s = 1.2
|
|
857
|
+
* go.set_scale(s, "obj_id")
|
|
858
|
+
* ```
|
|
859
|
+
*/
|
|
80
860
|
export function set_scale(scale: number | Vector3, id?: string | Hash | Url): void;
|
|
861
|
+
/**
|
|
862
|
+
* The scale factor is relative to the parent (if any). The global world scale factor cannot be manually set.
|
|
863
|
+
* See manual to know how physics affected when setting scale from this function.
|
|
864
|
+
*
|
|
865
|
+
* @param scale - vector or uniform scale factor, must be greater than 0
|
|
866
|
+
* @param id - optional id of the game object instance to get the scale for, by default the instance of the calling script
|
|
867
|
+
* @example
|
|
868
|
+
* ```lua
|
|
869
|
+
* Set the scale of the game object instance the script is attached to:
|
|
870
|
+
* local s = vmath.vector3(2.0, 1.0, 5.0)
|
|
871
|
+
* go.set_scale_xy(s) -- z will not be set here, only x and y
|
|
872
|
+
*
|
|
873
|
+
* Set the scale of another game object instance with id "obj_id":
|
|
874
|
+
* local s = 1.2
|
|
875
|
+
* go.set_scale_xy(s, "obj_id") -- z will not be set here, only x and y
|
|
876
|
+
* ```
|
|
877
|
+
*/
|
|
81
878
|
export function set_scale_xy(scale: number | Vector3, id?: string | Hash | Url): void;
|
|
879
|
+
/**
|
|
880
|
+
* This is a callback-function, which is called by the engine every frame to update the state of a script component.
|
|
881
|
+
* It can be used to perform any kind of game related tasks, e.g. moving the game object instance.
|
|
882
|
+
*
|
|
883
|
+
* @param self - reference to the script state to be used for storing data
|
|
884
|
+
* @param dt - the time-step of the frame update
|
|
885
|
+
* @example
|
|
886
|
+
* ```lua
|
|
887
|
+
* This example demonstrates how to move a game object instance through the script component:
|
|
888
|
+
* function init(self)
|
|
889
|
+
* -- set initial velocity to be 1 along world x-axis
|
|
890
|
+
* self.my_velocity = vmath.vector3(1, 0, 0)
|
|
891
|
+
* end
|
|
892
|
+
*
|
|
893
|
+
* function update(self, dt)
|
|
894
|
+
* -- move the game object instance
|
|
895
|
+
* go.set_position(go.get_position() + dt * self.my_velocity)
|
|
896
|
+
* end
|
|
897
|
+
* ```
|
|
898
|
+
*/
|
|
82
899
|
export function update(self: Opaque<"userdata">, dt: number): void;
|
|
900
|
+
/**
|
|
901
|
+
* Recalculates and updates the cached world transform immediately for the target instance
|
|
902
|
+
* and its ancestors (parent chain up to the collection root). Descendants (children) are
|
|
903
|
+
* not updated by this function.
|
|
904
|
+
* If no id is provided, the instance of the calling script is used.
|
|
905
|
+
* Use this after changing local transform mid-frame when you need the
|
|
906
|
+
* new world transform right away (e.g. before end-of-frame updates). Note that child
|
|
907
|
+
* instances will still have last-frame world transforms until the regular update.
|
|
908
|
+
*
|
|
909
|
+
* @param id - optional id of the game object instance to update
|
|
910
|
+
* @example
|
|
911
|
+
* ```lua
|
|
912
|
+
* Update this game object's world transform:
|
|
913
|
+
* go.update_world_transform()
|
|
914
|
+
*
|
|
915
|
+
* Update another game object's world transform:
|
|
916
|
+
* go.update_world_transform("/other")
|
|
917
|
+
* ```
|
|
918
|
+
*/
|
|
83
919
|
export function update_world_transform(id?: string | Hash | Url): void;
|
|
920
|
+
/**
|
|
921
|
+
* The function uses world transformation calculated at the end of previous frame.
|
|
922
|
+
*
|
|
923
|
+
* @param position - position which need to be converted
|
|
924
|
+
* @param url - url of the game object which coordinate system convert to
|
|
925
|
+
* @returns converted position
|
|
926
|
+
* @example
|
|
927
|
+
* ```lua
|
|
928
|
+
* Convert position of "test" game object into coordinate space of "child" object.
|
|
929
|
+
* local test_pos = go.get_world_position("/test")
|
|
930
|
+
* local child_pos = go.get_world_position("/child")
|
|
931
|
+
* local new_position = go.world_to_local_position(test_pos, "/child")
|
|
932
|
+
* ```
|
|
933
|
+
*/
|
|
84
934
|
export function world_to_local_position(position: Vector3, url: string | Hash | Url): Vector3;
|
|
935
|
+
/**
|
|
936
|
+
* The function uses world transformation calculated at the end of previous frame.
|
|
937
|
+
*
|
|
938
|
+
* @param transformation - transformation which need to be converted
|
|
939
|
+
* @param url - url of the game object which coordinate system convert to
|
|
940
|
+
* @returns converted transformation
|
|
941
|
+
* @example
|
|
942
|
+
* ```lua
|
|
943
|
+
* Convert transformation of "test" game object into coordinate space of "child" object.
|
|
944
|
+
* local test_transform = go.get_world_transform("/test")
|
|
945
|
+
* local child_transform = go.get_world_transform("/child")
|
|
946
|
+
* local result_transform = go.world_to_local_transform(test_transform, "/child")
|
|
947
|
+
* ```
|
|
948
|
+
*/
|
|
85
949
|
export function world_to_local_transform(transformation: Matrix4, url: string | Hash | Url): Matrix4;
|
|
86
950
|
export { _delete as delete };
|
|
87
951
|
export interface properties {
|
|
952
|
+
/**
|
|
953
|
+
* The rotation of the game object expressed in Euler angles.
|
|
954
|
+
* Euler angles are specified in degrees in the interval (-360, 360).
|
|
955
|
+
* The type of the property is vector3.
|
|
956
|
+
*/
|
|
88
957
|
euler: Vector3;
|
|
958
|
+
/**
|
|
959
|
+
* The position of the game object.
|
|
960
|
+
* The type of the property is vector3.
|
|
961
|
+
*/
|
|
89
962
|
position: Vector3;
|
|
963
|
+
/**
|
|
964
|
+
* The rotation of the game object.
|
|
965
|
+
* The type of the property is quaternion.
|
|
966
|
+
*/
|
|
90
967
|
rotation: Quaternion;
|
|
968
|
+
/**
|
|
969
|
+
* The uniform scale of the game object. The type of the property is number.
|
|
970
|
+
*/
|
|
91
971
|
scale: number;
|
|
92
972
|
}
|
|
93
973
|
}
|