emeraldengine 2.2.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 -555
  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
@@ -1,4 +1,3 @@
1
- import * as planck from "planck";
2
1
  /**
3
2
  * @class Physics
4
3
  * @description Represents the physics engine
@@ -6,11 +5,58 @@ import * as planck from "planck";
6
5
  * @param {number} scale - The scale of the physics engine
7
6
  * @param {number} velocityThreshold - The velocity threshold of the physics engine
8
7
  */
9
- declare class Physics {
8
+ export class Physics {
9
+ /**
10
+ * @method scheduleAction
11
+ * @description Schedules an action to be executed as soon as possible
12
+ * @param {Function} callback - The callback function to execute
13
+ */
14
+ static scheduleAction(callback: Function): void;
15
+ constructor(gravity: any, scale: any, velocityThreshold?: number);
10
16
  world: planck.World;
11
- gravity: number;
12
- scale: number;
13
- constructor(gravity: number, scale: number, velocityThreshold?: number);
17
+ gravity: any;
18
+ scale: any;
19
+ fixedTimeStep: number;
20
+ maxSubSteps: number;
21
+ /** @private */
22
+ private _accumulator;
23
+ /**
24
+ * @method _dispatchContacts
25
+ * @description Routes planck contacts to the owning objects so Behaviour
26
+ * components receive onCollisionEnter/onCollisionExit. Bodies created through
27
+ * RigidBody carry the owner via userData.
28
+ * @private
29
+ */
30
+ private _dispatchContacts;
31
+ /**
32
+ * @method raycast
33
+ * @description Casts a ray through the world and returns the closest hit.
34
+ * @param {Object} origin - World-space { x, y } start point
35
+ * @param {Object} direction - Ray direction { x, y } (need not be normalized)
36
+ * @param {number} maxDistance - Max ray length in world units
37
+ * @returns {{object, rigidBody, point, normal, fraction}|null}
38
+ */
39
+ raycast(origin: any, direction: any, maxDistance: number): {
40
+ object: any;
41
+ rigidBody: any;
42
+ point: any;
43
+ normal: any;
44
+ fraction: any;
45
+ } | null;
46
+ /**
47
+ * @method queryPoint
48
+ * @description Returns the objects whose colliders contain a world-space point.
49
+ * @param {Object} point - World-space { x, y }
50
+ * @returns {Array} - Owning objects at the point
51
+ */
52
+ queryPoint(point: any): any[];
53
+ /**
54
+ * @method setFixedTimeStep
55
+ * @description Sets the fixed physics step (seconds) and optional substep cap.
56
+ * @param {number} step - Fixed step in seconds (e.g. 1/60)
57
+ * @param {number} [maxSubSteps] - Max steps per process() call (spiral guard)
58
+ */
59
+ setFixedTimeStep(step: number, maxSubSteps?: number): void;
14
60
  /**
15
61
  * @method createBody
16
62
  * @description Creates a body in the physics engine
@@ -24,19 +70,19 @@ declare class Physics {
24
70
  * @param {number} restitution - The restitution of the fixture
25
71
  * @returns {Body} - The body
26
72
  */
27
- createBody(type: string, position?: Vector2, fixedRotation?: boolean, attachFixture?: boolean, fixtureSize?: Vector2, density?: number, friction?: number, restitution?: number): planck.Body;
73
+ createBody(type: string, position?: Vector2, fixedRotation?: boolean, attachFixture?: boolean, fixtureSize?: Vector2, density?: number, friction?: number, restitution?: number): Body;
28
74
  /**
29
75
  * @method onCollisionEnter
30
76
  * @description Handles the collision enter event
31
77
  * @param {Function} callback - The callback function to handle the collision enter event
32
78
  */
33
- onCollisionEnter(callback: (bodyA: planck.Body, bodyB: planck.Body, contact: planck.Contact) => void): void;
79
+ onCollisionEnter(callback: Function): void;
34
80
  /**
35
81
  * @method onCollisionExit
36
82
  * @description Handles the collision exit event
37
83
  * @param {Function} callback - The callback function to handle the collision exit event
38
84
  */
39
- onCollisionExit(callback: (bodyA: planck.Body, bodyB: planck.Body, contact: planck.Contact) => void): void;
85
+ onCollisionExit(callback: Function): void;
40
86
  /**
41
87
  * @method process
42
88
  * @description Processes the physics engine
@@ -60,12 +106,6 @@ declare class Physics {
60
106
  * @returns {number} - The scale of the physics engine
61
107
  */
62
108
  getScale(): number;
63
- /**
64
- * @method scheduleAction
65
- * @description Schedules an action to be executed as soon as possible
66
- * @param {Function} callback - The callback function to execute
67
- */
68
- static scheduleAction(callback: () => void): void;
69
109
  }
70
110
  /**
71
111
  * @class Vector2
@@ -73,10 +113,24 @@ declare class Physics {
73
113
  * @param {number} x - The x coordinate of the vector
74
114
  * @param {number} y - The y coordinate of the vector
75
115
  */
76
- declare class Vector2 {
116
+ export class Vector2 {
117
+ constructor(x?: number, y?: number);
77
118
  x: number;
78
119
  y: number;
79
- constructor(x: number, y: number);
120
+ /**
121
+ * @method set
122
+ * @description Sets the x and y coordinates in place
123
+ * @param {number} x - The x coordinate
124
+ * @param {number} y - The y coordinate
125
+ * @returns {Vector2} - This vector
126
+ */
127
+ set(x: number, y: number): Vector2;
128
+ /**
129
+ * @method clone
130
+ * @description Returns a copy of the vector
131
+ * @returns {Vector2} - The cloned vector
132
+ */
133
+ clone(): Vector2;
80
134
  /**
81
135
  * @method equals
82
136
  * @description Checks if the vector is equal to another vector
@@ -104,11 +158,26 @@ declare class Vector2 {
104
158
  * @param {number} y - The y coordinate of the vector
105
159
  * @param {number} z - The z coordinate of the vector
106
160
  */
107
- declare class Vector3 {
161
+ export class Vector3 {
162
+ constructor(x?: number, y?: number, z?: number);
108
163
  x: number;
109
164
  y: number;
110
165
  z: number;
111
- constructor(x: number, y: number, z: number);
166
+ /**
167
+ * @method set
168
+ * @description Sets the x, y and z coordinates in place
169
+ * @param {number} x - The x coordinate
170
+ * @param {number} y - The y coordinate
171
+ * @param {number} z - The z coordinate
172
+ * @returns {Vector3} - This vector
173
+ */
174
+ set(x: number, y: number, z: number): Vector3;
175
+ /**
176
+ * @method clone
177
+ * @description Returns a copy of the vector
178
+ * @returns {Vector3} - The cloned vector
179
+ */
180
+ clone(): Vector3;
112
181
  /**
113
182
  * @method equals
114
183
  * @description Checks if the vector is equal to another vector
@@ -135,5 +204,4 @@ declare class Vector3 {
135
204
  */
136
205
  getZ(): number;
137
206
  }
138
- export { Physics, Vector2, Vector3 };
139
- //# sourceMappingURL=Physics.d.ts.map
207
+ import * as planck from "planck";
@@ -0,0 +1,53 @@
1
+ export default Pool;
2
+ /**
3
+ * @class Pool
4
+ * @description Generic object pool to avoid per-frame allocations for churny
5
+ * objects (bullets, particles, enemies). Provide a factory and an optional
6
+ * reset function; acquire reused objects and release them when done.
7
+ *
8
+ * @example
9
+ * const bullets = new Pool(() => new Bullet(), (b, x, y) => b.spawn(x, y), 50);
10
+ * const b = bullets.acquire(px, py);
11
+ * // later...
12
+ * bullets.release(b);
13
+ */
14
+ declare class Pool {
15
+ /**
16
+ * @param {Function} factory - Creates a new pooled object
17
+ * @param {Function} [reset] - Called on acquire as reset(obj, ...args)
18
+ * @param {number} [initialSize] - Number of objects to pre-create
19
+ */
20
+ constructor(factory: Function, reset?: Function, initialSize?: number);
21
+ factory: Function;
22
+ reset: Function;
23
+ available: any[];
24
+ active: Set<any>;
25
+ /**
26
+ * @method acquire
27
+ * @description Returns a pooled object (reused or freshly created). Extra
28
+ * arguments are forwarded to the reset function.
29
+ * @returns {*} - The acquired object
30
+ */
31
+ acquire(...args: any[]): any;
32
+ /**
33
+ * @method release
34
+ * @description Returns an object to the pool.
35
+ * @param {*} obj - The object to release
36
+ */
37
+ release(obj: any): void;
38
+ /**
39
+ * @method releaseAll
40
+ * @description Returns every active object to the pool.
41
+ */
42
+ releaseAll(): void;
43
+ /**
44
+ * @member activeCount
45
+ * @description Number of currently-acquired objects.
46
+ */
47
+ get activeCount(): number;
48
+ /**
49
+ * @member size
50
+ * @description Total objects managed by the pool (active + available).
51
+ */
52
+ get size(): number;
53
+ }
@@ -0,0 +1,68 @@
1
+ export default PostEffects;
2
+ declare namespace PostEffects {
3
+ /**
4
+ * @method grayscale
5
+ * @description Desaturates the image.
6
+ */
7
+ function grayscale(): PostEffect;
8
+ /**
9
+ * @method vignette
10
+ * @description Darkens the edges of the screen.
11
+ * @param {Object} [options] - { intensity = 0.5, radius = 0.75, softness = 0.45 }
12
+ */
13
+ function vignette(options?: any): PostEffect;
14
+ /**
15
+ * @method colorGrade
16
+ * @description Adjusts brightness, contrast and saturation.
17
+ * @param {Object} [options] - { brightness = 0, contrast = 1, saturation = 1 }
18
+ */
19
+ function colorGrade(options?: any): PostEffect;
20
+ /**
21
+ * @method chromaticAberration
22
+ * @description Splits the RGB channels toward the screen edges.
23
+ * @param {Object} [options] - { amount = 0.003 }
24
+ */
25
+ function chromaticAberration(options?: any): PostEffect;
26
+ /**
27
+ * @method scanlines
28
+ * @description Overlays horizontal scanlines.
29
+ * @param {Object} [options] - { intensity = 0.15, count = 480 }
30
+ */
31
+ function scanlines(options?: any): PostEffect;
32
+ /**
33
+ * @method crt
34
+ * @description Retro CRT look: barrel distortion, scanlines and edge vignette.
35
+ * @param {Object} [options] - { curvature = 4.0, scanlineIntensity = 0.2, vignette = 0.3 }
36
+ */
37
+ function crt(options?: any): PostEffect;
38
+ /**
39
+ * @method bloom
40
+ * @description Glow around bright areas (multi-pass).
41
+ * @param {Object} [options] - { threshold = 0.7, intensity = 1.0, spread = 1.0 }
42
+ */
43
+ function bloom(options?: any): BloomEffect;
44
+ }
45
+ /**
46
+ * @class BloomEffect
47
+ * @description Multi-pass bloom: extract bright pixels above a threshold, blur
48
+ * them with a separable Gaussian, then add the result back over the scene. Built
49
+ * via {@link PostEffects.bloom}.
50
+ */
51
+ export class BloomEffect extends PostEffect {
52
+ constructor(options?: {});
53
+ threshold: any;
54
+ intensity: any;
55
+ spread: any;
56
+ /** @private */
57
+ private _threshold;
58
+ /** @private */
59
+ private _blurH;
60
+ /** @private */
61
+ private _blurV;
62
+ /** @private */
63
+ private _composite;
64
+ render(ctx: any): void;
65
+ /** @private */
66
+ private _bloomTex;
67
+ }
68
+ import { PostEffect } from "./PostProcessor.js";
@@ -0,0 +1,124 @@
1
+ export default PostProcessor;
2
+ /**
3
+ * @class PostProcessor
4
+ * @description Drives a chain of full-screen {@link PostEffect}s. The scene is
5
+ * rendered into a texture, then each effect is applied in sequence (ping-ponging
6
+ * between two render targets), and the final result is drawn to the screen.
7
+ *
8
+ * Created and managed by Emerald when you call `emerald.enablePostProcessing()`;
9
+ * you usually just add effects via `emerald.addPostEffect(PostEffects.bloom())`.
10
+ */
11
+ declare class PostProcessor {
12
+ gl: WebGLRenderingContext;
13
+ effects: any[];
14
+ enabled: boolean;
15
+ /** @private */
16
+ private _quad;
17
+ /** @private */
18
+ private _rtA;
19
+ /** @private */
20
+ private _rtB;
21
+ /** @private */
22
+ private _temps;
23
+ /** @private */
24
+ private _width;
25
+ /** @private */
26
+ private _height;
27
+ /**
28
+ * @method _restoreGL
29
+ * @description Rebuilds the fullscreen quad, ping-pong render targets, and
30
+ * every effect's program after a WebGL context loss.
31
+ * @private
32
+ */
33
+ private _restoreGL;
34
+ /**
35
+ * @method addEffect
36
+ * @description Appends an effect to the chain.
37
+ * @param {PostEffect} effect
38
+ * @returns {PostProcessor} - this
39
+ */
40
+ addEffect(effect: PostEffect): PostProcessor;
41
+ /**
42
+ * @method removeEffect
43
+ * @description Removes an effect from the chain.
44
+ */
45
+ removeEffect(effect: any): this;
46
+ /**
47
+ * @method clear
48
+ * @description Removes all effects.
49
+ */
50
+ clear(): this;
51
+ /**
52
+ * @method hasEffects
53
+ * @returns {boolean} - Whether any enabled effects exist.
54
+ */
55
+ hasEffects(): boolean;
56
+ /** @private */
57
+ private _acquireTemp;
58
+ /**
59
+ * @method process
60
+ * @description Applies the effect chain, drawing the final image to the canvas.
61
+ * @param {WebGLTexture} sceneTexture - The rendered scene
62
+ * @param {number} width - Canvas width in pixels
63
+ * @param {number} height - Canvas height in pixels
64
+ * @param {number} time - Seconds (for time-based effects)
65
+ */
66
+ process(sceneTexture: WebGLTexture, width: number, height: number, time: number): void;
67
+ /**
68
+ * @method _blit
69
+ * @description Renders one effect program from `input` into `output` (null =
70
+ * screen), setting the standard uniforms.
71
+ * @private
72
+ */
73
+ private _blit;
74
+ /**
75
+ * @method dispose
76
+ * @description Frees the render targets owned by this processor.
77
+ */
78
+ dispose(): void;
79
+ }
80
+ /**
81
+ * @class PostEffect
82
+ * @description A single full-screen post-processing pass: a fragment shader that
83
+ * samples the previous pass (`uScene`) and writes the next image. The shader
84
+ * automatically has `vUV`, `uScene`, `uResolution`, and `uTime` available; add
85
+ * your own uniforms and set them with the `setUniforms` callback.
86
+ *
87
+ * @example
88
+ * const tint = new PostEffect("tint", `
89
+ * uniform vec3 uTint;
90
+ * void main() { gl_FragColor = texture2D(uScene, vUV) * vec4(uTint, 1.0); }
91
+ * `, { setUniforms: (gl, loc) => gl.uniform3f(loc("uTint"), 1.0, 0.8, 0.8) });
92
+ */
93
+ export class PostEffect {
94
+ /**
95
+ * @param {string} name - A label (for debugging)
96
+ * @param {string} fragmentSource - Fragment shader body (declares void main)
97
+ * @param {Object} [options] - { setUniforms(gl, loc, ctx), enabled = true }
98
+ */
99
+ constructor(name: string, fragmentSource: string, options?: any);
100
+ name: string;
101
+ fragmentSource: string;
102
+ setUniforms: any;
103
+ enabled: boolean;
104
+ program: any;
105
+ /** @private */
106
+ private _locCache;
107
+ /** @private */
108
+ private _compile;
109
+ /**
110
+ * @method _restoreGL
111
+ * @description Drops the dead program/locations after a context loss so the
112
+ * next _compile builds fresh ones.
113
+ * @private
114
+ */
115
+ private _restoreGL;
116
+ loc(gl: any, name: any): any;
117
+ /**
118
+ * @method render
119
+ * @description Renders this effect from ctx.input into ctx.output. Override for
120
+ * multi-pass effects.
121
+ * @param {Object} ctx - Provided by the PostProcessor
122
+ */
123
+ render(ctx: any): void;
124
+ }
@@ -0,0 +1,56 @@
1
+ export default RenderTarget;
2
+ /**
3
+ * @class RenderTarget
4
+ * @description An offscreen render surface: a framebuffer backed by a color
5
+ * texture (and an optional depth buffer). Bind it to render the scene (or a
6
+ * post-processing pass) into a texture instead of the screen. The resulting
7
+ * `texture` can then be sampled by another pass or drawn to the canvas.
8
+ *
9
+ * Used by the post-processing pipeline, but also useful on its own for
10
+ * minimaps, mirrors, render-to-texture effects, or picture-in-picture.
11
+ *
12
+ * @example
13
+ * const rt = new RenderTarget(512, 512);
14
+ * rt.bind();
15
+ * // ...draw...
16
+ * rt.unbind();
17
+ * // rt.texture now holds the rendered image
18
+ */
19
+ declare class RenderTarget {
20
+ /**
21
+ * @param {number} width - Width in pixels
22
+ * @param {number} height - Height in pixels
23
+ * @param {Object} [options] - { depth = false, pixelart = false }
24
+ */
25
+ constructor(width: number, height: number, options?: any);
26
+ gl: WebGLRenderingContext;
27
+ width: number;
28
+ height: number;
29
+ depth: boolean;
30
+ pixelart: boolean;
31
+ framebuffer: WebGLFramebuffer;
32
+ texture: WebGLTexture;
33
+ depthBuffer: WebGLRenderbuffer;
34
+ /** @private */
35
+ private _allocate;
36
+ /**
37
+ * @method resize
38
+ * @description Resizes the surface (reallocating storage) if dimensions change.
39
+ */
40
+ resize(width: any, height: any): void;
41
+ /**
42
+ * @method bind
43
+ * @description Binds this framebuffer and sets the viewport to its full size.
44
+ */
45
+ bind(): void;
46
+ /**
47
+ * @method unbind
48
+ * @description Restores the default framebuffer (the canvas).
49
+ */
50
+ unbind(): void;
51
+ /**
52
+ * @method dispose
53
+ * @description Frees all GL resources held by this target.
54
+ */
55
+ dispose(): void;
56
+ }
@@ -0,0 +1,62 @@
1
+ export default Scene;
2
+ /**
3
+ * @class Scene
4
+ * @description Represents a scene
5
+ * @param {Array} objects - The objects in the scene
6
+ */
7
+ declare class Scene {
8
+ constructor(objects?: any[]);
9
+ objects: any[];
10
+ /**
11
+ * @method add
12
+ * @description Adds an object to the scene
13
+ * @param {GameObject} object - The object to add
14
+ */
15
+ add(object: GameObject): void;
16
+ /**
17
+ * @method remove
18
+ * @description Removes an object from the scene. By default the object's GPU
19
+ * resources stay alive so it can be re-added later; pass { dispose: true }
20
+ * to also destroy it (free GL buffers/textures, physics bodies) when it is
21
+ * being removed for good.
22
+ * @param {GameObject} object - The object to remove
23
+ * @param {Object} [options] - { dispose = false }
24
+ */
25
+ remove(object: GameObject, options?: any): void;
26
+ /**
27
+ * @method dispose
28
+ * @description Destroys every object in the scene (freeing their GPU
29
+ * resources and physics bodies) and empties it. Call when a level/screen is
30
+ * torn down for good — removing objects without disposing leaks GL buffers
31
+ * over repeated scene swaps.
32
+ */
33
+ dispose(): void;
34
+ /**
35
+ * @method update
36
+ * @description Ticks every active object's component lifecycle. Call once per
37
+ * frame (before or after drawScene) to drive Behaviour components.
38
+ * @param {number} deltaTime - Seconds since the previous frame
39
+ */
40
+ update(deltaTime: number): void;
41
+ /**
42
+ * @method setIsActive
43
+ * @description Sets the active state of the scene
44
+ * @param {boolean} bool - The active state
45
+ */
46
+ setIsActive(bool: boolean): void;
47
+ /**
48
+ * @method setActiveRecursive
49
+ * @description Sets the active state of the scene recursively
50
+ * @param {Object} object - The object to set the active state of
51
+ * @param {boolean} bool - The active state
52
+ */
53
+ setActiveRecursive(object: any, bool: boolean): void;
54
+ forEach(callback: any): void;
55
+ [Symbol.iterator](): {
56
+ next: () => {
57
+ value: any;
58
+ done: boolean;
59
+ };
60
+ };
61
+ }
62
+ import GameObject from "./components/GameObject.js";
@@ -0,0 +1,111 @@
1
+ export default ScreenEffects;
2
+ /**
3
+ * @class ScreenEffects
4
+ * @description In-engine full-screen camera/transition effects: fade to/from a
5
+ * color, screen flash, and cinematic letterbox bars. Everything is drawn with
6
+ * the engine's own screen-space quads (no DOM/CSS overlay), so it survives
7
+ * resolution changes, post-processing, and split-screen (the quads overfill
8
+ * every viewport and are clipped per camera).
9
+ *
10
+ * Add it to your scene's update loop by calling `update(dt)` each frame.
11
+ *
12
+ * @example
13
+ * const fx = new ScreenEffects(scene, { layer: 100000 });
14
+ * await fx.fadeOut(0.4, new Color(0,0,0,255)); // to black
15
+ * loadNextLevel();
16
+ * await fx.fadeIn(0.4);
17
+ * // bumps:
18
+ * fx.flash(new Color(255,255,255,255), 0.15);
19
+ * // in the loop, before drawScene: fx.update(dt);
20
+ */
21
+ declare class ScreenEffects {
22
+ /**
23
+ * @param {Scene} scene - The scene to draw the overlays into
24
+ * @param {Object} [options] - { layer = 100000, size = 5000 }
25
+ */
26
+ constructor(scene: Scene, options?: any);
27
+ scene: Scene;
28
+ /** @private */
29
+ private _fade;
30
+ /** @private */
31
+ private _flashQuad;
32
+ /** @private */
33
+ private _barTop;
34
+ /** @private */
35
+ private _barBottom;
36
+ /** @private */
37
+ private _letterboxHeight;
38
+ /** @private */
39
+ private _letterboxTarget;
40
+ /** @private */
41
+ private _barHalf;
42
+ /** @private */
43
+ private _fadeAnim;
44
+ /** @private */
45
+ private _flashAnim;
46
+ /** @private */
47
+ private _makeQuad;
48
+ /** @private */
49
+ private _shapeOf;
50
+ /** @private */
51
+ private _setColor;
52
+ /**
53
+ * @method fadeOut
54
+ * @description Fades the screen to a solid color (opacity 0 -> 1).
55
+ * @param {number} duration - Seconds
56
+ * @param {Color} [color] - Target color (default black)
57
+ * @param {Function} [easing] - Easing function (default linear)
58
+ * @returns {Promise<void>} - Resolves when the fade completes
59
+ */
60
+ fadeOut(duration?: number, color?: Color, easing?: Function): Promise<void>;
61
+ /**
62
+ * @method fadeIn
63
+ * @description Fades the screen back in from the current overlay (opacity -> 0).
64
+ * @param {number} duration - Seconds
65
+ * @param {Function} [easing] - Easing function (default linear)
66
+ * @returns {Promise<void>}
67
+ */
68
+ fadeIn(duration?: number, easing?: Function): Promise<void>;
69
+ /** @private */
70
+ private _startFade;
71
+ /**
72
+ * @method flash
73
+ * @description Flashes a color that ramps to full then fades out.
74
+ * @param {Color} [color] - Flash color (default white)
75
+ * @param {number} duration - Total seconds for the flash
76
+ * @returns {Promise<void>}
77
+ */
78
+ flash(color?: Color, duration?: number): Promise<void>;
79
+ /**
80
+ * @method transition
81
+ * @description Fades the screen out to a color, runs a swap callback at the
82
+ * darkest point (e.g. tear down the old scene and build the new one), then
83
+ * fades back in. Requires `update(dt)` to be pumped each frame by your loop.
84
+ * @param {Function} swap - Called (and awaited) while the screen is covered
85
+ * @param {Object} [options] - { duration = 0.4, color = black, outDuration,
86
+ * inDuration, easing }
87
+ * @returns {Promise<void>} - Resolves after the fade-in completes
88
+ */
89
+ transition(swap: Function, options?: any): Promise<void>;
90
+ /**
91
+ * @method setLetterbox
92
+ * @description Animates cinematic black bars to the given height (in pixels,
93
+ * per bar). Pass 0 to retract them.
94
+ * @param {number} heightPx - Target bar height in pixels
95
+ */
96
+ setLetterbox(heightPx: number): void;
97
+ /**
98
+ * @method update
99
+ * @description Advances all active transitions. Call once per frame.
100
+ * @param {number} dt - Seconds since last frame
101
+ */
102
+ update(dt: number): void;
103
+ /** @private */
104
+ private _screenHalfHeight;
105
+ /**
106
+ * @method destroy
107
+ * @description Removes all overlay objects from the scene.
108
+ */
109
+ destroy(): void;
110
+ }
111
+ import Color from "./Color.js";