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.
Files changed (162) hide show
  1. package/README.md +2359 -968
  2. package/dist/types/index.d.ts +72 -32
  3. package/dist/types/src/Animator.d.ts +50 -0
  4. package/dist/types/{BitmapText.d.ts → src/BitmapText.d.ts} +19 -21
  5. package/dist/types/src/Camera.d.ts +122 -0
  6. package/dist/types/src/CameraController.d.ts +107 -0
  7. package/dist/types/src/CanvasText.d.ts +91 -0
  8. package/dist/types/src/CollisionLayers.d.ts +58 -0
  9. package/dist/types/{Color.d.ts → src/Color.d.ts} +5 -6
  10. package/dist/types/src/Coroutine.d.ts +111 -0
  11. package/dist/types/src/DebugOverlay.d.ts +86 -0
  12. package/dist/types/src/Drawable.d.ts +271 -0
  13. package/dist/types/src/Easing.d.ts +22 -0
  14. package/dist/types/src/Emerald.d.ts +420 -0
  15. package/dist/types/src/EmeraldDB.d.ts +159 -0
  16. package/dist/types/{FPSCounter.d.ts → src/FPSCounter.d.ts} +1 -3
  17. package/dist/types/src/GLUtils.d.ts +4 -0
  18. package/dist/types/{Instance.d.ts → src/Instance.d.ts} +37 -15
  19. package/dist/types/{InstancedTexture.d.ts → src/InstancedTexture.d.ts} +60 -23
  20. package/dist/types/src/Interpolator.d.ts +66 -0
  21. package/dist/types/src/Material.d.ts +87 -0
  22. package/dist/types/src/MathUtils.d.ts +80 -0
  23. package/dist/types/src/ParticleEmitter.d.ts +131 -0
  24. package/dist/types/{Physics.d.ts → src/Physics.d.ts} +88 -20
  25. package/dist/types/src/Pool.d.ts +53 -0
  26. package/dist/types/src/PostEffects.d.ts +68 -0
  27. package/dist/types/src/PostProcessor.d.ts +124 -0
  28. package/dist/types/src/RenderTarget.d.ts +56 -0
  29. package/dist/types/src/Scene.d.ts +62 -0
  30. package/dist/types/src/ScreenEffects.d.ts +111 -0
  31. package/dist/types/src/Serializer.d.ts +86 -0
  32. package/dist/types/src/Shaders.d.ts +2 -0
  33. package/dist/types/{Shapes.d.ts → src/Shapes.d.ts} +4 -6
  34. package/dist/types/src/SpatialGrid.d.ts +50 -0
  35. package/dist/types/src/SpriteBatch.d.ts +89 -0
  36. package/dist/types/src/StateMachine.d.ts +59 -0
  37. package/dist/types/src/Storage.d.ts +89 -0
  38. package/dist/types/{Texture.d.ts → src/Texture.d.ts} +3 -4
  39. package/dist/types/src/TextureAtlas.d.ts +55 -0
  40. package/dist/types/src/Tilemap.d.ts +91 -0
  41. package/dist/types/src/Time.d.ts +53 -0
  42. package/dist/types/src/Timer.d.ts +54 -0
  43. package/dist/types/src/Transform.d.ts +94 -0
  44. package/dist/types/src/Tween.d.ts +81 -0
  45. package/dist/types/src/UI.d.ts +121 -0
  46. package/dist/types/src/components/Behaviour.d.ts +71 -0
  47. package/dist/types/{components → src/components}/BoxCollider.d.ts +14 -14
  48. package/dist/types/src/components/BoxColliderDebug.d.ts +15 -0
  49. package/dist/types/{components → src/components}/CircleCollider.d.ts +14 -12
  50. package/dist/types/src/components/CircleColliderDebug.d.ts +15 -0
  51. package/dist/types/src/components/Collider.d.ts +96 -0
  52. package/dist/types/src/components/GameObject.d.ts +135 -0
  53. package/dist/types/src/components/RigidBody.d.ts +183 -0
  54. package/dist/types/src/importers/Aseprite.d.ts +79 -0
  55. package/dist/types/src/importers/TiledMap.d.ts +62 -0
  56. package/dist/types/{lights → src/lights}/DirectionalLight.d.ts +7 -9
  57. package/dist/types/{lights → src/lights}/PointLight.d.ts +6 -9
  58. package/dist/types/src/managers/AssetManager.d.ts +116 -0
  59. package/dist/types/src/managers/AudioManager.d.ts +259 -0
  60. package/dist/types/{managers → src/managers}/CameraManager.d.ts +8 -8
  61. package/dist/types/{managers → src/managers}/EventManager.d.ts +46 -32
  62. package/dist/types/src/managers/GLManager.d.ts +84 -0
  63. package/dist/types/src/managers/GLState.d.ts +37 -0
  64. package/dist/types/src/managers/IDManager.d.ts +31 -0
  65. package/dist/types/src/managers/InputManager.d.ts +290 -0
  66. package/dist/types/src/managers/NetworkManager.d.ts +93 -0
  67. package/dist/types/src/managers/RenderStats.d.ts +34 -0
  68. package/dist/types/src/managers/SceneManager.d.ts +44 -0
  69. package/dist/types/src/managers/ShaderManager.d.ts +55 -0
  70. package/dist/types/src/managers/TextureManager.d.ts +102 -0
  71. package/dist/types/src/particlesystem/Particle.d.ts +64 -0
  72. package/dist/types/{particlesystem → src/particlesystem}/ParticleSettings.d.ts +32 -24
  73. package/dist/types/{particlesystem → src/particlesystem}/Particles.d.ts +20 -12
  74. package/index.js +72 -0
  75. package/package.json +74 -60
  76. package/src/Animator.js +95 -0
  77. package/src/BitmapText.js +6 -5
  78. package/src/Camera.js +183 -0
  79. package/src/CameraController.js +192 -0
  80. package/src/CanvasText.js +281 -0
  81. package/src/CollisionLayers.js +86 -0
  82. package/src/Color.js +18 -18
  83. package/src/Coroutine.js +259 -0
  84. package/src/DebugOverlay.js +246 -0
  85. package/src/Drawable.js +842 -582
  86. package/src/Easing.js +57 -0
  87. package/src/Emerald.js +1150 -459
  88. package/src/EmeraldDB.js +328 -0
  89. package/src/FPSCounter.js +43 -43
  90. package/src/GLUtils.js +60 -67
  91. package/src/Instance.js +41 -5
  92. package/src/InstancedTexture.js +251 -118
  93. package/src/Interpolator.js +124 -0
  94. package/src/Material.js +202 -0
  95. package/src/MathUtils.js +133 -0
  96. package/src/ParticleEmitter.js +284 -0
  97. package/src/Physics.js +186 -5
  98. package/src/Pool.js +85 -0
  99. package/src/PostEffects.js +296 -0
  100. package/src/PostProcessor.js +304 -0
  101. package/src/RenderTarget.js +134 -0
  102. package/src/Scene.js +115 -83
  103. package/src/ScreenEffects.js +266 -0
  104. package/src/Serializer.js +131 -0
  105. package/src/Shaders.js +150 -165
  106. package/src/Shapes.js +118 -129
  107. package/src/SpatialGrid.js +111 -0
  108. package/src/SpriteBatch.js +299 -0
  109. package/src/StateMachine.js +82 -0
  110. package/src/Storage.js +175 -47
  111. package/src/Texture.js +58 -67
  112. package/src/TextureAtlas.js +96 -0
  113. package/src/Tilemap.js +274 -0
  114. package/src/Time.js +51 -6
  115. package/src/Timer.js +99 -0
  116. package/src/Transform.js +100 -7
  117. package/src/Tween.js +160 -0
  118. package/src/UI.js +394 -0
  119. package/src/components/Behaviour.js +90 -0
  120. package/src/components/BoxCollider.js +22 -3
  121. package/src/components/CircleCollider.js +19 -3
  122. package/src/components/CircleColliderDebug.js +24 -24
  123. package/src/components/Collider.js +140 -34
  124. package/src/components/GameObject.js +130 -21
  125. package/src/components/RigidBody.js +123 -2
  126. package/src/importers/Aseprite.js +142 -0
  127. package/src/importers/TiledMap.js +158 -0
  128. package/src/lights/DirectionalLight.js +6 -15
  129. package/src/lights/PointLight.js +4 -4
  130. package/src/managers/AssetManager.js +239 -0
  131. package/src/managers/AudioManager.js +565 -146
  132. package/src/managers/EventManager.js +488 -477
  133. package/src/managers/GLManager.js +57 -0
  134. package/src/managers/GLState.js +70 -0
  135. package/src/managers/IDManager.js +24 -2
  136. package/src/managers/InputManager.js +779 -0
  137. package/src/managers/NetworkManager.js +178 -0
  138. package/src/managers/RenderStats.js +34 -0
  139. package/src/managers/SceneManager.js +30 -0
  140. package/src/managers/ShaderManager.js +0 -2
  141. package/src/managers/TextureManager.js +218 -0
  142. package/src/particlesystem/Particle.js +82 -7
  143. package/src/particlesystem/ParticleSettings.js +21 -3
  144. package/src/particlesystem/Particles.js +80 -31
  145. package/dist/types/Drawable.d.ts +0 -157
  146. package/dist/types/Emerald.d.ts +0 -73
  147. package/dist/types/GLUtils.d.ts +0 -6
  148. package/dist/types/Scene.d.ts +0 -39
  149. package/dist/types/Shaders.d.ts +0 -4
  150. package/dist/types/Storage.d.ts +0 -46
  151. package/dist/types/Time.d.ts +0 -22
  152. package/dist/types/Transform.d.ts +0 -41
  153. package/dist/types/components/BoxColliderDebug.d.ts +0 -19
  154. package/dist/types/components/CircleColliderDebug.d.ts +0 -19
  155. package/dist/types/components/Collider.d.ts +0 -53
  156. package/dist/types/components/GameObject.d.ts +0 -72
  157. package/dist/types/components/RigidBody.d.ts +0 -104
  158. package/dist/types/managers/AudioManager.d.ts +0 -60
  159. package/dist/types/managers/GLManager.d.ts +0 -47
  160. package/dist/types/managers/IDManager.d.ts +0 -21
  161. package/dist/types/managers/SceneManager.d.ts +0 -22
  162. package/dist/types/particlesystem/Particle.d.ts +0 -42
