emeraldengine 2.2.0 → 3.0.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.
- package/README.md +2359 -968
- package/dist/types/index.d.ts +72 -32
- package/dist/types/src/Animator.d.ts +50 -0
- package/dist/types/{BitmapText.d.ts → src/BitmapText.d.ts} +19 -21
- package/dist/types/src/Camera.d.ts +122 -0
- package/dist/types/src/CameraController.d.ts +107 -0
- package/dist/types/src/CanvasText.d.ts +91 -0
- package/dist/types/src/CollisionLayers.d.ts +58 -0
- package/dist/types/{Color.d.ts → src/Color.d.ts} +5 -6
- package/dist/types/src/Coroutine.d.ts +111 -0
- package/dist/types/src/DebugOverlay.d.ts +86 -0
- package/dist/types/src/Drawable.d.ts +271 -0
- package/dist/types/src/Easing.d.ts +22 -0
- package/dist/types/src/Emerald.d.ts +420 -0
- package/dist/types/src/EmeraldDB.d.ts +159 -0
- package/dist/types/{FPSCounter.d.ts → src/FPSCounter.d.ts} +1 -3
- package/dist/types/src/GLUtils.d.ts +4 -0
- package/dist/types/{Instance.d.ts → src/Instance.d.ts} +37 -15
- package/dist/types/{InstancedTexture.d.ts → src/InstancedTexture.d.ts} +60 -23
- package/dist/types/src/Interpolator.d.ts +66 -0
- package/dist/types/src/Material.d.ts +87 -0
- package/dist/types/src/MathUtils.d.ts +80 -0
- package/dist/types/src/ParticleEmitter.d.ts +131 -0
- package/dist/types/{Physics.d.ts → src/Physics.d.ts} +88 -20
- package/dist/types/src/Pool.d.ts +53 -0
- package/dist/types/src/PostEffects.d.ts +68 -0
- package/dist/types/src/PostProcessor.d.ts +124 -0
- package/dist/types/src/RenderTarget.d.ts +56 -0
- package/dist/types/src/Scene.d.ts +62 -0
- package/dist/types/src/ScreenEffects.d.ts +111 -0
- package/dist/types/src/Serializer.d.ts +86 -0
- package/dist/types/src/Shaders.d.ts +2 -0
- package/dist/types/{Shapes.d.ts → src/Shapes.d.ts} +4 -6
- package/dist/types/src/SpatialGrid.d.ts +50 -0
- package/dist/types/src/SpriteBatch.d.ts +89 -0
- package/dist/types/src/StateMachine.d.ts +59 -0
- package/dist/types/src/Storage.d.ts +89 -0
- package/dist/types/{Texture.d.ts → src/Texture.d.ts} +3 -4
- package/dist/types/src/TextureAtlas.d.ts +55 -0
- package/dist/types/src/Tilemap.d.ts +91 -0
- package/dist/types/src/Time.d.ts +53 -0
- package/dist/types/src/Timer.d.ts +54 -0
- package/dist/types/src/Transform.d.ts +94 -0
- package/dist/types/src/Tween.d.ts +81 -0
- package/dist/types/src/UI.d.ts +121 -0
- package/dist/types/src/components/Behaviour.d.ts +71 -0
- package/dist/types/{components → src/components}/BoxCollider.d.ts +14 -14
- package/dist/types/src/components/BoxColliderDebug.d.ts +15 -0
- package/dist/types/{components → src/components}/CircleCollider.d.ts +14 -12
- package/dist/types/src/components/CircleColliderDebug.d.ts +15 -0
- package/dist/types/src/components/Collider.d.ts +96 -0
- package/dist/types/src/components/GameObject.d.ts +135 -0
- package/dist/types/src/components/RigidBody.d.ts +183 -0
- package/dist/types/src/importers/Aseprite.d.ts +79 -0
- package/dist/types/src/importers/TiledMap.d.ts +62 -0
- package/dist/types/{lights → src/lights}/DirectionalLight.d.ts +7 -9
- package/dist/types/{lights → src/lights}/PointLight.d.ts +6 -9
- package/dist/types/src/managers/AssetManager.d.ts +116 -0
- package/dist/types/src/managers/AudioManager.d.ts +259 -0
- package/dist/types/{managers → src/managers}/CameraManager.d.ts +8 -8
- package/dist/types/{managers → src/managers}/EventManager.d.ts +46 -32
- package/dist/types/src/managers/GLManager.d.ts +84 -0
- package/dist/types/src/managers/GLState.d.ts +37 -0
- package/dist/types/src/managers/IDManager.d.ts +31 -0
- package/dist/types/src/managers/InputManager.d.ts +290 -0
- package/dist/types/src/managers/NetworkManager.d.ts +93 -0
- package/dist/types/src/managers/RenderStats.d.ts +34 -0
- package/dist/types/src/managers/SceneManager.d.ts +44 -0
- package/dist/types/src/managers/ShaderManager.d.ts +55 -0
- package/dist/types/src/managers/TextureManager.d.ts +102 -0
- package/dist/types/src/particlesystem/Particle.d.ts +64 -0
- package/dist/types/{particlesystem → src/particlesystem}/ParticleSettings.d.ts +32 -24
- package/dist/types/{particlesystem → src/particlesystem}/Particles.d.ts +20 -12
- package/index.js +72 -0
- package/package.json +74 -60
- package/src/Animator.js +95 -0
- package/src/BitmapText.js +6 -5
- package/src/Camera.js +183 -0
- package/src/CameraController.js +192 -0
- package/src/CanvasText.js +281 -0
- package/src/CollisionLayers.js +86 -0
- package/src/Color.js +18 -18
- package/src/Coroutine.js +259 -0
- package/src/DebugOverlay.js +246 -0
- package/src/Drawable.js +842 -555
- package/src/Easing.js +57 -0
- package/src/Emerald.js +1150 -459
- package/src/EmeraldDB.js +328 -0
- package/src/FPSCounter.js +43 -43
- package/src/GLUtils.js +60 -67
- package/src/Instance.js +41 -5
- package/src/InstancedTexture.js +251 -118
- package/src/Interpolator.js +124 -0
- package/src/Material.js +202 -0
- package/src/MathUtils.js +133 -0
- package/src/ParticleEmitter.js +284 -0
- package/src/Physics.js +186 -5
- package/src/Pool.js +85 -0
- package/src/PostEffects.js +296 -0
- package/src/PostProcessor.js +304 -0
- package/src/RenderTarget.js +134 -0
- package/src/Scene.js +115 -83
- package/src/ScreenEffects.js +266 -0
- package/src/Serializer.js +131 -0
- package/src/Shaders.js +150 -165
- package/src/Shapes.js +118 -129
- package/src/SpatialGrid.js +111 -0
- package/src/SpriteBatch.js +299 -0
- package/src/StateMachine.js +82 -0
- package/src/Storage.js +175 -47
- package/src/Texture.js +58 -67
- package/src/TextureAtlas.js +96 -0
- package/src/Tilemap.js +274 -0
- package/src/Time.js +51 -6
- package/src/Timer.js +99 -0
- package/src/Transform.js +100 -7
- package/src/Tween.js +160 -0
- package/src/UI.js +394 -0
- package/src/components/Behaviour.js +90 -0
- package/src/components/BoxCollider.js +22 -3
- package/src/components/CircleCollider.js +19 -3
- package/src/components/CircleColliderDebug.js +24 -24
- package/src/components/Collider.js +140 -34
- package/src/components/GameObject.js +130 -21
- package/src/components/RigidBody.js +123 -2
- package/src/importers/Aseprite.js +142 -0
- package/src/importers/TiledMap.js +158 -0
- package/src/lights/DirectionalLight.js +6 -15
- package/src/lights/PointLight.js +4 -4
- package/src/managers/AssetManager.js +239 -0
- package/src/managers/AudioManager.js +565 -146
- package/src/managers/EventManager.js +488 -477
- package/src/managers/GLManager.js +57 -0
- package/src/managers/GLState.js +70 -0
- package/src/managers/IDManager.js +24 -2
- package/src/managers/InputManager.js +779 -0
- package/src/managers/NetworkManager.js +178 -0
- package/src/managers/RenderStats.js +34 -0
- package/src/managers/SceneManager.js +30 -0
- package/src/managers/ShaderManager.js +0 -2
- package/src/managers/TextureManager.js +218 -0
- package/src/particlesystem/Particle.js +82 -7
- package/src/particlesystem/ParticleSettings.js +21 -3
- package/src/particlesystem/Particles.js +80 -31
- package/dist/types/Drawable.d.ts +0 -157
- package/dist/types/Emerald.d.ts +0 -73
- package/dist/types/GLUtils.d.ts +0 -6
- package/dist/types/Scene.d.ts +0 -39
- package/dist/types/Shaders.d.ts +0 -4
- package/dist/types/Storage.d.ts +0 -46
- package/dist/types/Time.d.ts +0 -22
- package/dist/types/Transform.d.ts +0 -41
- package/dist/types/components/BoxColliderDebug.d.ts +0 -19
- package/dist/types/components/CircleColliderDebug.d.ts +0 -19
- package/dist/types/components/Collider.d.ts +0 -53
- package/dist/types/components/GameObject.d.ts +0 -72
- package/dist/types/components/RigidBody.d.ts +0 -104
- package/dist/types/managers/AudioManager.d.ts +0 -60
- package/dist/types/managers/GLManager.d.ts +0 -47
- package/dist/types/managers/IDManager.d.ts +0 -21
- package/dist/types/managers/SceneManager.d.ts +0 -22
- package/dist/types/particlesystem/Particle.d.ts +0 -42
|
@@ -0,0 +1,290 @@
|
|
|
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
|
+
* @example
|
|
25
|
+
* const input = new InputManager();
|
|
26
|
+
* input.mapAction("jump", ["Space", " ", "pad:0:south"]);
|
|
27
|
+
* input.mapAction("left", ["a", "ArrowLeft", "pad:0:dpadLeft"]);
|
|
28
|
+
* input.onGamepadConnected((info) => console.log("pad:", info.id, info.mapping));
|
|
29
|
+
* // in the loop:
|
|
30
|
+
* if (input.justPressed("jump")) { player.jump(); input.rumble(0, { duration: 120 }); }
|
|
31
|
+
* const { x } = input.getGamepadStick("left"); // analog, deadzoned
|
|
32
|
+
* input.update();
|
|
33
|
+
*/
|
|
34
|
+
declare class InputManager {
|
|
35
|
+
/**
|
|
36
|
+
* @method registerGamepadMapping
|
|
37
|
+
* @description Registers a custom button/axis mapping for controllers whose
|
|
38
|
+
* `mapping` is not "standard" (so their raw button indices differ). Match by
|
|
39
|
+
* a substring of `gamepad.id` (case-insensitive), a RegExp, or a predicate.
|
|
40
|
+
* @param {string|RegExp|Function} match - id matcher
|
|
41
|
+
* @param {Object} mapping - { buttons:{name:index}, axes:{name:index} };
|
|
42
|
+
* merged over the standard table, so you only specify what differs.
|
|
43
|
+
*/
|
|
44
|
+
static registerGamepadMapping(match: string | RegExp | Function, mapping?: any): void;
|
|
45
|
+
constructor(options?: {});
|
|
46
|
+
target: any;
|
|
47
|
+
actions: Map<any, any>;
|
|
48
|
+
down: Set<any>;
|
|
49
|
+
prevDown: Set<any>;
|
|
50
|
+
mouse: {
|
|
51
|
+
x: number;
|
|
52
|
+
y: number;
|
|
53
|
+
buttons: Set<any>;
|
|
54
|
+
};
|
|
55
|
+
touches: any[];
|
|
56
|
+
gamepads: any[];
|
|
57
|
+
gamepadDeadzone: any;
|
|
58
|
+
gamepadCurve: any;
|
|
59
|
+
stickPressThreshold: any;
|
|
60
|
+
/** @private */
|
|
61
|
+
private _gamepadTokens;
|
|
62
|
+
/** @private */
|
|
63
|
+
private _connectHandlers;
|
|
64
|
+
/** @private */
|
|
65
|
+
private _disconnectHandlers;
|
|
66
|
+
/** @private */
|
|
67
|
+
private _connected;
|
|
68
|
+
/** @private */
|
|
69
|
+
private _onKeyDown;
|
|
70
|
+
/** @private */
|
|
71
|
+
private _onKeyUp;
|
|
72
|
+
/** @private */
|
|
73
|
+
private _onMouseDown;
|
|
74
|
+
/** @private */
|
|
75
|
+
private _onMouseUp;
|
|
76
|
+
/** @private */
|
|
77
|
+
private _onMouseMove;
|
|
78
|
+
/** @private */
|
|
79
|
+
private _onTouch;
|
|
80
|
+
/** @private */
|
|
81
|
+
private _onGamepadConnected;
|
|
82
|
+
/** @private */
|
|
83
|
+
private _onGamepadDisconnected;
|
|
84
|
+
/** @private */
|
|
85
|
+
private _normKey;
|
|
86
|
+
/**
|
|
87
|
+
* @method mapAction
|
|
88
|
+
* @description Binds an action name to one or more input tokens (keys,
|
|
89
|
+
* "mouse:0", or any gamepad token above).
|
|
90
|
+
* @param {string} name - Action name
|
|
91
|
+
* @param {string[]} tokens - Input tokens
|
|
92
|
+
* @returns {InputManager} - this
|
|
93
|
+
*/
|
|
94
|
+
mapAction(name: string, tokens: string[]): InputManager;
|
|
95
|
+
/** @private */
|
|
96
|
+
private _tokensFor;
|
|
97
|
+
/** @private */
|
|
98
|
+
private _tokenDown;
|
|
99
|
+
/**
|
|
100
|
+
* @method isDown
|
|
101
|
+
* @description Whether the action (or raw token) is currently held.
|
|
102
|
+
*/
|
|
103
|
+
isDown(actionOrToken: any): any;
|
|
104
|
+
/**
|
|
105
|
+
* @method justPressed
|
|
106
|
+
* @description Whether the action became pressed this frame.
|
|
107
|
+
*/
|
|
108
|
+
justPressed(actionOrToken: any): any;
|
|
109
|
+
/**
|
|
110
|
+
* @method justReleased
|
|
111
|
+
* @description Whether the action was released this frame.
|
|
112
|
+
*/
|
|
113
|
+
justReleased(actionOrToken: any): any;
|
|
114
|
+
/**
|
|
115
|
+
* @method getAxis
|
|
116
|
+
* @description Returns -1/0/+1 based on two opposing actions.
|
|
117
|
+
*/
|
|
118
|
+
getAxis(negative: any, positive: any): number;
|
|
119
|
+
/**
|
|
120
|
+
* @method getGamepad
|
|
121
|
+
* @description Returns the polled gamepad at an index (or null).
|
|
122
|
+
*/
|
|
123
|
+
getGamepad(index?: number): any;
|
|
124
|
+
/**
|
|
125
|
+
* @method setGamepadDeadzone
|
|
126
|
+
* @description Sets the analog deadzone (0..1) for axes and trigger buttons.
|
|
127
|
+
* @returns {InputManager} - this
|
|
128
|
+
*/
|
|
129
|
+
setGamepadDeadzone(dz: any): InputManager;
|
|
130
|
+
/**
|
|
131
|
+
* @method setGamepadCurve
|
|
132
|
+
* @description Sets the response-curve exponent applied to deadzoned analog
|
|
133
|
+
* values: 1 = linear (default), >1 = softer near center for fine aiming.
|
|
134
|
+
* @returns {InputManager} - this
|
|
135
|
+
*/
|
|
136
|
+
setGamepadCurve(exp: any): InputManager;
|
|
137
|
+
/**
|
|
138
|
+
* @method _rescaleAxis
|
|
139
|
+
* @description Deadzone + rescale + curve for a single axis value. Unlike a
|
|
140
|
+
* hard cutoff, the output ramps smoothly from 0 at the deadzone edge to ±1
|
|
141
|
+
* at full deflection (no jump, and the full range stays reachable).
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
144
|
+
private _rescaleAxis;
|
|
145
|
+
/**
|
|
146
|
+
* @method _buttonMapFor
|
|
147
|
+
* @description Resolves the button-name → index table for a gamepad: a
|
|
148
|
+
* registered custom mapping (matched by id) wins; otherwise the standard
|
|
149
|
+
* table is used (also as the best-effort fallback for unknown non-standard
|
|
150
|
+
* pads).
|
|
151
|
+
* @private
|
|
152
|
+
*/
|
|
153
|
+
private _buttonMapFor;
|
|
154
|
+
/**
|
|
155
|
+
* @method getGamepadAxis
|
|
156
|
+
* @description Returns a deadzoned analog axis value (-1..1). The value is
|
|
157
|
+
* RESCALED past the deadzone (0 at the edge, ±1 at full deflection) and runs
|
|
158
|
+
* through the response curve, so there is no jump at the threshold. Standard
|
|
159
|
+
* mapping: axis 0/1 = left stick X/Y, 2/3 = right stick X/Y.
|
|
160
|
+
* @param {number} axisIndex
|
|
161
|
+
* @param {number} [padIndex=0]
|
|
162
|
+
* @returns {number}
|
|
163
|
+
*/
|
|
164
|
+
getGamepadAxis(axisIndex: number, padIndex?: number): number;
|
|
165
|
+
/**
|
|
166
|
+
* @method getGamepadStick
|
|
167
|
+
* @description Returns the left or right stick with a RADIAL deadzone: the
|
|
168
|
+
* deadzone applies to the stick's distance from center (not per axis), so
|
|
169
|
+
* diagonals aren't clipped square and direction is preserved exactly. The
|
|
170
|
+
* magnitude is rescaled to use the full 0..1 range and shaped by the
|
|
171
|
+
* response curve.
|
|
172
|
+
* @param {"left"|"right"} [side="left"]
|
|
173
|
+
* @param {number} [padIndex=0]
|
|
174
|
+
* @param {Object} [opts] - { deadzone, curve, invertY } overrides. invertY
|
|
175
|
+
* flips the browser's y-down convention so up = +1.
|
|
176
|
+
* @returns {{x:number, y:number, magnitude:number, angle:number}}
|
|
177
|
+
*/
|
|
178
|
+
getGamepadStick(side?: "left" | "right", padIndex?: number, opts?: any): {
|
|
179
|
+
x: number;
|
|
180
|
+
y: number;
|
|
181
|
+
magnitude: number;
|
|
182
|
+
angle: number;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* @method _axisMapFor
|
|
186
|
+
* @description Axis-name table for a pad (custom/built-in mapping wins for
|
|
187
|
+
* non-standard pads, else the standard table).
|
|
188
|
+
* @private
|
|
189
|
+
*/
|
|
190
|
+
private _axisMapFor;
|
|
191
|
+
/**
|
|
192
|
+
* @method getGamepadButton
|
|
193
|
+
* @description Looks up a button by semantic name (e.g. "south", "a", "r1",
|
|
194
|
+
* "start", "dpadLeft") or raw index through the pad's active mapping.
|
|
195
|
+
* @param {string|number} name
|
|
196
|
+
* @param {number} [padIndex=0]
|
|
197
|
+
* @returns {{pressed:boolean, value:number, index:number}}
|
|
198
|
+
*/
|
|
199
|
+
getGamepadButton(name: string | number, padIndex?: number): {
|
|
200
|
+
pressed: boolean;
|
|
201
|
+
value: number;
|
|
202
|
+
index: number;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* @method getGamepadTrigger
|
|
206
|
+
* @description Returns the analog value (0..1) of a trigger.
|
|
207
|
+
* @param {"left"|"right"} [side="left"]
|
|
208
|
+
* @param {number} [padIndex=0]
|
|
209
|
+
* @returns {number}
|
|
210
|
+
*/
|
|
211
|
+
getGamepadTrigger(side?: "left" | "right", padIndex?: number): number;
|
|
212
|
+
/**
|
|
213
|
+
* @method rumble
|
|
214
|
+
* @description Plays a vibration effect on a pad (where supported).
|
|
215
|
+
* @param {number} [padIndex=0]
|
|
216
|
+
* @param {Object} [opts] - { duration=200, strong=1, weak=1 }
|
|
217
|
+
* @returns {Promise|undefined}
|
|
218
|
+
*/
|
|
219
|
+
rumble(padIndex?: number, opts?: any): Promise<any> | undefined;
|
|
220
|
+
/**
|
|
221
|
+
* @method onGamepadConnected
|
|
222
|
+
* @description Registers a callback fired when a pad connects (also called for
|
|
223
|
+
* pads already connected at registration time). Receives an info object.
|
|
224
|
+
* @param {Function} cb
|
|
225
|
+
* @returns {InputManager} - this
|
|
226
|
+
*/
|
|
227
|
+
onGamepadConnected(cb: Function): InputManager;
|
|
228
|
+
/**
|
|
229
|
+
* @method onGamepadDisconnected
|
|
230
|
+
* @description Registers a callback fired when a pad disconnects.
|
|
231
|
+
* @returns {InputManager} - this
|
|
232
|
+
*/
|
|
233
|
+
onGamepadDisconnected(cb: any): InputManager;
|
|
234
|
+
/** @private */
|
|
235
|
+
private _infoFromPad;
|
|
236
|
+
/**
|
|
237
|
+
* @method getGamepadInfo
|
|
238
|
+
* @description Diagnostic info for a connected pad (id, mapping, counts).
|
|
239
|
+
* @param {number} [padIndex=0]
|
|
240
|
+
* @returns {Object|null}
|
|
241
|
+
*/
|
|
242
|
+
getGamepadInfo(padIndex?: number): any | null;
|
|
243
|
+
/**
|
|
244
|
+
* @method getConnectedGamepads
|
|
245
|
+
* @description Info for every currently polled pad.
|
|
246
|
+
* @returns {Object[]}
|
|
247
|
+
*/
|
|
248
|
+
getConnectedGamepads(): any[];
|
|
249
|
+
/**
|
|
250
|
+
* @method isGamepadConnected
|
|
251
|
+
* @returns {boolean}
|
|
252
|
+
*/
|
|
253
|
+
isGamepadConnected(padIndex?: number): boolean;
|
|
254
|
+
/**
|
|
255
|
+
* @method getPressedButtons
|
|
256
|
+
* @description Diagnostic: raw indices of all currently pressed buttons on a
|
|
257
|
+
* pad. Handy for discovering an unknown controller's layout.
|
|
258
|
+
* @param {number} [padIndex=0]
|
|
259
|
+
* @returns {number[]}
|
|
260
|
+
*/
|
|
261
|
+
getPressedButtons(padIndex?: number): number[];
|
|
262
|
+
/**
|
|
263
|
+
* @method _decodeHat
|
|
264
|
+
* @description Some non-standard pads report the d-pad as an 8-way "hat" on a
|
|
265
|
+
* single axis instead of buttons 12-15. When a pad is non-standard and exposes
|
|
266
|
+
* an extra (odd) trailing axis, decode it into d-pad direction tokens.
|
|
267
|
+
* @private
|
|
268
|
+
*/
|
|
269
|
+
private _decodeHat;
|
|
270
|
+
/**
|
|
271
|
+
* @method _collectGamepadTokens
|
|
272
|
+
* @description Rebuilds the active gamepad token set (raw indices, semantic
|
|
273
|
+
* names via the pad's mapping, d-pad, and axis directions) for every connected
|
|
274
|
+
* pad, so gamepad input flows through the same down/justPressed machinery as
|
|
275
|
+
* the keyboard.
|
|
276
|
+
* @private
|
|
277
|
+
*/
|
|
278
|
+
private _collectGamepadTokens;
|
|
279
|
+
/**
|
|
280
|
+
* @method update
|
|
281
|
+
* @description Polls gamepads and advances edge-detection state. Call once
|
|
282
|
+
* per frame after reading input.
|
|
283
|
+
*/
|
|
284
|
+
update(): void;
|
|
285
|
+
/**
|
|
286
|
+
* @method destroy
|
|
287
|
+
* @description Removes all event listeners.
|
|
288
|
+
*/
|
|
289
|
+
destroy(): void;
|
|
290
|
+
}
|
|
@@ -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 — 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
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export default SceneManager;
|
|
2
|
+
/**
|
|
3
|
+
* @class SceneManager
|
|
4
|
+
* @description Manages the scene for the game
|
|
5
|
+
*/
|
|
6
|
+
declare class SceneManager {
|
|
7
|
+
/**
|
|
8
|
+
* @method setScene
|
|
9
|
+
* @description Sets the scene
|
|
10
|
+
* @param {Scene} scene - The scene to set
|
|
11
|
+
*/
|
|
12
|
+
static setScene(scene: Scene): void;
|
|
13
|
+
/**
|
|
14
|
+
* @method getScene
|
|
15
|
+
* @description Returns the scene
|
|
16
|
+
* @returns {Scene} - The scene
|
|
17
|
+
*/
|
|
18
|
+
static getScene(): Scene;
|
|
19
|
+
/**
|
|
20
|
+
* @method transitionTo
|
|
21
|
+
* @description Switches the active scene, optionally behind a ScreenEffects
|
|
22
|
+
* fade. With `screenEffects` provided the screen fades out, the scene is
|
|
23
|
+
* swapped (and your optional `onSwap` runs) while covered, then fades back in.
|
|
24
|
+
* Without it the swap happens immediately.
|
|
25
|
+
*
|
|
26
|
+
* @param {Scene} scene - The scene to make active
|
|
27
|
+
* @param {Object} [options]
|
|
28
|
+
* @param {ScreenEffects} [options.screenEffects] - Effects layer to fade with
|
|
29
|
+
* @param {Function} [options.onSwap] - `(scene) => void|Promise`, run during
|
|
30
|
+
* the covered swap (e.g. (re)build the new scene's contents)
|
|
31
|
+
* @param {number} [options.duration] - Fade duration (seconds)
|
|
32
|
+
* @param {Color} [options.color] - Fade color
|
|
33
|
+
* @returns {Promise<Scene>} - Resolves with the new scene
|
|
34
|
+
*/
|
|
35
|
+
static transitionTo(scene: Scene, options?: {
|
|
36
|
+
screenEffects?: ScreenEffects;
|
|
37
|
+
onSwap?: Function;
|
|
38
|
+
duration?: number;
|
|
39
|
+
color?: Color;
|
|
40
|
+
}): Promise<Scene>;
|
|
41
|
+
}
|
|
42
|
+
declare namespace SceneManager {
|
|
43
|
+
let scene: any;
|
|
44
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class ShaderManager
|
|
3
|
+
* @description Manages the shaders for the game
|
|
4
|
+
*/
|
|
5
|
+
export class ShaderManager {
|
|
6
|
+
constructor(gl: any);
|
|
7
|
+
gl: any;
|
|
8
|
+
shaders: Map<any, any>;
|
|
9
|
+
activeShader: any;
|
|
10
|
+
/**
|
|
11
|
+
* @method createShader
|
|
12
|
+
* @description Creates a shader
|
|
13
|
+
* @param {string} name - The name of the shader
|
|
14
|
+
* @param {string} vertexSource - The vertex shader source
|
|
15
|
+
* @param {string} fragmentSource - The fragment shader source
|
|
16
|
+
*/
|
|
17
|
+
createShader(name: string, vertexSource: string, fragmentSource: string): {
|
|
18
|
+
program: any;
|
|
19
|
+
attribLocations: any;
|
|
20
|
+
uniformLocations: any;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* @method compileShader
|
|
24
|
+
* @description Compiles a shader
|
|
25
|
+
* @param {string} source - The shader source
|
|
26
|
+
* @param {number} type - The type of shader
|
|
27
|
+
*/
|
|
28
|
+
compileShader(source: string, type: number): any;
|
|
29
|
+
/**
|
|
30
|
+
* @method useShader
|
|
31
|
+
* @description Uses a shader
|
|
32
|
+
* @param {string} name - The name of the shader
|
|
33
|
+
*/
|
|
34
|
+
useShader(name: string): any;
|
|
35
|
+
/**
|
|
36
|
+
* @method getActiveShader
|
|
37
|
+
* @description Returns the active shader
|
|
38
|
+
* @returns {Object} - The active shader
|
|
39
|
+
*/
|
|
40
|
+
getActiveShader(): any;
|
|
41
|
+
/**
|
|
42
|
+
* @method getAttributeLocations
|
|
43
|
+
* @description Returns the attribute locations for a shader program
|
|
44
|
+
* @param {WebGLProgram} program - The shader program
|
|
45
|
+
* @returns {Object} - The attribute locations
|
|
46
|
+
*/
|
|
47
|
+
getAttributeLocations(program: WebGLProgram): any;
|
|
48
|
+
/**
|
|
49
|
+
* @method getUniformLocations
|
|
50
|
+
* @description Returns the uniform locations for a shader program
|
|
51
|
+
* @param {WebGLProgram} program - The shader program
|
|
52
|
+
* @returns {Object} - The uniform locations
|
|
53
|
+
*/
|
|
54
|
+
getUniformLocations(program: WebGLProgram): any;
|
|
55
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export default TextureManager;
|
|
2
|
+
/**
|
|
3
|
+
* @class TextureManager
|
|
4
|
+
* @description Caches loaded images and GL textures so that many drawables
|
|
5
|
+
* sharing the same texture path download and upload the image only once.
|
|
6
|
+
*
|
|
7
|
+
* Textures are immutable after upload in this engine, so the same GL texture
|
|
8
|
+
* object can safely be bound by any number of objects. The GL-texture cache is
|
|
9
|
+
* keyed by path *and* filter mode, because pixel-art (NEAREST) and smooth
|
|
10
|
+
* (LINEAR) sampling require separate texture objects.
|
|
11
|
+
*/
|
|
12
|
+
declare class TextureManager {
|
|
13
|
+
/**
|
|
14
|
+
* @method loadImage
|
|
15
|
+
* @description Loads (and caches) an HTMLImageElement for a given path.
|
|
16
|
+
* Concurrent requests for the same path share a single in-flight load.
|
|
17
|
+
* @param {string} path - The path (or data URL) of the image
|
|
18
|
+
* @returns {Promise<HTMLImageElement>} - The loaded image
|
|
19
|
+
*/
|
|
20
|
+
static loadImage(path: string): Promise<HTMLImageElement>;
|
|
21
|
+
/**
|
|
22
|
+
* @method getTexture
|
|
23
|
+
* @description Returns a cached GL texture for the given path, creating and
|
|
24
|
+
* uploading it on first request. Subsequent calls reuse the same texture.
|
|
25
|
+
* @param {string} path - The path (or data URL) of the texture
|
|
26
|
+
* @param {boolean} pixelart - Whether to sample with NEAREST (pixel art) filtering
|
|
27
|
+
* @returns {Promise<{texture: WebGLTexture, width: number, height: number}>}
|
|
28
|
+
*/
|
|
29
|
+
static getTexture(path: string, pixelart?: boolean): Promise<{
|
|
30
|
+
texture: WebGLTexture;
|
|
31
|
+
width: number;
|
|
32
|
+
height: number;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* @method _upload
|
|
36
|
+
* @description Loads the image (via the shared image cache) and uploads it
|
|
37
|
+
* as a GL texture with the requested filtering.
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
private static _upload;
|
|
41
|
+
/**
|
|
42
|
+
* @method restoreAll
|
|
43
|
+
* @description Re-uploads every cached texture after a WebGL context loss.
|
|
44
|
+
* The image cache survives the loss, so this is upload-only (no network).
|
|
45
|
+
* Reference counts are untouched — they track logical ownership by
|
|
46
|
+
* drawables, which still exist.
|
|
47
|
+
*/
|
|
48
|
+
static restoreAll(): void;
|
|
49
|
+
/**
|
|
50
|
+
* @method preload
|
|
51
|
+
* @description Eagerly loads a list of texture paths so they are ready (and
|
|
52
|
+
* cached) before the first frame that needs them.
|
|
53
|
+
* @param {string[]} paths - The texture paths to preload
|
|
54
|
+
* @param {boolean} pixelart - Whether to use pixel-art filtering
|
|
55
|
+
* @returns {Promise<void>}
|
|
56
|
+
*/
|
|
57
|
+
static preload(paths: string[], pixelart?: boolean): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* @method has
|
|
60
|
+
* @description Checks whether a GL texture is already cached for a path
|
|
61
|
+
* @param {string} path - The texture path
|
|
62
|
+
* @param {boolean} pixelart - Whether the pixel-art variant is meant
|
|
63
|
+
* @returns {boolean}
|
|
64
|
+
*/
|
|
65
|
+
static has(path: string, pixelart?: boolean): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* @method retain
|
|
68
|
+
* @description Increments the reference count for a cached texture. Every
|
|
69
|
+
* Drawable that resolves a texture through getTexture() retains it; when the
|
|
70
|
+
* last user releases it, the GL texture is freed. Call retain/release in
|
|
71
|
+
* pairs (Drawable.dispose does the release for you).
|
|
72
|
+
* @param {string} path - The texture path
|
|
73
|
+
* @param {boolean} pixelart - Whether the pixel-art variant is meant
|
|
74
|
+
*/
|
|
75
|
+
static retain(path: string, pixelart?: boolean): void;
|
|
76
|
+
/**
|
|
77
|
+
* @method release
|
|
78
|
+
* @description Decrements a texture's reference count; when it reaches zero
|
|
79
|
+
* the GL texture is deleted and dropped from the cache (the CPU-side image
|
|
80
|
+
* cache is kept so a later reload is cheap).
|
|
81
|
+
* @param {string} path - The texture path
|
|
82
|
+
* @param {boolean} pixelart - Whether the pixel-art variant is meant
|
|
83
|
+
*/
|
|
84
|
+
static release(path: string, pixelart?: boolean): void;
|
|
85
|
+
/**
|
|
86
|
+
* @method refCount
|
|
87
|
+
* @description Current reference count for a texture (0 if uncached).
|
|
88
|
+
* @returns {number}
|
|
89
|
+
*/
|
|
90
|
+
static refCount(path: any, pixelart?: boolean): number;
|
|
91
|
+
/**
|
|
92
|
+
* @method clear
|
|
93
|
+
* @description Deletes all cached GL textures and clears the image cache.
|
|
94
|
+
* Useful when tearing down a context or freeing memory between levels.
|
|
95
|
+
*/
|
|
96
|
+
static clear(): void;
|
|
97
|
+
}
|
|
98
|
+
declare namespace TextureManager {
|
|
99
|
+
let images: Map<any, any>;
|
|
100
|
+
let textures: Map<any, any>;
|
|
101
|
+
let refs: Map<any, any>;
|
|
102
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export default Particle;
|
|
2
|
+
/**
|
|
3
|
+
* @class Particle
|
|
4
|
+
* @description Represents a particle in the particle system
|
|
5
|
+
* @param {InstancedTexture} instancedTexture - The instanced texture
|
|
6
|
+
* @param {Vector3} position - The position of the particle
|
|
7
|
+
* @param {number} rotation - The rotation of the particle
|
|
8
|
+
* @param {Vector2} scale - The scale of the particle
|
|
9
|
+
* @param {ParticleSettings} settings - The settings for the particle
|
|
10
|
+
*/
|
|
11
|
+
declare class Particle {
|
|
12
|
+
/** @private */
|
|
13
|
+
private static _normColor;
|
|
14
|
+
constructor(instancedTexture: any, position: any, rotation: any, scale: any, settings: any, velocity: any);
|
|
15
|
+
/**
|
|
16
|
+
* @method reset
|
|
17
|
+
* @description (Re)initializes the particle. Used by the pool so particle
|
|
18
|
+
* objects can be reused without allocating. `velocity` overrides
|
|
19
|
+
* settings.velocity when provided (avoids a ParticleSettings allocation per
|
|
20
|
+
* particle).
|
|
21
|
+
*/
|
|
22
|
+
reset(instancedTexture: any, position: any, rotation: any, scale: any, settings: any, velocity: any): void;
|
|
23
|
+
settings: any;
|
|
24
|
+
lifetime: any;
|
|
25
|
+
age: number;
|
|
26
|
+
velocity: {
|
|
27
|
+
x: any;
|
|
28
|
+
y: any;
|
|
29
|
+
};
|
|
30
|
+
gravity: {
|
|
31
|
+
x: any;
|
|
32
|
+
y: any;
|
|
33
|
+
};
|
|
34
|
+
instance: Instance;
|
|
35
|
+
/** @private */
|
|
36
|
+
private _baseScaleX;
|
|
37
|
+
/** @private */
|
|
38
|
+
private _baseScaleY;
|
|
39
|
+
/** @private */
|
|
40
|
+
private _colFrom;
|
|
41
|
+
/** @private */
|
|
42
|
+
private _colTo;
|
|
43
|
+
instancedTexture: any;
|
|
44
|
+
/** @private */
|
|
45
|
+
private _applyOverLife;
|
|
46
|
+
/**
|
|
47
|
+
* @method update
|
|
48
|
+
* @description Updates the particle
|
|
49
|
+
* @param {number} dt - The delta time
|
|
50
|
+
*/
|
|
51
|
+
update(dt: number): void;
|
|
52
|
+
/**
|
|
53
|
+
* @method isAlive
|
|
54
|
+
* @description Checks if the particle is alive
|
|
55
|
+
* @returns {boolean} - True if the particle is alive
|
|
56
|
+
*/
|
|
57
|
+
isAlive(): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* @method destroy
|
|
60
|
+
* @description Destroys the particle
|
|
61
|
+
*/
|
|
62
|
+
destroy(): void;
|
|
63
|
+
}
|
|
64
|
+
import Instance from "../Instance.js";
|