@flare-engine/scene 0.2.1 → 0.3.1

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/dist/index.d.ts CHANGED
@@ -1,59 +1,60 @@
1
- import { World } from '@flare-engine/ecs';
2
- import { Camera2D } from '@flare-engine/render';
3
- import { EasingFn } from '@flare-engine/math';
4
-
1
+ import { World } from "@flare-engine/ecs";
2
+ import { Camera2D } from "@flare-engine/render";
3
+ import { EasingFn } from "@flare-engine/math";
4
+ //#region src/scene.d.ts
5
5
  /**
6
6
  * Scene lifecycle hooks. All methods are optional.
7
7
  * A scene owns its own ECS World and Camera2D.
8
8
  */
9
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;
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
30
  }
31
31
  /** Factory function type for creating scenes. */
32
32
  type SceneFactory = () => Scene;
33
-
33
+ //#endregion
34
+ //#region src/transition.d.ts
34
35
  /** Slide direction — where the outgoing scene moves off-screen to. */
35
36
  type SlideDirection = 'left' | 'right' | 'up' | 'down';
36
37
  /** Transition state during a scene switch. */
37
38
  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';
39
+ /** Progress 0 → 1. */
40
+ progress: number;
41
+ /** Whether the transition is complete. */
42
+ done: boolean;
43
+ /** Phase: 'out' = leaving scene fading out, 'in' = entering scene fading in. */
44
+ phase: 'out' | 'in';
44
45
  }
45
46
  /** A transition controls the visual blending between two scenes. */
46
47
  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;
48
+ /** Discriminator for consumers that apply a visual effect (alpha, translate, etc.). */
49
+ readonly kind: 'none' | 'fade' | 'slide';
50
+ /** Duration in seconds for each phase (out + in). */
51
+ readonly duration: number;
52
+ /** For slide transitions, the direction the outgoing scene slides toward. */
53
+ readonly direction?: SlideDirection;
54
+ /** Start the transition. */
55
+ start(phase: 'out' | 'in'): TransitionState;
56
+ /** Update the transition by dt seconds. Returns the updated state. */
57
+ update(state: TransitionState, dt: number): TransitionState;
57
58
  }
58
59
  /** No transition — instant scene switch. */
59
60
  declare function noneTransition(): Transition;
@@ -64,7 +65,8 @@ declare function fadeTransition(duration?: number, easing?: EasingFn): Transitio
64
65
  * Default direction is 'left' (outgoing scene slides off to the left, incoming enters from the right).
65
66
  */
66
67
  declare function slideTransition(duration?: number, direction?: SlideDirection, easing?: EasingFn): Transition;
67
-
68
+ //#endregion
69
+ //#region src/scene-manager.d.ts
68
70
  /**
69
71
  * SceneManager — manages scene registration, navigation, and a scene stack.
70
72
  *
@@ -75,50 +77,54 @@ declare function slideTransition(duration?: number, direction?: SlideDirection,
75
77
  * - `update(dt)` — update the active scene and any active transition
76
78
  */
77
79
  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;
80
+ private _factories;
81
+ private _scenes;
82
+ private _initialized;
83
+ private _stack;
84
+ private _transition;
85
+ private _transitionState;
86
+ private _pendingScene;
87
+ private _pendingData;
88
+ private _preloadResolved;
89
+ private _preloadGen;
90
+ /** The currently active scene (top of stack). */
91
+ get current(): Scene | undefined;
92
+ /** Number of scenes on the stack. */
93
+ get stackSize(): number;
94
+ /** Whether a transition is currently in progress. */
95
+ get isTransitioning(): boolean;
96
+ /** Set the default transition for scene switches. */
97
+ setTransition(transition: Transition): void;
98
+ /** Register a scene factory by name. */
99
+ register(name: string, factory: SceneFactory): void;
100
+ /**
101
+ * Navigate to a scene by name. Clears the entire stack.
102
+ * Calls onExit on the current scene, onDestroy on all stacked scenes,
103
+ * then onPreload → onInit → onEnter on the new scene.
104
+ */
105
+ go(name: string, data?: unknown): Promise<void>;
106
+ /**
107
+ * Push a scene onto the stack. The current scene gets onExit.
108
+ * The new scene gets onPreload → onInit → onEnter.
109
+ */
110
+ push(name: string, data?: unknown): Promise<void>;
111
+ /** Pop the top scene. Calls onExit + onDestroy on it, onEnter on the one below. */
112
+ pop(): void;
113
+ /** Update the active scene and any active transition. */
114
+ update(dt: number): void;
115
+ /** Destroy all scenes and clear state. */
116
+ destroy(): void;
117
+ /** Get the transition progress (0–1) for rendering. 0 during 'out', 1 when done. */
118
+ get transitionProgress(): number;
119
+ /** Get the current transition phase. */
120
+ get transitionPhase(): 'out' | 'in' | null;
121
+ private _getOrCreate;
122
+ private _initIfNeeded;
123
+ private _activateScene;
124
+ private _exitAndDestroyCurrent;
125
+ private _finishOutPhase;
126
+ private _updateTransition;
122
127
  }
123
-
128
+ //#endregion
124
129
  export { type Scene, type SceneFactory, SceneManager, type SlideDirection, type Transition, type TransitionState, fadeTransition, noneTransition, slideTransition };
130
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/scene.ts","../src/transition.ts","../src/scene-manager.ts"],"mappings":";;;;;;;;UAOiB;;WAEN;;EAGT,OAAO;;EAGP,QAAQ;;EAGR,qBAAqB;;EAGrB;;EAGA,SAAS;;EAGT,UAAU;;EAGV;;EAGA;;EAGA;;;KAIU,qBAAqB;;;;KCnCrB;;UAGK;;EAEf;;EAEA;;EAEA;;;UAIe;;WAEN;;WAGA;;WAGA,YAAY;;EAGrB,MAAM,sBAAsB;;EAG5B,OAAO,OAAO,iBAAiB,aAAa;;;iBAgC9B,kBAAkB;;iBAgBlB,eAAe,mBAAgB,SAAQ,WAAsB;;;;;iBAmB7D,gBACd,mBACA,YAAW,gBACX,SAAQ,WACP;;;;;;;;;;;;cCtFU;UACH;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;MAGJ,WAAW;;MAKX;;MAKA;;EAKJ,cAAc,YAAY;;EAK1B,SAAS,cAAc,SAAS;;;;;;EAS1B,GAAG,cAAc,iBAAiB;;;;;EA4DlC,KAAK,cAAc,iBAAiB;;EAW1C;;EAaA,OAAO;;EAcP;;MAcI;;MAMA;UAII;UAeM;UAOA;UAgBN;UAWA;UA6BA"}