@@ -0,0 +1,86 @@
1
+ export default Serializer;
2
+ /**
3
+ * @class Serializer
4
+ * @description Saves/loads a scene to/from plain JSON. Because components hold
5
+ * live GL/physics handles that can't be serialized generically, reconstruction
6
+ * goes through registered factories keyed by a `prefabType`. Each object's
7
+ * transform, layer, opacity and an optional `serialize()` payload are captured.
8
+ *
9
+ * @example
10
+ * Serializer.register("coin", (data) => makeCoin(data.value));
11
+ * coin.prefabType = "coin";
12
+ * coin.serialize = () => ({ value: 5 });
13
+ *
14
+ * const json = Serializer.toJSON(scene); // save
15
+ * Serializer.fromJSON(json, new Scene()); // load
16
+ */
17
+ declare class Serializer {
18
+ /**
19
+ * @method register
20
+ * @description Registers a factory that rebuilds an object from its data.
21
+ * @param {string} type - The prefabType
22
+ * @param {(data:any, entry:any) => Object} factory - Returns a GameObject
23
+ */
24
+ static register(type: string, factory: (data: any, entry: any) => any): void;
25
+ /**
26
+ * @method serializeObject
27
+ * @description Captures a single object's serializable state.
28
+ */
29
+ static serializeObject(obj: any): {
30
+ type: any;
31
+ name: any;
32
+ layer: any;
33
+ opacity: any;
34
+ screenSpace: boolean;
35
+ transform: {
36
+ position: {
37
+ x: any;
38
+ y: any;
39
+ z: any;
40
+ };
41
+ rotation: any;
42
+ scale: {
43
+ x: any;
44
+ y: any;
45
+ };
46
+ };
47
+ data: any;
48
+ };
49
+ /**
50
+ * @method serializeScene
51
+ * @description Returns a plain object describing the scene.
52
+ */
53
+ static serializeScene(scene: any): {
54
+ objects: any;
55
+ };
56
+ /**
57
+ * @method applyState
58
+ * @description Applies a serialized entry's transform/layer/opacity to an object.
59
+ */
60
+ static applyState(obj: any, entry: any): void;
61
+ /**
62
+ * @method deserializeObject
63
+ * @description Rebuilds an object from an entry via its registered factory.
64
+ * @returns {Object|null}
65
+ */
66
+ static deserializeObject(entry: any): any | null;
67
+ /**
68
+ * @method deserializeScene
69
+ * @description Rebuilds objects into the given scene.
70
+ * @returns {Scene} - The populated scene
71
+ */
72
+ static deserializeScene(json: any, scene: any): Scene;
73
+ /**
74
+ * @method toJSON
75
+ * @description Serializes a scene to a JSON string.
76
+ */
77
+ static toJSON(scene: any): string;
78
+ /**
79
+ * @method fromJSON
80
+ * @description Loads a scene from a JSON string into the given scene.
81
+ */
82
+ static fromJSON(str: any, scene: any): Scene;
83
+ }
84
+ declare namespace Serializer {
85
+ let factories: Map<any, any>;
86
+ }
@@ -0,0 +1,2 @@
1
+ export const STANDARD_VERTEX_SHADER: "\n attribute vec4 aVertexPosition;\n attribute vec2 aTextureCoord;\n \n attribute vec4 aInstanceMatrix0;\n attribute vec4 aInstanceMatrix1;\n attribute vec4 aInstanceMatrix2;\n attribute vec4 aInstanceMatrix3;\n \n attribute vec2 aInstanceTexCoord0;\n attribute vec2 aInstanceTexCoord1;\n attribute vec2 aInstanceTexCoord2;\n attribute vec2 aInstanceTexCoord3;\n\n attribute vec4 aInstanceColor;\n\n uniform mat4 uModelViewMatrix;\n uniform mat4 uInstancedModelViewMatrix;\n uniform mat4 uProjectionMatrix;\n uniform bool useInstances;\n\n varying highp vec2 vTexCoord;\n varying vec2 vFragPos;\n varying vec4 vInstanceColor;\n\n void main() {\n mat4 instanceMatrix = mat4(\n aInstanceMatrix0,\n aInstanceMatrix1,\n aInstanceMatrix2,\n aInstanceMatrix3\n );\n \n if(useInstances) {\n gl_Position = uProjectionMatrix * uInstancedModelViewMatrix * instanceMatrix * aVertexPosition;\n vFragPos = (uInstancedModelViewMatrix * instanceMatrix * aVertexPosition).xy;\n vInstanceColor = aInstanceColor;\n\n int vertexIndex = int(aVertexPosition.x > 0.0 ? (aVertexPosition.y > 0.0 ? 0 : 2) : (aVertexPosition.y > 0.0 ? 1 : 3));\n \n if(vertexIndex == 0) {\n vTexCoord = aInstanceTexCoord0;\n } else if(vertexIndex == 1) {\n vTexCoord = aInstanceTexCoord1;\n } else if(vertexIndex == 2) {\n vTexCoord = aInstanceTexCoord2;\n } else {\n vTexCoord = aInstanceTexCoord3;\n }\n } else {\n gl_Position = uProjectionMatrix * uModelViewMatrix * aVertexPosition;\n vFragPos = (uModelViewMatrix * aVertexPosition).xy;\n vTexCoord = aTextureCoord;\n vInstanceColor = vec4(1.0);\n }\n }\n";
2
+ export const STANDARD_FRAGMENT_SHADER: "\n #ifdef GL_ES\n precision highp float;\n #endif\n uniform bool useTexture;\n uniform vec4 uColor;\n uniform sampler2D uSampler;\n uniform float uOpacity;\n\n uniform vec2 uLightPosition[4];\n uniform vec3 uLightColor[4];\n uniform float uLightIntensity[4];\n uniform float uLightRadius[4];\n uniform int uActiveLights;\n \n uniform vec2 uDirLightPosition[4];\n uniform vec2 uDirLightDirection[4];\n uniform vec3 uDirLightColor[4];\n uniform float uDirLightIntensity[4];\n uniform float uDirLightWidth[4];\n uniform int uActiveDirLights;\n \n uniform vec3 uAmbientLightValues;\n uniform bool uUseLighting;\n\n varying vec2 vTexCoord;\n varying vec2 vFragPos;\n varying vec4 vInstanceColor;\n\n void main() {\n vec4 ambientLight = vec4(uAmbientLightValues.xyz, 1.0);\n\n vec4 texColor;\n if (useTexture) {\n texColor = texture2D(uSampler, vTexCoord);\n if (texColor.a < 0.01) discard;\n texColor *= uColor;\n } else {\n texColor = uColor;\n }\n\n texColor *= vInstanceColor;\n \n vec3 lighting = ambientLight.rgb;\n \n for(int i = 0; i < 4; i++) {\n if(i >= uActiveLights) break;\n \n float distance = length(uLightPosition[i] - vFragPos);\n \n if(distance < uLightRadius[i]) {\n float attenuation = 1.0 - distance / uLightRadius[i];\n \n lighting += uLightColor[i] * attenuation * uLightIntensity[i];\n }\n }\n \n for(int i = 0; i < 4; i++) {\n if(i >= uActiveDirLights) break;\n \n vec2 lightPos = uDirLightPosition[i];\n vec2 lightDir = normalize(uDirLightDirection[i]);\n vec2 toFrag = vFragPos - lightPos;\n \n float projection = dot(toFrag, lightDir);\n if(projection < 0.0) continue;\n \n float perpDistance = abs(dot(toFrag, vec2(-lightDir.y, lightDir.x)));\n \n if(perpDistance > uDirLightWidth[i] * 0.5) continue;\n \n float widthFactor = 1.0 - (perpDistance / (uDirLightWidth[i] * 0.5));\n \n float distance = length(toFrag);\n float maxDistance = 1000.0;\n float distanceFactor = max(0.0, 1.0 - (distance / maxDistance));\n \n lighting += uDirLightColor[i] * uDirLightIntensity[i] * widthFactor * distanceFactor;\n }\n \n vec4 outColor;\n if (uUseLighting) {\n outColor = vec4(texColor.rgb * lighting, texColor.a);\n } else {\n outColor = texColor;\n }\n outColor.a *= clamp(uOpacity, 0.0, 1.0);\n gl_FragColor = outColor;\n }\n";
@@ -1,16 +1,15 @@
1
- import Drawable from "./Drawable";
2
1
  /**
3
2
  * @class Square2D
4
3
  * @description Represents a square 2D shape
5
4
  */
