@sharpee/plugins 1.0.0 → 1.0.8

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/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../repos/sharpee/packages/plugins/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/plugins/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sharpee/plugins",
3
- "version": "1.0.0",
3
+ "version": "1.0.8",
4
4
  "description": "Plugin contracts for Sharpee engine turn-cycle extensibility",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -12,8 +12,8 @@
12
12
  }
13
13
  },
14
14
  "dependencies": {
15
- "@sharpee/core": "^1.0.0",
16
- "@sharpee/world-model": "^1.0.0"
15
+ "@sharpee/core": "^1.0.8",
16
+ "@sharpee/world-model": "^1.0.8"
17
17
  },
18
18
  "keywords": [
19
19
  "interactive-fiction",
@@ -1,12 +1,32 @@
1
1
  import { TurnPlugin } from './turn-plugin';
2
+ /**
3
+ * Holds the turn plugins for a running game and hands them to the engine in
4
+ * priority order each turn (ADR-120). The engine owns the single registry;
5
+ * stories add behaviour through the plugin packages (NPC, scheduler, state
6
+ * machine) rather than implementing {@link TurnPlugin} directly.
7
+ */
2
8
  export declare class PluginRegistry {
3
9
  private plugins;
10
+ /** Register a plugin. Throws if a plugin with the same id is already registered. */
4
11
  register(plugin: TurnPlugin): void;
12
+ /** Remove a plugin by id; a no-op if no such plugin is registered. */
5
13
  unregister(id: string): void;
14
+ /** Remove all registered plugins. */
6
15
  clear(): void;
16
+ /** All registered plugins, sorted by descending priority (turn run order). */
7
17
  getAll(): TurnPlugin[];
18
+ /** Look up a single plugin by id, or `undefined` if absent. */
8
19
  getById(id: string): TurnPlugin | undefined;
20
+ /**
21
+ * Collect each plugin's {@link TurnPlugin.getState} result, keyed by plugin id,
22
+ * for inclusion in a save. Plugins without `getState` are omitted.
23
+ */
9
24
  getStates(): Record<string, unknown>;
25
+ /**
26
+ * Restore plugin state from a prior {@link PluginRegistry.getStates} result on
27
+ * load, calling each matching plugin's {@link TurnPlugin.setState}. Entries
28
+ * with no registered plugin (or no `setState`) are skipped.
29
+ */
10
30
  setStates(states: Record<string, unknown>): void;
11
31
  }
12
32
  //# sourceMappingURL=plugin-registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-registry.d.ts","sourceRoot":"","sources":["../../../../../repos/sharpee/packages/plugins/src/plugin-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAAsC;IAErD,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAOlC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAI5B,KAAK,IAAI,IAAI;IAIb,MAAM,IAAI,UAAU,EAAE;IAMtB,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAI3C,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAUpC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;CAQjD"}
1
+ {"version":3,"file":"plugin-registry.d.ts","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/plugins/src/plugin-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;;;;GAKG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAAsC;IAErD,oFAAoF;IACpF,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAOlC,sEAAsE;IACtE,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAI5B,qCAAqC;IACrC,KAAK,IAAI,IAAI;IAIb,8EAA8E;IAC9E,MAAM,IAAI,UAAU,EAAE;IAMtB,+DAA+D;IAC/D,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAI3C;;;OAGG;IACH,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAUpC;;;;OAIG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;CAQjD"}
@@ -1,26 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PluginRegistry = void 0;
4
+ /**
5
+ * Holds the turn plugins for a running game and hands them to the engine in
6
+ * priority order each turn (ADR-120). The engine owns the single registry;
7
+ * stories add behaviour through the plugin packages (NPC, scheduler, state
8
+ * machine) rather than implementing {@link TurnPlugin} directly.
9
+ */
4
10
  class PluginRegistry {
5
11
  plugins = new Map();
12
+ /** Register a plugin. Throws if a plugin with the same id is already registered. */
6
13
  register(plugin) {
7
14
  if (this.plugins.has(plugin.id)) {
8
15
  throw new Error(`Plugin already registered: ${plugin.id}`);
9
16
  }
10
17
  this.plugins.set(plugin.id, plugin);
11
18
  }
19
+ /** Remove a plugin by id; a no-op if no such plugin is registered. */
12
20
  unregister(id) {
13
21
  this.plugins.delete(id);
14
22
  }
23
+ /** Remove all registered plugins. */
15
24
  clear() {
16
25
  this.plugins.clear();
17
26
  }
27
+ /** All registered plugins, sorted by descending priority (turn run order). */
18
28
  getAll() {
19
29
  return Array.from(this.plugins.values()).sort((a, b) => b.priority - a.priority);
20
30
  }
31
+ /** Look up a single plugin by id, or `undefined` if absent. */
21
32
  getById(id) {
22
33
  return this.plugins.get(id);
23
34
  }
35
+ /**
36
+ * Collect each plugin's {@link TurnPlugin.getState} result, keyed by plugin id,
37
+ * for inclusion in a save. Plugins without `getState` are omitted.
38
+ */
24
39
  getStates() {
25
40
  const states = {};
26
41
  for (const plugin of this.plugins.values()) {
@@ -30,6 +45,11 @@ class PluginRegistry {
30
45
  }
31
46
  return states;
32
47
  }
48
+ /**
49
+ * Restore plugin state from a prior {@link PluginRegistry.getStates} result on
50
+ * load, calling each matching plugin's {@link TurnPlugin.setState}. Entries
51
+ * with no registered plugin (or no `setState`) are skipped.
52
+ */
33
53
  setStates(states) {
34
54
  for (const [id, state] of Object.entries(states)) {
35
55
  const plugin = this.plugins.get(id);
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-registry.js","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/plugins/src/plugin-registry.ts"],"names":[],"mappings":";;;AAEA,MAAa,cAAc;IACjB,OAAO,GAA4B,IAAI,GAAG,EAAE,CAAC;IAErD,QAAQ,CAAC,MAAkB;QACzB,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,8BAA8B,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7D,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IACtC,CAAC;IAED,UAAU,CAAC,EAAU;QACnB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED,MAAM;QACJ,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAC3C,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAClC,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,EAAU;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC;IAED,SAAS;QACP,MAAM,MAAM,GAA4B,EAAE,CAAC;QAC3C,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YAC3C,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACpB,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;YACxC,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,SAAS,CAAC,MAA+B;QACvC,KAAK,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACjD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACpC,IAAI,MAAM,EAAE,QAAQ,EAAE,CAAC;gBACrB,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA9CD,wCA8CC"}
1
+ {"version":3,"file":"plugin-registry.js","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/plugins/src/plugin-registry.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACH,MAAa,cAAc;IACjB,OAAO,GAA4B,IAAI,GAAG,EAAE,CAAC;IAErD,oFAAoF;IACpF,QAAQ,CAAC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IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACjD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACpC,IAAI,MAAM,EAAE,QAAQ,EAAE,CAAC;gBACrB,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA5DD,wCA4DC"}
@@ -1,18 +1,34 @@
1
- import { EntityId, SeededRandom, ISemanticEvent } from "../core/index";
2
- import { WorldModel } from "../world-model/index";
1
+ import { EntityId, SeededRandom, ISemanticEvent } from '@sharpee/core';
2
+ import { WorldModel } from '@sharpee/world-model';
3
+ /** Summary of the player action that just completed, passed to each plugin. */
3
4
  export interface TurnPluginActionResult {
5
+ /** The action's id (the verb that ran). */
4
6
  actionId: string;
7
+ /** Whether the action succeeded. Plugins only run after successful actions. */
5
8
  success: boolean;
9
+ /** The action's direct-object entity, when it had one. */
6
10
  targetId?: EntityId;
11
+ /** Arbitrary data the action chose to share, keyed by the action. */
7
12
  sharedData?: Record<string, unknown>;
8
13
  }
14
+ /** Read-only turn context the engine passes to each plugin's onAfterAction. */
9
15
  export interface TurnPluginContext {
16
+ /** The live world model. */
10
17
  world: WorldModel;
18
+ /** The current turn number. */
11
19
  turn: number;
20
+ /** The player entity id. */
12
21
  playerId: EntityId;
22
+ /** The player's current location id. */
13
23
  playerLocation: EntityId;
24
+ /**
25
+ * The engine's seeded RNG. Use this instead of `Math.random` so turns stay
26
+ * deterministic and replayable.
27
+ */
14
28
  random: SeededRandom;
29
+ /** The action that just completed this turn. */
15
30
  actionResult?: TurnPluginActionResult;
31
+ /** The semantic events the action emitted this turn. */
16
32
  actionEvents?: ISemanticEvent[];
17
33
  }
18
34
  //# sourceMappingURL=turn-plugin-context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"turn-plugin-context.d.ts","sourceRoot":"","sources":["../../../../../repos/sharpee/packages/plugins/src/turn-plugin-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,UAAU,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,CAAC;IACnB,cAAc,EAAE,QAAQ,CAAC;IACzB,MAAM,EAAE,YAAY,CAAC;IACrB,YAAY,CAAC,EAAE,sBAAsB,CAAC;IACtC,YAAY,CAAC,EAAE,cAAc,EAAE,CAAC;CACjC"}
1
+ {"version":3,"file":"turn-plugin-context.d.ts","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/plugins/src/turn-plugin-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,+EAA+E;AAC/E,MAAM,WAAW,sBAAsB;IACrC,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,OAAO,EAAE,OAAO,CAAC;IACjB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,qEAAqE;IACrE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,+EAA+E;AAC/E,MAAM,WAAW,iBAAiB;IAChC,4BAA4B;IAC5B,KAAK,EAAE,UAAU,CAAC;IAClB,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,QAAQ,EAAE,QAAQ,CAAC;IACnB,wCAAwC;IACxC,cAAc,EAAE,QAAQ,CAAC;IACzB;;;OAGG;IACH,MAAM,EAAE,YAAY,CAAC;IACrB,gDAAgD;IAChD,YAAY,CAAC,EAAE,sBAAsB,CAAC;IACtC,wDAAwD;IACxD,YAAY,CAAC,EAAE,cAAc,EAAE,CAAC;CACjC"}
package/turn-plugin.d.ts CHANGED
@@ -1,10 +1,28 @@
1
- import { ISemanticEvent } from "../core/index";
1
+ import { ISemanticEvent } from '@sharpee/core';
2
2
  import { TurnPluginContext } from './turn-plugin-context';
3
+ /**
4
+ * A turn-cycle plugin: code that runs once after each successful player action
5
+ * to contribute additional world changes and events (ADR-120).
6
+ *
7
+ * The engine invokes every registered plugin's {@link TurnPlugin.onAfterAction}
8
+ * in descending {@link TurnPlugin.priority} order (NPC behaviour at 100, state
9
+ * machines at 75, the scheduler at 50). Plugins do not run for meta-commands or
10
+ * for failed actions.
11
+ */
3
12
  export interface TurnPlugin {
13
+ /** Unique plugin identifier. Registering two plugins with the same id throws. */
4
14
  id: string;
15
+ /** Run order within a turn; higher priority runs first. */
5
16
  priority: number;
17
+ /**
18
+ * Called once per successful player action. Return the semantic events the
19
+ * plugin produces; the engine merges a non-empty array into the turn's event
20
+ * stream. Return an empty array to contribute nothing.
21
+ */
6
22
  onAfterAction(context: TurnPluginContext): ISemanticEvent[];
23
+ /** Optional: return serializable state to persist when the game is saved. */
7
24
  getState?(): unknown;
25
+ /** Optional: restore previously-saved state when the game is loaded. */
8
26
  setState?(state: unknown): void;
9
27
  }
10
28
  //# sourceMappingURL=turn-plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"turn-plugin.d.ts","sourceRoot":"","sources":["../../../../../repos/sharpee/packages/plugins/src/turn-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,OAAO,EAAE,iBAAiB,GAAG,cAAc,EAAE,CAAC;IAC5D,QAAQ,CAAC,IAAI,OAAO,CAAC;IACrB,QAAQ,CAAC,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CACjC"}
1
+ {"version":3,"file":"turn-plugin.d.ts","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/plugins/src/turn-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU;IACzB,iFAAiF;IACjF,EAAE,EAAE,MAAM,CAAC;IACX,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,aAAa,CAAC,OAAO,EAAE,iBAAiB,GAAG,cAAc,EAAE,CAAC;IAC5D,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,OAAO,CAAC;IACrB,wEAAwE;IACxE,QAAQ,CAAC,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CACjC"}