emeraldengine 2.2.1 → 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 (208) hide show
  1. package/README.md +2198 -968
  2. package/dist/types/index.d.ts +75 -32
  3. package/dist/types/src/Animator.d.ts +50 -0
  4. package/dist/types/{BitmapText.d.ts → src/BitmapText.d.ts} +19 -21
  5. package/dist/types/src/Camera.d.ts +122 -0
  6. package/dist/types/src/CameraController.d.ts +107 -0
  7. package/dist/types/src/CanvasText.d.ts +91 -0
  8. package/dist/types/src/CollisionLayers.d.ts +58 -0
  9. package/dist/types/{Color.d.ts → src/Color.d.ts} +6 -6
  10. package/dist/types/src/Coroutine.d.ts +111 -0
  11. package/dist/types/src/DebugOverlay.d.ts +86 -0
  12. package/dist/types/src/Drawable.d.ts +271 -0
  13. package/dist/types/src/Easing.d.ts +22 -0
  14. package/dist/types/src/Emerald.d.ts +420 -0
  15. package/dist/types/src/EmeraldDB.d.ts +159 -0
  16. package/dist/types/{FPSCounter.d.ts → src/FPSCounter.d.ts} +1 -3
  17. package/dist/types/src/GLUtils.d.ts +4 -0
  18. package/dist/types/{Instance.d.ts → src/Instance.d.ts} +37 -15
  19. package/dist/types/{InstancedTexture.d.ts → src/InstancedTexture.d.ts} +75 -23
  20. package/dist/types/src/Interpolator.d.ts +66 -0
  21. package/dist/types/src/Material.d.ts +87 -0
  22. package/dist/types/src/MathUtils.d.ts +81 -0
  23. package/dist/types/src/ParticleEmitter.d.ts +131 -0
  24. package/dist/types/src/Physics.d.ts +337 -0
  25. package/dist/types/src/Pool.d.ts +53 -0
  26. package/dist/types/src/PostEffects.d.ts +68 -0
  27. package/dist/types/src/PostProcessor.d.ts +124 -0
  28. package/dist/types/src/RenderTarget.d.ts +56 -0
  29. package/dist/types/src/Scene.d.ts +62 -0
  30. package/dist/types/src/ScreenEffects.d.ts +111 -0
  31. package/dist/types/src/Serializer.d.ts +86 -0
  32. package/dist/types/src/Shaders.d.ts +2 -0
  33. package/dist/types/{Shapes.d.ts → src/Shapes.d.ts} +4 -6
  34. package/dist/types/src/SpatialGrid.d.ts +50 -0
  35. package/dist/types/src/SpriteBatch.d.ts +89 -0
  36. package/dist/types/src/StateMachine.d.ts +59 -0
  37. package/dist/types/src/Storage.d.ts +89 -0
  38. package/dist/types/{Texture.d.ts → src/Texture.d.ts} +3 -4
  39. package/dist/types/src/TextureAtlas.d.ts +55 -0
  40. package/dist/types/src/Tilemap.d.ts +91 -0
  41. package/dist/types/src/Time.d.ts +53 -0
  42. package/dist/types/src/Timer.d.ts +54 -0
  43. package/dist/types/src/Transform.d.ts +94 -0
  44. package/dist/types/src/Tween.d.ts +81 -0
  45. package/dist/types/src/UI.d.ts +121 -0
  46. package/dist/types/src/components/Behaviour.d.ts +71 -0
  47. package/dist/types/{components → src/components}/BoxCollider.d.ts +14 -14
  48. package/dist/types/src/components/BoxColliderDebug.d.ts +15 -0
  49. package/dist/types/{components → src/components}/CircleCollider.d.ts +14 -12
  50. package/dist/types/src/components/CircleColliderDebug.d.ts +15 -0
  51. package/dist/types/src/components/Collider.d.ts +102 -0
  52. package/dist/types/src/components/GameObject.d.ts +135 -0
  53. package/dist/types/src/components/PolygonCollider.d.ts +33 -0
  54. package/dist/types/src/components/RigidBody.d.ts +456 -0
  55. package/dist/types/src/importers/Aseprite.d.ts +79 -0
  56. package/dist/types/src/importers/ForgeLevel.d.ts +97 -0
  57. package/dist/types/src/importers/TiledMap.d.ts +62 -0
  58. package/dist/types/{lights → src/lights}/DirectionalLight.d.ts +7 -9
  59. package/dist/types/{lights → src/lights}/PointLight.d.ts +6 -9
  60. package/dist/types/src/managers/AssetManager.d.ts +116 -0
  61. package/dist/types/src/managers/AudioManager.d.ts +259 -0
  62. package/dist/types/{managers → src/managers}/CameraManager.d.ts +8 -8
  63. package/dist/types/{managers → src/managers}/EventManager.d.ts +46 -32
  64. package/dist/types/src/managers/GLManager.d.ts +84 -0
  65. package/dist/types/src/managers/GLState.d.ts +37 -0
  66. package/dist/types/src/managers/Gamepad.d.ts +102 -0
  67. package/dist/types/src/managers/IDManager.d.ts +31 -0
  68. package/dist/types/src/managers/InputManager.d.ts +381 -0
  69. package/dist/types/src/managers/NetworkManager.d.ts +93 -0
  70. package/dist/types/src/managers/RenderStats.d.ts +34 -0
  71. package/dist/types/src/managers/SceneManager.d.ts +44 -0
  72. package/dist/types/src/managers/ShaderManager.d.ts +55 -0
  73. package/dist/types/src/managers/TextureManager.d.ts +102 -0
  74. package/dist/types/src/particlesystem/Particle.d.ts +64 -0
  75. package/dist/types/{particlesystem → src/particlesystem}/ParticleSettings.d.ts +32 -24
  76. package/dist/types/{particlesystem → src/particlesystem}/Particles.d.ts +20 -12
  77. package/dist/types/src/physics/AABB.d.ts +92 -0
  78. package/dist/types/src/physics/Body.d.ts +435 -0
  79. package/dist/types/src/physics/BodyType.d.ts +6 -0
  80. package/dist/types/src/physics/BroadPhase.d.ts +210 -0
  81. package/dist/types/src/physics/Collision.d.ts +102 -0
  82. package/dist/types/src/physics/Contact.d.ts +206 -0
  83. package/dist/types/src/physics/ContactSolver.d.ts +108 -0
  84. package/dist/types/src/physics/Distance.d.ts +54 -0
  85. package/dist/types/src/physics/DistanceJoint.d.ts +90 -0
  86. package/dist/types/src/physics/Fixture.d.ts +221 -0
  87. package/dist/types/src/physics/Island.d.ts +52 -0
  88. package/dist/types/src/physics/Joint.d.ts +59 -0
  89. package/dist/types/src/physics/Math2D.d.ts +371 -0
  90. package/dist/types/src/physics/RevoluteJoint.d.ts +119 -0
  91. package/dist/types/src/physics/Settings.d.ts +22 -0
  92. package/dist/types/src/physics/Shapes.d.ts +207 -0
  93. package/dist/types/src/physics/TimeOfImpact.d.ts +22 -0
  94. package/dist/types/src/physics/World.d.ts +274 -0
  95. package/dist/types/src/physics/index.d.ts +34 -0
  96. package/index.js +78 -0
  97. package/package.json +73 -60
  98. package/src/Animator.js +95 -0
  99. package/src/BitmapText.js +6 -5
  100. package/src/Camera.js +183 -0
  101. package/src/CameraController.js +192 -0
  102. package/src/CanvasText.js +281 -0
  103. package/src/CollisionLayers.js +86 -0
  104. package/src/Color.js +26 -18
  105. package/src/Coroutine.js +259 -0
  106. package/src/DebugOverlay.js +246 -0
  107. package/src/Drawable.js +842 -582
  108. package/src/Easing.js +57 -0
  109. package/src/Emerald.js +1150 -459
  110. package/src/EmeraldDB.js +328 -0
  111. package/src/FPSCounter.js +43 -43
  112. package/src/GLUtils.js +60 -67
  113. package/src/Instance.js +41 -5
  114. package/src/InstancedTexture.js +308 -127
  115. package/src/Interpolator.js +124 -0
  116. package/src/Material.js +202 -0
  117. package/src/MathUtils.js +134 -0
  118. package/src/ParticleEmitter.js +284 -0
  119. package/src/Physics.js +431 -40
  120. package/src/Pool.js +85 -0
  121. package/src/PostEffects.js +296 -0
  122. package/src/PostProcessor.js +304 -0
  123. package/src/RenderTarget.js +134 -0
  124. package/src/Scene.js +115 -83
  125. package/src/ScreenEffects.js +266 -0
  126. package/src/Serializer.js +131 -0
  127. package/src/Shaders.js +150 -165
  128. package/src/Shapes.js +118 -129
  129. package/src/SpatialGrid.js +111 -0
  130. package/src/SpriteBatch.js +299 -0
  131. package/src/StateMachine.js +82 -0
  132. package/src/Storage.js +175 -47
  133. package/src/Texture.js +58 -67
  134. package/src/TextureAtlas.js +96 -0
  135. package/src/Tilemap.js +274 -0
  136. package/src/Time.js +51 -6
  137. package/src/Timer.js +99 -0
  138. package/src/Transform.js +100 -7
  139. package/src/Tween.js +160 -0
  140. package/src/UI.js +394 -0
  141. package/src/components/Behaviour.js +90 -0
  142. package/src/components/BoxCollider.js +29 -12
  143. package/src/components/BoxColliderDebug.js +3 -4
  144. package/src/components/CircleCollider.js +26 -12
  145. package/src/components/CircleColliderDebug.js +25 -24
  146. package/src/components/Collider.js +150 -34
  147. package/src/components/GameObject.js +130 -21
  148. package/src/components/PolygonCollider.js +55 -0
  149. package/src/components/RigidBody.js +556 -8
  150. package/src/importers/Aseprite.js +142 -0
  151. package/src/importers/ForgeLevel.js +581 -0
  152. package/src/importers/TiledMap.js +158 -0
  153. package/src/lights/DirectionalLight.js +6 -15
  154. package/src/lights/PointLight.js +4 -4
  155. package/src/managers/AssetManager.js +239 -0
  156. package/src/managers/AudioManager.js +565 -146
  157. package/src/managers/EventManager.js +488 -477
  158. package/src/managers/GLManager.js +57 -0
  159. package/src/managers/GLState.js +70 -0
  160. package/src/managers/Gamepad.js +126 -0
  161. package/src/managers/IDManager.js +24 -2
  162. package/src/managers/InputManager.js +905 -0
  163. package/src/managers/NetworkManager.js +178 -0
  164. package/src/managers/RenderStats.js +34 -0
  165. package/src/managers/SceneManager.js +30 -0
  166. package/src/managers/ShaderManager.js +0 -2
  167. package/src/managers/TextureManager.js +218 -0
  168. package/src/particlesystem/Particle.js +82 -7
  169. package/src/particlesystem/ParticleSettings.js +21 -3
  170. package/src/particlesystem/Particles.js +80 -31
  171. package/src/physics/AABB.js +207 -0
  172. package/src/physics/Body.js +862 -0
  173. package/src/physics/BodyType.js +16 -0
  174. package/src/physics/BroadPhase.js +641 -0
  175. package/src/physics/Collision.js +534 -0
  176. package/src/physics/Contact.js +500 -0
  177. package/src/physics/ContactSolver.js +526 -0
  178. package/src/physics/Distance.js +403 -0
  179. package/src/physics/DistanceJoint.js +227 -0
  180. package/src/physics/Fixture.js +346 -0
  181. package/src/physics/Island.js +203 -0
  182. package/src/physics/Joint.js +78 -0
  183. package/src/physics/Math2D.js +573 -0
  184. package/src/physics/RevoluteJoint.js +278 -0
  185. package/src/physics/Settings.js +78 -0
  186. package/src/physics/Shapes.js +549 -0
  187. package/src/physics/TimeOfImpact.js +87 -0
  188. package/src/physics/World.js +731 -0
  189. package/src/physics/index.js +79 -0
  190. package/dist/types/Drawable.d.ts +0 -157
  191. package/dist/types/Emerald.d.ts +0 -73
  192. package/dist/types/GLUtils.d.ts +0 -6
  193. package/dist/types/Physics.d.ts +0 -139
  194. package/dist/types/Scene.d.ts +0 -39
  195. package/dist/types/Shaders.d.ts +0 -4
  196. package/dist/types/Storage.d.ts +0 -46
  197. package/dist/types/Time.d.ts +0 -22
  198. package/dist/types/Transform.d.ts +0 -41
  199. package/dist/types/components/BoxColliderDebug.d.ts +0 -19
  200. package/dist/types/components/CircleColliderDebug.d.ts +0 -19
  201. package/dist/types/components/Collider.d.ts +0 -53
  202. package/dist/types/components/GameObject.d.ts +0 -72
  203. package/dist/types/components/RigidBody.d.ts +0 -104
  204. package/dist/types/managers/AudioManager.d.ts +0 -60
  205. package/dist/types/managers/GLManager.d.ts +0 -47
  206. package/dist/types/managers/IDManager.d.ts +0 -21
  207. package/dist/types/managers/SceneManager.d.ts +0 -22
  208. package/dist/types/particlesystem/Particle.d.ts +0 -42
