@skewedaspect/sage 0.6.1 → 0.7.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.
@@ -4,6 +4,7 @@ import { SceneEngine } from "../engines/scene.d.ts";
4
4
  import { BindingManager } from "../managers/binding.d.ts";
5
5
  import { GameManager } from "../managers/game.d.ts";
6
6
  import { GameEntityManager } from "../managers/entity.d.ts";
7
+ import { LevelManager } from "../managers/level.d.ts";
7
8
  import { UserInputManager } from "../managers/input.d.ts";
8
9
  import { GameEventBus } from "./eventBus.d.ts";
9
10
  import { LoggingUtility } from "../utils/logger.d.ts";
@@ -25,6 +26,7 @@ interface Managers {
25
26
  gameManager: GameManager;
26
27
  entityManager: GameEntityManager;
27
28
  inputManager: UserInputManager;
29
+ levelManager: LevelManager;
28
30
  }
29
31
  /**
30
32
  * Class representing the SkewedAspect Game Engine.
@@ -0,0 +1,60 @@
1
+ import { Scene } from '@babylonjs/core';
2
+ import { LoggerInterface } from "../interfaces/logger.d.ts";
3
+ import { SceneEngine } from "../engines/scene.d.ts";
4
+ import { GameEventBus } from "./eventBus.d.ts";
5
+ export interface LevelProgressEvent {
6
+ type: 'level:progress' | 'level:complete' | 'level:error';
7
+ levelName: string;
8
+ progress?: number;
9
+ message?: string;
10
+ error?: any;
11
+ }
12
+ /**
13
+ * Abstract base class for game levels.
14
+ * Levels are responsible for creating and configuring their own scenes.
15
+ */
16
+ export declare abstract class Level {
17
+ protected _name: string;
18
+ protected _sceneEngine?: SceneEngine;
19
+ protected _eventBus?: GameEventBus;
20
+ protected _scene: Scene | null;
21
+ protected _log: LoggerInterface;
22
+ constructor(name: string);
23
+ /**
24
+ * The name of this level
25
+ */
26
+ get name(): string;
27
+ /**
28
+ * The current scene for this level (null if not loaded)
29
+ */
30
+ get scene(): Scene | null;
31
+ /**
32
+ * Whether this level has been loaded
33
+ */
34
+ get isLoaded(): boolean;
35
+ /**
36
+ * Emit a progress event during loading
37
+ */
38
+ protected _emitProgress(progress: number, message: string): void;
39
+ /**
40
+ * Load and create the scene for this level.
41
+ * Progress events will be emitted during loading.
42
+ *
43
+ * @param eventBus - The game event bus for publishing events
44
+ * @param sceneEngine - The scene engine used to create the scene
45
+ *
46
+ * @returns Promise that resolves to the loaded scene
47
+ */
48
+ loadScene(eventBus: GameEventBus, sceneEngine: SceneEngine): Promise<Scene>;
49
+ /**
50
+ * Abstract method for building the scene content.
51
+ * Concrete levels must implement this to create their specific content.
52
+ *
53
+ * @returns Promise that resolves to the created scene
54
+ */
55
+ protected abstract buildScene(): Promise<Scene>;
56
+ /**
57
+ * Dispose of this level's resources
58
+ */
59
+ dispose(): void;
60
+ }
@@ -1,13 +1,166 @@
1
- import { AbstractEngine, HavokPlugin, Scene } from '@babylonjs/core';
1
+ import { AbstractEngine, AbstractMesh, AssetContainer, DirectionalLight, FreeCamera, HavokPlugin, HemisphericLight, Light, Mesh, PhysicsAggregate, PhysicsShapeType, PointLight, Scene, Sound, SpotLight, Vector3 } from '@babylonjs/core';
2
2
  import { GameCanvas } from "../interfaces/game.d.ts";
3
3
  import { LoggingUtility } from "../utils/logger.d.ts";
