emeraldengine 3.0.0 → 3.1.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 (103) hide show
  1. package/README.md +1498 -1659
  2. package/dist/types/index.d.ts +4 -1
  3. package/dist/types/src/Animator.d.ts +1 -1
  4. package/dist/types/src/CollisionLayers.d.ts +2 -2
  5. package/dist/types/src/Color.d.ts +1 -0
  6. package/dist/types/src/Drawable.d.ts +1 -1
  7. package/dist/types/src/EmeraldDB.d.ts +2 -2
  8. package/dist/types/src/InstancedTexture.d.ts +17 -2
  9. package/dist/types/src/Material.d.ts +2 -2
  10. package/dist/types/src/MathUtils.d.ts +2 -1
  11. package/dist/types/src/ParticleEmitter.d.ts +1 -1
  12. package/dist/types/src/Physics.d.ts +148 -18
  13. package/dist/types/src/Scene.d.ts +1 -1
  14. package/dist/types/src/Shaders.d.ts +2 -2
  15. package/dist/types/src/Tilemap.d.ts +1 -1
  16. package/dist/types/src/UI.d.ts +1 -1
  17. package/dist/types/src/components/Behaviour.d.ts +2 -2
  18. package/dist/types/src/components/Collider.d.ts +7 -1
  19. package/dist/types/src/components/GameObject.d.ts +2 -2
  20. package/dist/types/src/components/PolygonCollider.d.ts +33 -0
  21. package/dist/types/src/components/RigidBody.d.ts +281 -8
  22. package/dist/types/src/importers/Aseprite.d.ts +2 -2
  23. package/dist/types/src/importers/ForgeLevel.d.ts +97 -0
  24. package/dist/types/src/importers/TiledMap.d.ts +1 -1
  25. package/dist/types/src/managers/EventManager.d.ts +1 -1
  26. package/dist/types/src/managers/Gamepad.d.ts +102 -0
  27. package/dist/types/src/managers/InputManager.d.ts +93 -2
  28. package/dist/types/src/managers/NetworkManager.d.ts +2 -2
  29. package/dist/types/src/managers/RenderStats.d.ts +1 -1
  30. package/dist/types/src/managers/TextureManager.d.ts +1 -1
  31. package/dist/types/src/physics/AABB.d.ts +92 -0
  32. package/dist/types/src/physics/Body.d.ts +435 -0
  33. package/dist/types/src/physics/BodyType.d.ts +6 -0
  34. package/dist/types/src/physics/BroadPhase.d.ts +210 -0
  35. package/dist/types/src/physics/Collision.d.ts +102 -0
  36. package/dist/types/src/physics/Contact.d.ts +206 -0
  37. package/dist/types/src/physics/ContactSolver.d.ts +108 -0
  38. package/dist/types/src/physics/Distance.d.ts +54 -0
  39. package/dist/types/src/physics/DistanceJoint.d.ts +90 -0
  40. package/dist/types/src/physics/Fixture.d.ts +221 -0
  41. package/dist/types/src/physics/Island.d.ts +52 -0
  42. package/dist/types/src/physics/Joint.d.ts +59 -0
  43. package/dist/types/src/physics/Math2D.d.ts +371 -0
  44. package/dist/types/src/physics/RevoluteJoint.d.ts +119 -0
  45. package/dist/types/src/physics/Settings.d.ts +22 -0
  46. package/dist/types/src/physics/Shapes.d.ts +207 -0
  47. package/dist/types/src/physics/TimeOfImpact.d.ts +22 -0
  48. package/dist/types/src/physics/World.d.ts +274 -0
  49. package/dist/types/src/physics/index.d.ts +34 -0
  50. package/index.js +6 -0
  51. package/package.json +2 -3
  52. package/src/Animator.js +1 -1
  53. package/src/CollisionLayers.js +3 -3
  54. package/src/Color.js +8 -0
  55. package/src/Drawable.js +1 -1
  56. package/src/Emerald.js +1 -1
  57. package/src/EmeraldDB.js +2 -2
  58. package/src/InstancedTexture.js +57 -9
  59. package/src/Material.js +2 -2
  60. package/src/MathUtils.js +2 -1
  61. package/src/ParticleEmitter.js +1 -1
  62. package/src/Physics.js +270 -60
  63. package/src/Scene.js +1 -1
  64. package/src/Shaders.js +20 -20
  65. package/src/Tilemap.js +1 -1
  66. package/src/UI.js +1 -1
  67. package/src/components/Behaviour.js +2 -2
  68. package/src/components/BoxCollider.js +7 -9
  69. package/src/components/BoxColliderDebug.js +3 -4
  70. package/src/components/CircleCollider.js +7 -9
  71. package/src/components/CircleColliderDebug.js +3 -2
  72. package/src/components/Collider.js +13 -3
  73. package/src/components/GameObject.js +2 -2
  74. package/src/components/PolygonCollider.js +55 -0
  75. package/src/components/RigidBody.js +441 -14
  76. package/src/importers/Aseprite.js +2 -2
  77. package/src/importers/ForgeLevel.js +581 -0
  78. package/src/importers/TiledMap.js +1 -1
  79. package/src/managers/EventManager.js +1 -1
  80. package/src/managers/Gamepad.js +126 -0
  81. package/src/managers/InputManager.js +129 -3
  82. package/src/managers/NetworkManager.js +2 -2
  83. package/src/managers/RenderStats.js +1 -1
  84. package/src/managers/TextureManager.js +1 -1
  85. package/src/physics/AABB.js +207 -0
  86. package/src/physics/Body.js +862 -0
  87. package/src/physics/BodyType.js +16 -0
  88. package/src/physics/BroadPhase.js +641 -0
  89. package/src/physics/Collision.js +534 -0
  90. package/src/physics/Contact.js +500 -0
  91. package/src/physics/ContactSolver.js +526 -0
  92. package/src/physics/Distance.js +403 -0
  93. package/src/physics/DistanceJoint.js +227 -0
  94. package/src/physics/Fixture.js +346 -0
  95. package/src/physics/Island.js +203 -0
  96. package/src/physics/Joint.js +78 -0
  97. package/src/physics/Math2D.js +573 -0
  98. package/src/physics/RevoluteJoint.js +278 -0
  99. package/src/physics/Settings.js +78 -0
  100. package/src/physics/Shapes.js +549 -0
  101. package/src/physics/TimeOfImpact.js +87 -0
  102. package/src/physics/World.js +731 -0
  103. package/src/physics/index.js +79 -0
