@patterkit/runtime 0.25.0 → 0.26.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.
package/dist/index.d.cts CHANGED
@@ -909,6 +909,15 @@ declare class Flow {
909
909
  private emit;
910
910
  /** How many times this flow has entered each node, by node id. */
911
911
  getVisitCounts(): Record<string, number>;
912
+ /**
913
+ * The step this flow would deliver for beat `beatId` right now, as `advance` would give it: its text in the
914
+ * active locale, interpolated against this flow's values (unless the project is voiced), closed captions
915
+ * applied, and the speaker's names and label, its pause, Game Data, and tags. Built by the same function that
916
+ * builds a delivered step, so the two can't differ. It doesn't move the flow, count a visit, or run an effect.
917
+ * Undefined for an id that is neither a beat nor an option's prompt. For a game that keeps lines by id and
918
+ * shows them again (after a load, or a language switch).
919
+ */
920
+ stepFor(beatId: string): StepResult | undefined;
912
921
  /** The options of a pending choice (empty when not at a choice point). */
913
922
  getChoices(): ChoiceOption[];
914
923
  /** Pick an eligible option by id; the next `advance()` runs it. */
package/dist/index.d.ts CHANGED
@@ -909,6 +909,15 @@ declare class Flow {
909
909
  private emit;
910
910
  /** How many times this flow has entered each node, by node id. */
911
911
  getVisitCounts(): Record<string, number>;
912
+ /**
913
+ * The step this flow would deliver for beat `beatId` right now, as `advance` would give it: its text in the
914
+ * active locale, interpolated against this flow's values (unless the project is voiced), closed captions
915
+ * applied, and the speaker's names and label, its pause, Game Data, and tags. Built by the same function that
916
+ * builds a delivered step, so the two can't differ. It doesn't move the flow, count a visit, or run an effect.
917
+ * Undefined for an id that is neither a beat nor an option's prompt. For a game that keeps lines by id and
918
+ * shows them again (after a load, or a language switch).
919
+ */
920
+ stepFor(beatId: string): StepResult | undefined;
912
921
  /** The options of a pending choice (empty when not at a choice point). */
913
922
  getChoices(): ChoiceOption[];
914
923
  /** Pick an eligible option by id; the next `advance()` runs it. */
package/dist/index.js CHANGED
@@ -100,6 +100,25 @@ function padIndexFor(bundle) {
100
100
  }
101
101
  return index;
102
102
  }
103
+ var beatIndexCache = /* @__PURE__ */ new WeakMap();
104
+ function beatIndexFor(bundle) {
105
+ let index = beatIndexCache.get(bundle);
106
+ if (index) return index;
107
+ index = /* @__PURE__ */ new Map();
108
+ for (const scene of Object.values(bundle.scenes)) {
109
+ for (const block of scene.blocks) {
110
+ walkNodes(block.children, (n) => {
111
+ if (n.type === "group") {
112
+ if (n.prompt) index.set(n.prompt.id, n.prompt);
113
+ return;
114
+ }
115
+ for (const beat of n.beats ?? []) index.set(beat.id, beat);
116
+ });
117
+ }
118
+ }
119
+ beatIndexCache.set(bundle, index);
120
+ return index;
121
+ }
103
122
  function tagsOf(host, id) {
104
123
  return host.tagIndex.get(id)?.slice();
105
124
  }
@@ -1352,6 +1371,18 @@ var Flow = class {
1352
1371
  getVisitCounts() {
1353
1372
  return Object.fromEntries(this.visitCounts);
1354
1373
  }
1374
+ /**
1375
+ * The step this flow would deliver for beat `beatId` right now, as `advance` would give it: its text in the
1376
+ * active locale, interpolated against this flow's values (unless the project is voiced), closed captions
1377
+ * applied, and the speaker's names and label, its pause, Game Data, and tags. Built by the same function that
1378
+ * builds a delivered step, so the two can't differ. It doesn't move the flow, count a visit, or run an effect.
1379
+ * Undefined for an id that is neither a beat nor an option's prompt. For a game that keeps lines by id and
1380
+ * shows them again (after a load, or a language switch).
1381
+ */
1382
+ stepFor(beatId) {
1383
+ const beat = beatIndexFor(this.host.bundle).get(beatId);
1384
+ return beat ? this.beatResult(beat) : void 0;
1385
+ }
1355
1386
  /** The options of a pending choice (empty when not at a choice point). */
1356
1387
  getChoices() {
1357
1388
  return this.pendingChoice?.options ?? [];