@storylet-studio/play-helpers 0.4.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/README.md +55 -0
- package/dist/index.cjs +1043 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +251 -0
- package/dist/index.d.ts +251 -0
- package/dist/index.js +999 -0
- package/dist/index.js.map +1 -0
- package/dist/storyletengine.min.js +33 -0
- package/dist/storyletengine.min.js.map +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# @storylet-studio/play-helpers
|
|
2
|
+
|
|
3
|
+
The **host-side helpers** for a JavaScript game running
|
|
4
|
+
[`@storylet-studio/runtime`](../runtime). The runtime deals cards; nothing in
|
|
5
|
+
it touches a file, a socket or the DOM. Everything that does lives here, so the
|
|
6
|
+
runtime stays the pure, corpus-pinned thing every port is transliterated from.
|
|
7
|
+
|
|
8
|
+
Each helper has a counterpart in the Unity, Godot and Unreal ports under the
|
|
9
|
+
same name, so an integration reads the same in every engine
|
|
10
|
+
(`scripts/check-runtime-api-parity.mjs` holds all four to it).
|
|
11
|
+
|
|
12
|
+
## What is in it
|
|
13
|
+
|
|
14
|
+
- **The save boundary** - `saveState` / `loadState` over the parsed file,
|
|
15
|
+
`serializeState` / `deserializeState` over text. Patterplay's pairing, so a
|
|
16
|
+
project running both engines saves and loads the same way in each.
|
|
17
|
+
The `.storyletsave` string form of a whole run: the shared state plus every
|
|
18
|
+
flow. Your game decides where the bytes go; this decides what they are.
|
|
19
|
+
- **The state logger** - `createStateLogger`, `snapshotState`, `diffState`.
|
|
20
|
+
A running account of what the story changed, as it changes, for a debug
|
|
21
|
+
overlay or a console. `createKernelStateLogger` is the product-agnostic core
|
|
22
|
+
if you are mounting your own bags.
|
|
23
|
+
- **Live Link** - `createLiveLink`, `applyLiveBundle`. Joins a running game to
|
|
24
|
+
Storyletter over a loopback WebSocket, so the editor's Board shows the real
|
|
25
|
+
run, and a save in the editor swaps the new bundle in underneath it without
|
|
26
|
+
a restart. Attach the **engine**, not a flow: the link discovers your flows
|
|
27
|
+
itself and announces them as they open and close.
|
|
28
|
+
→ [Live Link](https://storylet.studio/play/live-link/)
|
|
29
|
+
- **The examiners** - `createPropertyInspector`, `createBundleInspector`. A
|
|
30
|
+
DOM panel showing live state, the run log and what a bundle offers. The web
|
|
31
|
+
equivalent of the Runtime State window each engine port ships.
|
|
32
|
+
- **`createWorldContainer`** - a ready-made `@world` resolver for a game with
|
|
33
|
+
no state store of its own to bind.
|
|
34
|
+
|
|
35
|
+
## Using it
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { Engine } from "@storylet-studio/runtime";
|
|
39
|
+
import { createLiveLink, serializeState } from "@storylet-studio/play-helpers";
|
|
40
|
+
|
|
41
|
+
const engine = new Engine(bundle, { seed: 7, log: true });
|
|
42
|
+
const flow = engine.openFlow("main");
|
|
43
|
+
|
|
44
|
+
// Debug builds only: inert when no editor is listening, and it never throws
|
|
45
|
+
// into your game.
|
|
46
|
+
const link = createLiveLink({ build: bundle.content.hash, project: "My Game" });
|
|
47
|
+
link.attach(engine);
|
|
48
|
+
|
|
49
|
+
const saved = serializeState(engine); // hand the string to your save system
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The demo in [`demo/`](./demo) wires all of it together against the Hamlet
|
|
53
|
+
bundle and is the shortest complete example.
|
|
54
|
+
|
|
55
|
+
→ Full documentation: [storylet.studio/play/javascript](https://storylet.studio/play/javascript/)
|