@@ -1,6 +1,12 @@
1
1
  export default RigidBody;
2
2
  /**
3
3
  * @class RigidBody
4
+ * @description The game-facing physics body: everything you can do to a body
5
+ * (move it, push it, spin it, sleep it, query its mass) is a method on this
6
+ * class directly, in world/pixel units. There is no separate lower-level
7
+ * body object you need to fetch first. `getBody()` still returns the raw,
8
+ * physics-unit {@link Body} underneath for the rare case you need it (writing
9
+ * a custom joint, say), but nothing in ordinary use requires it.
4
10
  * @param {Physics} physics - The physics engine
5
11
  * @param {string | "static" | "dynamic" | "kinematic"} type - The type of rigidbody
6
12
  * @param {Vector2} position - The position of the rigidbody
@@ -19,12 +25,30 @@ declare class RigidBody {
19
25
  collider: Collider;
20
26
  id: string;
21
27
  name: string;
28
+ /** Freely usable by your own code; see {@link RigidBody#getUserData}. */
29
+ userData: any;
22
30
  /**
23
31
  * @method updatePosition
24
32
  * @description Updates the position of the rigidbody
25
33
  * @param {Vector2} position - The new position
26
34
  */
27
35
  updatePosition(position: Vector2): void;
36
+ /**
37
+ * @method setPosition
38
+ * @description Alias of {@link RigidBody#updatePosition}, named to match
39
+ * `setRotation`/`setTransform`.
40
+ * @param {Vector2} position - The new position, in world (pixel) units
41
+ */
42
+ setPosition(position: Vector2): void;
43
+ /**
44
+ * @method setTransform
45
+ * @description Teleports the body to a new position and angle in one move
46
+ * (no velocity implied), and wakes it so contacts at the new spot are seen
47
+ * on the very next step.
48
+ * @param {Vector2} position - World (pixel) units
49
+ * @param {number} angle - Radians
50
+ */
51
+ setTransform(position: Vector2, angle: number): void;
28
52
  /**
29
53
  * @method getWorldX
30
54
  * @description The single source of truth for body(physics) -> world(pixel)
@@ -61,6 +85,23 @@ declare class RigidBody {
61
85
  * @param {Collider} collider - The collider to set
62
86
  */
