@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
@@ -3,42 +3,493 @@ import type { Hash, Url, Vector3 } from "../src/core-types";
3
3
 
4
4
  declare global {
5
5
  namespace physics {
6
+ /**
7
+ * The following properties are available when connecting a joint of `JOINT_TYPE_FIXED` type:
8
+ */
6
9
  const JOINT_TYPE_FIXED: number & { readonly __brand: "physics.JOINT_TYPE_FIXED" };
10
+ /**
11
+ * The following properties are available when connecting a joint of `JOINT_TYPE_HINGE` type:
12
+ */
7
13
  const JOINT_TYPE_HINGE: number & { readonly __brand: "physics.JOINT_TYPE_HINGE" };
14
+ /**
15
+ * The following properties are available when connecting a joint of `JOINT_TYPE_SLIDER` type:
16
+ */
8
17
  const JOINT_TYPE_SLIDER: number & { readonly __brand: "physics.JOINT_TYPE_SLIDER" };
18
+ /**
19
+ * The following properties are available when connecting a joint of `JOINT_TYPE_SPRING` type:
20
+ */
9
21
  const JOINT_TYPE_SPRING: number & { readonly __brand: "physics.JOINT_TYPE_SPRING" };
22
+ /**
23
+ * The following properties are available when connecting a joint of `JOINT_TYPE_WELD` type:
24
+ */
10
25
  const JOINT_TYPE_WELD: number & { readonly __brand: "physics.JOINT_TYPE_WELD" };
26
+ /**
27
+ * The following properties are available when connecting a joint of `JOINT_TYPE_WHEEL` type:
28
+ */
11
29
  const JOINT_TYPE_WHEEL: number & { readonly __brand: "physics.JOINT_TYPE_WHEEL" };
12
30
  const SHAPE_TYPE_BOX: number & { readonly __brand: "physics.SHAPE_TYPE_BOX" };
13
31
  const SHAPE_TYPE_CAPSULE: number & { readonly __brand: "physics.SHAPE_TYPE_CAPSULE" };
14
32
  const SHAPE_TYPE_HULL: number & { readonly __brand: "physics.SHAPE_TYPE_HULL" };
15
33
  const SHAPE_TYPE_SPHERE: number & { readonly __brand: "physics.SHAPE_TYPE_SPHERE" };
34
+ /**
35
+ * Create a physics joint between two collision object components.
36
+ * Note: Currently only supported in 2D physics.
37
+ *
38
+ * @param joint_type - the joint type
39
+ * @param collisionobject_a - first collision object
40
+ * @param joint_id - id of the joint
41
+ * @param position_a - local position where to attach the joint on the first collision object
42
+ * @param collisionobject_b - second collision object
43
+ * @param position_b - local position where to attach the joint on the second collision object
44
+ * @param properties - optional joint specific properties table
45
+ See each joint type for possible properties field. The one field that is accepted for all joint types is:
46
+ - boolean `collide_connected`: Set this flag to true if the attached bodies should collide.
47
+ */
16
48
  function create_joint(joint_type: number, collisionobject_a: string | Hash | Url, joint_id: string | Hash, position_a: Vector3, collisionobject_b: string | Hash | Url, position_b: Vector3, properties?: Record<string | number, unknown>): void;
49
+ /**
50
+ * Destroy an already physics joint. The joint has to be created before a
51
+ * destroy can be issued.
52
+ * Note: Currently only supported in 2D physics.
53
+ *
54
+ * @param collisionobject - collision object where the joint exist
55
+ * @param joint_id - id of the joint
56
+ */
17
57
  function destroy_joint(collisionobject: string | Hash | Url, joint_id: string | Hash): void;
58
+ /**
59
+ * Get the gravity in runtime. The gravity returned is not global, it will return
60
+ * the gravity for the collection that the function is called from.
61
+ * Note: For 2D physics the z component will always be zero.
62
+ *
63
+ * @returns gravity vector of collection
64
+ * @example
65
+ * ```lua
66
+ * function init(self)
67
+ * local gravity = physics.get_gravity()
68
+ * -- Inverse gravity!
69
+ * gravity = -gravity
70
+ * physics.set_gravity(gravity)
71
+ * end
72
+ * ```
73
+ */
18
74
  function get_gravity(): Vector3;
75
+ /**
76
+ * Returns the group name of a collision object as a hash.
77
+ *
78
+ * @param url - the collision object to return the group of.
79
+ * @returns hash value of the group.
80
+ `local function check_is_enemy()
81
+ local group = physics.get_group("#collisionobject")
82
+ return group == hash("enemy")
83
+ end
84
+ `
85
+ */
19
86
  function get_group(url: string | Hash | Url): Hash;
87
+ /**
88
+ * Get a table for properties for a connected joint. The joint has to be created before
89
+ * properties can be retrieved.
90
+ * Note: Currently only supported in 2D physics.
91
+ *
92
+ * @param collisionobject - collision object where the joint exist
93
+ * @param joint_id - id of the joint
94
+ * @returns properties table. See the joint types for what fields are available, the only field available for all types is:
95
+ - boolean `collide_connected`: Set this flag to true if the attached bodies should collide.
96
+ */
20
97
  function get_joint_properties(collisionobject: string | Hash | Url, joint_id: string | Hash): { collide_connected: boolean };
98
+ /**
99
+ * Get the reaction force for a joint. The joint has to be created before
100
+ * the reaction force can be calculated.
101
+ * Note: Currently only supported in 2D physics.
102
+ *
103
+ * @param collisionobject - collision object where the joint exist
104
+ * @param joint_id - id of the joint
105
+ * @returns reaction force for the joint
106
+ */
21
107
  function get_joint_reaction_force(collisionobject: string | Hash | Url, joint_id: string | Hash): Vector3;
108
+ /**
109
+ * Get the reaction torque for a joint. The joint has to be created before
110
+ * the reaction torque can be calculated.
111
+ * Note: Currently only supported in 2D physics.
112
+ *
113
+ * @param collisionobject - collision object where the joint exist
114
+ * @param joint_id - id of the joint
115
+ * @returns the reaction torque on bodyB in N*m.
116
+ */
22
117
  function get_joint_reaction_torque(collisionobject: string | Hash | Url, joint_id: string | Hash): number;
118
+ /**
119
+ * Returns true if the specified group is set in the mask of a collision
120
+ * object, false otherwise.
121
+ *
122
+ * @param url - the collision object to check the mask of.
123
+ * @param group - the name of the group to check for.
124
+ * @returns boolean value of the maskbit. 'true' if present, 'false' otherwise.
125
+ `local function is_invincible()
126
+ -- check if the collisionobject would collide with the "bullet" group
127
+ local invincible = physics.get_maskbit("#collisionobject", "bullet")
128
+ return invincible
129
+ end
130
+ `
131
+ */
23
132
  function get_maskbit(url: string | Hash | Url, group: string): boolean;
133
+ /**
134
+ * Gets collision shape data from a collision object
135
+ *
136
+ * @param url - the collision object.
137
+ * @param shape - the name of the shape to get data for.
138
+ * @returns A table containing meta data about the physics shape
139
+ `type`
140
+ number The shape type. Supported values:
141
+ - `physics.SHAPE_TYPE_SPHERE`
142
+ - `physics.SHAPE_TYPE_BOX`
143
+ - `physics.SHAPE_TYPE_CAPSULE` *Only supported for 3D physics*
144
+ - `physics.SHAPE_TYPE_HULL`
145
+ The returned table contains different fields depending on which type the shape is.
146
+ If the shape is a sphere:
147
+ `diameter`
148
+ number the diameter of the sphere shape
149
+ If the shape is a box:
150
+ `dimensions`
151
+ vector3 a `vmath.vector3` of the box dimensions
152
+ If the shape is a capsule:
153
+ `diameter`
154
+ number the diameter of the capsule poles
155
+ `height`
156
+ number the height of the capsule
157
+ `local function get_shape_meta()
158
+ local sphere = physics.get_shape("#collisionobject", "my_sphere_shape")
159
+ -- returns a table with sphere.diameter
160
+ return sphere
161
+ end
162
+ `
163
+ */
24
164
  function get_shape(url: string | Hash | Url, shape: string | Hash): { type: number; diameter: number; dimensions: Vector3; diameter: number; height: number };
165
+ /**
166
+ * Ray casts are used to test for intersections against collision objects in the physics world.
167
+ * Collision objects of types kinematic, dynamic and static are tested against. Trigger objects
168
+ * do not intersect with ray casts.
169
+ * Which collision objects to hit is filtered by their collision groups and can be configured
170
+ * through `groups`.
171
+ * NOTE: Ray casts will ignore collision objects that contain the starting point of the ray. This is a limitation in Box2D.
172
+ *
173
+ * @param from - the world position of the start of the ray
174
+ * @param to - the world position of the end of the ray
175
+ * @param groups - a lua table containing the hashed groups for which to test collisions against
176
+ * @param options - a lua table containing options for the raycast.
177
+ `all`
178
+ boolean Set to `true` to return all ray cast hits. If `false`, it will only return the closest hit.
179
+ * @returns It returns a list. If missed it returns `nil`. See ray_cast_response for details on the returned values.
180
+ * @example
181
+ * ```lua
182
+ * How to perform a ray cast synchronously:
183
+ * function init(self)
184
+ * self.groups = {hash("world"), hash("enemy")}
185
+ * end
186
+ *
187
+ * function update(self, dt)
188
+ * -- request ray cast
189
+ * local result = physics.raycast(from, to, self.groups, {all=true})
190
+ * if result ~= nil then
191
+ * -- act on the hit (see 'ray_cast_response')
192
+ * for _,result in ipairs(results) do
193
+ * handle_result(result)
194
+ * end
195
+ * end
196
+ * end
197
+ * ```
198
+ */
25
199
  function raycast(from: Vector3, to: Vector3, groups: Record<string | number, unknown>, options?: { all?: boolean }): Record<string | number, unknown> | unknown;
200
+ /**
201
+ * Ray casts are used to test for intersections against collision objects in the physics world.
202
+ * Collision objects of types kinematic, dynamic and static are tested against. Trigger objects
203
+ * do not intersect with ray casts.
204
+ * Which collision objects to hit is filtered by their collision groups and can be configured
205
+ * through `groups`.
206
+ * The actual ray cast will be performed during the physics-update.
207
+ * - If an object is hit, the result will be reported via a ray_cast_response message.
208
+ * - If there is no object hit, the result will be reported via a ray_cast_missed message.
209
+ * NOTE: Ray casts will ignore collision objects that contain the starting point of the ray. This is a limitation in Box2D.
210
+ *
211
+ * @param from - the world position of the start of the ray
212
+ * @param to - the world position of the end of the ray
213
+ * @param groups - a lua table containing the hashed groups for which to test collisions against
214
+ * @param request_id - a number in range [0,255]. It will be sent back in the response for identification, 0 by default
215
+ * @example
216
+ * ```lua
217
+ * How to perform a ray cast asynchronously:
218
+ * function init(self)
219
+ * self.my_groups = {hash("my_group1"), hash("my_group2")}
220
+ * end
221
+ *
222
+ * function update(self, dt)
223
+ * -- request ray cast
224
+ * physics.raycast_async(my_start, my_end, self.my_groups)
225
+ * end
226
+ *
227
+ * function on_message(self, message_id, message, sender)
228
+ * -- check for the response
229
+ * if message_id == hash("ray_cast_response") then
230
+ * -- act on the hit
231
+ * elseif message_id == hash("ray_cast_missed") then
232
+ * -- act on the miss
233
+ * end
234
+ * end
235
+ * ```
236
+ */
26
237
  function raycast_async(from: Vector3, to: Vector3, groups: Record<string | number, unknown>, request_id?: number): void;
238
+ /**
239
+ * Only one physics world event listener can be set at a time.
240
+ *
241
+ * @param callback - A callback that receives an information about all the physics interactions in this physics world.
242
+ `self`
243
+ object The calling script
244
+ `event`
245
+ constant The type of event. Can be one of these messages:
246
+ - contact_point_event
247
+ - collision_event
248
+ - trigger_event
249
+ - ray_cast_response
250
+ - ray_cast_missed
251
+ `data`
252
+ table The callback value data is a table that contains event-related data. See the documentation for details on the messages.
253
+ * @example
254
+ * ```lua
255
+ * local function physics_world_listener(self, events)
256
+ * for _,event in ipairs(events):
257
+ * local event_type = event['type']
258
+ * if event_type == hash("contact_point_event") then
259
+ * pprint(event)
260
+ * -- {
261
+ * -- distance = 2.1490633487701,
262
+ * -- applied_impulse = 0
263
+ * -- a = { --[[0x113f7c6c0]]
264
+ * -- group = hash: [box],
265
+ * -- id = hash: [/box]
266
+ * -- mass = 0,
267
+ * -- normal = vmath.vector3(0.379, 0.925, -0),
268
+ * -- position = vmath.vector3(517.337, 235.068, 0),
269
+ * -- instance_position = vmath.vector3(480, 144, 0),
270
+ * -- relative_velocity = vmath.vector3(-0, -0, -0),
271
+ * -- },
272
+ * -- b = { --[[0x113f7c840]]
273
+ * -- group = hash: [circle],
274
+ * -- id = hash: [/circle]
275
+ * -- mass = 0,
276
+ * -- normal = vmath.vector3(-0.379, -0.925, 0),
277
+ * -- position = vmath.vector3(517.337, 235.068, 0),
278
+ * -- instance_position = vmath.vector3(-0.0021, 0, -0.0022),
279
+ * -- relative_velocity = vmath.vector3(0, 0, 0),
280
+ * -- },
281
+ * -- }
282
+ * elseif event == hash("collision_event") then
283
+ * pprint(event)
284
+ * -- {
285
+ * -- a = {
286
+ * -- group = hash: [default],
287
+ * -- position = vmath.vector3(183, 666, 0),
288
+ * -- id = hash: [/go1]
289
+ * -- },
290
+ * -- b = {
291
+ * -- group = hash: [default],
292
+ * -- position = vmath.vector3(185, 704.05865478516, 0),
293
+ * -- id = hash: [/go2]
294
+ * -- }
295
+ * -- }
296
+ * elseif event == hash("trigger_event") then
297
+ * pprint(event)
298
+ * -- {
299
+ * -- enter = true,
300
+ * -- b = {
301
+ * -- group = hash: [default],
302
+ * -- id = hash: [/go2]
303
+ * -- },
304
+ * -- a = {
305
+ * -- group = hash: [default],
306
+ * -- id = hash: [/go1]
307
+ * -- }
308
+ * -- },
309
+ * elseif event == hash("ray_cast_response") then
310
+ * pprint(event)
311
+ * --{
312
+ * -- group = hash: [default],
313
+ * -- request_id = 0,
314
+ * -- position = vmath.vector3(249.92222595215, 249.92222595215, 0),
315
+ * -- fraction = 0.68759721517563,
316
+ * -- normal = vmath.vector3(0, 1, 0),
317
+ * -- id = hash: [/go]
318
+ * -- }
319
+ * elseif event == hash("ray_cast_missed") then
320
+ * pprint(event)
321
+ * -- {
322
+ * -- request_id = 0
323
+ * --},
324
+ * end
325
+ * end
326
+ *
327
+ * function init(self)
328
+ * physics.set_event_listener(physics_world_listener)
329
+ * end
330
+ * ```
331
+ */
27
332
  function set_event_listener(callback?: (self: unknown, events: unknown) => void): void;
333
+ /**
334
+ * Set the gravity in runtime. The gravity change is not global, it will only affect
335
+ * the collection that the function is called from.
336
+ * Note: For 2D physics the z component of the gravity vector will be ignored.
337
+ *
338
+ * @param gravity - the new gravity vector
339
+ * @example
340
+ * ```lua
341
+ * function init(self)
342
+ * -- Set "upside down" gravity for this collection.
343
+ * physics.set_gravity(vmath.vector3(0, 10.0, 0))
344
+ * end
345
+ * ```
346
+ */
28
347
  function set_gravity(gravity: Vector3): void;
348
+ /**
349
+ * Updates the group property of a collision object to the specified
350
+ * string value. The group name should exist i.e. have been used in
351
+ * a collision object in the editor.
352
+ *
353
+ * @param url - the collision object affected.
354
+ * @param group - the new group name to be assigned.
355
+ `local function change_collision_group()
356
+ physics.set_group("#collisionobject", "enemy")
357
+ end
358
+ `
359
+ */
29
360
  function set_group(url: string | Hash | Url, group: string): void;
361
+ /**
362
+ * Flips the collision shapes horizontally for a collision object
363
+ *
364
+ * @param url - the collision object that should flip its shapes
365
+ * @param flip - `true` if the collision object should flip its shapes, `false` if not
366
+ * @example
367
+ * ```lua
368
+ * function init(self)
369
+ * self.fliph = true -- set on some condition
370
+ * physics.set_hflip("#collisionobject", self.fliph)
371
+ * end
372
+ * ```
373
+ */
30
374
  function set_hflip(url: string | Hash | Url, flip: boolean): void;
375
+ /**
376
+ * Updates the properties for an already connected joint. The joint has to be created before
377
+ * properties can be changed.
378
+ * Note: Currently only supported in 2D physics.
379
+ *
380
+ * @param collisionobject - collision object where the joint exist
381
+ * @param joint_id - id of the joint
382
+ * @param properties - joint specific properties table
383
+ Note: The `collide_connected` field cannot be updated/changed after a connection has been made.
384
+ */
31
385
  function set_joint_properties(collisionobject: string | Hash | Url, joint_id: string | Hash, properties: Record<string | number, unknown>): void;
386
+ /**
387
+ * Sets or clears the masking of a group (maskbit) in a collision object.
388
+ *
389
+ * @param url - the collision object to change the mask of.
390
+ * @param group - the name of the group (maskbit) to modify in the mask.
391
+ * @param maskbit - boolean value of the new maskbit. 'true' to enable, 'false' to disable.
392
+ `local function make_invincible()
393
+ -- no longer collide with the "bullet" group
394
+ physics.set_maskbit("#collisionobject", "bullet", false)
395
+ end
396
+ `
397
+ */
32
398
  function set_maskbit(url: string | Hash | Url, group: string, maskbit: boolean): void;
399
+ /**
400
+ * Sets collision shape data for a collision object. Please note that updating data in 3D
401
+ * can be quite costly for box and capsules. Because of the physics engine, the cost
402
+ * comes from having to recreate the shape objects when certain shapes needs to be updated.
403
+ *
404
+ * @param url - the collision object.
405
+ * @param shape - the name of the shape to get data for.
406
+ * @param table - the shape data to update the shape with.
407
+ See physics.get_shape for a detailed description of each field in the data table.
408
+ `local function set_shape_data()
409
+ -- set capsule shape data
410
+ local data = {}
411
+ data.type = physics.SHAPE_TYPE_CAPSULE
412
+ data.diameter = 10
413
+ data.height = 20
414
+ physics.set_shape("#collisionobject", "my_capsule_shape", data)
415
+ -- set sphere shape data
416
+ data = {}
417
+ data.type = physics.SHAPE_TYPE_SPHERE
418
+ data.diameter = 10
419
+ physics.set_shape("#collisionobject", "my_sphere_shape", data)
420
+ -- set box shape data
421
+ data = {}
422
+ data.type = physics.SHAPE_TYPE_BOX
423
+ data.dimensions = vmath.vector3(10, 10, 5)
424
+ physics.set_shape("#collisionobject", "my_box_shape", data)
425
+ end
426
+ `
427
+ */
33
428
  function set_shape(url: string | Hash | Url, shape: string | Hash, table: { type?: number; diameter?: number; dimensions?: Vector3; diameter?: number; height?: number }): void;
429
+ /**
430
+ * Flips the collision shapes vertically for a collision object
431
+ *
432
+ * @param url - the collision object that should flip its shapes
433
+ * @param flip - `true` if the collision object should flip its shapes, `false` if not
434
+ * @example
435
+ * ```lua
436
+ * function init(self)
437
+ * self.flipv = true -- set on some condition
438
+ * physics.set_vflip("#collisionobject", self.flipv)
439
+ * end
440
+ * ```
441
+ */
34
442
  function set_vflip(url: string | Hash | Url, flip: boolean): void;
443
+ /**
444
+ * The function recalculates the density of each shape based on the total area of all shapes and the specified mass, then updates the mass of the body accordingly.
445
+ * Note: Currently only supported in 2D physics.
446
+ *
447
+ * @param collisionobject - the collision object whose mass needs to be updated.
448
+ * @param mass - the new mass value to set for the collision object.
449
+ * @example
450
+ * ```lua
451
+ * physics.update_mass("#collisionobject", 14)
452
+ * ```
453
+ */
35
454
  function update_mass(collisionobject: string | Hash | Url, mass: number): void;
455
+ /**
456
+ * Collision objects tend to fall asleep when inactive for a small period of time for
457
+ * efficiency reasons. This function wakes them up.
458
+ *
459
+ * @param url - the collision object to wake.
460
+ `function on_input(self, action_id, action)
461
+ if action_id == hash("test") and action.pressed then
462
+ physics.wakeup("#collisionobject")
463
+ end
464
+ end
465
+ `
466
+ */
36
467
  function wakeup(url: string | Hash | Url): void;
37
468
  interface properties {
469
+ /**
470
+ * The angular damping value for the collision object. Setting this value alters the damping of
471
+ * angular motion of the object (rotation). Valid values are between 0 (no damping) and 1 (full damping).
472
+ */
38
473
  angular_damping: number;
474
+ /**
475
+ * The current angular velocity of the collision object component as a vector3.
476
+ * The velocity is measured as a rotation around the vector with a speed equivalent to the vector length
477
+ * in radians/s.
478
+ */
39
479
  angular_velocity: Vector3;
480
+ /**
481
+ * The linear damping value for the collision object. Setting this value alters the damping of
482
+ * linear motion of the object. Valid values are between 0 (no damping) and 1 (full damping).
483
+ */
40
484
  linear_damping: number;
485
+ /**
486
+ * The current linear velocity of the collision object component as a vector3.
487
+ * The velocity is measured in units/s (pixels/s).
488
+ */
41
489
  linear_velocity: Vector3;
490
+ /**
491
+ * READ ONLY Returns the defined physical mass of the collision object component as a number.
492
+ */
42
493
  mass: number;
43
494
  }
44
495
  }