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