63
87
  setCollider(collider: Collider): void;
88
+ /**
89
+ * @method createFixture
90
+ * @description Attaches a shape directly, bypassing the Collider component
91
+ * classes ({@link BoxCollider}, {@link CircleCollider}, {@link PolygonCollider})
92
+ * that normally build one for you. `shape` is a physics-unit shape (e.g. from
93
+ * `Box()`/`Circle()`/`new PolygonShape()`), not pixels.
94
+ * @param {Shape} shape
95
+ * @param {Object|number} [def] - `{ density, friction, restitution, isSensor, ... }`
96
+ * @returns {Fixture}
97
+ */
98
+ createFixture(shape: Shape, def?: any | number): Fixture;
99
+ /**
100
+ * @method destroyFixture
101
+ * @description Removes a fixture created with {@link RigidBody#createFixture}.
102
+ * @param {Fixture} fixture
103
+ */
104
+ destroyFixture(fixture: Fixture): void;
64
105
  /**
65
106
  * @method setRotation
66
107
  * @description Sets the rotation of the rigidbody
@@ -84,26 +125,127 @@ declare class RigidBody {
84
125
  x: number;
85
126
  y: number;
86
127
  };
128
+ /**
129
+ * @method getLinearVelocityFromWorldPoint
130
+ * @description The velocity (world units/sec) of the material point of this
131
+ * body currently at `worldPoint`: linear velocity plus the contribution
132
+ * from spin. Useful for e.g. where a spinning platform's edge is moving.
133
+ * @param {Object} worldPoint - World (pixel) units
134
+ * @returns {Vector2}
135
+ */
136
+ getLinearVelocityFromWorldPoint(worldPoint: any): Vector2;
137
+ /**
138
+ * @method setAngularVelocity
139
+ * @description Sets the body's spin, in radians per second.
140
+ * @param {number} omega
141
+ */
142
+ setAngularVelocity(omega: number): void;
143
+ /**
144
+ * @method getAngularVelocity
145
+ * @description Returns the body's spin, in radians per second.
146
+ * @returns {number}
147
+ */
148
+ getAngularVelocity(): number;
87
149
  /**
88
150
  * @method applyImpulse
89
- * @description Applies a linear impulse (world units) at the body's center.
151
+ * @description Applies an instantaneous change in momentum (world units).
152
+ * This is what a jump or a knockback should use, since (unlike a force) it
153
+ * takes effect immediately rather than accumulating over the step.
90
154
  * @param {number} ix
91
155
  * @param {number} iy
156
+ * @param {Object} [point] - World (pixel) point to apply it at; defaults to
157
+ * the center of mass (no torque)
158
+ * @param {boolean} [wake=true]
159
+ */
160
+ applyImpulse(ix: number, iy: number, point?: any, wake?: boolean): void;
161
+ /**
162
+ * @method applyAngularImpulse
163
+ * @description Applies an instantaneous change in angular momentum.
164
+ * @param {number} impulse
165
+ * @param {boolean} [wake=true]
166
+ */
167
+ applyAngularImpulse(impulse: number, wake?: boolean): void;
168
+ /**
169
+ * @method applyForce
170
+ * @description Applies a force (world units) at a world point. Forces
171
+ * accumulate and are cleared at the end of every step, so this belongs in
172
+ * your update loop, unlike an impulse.
173
+ * @param {number} fx
174
+ * @param {number} fy
175
+ * @param {Object} [point] - World (pixel) point; defaults to the center of
176
+ * mass (no torque)
177
+ * @param {boolean} [wake=true]
178
+ */
179
+ applyForce(fx: number, fy: number, point?: any, wake?: boolean): void;
180
+ /**
181
+ * @method applyForceToCenter
182
+ * @description Applies a force (world units) at the center of mass: no
183
+ * torque, unlike {@link RigidBody#applyForce} with a point.
184
+ * @param {number} fx
185
+ * @param {number} fy
186
+ * @param {boolean} [wake=true]
92
187
  */
