@patterkit/runtime 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@patterkit/runtime` (Patterplay JS) are documented here. The
4
+ Patterplay runtimes - JS, Unity, Unreal, and Godot - are versioned in lockstep: the same
5
+ version number always means the same runtime behaviour. This package is versioned by
6
+ `npm run bump:play`, not by Changesets.
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - Unreleased
11
+
12
+ ### Added
13
+ - The Patter runtime in JS/TS: `Engine` + `Flow` over a compiled `.patterc` bundle - scenes,
14
+ blocks, run/choice/branch/sequence selectors, sticky/fallback options, call-return jumps,
15
+ conditions + effects, visit counts, `{@ref}` interpolation, game events, tags, gameData
16
+ merge-at-read, and whole-game save/load (`saveGame` / `loadGame`).
17
+ - The `patterplay.min.js` drop-in: the whole runtime as one self-contained `<script>` file
18
+ (`window.Patterplay`), for plain HTML pages with no bundler.
19
+ - Localisation: play any locale of an Embedded bundle, switch live with `setLocale`, or ship
20
+ an IDs-only bundle and localise in your own system (`flow.interpolate`). Closed-caption cue
21
+ stripping via `setClosedCaptions`.
22
+ - Live refresh: `replaceStrings` (text-only edits, in place) and `hotSwap` (structural edits,
23
+ state carried over) - the engine side of Patterpad's Live Link hot reload.
24
+ - Structure introspection: `getOutline()` / `getBeatSequence()` expose the authored tree
25
+ (per-beat text, character, gameData, tags) for tooling.
26
+ - Companion helpers live in `@patterkit/play-helpers` (save envelopes, property setters,
27
+ state logger, Live Link client, property inspector, audio resolution).
28
+ - Distribution: `patterplay-js-<version>.zip` on each `play-js-v*` GitHub Release (the
29
+ runtime + module builds + two demos, no npm needed), npm, and the CDN drop-in - all the
30
+ same version.
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # @patterkit/runtime
2
+
3
+ **Patterplay JS** - play [Patter](https://patterkit.dev/) branching
4
+ dialogue in JavaScript or TypeScript. Load a compiled bundle (a `.patterc`, the
5
+ artifact Patterpad's *Build Bundle* writes) and play the dialogue: flows, selectors,
6
+ choices, jumps, effects, properties, save/load. One of the four Patterplay runtimes
7
+ (JS, Unity, Unreal, Godot): every runtime plays the same bundle with the same
8
+ behaviour, and the whole set is **versioned in lockstep** (see
9
+ [CHANGELOG.md](CHANGELOG.md)).
10
+
11
+ ## Get it
12
+
13
+ Three equivalent channels - pick whichever fits how you work; **no npm is required**:
14
+
15
+ - **Release zip**: `patterplay-js-<version>.zip` on every
16
+ [`play-js-v*` GitHub Release](https://github.com/patterkit/patter/releases) - this
17
+ runtime as a plain download, symmetric with the Unity / Unreal / Godot plugin zips.
18
+ It carries `patterplay.min.js` (the `<script>` drop-in), the module builds under
19
+ `dist/` (ESM + CJS + types, for vendoring into your own build), this README, the
20
+ CHANGELOG, and two `demos/` (the zero-build drop-in page and the interactive tour).
21
+ - **npm**: `npm install @patterkit/runtime` (same version as the zip).
22
+ - **CDN**: `patterplay.min.js` via unpkg/jsDelivr, or loose on the same Release.
23
+
24
+ ## Use it (npm / bundler)
25
+
26
+ ```ts
27
+ import { Engine } from "@patterkit/runtime";
28
+
29
+ const engine = new Engine(bundle); // bundle = parsed .patterc JSON
30
+ const flow = engine.openFlow("main", { scene: "square" });
31
+
32
+ for (;;) {
33
+ const step = flow.advance();
34
+ if (step.type === "line") console.log(`${step.characterName ?? step.character}: ${step.text}`);
35
+ else if (step.type === "text") console.log(step.text);
36
+ else if (step.type === "choice") { flow.choose(step.options.find((o) => o.eligible)!.id); }
37
+ else if (step.type === "end") break;
38
+ }
39
+ ```
40
+
41
+ `new Engine(bundle, options)` takes `{ rng?, seed?, locale?, world?, replayPromptOnChoose?, closedCaptions? }`:
42
+ - `world` is the host's resolver for `@world` properties (World Properties): `{ get(name), set?(name, value) }`.
43
+ Omit it and the runtime self-backs `@world` from the declared defaults.
44
+ - `locale` plays a non-default language (embedded localisation; an IDs-only bundle ignores it).
45
+ - A string the active locale is missing falls back to the default-locale source,
46
+ flagged `<Untranslated: {id}> {source}` so a partial translation is impossible to miss.
47
+
48
+ Switch language mid-game with **`engine.setLocale("fr")`** (read it back via `engine.locale`):
49
+ subsequent beats / character names / `{@ref}` render in the new locale while the flow's position,
50
+ state, visit counts, and PRNG are untouched - so a game's "language" setting can change live without
51
+ rebuilding the engine or losing the player's place.
52
+
53
+ The above is the **Embedded** build (strings ship inside the `.patterc`). An **IDs-only** build ships no
54
+ strings: `step.text` is the beat **ID** and `step.characterName` is omitted - your game localises the IDs in
55
+ its own system, then applies `{@ref}` replacement with **`flow.interpolate(yourString)`**. See the
56
+ [Localisation guide](https://patterkit.dev/play/localisation/) for both modes across all four runtimes.
57
+
58
+ ## Drop-in (`<script>`)
59
+
60
+ `patterplay.min.js` is a single self-contained, minified IIFE - every dependency
61
+ inlined - for plain HTML pages with no bundler:
62
+
63
+ ```html
64
+ <script src="https://unpkg.com/@patterkit/runtime/dist/patterplay.min.js"></script>
65
+ <script>
66
+ const { Engine } = window.Patterplay; // also: Flow, gameDataFields, gameDataValue, effectiveGameData
67
+ const flow = new Engine(BUNDLE).openFlow("main", { scene: "square" });
68
+ // ...advance() / choose() exactly as above.
69
+ </script>
70
+ ```
71
+
72
+ Build it locally with `npm run build -w @patterkit/runtime` (emits
73
+ `dist/patterplay.min.js`).
74
+
75
+ ## Demos
76
+
77
+ The release zip's `demos/` folder holds two working references (in the repo:
78
+ [examples/drop-in](../../examples/drop-in) and [examples/tour-web](../../examples/tour-web)):
79
+
80
+ - **drop-in** - the smallest possible host: a plain HTML page playing a compiled bundle
81
+ via `patterplay.min.js`. Open `index.html` straight from the unzipped folder.
82
+ - **tour-web** - the full interactive Patter tour in a browser (`node serve.mjs`, open
83
+ the page). The JS counterpart of the demos the Unity, Godot, and Unreal plugins bundle
84
+ (audio-less: the resolver wiring is there, playback is your call).
85
+
86
+ ## Save / load
87
+
88
+ `engine.saveGame()` returns a JSON-serialisable snapshot of the whole game (shared
89
+ state, visit counts, every live flow); `engine.loadGame(blob)` restores it.
90
+ [@patterkit/play-helpers](../play-helpers) wraps these as `serializeState` /
91
+ `deserializeState` with a tagged envelope.