@flare-engine/scene 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Grzegorz Otto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # @flare-engine/scene
2
+
3
+ Scene lifecycle + transitions — `SceneManager` with `register` / `go(name, data?)` / `push` / `pop`, `Scene` interface (`onPreload` / `onInit` / `onEnter` / `onUpdate` / `onDraw` / `onExit` / `onDestroy`), and three transition factories (`noneTransition`, `fadeTransition`, `slideTransition`).
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ bun add @flare-engine/scene
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { SceneManager, fadeTransition } from '@flare-engine/scene';
15
+
16
+ const manager = new SceneManager();
17
+ manager.register('menu', () => ({
18
+ onEnter() { /* ... */ },
19
+ onUpdate(dt) { /* ... */ },
20
+ onExit() { /* ... */ },
21
+ }));
22
+
23
+ await manager.go('menu', undefined, fadeTransition(0.3));
24
+ ```
25
+
26
+ See [API spec](../../docs/design/api-specs.md#flare-enginescene--4kb-gzip) and [skill reference](../../.github/skills/flare-scene/SKILL.md).
27
+
28
+ ## License
29
+
30
+ MIT
@@ -0,0 +1,124 @@
1
+ import { World } from '@flare-engine/ecs';
2
+ import { Camera2D } from '@flare-engine/render';
3
+ import { EasingFn } from '@flare-engine/math';
4
+
5
+ /**
6
+ * Scene lifecycle hooks. All methods are optional.
7
+ * A scene owns its own ECS World and Camera2D.
8
+ */
9
+ interface Scene {
10
+ /** Scene name (unique identifier). */
11
+ readonly name: string;
12
+ /** ECS World for this scene (created by SceneManager). */
13
+ world: World;
14
+ /** Camera for this scene (created by SceneManager). */
15
+ camera: Camera2D;
16
+ /** Load assets before the scene is initialized. */
17
+ onPreload?(): void | Promise<void>;
18
+ /** Initialize scene entities and systems. Called once after preload. */
19
+ onInit?(): void;
20
+ /** Called every time the scene becomes the active scene. */
21
+ onEnter?(data?: unknown): void;
22
+ /** Called every frame with scaled delta time. */
23
+ onUpdate?(dt: number): void;
24
+ /** Called every frame after update for rendering logic. */
25
+ onDraw?(): void;
26
+ /** Called when the scene is deactivated (pushed or replaced). */
27
+ onExit?(): void;
28
+ /** Called when the scene is permanently removed. Cleanup resources. */
29
+ onDestroy?(): void;
30
+ }
31
+ /** Factory function type for creating scenes. */
32
+ type SceneFactory = () => Scene;
33
+
34
+ /** Slide direction — where the outgoing scene moves off-screen to. */
35
+ type SlideDirection = 'left' | 'right' | 'up' | 'down';
36
+ /** Transition state during a scene switch. */
37
+ interface TransitionState {
38
+ /** Progress 0 → 1. */
39
+ progress: number;
40
+ /** Whether the transition is complete. */
41
+ done: boolean;
42
+ /** Phase: 'out' = leaving scene fading out, 'in' = entering scene fading in. */
43
+ phase: 'out' | 'in';
44
+ }
45
+ /** A transition controls the visual blending between two scenes. */
46
+ interface Transition {
47
+ /** Discriminator for consumers that apply a visual effect (alpha, translate, etc.). */
48
+ readonly kind: 'none' | 'fade' | 'slide';
49
+ /** Duration in seconds for each phase (out + in). */
50
+ readonly duration: number;
51
+ /** For slide transitions, the direction the outgoing scene slides toward. */
52
+ readonly direction?: SlideDirection;
53
+ /** Start the transition. */
54
+ start(phase: 'out' | 'in'): TransitionState;
55
+ /** Update the transition by dt seconds. Returns the updated state. */
56
+ update(state: TransitionState, dt: number): TransitionState;
57
+ }
58
+ /** No transition — instant scene switch. */
59
+ declare function noneTransition(): Transition;
60
+ /** Fade transition — consumer interprets `progress` as alpha. */
61
+ declare function fadeTransition(duration?: number, easing?: EasingFn): Transition;
62
+ /**
63
+ * Slide transition — consumer interprets `progress` as a 0→1 offset along `direction`.
64
+ * Default direction is 'left' (outgoing scene slides off to the left, incoming enters from the right).
65
+ */
66
+ declare function slideTransition(duration?: number, direction?: SlideDirection, easing?: EasingFn): Transition;
67
+
68
+ /**
69
+ * SceneManager — manages scene registration, navigation, and a scene stack.
70
+ *
71
+ * - `register(name, factory)` — register a scene factory
72
+ * - `go(name, data?)` — switch to a scene (clears the stack)
73
+ * - `push(name, data?)` — push a scene onto the stack (pauses current)
74
+ * - `pop()` — pop the top scene and resume the one below
75
+ * - `update(dt)` — update the active scene and any active transition
76
+ */
77
+ declare class SceneManager {
78
+ private _factories;
79
+ private _scenes;
80
+ private _initialized;
81
+ private _stack;
82
+ private _transition;
83
+ private _transitionState;
84
+ private _pendingScene;
85
+ private _pendingData;
86
+ /** The currently active scene (top of stack). */
87
+ get current(): Scene | undefined;
88
+ /** Number of scenes on the stack. */
89
+ get stackSize(): number;
90
+ /** Whether a transition is currently in progress. */
91
+ get isTransitioning(): boolean;
92
+ /** Set the default transition for scene switches. */
93
+ setTransition(transition: Transition): void;
94
+ /** Register a scene factory by name. */
95
+ register(name: string, factory: SceneFactory): void;
96
+ /**
97
+ * Navigate to a scene by name. Clears the entire stack.
98
+ * Calls onExit on the current scene, onDestroy on all stacked scenes,
99
+ * then onPreload → onInit → onEnter on the new scene.
100
+ */
101
+ go(name: string, data?: unknown): Promise<void>;
102
+ /**
103
+ * Push a scene onto the stack. The current scene gets onExit.
104
+ * The new scene gets onPreload → onInit → onEnter.
105
+ */
106
+ push(name: string, data?: unknown): Promise<void>;
107
+ /** Pop the top scene. Calls onExit + onDestroy on it, onEnter on the one below. */
108
+ pop(): void;
109
+ /** Update the active scene and any active transition. */
110
+ update(dt: number): void;
111
+ /** Destroy all scenes and clear state. */
112
+ destroy(): void;
113
+ /** Get the transition progress (0–1) for rendering. 0 during 'out', 1 when done. */
114
+ get transitionProgress(): number;
115
+ /** Get the current transition phase. */
116
+ get transitionPhase(): 'out' | 'in' | null;
117
+ private _getOrCreate;
118
+ private _initIfNeeded;
119
+ private _activateScene;
120
+ private _exitAndDestroyCurrent;
121
+ private _updateTransition;
122
+ }
123
+
124
+ export { type Scene, type SceneFactory, SceneManager, type SlideDirection, type Transition, type TransitionState, fadeTransition, noneTransition, slideTransition };
@@ -0,0 +1,124 @@
1
+ import { World } from '@flare-engine/ecs';
2
+ import { Camera2D } from '@flare-engine/render';
3
+ import { EasingFn } from '@flare-engine/math';
4
+
5
+ /**
6
+ * Scene lifecycle hooks. All methods are optional.
7
+ * A scene owns its own ECS World and Camera2D.
8
+ */
9
+ interface Scene {
10
+ /** Scene name (unique identifier). */
11
+ readonly name: string;
12
+ /** ECS World for this scene (created by SceneManager). */
13
+ world: World;
14
+ /** Camera for this scene (created by SceneManager). */
15
+ camera: Camera2D;
16
+ /** Load assets before the scene is initialized. */
17
+ onPreload?(): void | Promise<void>;
18
+ /** Initialize scene entities and systems. Called once after preload. */
19
+ onInit?(): void;
20
+ /** Called every time the scene becomes the active scene. */
21
+ onEnter?(data?: unknown): void;
22
+ /** Called every frame with scaled delta time. */
23
+ onUpdate?(dt: number): void;
24
+ /** Called every frame after update for rendering logic. */
25
+ onDraw?(): void;
26
+ /** Called when the scene is deactivated (pushed or replaced). */
27
+ onExit?(): void;
28
+ /** Called when the scene is permanently removed. Cleanup resources. */
29
+ onDestroy?(): void;
30
+ }
31
+ /** Factory function type for creating scenes. */
32
+ type SceneFactory = () => Scene;
33
+
34
+ /** Slide direction — where the outgoing scene moves off-screen to. */
35
+ type SlideDirection = 'left' | 'right' | 'up' | 'down';
36
+ /** Transition state during a scene switch. */
37
+ interface TransitionState {
38
+ /** Progress 0 → 1. */
39
+ progress: number;
40
+ /** Whether the transition is complete. */
41
+ done: boolean;
42
+ /** Phase: 'out' = leaving scene fading out, 'in' = entering scene fading in. */
43
+ phase: 'out' | 'in';
44
+ }
45
+ /** A transition controls the visual blending between two scenes. */
46
+ interface Transition {
47
+ /** Discriminator for consumers that apply a visual effect (alpha, translate, etc.). */
48
+ readonly kind: 'none' | 'fade' | 'slide';
49
+ /** Duration in seconds for each phase (out + in). */
50
+ readonly duration: number;
51
+ /** For slide transitions, the direction the outgoing scene slides toward. */
52
+ readonly direction?: SlideDirection;
53
+ /** Start the transition. */
54
+ start(phase: 'out' | 'in'): TransitionState;
55
+ /** Update the transition by dt seconds. Returns the updated state. */
56
+ update(state: TransitionState, dt: number): TransitionState;
57
+ }
58
+ /** No transition — instant scene switch. */
59
+ declare function noneTransition(): Transition;
60
+ /** Fade transition — consumer interprets `progress` as alpha. */
61
+ declare function fadeTransition(duration?: number, easing?: EasingFn): Transition;
62
+ /**
63
+ * Slide transition — consumer interprets `progress` as a 0→1 offset along `direction`.
64
+ * Default direction is 'left' (outgoing scene slides off to the left, incoming enters from the right).
65
+ */
66
+ declare function slideTransition(duration?: number, direction?: SlideDirection, easing?: EasingFn): Transition;
67
+
68
+ /**
69
+ * SceneManager — manages scene registration, navigation, and a scene stack.
70
+ *
71
+ * - `register(name, factory)` — register a scene factory
72
+ * - `go(name, data?)` — switch to a scene (clears the stack)
73
+ * - `push(name, data?)` — push a scene onto the stack (pauses current)
74
+ * - `pop()` — pop the top scene and resume the one below
75
+ * - `update(dt)` — update the active scene and any active transition
76
+ */
77
+ declare class SceneManager {
78
+ private _factories;
79
+ private _scenes;
80
+ private _initialized;
81
+ private _stack;
82
+ private _transition;
83
+ private _transitionState;
84
+ private _pendingScene;
85
+ private _pendingData;
86
+ /** The currently active scene (top of stack). */
87
+ get current(): Scene | undefined;
88
+ /** Number of scenes on the stack. */
89
+ get stackSize(): number;
90
+ /** Whether a transition is currently in progress. */
91
+ get isTransitioning(): boolean;
92
+ /** Set the default transition for scene switches. */
93
+ setTransition(transition: Transition): void;
94
+ /** Register a scene factory by name. */
95
+ register(name: string, factory: SceneFactory): void;
96
+ /**
97
+ * Navigate to a scene by name. Clears the entire stack.
98
+ * Calls onExit on the current scene, onDestroy on all stacked scenes,
99
+ * then onPreload → onInit → onEnter on the new scene.
100
+ */
101
+ go(name: string, data?: unknown): Promise<void>;
102
+ /**
103
+ * Push a scene onto the stack. The current scene gets onExit.
104
+ * The new scene gets onPreload → onInit → onEnter.
105
+ */
106
+ push(name: string, data?: unknown): Promise<void>;
107
+ /** Pop the top scene. Calls onExit + onDestroy on it, onEnter on the one below. */
108
+ pop(): void;
109
+ /** Update the active scene and any active transition. */
110
+ update(dt: number): void;
111
+ /** Destroy all scenes and clear state. */
112
+ destroy(): void;
113
+ /** Get the transition progress (0–1) for rendering. 0 during 'out', 1 when done. */
114
+ get transitionProgress(): number;
115
+ /** Get the current transition phase. */
116
+ get transitionPhase(): 'out' | 'in' | null;
117
+ private _getOrCreate;
118
+ private _initIfNeeded;
119
+ private _activateScene;
120
+ private _exitAndDestroyCurrent;
121
+ private _updateTransition;
122
+ }
123
+
124
+ export { type Scene, type SceneFactory, SceneManager, type SlideDirection, type Transition, type TransitionState, fadeTransition, noneTransition, slideTransition };
package/dist/index.js ADDED
@@ -0,0 +1,284 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ SceneManager: () => SceneManager,
24
+ fadeTransition: () => fadeTransition,
25
+ noneTransition: () => noneTransition,
26
+ slideTransition: () => slideTransition
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+
30
+ // src/transition.ts
31
+ var identity = (t) => t;
32
+ function makeAdvancer(duration, easing) {
33
+ let raw = 0;
34
+ return {
35
+ reset() {
36
+ raw = 0;
37
+ },
38
+ advance(state, dt) {
39
+ if (state.done) return state;
40
+ raw += dt / duration;
41
+ if (raw >= 1) {
42
+ raw = 1;
43
+ state.progress = 1;
44
+ state.done = true;
45
+ } else {
46
+ state.progress = easing(raw);
47
+ }
48
+ return state;
49
+ }
50
+ };
51
+ }
52
+ function noneTransition() {
53
+ return {
54
+ kind: "none",
55
+ duration: 0,
56
+ start(phase) {
57
+ return { progress: 1, done: true, phase };
58
+ },
59
+ update(state) {
60
+ state.progress = 1;
61
+ state.done = true;
62
+ return state;
63
+ }
64
+ };
65
+ }
66
+ function fadeTransition(duration = 0.3, easing = identity) {
67
+ const advancer = makeAdvancer(duration, easing);
68
+ return {
69
+ kind: "fade",
70
+ duration,
71
+ start(phase) {
72
+ advancer.reset();
73
+ return { progress: 0, done: false, phase };
74
+ },
75
+ update(state, dt) {
76
+ return advancer.advance(state, dt);
77
+ }
78
+ };
79
+ }
80
+ function slideTransition(duration = 0.3, direction = "left", easing = identity) {
81
+ const advancer = makeAdvancer(duration, easing);
82
+ return {
83
+ kind: "slide",
84
+ duration,
85
+ direction,
86
+ start(phase) {
87
+ advancer.reset();
88
+ return { progress: 0, done: false, phase };
89
+ },
90
+ update(state, dt) {
91
+ return advancer.advance(state, dt);
92
+ }
93
+ };
94
+ }
95
+
96
+ // src/scene-manager.ts
97
+ var import_ecs = require("@flare-engine/ecs");
98
+ var import_render = require("@flare-engine/render");
99
+ var SceneManager = class {
100
+ _factories = /* @__PURE__ */ new Map();
101
+ _scenes = /* @__PURE__ */ new Map();
102
+ _initialized = /* @__PURE__ */ new Set();
103
+ _stack = [];
104
+ _transition = noneTransition();
105
+ _transitionState = null;
106
+ _pendingScene = null;
107
+ _pendingData = void 0;
108
+ /** The currently active scene (top of stack). */
109
+ get current() {
110
+ return this._stack.length > 0 ? this._stack[this._stack.length - 1] : void 0;
111
+ }
112
+ /** Number of scenes on the stack. */
113
+ get stackSize() {
114
+ return this._stack.length;
115
+ }
116
+ /** Whether a transition is currently in progress. */
117
+ get isTransitioning() {
118
+ return this._transitionState !== null;
119
+ }
120
+ /** Set the default transition for scene switches. */
121
+ setTransition(transition) {
122
+ this._transition = transition;
123
+ }
124
+ /** Register a scene factory by name. */
125
+ register(name, factory) {
126
+ this._factories.set(name, factory);
127
+ }
128
+ /**
129
+ * Navigate to a scene by name. Clears the entire stack.
130
+ * Calls onExit on the current scene, onDestroy on all stacked scenes,
131
+ * then onPreload → onInit → onEnter on the new scene.
132
+ */
133
+ async go(name, data) {
134
+ const scene = this._getOrCreate(name);
135
+ if (!scene) return;
136
+ if (this._transition.duration > 0 && this.current) {
137
+ this._pendingScene = scene;
138
+ this._pendingData = data;
139
+ this._transitionState = this._transition.start("out");
140
+ } else {
141
+ this._exitAndDestroyCurrent();
142
+ await this._activateScene(scene, data);
143
+ }
144
+ }
145
+ /**
146
+ * Push a scene onto the stack. The current scene gets onExit.
147
+ * The new scene gets onPreload → onInit → onEnter.
148
+ */
149
+ async push(name, data) {
150
+ const scene = this._getOrCreate(name);
151
+ if (!scene) return;
152
+ this.current?.onExit?.();
153
+ await this._initIfNeeded(scene);
154
+ this._stack.push(scene);
155
+ scene.onEnter?.(data);
156
+ }
157
+ /** Pop the top scene. Calls onExit + onDestroy on it, onEnter on the one below. */
158
+ pop() {
159
+ if (this._stack.length <= 1) return;
160
+ const top = this._stack.pop();
161
+ top.onExit?.();
162
+ top.onDestroy?.();
163
+ this._scenes.delete(top.name);
164
+ this._initialized.delete(top.name);
165
+ this.current?.onEnter?.();
166
+ }
167
+ /** Update the active scene and any active transition. */
168
+ update(dt) {
169
+ if (this._transitionState) {
170
+ this._updateTransition(dt);
171
+ return;
172
+ }
173
+ const scene = this.current;
174
+ if (scene) {
175
+ scene.onUpdate?.(dt);
176
+ scene.onDraw?.();
177
+ }
178
+ }
179
+ /** Destroy all scenes and clear state. */
180
+ destroy() {
181
+ for (let i = this._stack.length - 1; i >= 0; i--) {
182
+ const scene = this._stack[i];
183
+ scene.onExit?.();
184
+ scene.onDestroy?.();
185
+ }
186
+ this._stack.length = 0;
187
+ this._scenes.clear();
188
+ this._initialized.clear();
189
+ this._transitionState = null;
190
+ this._pendingScene = null;
191
+ }
192
+ /** Get the transition progress (0–1) for rendering. 0 during 'out', 1 when done. */
193
+ get transitionProgress() {
194
+ if (!this._transitionState) return 0;
195
+ return this._transitionState.progress;
196
+ }
197
+ /** Get the current transition phase. */
198
+ get transitionPhase() {
199
+ return this._transitionState?.phase ?? null;
200
+ }
201
+ _getOrCreate(name) {
202
+ let scene = this._scenes.get(name);
203
+ if (scene) return scene;
204
+ const factory = this._factories.get(name);
205
+ if (!factory) return null;
206
+ scene = factory();
207
+ scene.world = new import_ecs.World();
208
+ scene.camera = new import_render.Camera2D();
209
+ this._scenes.set(name, scene);
210
+ return scene;
211
+ }
212
+ async _initIfNeeded(scene) {
213
+ if (this._initialized.has(scene.name)) return;
214
+ this._initialized.add(scene.name);
215
+ await scene.onPreload?.();
216
+ scene.onInit?.();
217
+ }
218
+ async _activateScene(scene, data) {
219
+ for (let i = this._stack.length - 1; i >= 0; i--) {
220
+ const s = this._stack[i];
221
+ s.onExit?.();
222
+ s.onDestroy?.();
223
+ this._scenes.delete(s.name);
224
+ this._initialized.delete(s.name);
225
+ }
226
+ this._stack.length = 0;
227
+ await this._initIfNeeded(scene);
228
+ this._stack.push(scene);
229
+ scene.onEnter?.(data);
230
+ }
231
+ _exitAndDestroyCurrent() {
232
+ for (let i = this._stack.length - 1; i >= 0; i--) {
233
+ const s = this._stack[i];
234
+ s.onExit?.();
235
+ s.onDestroy?.();
236
+ this._scenes.delete(s.name);
237
+ this._initialized.delete(s.name);
238
+ }
239
+ this._stack.length = 0;
240
+ }
241
+ _updateTransition(dt) {
242
+ if (!this._transitionState) return;
243
+ this._transition.update(this._transitionState, dt);
244
+ if (this._transitionState.done) {
245
+ if (this._transitionState.phase === "out") {
246
+ const pending = this._pendingScene;
247
+ const data = this._pendingData;
248
+ this._pendingScene = null;
249
+ this._pendingData = void 0;
250
+ if (pending) {
251
+ for (let i = this._stack.length - 1; i >= 0; i--) {
252
+ const s = this._stack[i];
253
+ s.onExit?.();
254
+ s.onDestroy?.();
255
+ this._scenes.delete(s.name);
256
+ this._initialized.delete(s.name);
257
+ }
258
+ this._stack.length = 0;
259
+ this._scenes.set(pending.name, pending);
260
+ if (!this._initialized.has(pending.name)) {
261
+ this._initialized.add(pending.name);
262
+ pending.onPreload?.();
263
+ pending.onInit?.();
264
+ }
265
+ this._stack.push(pending);
266
+ pending.onEnter?.(data);
267
+ }
268
+ this._transitionState = this._transition.start("in");
269
+ } else {
270
+ this._transitionState = null;
271
+ }
272
+ }
273
+ this.current?.onUpdate?.(dt);
274
+ this.current?.onDraw?.();
275
+ }
276
+ };
277
+ // Annotate the CommonJS export names for ESM import in node:
278
+ 0 && (module.exports = {
279
+ SceneManager,
280
+ fadeTransition,
281
+ noneTransition,
282
+ slideTransition
283
+ });
284
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/transition.ts","../src/scene-manager.ts"],"sourcesContent":["export type { Scene, SceneFactory } from './scene.js';\n\nexport {\n type SlideDirection,\n type Transition,\n type TransitionState,\n noneTransition,\n fadeTransition,\n slideTransition,\n} from './transition.js';\n\nexport { SceneManager } from './scene-manager.js';\n","import type { EasingFn } from '@flare-engine/math';\n\nexport type { EasingFn };\n\n/** Slide direction — where the outgoing scene moves off-screen to. */\nexport type SlideDirection = 'left' | 'right' | 'up' | 'down';\n\n/** Transition state during a scene switch. */\nexport interface TransitionState {\n /** Progress 0 → 1. */\n progress: number;\n /** Whether the transition is complete. */\n done: boolean;\n /** Phase: 'out' = leaving scene fading out, 'in' = entering scene fading in. */\n phase: 'out' | 'in';\n}\n\n/** A transition controls the visual blending between two scenes. */\nexport interface Transition {\n /** Discriminator for consumers that apply a visual effect (alpha, translate, etc.). */\n readonly kind: 'none' | 'fade' | 'slide';\n\n /** Duration in seconds for each phase (out + in). */\n readonly duration: number;\n\n /** For slide transitions, the direction the outgoing scene slides toward. */\n readonly direction?: SlideDirection;\n\n /** Start the transition. */\n start(phase: 'out' | 'in'): TransitionState;\n\n /** Update the transition by dt seconds. Returns the updated state. */\n update(state: TransitionState, dt: number): TransitionState;\n}\n\nconst identity: EasingFn = (t) => t;\n\n/**\n * Returns a stateful advance function that tracks raw (linear) progress in its\n * own closure so the easing function is applied without accumulating drift.\n * Call `reset()` when starting a new transition phase.\n */\nfunction makeAdvancer(duration: number, easing: EasingFn) {\n let raw = 0;\n return {\n reset() {\n raw = 0;\n },\n advance(state: TransitionState, dt: number): TransitionState {\n if (state.done) return state;\n raw += dt / duration;\n if (raw >= 1) {\n raw = 1;\n state.progress = 1;\n state.done = true;\n } else {\n state.progress = easing(raw);\n }\n return state;\n },\n };\n}\n\n/** No transition — instant scene switch. */\nexport function noneTransition(): Transition {\n return {\n kind: 'none',\n duration: 0,\n start(phase) {\n return { progress: 1, done: true, phase };\n },\n update(state) {\n state.progress = 1;\n state.done = true;\n return state;\n },\n };\n}\n\n/** Fade transition — consumer interprets `progress` as alpha. */\nexport function fadeTransition(duration = 0.3, easing: EasingFn = identity): Transition {\n const advancer = makeAdvancer(duration, easing);\n return {\n kind: 'fade',\n duration,\n start(phase) {\n advancer.reset();\n return { progress: 0, done: false, phase };\n },\n update(state, dt) {\n return advancer.advance(state, dt);\n },\n };\n}\n\n/**\n * Slide transition — consumer interprets `progress` as a 0→1 offset along `direction`.\n * Default direction is 'left' (outgoing scene slides off to the left, incoming enters from the right).\n */\nexport function slideTransition(\n duration = 0.3,\n direction: SlideDirection = 'left',\n easing: EasingFn = identity,\n): Transition {\n const advancer = makeAdvancer(duration, easing);\n return {\n kind: 'slide',\n duration,\n direction,\n start(phase) {\n advancer.reset();\n return { progress: 0, done: false, phase };\n },\n update(state, dt) {\n return advancer.advance(state, dt);\n },\n };\n}\n","import { World } from '@flare-engine/ecs';\nimport { Camera2D } from '@flare-engine/render';\nimport type { Scene, SceneFactory } from './scene.js';\nimport type { Transition, TransitionState } from './transition.js';\nimport { noneTransition } from './transition.js';\n\n/**\n * SceneManager — manages scene registration, navigation, and a scene stack.\n *\n * - `register(name, factory)` — register a scene factory\n * - `go(name, data?)` — switch to a scene (clears the stack)\n * - `push(name, data?)` — push a scene onto the stack (pauses current)\n * - `pop()` — pop the top scene and resume the one below\n * - `update(dt)` — update the active scene and any active transition\n */\nexport class SceneManager {\n private _factories = new Map<string, SceneFactory>();\n private _scenes = new Map<string, Scene>();\n private _initialized = new Set<string>();\n private _stack: Scene[] = [];\n private _transition: Transition = noneTransition();\n private _transitionState: TransitionState | null = null;\n private _pendingScene: Scene | null = null;\n private _pendingData: unknown = undefined;\n\n /** The currently active scene (top of stack). */\n get current(): Scene | undefined {\n return this._stack.length > 0 ? this._stack[this._stack.length - 1] : undefined;\n }\n\n /** Number of scenes on the stack. */\n get stackSize(): number {\n return this._stack.length;\n }\n\n /** Whether a transition is currently in progress. */\n get isTransitioning(): boolean {\n return this._transitionState !== null;\n }\n\n /** Set the default transition for scene switches. */\n setTransition(transition: Transition): void {\n this._transition = transition;\n }\n\n /** Register a scene factory by name. */\n register(name: string, factory: SceneFactory): void {\n this._factories.set(name, factory);\n }\n\n /**\n * Navigate to a scene by name. Clears the entire stack.\n * Calls onExit on the current scene, onDestroy on all stacked scenes,\n * then onPreload → onInit → onEnter on the new scene.\n */\n async go(name: string, data?: unknown): Promise<void> {\n const scene = this._getOrCreate(name);\n if (!scene) return;\n\n if (this._transition.duration > 0 && this.current) {\n // Animated transition\n this._pendingScene = scene;\n this._pendingData = data;\n this._transitionState = this._transition.start('out');\n } else {\n // Instant transition\n this._exitAndDestroyCurrent();\n await this._activateScene(scene, data);\n }\n }\n\n /**\n * Push a scene onto the stack. The current scene gets onExit.\n * The new scene gets onPreload → onInit → onEnter.\n */\n async push(name: string, data?: unknown): Promise<void> {\n const scene = this._getOrCreate(name);\n if (!scene) return;\n\n this.current?.onExit?.();\n await this._initIfNeeded(scene);\n this._stack.push(scene);\n scene.onEnter?.(data);\n }\n\n /** Pop the top scene. Calls onExit + onDestroy on it, onEnter on the one below. */\n pop(): void {\n if (this._stack.length <= 1) return;\n\n const top = this._stack.pop()!;\n top.onExit?.();\n top.onDestroy?.();\n this._scenes.delete(top.name);\n this._initialized.delete(top.name);\n\n this.current?.onEnter?.();\n }\n\n /** Update the active scene and any active transition. */\n update(dt: number): void {\n if (this._transitionState) {\n this._updateTransition(dt);\n return;\n }\n\n const scene = this.current;\n if (scene) {\n scene.onUpdate?.(dt);\n scene.onDraw?.();\n }\n }\n\n /** Destroy all scenes and clear state. */\n destroy(): void {\n for (let i = this._stack.length - 1; i >= 0; i--) {\n const scene = this._stack[i]!;\n scene.onExit?.();\n scene.onDestroy?.();\n }\n this._stack.length = 0;\n this._scenes.clear();\n this._initialized.clear();\n this._transitionState = null;\n this._pendingScene = null;\n }\n\n /** Get the transition progress (0–1) for rendering. 0 during 'out', 1 when done. */\n get transitionProgress(): number {\n if (!this._transitionState) return 0;\n return this._transitionState.progress;\n }\n\n /** Get the current transition phase. */\n get transitionPhase(): 'out' | 'in' | null {\n return this._transitionState?.phase ?? null;\n }\n\n private _getOrCreate(name: string): Scene | null {\n let scene = this._scenes.get(name);\n if (scene) return scene;\n\n const factory = this._factories.get(name);\n if (!factory) return null;\n\n scene = factory();\n // Inject World and Camera\n scene.world = new World();\n scene.camera = new Camera2D();\n this._scenes.set(name, scene);\n return scene;\n }\n\n private async _initIfNeeded(scene: Scene): Promise<void> {\n if (this._initialized.has(scene.name)) return;\n this._initialized.add(scene.name);\n await scene.onPreload?.();\n scene.onInit?.();\n }\n\n private async _activateScene(scene: Scene, data?: unknown): Promise<void> {\n // Destroy all stacked scenes\n for (let i = this._stack.length - 1; i >= 0; i--) {\n const s = this._stack[i]!;\n s.onExit?.();\n s.onDestroy?.();\n this._scenes.delete(s.name);\n this._initialized.delete(s.name);\n }\n this._stack.length = 0;\n\n await this._initIfNeeded(scene);\n this._stack.push(scene);\n scene.onEnter?.(data);\n }\n\n private _exitAndDestroyCurrent(): void {\n for (let i = this._stack.length - 1; i >= 0; i--) {\n const s = this._stack[i]!;\n s.onExit?.();\n s.onDestroy?.();\n this._scenes.delete(s.name);\n this._initialized.delete(s.name);\n }\n this._stack.length = 0;\n }\n\n private _updateTransition(dt: number): void {\n if (!this._transitionState) return;\n\n this._transition.update(this._transitionState, dt);\n\n if (this._transitionState.done) {\n if (this._transitionState.phase === 'out') {\n // Phase 'out' done — switch scenes, start 'in' phase\n const pending = this._pendingScene;\n const data = this._pendingData;\n this._pendingScene = null;\n this._pendingData = undefined;\n\n if (pending) {\n // Destroy current stack\n for (let i = this._stack.length - 1; i >= 0; i--) {\n const s = this._stack[i]!;\n s.onExit?.();\n s.onDestroy?.();\n this._scenes.delete(s.name);\n this._initialized.delete(s.name);\n }\n this._stack.length = 0;\n\n // Init and activate pending scene synchronously for transitions\n this._scenes.set(pending.name, pending);\n if (!this._initialized.has(pending.name)) {\n this._initialized.add(pending.name);\n pending.onPreload?.();\n pending.onInit?.();\n }\n this._stack.push(pending);\n pending.onEnter?.(data);\n }\n\n this._transitionState = this._transition.start('in');\n } else {\n // Phase 'in' done — transition complete\n this._transitionState = null;\n }\n }\n\n // Still update the current scene during transition\n this.current?.onUpdate?.(dt);\n this.current?.onDraw?.();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmCA,IAAM,WAAqB,CAAC,MAAM;AAOlC,SAAS,aAAa,UAAkB,QAAkB;AACxD,MAAI,MAAM;AACV,SAAO;AAAA,IACL,QAAQ;AACN,YAAM;AAAA,IACR;AAAA,IACA,QAAQ,OAAwB,IAA6B;AAC3D,UAAI,MAAM,KAAM,QAAO;AACvB,aAAO,KAAK;AACZ,UAAI,OAAO,GAAG;AACZ,cAAM;AACN,cAAM,WAAW;AACjB,cAAM,OAAO;AAAA,MACf,OAAO;AACL,cAAM,WAAW,OAAO,GAAG;AAAA,MAC7B;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAGO,SAAS,iBAA6B;AAC3C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,IACV,MAAM,OAAO;AACX,aAAO,EAAE,UAAU,GAAG,MAAM,MAAM,MAAM;AAAA,IAC1C;AAAA,IACA,OAAO,OAAO;AACZ,YAAM,WAAW;AACjB,YAAM,OAAO;AACb,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAGO,SAAS,eAAe,WAAW,KAAK,SAAmB,UAAsB;AACtF,QAAM,WAAW,aAAa,UAAU,MAAM;AAC9C,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA,MAAM,OAAO;AACX,eAAS,MAAM;AACf,aAAO,EAAE,UAAU,GAAG,MAAM,OAAO,MAAM;AAAA,IAC3C;AAAA,IACA,OAAO,OAAO,IAAI;AAChB,aAAO,SAAS,Q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AA,IACjC;AACA,SAAK,OAAO,SAAS;AAAA,EACvB;AAAA,EAEQ,kBAAkB,IAAkB;AAC1C,QAAI,CAAC,KAAK,iBAAkB;AAE5B,SAAK,YAAY,OAAO,KAAK,kBAAkB,EAAE;AAEjD,QAAI,KAAK,iBAAiB,MAAM;AAC9B,UAAI,KAAK,iBAAiB,UAAU,OAAO;AAEzC,cAAM,UAAU,KAAK;AACrB,cAAM,OAAO,KAAK;AAClB,aAAK,gBAAgB;AACrB,aAAK,eAAe;AAEpB,YAAI,SAAS;AAEX,mBAAS,IAAI,KAAK,OAAO,SAAS,GAAG,KAAK,GAAG,KAAK;AAChD,kBAAM,IAAI,KAAK,OAAO,CAAC;AACvB,cAAE,SAAS;AACX,cAAE,YAAY;AACd,iBAAK,QAAQ,OAAO,EAAE,IAAI;AAC1B,iBAAK,aAAa,OAAO,EAAE,IAAI;AAAA,UACjC;AACA,eAAK,OAAO,SAAS;AAGrB,eAAK,QAAQ,IAAI,QAAQ,MAAM,OAAO;AACtC,cAAI,CAAC,KAAK,aAAa,IAAI,QAAQ,IAAI,GAAG;AACxC,iBAAK,aAAa,IAAI,QAAQ,IAAI;AAClC,oBAAQ,YAAY;AACpB,oBAAQ,SAAS;AAAA,UACnB;AACA,eAAK,OAAO,KAAK,OAAO;AACxB,kBAAQ,UAAU,IAAI;AAAA,QACxB;AAEA,aAAK,mBAAmB,KAAK,YAAY,MAAM,IAAI;AAAA,MACrD,OAAO;AAEL,aAAK,mBAAmB;AAAA,MAC1B;AAAA,IACF;AAGA,SAAK,SAAS,WAAW,EAAE;AAC3B,SAAK,SAAS,SAAS;AAAA,EACzB;AACF;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,254 @@
1
+ // src/transition.ts
2
+ var identity = (t) => t;
3
+ function makeAdvancer(duration, easing) {
4
+ let raw = 0;
5
+ return {
6
+ reset() {
7
+ raw = 0;
8
+ },
9
+ advance(state, dt) {
10
+ if (state.done) return state;
11
+ raw += dt / duration;
12
+ if (raw >= 1) {
13
+ raw = 1;
14
+ state.progress = 1;
15
+ state.done = true;
16
+ } else {
17
+ state.progress = easing(raw);
18
+ }
19
+ return state;
20
+ }
21
+ };
22
+ }
23
+ function noneTransition() {
24
+ return {
25
+ kind: "none",
26
+ duration: 0,
27
+ start(phase) {
28
+ return { progress: 1, done: true, phase };
29
+ },
30
+ update(state) {
31
+ state.progress = 1;
32
+ state.done = true;
33
+ return state;
34
+ }
35
+ };
36
+ }
37
+ function fadeTransition(duration = 0.3, easing = identity) {
38
+ const advancer = makeAdvancer(duration, easing);
39
+ return {
40
+ kind: "fade",
41
+ duration,
42
+ start(phase) {
43
+ advancer.reset();
44
+ return { progress: 0, done: false, phase };
45
+ },
46
+ update(state, dt) {
47
+ return advancer.advance(state, dt);
48
+ }
49
+ };
50
+ }
51
+ function slideTransition(duration = 0.3, direction = "left", easing = identity) {
52
+ const advancer = makeAdvancer(duration, easing);
53
+ return {
54
+ kind: "slide",
55
+ duration,
56
+ direction,
57
+ start(phase) {
58
+ advancer.reset();
59
+ return { progress: 0, done: false, phase };
60
+ },
61
+ update(state, dt) {
62
+ return advancer.advance(state, dt);
63
+ }
64
+ };
65
+ }
66
+
67
+ // src/scene-manager.ts
68
+ import { World } from "@flare-engine/ecs";
69
+ import { Camera2D } from "@flare-engine/render";
70
+ var SceneManager = class {
71
+ _factories = /* @__PURE__ */ new Map();
72
+ _scenes = /* @__PURE__ */ new Map();
73
+ _initialized = /* @__PURE__ */ new Set();
74
+ _stack = [];
75
+ _transition = noneTransition();
76
+ _transitionState = null;
77
+ _pendingScene = null;
78
+ _pendingData = void 0;
79
+ /** The currently active scene (top of stack). */
80
+ get current() {
81
+ return this._stack.length > 0 ? this._stack[this._stack.length - 1] : void 0;
82
+ }
83
+ /** Number of scenes on the stack. */
84
+ get stackSize() {
85
+ return this._stack.length;
86
+ }
87
+ /** Whether a transition is currently in progress. */
88
+ get isTransitioning() {
89
+ return this._transitionState !== null;
90
+ }
91
+ /** Set the default transition for scene switches. */
92
+ setTransition(transition) {
93
+ this._transition = transition;
94
+ }
95
+ /** Register a scene factory by name. */
96
+ register(name, factory) {
97
+ this._factories.set(name, factory);
98
+ }
99
+ /**
100
+ * Navigate to a scene by name. Clears the entire stack.
101
+ * Calls onExit on the current scene, onDestroy on all stacked scenes,
102
+ * then onPreload → onInit → onEnter on the new scene.
103
+ */
104
+ async go(name, data) {
105
+ const scene = this._getOrCreate(name);
106
+ if (!scene) return;
107
+ if (this._transition.duration > 0 && this.current) {
108
+ this._pendingScene = scene;
109
+ this._pendingData = data;
110
+ this._transitionState = this._transition.start("out");
111
+ } else {
112
+ this._exitAndDestroyCurrent();
113
+ await this._activateScene(scene, data);
114
+ }
115
+ }
116
+ /**
117
+ * Push a scene onto the stack. The current scene gets onExit.
118
+ * The new scene gets onPreload → onInit → onEnter.
119
+ */
120
+ async push(name, data) {
121
+ const scene = this._getOrCreate(name);
122
+ if (!scene) return;
123
+ this.current?.onExit?.();
124
+ await this._initIfNeeded(scene);
125
+ this._stack.push(scene);
126
+ scene.onEnter?.(data);
127
+ }
128
+ /** Pop the top scene. Calls onExit + onDestroy on it, onEnter on the one below. */
129
+ pop() {
130
+ if (this._stack.length <= 1) return;
131
+ const top = this._stack.pop();
132
+ top.onExit?.();
133
+ top.onDestroy?.();
134
+ this._scenes.delete(top.name);
135
+ this._initialized.delete(top.name);
136
+ this.current?.onEnter?.();
137
+ }
138
+ /** Update the active scene and any active transition. */
139
+ update(dt) {
140
+ if (this._transitionState) {
141
+ this._updateTransition(dt);
142
+ return;
143
+ }
144
+ const scene = this.current;
145
+ if (scene) {
146
+ scene.onUpdate?.(dt);
147
+ scene.onDraw?.();
148
+ }
149
+ }
150
+ /** Destroy all scenes and clear state. */
151
+ destroy() {
152
+ for (let i = this._stack.length - 1; i >= 0; i--) {
153
+ const scene = this._stack[i];
154
+ scene.onExit?.();
155
+ scene.onDestroy?.();
156
+ }
157
+ this._stack.length = 0;
158
+ this._scenes.clear();
159
+ this._initialized.clear();
160
+ this._transitionState = null;
161
+ this._pendingScene = null;
162
+ }
163
+ /** Get the transition progress (0–1) for rendering. 0 during 'out', 1 when done. */
164
+ get transitionProgress() {
165
+ if (!this._transitionState) return 0;
166
+ return this._transitionState.progress;
167
+ }
168
+ /** Get the current transition phase. */
169
+ get transitionPhase() {
170
+ return this._transitionState?.phase ?? null;
171
+ }
172
+ _getOrCreate(name) {
173
+ let scene = this._scenes.get(name);
174
+ if (scene) return scene;
175
+ const factory = this._factories.get(name);
176
+ if (!factory) return null;
177
+ scene = factory();
178
+ scene.world = new World();
179
+ scene.camera = new Camera2D();
180
+ this._scenes.set(name, scene);
181
+ return scene;
182
+ }
183
+ async _initIfNeeded(scene) {
184
+ if (this._initialized.has(scene.name)) return;
185
+ this._initialized.add(scene.name);
186
+ await scene.onPreload?.();
187
+ scene.onInit?.();
188
+ }
189
+ async _activateScene(scene, data) {
190
+ for (let i = this._stack.length - 1; i >= 0; i--) {
191
+ const s = this._stack[i];
192
+ s.onExit?.();
193
+ s.onDestroy?.();
194
+ this._scenes.delete(s.name);
195
+ this._initialized.delete(s.name);
196
+ }
197
+ this._stack.length = 0;
198
+ await this._initIfNeeded(scene);
199
+ this._stack.push(scene);
200
+ scene.onEnter?.(data);
201
+ }
202
+ _exitAndDestroyCurrent() {
203
+ for (let i = this._stack.length - 1; i >= 0; i--) {
204
+ const s = this._stack[i];
205
+ s.onExit?.();
206
+ s.onDestroy?.();
207
+ this._scenes.delete(s.name);
208
+ this._initialized.delete(s.name);
209
+ }
210
+ this._stack.length = 0;
211
+ }
212
+ _updateTransition(dt) {
213
+ if (!this._transitionState) return;
214
+ this._transition.update(this._transitionState, dt);
215
+ if (this._transitionState.done) {
216
+ if (this._transitionState.phase === "out") {
217
+ const pending = this._pendingScene;
218
+ const data = this._pendingData;
219
+ this._pendingScene = null;
220
+ this._pendingData = void 0;
221
+ if (pending) {
222
+ for (let i = this._stack.length - 1; i >= 0; i--) {
223
+ const s = this._stack[i];
224
+ s.onExit?.();
225
+ s.onDestroy?.();
226
+ this._scenes.delete(s.name);
227
+ this._initialized.delete(s.name);
228
+ }
229
+ this._stack.length = 0;
230
+ this._scenes.set(pending.name, pending);
231
+ if (!this._initialized.has(pending.name)) {
232
+ this._initialized.add(pending.name);
233
+ pending.onPreload?.();
234
+ pending.onInit?.();
235
+ }
236
+ this._stack.push(pending);
237
+ pending.onEnter?.(data);
238
+ }
239
+ this._transitionState = this._transition.start("in");
240
+ } else {
241
+ this._transitionState = null;
242
+ }
243
+ }
244
+ this.current?.onUpdate?.(dt);
245
+ this.current?.onDraw?.();
246
+ }
247
+ };
248
+ export {
249
+ SceneManager,
250
+ fadeTransition,
251
+ noneTransition,
252
+ slideTransition
253
+ };
254
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/transition.ts","../src/scene-manager.ts"],"sourcesContent":["import type { EasingFn } from '@flare-engine/math';\n\nexport type { EasingFn };\n\n/** Slide direction — where the outgoing scene moves off-screen to. */\nexport type SlideDirection = 'left' | 'right' | 'up' | 'down';\n\n/** Transition state during a scene switch. */\nexport interface TransitionState {\n /** Progress 0 → 1. */\n progress: number;\n /** Whether the transition is complete. */\n done: boolean;\n /** Phase: 'out' = leaving scene fading out, 'in' = entering scene fading in. */\n phase: 'out' | 'in';\n}\n\n/** A transition controls the visual blending between two scenes. */\nexport interface Transition {\n /** Discriminator for consumers that apply a visual effect (alpha, translate, etc.). */\n readonly kind: 'none' | 'fade' | 'slide';\n\n /** Duration in seconds for each phase (out + in). */\n readonly duration: number;\n\n /** For slide transitions, the direction the outgoing scene slides toward. */\n readonly direction?: SlideDirection;\n\n /** Start the transition. */\n start(phase: 'out' | 'in'): TransitionState;\n\n /** Update the transition by dt seconds. Returns the updated state. */\n update(state: TransitionState, dt: number): TransitionState;\n}\n\nconst identity: EasingFn = (t) => t;\n\n/**\n * Returns a stateful advance function that tracks raw (linear) progress in its\n * own closure so the easing function is applied without accumulating drift.\n * Call `reset()` when starting a new transition phase.\n */\nfunction makeAdvancer(duration: number, easing: EasingFn) {\n let raw = 0;\n return {\n reset() {\n raw = 0;\n },\n advance(state: TransitionState, dt: number): TransitionState {\n if (state.done) return state;\n raw += dt / duration;\n if (raw >= 1) {\n raw = 1;\n state.progress = 1;\n state.done = true;\n } else {\n state.progress = easing(raw);\n }\n return state;\n },\n };\n}\n\n/** No transition — instant scene switch. */\nexport function noneTransition(): Transition {\n return {\n kind: 'none',\n duration: 0,\n start(phase) {\n return { progress: 1, done: true, phase };\n },\n update(state) {\n state.progress = 1;\n state.done = true;\n return state;\n },\n };\n}\n\n/** Fade transition — consumer interprets `progress` as alpha. */\nexport function fadeTransition(duration = 0.3, easing: EasingFn = identity): Transition {\n const advancer = makeAdvancer(duration, easing);\n return {\n kind: 'fade',\n duration,\n start(phase) {\n advancer.reset();\n return { progress: 0, done: false, phase };\n },\n update(state, dt) {\n return advancer.advance(state, dt);\n },\n };\n}\n\n/**\n * Slide transition — consumer interprets `progress` as a 0→1 offset along `direction`.\n * Default direction is 'left' (outgoing scene slides off to the left, incoming enters from the right).\n */\nexport function slideTransition(\n duration = 0.3,\n direction: SlideDirection = 'left',\n easing: EasingFn = identity,\n): Transition {\n const advancer = makeAdvancer(duration, easing);\n return {\n kind: 'slide',\n duration,\n direction,\n start(phase) {\n advancer.reset();\n return { progress: 0, done: false, phase };\n },\n update(state, dt) {\n return advancer.advance(state, dt);\n },\n };\n}\n","import { World } from '@flare-engine/ecs';\nimport { Camera2D } from '@flare-engine/render';\nimport type { Scene, SceneFactory } from './scene.js';\nimport type { Transition, TransitionState } from './transition.js';\nimport { noneTransition } from './transition.js';\n\n/**\n * SceneManager — manages scene registration, navigation, and a scene stack.\n *\n * - `register(name, factory)` — register a scene factory\n * - `go(name, data?)` — switch to a scene (clears the stack)\n * - `push(name, data?)` — push a scene onto the stack (pauses current)\n * - `pop()` — pop the top scene and resume the one below\n * - `update(dt)` — update the active scene and any active transition\n */\nexport class SceneManager {\n private _factories = new Map<string, SceneFactory>();\n private _scenes = new Map<string, Scene>();\n private _initialized = new Set<string>();\n private _stack: Scene[] = [];\n private _transition: Transition = noneTransition();\n private _transitionState: TransitionState | null = null;\n private _pendingScene: Scene | null = null;\n private _pendingData: unknown = undefined;\n\n /** The currently active scene (top of stack). */\n get current(): Scene | undefined {\n return this._stack.length > 0 ? this._stack[this._stack.length - 1] : undefined;\n }\n\n /** Number of scenes on the stack. */\n get stackSize(): number {\n return this._stack.length;\n }\n\n /** Whether a transition is currently in progress. */\n get isTransitioning(): boolean {\n return this._transitionState !== null;\n }\n\n /** Set the default transition for scene switches. */\n setTransition(transition: Transition): void {\n this._transition = transition;\n }\n\n /** Register a scene factory by name. */\n register(name: string, factory: SceneFactory): void {\n this._factories.set(name, factory);\n }\n\n /**\n * Navigate to a scene by name. Clears the entire stack.\n * Calls onExit on the current scene, onDestroy on all stacked scenes,\n * then onPreload → onInit → onEnter on the new scene.\n */\n async go(name: string, data?: unknown): Promise<void> {\n const scene = this._getOrCreate(name);\n if (!scene) return;\n\n if (this._transition.duration > 0 && this.current) {\n // Animated transition\n this._pendingScene = scene;\n this._pendingData = data;\n this._transitionState = this._transition.start('out');\n } else {\n // Instant transition\n this._exitAndDestroyCurrent();\n await this._activateScene(scene, data);\n }\n }\n\n /**\n * Push a scene onto the stack. The current scene gets onExit.\n * The new scene gets onPreload → onInit → onEnter.\n */\n async push(name: string, data?: unknown): Promise<void> {\n const scene = this._getOrCreate(name);\n if (!scene) return;\n\n this.current?.onExit?.();\n await this._initIfNeeded(scene);\n this._stack.push(scene);\n scene.onEnter?.(data);\n }\n\n /** Pop the top scene. Calls onExit + onDestroy on it, onEnter on the one below. */\n pop(): void {\n if (this._stack.length <= 1) return;\n\n const top = this._stack.pop()!;\n top.onExit?.();\n top.onDestroy?.();\n this._scenes.delete(top.name);\n this._initialized.delete(top.name);\n\n this.current?.onEnter?.();\n }\n\n /** Update the active scene and any active transition. */\n update(dt: number): void {\n if (this._transitionState) {\n this._updateTransition(dt);\n return;\n }\n\n const scene = this.current;\n if (scene) {\n scene.onUpdate?.(dt);\n scene.onDraw?.();\n }\n }\n\n /** Destroy all scenes and clear state. */\n destroy(): void {\n for (let i = this._stack.length - 1; i >= 0; i--) {\n const scene = this._stack[i]!;\n scene.onExit?.();\n scene.onDestroy?.();\n }\n this._stack.length = 0;\n this._scenes.clear();\n this._initialized.clear();\n this._transitionState = null;\n this._pendingScene = null;\n }\n\n /** Get the transition progress (0–1) for rendering. 0 during 'out', 1 when done. */\n get transitionProgress(): number {\n if (!this._transitionState) return 0;\n return this._transitionState.progress;\n }\n\n /** Get the current transition phase. */\n get transitionPhase(): 'out' | 'in' | null {\n return this._transitionState?.phase ?? null;\n }\n\n private _getOrCreate(name: string): Scene | null {\n let scene = this._scenes.get(name);\n if (scene) return scene;\n\n const factory = this._factories.get(name);\n if (!factory) return null;\n\n scene = factory();\n // Inject World and Camera\n scene.world = new World();\n scene.camera = new Camera2D();\n this._scenes.set(name, scene);\n return scene;\n }\n\n private async _initIfNeeded(scene: Scene): Promise<void> {\n if (this._initialized.has(scene.name)) return;\n this._initialized.add(scene.name);\n await scene.onPreload?.();\n scene.onInit?.();\n }\n\n private async _activateScene(scene: Scene, data?: unknown): Promise<void> {\n // Destroy all stacked scenes\n for (let i = this._stack.length - 1; i >= 0; i--) {\n const s = this._stack[i]!;\n s.onExit?.();\n s.onDestroy?.();\n this._scenes.delete(s.name);\n this._initialized.delete(s.name);\n }\n this._stack.length = 0;\n\n await this._initIfNeeded(scene);\n this._stack.push(scene);\n scene.onEnter?.(data);\n }\n\n private _exitAndDestroyCurrent(): void {\n for (let i = this._stack.length - 1; i >= 0; i--) {\n const s = this._stack[i]!;\n s.onExit?.();\n s.onDestroy?.();\n this._scenes.delete(s.name);\n this._initialized.delete(s.name);\n }\n this._stack.length = 0;\n }\n\n private _updateTransition(dt: number): void {\n if (!this._transitionState) return;\n\n this._transition.update(this._transitionState, dt);\n\n if (this._transitionState.done) {\n if (this._transitionState.phase === 'out') {\n // Phase 'out' done — switch scenes, start 'in' phase\n const pending = this._pendingScene;\n const data = this._pendingData;\n this._pendingScene = null;\n this._pendingData = undefined;\n\n if (pending) {\n // Destroy current stack\n for (let i = this._stack.length - 1; i >= 0; i--) {\n const s = this._stack[i]!;\n s.onExit?.();\n s.onDestroy?.();\n this._scenes.delete(s.name);\n this._initialized.delete(s.name);\n }\n this._stack.length = 0;\n\n // Init and activate pending scene synchronously for transitions\n this._scenes.set(pending.name, pending);\n if (!this._initialized.has(pending.name)) {\n this._initialized.add(pending.name);\n pending.onPreload?.();\n pending.onInit?.();\n }\n this._stack.push(pending);\n pending.onEnter?.(data);\n }\n\n this._transitionState = this._transition.start('in');\n } else {\n // Phase 'in' done — transition complete\n this._transitionState = null;\n }\n }\n\n // Still update the current scene during transition\n this.current?.onUpdate?.(dt);\n this.current?.onDraw?.();\n }\n}\n"],"mappings":";AAmCA,IAAM,WAAqB,CAAC,MAAM;AAOlC,SAAS,aAAa,UAAkB,QAAkB;AACxD,MAAI,MAAM;AACV,SAAO;AAAA,IACL,QAAQ;AACN,YAAM;AAAA,IACR;AAAA,IACA,QAAQ,OAAwB,IAA6B;AAC3D,UAAI,MAAM,KAAM,QAAO;AACvB,aAAO,KAAK;AACZ,UAAI,OAAO,GAAG;AACZ,cAAM;AACN,cAAM,WAAW;AACjB,cAAM,OAAO;AAAA,MACf,OAAO;AACL,cAAM,WAAW,OAAO,GAAG;AAAA,MAC7B;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAGO,SAAS,iBAA6B;AAC3C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,IACV,MAAM,OAAO;AACX,aAAO,EAAE,UAAU,GAAG,MAAM,MAAM,MAAM;AAAA,IAC1C;AAAA,IACA,OAAO,OAAO;AACZ,YAAM,WAAW;AACjB,YAAM,OAAO;AACb,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAGO,SAAS,eAAe,WAAW,KAAK,SAAmB,UAAsB;AACtF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,EACzB;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@flare-engine/scene",
3
+ "version": "0.1.0",
4
+ "description": "Scene manager, transitions, lifecycle",
5
+ "keywords": ["flare-engine", "scene", "transitions"],
6
+ "license": "MIT",
7
+ "author": "Grzegorz Otto",
8
+ "homepage": "https://github.com/grzott/flare-engine#readme",
9
+ "bugs": {
10
+ "url": "https://github.com/grzott/flare-engine/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/grzott/flare-engine.git",
15
+ "directory": "packages/scene"
16
+ },
17
+ "main": "dist/index.js",
18
+ "module": "dist/index.mjs",
19
+ "types": "dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.mjs",
24
+ "require": "./dist/index.js"
25
+ }
26
+ },
27
+ "files": ["dist", "README.md", "LICENSE"],
28
+ "scripts": {
29
+ "build": "tsup",
30
+ "test": "bun test",
31
+ "lint": "biome check src/",
32
+ "typecheck": "tsc --noEmit"
33
+ },
34
+ "dependencies": {
35
+ "@flare-engine/core": "^0.1.0",
36
+ "@flare-engine/ecs": "^0.1.0",
37
+ "@flare-engine/events": "^0.1.0",
38
+ "@flare-engine/math": "^0.1.0",
39
+ "@flare-engine/render": "^0.1.0"
40
+ },
41
+ "publishConfig": {
42
+ "access": "restricted",
43
+ "registry": "https://registry.npmjs.org/"
44
+ },
45
+ "sideEffects": false
46
+ }