emeraldengine 2.2.1 → 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 -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 +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,135 @@
|
|
|
1
|
+
export default GameObject;
|
|
2
|
+
/**
|
|
3
|
+
* @class GameObject
|
|
4
|
+
* @param {string} name - The name of the game object
|
|
5
|
+
* @param {Vector3} position - The position of the game object
|
|
6
|
+
* @param {number} rotation - The rotation of the game object
|
|
7
|
+
* @param {Vector2} scale - The scale of the game object
|
|
8
|
+
*/
|
|
9
|
+
declare class GameObject {
|
|
10
|
+
constructor(name: any, position?: Vector3, rotation?: number, scale?: Vector2);
|
|
11
|
+
name: any;
|
|
12
|
+
components: any[];
|
|
13
|
+
id: string;
|
|
14
|
+
isActive: boolean;
|
|
15
|
+
transform: Transform;
|
|
16
|
+
opacity: number;
|
|
17
|
+
layer: number;
|
|
18
|
+
screenSpace: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* @method setLayer
|
|
21
|
+
* @description Sets the render layer. Objects are drawn by layer first, then
|
|
22
|
+
* by z within a layer.
|
|
23
|
+
* @param {number} layer - The layer index
|
|
24
|
+
* @returns {GameObject} - this
|
|
25
|
+
*/
|
|
26
|
+
setLayer(layer: number): GameObject;
|
|
27
|
+
/**
|
|
28
|
+
* @method setScreenSpace
|
|
29
|
+
* @description When true, the object ignores the camera (fixed on screen) —
|
|
30
|
+
* useful for HUD/UI. Position is then in pixels from the viewport center.
|
|
31
|
+
* Note: not supported for InstancedTexture-based objects.
|
|
32
|
+
* @param {boolean} value
|
|
33
|
+
* @returns {GameObject} - this
|
|
34
|
+
*/
|
|
35
|
+
setScreenSpace(value: boolean): GameObject;
|
|
36
|
+
/**
|
|
37
|
+
* @method addComponent
|
|
38
|
+
* @description Adds a component to the game object
|
|
39
|
+
* @param {Component} componentInstance - The component to add
|
|
40
|
+
*/
|
|
41
|
+
addComponent(componentInstance: Component): void;
|
|
42
|
+
/**
|
|
43
|
+
* @method removeComponent
|
|
44
|
+
* @description Removes a component from the game object
|
|
45
|
+
* @param {Component} component - The component to remove
|
|
46
|
+
*/
|
|
47
|
+
removeComponent(component: Component): void;
|
|
48
|
+
/**
|
|
49
|
+
* @method update
|
|
50
|
+
* @description Ticks the lifecycle of Behaviour components on this object.
|
|
51
|
+
* Only Behaviours are ticked here so component types with their own update
|
|
52
|
+
* signature (e.g. InstancedTexture) are left untouched.
|
|
53
|
+
* @param {number} deltaTime - Seconds since the previous frame (time-scaled)
|
|
54
|
+
*/
|
|
55
|
+
update(deltaTime: number): void;
|
|
56
|
+
/**
|
|
57
|
+
* @method setParent
|
|
58
|
+
* @description Parents this object to another GameObject (or detaches with
|
|
59
|
+
* null). The object's transform then composes on top of the parent's, so
|
|
60
|
+
* moving/rotating/scaling the parent moves its children.
|
|
61
|
+
* @param {GameObject|null} parent - The parent GameObject, or null
|
|
62
|
+
* @returns {GameObject} - this
|
|
63
|
+
*/
|
|
64
|
+
setParent(parent: GameObject | null): GameObject;
|
|
65
|
+
/**
|
|
66
|
+
* @method addChild
|
|
67
|
+
* @description Parents another GameObject to this one.
|
|
68
|
+
* @param {GameObject} child - The child GameObject
|
|
69
|
+
* @returns {GameObject} - this
|
|
70
|
+
*/
|
|
71
|
+
addChild(child: GameObject): GameObject;
|
|
72
|
+
/**
|
|
73
|
+
* @method setIsActive
|
|
74
|
+
* @description Sets the active state of the game object
|
|
75
|
+
* @param {boolean} bool - The active state
|
|
76
|
+
*/
|
|
77
|
+
setIsActive(bool: boolean): void;
|
|
78
|
+
/**
|
|
79
|
+
* @method setOpacity
|
|
80
|
+
* @description Sets the opacity of the game object (0..1)
|
|
81
|
+
* @param {number} value - The opacity value between 0 and 1
|
|
82
|
+
*/
|
|
83
|
+
setOpacity(value: number): void;
|
|
84
|
+
/**
|
|
85
|
+
* @method getOpacity
|
|
86
|
+
* @description Gets the opacity of the game object
|
|
87
|
+
* @returns {number} - The opacity value between 0 and 1
|
|
88
|
+
*/
|
|
89
|
+
getOpacity(): number;
|
|
90
|
+
/**
|
|
91
|
+
* @method getComponent
|
|
92
|
+
* @description Returns a component from the game object
|
|
93
|
+
* @param {Component} componentType - The type of component to return
|
|
94
|
+
*/
|
|
95
|
+
getComponent(componentType: Component): any;
|
|
96
|
+
/**
|
|
97
|
+
* @method getRigidBodyAtPosition
|
|
98
|
+
* @description Returns the rigidbody at a position
|
|
99
|
+
* @param {Vector2} position - The position to check
|
|
100
|
+
*/
|
|
101
|
+
getRigidBodyAtPosition(position: Vector2): RigidBody;
|
|
102
|
+
/**
|
|
103
|
+
* @method syncPhysics
|
|
104
|
+
* @description Copies simulation state (position + rotation) from this
|
|
105
|
+
* object's dynamic rigidbody onto its transform, and mirrors it onto any
|
|
106
|
+
* visible collider debug shape. Called once per frame from the render loop so
|
|
107
|
+
* draw() stays read-only and physics isn't re-applied per camera. Also
|
|
108
|
+
* forwards to components that own their own physics-driven content (e.g.
|
|
109
|
+
* InstancedTexture).
|
|
110
|
+
*/
|
|
111
|
+
syncPhysics(): void;
|
|
112
|
+
/**
|
|
113
|
+
* @method destroy
|
|
114
|
+
* @description Permanently tears the object down: disposes every Drawable's
|
|
115
|
+
* GPU resources, destroys physics bodies, and runs Behaviour.onDestroy().
|
|
116
|
+
* Use it (or Scene.remove(obj, { dispose: true })) when an object will not
|
|
117
|
+
* be re-added — plain Scene.remove() keeps GPU resources alive for re-use.
|
|
118
|
+
* Safe to call twice.
|
|
119
|
+
*/
|
|
120
|
+
destroy(): void;
|
|
121
|
+
/** @private */
|
|
122
|
+
private _destroyed;
|
|
123
|
+
/**
|
|
124
|
+
* @method draw
|
|
125
|
+
* @description Draws the game object
|
|
126
|
+
* @param {Matrix4} globalViewMatrix - The global view matrix
|
|
127
|
+
* @param {WebGLUniformLocation} uniformLocation - The uniform location
|
|
128
|
+
* @param {number} currentTime - The current time
|
|
129
|
+
*/
|
|
130
|
+
draw(globalViewMatrix: Matrix4, uniformLocation: WebGLUniformLocation, currentTime: number): void;
|
|
131
|
+
}
|
|
132
|
+
import Transform from "../Transform.js";
|
|
133
|
+
import { Vector2 } from "../Physics.js";
|
|
134
|
+
import RigidBody from "./RigidBody.js";
|
|
135
|
+
import { Vector3 } from "../Physics.js";
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
export default RigidBody;
|
|
2
|
+
/**
|
|
3
|
+
* @class RigidBody
|
|
4
|
+
* @param {Physics} physics - The physics engine
|
|
5
|
+
* @param {string | "static" | "dynamic" | "kinematic"} type - The type of rigidbody
|
|
6
|
+
* @param {Vector2} position - The position of the rigidbody
|
|
7
|
+
* @param {boolean} fixedRotation - Whether the rigidbody is fixed rotation
|
|
8
|
+
* @param {GameObject} parentObject - The parent object of the rigidbody
|
|
9
|
+
* @param {Vector2} offset - The offset of the rigidbody
|
|
10
|
+
*/
|
|
11
|
+
declare class RigidBody {
|
|
12
|
+
constructor(physics: any, type: any, position: any, fixedRotation: any, parentObject?: any, offset?: Vector2);
|
|
13
|
+
physics: any;
|
|
14
|
+
offset: Vector2;
|
|
15
|
+
type: any;
|
|
16
|
+
body: any;
|
|
17
|
+
parentObject: any;
|
|
18
|
+
position: any;
|
|
19
|
+
collider: Collider;
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
/**
|
|
23
|
+
* @method updatePosition
|
|
24
|
+
* @description Updates the position of the rigidbody
|
|
25
|
+
* @param {Vector2} position - The new position
|
|
26
|
+
*/
|
|
27
|
+
updatePosition(position: Vector2): void;
|
|
28
|
+
/**
|
|
29
|
+
* @method getWorldX
|
|
30
|
+
* @description The single source of truth for body(physics) -> world(pixel)
|
|
31
|
+
* conversion on X: undo the scale and the spawn offset.
|
|
32
|
+
* @returns {number} - The live world-space x of the body
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
private getWorldX;
|
|
36
|
+
/**
|
|
37
|
+
* @method getWorldY
|
|
38
|
+
* @description World-space y counterpart of getWorldX.
|
|
39
|
+
* @returns {number} - The live world-space y of the body
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
private getWorldY;
|
|
43
|
+
/**
|
|
44
|
+
* @method syncTransform
|
|
45
|
+
* @description Writes the body's live world position and angle into a
|
|
46
|
+
* Transform. This is the one place body state is copied onto a renderable, so
|
|
47
|
+
* position and rotation stay in lock-step. Static/kinematic bodies are not
|
|
48
|
+
* driven by the simulation, so only dynamic bodies write back.
|
|
49
|
+
* @param {Transform} transform - The transform to update in place
|
|
50
|
+
*/
|
|
51
|
+
syncTransform(transform: Transform): void;
|
|
52
|
+
/**
|
|
53
|
+
* @method getOffset
|
|
54
|
+
* @description Returns the offset of the rigidbody
|
|
55
|
+
* @returns {Vector2} - The offset of the rigidbody
|
|
56
|
+
*/
|
|
57
|
+
getOffset(): Vector2;
|
|
58
|
+
/**
|
|
59
|
+
* @method setCollider
|
|
60
|
+
* @description Sets the collider of the rigidbody
|
|
61
|
+
* @param {Collider} collider - The collider to set
|
|
62
|
+
*/
|
|
63
|
+
setCollider(collider: Collider): void;
|
|
64
|
+
/**
|
|
65
|
+
* @method setRotation
|
|
66
|
+
* @description Sets the rotation of the rigidbody
|
|
67
|
+
* @param {number} rotation - The new rotation
|
|
68
|
+
*/
|
|
69
|
+
setRotation(rotation: number): void;
|
|
70
|
+
/**
|
|
71
|
+
* @method setLinearVelocity
|
|
72
|
+
* @description Sets the body's linear velocity in world (pixel) units per
|
|
73
|
+
* second. Converts to physics units internally.
|
|
74
|
+
* @param {number} vx - Horizontal velocity (world units/sec)
|
|
75
|
+
* @param {number} vy - Vertical velocity (world units/sec)
|
|
76
|
+
*/
|
|
77
|
+
setLinearVelocity(vx: number, vy: number): void;
|
|
78
|
+
/**
|
|
79
|
+
* @method getLinearVelocity
|
|
80
|
+
* @description Returns the body's linear velocity in world (pixel) units/sec.
|
|
81
|
+
* @returns {{x:number, y:number}}
|
|
82
|
+
*/
|
|
83
|
+
getLinearVelocity(): {
|
|
84
|
+
x: number;
|
|
85
|
+
y: number;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* @method applyImpulse
|
|
89
|
+
* @description Applies a linear impulse (world units) at the body's center.
|
|
90
|
+
* @param {number} ix
|
|
91
|
+
* @param {number} iy
|
|
92
|
+
*/
|
|
93
|
+
applyImpulse(ix: number, iy: number): void;
|
|
94
|
+
/**
|
|
95
|
+
* @method setAwake
|
|
96
|
+
* @description Wakes or sleeps the body.
|
|
97
|
+
* @param {boolean} awake
|
|
98
|
+
*/
|
|
99
|
+
setAwake(awake: boolean): void;
|
|
100
|
+
/**
|
|
101
|
+
* @method setContinuous
|
|
102
|
+
* @description Enables continuous collision detection (CCD) for this body by
|
|
103
|
+
* marking it a "bullet". Fast-moving bodies (e.g. a dash, a projectile, a
|
|
104
|
+
* player falling at high speed) otherwise sweep so far in a single fixed step
|
|
105
|
+
* that they tunnel straight through thin static geometry; with CCD on, planck
|
|
106
|
+
* solves the swept path against static bodies so the body stops at the wall
|
|
107
|
+
* instead of teleporting past it. Costs more per step, so reserve it for the
|
|
108
|
+
* handful of bodies that actually move fast.
|
|
109
|
+
* @param {boolean} [enabled=true]
|
|
110
|
+
* @returns {RigidBody} - this
|
|
111
|
+
*/
|
|
112
|
+
setContinuous(enabled?: boolean): RigidBody;
|
|
113
|
+
/**
|
|
114
|
+
* @method isContinuous
|
|
115
|
+
* @description Whether CCD (bullet mode) is enabled for this body.
|
|
116
|
+
* @returns {boolean}
|
|
117
|
+
*/
|
|
118
|
+
isContinuous(): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* @method getPosition
|
|
121
|
+
* @description Returns the live world-space position of the body (kept in sync
|
|
122
|
+
* with the simulation), not the spawn position. Use getInitialPosition() for
|
|
123
|
+
* the position the body was created at.
|
|
124
|
+
* @returns {Vector2} - The current world-space position of the rigidbody
|
|
125
|
+
*/
|
|
126
|
+
getPosition(): Vector2;
|
|
127
|
+
/**
|
|
128
|
+
* @method getInitialPosition
|
|
129
|
+
* @description Returns the world-space position the body was created at.
|
|
130
|
+
* @returns {Vector2} - The spawn position of the rigidbody
|
|
131
|
+
*/
|
|
132
|
+
getInitialPosition(): Vector2;
|
|
133
|
+
/**
|
|
134
|
+
* @method getAngle
|
|
135
|
+
* @description Returns the angle of the rigidbody
|
|
136
|
+
* @returns {number} - The angle of the rigidbody
|
|
137
|
+
*/
|
|
138
|
+
getAngle(): number;
|
|
139
|
+
/**
|
|
140
|
+
* @method getCollider
|
|
141
|
+
* @description Returns the collider of the rigidbody
|
|
142
|
+
* @returns {Collider} - The collider of the rigidbody
|
|
143
|
+
*/
|
|
144
|
+
getCollider(): Collider;
|
|
145
|
+
/**
|
|
146
|
+
* @method getBody
|
|
147
|
+
* @description Returns the body of the rigidbody
|
|
148
|
+
* @returns {planck.Body} - The body of the rigidbody
|
|
149
|
+
*/
|
|
150
|
+
getBody(): planck.Body;
|
|
151
|
+
/**
|
|
152
|
+
* @method getPhysics
|
|
153
|
+
* @description Returns the physics engine of the rigidbody
|
|
154
|
+
* @returns {Physics} - The physics engine of the rigidbody
|
|
155
|
+
*/
|
|
156
|
+
getPhysics(): Physics;
|
|
157
|
+
/**
|
|
158
|
+
* @method destroy
|
|
159
|
+
* @description Destroys the rigidbody
|
|
160
|
+
*/
|
|
161
|
+
destroy(): void;
|
|
162
|
+
/**
|
|
163
|
+
* @method detachCollider
|
|
164
|
+
* @description Detaches a collider from the rigidbody
|
|
165
|
+
* @param {Collider} collider - The collider to detach
|
|
166
|
+
*/
|
|
167
|
+
detachCollider(collider: Collider): void;
|
|
168
|
+
/**
|
|
169
|
+
* @method setParent
|
|
170
|
+
* @description Sets the parent object of the rigidbody
|
|
171
|
+
* @param {GameObject} parent - The parent object to set
|
|
172
|
+
*/
|
|
173
|
+
setParent(parent: GameObject): void;
|
|
174
|
+
/**
|
|
175
|
+
* @method getType
|
|
176
|
+
* @description Returns the type of the rigidbody
|
|
177
|
+
* @returns {string | "static" | "dynamic" | "kinematic"} - The type of the rigidbody
|
|
178
|
+
*/
|
|
179
|
+
getType(): string | "static" | "dynamic" | "kinematic";
|
|
180
|
+
}
|
|
181
|
+
import { Vector2 } from "../Physics.js";
|
|
182
|
+
import Collider from "./Collider.js";
|
|
183
|
+
import * as planck from "planck";
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export default Aseprite;
|
|
2
|
+
/**
|
|
3
|
+
* @class Aseprite
|
|
4
|
+
* @description Imports sprite-sheet metadata exported from Aseprite
|
|
5
|
+
* (File ▸ Export Sprite Sheet, with "JSON Data" on) and turns its frame tags
|
|
6
|
+
* into engine animation clips. Works with both the Hash and Array JSON layouts.
|
|
7
|
+
* Pure parsing — pass it the already-parsed JSON object.
|
|
8
|
+
*
|
|
9
|
+
* Assumes the sheet is a uniform grid in frame order (the common case), so the
|
|
10
|
+
* frame indices line up with the engine's Texture/Animator frame numbering.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const cfg = Aseprite.spriteConfig(sheetJson); // {frameWidth, framesPerRow, ...}
|
|
14
|
+
* const tex = new Texture("hero.png", cfg.frameWidth, cfg.frameHeight,
|
|
15
|
+
* cfg.framesPerRow, cfg.totalFrames, 0, false);
|
|
16
|
+
* obj.addComponent(tex);
|
|
17
|
+
* const anim = new Animator();
|
|
18
|
+
* obj.addComponent(anim);
|
|
19
|
+
* Aseprite.applyTo(anim, sheetJson); // registers "idle", "run", ... clips
|
|
20
|
+
* anim.play("run");
|
|
21
|
+
*/
|
|
22
|
+
declare class Aseprite {
|
|
23
|
+
/**
|
|
24
|
+
* @method frames
|
|
25
|
+
* @description Returns the frames as an ordered array regardless of whether
|
|
26
|
+
* the export used the Hash (object) or Array layout.
|
|
27
|
+
* @param {Object} sheet - Parsed Aseprite JSON
|
|
28
|
+
* @returns {Array<Object>}
|
|
29
|
+
*/
|
|
30
|
+
static frames(sheet: any): Array<any>;
|
|
31
|
+
/**
|
|
32
|
+
* @method spriteConfig
|
|
33
|
+
* @description Derives the uniform-grid sprite config (for Texture) from the
|
|
34
|
+
* first frame and the sheet size.
|
|
35
|
+
* @param {Object} sheet - Parsed Aseprite JSON
|
|
36
|
+
* @returns {{frameWidth:number, frameHeight:number, framesPerRow:number, totalFrames:number}}
|
|
37
|
+
*/
|
|
38
|
+
static spriteConfig(sheet: any): {
|
|
39
|
+
frameWidth: number;
|
|
40
|
+
frameHeight: number;
|
|
41
|
+
framesPerRow: number;
|
|
42
|
+
totalFrames: number;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* @method durations
|
|
46
|
+
* @description Per-frame durations in milliseconds, in frame order.
|
|
47
|
+
* @param {Object} sheet - Parsed Aseprite JSON
|
|
48
|
+
* @returns {number[]}
|
|
49
|
+
*/
|
|
50
|
+
static durations(sheet: any): number[];
|
|
51
|
+
/** @private */
|
|
52
|
+
private static _expandTag;
|
|
53
|
+
/**
|
|
54
|
+
* @method toClips
|
|
55
|
+
* @description Builds clip descriptors from the sheet's frame tags. Each clip
|
|
56
|
+
* is `{ name, frames, speed }` where `frames` are frame indices and `speed`
|
|
57
|
+
* is the average frame duration (ms) — the per-clip speed the Animator uses.
|
|
58
|
+
* If the sheet has no tags, a single "default" clip spanning all frames is
|
|
59
|
+
* returned.
|
|
60
|
+
* @param {Object} sheet - Parsed Aseprite JSON
|
|
61
|
+
* @returns {Array<{name:string, frames:number[], speed:number}>}
|
|
62
|
+
*/
|
|
63
|
+
static toClips(sheet: any): Array<{
|
|
64
|
+
name: string;
|
|
65
|
+
frames: number[];
|
|
66
|
+
speed: number;
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* @method applyTo
|
|
70
|
+
* @description Registers every clip from the sheet on an Animator. Clips loop
|
|
71
|
+
* by default; pass `loop` as a boolean (applies to all) or an object mapping
|
|
72
|
+
* clip name -> boolean to override individual clips.
|
|
73
|
+
* @param {Animator} animator - Target animator
|
|
74
|
+
* @param {Object} sheet - Parsed Aseprite JSON
|
|
75
|
+
* @param {Object} [options] - { loop = true }
|
|
76
|
+
* @returns {Animator} - The animator (for chaining)
|
|
77
|
+
*/
|
|
78
|
+
static applyTo(animator: Animator, sheet: any, options?: any): Animator;
|
|
79
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export default TiledMap;
|
|
2
|
+
export const FLIP_FLAGS: 3758096384;
|
|
3
|
+
export const GID_MASK: 536870911;
|
|
4
|
+
/**
|
|
5
|
+
* @class TiledMap
|
|
6
|
+
* @description Imports orthogonal maps exported from the Tiled editor
|
|
7
|
+
* (https://www.mapeditor.org) in JSON format into the engine's Tilemap, plus
|
|
8
|
+
* helpers to pull object layers (spawn points, triggers, etc.) out as plain
|
|
9
|
+
* data. Pure parsing — pass it the already-parsed JSON object (load it with
|
|
10
|
+
* AssetManager.json or fetch).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const map = TiledMap.toTilemap(mapJson, "tiles.png");
|
|
14
|
+
* scene.add(map.gameObject);
|
|
15
|
+
* map.buildColliders(physics);
|
|
16
|
+
* const spawns = TiledMap.objects(mapJson, { layer: "spawns", flipY: true });
|
|
17
|
+
*/
|
|
18
|
+
declare class TiledMap {
|
|
19
|
+
/**
|
|
20
|
+
* @method tilesetFor
|
|
21
|
+
* @description Finds the tileset a (masked) global id belongs to.
|
|
22
|
+
* @param {Object} map - Parsed Tiled map JSON
|
|
23
|
+
* @param {number} gid - Masked global tile id (flip flags removed)
|
|
24
|
+
* @returns {Object|null}
|
|
25
|
+
*/
|
|
26
|
+
static tilesetFor(map: any, gid: number): any | null;
|
|
27
|
+
/** @private */
|
|
28
|
+
private static _tileLayer;
|
|
29
|
+
/**
|
|
30
|
+
* @method toFrameGrid
|
|
31
|
+
* @description Converts a tile layer into a 2D array of local frame indices
|
|
32
|
+
* (-1 for empty), ready for Tilemap.setMap. Global ids are converted to
|
|
33
|
+
* tileset-local indices and flip flags are stripped.
|
|
34
|
+
* @param {Object} map - Parsed Tiled map JSON
|
|
35
|
+
* @param {Object} [options] - { layer } (name, index, or first tile layer)
|
|
36
|
+
* @returns {number[][]}
|
|
37
|
+
*/
|
|
38
|
+
static toFrameGrid(map: any, options?: any): number[][];
|
|
39
|
+
/**
|
|
40
|
+
* @method toTilemap
|
|
41
|
+
* @description Builds a ready-to-render Tilemap from a Tiled map. The tile
|
|
42
|
+
* sheet config (frame size, columns, count) is read from the map's first
|
|
43
|
+
* tileset; the render tile size comes from the map's tilewidth.
|
|
44
|
+
* @param {Object} map - Parsed Tiled map JSON
|
|
45
|
+
* @param {string} texturePath - Path to the tile sheet image
|
|
46
|
+
* @param {Object} [options] - { layer, pixelart = true, name, originX, originY }
|
|
47
|
+
* @returns {Tilemap}
|
|
48
|
+
*/
|
|
49
|
+
static toTilemap(map: any, texturePath: string, options?: any): Tilemap;
|
|
50
|
+
/**
|
|
51
|
+
* @method objects
|
|
52
|
+
* @description Extracts the objects from an object layer as plain data
|
|
53
|
+
* (spawn points, triggers, regions). Tiled `properties` arrays are flattened
|
|
54
|
+
* into a `props` object. With `flipY` set, y is converted from Tiled's
|
|
55
|
+
* top-left pixel origin to a y-up world using the map's pixel height.
|
|
56
|
+
* @param {Object} map - Parsed Tiled map JSON
|
|
57
|
+
* @param {Object} [options] - { layer, flipY = false, originX = 0, originY = 0 }
|
|
58
|
+
* @returns {Array<Object>}
|
|
59
|
+
*/
|
|
60
|
+
static objects(map: any, options?: any): Array<any>;
|
|
61
|
+
}
|
|
62
|
+
import Tilemap from "../Tilemap.js";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { Vector2 } from "../Physics";
|
|
1
|
+
export default DirectionalLight;
|
|
3
2
|
/**
|
|
4
3
|
* @class DirectionalLight
|
|
5
4
|
* @param {Vector2} position - The position of the light
|
|
@@ -9,12 +8,12 @@ import { Vector2 } from "../Physics";
|
|
|
9
8
|
* @param {number} width - The width of the light
|
|
10
9
|
*/
|
|
11
10
|
declare class DirectionalLight {
|
|
12
|
-
position:
|
|
11
|
+
constructor(position: any, direction: any, color: any, intensity: any, width: any);
|
|
12
|
+
position: any;
|
|
13
13
|
direction: Vector2;
|
|
14
|
-
color:
|
|
15
|
-
intensity:
|
|
16
|
-
width:
|
|
17
|
-
constructor(position: Vector2, direction: Vector2, color: Color, intensity: number, width: number);
|
|
14
|
+
color: any;
|
|
15
|
+
intensity: any;
|
|
16
|
+
width: any;
|
|
18
17
|
/**
|
|
19
18
|
* Calculate the light intensity at a given point
|
|
20
19
|
* @param {Vector2} point - The point to calculate intensity for
|
|
@@ -22,5 +21,4 @@ declare class DirectionalLight {
|
|
|
22
21
|
*/
|
|
23
22
|
getIntensityAtPoint(point: Vector2): number;
|
|
24
23
|
}
|
|
25
|
-
|
|
26
|
-
//# sourceMappingURL=DirectionalLight.d.ts.map
|
|
24
|
+
import { Vector2 } from "../Physics.js";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { Vector2 } from "../Physics";
|
|
1
|
+
export default PointLight;
|
|
3
2
|
/**
|
|
4
3
|
* @class PointLight
|
|
5
4
|
* @param {Vector2} position - The position of the light
|
|
@@ -8,11 +7,9 @@ import { Vector2 } from "../Physics";
|
|
|
8
7
|
* @param {number} radius - The radius of the light
|
|
9
8
|
*/
|
|
10
9
|
declare class PointLight {
|
|
11
|
-
position:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
constructor(position: any, color: any, intensity: any, radius: any);
|
|
11
|
+
position: any;
|
|
12
|
+
color: any;
|
|
13
|
+
intensity: any;
|
|
14
|
+
radius: any;
|
|
16
15
|
}
|
|
17
|
-
export default PointLight;
|
|
18
|
-
//# sourceMappingURL=PointLight.d.ts.map
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
export default AssetManager;
|
|
2
|
+
/**
|
|
3
|
+
* @class AssetManager
|
|
4
|
+
* @description A general async loader for everything a game needs at startup:
|
|
5
|
+
* images/textures, audio, JSON, text, and web fonts. It deduplicates by key,
|
|
6
|
+
* reports aggregate progress (so you can drive a loading bar), and stores the
|
|
7
|
+
* resolved assets for synchronous lookup afterwards via `get(key)`.
|
|
8
|
+
*
|
|
9
|
+
* Textures are routed through TextureManager so the GL upload cache is shared
|
|
10
|
+
* with the rest of the engine.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const assets = new AssetManager();
|
|
14
|
+
* assets.image("player", "player.png", { pixelart: true });
|
|
15
|
+
* assets.audio("jump", "jump.wav");
|
|
16
|
+
* assets.json("level1", "levels/1.json");
|
|
17
|
+
* assets.font("Press Start 2P", "fonts/press-start.woff2");
|
|
18
|
+
* assets.onProgress((loaded, total) => bar.set(loaded / total));
|
|
19
|
+
* await assets.load();
|
|
20
|
+
* const img = assets.get("player"); // HTMLImageElement
|
|
21
|
+
* const data = assets.get("level1"); // parsed JSON
|
|
22
|
+
*/
|
|
23
|
+
declare class AssetManager {
|
|
24
|
+
/** @private */
|
|
25
|
+
private static _loadAudio;
|
|
26
|
+
/** @private */
|
|
27
|
+
private static _loadFont;
|
|
28
|
+
/** @private */
|
|
29
|
+
private _queue;
|
|
30
|
+
assets: Map<any, any>;
|
|
31
|
+
/** @private */
|
|
32
|
+
private _paths;
|
|
33
|
+
/** @private */
|
|
34
|
+
private _progressHandlers;
|
|
35
|
+
/** @private */
|
|
36
|
+
private _loaded;
|
|
37
|
+
/** @private */
|
|
38
|
+
private _total;
|
|
39
|
+
/**
|
|
40
|
+
* @method image
|
|
41
|
+
* @description Queues an image/texture. The GL texture is created lazily by
|
|
42
|
+
* the renderer; `get(key)` returns the HTMLImageElement.
|
|
43
|
+
*/
|
|
44
|
+
image(key: any, path: any, options?: {}): this;
|
|
45
|
+
/**
|
|
46
|
+
* @method audio
|
|
47
|
+
* @description Queues an audio file (returns an HTMLAudioElement on get()).
|
|
48
|
+
*/
|
|
49
|
+
audio(key: any, path: any): this;
|
|
50
|
+
/**
|
|
51
|
+
* @method json
|
|
52
|
+
* @description Queues a JSON file (parsed on get()).
|
|
53
|
+
*/
|
|
54
|
+
json(key: any, path: any): this;
|
|
55
|
+
/**
|
|
56
|
+
* @method text
|
|
57
|
+
* @description Queues a plain-text file.
|
|
58
|
+
*/
|
|
59
|
+
text(key: any, path: any): this;
|
|
60
|
+
/**
|
|
61
|
+
* @method font
|
|
62
|
+
* @description Queues a web font. `key` is the font-family name you will use
|
|
63
|
+
* in CSS/canvas; `path` is the font file URL.
|
|
64
|
+
*/
|
|
65
|
+
font(key: any, path: any, descriptors?: {}): this;
|
|
66
|
+
/**
|
|
67
|
+
* @method onProgress
|
|
68
|
+
* @description Registers a callback invoked as (loaded, total) after each
|
|
69
|
+
* asset resolves.
|
|
70
|
+
*/
|
|
71
|
+
onProgress(handler: any): this;
|
|
72
|
+
/**
|
|
73
|
+
* @method progress
|
|
74
|
+
* @returns {number} - Fraction loaded in [0, 1] (1 when nothing is queued).
|
|
75
|
+
*/
|
|
76
|
+
progress(): number;
|
|
77
|
+
/**
|
|
78
|
+
* @method load
|
|
79
|
+
* @description Loads every queued asset, resolving when all are done. Failed
|
|
80
|
+
* assets reject the returned promise unless `continueOnError` is true, in
|
|
81
|
+
* which case they resolve to null and loading continues.
|
|
82
|
+
* @param {Object} [options] - { continueOnError = false }
|
|
83
|
+
* @returns {Promise<Map>} - The resolved assets map
|
|
84
|
+
*/
|
|
85
|
+
load(options?: any): Promise<Map<any, any>>;
|
|
86
|
+
/** @private */
|
|
87
|
+
private _loadOne;
|
|
88
|
+
/**
|
|
89
|
+
* @method get
|
|
90
|
+
* @description Returns a previously loaded asset by key.
|
|
91
|
+
*/
|
|
92
|
+
get(key: any): any;
|
|
93
|
+
/**
|
|
94
|
+
* @method has
|
|
95
|
+
* @returns {boolean} - Whether an asset has been loaded for the key.
|
|
96
|
+
*/
|
|
97
|
+
has(key: any): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* @method getTexture
|
|
100
|
+
* @description Convenience: returns the cached GL texture for an image asset
|
|
101
|
+
* that was queued with `image()`. Resolves once the upload completes.
|
|
102
|
+
* @param {string} key - The image asset key
|
|
103
|
+
* @returns {Promise<{texture: WebGLTexture, width: number, height: number}>}
|
|
104
|
+
*/
|
|
105
|
+
getTexture(key: string): Promise<{
|
|
106
|
+
texture: WebGLTexture;
|
|
107
|
+
width: number;
|
|
108
|
+
height: number;
|
|
109
|
+
}>;
|
|
110
|
+
/**
|
|
111
|
+
* @method clear
|
|
112
|
+
* @description Forgets all loaded assets (does not free GL textures; use
|
|
113
|
+
* TextureManager.clear for that).
|
|
114
|
+
*/
|
|
115
|
+
clear(): void;
|
|
116
|
+
}
|