@patterkit/runtime 0.16.0 → 0.17.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
@@ -459,6 +459,10 @@ declare class Engine {
459
459
  *
460
460
  * Contrast {@link runFlow}, which REUSES a flow of the same name instead of replacing it - that is the
461
461
  * call to reach for when you want a speaker's variation state to carry on.
462
+ *
463
+ * THROWS on an address that does not resolve (an unknown scene, or a block that is not in the named
464
+ * scene), before anything changes: nothing is opened, and a flow already open under `id` carries on
465
+ * exactly as it was.
462
466
  */
463
467
  openFlow(id: string, opts?: OpenFlowOptions): Flow;
464
468
  /**
@@ -490,6 +494,13 @@ declare class Engine {
490
494
  * it opens (or the save as it loads), before anything changes. By then a game has built all of its
491
495
  * engines, whatever order it built them in. The same message on every runtime. */
492
496
  private assertExternalScopes;
497
+ /**
498
+ * `openFlow`'s address as internal ids, or a throw when it does not resolve. With a scene, the block is
499
+ * scene-scoped exactly as {@link Flow.goto} resolves it (a gameId address in that scene, or the internal
500
+ * id of a block in that scene), so a block from another scene does not resolve. With no scene, the block
501
+ * is an internal id from any scene. Neither: the bundle's first scene. The same rule on every runtime.
502
+ */
503
+ private resolveOpenAddress;
493
504
  /** Resolve a scene reference (a gameId address OR an internal id) to its internal id. */
494
505
  private resolveSceneRef;
495
506
  /** Resolve a block reference (a scene-scoped gameId OR an internal id) to its internal id. */
package/dist/index.d.ts CHANGED
@@ -459,6 +459,10 @@ declare class Engine {
459
459
  *
460
460
  * Contrast {@link runFlow}, which REUSES a flow of the same name instead of replacing it - that is the
461
461
  * call to reach for when you want a speaker's variation state to carry on.
462
+ *
463
+ * THROWS on an address that does not resolve (an unknown scene, or a block that is not in the named
464
+ * scene), before anything changes: nothing is opened, and a flow already open under `id` carries on
465
+ * exactly as it was.
462
466
  */
463
467
  openFlow(id: string, opts?: OpenFlowOptions): Flow;
464
468
  /**
@@ -490,6 +494,13 @@ declare class Engine {
490
494
  * it opens (or the save as it loads), before anything changes. By then a game has built all of its
491
495
  * engines, whatever order it built them in. The same message on every runtime. */
492
496
  private assertExternalScopes;
497
+ /**
498
+ * `openFlow`'s address as internal ids, or a throw when it does not resolve. With a scene, the block is
499
+ * scene-scoped exactly as {@link Flow.goto} resolves it (a gameId address in that scene, or the internal
500
+ * id of a block in that scene), so a block from another scene does not resolve. With no scene, the block
501
+ * is an internal id from any scene. Neither: the bundle's first scene. The same rule on every runtime.
502
+ */
503
+ private resolveOpenAddress;
493
504
  /** Resolve a scene reference (a gameId address OR an internal id) to its internal id. */
494
505
  private resolveSceneRef;
495
506
  /** Resolve a block reference (a scene-scoped gameId OR an internal id) to its internal id. */
package/dist/index.js CHANGED
@@ -299,11 +299,14 @@ var Engine = class _Engine {
299
299
  *
300
300
  * Contrast {@link runFlow}, which REUSES a flow of the same name instead of replacing it - that is the
301
301
  * call to reach for when you want a speaker's variation state to carry on.
302
+ *
303
+ * THROWS on an address that does not resolve (an unknown scene, or a block that is not in the named
304
+ * scene), before anything changes: nothing is opened, and a flow already open under `id` carries on
305
+ * exactly as it was.
302
306
  */
303
307
  openFlow(id, opts = {}) {
304
308
  this.assertExternalScopes();
305
- const sceneId = this.resolveSceneRef(opts.scene);
306
- const blockId = this.resolveBlockRef(sceneId, opts.block);
309
+ const { sceneId, blockId } = this.resolveOpenAddress(opts.scene, opts.block);
307
310
  const prior = this.flowsById.get(id);
308
311
  const journal = this.host.journal;
309
312
  if (journal && prior && !prior.isClosed) throw new Error(`openFlow would replace the open flow '${id}', which can't be undone while a checkpoint is open`);
@@ -364,6 +367,28 @@ var Engine = class _Engine {
364
367
  }
365
368
  }
366
369
  }
370
+ /**
371
+ * `openFlow`'s address as internal ids, or a throw when it does not resolve. With a scene, the block is
372
+ * scene-scoped exactly as {@link Flow.goto} resolves it (a gameId address in that scene, or the internal
373
+ * id of a block in that scene), so a block from another scene does not resolve. With no scene, the block
374
+ * is an internal id from any scene. Neither: the bundle's first scene. The same rule on every runtime.
375
+ */
376
+ resolveOpenAddress(scene, block) {
377
+ if (scene !== void 0) {
378
+ const sceneId = this.resolveSceneRef(scene);
379
+ if (!this.host.bundle.scenes[sceneId]) throw new Error(`unknown scene: ${scene}`);
380
+ if (block === void 0) return { sceneId };
381
+ const blockId = this.blockGameIdToId.get(sceneId)?.get(block) ?? (this.host.blockIndex.get(block)?.sceneId === sceneId ? block : void 0);
382
+ if (blockId === void 0) throw new Error(`unknown block: ${block}`);
383
+ return { sceneId, blockId };
384
+ }
385
+ if (block !== void 0) {
386
+ if (!this.host.blockIndex.has(block)) throw new Error(`unknown block: ${block}`);
387
+ return { blockId: block };
388
+ }
389
+ if (Object.keys(this.host.bundle.scenes).length === 0) throw new Error("no scenes in bundle");
390
+ return {};
391
+ }
367
392
  /** Resolve a scene reference (a gameId address OR an internal id) to its internal id. */
368
393
  resolveSceneRef(ref) {
369
394
  if (ref == null) return void 0;