93
- applyImpulse(ix: number, iy: number): void;
188
+ applyForceToCenter(fx: number, fy: number, wake?: boolean): void;
189
+ /**
190
+ * @method applyTorque
191
+ * @description Applies a torque about the center of mass.
192
+ * @param {number} torque
193
+ * @param {boolean} [wake=true]
194
+ */
195
+ applyTorque(torque: number, wake?: boolean): void;
94
196
  /**
95
197
  * @method setAwake
96
198
  * @description Wakes or sleeps the body.
97
199
  * @param {boolean} awake
98
200
  */
99
201
  setAwake(awake: boolean): void;
202
+ /**
203
+ * @method isAwake
204
+ * @description Whether the body is currently simulated.
205
+ * @returns {boolean}
206
+ */
207
+ isAwake(): boolean;
208
+ /**
209
+ * @method setSleepingAllowed
210
+ * @description Allows or forbids this body from ever sleeping.
211
+ * @param {boolean} flag
212
+ */
213
+ setSleepingAllowed(flag: boolean): void;
214
+ /**
215
+ * @method isSleepingAllowed
216
+ * @returns {boolean}
217
+ */
218
+ isSleepingAllowed(): boolean;
219
+ /**
220
+ * @method setActive
221
+ * @description Adds or removes the body from collision detection without
222
+ * destroying it.
223
+ * @param {boolean} flag
224
+ */
225
+ setActive(flag: boolean): void;
226
+ /**
227
+ * @method isActive
228
+ * @returns {boolean}
229
+ */
230
+ isActive(): boolean;
231
+ /**
232
+ * @method setFixedRotation
233
+ * @description Locks or unlocks the body's rotation at runtime.
234
+ * @param {boolean} flag
235
+ */
236
+ setFixedRotation(flag: boolean): void;
237
+ /**
238
+ * @method isFixedRotation
239
+ * @returns {boolean}
240
+ */
241
+ isFixedRotation(): boolean;
100
242
  /**
101
243
  * @method setContinuous
102
244
  * @description Enables continuous collision detection (CCD) for this body by
103
245
  * marking it a "bullet". Fast-moving bodies (e.g. a dash, a projectile, a
104
246
  * player falling at high speed) otherwise sweep so far in a single fixed step
105
- * that they tunnel straight through thin static geometry; with CCD on, planck
106
- * solves the swept path against static bodies so the body stops at the wall
247
+ * that they tunnel straight through thin static geometry; with CCD on, the
248
+ * engine sweeps the body against static geometry so it stops at the wall
107
249
  * instead of teleporting past it. Costs more per step, so reserve it for the
108
250
  * handful of bodies that actually move fast.
109
251
  * @param {boolean} [enabled=true]
@@ -116,6 +258,126 @@ declare class RigidBody {
116
258
  * @returns {boolean}
117
259
  */
118
260
  isContinuous(): boolean;
