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.
- package/README.md +2198 -968
- package/dist/types/index.d.ts +75 -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} +6 -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} +75 -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 +81 -0
- package/dist/types/src/ParticleEmitter.d.ts +131 -0
- package/dist/types/src/Physics.d.ts +337 -0
- 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 +102 -0
- package/dist/types/src/components/GameObject.d.ts +135 -0
- package/dist/types/src/components/PolygonCollider.d.ts +33 -0
- package/dist/types/src/components/RigidBody.d.ts +456 -0
- package/dist/types/src/importers/Aseprite.d.ts +79 -0
- package/dist/types/src/importers/ForgeLevel.d.ts +97 -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/Gamepad.d.ts +102 -0
- package/dist/types/src/managers/IDManager.d.ts +31 -0
- package/dist/types/src/managers/InputManager.d.ts +381 -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/dist/types/src/physics/AABB.d.ts +92 -0
- package/dist/types/src/physics/Body.d.ts +435 -0
- package/dist/types/src/physics/BodyType.d.ts +6 -0
- package/dist/types/src/physics/BroadPhase.d.ts +210 -0
- package/dist/types/src/physics/Collision.d.ts +102 -0
- package/dist/types/src/physics/Contact.d.ts +206 -0
- package/dist/types/src/physics/ContactSolver.d.ts +108 -0
- package/dist/types/src/physics/Distance.d.ts +54 -0
- package/dist/types/src/physics/DistanceJoint.d.ts +90 -0
- package/dist/types/src/physics/Fixture.d.ts +221 -0
- package/dist/types/src/physics/Island.d.ts +52 -0
- package/dist/types/src/physics/Joint.d.ts +59 -0
- package/dist/types/src/physics/Math2D.d.ts +371 -0
- package/dist/types/src/physics/RevoluteJoint.d.ts +119 -0
- package/dist/types/src/physics/Settings.d.ts +22 -0
- package/dist/types/src/physics/Shapes.d.ts +207 -0
- package/dist/types/src/physics/TimeOfImpact.d.ts +22 -0
- package/dist/types/src/physics/World.d.ts +274 -0
- package/dist/types/src/physics/index.d.ts +34 -0
- package/index.js +78 -0
- package/package.json +73 -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 +26 -18
- package/src/Coroutine.js +259 -0
- package/src/DebugOverlay.js +246 -0
- package/src/Drawable.js +842 -582
- 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 +308 -127
- package/src/Interpolator.js +124 -0
- package/src/Material.js +202 -0
- package/src/MathUtils.js +134 -0
- package/src/ParticleEmitter.js +284 -0
- package/src/Physics.js +431 -40
- 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 +29 -12
- package/src/components/BoxColliderDebug.js +3 -4
- package/src/components/CircleCollider.js +26 -12
- package/src/components/CircleColliderDebug.js +25 -24
- package/src/components/Collider.js +150 -34
- package/src/components/GameObject.js +130 -21
- package/src/components/PolygonCollider.js +55 -0
- package/src/components/RigidBody.js +556 -8
- package/src/importers/Aseprite.js +142 -0
- package/src/importers/ForgeLevel.js +581 -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/Gamepad.js +126 -0
- package/src/managers/IDManager.js +24 -2
- package/src/managers/InputManager.js +905 -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/src/physics/AABB.js +207 -0
- package/src/physics/Body.js +862 -0
- package/src/physics/BodyType.js +16 -0
- package/src/physics/BroadPhase.js +641 -0
- package/src/physics/Collision.js +534 -0
- package/src/physics/Contact.js +500 -0
- package/src/physics/ContactSolver.js +526 -0
- package/src/physics/Distance.js +403 -0
- package/src/physics/DistanceJoint.js +227 -0
- package/src/physics/Fixture.js +346 -0
- package/src/physics/Island.js +203 -0
- package/src/physics/Joint.js +78 -0
- package/src/physics/Math2D.js +573 -0
- package/src/physics/RevoluteJoint.js +278 -0
- package/src/physics/Settings.js +78 -0
- package/src/physics/Shapes.js +549 -0
- package/src/physics/TimeOfImpact.js +87 -0
- package/src/physics/World.js +731 -0
- package/src/physics/index.js +79 -0
- 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/Physics.d.ts +0 -139
- 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
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { Vector2, Vector3 } from "./Physics";
|
|
3
|
-
import Transform from "./Transform";
|
|
1
|
+
export default Instance;
|
|
4
2
|
/**
|
|
5
3
|
* @class Instance
|
|
6
4
|
* @description Represents an instance
|
|
@@ -11,40 +9,63 @@ import Transform from "./Transform";
|
|
|
11
9
|
* @param {number} frame - The frame of the instance
|
|
12
10
|
*/
|
|
13
11
|
declare class Instance {
|
|
14
|
-
name:
|
|
12
|
+
constructor(name: any, position?: Vector3, scale?: Vector2, rotation?: number, frame?: number);
|
|
13
|
+
name: any;
|
|
15
14
|
transform: Transform;
|
|
16
15
|
id: string;
|
|
17
|
-
parent:
|
|
16
|
+
parent: Instance;
|
|
18
17
|
frame: number;
|
|
19
18
|
isAnimating: boolean;
|
|
20
|
-
animationFrames:
|
|
19
|
+
animationFrames: any[];
|
|
21
20
|
currentAnimationIndex: number;
|
|
22
21
|
animationSpeed: number;
|
|
23
22
|
lastFrameTime: number;
|
|
24
23
|
playOnce: boolean;
|
|
25
24
|
originalFrame: number;
|
|
26
25
|
components: any[];
|
|
27
|
-
|
|
26
|
+
/** @private */
|
|
27
|
+
private _tint;
|
|
28
|
+
/**
|
|
29
|
+
* @method setColor
|
|
30
|
+
* @description Sets this instance's tint. Accepts a Color (0..255 channels) or
|
|
31
|
+
* raw 0..1 components. Multiplies the texture/base color in the shader.
|
|
32
|
+
* @param {Color|number} colorOrR - A Color instance, or the red channel
|
|
33
|
+
* @param {number} [g]
|
|
34
|
+
* @param {number} [b]
|
|
35
|
+
* @param {number} [a]
|
|
36
|
+
*/
|
|
37
|
+
setColor(colorOrR: Color | number, g?: number, b?: number, a?: number): void;
|
|
38
|
+
/**
|
|
39
|
+
* @method setTexCoords
|
|
40
|
+
* @description Gives this instance an explicit UV quad (8 floats, one vec2
|
|
41
|
+
* per corner in the same order as getFrameTexCoords) instead of the shared
|
|
42
|
+
* frame grid. Lets one InstancedTexture batch tiles from an atlas with
|
|
43
|
+
* margins/spacing or per-instance flips. Pass null to go back to `frame`.
|
|
44
|
+
* @param {number[]|Float32Array|null} uv8 - 8 UV floats, or null to clear
|
|
45
|
+
*/
|
|
46
|
+
setTexCoords(uv8: number[] | Float32Array | null): void;
|
|
47
|
+
/** @private */
|
|
48
|
+
private _regionUV;
|
|
28
49
|
/**
|
|
29
50
|
* @method setParent
|
|
30
51
|
* @description Sets the parent of the instance
|
|
31
52
|
* @param {Instance} parent - The parent of the instance
|
|
32
53
|
*/
|
|
33
|
-
setParent(parent:
|
|
54
|
+
setParent(parent: Instance): void;
|
|
34
55
|
/**
|
|
35
56
|
* @method playAnimation
|
|
36
57
|
* @description Plays an animation with an array of frames
|
|
37
58
|
* @param {Array} frames - The frames to play
|
|
38
59
|
* @param {number} speed - The speed of the animation
|
|
39
60
|
*/
|
|
40
|
-
playAnimation(frames:
|
|
61
|
+
playAnimation(frames: any[], speed?: number): void;
|
|
41
62
|
/**
|
|
42
63
|
* @method playAnimationOnce
|
|
43
64
|
* @description Plays an animation with an array of frames once then stops
|
|
44
65
|
* @param {Array} frames - The frames to play
|
|
45
66
|
* @param {number} speed - The speed of the animation
|
|
46
67
|
*/
|
|
47
|
-
playAnimationOnce(frames:
|
|
68
|
+
playAnimationOnce(frames: any[], speed?: number): void;
|
|
48
69
|
/**
|
|
49
70
|
* @method stopAnimation
|
|
50
71
|
* @description Stops the animation and optionally reverts to the original frame
|
|
@@ -68,20 +89,21 @@ declare class Instance {
|
|
|
68
89
|
* @description Adds a component to the instance
|
|
69
90
|
* @param {Component} componentInstance - The component to add
|
|
70
91
|
*/
|
|
71
|
-
addComponent(componentInstance:
|
|
92
|
+
addComponent(componentInstance: Component): void;
|
|
72
93
|
/**
|
|
73
94
|
* @method removeComponent
|
|
74
95
|
* @description Removes a component from the instance
|
|
75
96
|
* @param {Component} component - The component to remove
|
|
76
97
|
*/
|
|
77
|
-
removeComponent(component:
|
|
98
|
+
removeComponent(component: Component): void;
|
|
78
99
|
/**
|
|
79
100
|
* @method getComponent
|
|
80
101
|
* @description Gets a component from the instance
|
|
81
102
|
* @param {Component} componentType - The type of the component to get
|
|
82
103
|
* @returns {Component} - The component
|
|
83
104
|
*/
|
|
84
|
-
getComponent(componentType:
|
|
105
|
+
getComponent(componentType: Component): Component;
|
|
85
106
|
}
|
|
86
|
-
|
|
87
|
-
|
|
107
|
+
import Transform from "./Transform.js";
|
|
108
|
+
import { Vector3 } from "./Physics.js";
|
|
109
|
+
import { Vector2 } from "./Physics.js";
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import Drawable from "./Drawable";
|
|
3
|
-
import { Vector3 } from "./Physics";
|
|
1
|
+
export default InstancedTexture;
|
|
4
2
|
/**
|
|
5
3
|
* @class InstancedTexture
|
|
6
4
|
* @description Represents an instanced texture component
|
|
@@ -16,18 +14,33 @@ import { Vector3 } from "./Physics";
|
|
|
16
14
|
* @param {boolean} useLighting - Whether to use lighting
|
|
17
15
|
*/
|
|
18
16
|
declare class InstancedTexture extends Drawable {
|
|
17
|
+
constructor(texturePath?: {}, instanceCount?: number, frameWidth?: number, frameHeight?: number, framesPerRow?: number, totalFrames?: number, animationSpeed?: number, autoPlay?: boolean, pixelart?: boolean, useLighting?: boolean);
|
|
19
18
|
instanceCount: number;
|
|
20
|
-
instances:
|
|
21
|
-
instanceMatrices: Float32Array
|
|
22
|
-
instanceTexCoords: Float32Array
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
19
|
+
instances: any[];
|
|
20
|
+
instanceMatrices: Float32Array<ArrayBuffer>;
|
|
21
|
+
instanceTexCoords: Float32Array<ArrayBuffer>;
|
|
22
|
+
instanceColors: Float32Array<ArrayBuffer>;
|
|
23
|
+
instanceMatrixBuffer: any;
|
|
24
|
+
instanceTexCoordBuffer: any;
|
|
25
|
+
instanceColorBuffer: any;
|
|
26
|
+
instanceClickListeners: Map<any, any>;
|
|
27
|
+
instanceHoverListeners: Map<any, any>;
|
|
28
|
+
static: boolean;
|
|
29
|
+
/** @private */
|
|
30
|
+
private _matricesDirty;
|
|
31
|
+
/** The animation every instance starts with; set by playAnimation/playAnimationOnce. @private */
|
|
32
|
+
private _defaultAnimation;
|
|
33
|
+
/**
|
|
34
|
+
* @method setStatic
|
|
35
|
+
* @description Toggles static mode (see constructor notes).
|
|
36
|
+
* @param {boolean} isStatic - Whether instances are non-moving
|
|
37
|
+
*/
|
|
38
|
+
setStatic(isStatic: boolean): void;
|
|
39
|
+
/**
|
|
40
|
+
* @method markDirty
|
|
41
|
+
* @description Forces an instance-matrix rebuild on the next draw.
|
|
42
|
+
*/
|
|
43
|
+
markDirty(): void;
|
|
31
44
|
/**
|
|
32
45
|
* @method addInstance
|
|
33
46
|
* @description Adds an instance to the instanced texture
|
|
@@ -62,6 +75,18 @@ declare class InstancedTexture extends Drawable {
|
|
|
62
75
|
* @description Updates all instance matrices
|
|
63
76
|
*/
|
|
64
77
|
updateAllInstanceMatrices(): void;
|
|
78
|
+
/**
|
|
79
|
+
* @method updateInstanceColor
|
|
80
|
+
* @description Writes a single instance's RGBA tint into the color array.
|
|
81
|
+
* Reads `instance._tint` ([r,g,b,a] in 0..1) when set, else opaque white.
|
|
82
|
+
* @param {number} index - The instance index
|
|
83
|
+
*/
|
|
84
|
+
updateInstanceColor(index: number): void;
|
|
85
|
+
/**
|
|
86
|
+
* @method updateAllInstanceColors
|
|
87
|
+
* @description Rebuilds and uploads the per-instance color buffer.
|
|
88
|
+
*/
|
|
89
|
+
updateAllInstanceColors(): void;
|
|
65
90
|
/**
|
|
66
91
|
* @method updateInstanceTexCoords
|
|
67
92
|
* @description Updates the texture coordinates for a specific instance
|
|
@@ -79,7 +104,7 @@ declare class InstancedTexture extends Drawable {
|
|
|
79
104
|
* @param {string} id - The ID of the instance to get
|
|
80
105
|
* @returns {Instance} - The instance
|
|
81
106
|
*/
|
|
82
|
-
getInstanceWithId(id: string): Instance
|
|
107
|
+
getInstanceWithId(id: string): Instance;
|
|
83
108
|
/**
|
|
84
109
|
* @method update
|
|
85
110
|
* @description Updates the instanced texture
|
|
@@ -93,7 +118,7 @@ declare class InstancedTexture extends Drawable {
|
|
|
93
118
|
* @param {Array} frames - The frames to animate
|
|
94
119
|
* @param {number} speed - The speed of the animation
|
|
95
120
|
*/
|
|
96
|
-
animateInstance(instanceId: string, frames:
|
|
121
|
+
animateInstance(instanceId: string, frames: any[], speed?: number): void;
|
|
97
122
|
/**
|
|
98
123
|
* @method stopInstanceAnimation
|
|
99
124
|
* @description Stops animation on a specific instance
|
|
@@ -133,7 +158,14 @@ declare class InstancedTexture extends Drawable {
|
|
|
133
158
|
* @param {number} frame - The frame to calculate the texture coordinates for
|
|
134
159
|
* @returns {Array} - The texture coordinates
|
|
135
160
|
*/
|
|
136
|
-
getFrameTexCoords(frame: number):
|
|
161
|
+
getFrameTexCoords(frame: number): any[];
|
|
162
|
+
/**
|
|
163
|
+
* @method syncPhysics
|
|
164
|
+
* @description Copies simulation state (position + rotation) from each
|
|
165
|
+
* instance's dynamic rigidbody onto the instance transform. Driven once per
|
|
166
|
+
* frame by the owning GameObject's syncPhysics(), so draw() stays read-only.
|
|
167
|
+
*/
|
|
168
|
+
syncPhysics(): void;
|
|
137
169
|
/**
|
|
138
170
|
* @method draw
|
|
139
171
|
* @description Draws the instanced texture
|
|
@@ -162,14 +194,14 @@ declare class InstancedTexture extends Drawable {
|
|
|
162
194
|
* @param {number} tolerance - The tolerance for the position
|
|
163
195
|
* @returns {Instance} - The instance at the position
|
|
164
196
|
*/
|
|
165
|
-
getInstanceAtPosition(position: Vector3, tolerance?: number): Instance
|
|
197
|
+
getInstanceAtPosition(position: Vector3, tolerance?: number): Instance;
|
|
166
198
|
/**
|
|
167
199
|
* @method getInstanceByFrame
|
|
168
200
|
* @description Gets an instance by its frame index
|
|
169
201
|
* @param {number} frameIndex - The frame index to get
|
|
170
202
|
* @returns {Instance} - The instance at the frame index
|
|
171
203
|
*/
|
|
172
|
-
getInstanceByFrame(frameIndex: number): Instance
|
|
204
|
+
getInstanceByFrame(frameIndex: number): Instance;
|
|
173
205
|
/**
|
|
174
206
|
* @method getInstanceAtPoint
|
|
175
207
|
* @description Gets an instance at a specific point
|
|
@@ -177,7 +209,7 @@ declare class InstancedTexture extends Drawable {
|
|
|
177
209
|
* @param {number} y - The y coordinate of the point
|
|
178
210
|
* @returns {Instance} - The instance at the point
|
|
179
211
|
*/
|
|
180
|
-
getInstanceAtPoint(x: number, y: number): Instance
|
|
212
|
+
getInstanceAtPoint(x: number, y: number): Instance;
|
|
181
213
|
/**
|
|
182
214
|
* @method addInstanceClickEvent
|
|
183
215
|
* @description Adds a click event listener to a specific instance
|
|
@@ -224,7 +256,27 @@ declare class InstancedTexture extends Drawable {
|
|
|
224
256
|
* @param {number} y - The y coordinate of the hover
|
|
225
257
|
* @param {Instance} lastHoveredInstance - The last hovered instance
|
|
226
258
|
*/
|
|
227
|
-
handleInstanceHover(event: Event, x: number, y: number, lastHoveredInstance: Instance
|
|
259
|
+
handleInstanceHover(event: Event, x: number, y: number, lastHoveredInstance: Instance): Instance;
|
|
260
|
+
/**
|
|
261
|
+
* @method playAnimationOnce
|
|
262
|
+
* @description Plays the same animation once, in lockstep, on every
|
|
263
|
+
* instance, then holds each on its last frame: the current instances
|
|
264
|
+
* immediately, and any added later via {@link InstancedTexture#addInstance}.
|
|
265
|
+
* @param {Array} frames - The frames to play
|
|
266
|
+
* @param {number} [speed=1000] - Milliseconds per frame
|
|
267
|
+
*/
|
|
268
|
+
playAnimationOnce(frames: any[], speed?: number): void;
|
|
269
|
+
/**
|
|
270
|
+
* @method stopAnimation
|
|
271
|
+
* @description Stops the shared animation started by playAnimation/
|
|
272
|
+
* playAnimationOnce on every current instance, and clears it so instances
|
|
273
|
+
* added afterwards no longer start playing it either. Instances animated
|
|
274
|
+
* individually via {@link InstancedTexture#animateInstance} are unaffected
|
|
275
|
+
* unless you stop them the same way, through {@link InstancedTexture#stopInstanceAnimation}.
|
|
276
|
+
* @param {boolean} [revertToOriginal=false] - Whether to reset each
|
|
277
|
+
* instance back to the frame it had before playAnimation was called
|
|
278
|
+
*/
|
|
279
|
+
stopAnimation(revertToOriginal?: boolean): void;
|
|
228
280
|
}
|
|
229
|
-
|
|
230
|
-
|
|
281
|
+
import Drawable from "./Drawable.js";
|
|
282
|
+
import Instance from "./Instance.js";
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export default Interpolator;
|
|
2
|
+
/**
|
|
3
|
+
* @class Interpolator
|
|
4
|
+
* @description Snapshot interpolation buffer for smoothing networked state.
|
|
5
|
+
* Authoritative updates arrive at a low, irregular rate (e.g. 10–20 Hz); this
|
|
6
|
+
* buffers timestamped snapshots and lets you sample a position "in the past" by
|
|
7
|
+
* a fixed render delay, so remote entities move smoothly between updates instead
|
|
8
|
+
* of teleporting.
|
|
9
|
+
*
|
|
10
|
+
* It is transport-agnostic and pure (no network/DOM dependency), so it works
|
|
11
|
+
* with the built-in NetworkManager, any other transport, or in tests.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const interp = new Interpolator({ delay: 0.1 });
|
|
15
|
+
* // on each server update for an entity:
|
|
16
|
+
* interp.push(entityId, { x, y }, serverTimeSeconds);
|
|
17
|
+
* // each frame:
|
|
18
|
+
* const pos = interp.sample(entityId, nowSeconds); // { x, y } or null
|
|
19
|
+
*/
|
|
20
|
+
declare class Interpolator {
|
|
21
|
+
/**
|
|
22
|
+
* @param {Object} [options] - { delay = 0.1, maxBuffer = 60 }
|
|
23
|
+
*/
|
|
24
|
+
constructor(options?: any);
|
|
25
|
+
delay: any;
|
|
26
|
+
maxBuffer: any;
|
|
27
|
+
/** @private */
|
|
28
|
+
private _buffers;
|
|
29
|
+
/**
|
|
30
|
+
* @method push
|
|
31
|
+
* @description Records a snapshot for an entity at a given timestamp.
|
|
32
|
+
* @param {string|number} id - Entity id
|
|
33
|
+
* @param {Object} state - Any object with numeric fields to interpolate (e.g. {x,y})
|
|
34
|
+
* @param {number} time - Snapshot timestamp in seconds
|
|
35
|
+
*/
|
|
36
|
+
push(id: string | number, state: any, time: number): void;
|
|
37
|
+
/**
|
|
38
|
+
* @method sample
|
|
39
|
+
* @description Returns the interpolated state for an entity at (now - delay).
|
|
40
|
+
* Linearly interpolates numeric fields between the two surrounding snapshots.
|
|
41
|
+
* Returns the latest snapshot if rendering ahead of the buffer, or null if no
|
|
42
|
+
* data exists.
|
|
43
|
+
* @param {string|number} id - Entity id
|
|
44
|
+
* @param {number} now - Current time in seconds
|
|
45
|
+
* @returns {Object|null} - Interpolated state, or null
|
|
46
|
+
*/
|
|
47
|
+
sample(id: string | number, now: number): any | null;
|
|
48
|
+
/**
|
|
49
|
+
* @method remove
|
|
50
|
+
* @description Drops an entity's buffer (e.g. when it leaves).
|
|
51
|
+
*/
|
|
52
|
+
remove(id: any): void;
|
|
53
|
+
/**
|
|
54
|
+
* @method prune
|
|
55
|
+
* @description Drops snapshots older than (now - delay - keep) to bound memory
|
|
56
|
+
* for long-lived entities.
|
|
57
|
+
* @param {number} now - Current time in seconds
|
|
58
|
+
* @param {number} [keep] - Extra history to retain past the render point
|
|
59
|
+
*/
|
|
60
|
+
prune(now: number, keep?: number): void;
|
|
61
|
+
/**
|
|
62
|
+
* @method clear
|
|
63
|
+
* @description Removes all buffered snapshots.
|
|
64
|
+
*/
|
|
65
|
+
clear(): void;
|
|
66
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export default Material;
|
|
2
|
+
/**
|
|
3
|
+
* @class Material
|
|
4
|
+
* @description A custom shader for a Drawable. By default it reuses the engine's
|
|
5
|
+
* standard vertex shader (so transforms, the camera, and instancing keep
|
|
6
|
+
* working) and only overrides the fragment program. Pass `options.vertex` to
|
|
7
|
+
* also supply a custom VERTEX program: the escape hatch for effects the fixed
|
|
8
|
+
* pipeline can't express (perspective tilt, vertex waves, billboarding, ...).
|
|
9
|
+
*
|
|
10
|
+
* The fragment shader always has: `vTexCoord`, `vFragPos`, `vInstanceColor`,
|
|
11
|
+
* `uSampler`, `uColor`, `uOpacity`, `uTime`. A custom vertex shader gets
|
|
12
|
+
* `aVertexPosition`, `aTextureCoord`, `uProjectionMatrix`, `uModelViewMatrix`,
|
|
13
|
+
* `uTime`, and must write `vTexCoord` + `gl_Position`.
|
|
14
|
+
*
|
|
15
|
+
* Declare extra uniforms and set them via `set(name, value)`. A uniform value
|
|
16
|
+
* may be a number, an array (vec2/3/4), or a FUNCTION: the function is called
|
|
17
|
+
* each draw and receives the Drawable currently rendering, so a single shared
|
|
18
|
+
* Material can read PER-OBJECT state (e.g. each card's own tilt angle).
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Per-object 3D tilt with one shared material:
|
|
22
|
+
* const tilt = new Material(fragSrc, {
|
|
23
|
+
* vertex: tiltVertexSrc,
|
|
24
|
+
* uniforms: { uTiltX: (d) => d._tiltX || 0, uTiltY: (d) => d._tiltY || 0 },
|
|
25
|
+
* });
|
|
26
|
+
* cardA.setMaterial(tilt); cardB.setMaterial(tilt);
|
|
27
|
+
* cardA.getComponent(Texture)._tiltX = 0.3; // each object animates independently
|
|
28
|
+
*/
|
|
29
|
+
declare class Material {
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} fragmentSource - Fragment shader body (declares void main)
|
|
32
|
+
* @param {Object} [options] - { vertex?: string, uniforms?: { name: value|function } }
|
|
33
|
+
*/
|
|
34
|
+
constructor(fragmentSource: string, options?: any);
|
|
35
|
+
gl: WebGLRenderingContext;
|
|
36
|
+
/** @private */
|
|
37
|
+
private _vertexSource;
|
|
38
|
+
/** @private */
|
|
39
|
+
private _fragmentSource;
|
|
40
|
+
program: any;
|
|
41
|
+
programInfo: {
|
|
42
|
+
program: any;
|
|
43
|
+
attribLocations: {
|
|
44
|
+
vertexPosition: number;
|
|
45
|
+
aTexCoord: number;
|
|
46
|
+
};
|
|
47
|
+
uniformLocations: {
|
|
48
|
+
projectionMatrix: WebGLUniformLocation;
|
|
49
|
+
globalViewMatrix: WebGLUniformLocation;
|
|
50
|
+
useInstances: WebGLUniformLocation;
|
|
51
|
+
uSampler: WebGLUniformLocation;
|
|
52
|
+
color: WebGLUniformLocation;
|
|
53
|
+
uOpacity: WebGLUniformLocation;
|
|
54
|
+
uTime: WebGLUniformLocation;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
uniforms: any;
|
|
58
|
+
/** @private */
|
|
59
|
+
private _locCache;
|
|
60
|
+
/**
|
|
61
|
+
* @method _restoreGL
|
|
62
|
+
* @description Recompiles the material's program and refreshes every cached
|
|
63
|
+
* location after a WebGL context loss.
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
private _restoreGL;
|
|
67
|
+
/**
|
|
68
|
+
* @method set
|
|
69
|
+
* @description Sets (or schedules) a custom uniform value. Numbers, arrays
|
|
70
|
+
* (vec2/3/4), and functions returning those are supported. A function uniform
|
|
71
|
+
* receives the Drawable currently being rendered.
|
|
72
|
+
* @param {string} name - Uniform name
|
|
73
|
+
* @param {number|number[]|Function} value
|
|
74
|
+
* @returns {Material} - this
|
|
75
|
+
*/
|
|
76
|
+
set(name: string, value: number | number[] | Function): Material;
|
|
77
|
+
/** @private */
|
|
78
|
+
private _loc;
|
|
79
|
+
/**
|
|
80
|
+
* @method applyCustomUniforms
|
|
81
|
+
* @description Uploads all user-declared uniforms. Called by Drawable each draw
|
|
82
|
+
* after the program is bound. Inferred by value shape. Function uniforms are
|
|
83
|
+
* called with the rendering Drawable so shared materials can read per-object data.
|
|
84
|
+
* @param {Drawable} [drawable] - The drawable currently rendering
|
|
85
|
+
*/
|
|
86
|
+
applyCustomUniforms(drawable?: Drawable): void;
|
|
87
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export default MathUtils;
|
|
2
|
+
/**
|
|
3
|
+
* @class MathUtils
|
|
4
|
+
* @description Common math helpers for games: interpolation, clamping, angle
|
|
5
|
+
* conversion, random ranges, and lightweight 2D vector operations that work on
|
|
6
|
+
* any `{ x, y }` object (including the physics engine's Vec2 and Emerald
|
|
7
|
+
* Vector2).
|
|
8
|
+
*/
|
|
9
|
+
declare class MathUtils {
|
|
10
|
+
/**
|
|
11
|
+
* Clamps a value to the [min, max] range.
|
|
12
|
+
*/
|
|
13
|
+
static clamp(value: any, min: any, max: any): any;
|
|
14
|
+
/**
|
|
15
|
+
* Linearly interpolates between a and b by t (t is not clamped).
|
|
16
|
+
*/
|
|
17
|
+
static lerp(a: any, b: any, t: any): any;
|
|
18
|
+
/**
|
|
19
|
+
* Inverse lerp: returns the t for which lerp(a, b, t) === value.
|
|
20
|
+
*/
|
|
21
|
+
static inverseLerp(a: any, b: any, value: any): number;
|
|
22
|
+
/**
|
|
23
|
+
* Remaps a value from one range to another.
|
|
24
|
+
*/
|
|
25
|
+
static map(value: any, inMin: any, inMax: any, outMin: any, outMax: any): any;
|
|
26
|
+
/**
|
|
27
|
+
* Converts degrees to radians.
|
|
28
|
+
*/
|
|
29
|
+
static degToRad(degrees: any): number;
|
|
30
|
+
/**
|
|
31
|
+
* Converts radians to degrees.
|
|
32
|
+
*/
|
|
33
|
+
static radToDeg(radians: any): number;
|
|
34
|
+
/**
|
|
35
|
+
* Returns a random float in [min, max).
|
|
36
|
+
*/
|
|
37
|
+
static randomRange(min: any, max: any): any;
|
|
38
|
+
/**
|
|
39
|
+
* Returns a random integer in [min, max] (inclusive).
|
|
40
|
+
*/
|
|
41
|
+
static randomInt(min: any, max: any): number;
|
|
42
|
+
/**
|
|
43
|
+
* Returns a random element of an array (or undefined if empty).
|
|
44
|
+
*/
|
|
45
|
+
static randomChoice(array: any): any;
|
|
46
|
+
/**
|
|
47
|
+
* Euclidean distance between two `{ x, y }` points.
|
|
48
|
+
*/
|
|
49
|
+
static distance(a: any, b: any): number;
|
|
50
|
+
/**
|
|
51
|
+
* Squared distance between two points (cheaper than distance for comparisons).
|
|
52
|
+
*/
|
|
53
|
+
static distanceSquared(a: any, b: any): number;
|
|
54
|
+
/**
|
|
55
|
+
* Vector length (magnitude) of an `{ x, y }`.
|
|
56
|
+
*/
|
|
57
|
+
static length(v: any): number;
|
|
58
|
+
/**
|
|
59
|
+
* Returns a normalized copy of `{ x, y }` as a plain object. Zero-length
|
|
60
|
+
* vectors return { x: 0, y: 0 }.
|
|
61
|
+
*/
|
|
62
|
+
static normalize(v: any): {
|
|
63
|
+
x: number;
|
|
64
|
+
y: number;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Dot product of two `{ x, y }` vectors.
|
|
68
|
+
*/
|
|
69
|
+
static dot(a: any, b: any): number;
|
|
70
|
+
/**
|
|
71
|
+
* Angle in radians from a to b.
|
|
72
|
+
*/
|
|
73
|
+
static angleBetween(a: any, b: any): number;
|
|
74
|
+
/**
|
|
75
|
+
* Linearly interpolates between two `{ x, y }` points, returning a plain object.
|
|
76
|
+
*/
|
|
77
|
+
static lerpVector(a: any, b: any, t: any): {
|
|
78
|
+
x: any;
|
|
79
|
+
y: any;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
export default ParticleEmitter;
|
|
2
|
+
/**
|
|
3
|
+
* @class ParticleEmitter
|
|
4
|
+
* @description A reliable, allocation-free particle system built from a fixed
|
|
5
|
+
* pool of ordinary textured GameObjects. Each live particle's transform, tint
|
|
6
|
+
* and opacity are driven by hand every frame; there is no instanced-draw /
|
|
7
|
+
* dynamic-buffer lifecycle to desync, so it keeps drawing for the whole session
|
|
8
|
+
* (unlike the InstancedTexture-based `Particles`, which can stop emitting after
|
|
9
|
+
* heavy reuse on some GPUs).
|
|
10
|
+
*
|
|
11
|
+
* Spawn with `burst(n, cfg)` or `emit(cfg)`; advance with `update(dt)` once per
|
|
12
|
+
* frame. Every `cfg` field is optional and has a sensible default, so the
|
|
13
|
+
* minimal call is `emitter.burst(8, { x, y })`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const fx = new ParticleEmitter(scene, { texture: smokeImg, layer: 50 });
|
|
17
|
+
* fx.burst(12, {
|
|
18
|
+
* x: 100, y: 200, dir: -Math.PI / 2, spread: Math.PI, speed: 180,
|
|
19
|
+
* gy: -300, drag: 2, life: 0.4, size: 8, sFrom: 1, sTo: 0.1,
|
|
20
|
+
* aFrom: 0.7, aTo: 0, cr: 255, cg: 220, cb: 120, additive: true,
|
|
21
|
+
* shape: "circle", radius: 6,
|
|
22
|
+
* });
|
|
23
|
+
* // in the loop: fx.update(dt);
|
|
24
|
+
*/
|
|
25
|
+
declare class ParticleEmitter {
|
|
26
|
+
/**
|
|
27
|
+
* @param {Scene} scene - Scene the particle GameObjects are added to
|
|
28
|
+
* @param {Object} [options]
|
|
29
|
+
* @param {string|HTMLImageElement} [options.texture] - Particle sprite source
|
|
30
|
+
* @param {number} [options.capacity=256] - Pool size (max live particles)
|
|
31
|
+
* @param {number} [options.layer=0] - Render layer for every particle
|
|
32
|
+
* @param {boolean} [options.pixelart=false] - Pixel-art sampling for the sprite
|
|
33
|
+
* @param {Function} [options.spriteFactory] - `(texture, options) => Drawable`
|
|
34
|
+
* override used to build each particle's drawable (handy for tests / custom
|
|
35
|
+
* shaders). Defaults to a non-lit `Texture`.
|
|
36
|
+
*/
|
|
37
|
+
constructor(scene: Scene, options?: {
|
|
38
|
+
texture?: string | HTMLImageElement;
|
|
39
|
+
capacity?: number;
|
|
40
|
+
layer?: number;
|
|
41
|
+
pixelart?: boolean;
|
|
42
|
+
spriteFactory?: Function;
|
|
43
|
+
});
|
|
44
|
+
scene: Scene;
|
|
45
|
+
capacity: number;
|
|
46
|
+
layer: number;
|
|
47
|
+
parts: {
|
|
48
|
+
go: GameObject;
|
|
49
|
+
drawable: any;
|
|
50
|
+
color: Color;
|
|
51
|
+
alive: boolean;
|
|
52
|
+
x: number;
|
|
53
|
+
y: number;
|
|
54
|
+
vx: number;
|
|
55
|
+
vy: number;
|
|
56
|
+
gx: number;
|
|
57
|
+
gy: number;
|
|
58
|
+
drag: number;
|
|
59
|
+
age: number;
|
|
60
|
+
life: number;
|
|
61
|
+
base: number;
|
|
62
|
+
sFrom: number;
|
|
63
|
+
sTo: number;
|
|
64
|
+
aFrom: number;
|
|
65
|
+
aTo: number;
|
|
66
|
+
rot: number;
|
|
67
|
+
rotSpeed: number;
|
|
68
|
+
additive: boolean;
|
|
69
|
+
}[];
|
|
70
|
+
free: {
|
|
71
|
+
go: GameObject;
|
|
72
|
+
drawable: any;
|
|
73
|
+
color: Color;
|
|
74
|
+
alive: boolean;
|
|
75
|
+
x: number;
|
|
76
|
+
y: number;
|
|
77
|
+
vx: number;
|
|
78
|
+
vy: number;
|
|
79
|
+
gx: number;
|
|
80
|
+
gy: number;
|
|
81
|
+
drag: number;
|
|
82
|
+
age: number;
|
|
83
|
+
life: number;
|
|
84
|
+
base: number;
|
|
85
|
+
sFrom: number;
|
|
86
|
+
sTo: number;
|
|
87
|
+
aFrom: number;
|
|
88
|
+
aTo: number;
|
|
89
|
+
rot: number;
|
|
90
|
+
rotSpeed: number;
|
|
91
|
+
additive: boolean;
|
|
92
|
+
}[];
|
|
93
|
+
/**
|
|
94
|
+
* @member activeCount
|
|
95
|
+
* @description Number of particles currently alive.
|
|
96
|
+
*/
|
|
97
|
+
get activeCount(): number;
|
|
98
|
+
/**
|
|
99
|
+
* @method emit
|
|
100
|
+
* @description Spawns a single particle. Returns the emitter for chaining.
|
|
101
|
+
* @param {Object} cfg - Spawn config (see class example; all fields optional)
|
|
102
|
+
*/
|
|
103
|
+
emit(cfg?: any): this;
|
|
104
|
+
/**
|
|
105
|
+
* @method burst
|
|
106
|
+
* @description Spawns `n` particles with the same config.
|
|
107
|
+
* @param {number} n - How many to spawn
|
|
108
|
+
* @param {Object} cfg - Spawn config
|
|
109
|
+
*/
|
|
110
|
+
burst(n: number, cfg?: any): this;
|
|
111
|
+
/** @private */
|
|
112
|
+
private _spawn;
|
|
113
|
+
/**
|
|
114
|
+
* @method update
|
|
115
|
+
* @description Advances and renders every live particle. Call once per frame.
|
|
116
|
+
* @param {number} dt - Seconds since the last frame
|
|
117
|
+
*/
|
|
118
|
+
update(dt: number): void;
|
|
119
|
+
/**
|
|
120
|
+
* @method reset
|
|
121
|
+
* @description Kills every live particle immediately (no fade).
|
|
122
|
+
*/
|
|
123
|
+
reset(): void;
|
|
124
|
+
/**
|
|
125
|
+
* @method destroy
|
|
126
|
+
* @description Removes every particle GameObject from the scene.
|
|
127
|
+
*/
|
|
128
|
+
destroy(): void;
|
|
129
|
+
}
|
|
130
|
+
import GameObject from "./components/GameObject.js";
|
|
131
|
+
import Color from "./Color.js";
|