@@ -0,0 +1,37 @@
1
+ export default GLState;
2
+ /**
3
+ * @class GLState
4
+ * @description Tiny redundant-uniform filter. The renderer sets the same handful
5
+ * of per-object uniforms (useTexture, useInstances, useLighting, color, opacity)
6
+ * for every object every frame; most calls repeat the previous value. These
7
+ * helpers skip the GL call when the value is unchanged. Keyed by uniform
8
+ * location, which is program-specific, so the cache is safe across objects.
9
+ */
10
+ declare class GLState {
11
+ /**
12
+ * @method reset
13
+ * @description Clears the cache. Called at the start of each frame so the
14
+ * first object always re-establishes state.
15
+ */
16
+ static reset(): void;
17
+ /**
18
+ * @method uniform1i
19
+ * @description Cached gl.uniform1i (accepts booleans, coerced like WebGL does).
20
+ */
21
+ static uniform1i(gl: any, location: any, value: any): void;
22
+ /**
23
+ * @method uniform1f
24
+ * @description Cached gl.uniform1f.
25
+ */
26
+ static uniform1f(gl: any, location: any, value: any): void;
27
+ /**
28
+ * @method uniform4fv
29
+ * @description Cached gl.uniform4fv (compares the four components).
30
+ */
31
+ static uniform4fv(gl: any, location: any, value: any): void;
32
+ }
33
+ declare namespace GLState {
34
+ let ints: Map<any, any>;
35
+ let floats: Map<any, any>;
36
+ let vec4s: Map<any, any>;
37
+ }
@@ -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
+ }
@@ -0,0 +1,31 @@
1
+ export default IDManager;
2
+ /**
3
+ * @class IDManager
4
+ * @description Manages the IDs for the game
5
+ */
6
+ declare class IDManager {
7
+ /**
8
+ * @method generateID
9
+ * @description Generates a random ID, preferring the collision-resistant
10
+ * crypto.randomUUID when available and falling back to a random string.
11
+ * @returns {string} - The random ID
12
+ */
13
+ static generateID(): string;
14
+ /**
15
+ * @method generateUniqueID
16
+ * @description Generates a unique ID
17
+ * @returns {string} - The unique ID
18
+ */
19
+ static generateUniqueID(): string;
20
+ /**
21
+ * @method release
22
+ * @description Releases a previously-generated ID so the global registry
23
+ * doesn't grow without bound. Call this when an object/instance is destroyed
24
+ * (e.g. particles removed from an InstancedTexture).
25
+ * @param {string} id - The ID to release
26
+ */
27
+ static release(id: string): void;
28
+ }
29
+ declare namespace IDManager {
30
+ let existingIDs: Set<any>;
31
+ }
@@ -0,0 +1,381 @@
1
+ export default InputManager;
2
+ /**
3
+ * @class InputManager
4
+ * @description Unified, pollable input: keyboard, mouse, touch, and full
5
+ * gamepad support (analog sticks/triggers, semantic button names, rumble,
6
+ * connect events, and per-controller mapping), with rebindable named actions.
7
+ * Call `update()` once per frame so `justPressed`/`justReleased` edge queries
8
+ * work for every device, including the gamepad.
9
+ *
10
+ * Gamepad tokens (usable anywhere a key token is, including in mapAction and
11
+ * justPressed); `<i>` is the pad index:
12
+ * "pad:<i>:south" / "pad:<i>:a" - face buttons (also east/b, west/x, north/y)
13
+ * "pad:<i>:l1" / "pad:<i>:r2" ... - shoulders / triggers
14
+ * "pad:<i>:start" / "pad:<i>:select" - center buttons
15
+ * "pad:<i>:dpadLeft" ... - d-pad (works via buttons or a hat axis)
16
+ * "pad:<i>:<n>" - raw button index (mapping-independent)
17
+ * "pad:<i>:axis<n>+" / "axis<n>-" - analog axis past the deadzone
18
+ * "pad:<i>:leftStickUp" / "Down" / "Left" / "Right" - stick as a d-pad
19
+ * "pad:<i>:rightStickUp" ... - (threshold: stickPressThreshold)
20
+ * "gamepad:<n>" - legacy: raw button <n> on pad 0
21
+ * Names resolve through the active mapping, so "pad:0:south" is the bottom face
22
+ * button regardless of whether the pad reports Xbox or PlayStation ordering.
23
+ *
24
+ * Typing these by hand means remembering the exact spelling of every button
25
+ * name above; {@link Gamepad} builds the same strings from named constants
26
+ * instead (`Gamepad.get(0).key(Gamepad.SOUTH)` === "pad:0:south"), which most
27
+ * editors will autocomplete the way an enum's members would.
28
+ *
29
+ * @example
30
+ * const input = new InputManager();
31
+ * input.mapAction("jump", ["Space", " ", "pad:0:south"]);
32
+ * input.mapAction("left", ["a", "ArrowLeft", "pad:0:dpadLeft"]);
33
+ * input.onGamepadConnected((info) => console.log("pad:", info.id, info.mapping));
34
+ * // in the loop:
35
+ * if (input.justPressed("jump")) { player.jump(); input.rumble(0, { duration: 120 }); }
36
+ * const { x } = input.getGamepadStick("left"); // analog, deadzoned
37
+ * input.update();
38
+ */
39
+ declare class InputManager {
40
+ /**
41
+ * @method registerGamepadMapping
42
+ * @description Registers a custom button/axis mapping for controllers whose
43
+ * `mapping` is not "standard" (so their raw button indices differ). Match by
44
+ * a substring of `gamepad.id` (case-insensitive), a RegExp, or a predicate.
45
+ * @param {string|RegExp|Function} match - id matcher
46
+ * @param {Object} mapping - { buttons:{name:index}, axes:{name:index} };
47
+ * merged over the standard table, so you only specify what differs.
48
+ */
49
+ static registerGamepadMapping(match: string | RegExp | Function, mapping?: any): void;
50
+ constructor(options?: {});
51
+ target: any;
52
+ actions: Map<any, any>;
53
+ down: Set<any>;
54
+ prevDown: Set<any>;
55
+ mouse: {
56
+ x: number;
57
+ y: number;
58
+ buttons: Set<any>;
59
+ };
60
+ touches: any[];
61
+ gamepads: any[];
62
+ gamepadDeadzone: any;
63
+ gamepadCurve: any;
64
+ stickPressThreshold: any;
65
+ /** @private */
66
+ private _gamepadTokens;
67
+ /** @private */
68
+ private _connectHandlers;
69
+ /** @private */
70
+ private _disconnectHandlers;
71
+ /** @private */
72
+ private _connected;
73
+ /**
74
+ * Which device last produced real input: "keyboard", "mouse",
75
+ * "gamepad", "touch", or null before anything has happened yet. See
76
+ * {@link getLastActiveDevice}.
77
+ * @private
78
+ */
79
+ private _lastActiveDevice;
80
+ /** Pending {@link identifyButton} calls, resolved from `update()`. @private */
81
+ private _buttonWaiters;
82
+ /** @private */
83
+ private _onKeyDown;
84
+ /** @private */
85
+ private _onKeyUp;
86
+ /** @private */
87
+ private _onMouseDown;
88
+ /** @private */
89
+ private _onMouseUp;
90
+ /** @private */
91
+ private _onMouseMove;
92
+ /** @private */
93
+ private _onTouch;
94
+ /** @private */
95
+ private _onGamepadConnected;
96
+ /** @private */
97
+ private _onGamepadDisconnected;
98
+ /** @private */
99
+ private _normKey;
100
+ /**
101
+ * @method mapAction
102
+ * @description Binds an action name to one or more input tokens (keys,
103
+ * "mouse:0", or any gamepad token above).
104
+ * @param {string} name - Action name
105
+ * @param {string[]} tokens - Input tokens
106
+ * @returns {InputManager} - this
107
+ */
108
+ mapAction(name: string, tokens: string[]): InputManager;
109
+ /** @private */
110
+ private _tokensFor;
111
+ /** @private */
112
+ private _tokenDown;
113
+ /**
114
+ * @method isDown
115
+ * @description Whether the action (or raw token) is currently held.
116
+ */
117
+ isDown(actionOrToken: any): any;
118
+ /**
119
+ * @method justPressed
120
+ * @description Whether the action became pressed this frame.
121
+ */
122
+ justPressed(actionOrToken: any): any;
123
+ /**
124
+ * @method justReleased
125
+ * @description Whether the action was released this frame.
126
+ */
127
+ justReleased(actionOrToken: any): any;
128
+ /**
129
+ * @method getAxis
130
+ * @description Returns -1/0/+1 based on two opposing actions.
131
+ */
132
+ getAxis(negative: any, positive: any): number;
133
+ /**
134
+ * @method getGamepad
135
+ * @description Returns the polled gamepad at an index (or null).
136
+ */
137
+ getGamepad(index?: number): any;
138
+ /**
139
+ * @method setGamepadDeadzone
140
+ * @description Sets the analog deadzone (0..1) for axes and trigger buttons.
141
+ * @returns {InputManager} - this
142
+ */
143
+ setGamepadDeadzone(dz: any): InputManager;
144
+ /**
145
+ * @method setGamepadCurve
146
+ * @description Sets the response-curve exponent applied to deadzoned analog
147
+ * values: 1 = linear (default), >1 = softer near center for fine aiming.
148
+ * @returns {InputManager} - this
149
+ */
150
+ setGamepadCurve(exp: any): InputManager;
151
+ /**
152
+ * @method _rescaleAxis
153
+ * @description Deadzone + rescale + curve for a single axis value. Unlike a
154
+ * hard cutoff, the output ramps smoothly from 0 at the deadzone edge to ±1
155
+ * at full deflection (no jump, and the full range stays reachable).
156
+ * @private
157
+ */
158
+ private _rescaleAxis;
159
+ /**
160
+ * @method _buttonMapFor
161
+ * @description Resolves the button-name → index table for a gamepad: a
162
+ * registered custom mapping (matched by id) wins; otherwise the standard
163
+ * table is used (also as the best-effort fallback for unknown non-standard
164
+ * pads).
165
+ * @private
166
+ */
167
+ private _buttonMapFor;
168
+ /**
169
+ * @method getGamepadAxis
170
+ * @description Returns a deadzoned analog axis value (-1..1). The value is
171
+ * RESCALED past the deadzone (0 at the edge, ±1 at full deflection) and runs
172
+ * through the response curve, so there is no jump at the threshold. Standard
173
+ * mapping: axis 0/1 = left stick X/Y, 2/3 = right stick X/Y.
174
+ * @param {number} axisIndex
175
+ * @param {number} [padIndex=0]
176
+ * @returns {number}
177
+ */
178
+ getGamepadAxis(axisIndex: number, padIndex?: number): number;
179
+ /**
180
+ * @method getGamepadStick
181
+ * @description Returns the left or right stick with a RADIAL deadzone: the
182
+ * deadzone applies to the stick's distance from center (not per axis), so
183
+ * diagonals aren't clipped square and direction is preserved exactly. The
184
+ * magnitude is rescaled to use the full 0..1 range and shaped by the
185
+ * response curve.
186
+ * @param {"left"|"right"} [side="left"]
187
+ * @param {number} [padIndex=0]
188
+ * @param {Object} [opts] - { deadzone, curve, invertY } overrides. invertY
189
+ * flips the browser's y-down convention so up = +1.
190
+ * @returns {{x:number, y:number, magnitude:number, angle:number}}
191
+ */
192
+ getGamepadStick(side?: "left" | "right", padIndex?: number, opts?: any): {
193
+ x: number;
194
+ y: number;
195
+ magnitude: number;
196
+ angle: number;
197
+ };
198
+ /**
199
+ * @method _axisMapFor
200
+ * @description Axis-name table for a pad (custom/built-in mapping wins for
201
+ * non-standard pads, else the standard table).
202
+ * @private
203
+ */
204
+ private _axisMapFor;
205
+ /**
206
+ * @method getGamepadButton
207
+ * @description Looks up a button by semantic name (e.g. "south", "a", "r1",
208
+ * "start", "dpadLeft") or raw index through the pad's active mapping.
209
+ * @param {string|number} name
210
+ * @param {number} [padIndex=0]
211
+ * @returns {{pressed:boolean, value:number, index:number}}
212
+ */
213
+ getGamepadButton(name: string | number, padIndex?: number): {
214
+ pressed: boolean;
215
+ value: number;
216
+ index: number;
217
+ };
218
+ /**
219
+ * @method getGamepadTrigger
220
+ * @description Returns the analog value (0..1) of a trigger.
221
+ * @param {"left"|"right"} [side="left"]
222
+ * @param {number} [padIndex=0]
223
+ * @returns {number}
224
+ */
225
+ getGamepadTrigger(side?: "left" | "right", padIndex?: number): number;
226
+ /**
227
+ * @method rumble
228
+ * @description Plays a vibration effect on a pad (where supported).
229
+ * @param {number} [padIndex=0]
230
+ * @param {Object} [opts] - { duration=200, strong=1, weak=1 }
231
+ * @returns {Promise|undefined}
232
+ */
233
+ rumble(padIndex?: number, opts?: any): Promise<any> | undefined;
234
+ /**
235
+ * @method onGamepadConnected
236
+ * @description Registers a callback fired when a pad connects (also called for
237
+ * pads already connected at registration time). Receives an info object.
238
+ * @param {Function} cb
239
+ * @returns {InputManager} - this
240
+ */
241
+ onGamepadConnected(cb: Function): InputManager;
242
+ /**
243
+ * @method onGamepadDisconnected
244
+ * @description Registers a callback fired when a pad disconnects.
245
+ * @returns {InputManager} - this
246
+ */
247
+ onGamepadDisconnected(cb: any): InputManager;
248
+ /** @private */
249
+ private _infoFromPad;
250
+ /**
251
+ * @method getGamepadInfo
252
+ * @description Diagnostic info for a connected pad (id, mapping, counts).
253
+ * @param {number} [padIndex=0]
254
+ * @returns {Object|null}
255
+ */
256
+ getGamepadInfo(padIndex?: number): any | null;
257
+ /**
258
+ * @method getConnectedGamepads
259
+ * @description Info for every currently polled pad.
260
+ * @returns {Object[]}
261
+ */
262
+ getConnectedGamepads(): any[];
263
+ /**
264
+ * @method isGamepadConnected
265
+ * @returns {boolean}
266
+ */
267
+ isGamepadConnected(padIndex?: number): boolean;
268
+ /**
269
+ * @method getLastActiveDevice
270
+ * @description Which device the player most recently *actually used*,
271
+ * not just "is a gamepad plugged in" (see `isGamepadConnected`, which stays
272
+ * true all game long once one is), but "did they just press a key, click,
273
+ * touch, or move a gamepad button/stick". A pad being connected doesn't
274
+ * mean it's what's driving the game right now; this is the signal for
275
+ * swapping on-screen prompts between keyboard and gamepad button icons as
276
+ * the player actually switches between them mid-session.
277
+ *
278
+ * Only counts deliberate input: keydown, mousedown, and touch, not
279
+ * incidental mouse movement, so idly nudging the mouse while playing on a
280
+ * pad won't flip prompts back to keyboard/mouse.
281
+ *
282
+ * @example
283
+ * // once per frame, after input.update():
284
+ * hud.setPromptStyle(input.getLastActiveDevice() === "gamepad" ? "pad" : "keyboard");
285
+ *
286
+ * @returns {"keyboard"|"mouse"|"gamepad"|"touch"|null} - null before any input at all
287
+ */
288
+ getLastActiveDevice(): "keyboard" | "mouse" | "gamepad" | "touch" | null;
289
+ /**
290
+ * @method getPressedButtons
291
+ * @description Diagnostic: raw indices of all currently pressed buttons on a
292
+ * pad. Handy for discovering an unknown controller's layout.
293
+ * @param {number} [padIndex=0]
294
+ * @returns {number[]}
295
+ */
296
+ getPressedButtons(padIndex?: number): number[];
297
+ /**
298
+ * @method identifyButton
299
+ * @description Resolves with the raw index of the next *new* button press
300
+ * on a pad: the reliable way to support a controller whose layout isn't
301
+ * already covered by the standard/registered mapping tables (a Steam
302
+ * Controller running outside Steam Input, an old flight stick, anything
303
+ * with a scrambled button order), instead of guessing indices: ask for one
304
+ * physical press and record wherever it actually lands on that specific
305
+ * device. Keep calling `update()` as normal while waiting; the promise
306
+ * resolves on the frame a button transitions from up to down. A button
307
+ * already held when this is called doesn't count; only a fresh press does.
308
+ *
309
+ * @example
310
+ * console.log("Press the button you want for Jump…");
311
+ * const index = await input.identifyButton(0);
312
+ * InputManager.registerGamepadMapping(input.getGamepadInfo(0).id, {
313
+ * buttons: { south: index },
314
+ * });
315
+ *
316
+ * @param {number} [padIndex=0]
317
+ * @returns {Promise<number>} - Never resolves if no new button is ever pressed
318
+ */
319
+ identifyButton(padIndex?: number): Promise<number>;
320
+ /**
321
+ * @method calibrateGamepad
322
+ * @description Walks a list of semantic button names one at a time, asking
323
+ * for a physical press for each (see {@link identifyButton}), and resolves
324
+ * with a `{name: rawIndex}` map ready to hand straight to
325
+ * `InputManager.registerGamepadMapping`, a complete fix for an oddball
326
+ * controller in a few seconds, without knowing anything about its layout
327
+ * in advance.
328
+ *
329
+ * @example
330
+ * const mapping = await input.calibrateGamepad(
331
+ * 0,
332
+ * ["south", "east", "west", "north", "l1", "r1", "start"],
333
+ * (name, i, total) => showPrompt(`(${i + 1}/${total}) Press the button for "${name}"`)
334
+ * );
335
+ * InputManager.registerGamepadMapping(input.getGamepadInfo(0).id, { buttons: mapping });
336
+ *
337
+ * @param {number} padIndex
338
+ * @param {string[]} names - Semantic names to calibrate, e.g. ["south", "east", "start"]
339
+ * @param {(name: string, index: number, total: number) => void} [onPrompt] -
340
+ * Called right before waiting for each name, so you can show "press ___" UI
341
+ * @returns {Promise<Object.<string, number>>} - { [name]: rawButtonIndex }
342
+ */
343
+ calibrateGamepad(padIndex: number, names: string[], onPrompt?: (name: string, index: number, total: number) => void): Promise<{
344
+ [x: string]: number;
345
+ }>;
346
+ /**
347
+ * @method _decodeHat
348
+ * @description Some non-standard pads report the d-pad as an 8-way "hat" on a
349
+ * single axis instead of buttons 12-15. When a pad is non-standard and exposes
350
+ * an extra (odd) trailing axis, decode it into d-pad direction tokens.
351
+ * @private
352
+ */
353
+ private _decodeHat;
354
+ /**
355
+ * @method _collectGamepadTokens
356
+ * @description Rebuilds the active gamepad token set (raw indices, semantic
357
+ * names via the pad's mapping, d-pad, and axis directions) for every connected
358
+ * pad, so gamepad input flows through the same down/justPressed machinery as
359
+ * the keyboard.
360
+ * @private
361
+ */
362
+ private _collectGamepadTokens;
363
+ /**
364
+ * @method update
365
+ * @description Polls gamepads and advances edge-detection state. Call once
366
+ * per frame after reading input.
367
+ */
368
+ update(): void;
369
+ /**
370
+ * @method _resolveButtonWaiters
371
+ * @description Resolves any {@link identifyButton} calls whose pad just
372
+ * saw a button go from up to down.
373
+ * @private
374
+ */
375
+ private _resolveButtonWaiters;
376
+ /**
377
+ * @method destroy
378
+ * @description Removes all event listeners.
379
+ */
380
+ destroy(): void;
381
+ }
@@ -0,0 +1,93 @@
1
+ export default NetworkManager;
2
+ /**
3
+ * @class NetworkManager
4
+ * @description A thin, optional multiplayer layer over Colyseus. `colyseus.js`
5
+ * is an optional peer dependency and is imported dynamically, so the engine has
6
+ * no hard dependency on it, so games that don't use networking never load it.
7
+ *
8
+ * It wraps connection/room lifecycle, exposes a small event API
9
+ * (onStateChange / onMessage / onAdd / onRemove / onLeave), and bundles an
10
+ * {@link Interpolator} so remote entities can be rendered smoothly.
11
+ *
12
+ * @example
13
+ * const net = new NetworkManager();
14
+ * await net.connect("wss://my-server");
15
+ * const room = await net.join("arena", { name: "P1" });
16
+ * net.onMessage("hit", (msg) => applyHit(msg));
17
+ * net.onStateChange((state) => {
18
+ * for (const [id, p] of state.players) net.interpolator.push(id, p, net.now());
19
+ * });
20
+ * // each frame:
21
+ * const pos = net.interpolator.sample(remoteId, net.now());
22
+ */
23
+ declare class NetworkManager {
24
+ /** @private */
25
+ private static _now;
26
+ constructor(options?: {});
27
+ client: import("colyseus.js").Client;
28
+ room: import("colyseus.js").Room<any>;
29
+ interpolator: Interpolator;
30
+ /** @private */
31
+ private _messageHandlers;
32
+ /** @private */
33
+ private _stateHandlers;
34
+ /** @private */
35
+ private _leaveHandlers;
36
+ /** @private */
37
+ private _startTime;
38
+ /**
39
+ * @method connect
40
+ * @description Dynamically imports colyseus.js and creates a Client.
41
+ * @param {string} endpoint - The server endpoint (e.g. "wss://host:2567")
42
+ * @returns {Promise<NetworkManager>} - this
43
+ */
44
+ connect(endpoint: string): Promise<NetworkManager>;
45
+ /**
46
+ * @method join
47
+ * @description Joins (or creates) a room by name and wires up the event hooks.
48
+ * @param {string} roomName - The room name
49
+ * @param {Object} [options] - Join options forwarded to the server
50
+ * @returns {Promise<Object>} - The joined room
51
+ */
52
+ join(roomName: string, options?: any): Promise<any>;
53
+ /** @private */
54
+ private _wireRoom;
55
+ /**
56
+ * @method onStateChange
57
+ * @description Registers a handler for full room-state updates.
58
+ */
59
+ onStateChange(handler: any): this;
60
+ /**
61
+ * @method onMessage
62
+ * @description Registers a handler for a server message type.
63
+ */
64
+ onMessage(type: any, handler: any): this;
65
+ /**
66
+ * @method onLeave
67
+ * @description Registers a handler invoked when the room is left.
68
+ */
69
+ onLeave(handler: any): this;
70
+ /**
71
+ * @method send
72
+ * @description Sends a typed message to the server.
73
+ */
74
+ send(type: any, payload: any): this;
75
+ /**
76
+ * @method now
77
+ * @description Seconds since this manager was created, a convenient clock for
78
+ * feeding the interpolator.
79
+ * @returns {number}
80
+ */
81
+ now(): number;
82
+ /**
83
+ * @method leave
84
+ * @description Leaves the current room.
85
+ */
86
+ leave(): Promise<void>;
87
+ /**
88
+ * @method sessionId
89
+ * @returns {string|null} - This client's session id, if joined.
90
+ */
91
+ get sessionId(): string | null;
92
+ }
93
+ import Interpolator from "../Interpolator.js";
@@ -0,0 +1,34 @@
1
+ export default RenderStats;
2
+ /**
3
+ * @class RenderStats
4
+ * @description Frame-level render counters, incremented by every draw site in
5
+ * the engine (Drawable, InstancedTexture, SpriteBatch, post-processing) and
6
+ * reset at the start of each drawScene. Read the previous completed frame via
7
+ * `RenderStats.frame` or `emerald.getRenderStats()`. DebugOverlay shows it
8
+ * automatically.
9
+ *
10
+ * - drawCalls: GPU draw commands issued (the batching win shows up here)
11
+ * - quads: sprites/shapes drawn, counting every instance in a batch
12
+ * - textureBinds: texture switches (high numbers = poor batching order)
13
+ */
14
+ declare class RenderStats {
15
+ /**
16
+ * @method beginFrame
17
+ * @description Snapshots the counters gathered since the previous call into
18
+ * `frame` and zeroes the accumulators. Called by Emerald.drawScene.
19
+ */
20
+ static beginFrame(): void;
21
+ }
22
+ declare namespace RenderStats {
23
+ let drawCalls: number;
24
+ let quads: number;
25
+ let textureBinds: number;
26
+ namespace frame {
27
+ let drawCalls_1: number;
28
+ export { drawCalls_1 as drawCalls };
29
+ let quads_1: number;
30
+ export { quads_1 as quads };
31
+ let textureBinds_1: number;
32
+ export { textureBinds_1 as textureBinds };
33
+ }
34
+ }