261
+ /**
262
+ * @method setLinearDamping
263
+ * @description Sets the drag applied to linear motion each step.
264
+ * @param {number} damping
265
+ */
266
+ setLinearDamping(damping: number): void;
267
+ /**
268
+ * @method getLinearDamping
269
+ * @returns {number}
270
+ */
271
+ getLinearDamping(): number;
272
+ /**
273
+ * @method setAngularDamping
274
+ * @description Sets the drag applied to rotation each step.
275
+ * @param {number} damping
276
+ */
277
+ setAngularDamping(damping: number): void;
278
+ /**
279
+ * @method getAngularDamping
280
+ * @returns {number}
281
+ */
282
+ getAngularDamping(): number;
283
+ /**
284
+ * @method setGravityScale
285
+ * @description Scales how strongly gravity pulls on this body (0 disables
286
+ * it, 2 makes it twice as heavy-feeling).
287
+ * @param {number} scale
288
+ */
289
+ setGravityScale(scale: number): void;
290
+ /**
291
+ * @method getGravityScale
292
+ * @returns {number}
293
+ */
294
+ getGravityScale(): number;
295
+ /**
296
+ * @method getMass
297
+ * @description Returns the body's mass, in physics units (derived from its
298
+ * fixtures' shapes and densities, unaffected by the pixel scale).
299
+ * @returns {number}
300
+ */
301
+ getMass(): number;
302
+ /**
303
+ * @method getInertia
304
+ * @description Returns the body's rotational inertia about its center of
305
+ * mass, in physics units.
306
+ * @returns {number}
307
+ */
308
+ getInertia(): number;
309
+ /**
310
+ * @method resetMassData
311
+ * @description Re-derives mass/center/inertia from the body's current
312
+ * fixtures. Call this after changing a fixture's density at runtime.
313
+ */
314
+ resetMassData(): void;
315
+ /**
316
+ * @method setMassData
317
+ * @description Overrides the computed mass properties directly.
318
+ * @param {Object} massData - `{ mass, center, I }`; `center` is a world
319
+ * (pixel) offset from the body's origin
320
+ */
321
+ setMassData(massData: any): void;
322
+ /**
323
+ * @method getWorldPoint
324
+ * @description Converts a point local to this body into world (pixel) space.
325
+ * @param {Object} localPoint - World-unit offset from the body's origin
326
+ * @returns {Vector2}
327
+ */
328
+ getWorldPoint(localPoint: any): Vector2;
329
+ /**
330
+ * @method getLocalPoint
331
+ * @description Converts a world (pixel) point into this body's local frame.
332
+ * @param {Object} worldPoint - World (pixel) units
333
+ * @returns {Vector2}
334
+ */
335
+ getLocalPoint(worldPoint: any): Vector2;
336
+ /**
337
+ * @method getWorldVector
338
+ * @description Rotates a local direction (not a point, unaffected by the
339
+ * body's position) into world space.
340
+ * @param {Object} localVector
341
+ * @returns {Vector2}
342
+ */
343
+ getWorldVector(localVector: any): Vector2;
344
+ /**
345
+ * @method getLocalVector
346
+ * @description Rotates a world direction into this body's local frame.
347
+ * @param {Object} worldVector
348
+ * @returns {Vector2}
349
+ */
350
+ getLocalVector(worldVector: any): Vector2;
351
+ /**
352
+ * @method getContactList
353
+ * @description Returns the raw physics contacts this body currently takes
354
+ * part in. Each contact's `fixtureA`/`fixtureB` point at physics-unit
355
+ * fixtures/bodies, not RigidBody wrappers. Walk `fixture.body.getUserData()`
356
+ * to get back to the owning RigidBody.
357
+ * @returns {Array<Contact>}
358
+ */
359
+ getContactList(): Array<Contact>;
360
+ /**
361
+ * @method getWorld
362
+ * @description Returns the raw physics {@link World} this body lives in.
363
+ * @returns {World}
364
+ */
365
+ getWorld(): World;
366
+ /**
367
+ * @method getUserData
368
+ * @description Returns whatever you last passed to
369
+ * {@link RigidBody#setUserData}. This is separate from the underlying
370
+ * physics body's own userData slot, which the engine itself uses internally
371
+ * to route collisions back to this RigidBody, so setting it here can never
372
+ * break that.
373
+ * @returns {*}
374
+ */
375
+ getUserData(): any;
376
+ /**
377
+ * @method setUserData
378
+ * @param {*} data
379
+ */
380
+ setUserData(data: any): void;
119
381
  /**
120
382
  * @method getPosition
121
383
  * @description Returns the live world-space position of the body (kept in sync
@@ -144,10 +406,13 @@ declare class RigidBody {
144
406
  getCollider(): Collider;
145
407
  /**
146
408
  * @method getBody
147
- * @description Returns the body of the rigidbody
148
- * @returns {planck.Body} - The body of the rigidbody
409
+ * @description Returns the underlying, physics-unit {@link Body}. Nothing in
410
+ * ordinary use needs this: every common operation is a method on RigidBody
411
+ * itself, in world/pixel units, but it's here for advanced cases (writing a
412
+ * custom joint or solver hook) that need the raw physics object.
413
+ * @returns {Body} - The body of the rigidbody
149
414
  */