4
4
  export declare class SceneEngine {
5
+ private _canvas;
5
6
  private _engine;
6
7
  private _physics;
7
8
  private _log;
8
- constructor(engine: AbstractEngine, physics: HavokPlugin, logger?: LoggingUtility);
9
- private _buildDemoScene;
10
- loadScene(canvas: GameCanvas): Promise<Scene>;
9
+ constructor(canvas: GameCanvas, engine: AbstractEngine, physics: HavokPlugin, logger?: LoggingUtility);
10
+ /**
11
+ * Creates a new scene with physics enabled
12
+ * @returns A new Scene instance with physics enabled
13
+ */
14
+ createScene(): Scene;
15
+ enablePhysics(scene: Scene, gravityVector?: Vector3): void;
16
+ /**
17
+ * Creates a free camera at the specified position
18
+ * @param name - The name for the camera
19
+ * @param position - The position of the camera
20
+ * @param scene - The scene to add the camera to
21
+ * @param canvas - The canvas to attach the camera controls to
22
+ * @returns A new FreeCamera instance
23
+ */
24
+ createFreeCamera(name: string, position: Vector3, scene: Scene, canvas?: GameCanvas): FreeCamera;
25
+ /**
26
+ * Creates a hemispheric light (ambient lighting)
27
+ * @param name - The name for the light
28
+ * @param direction - The direction of the light
29
+ * @param scene - The scene to add the light to
30
+ * @param intensity - The intensity of the light (default: 0.7)
31
+ * @returns A new HemisphericLight instance
32
+ */
33
+ createHemisphericLight(name: string, direction: Vector3, scene: Scene, intensity?: number): HemisphericLight;
34
+ /**
35
+ * Creates a directional light (sun-like lighting)
36
+ * @param name - The name for the light
37
+ * @param direction - The direction of the light
38
+ * @param scene - The scene to add the light to
39
+ * @param intensity - The intensity of the light (default: 1.0)
40
+ * @returns A new DirectionalLight instance
41
+ */
42
+ createDirectionalLight(name: string, direction: Vector3, scene: Scene, intensity?: number): DirectionalLight;
43
+ /**
44
+ * Creates a point light (bulb-like lighting)
45
+ * @param name - The name for the light
46
+ * @param position - The position of the light
47
+ * @param scene - The scene to add the light to
48
+ * @param intensity - The intensity of the light (default: 1.0)
49
+ * @returns A new PointLight instance
50
+ */
51
+ createPointLight(name: string, position: Vector3, scene: Scene, intensity?: number): PointLight;
52
+ /**
53
+ * Creates a spot light (flashlight-like lighting)
54
+ * @param name - The name for the light
55
+ * @param position - The position of the light
56
+ * @param direction - The direction of the light
57
+ * @param angle - The angle of the light cone
58
+ * @param exponent - The exponent of the light falloff
59
+ * @param scene - The scene to add the light to
60
+ * @param intensity - The intensity of the light (default: 1.0)
61
+ * @returns A new SpotLight instance
62
+ */
63
+ createSpotLight(name: string, position: Vector3, direction: Vector3, angle: number, exponent: number, scene: Scene, intensity?: number): SpotLight;
64
+ /**
65
+ * Creates a sphere mesh
66
+ * @param name - The name for the mesh
67
+ * @param options - Options for creating the sphere
68
+ * @param scene - The scene to add the mesh to
69
+ * @returns A new sphere Mesh instance
70
+ */
71
+ createSphere(name: string, options: {
72
+ diameter?: number;
73
+ segments?: number;
74
+ } | undefined, scene: Scene): Mesh;
75
+ /**
76
+ * Creates a box mesh
77
+ * @param name - The name for the mesh
78
+ * @param options - Options for creating the box
79
+ * @param scene - The scene to add the mesh to
80
+ * @returns A new box Mesh instance
81
+ */
82
+ createBox(name: string, options: {
83
+ size?: number;
84
+ width?: number;
85
+ height?: number;
86
+ depth?: number;
87
+ } | undefined, scene: Scene): Mesh;
88
+ /**
89
+ * Creates a ground mesh
90
+ * @param name - The name for the mesh
91
+ * @param options - Options for creating the ground
92
+ * @param scene - The scene to add the mesh to
93
+ * @returns A new ground Mesh instance
94
+ */
95
+ createGround(name: string, options: {
96
+ width?: number;
97
+ height?: number;
98
+ subdivisions?: number;
99
+ } | undefined, scene: Scene): Mesh;
100
+ /**
101
+ * Creates a cylinder mesh
102
+ * @param name - The name for the mesh
103
+ * @param options - Options for creating the cylinder
104
+ * @param scene - The scene to add the mesh to
105
+ * @returns A new cylinder Mesh instance
106
+ */
107
+ createCylinder(name: string, options: {
108
+ height?: number;
109
+ diameterTop?: number;
110
+ diameterBottom?: number;
111
+ } | undefined, scene: Scene): Mesh;
112
+ /**
113
+ * Adds physics to a mesh
114
+ * @param mesh - The mesh to add physics to
115
+ * @param shapeType - The physics shape type
116
+ * @param physicsProps - The physics properties (mass, restitution, etc.)
117
+ * @param scene - The scene the mesh belongs to
118
+ * @returns A new PhysicsAggregate instance
119
+ */
120
+ addPhysics(mesh: Mesh, shapeType: PhysicsShapeType, physicsProps: {
121
+ mass?: number;
122
+ restitution?: number;
123
+ friction?: number;
124
+ } | undefined, scene: Scene): PhysicsAggregate;
125
+ /**
126
+ * Creates and loads a sound
127
+ * @param name - The name for the sound
128
+ * @param url - The URL or file path of the sound
129
+ * @param scene - The scene to add the sound to
130
+ * @param options - Additional sound options
131
+ * @returns A new Sound instance
132
+ */
133
+ createSound(name: string, url: string, scene: Scene, options?: {
134
+ loop?: boolean;
135
+ autoplay?: boolean;
136
+ volume?: number;
137
+ playbackRate?: number;
138
+ }): Sound;
139
+ /**
140
+ * Loads a 3D model/asset from a file
141
+ * @param rootUrl - The root URL where the file is located
142
+ * @param sceneFilename - The filename of the scene file
143
+ * @param scene - The scene to load the model into
144
+ * @returns Promise that resolves with the loaded AssetContainer
145
+ */
146
+ loadModel(rootUrl: string, sceneFilename: string, scene: Scene): Promise<AssetContainer>;
147
+ /**
148
+ * Imports meshes from a file
149
+ * @param meshNames - Array of mesh names to import (empty array imports all)
150
+ * @param rootUrl - The root URL where the file is located
151
+ * @param sceneFilename - The filename of the scene file
152
+ * @param scene - The scene to import the meshes into
153
+ * @returns Promise that resolves with the import result
154
+ */
155
+ importMeshes(meshNames: string[], rootUrl: string, sceneFilename: string, scene: Scene): Promise<{
156
+ meshes: AbstractMesh[];
157
+ particleSystems: any[];
158
+ skeletons: any[];
159
+ animationGroups: any[];
160
+ transformNodes: any[];
161
+ geometries: any[];
162
+ lights: Light[];
163
+ }>;
11
164
  /**
12
165
  * Tears down the scene engine and cleans up any resources
13
166
  */
@@ -1,22 +1,21 @@
1
- import { AbstractEngine } from '@babylonjs/core';
2
- import { GameCanvas } from "../interfaces/game.d.ts";
1
+ import { AbstractEngine, Scene } from '@babylonjs/core';
3
2
  import { GameEntityManager } from "./entity.d.ts";
3
+ import { LevelManager } from "./level.d.ts";
4
4
  import { UserInputManager } from "./input.d.ts";
5
- import { SceneEngine } from "../engines/scene.d.ts";
6
5
  import { LoggingUtility } from "../utils/logger.d.ts";
7
6
  export declare class GameManager {
8
7
  private _engine;
9
8
  private _entityManager;
10
9
  private _inputManager;
11
- private _sceneEngine;
12
- private _currentScene;
10
+ private _levelManager;
13
11
  private _log;
14
12
  private _boundResizeHandler;
15
13
  started: boolean;
16
- constructor(engine: AbstractEngine, sceneEngine: SceneEngine, entityManager: GameEntityManager, inputManager: UserInputManager, logger?: LoggingUtility);
14
+ constructor(engine: AbstractEngine, entityManager: GameEntityManager, inputManager: UserInputManager, levelManager: LevelManager, logger?: LoggingUtility);
15
+ get currentScene(): Scene | null;
17
16
  private _renderLoop;
18
17
  private _resizeHandler;
19
- start(canvas: GameCanvas): Promise<void>;
18
+ start(): Promise<void>;
20
19
  stop(): Promise<void>;
21
20
  /**
22
21
  * Tears down any resources held by the GameManager
@@ -1,58 +1,54 @@
1
- import { Engine, Scene } from '@babylonjs/core';
2
- import { GameEntityManager } from "./entity.d.ts";
3
- export interface LevelLoadOptions {
4
- rootUrl: string;
5
- filename: string;
6
- useAssetContainer?: boolean;
7
- showLoadingUI?: boolean;
8
- onProgress?: (percent: number) => void;
9
- onSuccess?: (scene: Scene) => void;
10
- onError?: (message: string, exception?: any) => void;
11
- }
12
- /**
1
+ import { Level } from "../classes/level.d.ts";
2
+ import { GameEventBus } from "../classes/eventBus.d.ts";
3
+ import { SceneEngine } from "../engines/scene.d.ts";
4
+ import { LoggingUtility } from "../utils/logger.d.ts";
13
5
  /**
14
- * Manages level loading and streaming using BabylonJS SceneLoader and AssetContainer.
15
- * Also includes tagging for auto-detection (e.g. "Door", "Trigger", "Enemy"),
16
- * and automatically spawns entities via an entity manager if an 'entityType' is found.
17
- *
18
- * Additionally, this version checks for audio metadata (e.g. sound files) and automatically
19
- * creates BabylonJS Sound objects when found.
6
+ * Manages game levels, tracking loaded levels and the current active scene.
7
+ * Provides centralized access to level functionality and scene management.
20
8
  */
21
9
  export declare class LevelManager {
22
- private engine;
23
- private currentScene;
24
- private activeContainer;
25
- private entityManager;
26
- constructor(engine: Engine, entityManager: GameEntityManager);
10
+ private _eventBus;
11
+ private _sceneEngine;
12
+ private _log;
13
+ /** Map of registered levels by name */
14
+ private _registeredLevels;
15
+ /** The currently active level */
16
+ private _currentLevel;
17
+ constructor(eventBus: GameEventBus, sceneEngine: SceneEngine, logger?: LoggingUtility);
27
18
  /**
28
- * Loads a level, either as a full scene or into a container.
29
- * @param options - Specifies rootUrl, filename, and optional callbacks.
19
+ * Handles level events from the event bus
30
20
  */
31
- loadLevel(options: LevelLoadOptions): Promise<void>;
21
+ private _handleLevelEvent;
32
22
  /**
33
- * Disposes the current scene and container (if any), freeing up memory.
23
+ * Registers a level class that can be instantiated later
24
+ * @param name - The name to register the level under
25
+ * @param level - The level class instance
34
26
  */
35
- disposeCurrentScene(): void;
27
+ registerLevel(name: string, level: Level): void;
36
28
  /**
37
- * Tears down the level manager and cleans up any resources
29
+ * Loads and activates a level by name
30
+ * @param levelName - The name of the level to load
31
+ * @returns Promise that resolves when the level is loaded
38
32
  */
39
- $teardown(): Promise<void>;
33
+ loadLevel(levelName: string): Promise<void>;
34
+ /**
35
+ * Gets the currently active level
36
+ */
37
+ get currentLevel(): Level | null;
40
38
  /**
41
- * Returns the current active scene, if one is loaded.
39
+ * Gets a loaded level by name
42
40
  */
43
- getScene(): Scene | null;
41
+ getLevel(name: string): Level | null;
44
42
  /**
45
- * Internal helper: Reports loading progress as a percentage.
46
- * @param evt ISceneLoaderProgressEvent data
47
- * @param callback optional progress callback
43
+ * Unloads a level and disposes its resources
48
44
  */
49
- private reportProgress;
45
+ unloadLevel(name: string): void;
50
46
  /**
51
- * Automatically tag loaded meshes and create entities based on metadata.
52
- * Also, if audio metadata is present, create spatial sounds.
53
- *
54
- * @param meshes An array of loaded AbstractMesh objects.
55
- * @param scene The scene into which these meshes have been loaded.
47
+ * Unloads the current level and disposes its resources
56
48
  */
57
- private autoTagAndEntityHook;
49
+ unloadCurrentLevel(): void;
50
+ /**
51
+ * Tears down the level manager and cleans up any resources
52
+ */
53
+ $teardown(): Promise<void>;
58
54
  }
package/dist/sage.d.ts CHANGED
@@ -20,5 +20,6 @@ export * from "./interfaces/logger.d.ts";
20
20
  export { GameEventBus, SkewedAspectGameEngine };
21
21
  export * from "./classes/eventBus.d.ts";
22
22
  export * from "./classes/entity.d.ts";
23
+ export * from "./classes/level.d.ts";
23
24
  export * from "./utils/logger.d.ts";
24
25
  export * from "./utils/version.d.ts";