6
- declare class Square2D extends Drawable {
5
+ export class Square2D extends Drawable {
7
6
  constructor();
8
7
  }
9
8
  /**
10
9
  * @class Triangle2D
11
10
  * @description Represents a triangle 2D shape
12
11
  */
13
- declare class Triangle2D extends Drawable {
12
+ export class Triangle2D extends Drawable {
14
13
  constructor();
15
14
  }
16
15
  /**
@@ -18,8 +17,7 @@ declare class Triangle2D extends Drawable {
18
17
  * @description Represents a circle 2D shape
19
18
  * @param {number} segments - The number of segments to use to draw the circle
20
19
  */
21
- declare class Circle2D extends Drawable {
20
+ export class Circle2D extends Drawable {
22
21
  constructor(segments?: number);
23
22
  }
24
- export { Square2D, Triangle2D, Circle2D };
25
- //# sourceMappingURL=Shapes.d.ts.map
23
+ import Drawable from "./Drawable.js";
@@ -0,0 +1,50 @@
1
+ export default SpatialGrid;
2
+ /**
3
+ * @class SpatialGrid
4
+ * @description A uniform spatial hash grid for fast 2D neighbor queries (picking,
5
+ * proximity, broadphase). Rebuild it each frame (or as objects move) with
6
+ * clear()/insert(), then query by radius or rectangle.
7
+ *
8
+ * @example
9
+ * const grid = new SpatialGrid(64);
10
+ * grid.clear();
11
+ * for (const e of enemies) grid.insert(e, e.transform.position.x, e.transform.position.y);
12
+ * const near = grid.queryRadius(player.x, player.y, 100);
13
+ */
14
+ declare class SpatialGrid {
15
+ /**
16
+ * @param {number} cellSize - World units per cell
17
+ */
18
+ constructor(cellSize?: number);
19
+ cellSize: number;
20
+ cells: Map<any, any>;
21
+ /** @private */
22
+ private _key;
23
+ /** @private */
24
+ private _cell;
25
+ /**
26
+ * @method clear
27
+ * @description Empties the grid.
28
+ */
29
+ clear(): void;
30
+ /**
31
+ * @method insert
32
+ * @description Inserts an item at a world position.
33
+ * @param {*} item - The item to store
34
+ * @param {number} x - World x
35
+ * @param {number} y - World y
36
+ */
37
+ insert(item: any, x: number, y: number): void;
38
+ /**
39
+ * @method queryRect
40
+ * @description Returns items whose stored position lies within a rectangle.
41
+ * @returns {Array} - Matching items
42
+ */
43
+ queryRect(minX: any, minY: any, maxX: any, maxY: any): any[];
44
+ /**
45
+ * @method queryRadius
46
+ * @description Returns items within a radius of a point.
47
+ * @returns {Array} - Matching items
48
+ */
49
+ queryRadius(x: any, y: any, radius: any): any[];
50
+ }
@@ -0,0 +1,89 @@
1
+ export default SpriteBatch;
2
+ /**
3
+ * @class SpriteBatch
4
+ * @description A dynamic batched sprite renderer. Instead of one draw call per
5
+ * sprite (as ordinary Drawables incur), it accumulates many sprites that share a
6
+ * texture into a single interleaved buffer and submits them in one
7
+ * `drawElements` call. Batches are flushed automatically when the texture
8
+ * changes or the buffer fills, so for content that shares a texture/atlas this
9
+ * collapses hundreds of draw calls into a handful.
10
+ *
11
+ * It uses its own minimal shader program (position + uv + per-vertex color), so
12
+ * it is independent of the main render pipeline.
13
+ *
14
+ * @example
15
+ * const batch = new SpriteBatch();
16
+ * batch.begin(projectionMatrix, viewMatrix); // gl-matrix mat4s
17
+ * for (const e of entities) {
18
+ * batch.draw({ texture: atlasTex, x: e.x, y: e.y, w: 32, h: 32,
19
+ * u0: e.u0, v0: e.v0, u1: e.u1, v1: e.v1 });
20
+ * }
21
+ * batch.end();
22
+ */
23
+ declare class SpriteBatch {
24
+ /**
25
+ * @method _writeQuad
26
+ * @description Pure helper that writes one quad's 4 interleaved vertices
27
+ * (position, uv, color) into `out` at `offset`. Positions are rotated around
28
+ * the quad center (cx, cy). Exposed (and side-effect free) for testing.
29
+ * @private
30
+ */
31
+ private static _writeQuad;
32
+ /**
33
+ * @param {Object} [options] - { maxQuads = 2000 }
34
+ */
35
+ constructor(options?: any);
36
+ gl: WebGLRenderingContext;
37
+ maxQuads: any;
38
+ program: any;
39
+ attribs: {
40
+ pos: number;
41
+ uv: number;
42
+ color: number;
43
+ };
44
+ uniforms: {
45
+ projection: WebGLUniformLocation;
46
+ view: WebGLUniformLocation;
47
+ sampler: WebGLUniformLocation;
48
+ };
49
+ vertexData: Float32Array<ArrayBuffer>;
50
+ vertexBuffer: WebGLBuffer;
51
+ indexBuffer: WebGLBuffer;
52
+ /** @private */
53
+ private _quadCount;
54
+ /** @private */
55
+ private _currentTexture;
56
+ /** @private */
57
+ private _projection;
58
+ /** @private */
59
+ private _view;
60
+ drawCalls: number;
61
+ /**
62
+ * @method begin
63
+ * @description Starts a batch with the given projection and view matrices
64
+ * (gl-matrix mat4 / Float32Array(16)).
65
+ */
66
+ begin(projectionMatrix: any, viewMatrix: any): void;
67
+ /**
68
+ * @method draw
69
+ * @description Queues one sprite. Flushes first if the texture changed or the
70
+ * batch is full.
71
+ * @param {Object} sprite - {
72
+ * texture, x, y, w, h,
73
+ * rotation = 0, originX = 0.5, originY = 0.5,
74
+ * u0 = 0, v0 = 0, u1 = 1, v1 = 1,
75
+ * r = 1, g = 1, b = 1, a = 1
76
+ * }
77
+ */
78
+ draw(sprite: any): void;
79
+ /**
80
+ * @method end
81
+ * @description Flushes any remaining sprites.
82
+ */
83
+ end(): void;
84
+ /**
85
+ * @method flush
86
+ * @description Uploads and draws the currently staged quads.
87
+ */
88
+ flush(): void;
89
+ }
@@ -0,0 +1,59 @@
1
+ export default StateMachine;
2
+ /**
3
+ * @class StateMachine
4
+ * @description A lightweight finite state machine for entity AI, animation
5
+ * states, game flow, etc. Each state can define `enter`, `update(dt)`, and
6
+ * `exit` handlers. Drive it from a Behaviour's update().
7
+ *
8
+ * @example
9
+ * const fsm = new StateMachine();
10
+ * fsm.add("idle", {
11
+ * update: (dt, sm) => { if (seesPlayer) sm.set("chase"); },
12
+ * });
13
+ * fsm.add("chase", {
14
+ * enter: () => playRoarSound(),
15
+ * update: (dt, sm) => moveTowardPlayer(dt),
16
+ * });
17
+ * fsm.set("idle");
18
+ * // in update(dt): fsm.update(dt);
19
+ */
20
+ declare class StateMachine {
21
+ states: Map<any, any>;
22
+ current: any;
23
+ currentName: any;
24
+ previousName: any;
25
+ /**
26
+ * @method add
27
+ * @description Registers a state.
28
+ * @param {string} name - State name
29
+ * @param {{enter?:Function, update?:Function, exit?:Function}} handlers
30
+ * @returns {StateMachine} - this
31
+ */
32
+ add(name: string, handlers: {
33
+ enter?: Function;
34
+ update?: Function;
35
+ exit?: Function;
36
+ }): StateMachine;
37
+ /**
38
+ * @method set
39
+ * @description Transitions to a state, running exit/enter handlers. Re-entering
40
+ * the same state is a no-op unless `force` is true.
41
+ * @param {string} name - Target state name
42
+ * @param {boolean} [force] - Allow re-entering the current state
43
+ * @returns {StateMachine} - this
44
+ */
45
+ set(name: string, force?: boolean): StateMachine;
46
+ /**
47
+ * @method update
48
+ * @description Runs the current state's update handler.
49
+ * @param {number} dt - Seconds since the last frame
50
+ */
51
+ update(dt: number): void;
52
+ /**
53
+ * @method is
54
+ * @description Whether the given state is current.
55
+ * @param {string} name
56
+ * @returns {boolean}
57
+ */
58
+ is(name: string): boolean;
59
+ }
@@ -0,0 +1,89 @@
1
+ export default Storage;
2
+ /**
3
+ * @class Storage
4
+ * @description Manages the storage of the game
5
+ */
6
+ declare class Storage {
7
+ /**
8
+ * @method writeToLocalStorage
9
+ * @description Writes to local storage
10
+ * @param {string} key - The key to write to
11
+ * @param {any} value - The value to write to
12
+ */
13
+ static writeToLocalStorage(key: string, value: any): void;
14
+ /**
15
+ * @method readFromLocalStorage
16
+ * @description Reads from local storage
17
+ * @param {string} key - The key to read from
18
+ * @returns {any} - The value read from local storage
19
+ */
20
+ static readFromLocalStorage(key: string): any;
21
+ /**
22
+ * @method clearLocalStorage
23
+ * @description Clears local storage
24
+ */
25
+ static clearLocalStorage(): void;
26
+ /**
27
+ * @method writeToSessionStorage
28
+ * @description Writes to session storage
29
+ * @param {string} key - The key to write to
30
+ * @param {any} value - The value to write to
31
+ */
32
+ static writeToSessionStorage(key: string, value: any): void;
33
+ /**
34
+ * @method readFromSessionStorage
35
+ * @description Reads from session storage
36
+ * @param {string} key - The key to read from
37
+ * @returns {any} - The value read from session storage
38
+ */
39
+ static readFromSessionStorage(key: string): any;
40
+ /**
41
+ * @method clearSessionStorage
42
+ * @description Clears session storage
43
+ */
44
+ static clearSessionStorage(): void;
45
+ /**
46
+ * @method save
47
+ * @description Writes a versioned save under `key`. The payload is wrapped in
48
+ * an envelope `{ v, t, data }` so it can be migrated later, and the previous
49
+ * value is mirrored to `key + ".bak"` for corruption recovery. Quota and
50
+ * serialization errors are caught and reported rather than thrown.
51
+ * @param {string} key - The storage key
52
+ * @param {any} data - The data to persist (must be JSON-serializable)
53
+ * @param {Object} [options] - { version = 1, backup = true }
54
+ * @returns {boolean} - Whether the write succeeded
55
+ */
56
+ static save(key: string, data: any, options?: any): boolean;
57
+ /**
58
+ * @method _unwrap
59
+ * @description Parses a stored string into a `{ v, data }` envelope, treating
60
+ * a plain (pre-versioning) value as version 0. Returns undefined for missing
61
+ * data and throws for malformed JSON.
62
+ * @private
63
+ */
64
+ private static _unwrap;
65
+ /**
66
+ * @method load
67
+ * @description Reads a versioned save written by `save`. If the primary value
68
+ * is corrupt it falls back to the `.bak` copy; if that fails too it returns
69
+ * `fallback`. When the stored version differs from `version` and a `migrate`
70
+ * function is given, the data is upgraded (and rewritten unless disabled).
71
+ * @param {string} key - The storage key
72
+ * @param {Object} [options] - { version = 1, fallback = null, migrate, rewrite = true }
73
+ * @returns {any} - The (possibly migrated) saved data, or `fallback`
74
+ */
75
+ static load(key: string, options?: any): any;
76
+ /**
77
+ * @method hasSave
78
+ * @description Returns whether a save (or its backup) exists for `key`.
79
+ * @param {string} key - The storage key
80
+ * @returns {boolean}
81
+ */
82
+ static hasSave(key: string): boolean;
83
+ /**
84
+ * @method removeSave
85
+ * @description Deletes a save and its backup.
86
+ * @param {string} key - The storage key
87
+ */
88
+ static removeSave(key: string): void;
89
+ }
@@ -1,4 +1,4 @@
1
- import Drawable from "./Drawable";
1
+ export default Texture;
2
2
  /**
3
3
  * @class Texture
4
4
  * @description Represents a texture component
@@ -13,7 +13,6 @@ import Drawable from "./Drawable";
13
13
  * @param {boolean} useLighting - Whether the texture should react to lighting
14
14
  */
15
15
  declare class Texture extends Drawable {
16
- constructor(texturePath?: string, frameWidth?: number, frameHeight?: number, framesPerRow?: number, totalFrames?: number, animationSpeed?: number, autoPlay?: boolean, pixelart?: boolean, useLighting?: boolean);
16
+ constructor(texturePath?: {}, frameWidth?: number, frameHeight?: number, framesPerRow?: number, totalFrames?: number, animationSpeed?: number, autoPlay?: boolean, pixelart?: boolean, useLighting?: boolean);
17
17
  }
18
- export default Texture;
19
- //# sourceMappingURL=Texture.d.ts.map
18
+ import Drawable from "./Drawable.js";
@@ -0,0 +1,55 @@
1
+ export default TextureAtlas;
2
+ /**
3
+ * @class TextureAtlas
4
+ * @description Loads a packed sprite atlas (image + frame rectangles) and applies
5
+ * named frames to Drawables as normalized UV regions. Accepts TexturePacker
6
+ * JSON (hash or array `frames`) or a plain `{ name: {x,y,w,h} }` map.
7
+ *
8
+ * @example
9
+ * const atlas = await TextureAtlas.load("sheet.png", sheetJson, true);
10
+ * const sprite = new Texture(atlas.texturePath, 0, 0, 1, 1, 0, false, true);
11
+ * obj.addComponent(sprite);
12
+ * atlas.applyTo(sprite, "player_idle_0");
13
+ */
14
+ declare class TextureAtlas {
15
+ /**
16
+ * @method load
17
+ * @description Loads the atlas image (caching its GL texture) and parses frames.
18
+ * @param {string} texturePath
19
+ * @param {Object} atlasJson - Atlas description
20
+ * @param {boolean} [pixelart] - Filter mode for the cached texture
21
+ * @returns {Promise<TextureAtlas>}
22
+ */
23
+ static load(texturePath: string, atlasJson: any, pixelart?: boolean): Promise<TextureAtlas>;
24
+ /** @private */
25
+ private static _parse;
26
+ constructor(texturePath: any, frames: any, width: any, height: any);
27
+ texturePath: any;
28
+ frames: any;
29
+ width: any;
30
+ height: any;
31
+ /**
32
+ * @method getFrame
33
+ * @description Returns the pixel rect { x, y, w, h } for a frame name.
34
+ */
35
+ getFrame(name: any): any;
36
+ /**
37
+ * @method getRegion
38
+ * @description Returns the normalized UV region for a frame name.
39
+ * @returns {{left,top,right,bottom}|null}
40
+ */
41
+ getRegion(name: any): {
42
+ left: any;
43
+ top: any;
44
+ right: any;
45
+ bottom: any;
46
+ } | null;
47
+ /**
48
+ * @method applyTo
49
+ * @description Applies a frame's UV region to a Drawable.
50
+ * @param {Drawable} drawable
51
+ * @param {string} name - Frame name
52
+ * @returns {TextureAtlas} - this
53
+ */
54
+ applyTo(drawable: Drawable, name: string): TextureAtlas;
55
+ }
@@ -0,0 +1,91 @@
1
+ export default Tilemap;
2
+ /**
3
+ * @class Tilemap
4
+ * @description Builds a grid of tiles from a 2D array of frame indices, rendered
5
+ * as a single instanced draw call. Use -1 (or null) for empty cells. The tiles
6
+ * live on `tilemap.gameObject`, which you add to the scene.
7
+ *
8
+ * @example
9
+ * const map = new Tilemap("level", "tiles.png", {
10
+ * tileSize: 32, frameWidth: 16, frameHeight: 16, framesPerRow: 4, totalFrames: 16,
11
+ * });
12
+ * map.setMap([
13
+ * [0, 0, 0, 0],
14
+ * [1, -1, -1, 1],
15
+ * [2, 2, 2, 2],
16
+ * ]);
17
+ * scene.add(map.gameObject);
18
+ */
19
+ declare class Tilemap {
20
+ /**
21
+ * @method computeAutoTile
22
+ * @description Pure helper that converts a 2D solidity grid into a 2D frame
23
+ * index grid using 4-bit edge bitmasking. For each solid cell the neighbor
24
+ * mask is built as up|right|down|left (bits 1,2,4,8); empty cells become -1.
25
+ * Provide `frames` (a length-16 lookup from mask -> frame index) to match your
26
+ * tilesheet layout; otherwise the mask itself is used as the frame index, and
27
+ * `base` is added to every solid frame.
28
+ *
29
+ * @param {Array<Array<boolean|number>>} grid - Truthy = solid
30
+ * @param {Object} [options] - { frames, base = 0, edgesSolid = true }
31
+ * @returns {number[][]} - Frame indices (-1 for empty)
32
+ */
33
+ static computeAutoTile(grid: Array<Array<boolean | number>>, options?: any): number[][];
34
+ /**
35
+ * @param {string} name - Name for the underlying GameObject
36
+ * @param {string} texturePath - Path to the tile sheet
37
+ * @param {Object} [options] - tileSize, frameWidth, frameHeight, framesPerRow, totalFrames, pixelart
38
+ */
39
+ constructor(name: string, texturePath: string, options?: any);
40
+ name: string;
41
+ tileSize: any;
42
+ /** @private */
43
+ private _config;
44
+ gameObject: GameObject;
45
+ texture: InstancedTexture;
46
+ /** @private */
47
+ private _map;
48
+ /** @private */
49
+ private _layout;
50
+ /** @private */
51
+ private _colliders;
52
+ /**
53
+ * @method setMap
54
+ * @description Builds (or rebuilds) the tile instances from a 2D array.
55
+ * @param {number[][]} map - Rows of frame indices (-1/null = empty)
56
+ * @param {Object} [options] - { originX = 0, originY = 0, flipY = true }
57
+ * @returns {Tilemap} - this
58
+ */
59
+ setMap(map: number[][], options?: any): Tilemap;
60
+ /**
61
+ * @method buildColliders
62
+ * @description Generates static physics colliders from the current map. Solid
63
+ * cells are merged greedily into horizontal runs, so a row of N tiles becomes
64
+ * one box collider instead of N — far fewer bodies for the physics engine.
65
+ * The bodies are tagged so collision callbacks resolve back to `ownerObject`
66
+ * (defaults to the tilemap's GameObject). Call again after setMap to rebuild.
67
+ *
68
+ * @param {Physics} physics - The physics engine
69
+ * @param {Object} [options] - { isSolid, friction = 0.2, restitution = 0,
70
+ * density = 0, ownerObject }
71
+ * @returns {Tilemap} - this
72
+ */
73
+ buildColliders(physics: Physics, options?: any): Tilemap;
74
+ /**
75
+ * @method clearColliders
76
+ * @description Destroys the physics bodies created by buildColliders.
77
+ * @returns {Tilemap} - this
78
+ */
79
+ clearColliders(): Tilemap;
80
+ /**
81
+ * @method setAutoTiledMap
82
+ * @description Convenience: computes frame indices from a solidity grid using
83
+ * bitmask auto-tiling, then builds the map. See Tilemap.computeAutoTile.
84
+ * @param {Array<Array<boolean|number>>} solidGrid - Truthy = solid cell
85
+ * @param {Object} [options] - Auto-tile options + setMap options
86
+ * @returns {Tilemap} - this
87
+ */
88
+ setAutoTiledMap(solidGrid: Array<Array<boolean | number>>, options?: any): Tilemap;
89
+ }
90
+ import GameObject from "./components/GameObject.js";
91
+ import InstancedTexture from "./InstancedTexture.js";
@@ -0,0 +1,53 @@
1
+ export default Time;
2
+ /**
3
+ * @class Time
4
+ * @description Global time state for the game. `deltaTime` is the (scaled)
5
+ * seconds since the last frame, `elapsedTime` accumulates total scaled time, and
6
+ * `timeScale` lets you slow down / speed up / pause the simulation.
7
+ */
8
+ declare class Time {
9
+ /**
10
+ * @method getDeltaTime
11
+ * @description Returns the (time-scaled) delta time in seconds
12
+ * @returns {number} - The delta time
13
+ */
14
+ static getDeltaTime(): number;
15
+ /**
16
+ * @method setDeltaTime
17
+ * @description Sets the delta time. The stored value is multiplied by
18
+ * `timeScale`, and `elapsedTime` is advanced by the scaled amount. Called by
19
+ * `Emerald.drawScene`, but can be called manually for custom loops.
20
+ * @param {number} deltaTime - The unscaled delta time in seconds
21
+ */
22
+ static setDeltaTime(deltaTime: number): void;
23
+ /**
24
+ * @method getUnscaledDeltaTime
25
+ * @description Returns the raw delta time, ignoring timeScale
26
+ * @returns {number} - The unscaled delta time
27
+ */
28
+ static getUnscaledDeltaTime(): number;
29
+ /**
30
+ * @method getElapsedTime
31
+ * @description Returns the total accumulated (scaled) time in seconds
32
+ * @returns {number} - The elapsed time
33
+ */
34
+ static getElapsedTime(): number;
35
+ /**
36
+ * @method setTimeScale
37
+ * @description Sets the time scale (1 = normal, 0 = paused, 2 = double speed)
38
+ * @param {number} scale - The time scale (clamped to >= 0)
39
+ */
40
+ static setTimeScale(scale: number): void;
41
+ /**
42
+ * @method getTimeScale
43
+ * @description Returns the current time scale
44
+ * @returns {number} - The time scale
45
+ */
46
+ static getTimeScale(): number;
47
+ }
48
+ declare namespace Time {
49
+ let deltaTime: number;
50
+ let unscaledDeltaTime: number;
51
+ let elapsedTime: number;
52
+ let timeScale: number;
53
+ }