150
- getBody(): planck.Body;
415
+ getBody(): Body;
151
416
  /**
152
417
  * @method getPhysics
153
418
  * @description Returns the physics engine of the rigidbody
@@ -177,7 +442,15 @@ declare class RigidBody {
177
442
  * @returns {string | "static" | "dynamic" | "kinematic"} - The type of the rigidbody
178
443
  */
179
444
  getType(): string | "static" | "dynamic" | "kinematic";
445
+ /**
446
+ * @method setType
447
+ * @description Changes the body type at runtime (e.g. turning a kinematic
448
+ * moving platform into a dynamic one when it breaks apart). Resets
449
+ * velocities and re-derives mass; existing contacts are dropped so they
450
+ * rebuild against the new type.
451
+ * @param {string | "static" | "dynamic" | "kinematic"} type
452
+ */
453
+ setType(type: string | "static" | "dynamic" | "kinematic"): void;
180
454
  }
181
455
  import { Vector2 } from "../Physics.js";
182
456
  import Collider from "./Collider.js";
183
- import * as planck from "planck";
@@ -4,7 +4,7 @@ export default Aseprite;
4
4
  * @description Imports sprite-sheet metadata exported from Aseprite
5
5
  * (File ▸ Export Sprite Sheet, with "JSON Data" on) and turns its frame tags
6
6
  * into engine animation clips. Works with both the Hash and Array JSON layouts.
7
- * Pure parsing pass it the already-parsed JSON object.
7
+ * Pure parsing: pass it the already-parsed JSON object.
8
8
  *
9
9
  * Assumes the sheet is a uniform grid in frame order (the common case), so the
10
10
  * frame indices line up with the engine's Texture/Animator frame numbering.
