@skewedaspect/sage 0.9.5 → 0.10.0-beta.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/classes/debugConsole.d.ts +1 -0
- package/dist/classes/gameEngine.d.ts +24 -46
- package/dist/classes/gameLevel.d.ts +15 -12
- package/dist/classes/level.d.ts +5 -29
- package/dist/debug/builtins.d.ts +4 -0
- package/dist/entities/constants.d.ts +1 -0
- package/dist/entities/defineEntity.d.ts +17 -0
- package/dist/entities/entityPicking.d.ts +14 -0
- package/dist/entities/meshConfig.d.ts +14 -0
- package/dist/entities/nodeEntity.d.ts +33 -0
- package/dist/entities/nodePool.d.ts +8 -0
- package/dist/entities/nodeSimulation.d.ts +22 -0
- package/dist/entities/nodeSimulationContext.d.ts +13 -0
- package/dist/entities/standardMeshSource.d.ts +8 -0
- package/dist/events/payloads.d.ts +0 -30
- package/dist/events/types.d.ts +2 -23
- package/dist/input/actionContext.d.ts +11 -0
- package/dist/input/actionRegistry.d.ts +7 -0
- package/dist/input/binding.d.ts +31 -0
- package/dist/input/bindings/toggle.d.ts +21 -0
- package/dist/input/bindings/trigger.d.ts +19 -0
- package/dist/input/bindings/value.d.ts +23 -0
- package/dist/input/configuration.d.ts +15 -0
- package/dist/input/deliverAction.d.ts +3 -0
- package/dist/input/deviceReader.d.ts +5 -0
- package/dist/input/deviceReaders/gamepad.d.ts +9 -0
- package/dist/input/deviceReaders/keyboard.d.ts +8 -0
- package/dist/input/deviceReaders/mouse.d.ts +9 -0
- package/dist/input/deviceState.d.ts +19 -0
- package/dist/input/inputCapture.d.ts +21 -0
- package/dist/input/resolveBinding.d.ts +4 -0
- package/dist/interfaces/game.d.ts +20 -4
- package/dist/interfaces/level.d.ts +19 -1
- package/dist/managers/game.d.ts +8 -5
- package/dist/managers/level.d.ts +16 -4
- package/dist/managers/outline.d.ts +4 -4
- package/dist/managers/simulationSave.d.ts +30 -0
- package/dist/{postProcessingFrameGraph-CaMgQzR-.js → postProcessingFrameGraph-rr2DbgPi.js} +1 -1
- package/dist/{postProcessingFrameGraph-CaMgQzR-.js.map → postProcessingFrameGraph-rr2DbgPi.js.map} +1 -1
- package/dist/sage.d.ts +46 -16
- package/dist/sage.es.js +1441 -2470
- package/dist/sage.es.js.map +1 -1
- package/dist/sage.umd.js +1 -1
- package/dist/sage.umd.js.map +1 -1
- package/dist/utils/physics.d.ts +4 -1
- package/package.json +29 -66
- package/LICENSE +0 -21
- package/Readme.md +0 -73
- package/dist/behaviors/index.d.ts +0 -2
- package/dist/behaviors/sound.d.ts +0 -137
- package/dist/behaviors/stateMachine.d.ts +0 -76
- package/dist/classes/bindings/toggle.d.ts +0 -116
- package/dist/classes/bindings/trigger.d.ts +0 -81
- package/dist/classes/bindings/value.d.ts +0 -104
- package/dist/classes/entity.d.ts +0 -332
- package/dist/classes/input/gamepad.d.ts +0 -94
- package/dist/classes/input/keyboard.d.ts +0 -66
- package/dist/classes/input/mouse.d.ts +0 -91
- package/dist/classes/input/readers/gamepad.d.ts +0 -73
- package/dist/classes/input/readers/keyboard.d.ts +0 -56
- package/dist/classes/input/readers/mouse.d.ts +0 -41
- package/dist/interfaces/action.d.ts +0 -22
- package/dist/interfaces/binding.d.ts +0 -123
- package/dist/interfaces/entity.d.ts +0 -97
- package/dist/interfaces/input.d.ts +0 -180
- package/dist/managers/binding.d.ts +0 -233
- package/dist/managers/entity.d.ts +0 -256
- package/dist/managers/input.d.ts +0 -54
- package/dist/managers/save.d.ts +0 -75
- package/dist/utils/entityProxy.d.ts +0 -2
- package/dist/utils/raycast.d.ts +0 -26
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
import { AbstractEngine, HavokPlugin } from '@babylonjs/core';
|
|
2
|
-
import { GameCanvas } from "../interfaces/game.d.ts";
|
|
1
|
+
import { AbstractEngine, HavokPlugin, Scene } from '@babylonjs/core';
|
|
2
|
+
import { EntityMeshLoader, GameCanvas } from "../interfaces/game.d.ts";
|
|
3
3
|
import { Disposable } from "../interfaces/lifecycle.d.ts";
|
|
4
|
+
import { NodeSimulation } from "../entities/nodeSimulation.d.ts";
|
|
4
5
|
import { SceneEngine } from "../engines/scene.d.ts";
|
|
5
6
|
import { AudioEngine } from "../engines/audio.d.ts";
|
|
6
7
|
import { AssetManager } from "../managers/asset.d.ts";
|
|
7
|
-
import { BindingManager } from "../managers/binding.d.ts";
|
|
8
8
|
import { ColliderDebugManager } from "../managers/colliderDebug.d.ts";
|
|
9
9
|
import { DebugConsole } from "./debugConsole.d.ts";
|
|
10
10
|
import { GameManager } from "../managers/game.d.ts";
|
|
11
|
-
import { GameEntityManager } from "../managers/entity.d.ts";
|
|
12
11
|
import { LevelManager } from "../managers/level.d.ts";
|
|
13
|
-
import {
|
|
14
|
-
import { UserInputManager } from "../managers/input.d.ts";
|
|
12
|
+
import { SimulationSaveManager } from "../managers/simulationSave.d.ts";
|
|
15
13
|
import { AudioManager } from "../managers/audio.d.ts";
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
14
|
+
import { GameEventBus, GameEventCallback, Unsubscribe } from "./eventBus.d.ts";
|
|
15
|
+
import { LibraryEventPayloadMap } from "../events/payloads.d.ts";
|
|
18
16
|
import { WildcardPattern } from "../events/types.d.ts";
|
|
19
17
|
import { LoggingUtility } from "../utils/logger.d.ts";
|
|
20
|
-
import { RaycastHelper } from "../utils/raycast.d.ts";
|
|
21
18
|
import { GameTimer } from "../utils/timer.d.ts";
|
|
22
19
|
/**
|
|
23
20
|
* Type definition for game lifecycle hook functions
|
|
24
21
|
*/
|
|
25
22
|
export type GameHook = (gameEngine: GameEngine) => Promise<void>;
|
|
23
|
+
/** Builds a NodeSimulation bound to a scene and a mesh source -- a fresh one is built for every level that loads. */
|
|
24
|
+
export type SimulationFactory = (scene: Scene, meshSource?: EntityMeshLoader) => NodeSimulation;
|
|
26
25
|
/**
|
|
27
26
|
* Interface representing the engines used in the game.
|
|
28
27
|
* All engines must implement Disposable for proper cleanup.
|
|
@@ -37,12 +36,9 @@ interface Engines extends Record<string, Disposable | undefined> {
|
|
|
37
36
|
*/
|
|
38
37
|
interface Managers extends Record<string, Disposable | undefined> {
|
|
39
38
|
assetManager: AssetManager;
|
|
40
|
-
bindingManager: BindingManager;
|
|
41
39
|
gameManager: GameManager;
|
|
42
|
-
entityManager: GameEntityManager;
|
|
43
|
-
inputManager: UserInputManager;
|
|
44
40
|
levelManager: LevelManager;
|
|
45
|
-
saveManager:
|
|
41
|
+
saveManager: SimulationSaveManager;
|
|
46
42
|
audioManager?: AudioManager;
|
|
47
43
|
}
|
|
48
44
|
/**
|
|
@@ -65,12 +61,13 @@ export declare class GameEngine {
|
|
|
65
61
|
engines: Engines;
|
|
66
62
|
eventBus: GameEventBus;
|
|
67
63
|
logger: LoggingUtility;
|
|
68
|
-
|
|
64
|
+
simulation: NodeSimulation | null;
|
|
69
65
|
timer: GameTimer;
|
|
70
66
|
debug: DebugTools;
|
|
71
67
|
largeWorldRendering: boolean;
|
|
72
68
|
started: boolean;
|
|
73
69
|
private _log;
|
|
70
|
+
private _buildSimulation;
|
|
74
71
|
private _beforeStartHook;
|
|
75
72
|
private _onStartHook;
|
|
76
73
|
private _onTeardownHook;
|
|
@@ -81,10 +78,18 @@ export declare class GameEngine {
|
|
|
81
78
|
* @param physics
|
|
82
79
|
* @param eventBus
|
|
83
80
|
* @param logger
|
|
81
|
+
* @param timer
|
|
82
|
+
* @param buildSimulation - Builds a fresh simulation for a scene, once rebuildSimulation is called with one.
|
|
84
83
|
* @param engines
|
|
85
84
|
* @param managers
|
|
86
85
|
*/
|
|
87
|
-
constructor(canvas: GameCanvas, renderEngine: AbstractEngine, physics: HavokPlugin, eventBus: GameEventBus, logger: LoggingUtility,
|
|
86
|
+
constructor(canvas: GameCanvas, renderEngine: AbstractEngine, physics: HavokPlugin, eventBus: GameEventBus, logger: LoggingUtility, timer: GameTimer, buildSimulation: SimulationFactory, engines: Engines, managers: Managers, largeWorldRendering?: boolean, debug?: DebugTools);
|
|
87
|
+
/**
|
|
88
|
+
* Builds a fresh NodeSimulation bound to the given scene and mesh source, and swaps it in. A level calls
|
|
89
|
+
* this once its own scene is ready, so every NodeEntity it spawns gets a node in that scene and loads its
|
|
90
|
+
* mesh through that source. Left unset, a spawned entity gets a node with no mesh.
|
|
91
|
+
*/
|
|
92
|
+
rebuildSimulation(scene: Scene, meshSource?: EntityMeshLoader): NodeSimulation;
|
|
88
93
|
/**
|
|
89
94
|
* Register a function to be called before the game engine starts
|
|
90
95
|
* @param hook
|
|
@@ -108,7 +113,7 @@ export declare class GameEngine {
|
|
|
108
113
|
*
|
|
109
114
|
* This is a convenience method that forwards to `eventBus.subscribe()`.
|
|
110
115
|
*
|
|
111
|
-
* @param eventType - Exact event type string, wildcard pattern (e.g. '
|
|
116
|
+
* @param eventType - Exact event type string, wildcard pattern (e.g. 'level:*'), or RegExp
|
|
112
117
|
* @param callback
|
|
113
118
|
* @returns A function that removes this subscription when called
|
|
114
119
|
*
|
|
@@ -118,39 +123,12 @@ export declare class GameEngine {
|
|
|
118
123
|
* console.log('Level complete:', event.payload.levelName);
|
|
119
124
|
* });
|
|
120
125
|
*
|
|
121
|
-
* // Subscribe to
|
|
122
|
-
* engine.subscribe('
|
|
123
|
-
* console.log('
|
|
126
|
+
* // Subscribe to every level event
|
|
127
|
+
* engine.subscribe('level:*', (event) => {
|
|
128
|
+
* console.log('Level event:', event.type);
|
|
124
129
|
* });
|
|
125
130
|
*/
|
|
126
131
|
subscribe<T extends keyof LibraryEventPayloadMap & string>(eventType: T | WildcardPattern | RegExp, callback: GameEventCallback<T, LibraryEventPayloadMap>): Unsubscribe;
|
|
127
|
-
/**
|
|
128
|
-
* Subscribe to an action event with full type safety.
|
|
129
|
-
*
|
|
130
|
-
* Action events are fired by the binding system when inputs trigger registered actions.
|
|
131
|
-
* All action events have the same payload structure (`ActionPayload`), containing:
|
|
132
|
-
* - `value`: The action value (number for analog, boolean for digital)
|
|
133
|
-
* - `deviceId`: The ID of the input device that triggered the action
|
|
134
|
-
* - `context`: The binding context that was active (optional)
|
|
135
|
-
*
|
|
136
|
-
* @param actionName - The action name (without the 'action:' prefix)
|
|
137
|
-
* @param callback
|
|
138
|
-
* @returns A function that removes this subscription when called
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* // Subscribe to a specific action
|
|
142
|
-
* engine.subscribeAction('jump', (event) => {
|
|
143
|
-
* console.log('Jump triggered with value:', event.payload.value);
|
|
144
|
-
* console.log('From device:', event.payload.deviceId);
|
|
145
|
-
* });
|
|
146
|
-
*
|
|
147
|
-
* // Subscribe to movement action
|
|
148
|
-
* engine.subscribeAction('moveForward', (event) => {
|
|
149
|
-
* const velocity = Number(event.payload.value);
|
|
150
|
-
* player.move(velocity);
|
|
151
|
-
* });
|
|
152
|
-
*/
|
|
153
|
-
subscribeAction(actionName: string, callback: (event: GameEvent<`action:${string}`, Record<`action:${string}`, ActionPayload>>) => void): Unsubscribe;
|
|
154
132
|
/**
|
|
155
133
|
* Start the engine: runs beforeStart hook, starts the game manager, then runs onStart hook.
|
|
156
134
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Quaternion, Scene, StaticSound, TransformNode, Vector3 } from '@babylonjs/core';
|
|
2
2
|
import { LevelConfig, LevelContext } from "../interfaces/level.d.ts";
|
|
3
|
-
import {
|
|
3
|
+
import { NodeEntity } from "../entities/nodeEntity.d.ts";
|
|
4
4
|
import { Level } from "./level.d.ts";
|
|
5
5
|
/**
|
|
6
6
|
* Metadata collected from a spawn point node.
|
|
@@ -33,7 +33,7 @@ export declare class GameLevel extends Level {
|
|
|
33
33
|
/** Collected entity nodes from the scene */
|
|
34
34
|
protected _entityNodes: EntityNodeData[];
|
|
35
35
|
/** Entities spawned by this level */
|
|
36
|
-
protected _spawnedEntities:
|
|
36
|
+
protected _spawnedEntities: NodeEntity[];
|
|
37
37
|
/** Level-scoped sounds created from config */
|
|
38
38
|
protected _levelSounds: Map<string, StaticSound>;
|
|
39
39
|
/** Sounds that were playing before deactivation (for resume on activate) */
|
|
@@ -46,7 +46,7 @@ export declare class GameLevel extends Level {
|
|
|
46
46
|
*/
|
|
47
47
|
constructor(config: LevelConfig, context: LevelContext);
|
|
48
48
|
get config(): LevelConfig;
|
|
49
|
-
get spawnedEntities(): readonly
|
|
49
|
+
get spawnedEntities(): readonly NodeEntity[];
|
|
50
50
|
/**
|
|
51
51
|
* Build the scene by loading assets, processing node metadata, and spawning entities.
|
|
52
52
|
*/
|
|
@@ -124,22 +124,25 @@ export declare class GameLevel extends Level {
|
|
|
124
124
|
*/
|
|
125
125
|
private _processSpawnPoint;
|
|
126
126
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
*
|
|
127
|
+
* Spawn an entity through the simulation, inheriting position and rotation from the spawn point. The node
|
|
128
|
+
* and its mesh are the simulation's own business, built by NodeEntity's constructor from the class name and
|
|
129
|
+
* state -- the level does no mesh building of its own.
|
|
130
|
+
*
|
|
131
|
+
* A spawn point's scaling has nowhere to go: NodeEntityState declares position and rotation, not scaling,
|
|
132
|
+
* and inventing a state field for it is not this level's call to make. It is dropped.
|
|
133
133
|
*/
|
|
134
134
|
private _spawnEntity;
|
|
135
135
|
/**
|
|
136
|
-
*
|
|
136
|
+
* Match collected entity nodes against the level config's entity definitions and spawn entities adopting
|
|
137
|
+
* their marked node.
|
|
137
138
|
*/
|
|
138
139
|
private _processEntityNodes;
|
|
139
140
|
/**
|
|
140
|
-
*
|
|
141
|
+
* Spawn an entity adopting an entity marker's node. `nodeName` is the marked node's own name, written by
|
|
142
|
+
* the level rather than by configuration, since it is the binding key adoption resolves through
|
|
143
|
+
* (design/authoring.md#the-binding-key).
|
|
141
144
|
*/
|
|
142
|
-
private
|
|
145
|
+
private _spawnEntityNode;
|
|
143
146
|
/**
|
|
144
147
|
* Create level-scoped sounds from YAML config. Sounds are tracked for lifecycle management
|
|
145
148
|
* (pause on deactivate, resume on activate, dispose on unload).
|
package/dist/classes/level.d.ts
CHANGED
|
@@ -1,28 +1,14 @@
|
|
|
1
|
-
import { Color3,
|
|
1
|
+
import { Color3, Scene, TransformNode } from '@babylonjs/core';
|
|
2
2
|
import { ClusteredLightContainer } from '@babylonjs/core/Lights/Clustered/clusteredLightContainer';
|
|
3
3
|
import { LoggerInterface } from "../interfaces/logger.d.ts";
|
|
4
|
-
import { ColorConfig, LevelConfig, LevelContext, LevelInstance, PropertyHandler } from "../interfaces/level.d.ts";
|
|
5
|
-
import { GameEntity } from "./entity.d.ts";
|
|
4
|
+
import { ColorConfig, LevelConfig, LevelContext, LevelInstance, LevelLoadOptions, PropertyHandler } from "../interfaces/level.d.ts";
|
|
6
5
|
import { GameEngine } from "./gameEngine.d.ts";
|
|
7
6
|
import { OutlineManager } from "../managers/outline.d.ts";
|
|
8
|
-
/**
|
|
9
|
-
* Transform and visibility overrides applied to a mesh built by `Level.createEntityMesh()`.
|
|
10
|
-
*/
|
|
11
|
-
export interface CreateEntityMeshOptions {
|
|
12
|
-
/** World position for the entity's root node. Left at the node default when omitted. */
|
|
13
|
-
position?: Vector3;
|
|
14
|
-
/** World rotation for the entity's root node. Left at the node default when omitted. */
|
|
15
|
-
rotation?: Quaternion;
|
|
16
|
-
/** Scaling for the entity's root node. Left at the node default when omitted. */
|
|
17
|
-
scaling?: Vector3;
|
|
18
|
-
/** When false, the node is disabled immediately on creation so nothing ever renders. Default true. */
|
|
19
|
-
enabled?: boolean;
|
|
20
|
-
}
|
|
21
7
|
/**
|
|
22
8
|
* Abstract base class for game levels.
|
|
23
9
|
*
|
|
24
10
|
* Levels are responsible for creating and configuring their own scenes via the
|
|
25
|
-
* `buildScene()` method. All runtime dependencies (eventBus, sceneEngine,
|
|
11
|
+
* `buildScene()` method. All runtime dependencies (eventBus, sceneEngine, simulation)
|
|
26
12
|
* are injected via the constructor and are immediately available.
|
|
27
13
|
*
|
|
28
14
|
* Users should not instantiate Level subclasses directly. Instead, use LevelManager
|
|
@@ -41,6 +27,7 @@ export declare abstract class Level implements LevelInstance {
|
|
|
41
27
|
protected readonly _log: LoggerInterface;
|
|
42
28
|
protected readonly _context: LevelContext;
|
|
43
29
|
protected _scene: Scene | null;
|
|
30
|
+
protected _forRestore: boolean;
|
|
44
31
|
clusteredLights: ClusteredLightContainer | null;
|
|
45
32
|
outlines: OutlineManager | null;
|
|
46
33
|
/**
|
|
@@ -77,18 +64,7 @@ export declare abstract class Level implements LevelInstance {
|
|
|
77
64
|
* Load and create the scene for this level.
|
|
78
65
|
* Progress events will be emitted during loading.
|
|
79
66
|
*/
|
|
80
|
-
load(): Promise<Scene>;
|
|
81
|
-
/**
|
|
82
|
-
* Build or import a mesh from the entity definition and attach it to the entity.
|
|
83
|
-
* Supports primitive shapes (box/sphere/capsule/cylinder) and GLB/GLTF file paths.
|
|
84
|
-
*
|
|
85
|
-
* @param entity - The entity whose definition supplies the mesh spec
|
|
86
|
-
* @param options - Transform overrides and initial enabled state
|
|
87
|
-
*
|
|
88
|
-
* @returns The root node the mesh was built under, or null if the level has no scene, the definition has no
|
|
89
|
-
* mesh spec, or the GLB import produced no meshes.
|
|
90
|
-
*/
|
|
91
|
-
createEntityMesh(entity: GameEntity, options?: CreateEntityMeshOptions): Promise<TransformNode | null>;
|
|
67
|
+
load(options?: LevelLoadOptions): Promise<Scene>;
|
|
92
68
|
/**
|
|
93
69
|
* Abstract method for building the scene content.
|
|
94
70
|
* Concrete levels must implement this to create their specific content.
|
package/dist/debug/builtins.d.ts
CHANGED
|
@@ -2,5 +2,9 @@ import { DebugConsole } from "../classes/debugConsole.d.ts";
|
|
|
2
2
|
import { GameEngine } from "../classes/gameEngine.d.ts";
|
|
3
3
|
/**
|
|
4
4
|
* Registers all default references and commands onto the debug console namespace.
|
|
5
|
+
*
|
|
6
|
+
* The entity system's class table carries no behavior list on the entity itself (entities.md#the-entity-
|
|
7
|
+
* class-table), and a NodeEntity has no collider-debug method of its own -- so, unlike the 0.9 console, this
|
|
8
|
+
* has no `list(type)`, no `entities` proxy, and no `showColliders`/`hideColliders`.
|
|
5
9
|
*/
|
|
6
10
|
export declare function registerBuiltins(dc: DebugConsole, ge: GameEngine): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const poolSizeLimit = 8;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Action, BehaviorClass, StateFor, ValidTuple } from '@skewedaspect/sage-core';
|
|
2
|
+
import { NodeEntity } from "./nodeEntity.d.ts";
|
|
3
|
+
import { MeshConfig } from "./meshConfig.d.ts";
|
|
4
|
+
export interface GameEntityDefinition<Behaviors extends readonly BehaviorClass[]> {
|
|
5
|
+
type: string;
|
|
6
|
+
tags?: string[];
|
|
7
|
+
defaultState?: Partial<StateFor<Behaviors>>;
|
|
8
|
+
behaviors: Behaviors;
|
|
9
|
+
mesh?: MeshConfig;
|
|
10
|
+
actions?: readonly Action[];
|
|
11
|
+
}
|
|
12
|
+
export type GameEntityDefinitionClass<Behaviors extends readonly BehaviorClass[]> = typeof NodeEntity & {
|
|
13
|
+
readonly behaviors: Behaviors;
|
|
14
|
+
};
|
|
15
|
+
export declare function defineEntity<Behaviors extends readonly BehaviorClass[]>(definition: GameEntityDefinition<Behaviors> & {
|
|
16
|
+
behaviors: ValidTuple<Behaviors>;
|
|
17
|
+
}): GameEntityDefinitionClass<Behaviors>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Vector3, AbstractMesh, PickingInfo } from '@babylonjs/core';
|
|
2
|
+
import { GameEntity } from '@skewedaspect/sage-core';
|
|
3
|
+
import { NodeEntity } from "./nodeEntity.d.ts";
|
|
4
|
+
export interface EntityPickFilter {
|
|
5
|
+
tags?: readonly string[];
|
|
6
|
+
}
|
|
7
|
+
export interface EntityPickResult {
|
|
8
|
+
entity: NodeEntity;
|
|
9
|
+
mesh: AbstractMesh;
|
|
10
|
+
point: Vector3;
|
|
11
|
+
distance: number;
|
|
12
|
+
normal: Vector3;
|
|
13
|
+
}
|
|
14
|
+
export declare function toEntityPickResult(entities: readonly GameEntity[], info: PickingInfo | null, filter?: EntityPickFilter): EntityPickResult | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ColorConfig } from "../interfaces/level.d.ts";
|
|
2
|
+
export interface MeshMaterialConfig {
|
|
3
|
+
type?: 'standard' | 'pbr';
|
|
4
|
+
color?: ColorConfig;
|
|
5
|
+
emissive?: ColorConfig;
|
|
6
|
+
metallic?: number;
|
|
7
|
+
roughness?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface MeshConfig {
|
|
10
|
+
source: string;
|
|
11
|
+
params?: Record<string, unknown>;
|
|
12
|
+
material?: MeshMaterialConfig;
|
|
13
|
+
visible?: boolean;
|
|
14
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { TransformNode, AbstractMesh } from '@babylonjs/core';
|
|
2
|
+
import { GameEntity, Action, GameEntityState, GameSimulationContext } from '@skewedaspect/sage-core';
|
|
3
|
+
import { MeshConfig } from "./meshConfig.d.ts";
|
|
4
|
+
export interface Vector3State {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
z: number;
|
|
8
|
+
}
|
|
9
|
+
export interface QuaternionState {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
z: number;
|
|
13
|
+
w: number;
|
|
14
|
+
}
|
|
15
|
+
export interface NodeEntityState extends GameEntityState {
|
|
16
|
+
parentID?: string;
|
|
17
|
+
nodeName?: string;
|
|
18
|
+
position: Vector3State;
|
|
19
|
+
rotation: QuaternionState;
|
|
20
|
+
}
|
|
21
|
+
export declare abstract class NodeEntity extends GameEntity {
|
|
22
|
+
#private;
|
|
23
|
+
static readonly poolable: boolean;
|
|
24
|
+
static readonly poolSize?: number;
|
|
25
|
+
static readonly meshConfig?: MeshConfig;
|
|
26
|
+
static readonly actions?: readonly Action[];
|
|
27
|
+
get node(): TransformNode;
|
|
28
|
+
get mesh(): AbstractMesh | undefined;
|
|
29
|
+
set mesh(mesh: AbstractMesh | undefined);
|
|
30
|
+
protected constructor(id: string, context: GameSimulationContext, providedState: object, runCreateHooks: boolean, name?: string);
|
|
31
|
+
update(dt: number): void;
|
|
32
|
+
destroy(): void;
|
|
33
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { GameSimulationManager, GameSimulationOptions, StateBag } from '@skewedaspect/sage-core';
|
|
2
|
+
import { Camera, Ray, Scene } from '@babylonjs/core';
|
|
3
|
+
import { EntityPickFilter, EntityPickResult } from "./entityPicking.d.ts";
|
|
4
|
+
import { NodePool } from "./nodePool.d.ts";
|
|
5
|
+
import { MeshLoader, NodeSimulationContext } from "./nodeSimulationContext.d.ts";
|
|
6
|
+
export interface NodeSimulationOptions extends GameSimulationOptions {
|
|
7
|
+
scene: Scene;
|
|
8
|
+
loadMesh: MeshLoader;
|
|
9
|
+
pool: NodePool;
|
|
10
|
+
}
|
|
11
|
+
export declare class NodeSimulation extends GameSimulationManager implements NodeSimulationContext {
|
|
12
|
+
#private;
|
|
13
|
+
readonly scene: Scene;
|
|
14
|
+
readonly pool: NodePool;
|
|
15
|
+
readonly loadMesh: MeshLoader;
|
|
16
|
+
constructor(options: NodeSimulationOptions);
|
|
17
|
+
prewarm(name: string, count: number, state?: StateBag): Promise<void>;
|
|
18
|
+
pickEntityWithRay(ray: Ray, filter?: EntityPickFilter): EntityPickResult | undefined;
|
|
19
|
+
pickEntity(x: number, y: number, filter?: EntityPickFilter): EntityPickResult | undefined;
|
|
20
|
+
pickEntityForward(camera: Camera, range: number, filter?: EntityPickFilter): EntityPickResult | undefined;
|
|
21
|
+
protected buildReplacementSimulation(options: GameSimulationOptions): NodeSimulation;
|
|
22
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AbstractMesh, Scene, TransformNode } from '@babylonjs/core';
|
|
2
|
+
import { GameSimulationContext, StateBag } from '@skewedaspect/sage-core';
|
|
3
|
+
import { NodePool } from "./nodePool.d.ts";
|
|
4
|
+
export interface NodeSet {
|
|
5
|
+
node: TransformNode;
|
|
6
|
+
mesh: AbstractMesh | undefined;
|
|
7
|
+
}
|
|
8
|
+
export type MeshLoader = (name: string, state: Readonly<StateBag>) => Promise<AbstractMesh | undefined>;
|
|
9
|
+
export interface NodeSimulationContext extends GameSimulationContext {
|
|
10
|
+
readonly scene: Scene;
|
|
11
|
+
readonly pool: NodePool;
|
|
12
|
+
readonly loadMesh: MeshLoader;
|
|
13
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AbstractMesh, AssetContainer, Mesh } from '@babylonjs/core';
|
|
2
|
+
import { GameEntityType } from '@skewedaspect/sage-core';
|
|
3
|
+
import { EntityMeshLoader } from "../interfaces/game.d.ts";
|
|
4
|
+
export interface MeshAssetSource {
|
|
5
|
+
load(path: string): Promise<AssetContainer | AbstractMesh>;
|
|
6
|
+
clone(path: string): Mesh;
|
|
7
|
+
}
|
|
8
|
+
export declare function buildStandardMeshSource(entityClasses: Readonly<Record<string, GameEntityType>>, assets: MeshAssetSource): EntityMeshLoader;
|
|
@@ -1,24 +1,4 @@
|
|
|
1
1
|
import { AbstractMesh } from '@babylonjs/core';
|
|
2
|
-
import { DeviceType, InputDevice, InputState } from "../interfaces/input.d.ts";
|
|
3
|
-
/** Payload for input:device:connected events */
|
|
4
|
-
export interface DeviceConnectedPayload {
|
|
5
|
-
device: InputDevice;
|
|
6
|
-
}
|
|
7
|
-
/** Payload for input:device:disconnected events */
|
|
8
|
-
export interface DeviceDisconnectedPayload {
|
|
9
|
-
device: InputDevice;
|
|
10
|
-
}
|
|
11
|
-
/** Payload for input:changed events */
|
|
12
|
-
export interface InputChangedPayload {
|
|
13
|
-
deviceId: string;
|
|
14
|
-
device: InputDevice;
|
|
15
|
-
state: InputState;
|
|
16
|
-
}
|
|
17
|
-
/** Payload for input:device-type:changed events */
|
|
18
|
-
export interface DeviceTypeChangedPayload {
|
|
19
|
-
deviceType: DeviceType;
|
|
20
|
-
previousDeviceType: DeviceType | null;
|
|
21
|
-
}
|
|
22
2
|
/** Payload for level:progress events */
|
|
23
3
|
export interface LevelProgressPayload {
|
|
24
4
|
levelName: string;
|
|
@@ -58,12 +38,6 @@ export interface LevelTransitionErrorPayload {
|
|
|
58
38
|
to: string;
|
|
59
39
|
error: unknown;
|
|
60
40
|
}
|
|
61
|
-
/** Payload for action:* events */
|
|
62
|
-
export interface ActionPayload {
|
|
63
|
-
value: boolean | number;
|
|
64
|
-
deviceId: string;
|
|
65
|
-
context?: string;
|
|
66
|
-
}
|
|
67
41
|
/** Payload for trigger:enter events */
|
|
68
42
|
export interface TriggerEnterPayload {
|
|
69
43
|
trigger: string;
|
|
@@ -113,10 +87,6 @@ export interface GameResumedPayload {
|
|
|
113
87
|
* while still providing type safety for known event types.
|
|
114
88
|
*/
|
|
115
89
|
export interface LibraryEventPayloadMap {
|
|
116
|
-
'input:device:connected': DeviceConnectedPayload;
|
|
117
|
-
'input:device:disconnected': DeviceDisconnectedPayload;
|
|
118
|
-
'input:changed': InputChangedPayload;
|
|
119
|
-
'input:device-type:changed': DeviceTypeChangedPayload;
|
|
120
90
|
'level:progress': LevelProgressPayload;
|
|
121
91
|
'level:complete': LevelCompletePayload;
|
|
122
92
|
'level:error': LevelErrorPayload;
|
package/dist/events/types.d.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Template literal type for action events.
|
|
3
|
-
* Actions are dynamically named based on user-defined action names.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* type MyActions = ActionEvent<'jump' | 'attack' | 'dodge'>;
|
|
7
|
-
* // Results in: "action:jump" | "action:attack" | "action:dodge"
|
|
8
|
-
*/
|
|
9
|
-
export type ActionEvent<Name extends string = string> = `action:${Name}`;
|
|
10
1
|
/**
|
|
11
2
|
* Template literal type for level events.
|
|
12
3
|
*
|
|
@@ -15,24 +6,12 @@ export type ActionEvent<Name extends string = string> = `action:${Name}`;
|
|
|
15
6
|
* // Results in: "level:progress" | "level:complete"
|
|
16
7
|
*/
|
|
17
8
|
export type LevelEvent<Name extends string = string> = `level:${Name}`;
|
|
18
|
-
/**
|
|
19
|
-
* Template literal type for input events.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* type MyInputEvents = InputEvent<'changed' | 'device:connected'>;
|
|
23
|
-
* // Results in: "input:changed" | "input:device:connected"
|
|
24
|
-
*/
|
|
25
|
-
export type InputEvent<Name extends string = string> = `input:${Name}`;
|
|
26
9
|
/** Library-defined level event types */
|
|
27
10
|
export type LibraryLevelEvent = LevelEvent<'progress' | 'complete' | 'error'>;
|
|
28
|
-
/** Library-defined input event types */
|
|
29
|
-
export type LibraryInputEvent = InputEvent<'changed' | 'device:connected' | 'device:disconnected'>;
|
|
30
|
-
/** Library-defined action event types (dynamic, based on action name) */
|
|
31
|
-
export type LibraryActionEvent = ActionEvent<string>;
|
|
32
11
|
/** All library-defined event types */
|
|
33
|
-
export type LibraryEventType = LibraryLevelEvent
|
|
12
|
+
export type LibraryEventType = LibraryLevelEvent;
|
|
34
13
|
/**
|
|
35
14
|
* Wildcard subscription patterns for subscribing to multiple events.
|
|
36
15
|
* These are valid for subscribe() but NOT for publish().
|
|
37
16
|
*/
|
|
38
|
-
export type WildcardPattern = '
|
|
17
|
+
export type WildcardPattern = 'level:*' | `${string}:*`;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Binding } from "./binding.d.ts";
|
|
2
|
+
export declare class ActionContextRegistry {
|
|
3
|
+
#private;
|
|
4
|
+
registerContext(name: string, exclusive?: boolean): void;
|
|
5
|
+
activateContext(name: string, currentState: (binding: Binding<unknown>) => unknown): void;
|
|
6
|
+
deactivateContext(name: string): void;
|
|
7
|
+
isActive(name: string): boolean;
|
|
8
|
+
isRegistered(name: string): boolean;
|
|
9
|
+
addBinding(binding: Binding<unknown>): void;
|
|
10
|
+
isLive(binding: Binding<unknown>): boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Action } from '@skewedaspect/sage-core';
|
|
2
|
+
export type BindingKind = 'trigger' | 'toggle' | 'value';
|
|
3
|
+
export type DeviceType = 'keyboard' | 'mouse' | 'gamepad';
|
|
4
|
+
export interface DeviceID {
|
|
5
|
+
type: DeviceType;
|
|
6
|
+
index: number;
|
|
7
|
+
}
|
|
8
|
+
export interface BindingInput {
|
|
9
|
+
device: DeviceID;
|
|
10
|
+
sourceType: string;
|
|
11
|
+
sourceKey: string;
|
|
12
|
+
}
|
|
13
|
+
export interface BindingDefinition {
|
|
14
|
+
kind: BindingKind;
|
|
15
|
+
action: string;
|
|
16
|
+
input: BindingInput;
|
|
17
|
+
context?: string;
|
|
18
|
+
options?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
export interface BindingFire {
|
|
21
|
+
value: boolean | number;
|
|
22
|
+
}
|
|
23
|
+
export interface Binding<State> {
|
|
24
|
+
readonly kind: BindingKind;
|
|
25
|
+
readonly action: Action;
|
|
26
|
+
readonly device: DeviceID;
|
|
27
|
+
readonly context?: string;
|
|
28
|
+
process(state: State): BindingFire | undefined;
|
|
29
|
+
prime(state: State): void;
|
|
30
|
+
toDefinition(): BindingDefinition;
|
|
31
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Action } from '@skewedaspect/sage-core';
|
|
2
|
+
import { Binding, BindingDefinition, BindingFire, DeviceID } from "../binding.d.ts";
|
|
3
|
+
import { DeviceReader } from "../deviceReader.d.ts";
|
|
4
|
+
export interface ToggleOptions {
|
|
5
|
+
onValue?: boolean | number;
|
|
6
|
+
offValue?: boolean | number;
|
|
7
|
+
initialState?: boolean;
|
|
8
|
+
threshold?: number;
|
|
9
|
+
invert?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare class ToggleBinding<State> implements Binding<State> {
|
|
12
|
+
#private;
|
|
13
|
+
readonly kind: "toggle";
|
|
14
|
+
readonly action: Action;
|
|
15
|
+
readonly device: DeviceID;
|
|
16
|
+
readonly context?: string;
|
|
17
|
+
constructor(action: Action, device: DeviceID, reader: DeviceReader<State>, options?: ToggleOptions, context?: string);
|
|
18
|
+
process(state: State): BindingFire | undefined;
|
|
19
|
+
prime(state: State): void;
|
|
20
|
+
toDefinition(): BindingDefinition;
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Action } from '@skewedaspect/sage-core';
|
|
2
|
+
import { Binding, BindingDefinition, BindingFire, DeviceID } from "../binding.d.ts";
|
|
3
|
+
import { DeviceReader } from "../deviceReader.d.ts";
|
|
4
|
+
export type EdgeMode = 'rising' | 'falling' | 'both';
|
|
5
|
+
export interface TriggerOptions {
|
|
6
|
+
edge?: EdgeMode;
|
|
7
|
+
threshold?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class TriggerBinding<State> implements Binding<State> {
|
|
10
|
+
#private;
|
|
11
|
+
readonly kind: "trigger";
|
|
12
|
+
readonly action: Action;
|
|
13
|
+
readonly device: DeviceID;
|
|
14
|
+
readonly context?: string;
|
|
15
|
+
constructor(action: Action, device: DeviceID, reader: DeviceReader<State>, options?: TriggerOptions, context?: string);
|
|
16
|
+
process(state: State): BindingFire | undefined;
|
|
17
|
+
prime(state: State): void;
|
|
18
|
+
toDefinition(): BindingDefinition;
|
|
19
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Action } from '@skewedaspect/sage-core';
|
|
2
|
+
import { Binding, BindingDefinition, BindingFire, DeviceID } from "../binding.d.ts";
|
|
3
|
+
import { DeviceReader } from "../deviceReader.d.ts";
|
|
4
|
+
export interface ValueOptions {
|
|
5
|
+
scale?: number;
|
|
6
|
+
offset?: number;
|
|
7
|
+
invert?: boolean;
|
|
8
|
+
deadzone?: number;
|
|
9
|
+
min?: number;
|
|
10
|
+
max?: number;
|
|
11
|
+
emitOnChange?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare class ValueBinding<State> implements Binding<State> {
|
|
14
|
+
#private;
|
|
15
|
+
readonly kind: "value";
|
|
16
|
+
readonly action: Action;
|
|
17
|
+
readonly device: DeviceID;
|
|
18
|
+
readonly context?: string;
|
|
19
|
+
constructor(action: Action, device: DeviceID, reader: DeviceReader<State>, options?: ValueOptions, context?: string);
|
|
20
|
+
process(state: State): BindingFire | undefined;
|
|
21
|
+
prime(state: State): void;
|
|
22
|
+
toDefinition(): BindingDefinition;
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Action } from '@skewedaspect/sage-core';
|
|
2
|
+
import { ActionContextRegistry } from "./actionContext.d.ts";
|
|
3
|
+
import { ActionRegistry } from "./actionRegistry.d.ts";
|
|
4
|
+
import { Binding, BindingDefinition } from "./binding.d.ts";
|
|
5
|
+
export interface ContextDefinition {
|
|
6
|
+
name: string;
|
|
7
|
+
exclusive: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface Configuration {
|
|
10
|
+
actions: readonly Action[];
|
|
11
|
+
bindings: readonly BindingDefinition[];
|
|
12
|
+
contexts: readonly ContextDefinition[];
|
|
13
|
+
}
|
|
14
|
+
export declare function exportConfiguration(actions: readonly Action[], bindings: readonly Binding<unknown>[], contexts: readonly ContextDefinition[]): Configuration;
|
|
15
|
+
export declare function importConfiguration(config: Configuration, actions: ActionRegistry, contexts: ActionContextRegistry): readonly BindingDefinition[];
|