@sharpee/engine 0.9.60-beta
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 +21 -0
- package/README.md +328 -0
- package/dist/action-context-factory.d.ts +11 -0
- package/dist/action-context-factory.d.ts.map +1 -0
- package/dist/action-context-factory.js +258 -0
- package/dist/action-context-factory.js.map +1 -0
- package/dist/capability-dispatch-helper.d.ts +106 -0
- package/dist/capability-dispatch-helper.d.ts.map +1 -0
- package/dist/capability-dispatch-helper.js +269 -0
- package/dist/capability-dispatch-helper.js.map +1 -0
- package/dist/command-executor.d.ts +53 -0
- package/dist/command-executor.d.ts.map +1 -0
- package/dist/command-executor.js +329 -0
- package/dist/command-executor.js.map +1 -0
- package/dist/event-adapter.d.ts +44 -0
- package/dist/event-adapter.d.ts.map +1 -0
- package/dist/event-adapter.js +127 -0
- package/dist/event-adapter.js.map +1 -0
- package/dist/event-sequencer.d.ts +73 -0
- package/dist/event-sequencer.d.ts.map +1 -0
- package/dist/event-sequencer.js +134 -0
- package/dist/event-sequencer.js.map +1 -0
- package/dist/events/event-emitter.d.ts +34 -0
- package/dist/events/event-emitter.d.ts.map +1 -0
- package/dist/events/event-emitter.js +67 -0
- package/dist/events/event-emitter.js.map +1 -0
- package/dist/game-engine.d.ts +292 -0
- package/dist/game-engine.d.ts.map +1 -0
- package/dist/game-engine.js +1631 -0
- package/dist/game-engine.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/narrative/index.d.ts +5 -0
- package/dist/narrative/index.d.ts.map +1 -0
- package/dist/narrative/index.js +10 -0
- package/dist/narrative/index.js.map +1 -0
- package/dist/narrative/narrative-settings.d.ts +73 -0
- package/dist/narrative/narrative-settings.d.ts.map +1 -0
- package/dist/narrative/narrative-settings.js +28 -0
- package/dist/narrative/narrative-settings.js.map +1 -0
- package/dist/parser-interface.d.ts +77 -0
- package/dist/parser-interface.d.ts.map +1 -0
- package/dist/parser-interface.js +48 -0
- package/dist/parser-interface.js.map +1 -0
- package/dist/platform-operations.d.ts +83 -0
- package/dist/platform-operations.d.ts.map +1 -0
- package/dist/platform-operations.js +218 -0
- package/dist/platform-operations.js.map +1 -0
- package/dist/save-restore-service.d.ts +133 -0
- package/dist/save-restore-service.d.ts.map +1 -0
- package/dist/save-restore-service.js +446 -0
- package/dist/save-restore-service.js.map +1 -0
- package/dist/scheduler/index.d.ts +9 -0
- package/dist/scheduler/index.d.ts.map +1 -0
- package/dist/scheduler/index.js +25 -0
- package/dist/scheduler/index.js.map +1 -0
- package/dist/scheduler/scheduler-service.d.ts +75 -0
- package/dist/scheduler/scheduler-service.d.ts.map +1 -0
- package/dist/scheduler/scheduler-service.js +310 -0
- package/dist/scheduler/scheduler-service.js.map +1 -0
- package/dist/scheduler/seeded-random.d.ts +7 -0
- package/dist/scheduler/seeded-random.d.ts.map +1 -0
- package/dist/scheduler/seeded-random.js +11 -0
- package/dist/scheduler/seeded-random.js.map +1 -0
- package/dist/scheduler/types.d.ts +134 -0
- package/dist/scheduler/types.d.ts.map +1 -0
- package/dist/scheduler/types.js +9 -0
- package/dist/scheduler/types.js.map +1 -0
- package/dist/shared-data-keys.d.ts +53 -0
- package/dist/shared-data-keys.d.ts.map +1 -0
- package/dist/shared-data-keys.js +29 -0
- package/dist/shared-data-keys.js.map +1 -0
- package/dist/story.d.ts +211 -0
- package/dist/story.d.ts.map +1 -0
- package/dist/story.js +60 -0
- package/dist/story.js.map +1 -0
- package/dist/test-helpers/mock-text-service.d.ts +11 -0
- package/dist/test-helpers/mock-text-service.d.ts.map +1 -0
- package/dist/test-helpers/mock-text-service.js +47 -0
- package/dist/test-helpers/mock-text-service.js.map +1 -0
- package/dist/turn-event-processor.d.ts +89 -0
- package/dist/turn-event-processor.d.ts.map +1 -0
- package/dist/turn-event-processor.js +144 -0
- package/dist/turn-event-processor.js.map +1 -0
- package/dist/types.d.ts +214 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/vocabulary-manager.d.ts +35 -0
- package/dist/vocabulary-manager.d.ts.map +1 -0
- package/dist/vocabulary-manager.js +74 -0
- package/dist/vocabulary-manager.js.map +1 -0
- package/package.json +70 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Engine-specific types and interfaces
|
|
3
|
+
*
|
|
4
|
+
* The engine manages game state, turn execution, and event sequencing
|
|
5
|
+
*/
|
|
6
|
+
import { ISemanticEvent } from '@sharpee/core';
|
|
7
|
+
import { IParsedCommand, IValidatedCommand, IFEntity } from '@sharpee/world-model';
|
|
8
|
+
export { IPerceptionService, Sense } from '@sharpee/stdlib';
|
|
9
|
+
/**
|
|
10
|
+
* Basic game event (before sequencing)
|
|
11
|
+
* Note: data is optional to support ISemanticEvent compatibility
|
|
12
|
+
*/
|
|
13
|
+
export interface GameEvent<T = unknown> {
|
|
14
|
+
type: string;
|
|
15
|
+
data?: T;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Sequenced event with turn and ordering information
|
|
19
|
+
*/
|
|
20
|
+
export interface SequencedEvent extends GameEvent {
|
|
21
|
+
sequence: number;
|
|
22
|
+
timestamp: Date;
|
|
23
|
+
turn: number;
|
|
24
|
+
scope: 'turn' | 'global' | 'system';
|
|
25
|
+
source?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Timing data for performance tracking
|
|
29
|
+
*/
|
|
30
|
+
export interface TimingData {
|
|
31
|
+
parsing?: number;
|
|
32
|
+
execution?: number;
|
|
33
|
+
processing?: number;
|
|
34
|
+
total: number;
|
|
35
|
+
custom?: Record<string, number>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Result of executing a meta-command (VERSION, SCORE, HELP, etc.)
|
|
39
|
+
*
|
|
40
|
+
* Meta-commands operate outside the turn cycle - they don't increment turns,
|
|
41
|
+
* trigger NPCs, or get stored in command history. They emit semantic events
|
|
42
|
+
* that are processed immediately through the text service.
|
|
43
|
+
*/
|
|
44
|
+
export interface MetaCommandResult {
|
|
45
|
+
/**
|
|
46
|
+
* Discriminator for union type
|
|
47
|
+
*/
|
|
48
|
+
type: 'meta';
|
|
49
|
+
/**
|
|
50
|
+
* Raw input string
|
|
51
|
+
*/
|
|
52
|
+
input: string;
|
|
53
|
+
/**
|
|
54
|
+
* Whether the command succeeded
|
|
55
|
+
*/
|
|
56
|
+
success: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Semantic events emitted by the meta-command
|
|
59
|
+
* These are processed immediately through text service, not stored in turnEvents
|
|
60
|
+
*/
|
|
61
|
+
events: ISemanticEvent[];
|
|
62
|
+
/**
|
|
63
|
+
* Error message if command failed
|
|
64
|
+
*/
|
|
65
|
+
error?: string;
|
|
66
|
+
/**
|
|
67
|
+
* The action ID that was executed
|
|
68
|
+
*/
|
|
69
|
+
actionId?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Result of executing a turn
|
|
73
|
+
*/
|
|
74
|
+
export interface TurnResult {
|
|
75
|
+
/**
|
|
76
|
+
* Discriminator for union type (optional for backward compatibility)
|
|
77
|
+
*/
|
|
78
|
+
type?: 'turn';
|
|
79
|
+
/**
|
|
80
|
+
* Turn number
|
|
81
|
+
*/
|
|
82
|
+
turn: number;
|
|
83
|
+
/**
|
|
84
|
+
* Raw input string
|
|
85
|
+
*/
|
|
86
|
+
input: string;
|
|
87
|
+
/**
|
|
88
|
+
* All events generated this turn (in sequence)
|
|
89
|
+
*/
|
|
90
|
+
events: SequencedEvent[];
|
|
91
|
+
/**
|
|
92
|
+
* Whether the turn succeeded
|
|
93
|
+
*/
|
|
94
|
+
success: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Error message if turn failed
|
|
97
|
+
*/
|
|
98
|
+
error?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Timing information
|
|
101
|
+
*/
|
|
102
|
+
timing?: TimingData;
|
|
103
|
+
/**
|
|
104
|
+
* The action ID that was executed (if any)
|
|
105
|
+
*/
|
|
106
|
+
actionId?: string;
|
|
107
|
+
/**
|
|
108
|
+
* The parsed command (if successfully parsed)
|
|
109
|
+
*/
|
|
110
|
+
parsedCommand?: IParsedCommand;
|
|
111
|
+
/**
|
|
112
|
+
* The validated command with resolved entity IDs (if successfully validated)
|
|
113
|
+
* Used for pronoun resolution (ADR-089)
|
|
114
|
+
*/
|
|
115
|
+
validatedCommand?: IValidatedCommand;
|
|
116
|
+
/**
|
|
117
|
+
* Whether the turn is waiting for additional input (e.g., disambiguation)
|
|
118
|
+
* When true, a client.query event was emitted and the engine expects
|
|
119
|
+
* a follow-up response before continuing.
|
|
120
|
+
*/
|
|
121
|
+
needsInput?: boolean;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Union of all command execution results.
|
|
125
|
+
*
|
|
126
|
+
* executeTurn() returns this union type - callers should check `type` to determine
|
|
127
|
+
* whether a turn was executed (TurnResult) or a meta-command was executed (MetaCommandResult).
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const result = await engine.executeTurn(input);
|
|
132
|
+
* if (result.type === 'meta') {
|
|
133
|
+
* // Meta-command: no turn number, text already emitted
|
|
134
|
+
* } else {
|
|
135
|
+
* // Regular turn: has turn number, events to process
|
|
136
|
+
* console.log(`Turn ${result.turn}`);
|
|
137
|
+
* }
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export type CommandResult = TurnResult | MetaCommandResult;
|
|
141
|
+
/**
|
|
142
|
+
* Game context for execution
|
|
143
|
+
*/
|
|
144
|
+
export interface GameContext {
|
|
145
|
+
/**
|
|
146
|
+
* Current turn number
|
|
147
|
+
*/
|
|
148
|
+
currentTurn: number;
|
|
149
|
+
/**
|
|
150
|
+
* Player entity
|
|
151
|
+
*/
|
|
152
|
+
player: IFEntity;
|
|
153
|
+
/**
|
|
154
|
+
* Turn history
|
|
155
|
+
*/
|
|
156
|
+
history: TurnResult[];
|
|
157
|
+
/**
|
|
158
|
+
* Game metadata
|
|
159
|
+
*/
|
|
160
|
+
metadata: {
|
|
161
|
+
title?: string;
|
|
162
|
+
author?: string;
|
|
163
|
+
version?: string;
|
|
164
|
+
started: Date;
|
|
165
|
+
lastPlayed: Date;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Custom game state
|
|
169
|
+
*/
|
|
170
|
+
customState?: Record<string, unknown>;
|
|
171
|
+
/**
|
|
172
|
+
* Implicit actions configuration (ADR-104)
|
|
173
|
+
* Populated from StoryConfig.implicitActions
|
|
174
|
+
*/
|
|
175
|
+
implicitActions?: {
|
|
176
|
+
inference?: boolean;
|
|
177
|
+
implicitTake?: boolean;
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Engine configuration
|
|
182
|
+
*/
|
|
183
|
+
export interface EngineConfig {
|
|
184
|
+
/**
|
|
185
|
+
* Maximum turns to keep in history
|
|
186
|
+
*/
|
|
187
|
+
maxHistory?: number;
|
|
188
|
+
/**
|
|
189
|
+
* Whether to validate events before processing
|
|
190
|
+
*/
|
|
191
|
+
validateEvents?: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Whether to emit timing information
|
|
194
|
+
*/
|
|
195
|
+
collectTiming?: boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Custom error handler
|
|
198
|
+
*/
|
|
199
|
+
onError?: (error: Error, context: GameContext) => void;
|
|
200
|
+
/**
|
|
201
|
+
* Event interceptor for debugging
|
|
202
|
+
*/
|
|
203
|
+
onEvent?: (event: SequencedEvent) => void;
|
|
204
|
+
/**
|
|
205
|
+
* Debug mode - shows more detailed output
|
|
206
|
+
*/
|
|
207
|
+
debug?: boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Maximum undo snapshots to keep (default 10)
|
|
210
|
+
* Set to 0 to disable undo
|
|
211
|
+
*/
|
|
212
|
+
maxUndoSnapshots?: number;
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"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"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vocabulary Manager - Manages entity vocabulary for parser scope resolution
|
|
3
|
+
*
|
|
4
|
+
* Extracted from GameEngine as part of Phase 4 remediation.
|
|
5
|
+
* Handles registering entity nouns/adjectives with the vocabulary registry
|
|
6
|
+
* to enable parser noun resolution within the current scope.
|
|
7
|
+
*/
|
|
8
|
+
import { IFEntity, WorldModel } from '@sharpee/world-model';
|
|
9
|
+
/**
|
|
10
|
+
* Manages vocabulary registration for entities in scope
|
|
11
|
+
*/
|
|
12
|
+
export declare class VocabularyManager {
|
|
13
|
+
/**
|
|
14
|
+
* Update vocabulary for a single entity
|
|
15
|
+
*
|
|
16
|
+
* @param entity - The entity to register
|
|
17
|
+
* @param inScope - Whether the entity is currently in scope
|
|
18
|
+
*/
|
|
19
|
+
updateEntityVocabulary(entity: IFEntity, inScope: boolean): void;
|
|
20
|
+
/**
|
|
21
|
+
* Update vocabulary for all entities based on current scope
|
|
22
|
+
*
|
|
23
|
+
* Marks all entities as out of scope first, then marks
|
|
24
|
+
* entities visible to the player as in scope.
|
|
25
|
+
*
|
|
26
|
+
* @param world - The world model
|
|
27
|
+
* @param playerId - The player entity ID
|
|
28
|
+
*/
|
|
29
|
+
updateScopeVocabulary(world: WorldModel, playerId: string): void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a vocabulary manager instance
|
|
33
|
+
*/
|
|
34
|
+
export declare function createVocabularyManager(): VocabularyManager;
|
|
35
|
+
//# sourceMappingURL=vocabulary-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocabulary-manager.d.ts","sourceRoot":"","sources":["../src/vocabulary-manager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAG5D;;GAEG;AACH,qBAAa,iBAAiB;IAC5B;;;;;OAKG;IACH,sBAAsB,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IA2BhE;;;;;;;;OAQG;IACH,qBAAqB,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;CAgBjE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,iBAAiB,CAE3D"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Vocabulary Manager - Manages entity vocabulary for parser scope resolution
|
|
4
|
+
*
|
|
5
|
+
* Extracted from GameEngine as part of Phase 4 remediation.
|
|
6
|
+
* Handles registering entity nouns/adjectives with the vocabulary registry
|
|
7
|
+
* to enable parser noun resolution within the current scope.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.VocabularyManager = void 0;
|
|
11
|
+
exports.createVocabularyManager = createVocabularyManager;
|
|
12
|
+
const stdlib_1 = require("@sharpee/stdlib");
|
|
13
|
+
/**
|
|
14
|
+
* Manages vocabulary registration for entities in scope
|
|
15
|
+
*/
|
|
16
|
+
class VocabularyManager {
|
|
17
|
+
/**
|
|
18
|
+
* Update vocabulary for a single entity
|
|
19
|
+
*
|
|
20
|
+
* @param entity - The entity to register
|
|
21
|
+
* @param inScope - Whether the entity is currently in scope
|
|
22
|
+
*/
|
|
23
|
+
updateEntityVocabulary(entity, inScope) {
|
|
24
|
+
const identityTrait = entity.get('IDENTITY');
|
|
25
|
+
if (identityTrait && typeof identityTrait === 'object') {
|
|
26
|
+
const identity = identityTrait;
|
|
27
|
+
// Build nouns from name and aliases
|
|
28
|
+
const nouns = [];
|
|
29
|
+
if (identity.name) {
|
|
30
|
+
nouns.push(identity.name.toLowerCase());
|
|
31
|
+
}
|
|
32
|
+
if (identity.aliases && Array.isArray(identity.aliases)) {
|
|
33
|
+
nouns.push(...identity.aliases);
|
|
34
|
+
}
|
|
35
|
+
stdlib_1.vocabularyRegistry.registerEntity({
|
|
36
|
+
entityId: entity.id,
|
|
37
|
+
nouns: nouns,
|
|
38
|
+
adjectives: identity.adjectives || [],
|
|
39
|
+
inScope
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Update vocabulary for all entities based on current scope
|
|
45
|
+
*
|
|
46
|
+
* Marks all entities as out of scope first, then marks
|
|
47
|
+
* entities visible to the player as in scope.
|
|
48
|
+
*
|
|
49
|
+
* @param world - The world model
|
|
50
|
+
* @param playerId - The player entity ID
|
|
51
|
+
*/
|
|
52
|
+
updateScopeVocabulary(world, playerId) {
|
|
53
|
+
const player = world.getEntity(playerId);
|
|
54
|
+
if (!player)
|
|
55
|
+
return;
|
|
56
|
+
const inScope = world.getInScope(playerId);
|
|
57
|
+
// Mark all entities as out of scope first
|
|
58
|
+
for (const entity of world.getAllEntities()) {
|
|
59
|
+
this.updateEntityVocabulary(entity, false);
|
|
60
|
+
}
|
|
61
|
+
// Mark in-scope entities
|
|
62
|
+
for (const entity of inScope) {
|
|
63
|
+
this.updateEntityVocabulary(entity, true);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.VocabularyManager = VocabularyManager;
|
|
68
|
+
/**
|
|
69
|
+
* Create a vocabulary manager instance
|
|
70
|
+
*/
|
|
71
|
+
function createVocabularyManager() {
|
|
72
|
+
return new VocabularyManager();
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=vocabulary-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocabulary-manager.js","sourceRoot":"","sources":["../src/vocabulary-manager.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAwEH,0DAEC;AAvED,4CAAqD;AAErD;;GAEG;AACH,MAAa,iBAAiB;IAC5B;;;;;OAKG;IACH,sBAAsB,CAAC,MAAgB,EAAE,OAAgB;QACvD,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC7C,IAAI,aAAa,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE,CAAC;YACvD,MAAM,QAAQ,GAAG,aAIhB,CAAC;YAEF,oCAAoC;YACpC,MAAM,KAAK,GAAa,EAAE,CAAC;YAC3B,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;gBAClB,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;YAC1C,CAAC;YACD,IAAI,QAAQ,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;gBACxD,KAAK,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;YAClC,CAAC;YAED,2BAAkB,CAAC,cAAc,CAAC;gBAChC,QAAQ,EAAE,MAAM,CAAC,EAAE;gBACnB,KAAK,EAAE,KAAK;gBACZ,UAAU,EAAE,QAAQ,CAAC,UAAU,IAAI,EAAE;gBACrC,OAAO;aACR,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED;;;;;;;;OAQG;IACH,qBAAqB,CAAC,KAAiB,EAAE,QAAgB;QACvD,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM;YAAE,OAAO;QAEpB,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAE3C,0CAA0C;QAC1C,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,cAAc,EAAE,EAAE,CAAC;YAC5C,IAAI,CAAC,sBAAsB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC7C,CAAC;QAED,yBAAyB;QACzB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC,sBAAsB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;CACF;AA3DD,8CA2DC;AAED;;GAEG;AACH,SAAgB,uBAAuB;IACrC,OAAO,IAAI,iBAAiB,EAAE,CAAC;AACjC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sharpee/engine",
|
|
3
|
+
"version": "0.9.60-beta",
|
|
4
|
+
"description": "Runtime engine for Sharpee IF Platform - game loop, command execution, and turn management",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@sharpee/core": "0.9.60-beta",
|
|
17
|
+
"@sharpee/event-processor": "0.9.60-beta",
|
|
18
|
+
"@sharpee/if-domain": "0.9.60-beta",
|
|
19
|
+
"@sharpee/if-services": "0.9.60-beta",
|
|
20
|
+
"@sharpee/parser-en-us": "0.9.60-beta",
|
|
21
|
+
"@sharpee/lang-en-us": "0.9.60-beta",
|
|
22
|
+
"@sharpee/stdlib": "0.9.60-beta",
|
|
23
|
+
"@sharpee/text-blocks": "0.9.60-beta",
|
|
24
|
+
"@sharpee/text-service": "0.9.60-beta",
|
|
25
|
+
"@sharpee/world-model": "0.9.60-beta"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^20.11.19",
|
|
29
|
+
"cross-env": "^7.0.3",
|
|
30
|
+
"rimraf": "^5.0.5",
|
|
31
|
+
"typescript": "^5.3.3"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"keywords": [
|
|
37
|
+
"interactive-fiction",
|
|
38
|
+
"if",
|
|
39
|
+
"text-adventure",
|
|
40
|
+
"sharpee",
|
|
41
|
+
"engine",
|
|
42
|
+
"game-engine"
|
|
43
|
+
],
|
|
44
|
+
"author": "Sharpee Team",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "https://github.com/ChicagoDave/sharpee.git",
|
|
49
|
+
"directory": "packages/engine"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://github.com/ChicagoDave/sharpee#readme",
|
|
52
|
+
"bugs": {
|
|
53
|
+
"url": "https://github.com/ChicagoDave/sharpee/issues"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=18.0.0"
|
|
57
|
+
},
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "tsc",
|
|
63
|
+
"test": "vitest",
|
|
64
|
+
"test:ci": "vitest run",
|
|
65
|
+
"test:verbose": "vitest run --reporter=verbose",
|
|
66
|
+
"test:watch": "vitest",
|
|
67
|
+
"test:coverage": "vitest run --coverage",
|
|
68
|
+
"clean": "rimraf dist"
|
|
69
|
+
}
|
|
70
|
+
}
|