@@ -54,7 +54,7 @@ declare class Aseprite {
54
54
  * @method toClips
55
55
  * @description Builds clip descriptors from the sheet's frame tags. Each clip
56
56
  * is `{ name, frames, speed }` where `frames` are frame indices and `speed`
57
- * is the average frame duration (ms) the per-clip speed the Animator uses.
57
+ * is the average frame duration (ms), the per-clip speed the Animator uses.
58
58
  * If the sheet has no tags, a single "default" clip spanning all frames is
59
59
  * returned.
60
60
  * @param {Object} sheet - Parsed Aseprite JSON
@@ -0,0 +1,97 @@
1
+ export default ForgeLevel;
2
+ declare class ForgeLevel {
3
+ /**
4
+ * @method load
5
+ * @description Builds renderable and collidable objects from a Forge export.
6
+ * @param {Object} data - The parsed `level.json`
7
+ * @param {Object} options
8
+ * @param {Scene} options.scene - Scene to add the layer objects to
9
+ * @param {Physics} [options.physics] - Physics engine; omit to skip colliders
10
+ * @param {Object} [options.filter] - Collision filter spec for the colliders
11
+ * @param {Object} [options.ownerObject] - Owner reported by collision events
12
+ * @param {boolean} [options.pixelart=true] - NEAREST filtering for the atlas
13
+ * @param {string} [options.layerOrder="top-first"] - Whether `layers[0]` is
14
+ * the topmost layer ("top-first") or the bottommost ("bottom-first")
15
+ * @returns {Object} - `{ tileSize, cols, rows, width, height, background,
16
+ * bounds, layers, colliders, objects, entityTypes, toWorld }`
17
+ */
18
+ static load(data: any, options?: {
19
+ scene: Scene;
20
+ physics?: Physics;
21
+ filter?: any;
22
+ ownerObject?: any;
23
+ pixelart?: boolean;
24
+ layerOrder?: string;
25
+ }): any;
26
+ /**
27
+ * @method _readObjects
28
+ * @description Converts one object layer's entries from grid cells to world
29
+ * space. An object's `x`/`y` is its top-left cell and `w`/`h` its size in
30
+ * cells, so a 1x1 object resolves to that cell's centre.
31
+ * @returns {Array<Object>} - `{ type, name, x, y, width, height, props, layer, cell }`
32
+ * @private
33
+ */
34
+ private static _readObjects;
35
+ /**
36
+ * @method _buildTileLayer
37
+ * @description Turns one tile layer into an InstancedTexture per tileset it
38
+ * references (a texture switch is a new draw call, so tiles are grouped by
39
+ * the atlas they come from).
40
+ * @returns {Array<Object>} - `{ gameObject, instanced, tileset, layer, count }`
41
+ * @private
42
+ */
43
+ private static _buildTileLayer;
44
+ /**
45
+ * @method tileTexCoords
46
+ * @description UV quad for one tile of an atlas, in the corner order
47
+ * `Drawable.getFrameTexCoords` uses: (R,B) (L,B) (R,T) (L,T). Coordinates are
48
+ * inset by half a texel so neighbouring tiles never bleed into each other,
49
+ * and the v axis is flipped because GL samples from the bottom up.
50
+ * @param {Object} tileset - A Forge tileset entry
51
+ * @param {number} index - Tile index within the tileset
52
+ * @param {boolean} [flipH=false]
53
+ * @param {boolean} [flipV=false]
54
+ * @returns {number[]} - 8 UV floats
55
+ */
56
+ static tileTexCoords(tileset: any, index: number, flipH?: boolean, flipV?: boolean): number[];
57
+ /**
58
+ * @method _tilesetFor
59
+ * @description Finds the tileset that owns a gid (the one with the largest
60
+ * firstgid not greater than it).
61
+ * @private
62
+ */
63
+ private static _tilesetFor;
64
+ /**
65
+ * @method _buildColliders
66
+ * @description Creates static bodies for solid tiles. Full-tile colliders are
67
+ * merged into horizontal runs, since BoxCollider is cheaper than a polygon
68
+ * with the same 4 corners. A tile whose collider shape isn't the full tile
69
+ * gets its own {@link PolygonCollider} built from that shape's actual
70
+ * points, in world space, not a bounding-box stand-in.
71
+ * @returns {Array<RigidBody>}
72
+ * @private
73
+ */
74
+ private static _buildColliders;
75
+ /**
76
+ * @method _staticBox
77
+ * @description Creates one static body with a box collider, in world pixels.
78
+ * @private
79
+ */
80
+ private static _staticBox;
81
+ /**
82
+ * @method _staticPolygon
83
+ * @description Creates one static body with a polygon collider built from a
84
+ * tile's own collider shape. The body sits at the shape's bounding-box
85
+ * centre; the polygon's points are converted from Forge's normalised,
86
+ * top-down tile space into local physics units around that centre.
87
+ * @private
88
+ */
89
+ private static _staticPolygon;
90
+ /**
91
+ * @method _boundsOf
92
+ * @description Normalised bounding box of a collider polygon.
93
+ * @returns {{x:number, y:number, w:number, h:number}}
94
+ * @private
95
+ */
96
+ private static _boundsOf;
97
+ }
@@ -6,7 +6,7 @@ export const GID_MASK: 536870911;
6
6
  * @description Imports orthogonal maps exported from the Tiled editor
7
7
  * (https://www.mapeditor.org) in JSON format into the engine's Tilemap, plus
8
8
  * helpers to pull object layers (spawn points, triggers, etc.) out as plain
9
- * data. Pure parsing pass it the already-parsed JSON object (load it with
9
+ * data. Pure parsing: pass it the already-parsed JSON object (load it with
10
10
  * AssetManager.json or fetch).
11
11
  *
12
12
  * @example
@@ -104,7 +104,7 @@ declare class EventManager {
104
104
  * @method getTopObjectAt
105
105
  * @description Returns the topmost active object under a world-space point
106
106
  * along with the instance hit (if the object is an InstancedTexture). Topmost
107
- * means highest z, with later scene order breaking ties matching draw order.
107
+ * means highest z, with later scene order breaking ties, matching draw order.
108
108
  * @param {number} worldX - The world-space x coordinate
109
109
  * @param {number} worldY - The world-space y coordinate
110
110
  * @returns {{object: GameObject, instance: Instance|null}|null}
@@ -0,0 +1,102 @@
1
+ export default Gamepad;
2
+ /**
3
+ * @class Gamepad
4
+ * @description An autocomplete-friendly way to build the raw gamepad token
5
+ * strings InputManager already understands ("pad:0:south", etc.). It does
6
+ * not read input itself, and it is unrelated to the browser's own native
7
+ * `Gamepad` interface (the objects `navigator.getGamepads()` returns). It
8
+ * exists purely so you don't have to remember button-name spelling: every
9
+ * button/stick-direction name InputManager's standard mapping recognizes is
10
+ * a static constant here, so typing `Gamepad.` in an editor lists them the
11
+ * way an enum's members would.
12
+ *
13
+ * `Gamepad.get(index).key(name)` produces exactly the same string as writing
14
+ * the token by hand, so the two are fully interchangeable anywhere
15
+ * InputManager takes one: `mapAction`, `isDown`, `justPressed`,
16
+ * `justReleased`.
17
+ *
18
+ * @example
19
+ * import { Gamepad, InputManager } from "./index.js";
20
+ *
21
+ * const input = new InputManager();
22
+ * const pad = Gamepad.get(0); // the first controller
23
+ *
24
+ * input.mapAction("jump", [pad.key(Gamepad.SOUTH)]);
25
+ * input.mapAction("left", [pad.key(Gamepad.DPAD_LEFT), pad.key(Gamepad.LEFT_STICK_LEFT)]);
26
+ *
27
+ * // in the loop:
28
+ * if (input.justPressed("jump")) player.jump();
29
+ */
30
+ declare class Gamepad {
31
+ /**
32
+ * @method get
33
+ * @description Returns the (cached) handle for a pad index: 0 for the
34
+ * first controller, 1 for the second, and so on.
35
+ * @param {number} [index=0]
36
+ * @returns {Gamepad}
37
+ */
38
+ static get(index?: number): Gamepad;
39
+ /**
40
+ * @private Use `Gamepad.get(index)` rather than constructing directly, so
41
+ * every caller asking for the same pad index shares one instance.
42
+ */
43
+ private constructor();
44
+ index: any;
45
+ /**
46
+ * @method key
47
+ * @description A face/shoulder/centre/d-pad/stick-as-button token for this
48
+ * pad. Pass one of the `Gamepad.*` constants (`Gamepad.SOUTH`,
49
+ * `Gamepad.DPAD_UP`, …). InputManager's standard mapping also accepts a
50
+ * few vendor aliases these don't cover (e.g. "a", "cross" for `SOUTH`) if
51
+ * you'd rather think in Xbox/PlayStation terms; those still work as plain
52
+ * strings, `key()` just doesn't need to name them since `SOUTH` already
53
+ * reads the same on every pad.
54
+ * @param {string} name - One of the `Gamepad.*` button constants
55
+ * @returns {string}
56
+ */
57
+ key(name: string): string;
58
+ /**
59
+ * @method button
60
+ * @description A raw button index, mapping-independent: an escape hatch
61
+ * for a pad whose layout the standard/custom mapping tables don't cover.
62
+ * @param {number} n
63
+ * @returns {string}
64
+ */
65
+ button(n: number): string;
66
+ /**
67
+ * @method axis
68
+ * @description A raw analog axis past the deadzone, in one direction.
69
+ * @param {number} n - Axis index (0/1 = left stick X/Y, 2/3 = right stick X/Y on a standard pad)
70
+ * @param {"+"|"-"} [sign="+"]
71
+ * @returns {string}
72
+ */
73
+ axis(n: number, sign?: "+" | "-"): string;
74
+ }
75
+ declare namespace Gamepad {
76
+ let _instances: Map<any, any>;
77
+ let SOUTH: string;
78
+ let EAST: string;
79
+ let WEST: string;
80
+ let NORTH: string;
81
+ let L1: string;
82
+ let R1: string;
83
+ let L2: string;
84
+ let R2: string;
85
+ let SELECT: string;
86
+ let START: string;
87
+ let HOME: string;
88
+ let L3: string;
89
+ let R3: string;
90
+ let DPAD_UP: string;
91
+ let DPAD_DOWN: string;
92
+ let DPAD_LEFT: string;
93
+ let DPAD_RIGHT: string;
94
+ let LEFT_STICK_UP: string;
95
+ let LEFT_STICK_DOWN: string;
96
+ let LEFT_STICK_LEFT: string;
97
+ let LEFT_STICK_RIGHT: string;
98
+ let RIGHT_STICK_UP: string;
99
+ let RIGHT_STICK_DOWN: string;
100
+ let RIGHT_STICK_LEFT: string;
101
+ let RIGHT_STICK_RIGHT: string;
102
+ }