yarn-spinner-runner-ts 0.1.2 → 0.1.4-a
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 +102 -88
- package/dist/compile/compiler.js +4 -4
- package/dist/compile/compiler.js.map +1 -1
- package/dist/compile/ir.d.ts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/markup/parser.d.ts +3 -0
- package/dist/markup/parser.js +332 -0
- package/dist/markup/parser.js.map +1 -0
- package/dist/markup/types.d.ts +17 -0
- package/dist/markup/types.js +2 -0
- package/dist/markup/types.js.map +1 -0
- package/dist/model/ast.d.ts +3 -0
- package/dist/parse/parser.js +57 -8
- package/dist/parse/parser.js.map +1 -1
- package/dist/react/DialogueExample.js +13 -10
- package/dist/react/DialogueExample.js.map +1 -1
- package/dist/react/DialogueScene.d.ts +2 -1
- package/dist/react/DialogueScene.js +95 -26
- package/dist/react/DialogueScene.js.map +1 -1
- package/dist/react/DialogueView.d.ts +18 -4
- package/dist/react/DialogueView.js +84 -7
- package/dist/react/DialogueView.js.map +1 -1
- package/dist/react/MarkupRenderer.d.ts +8 -0
- package/dist/react/MarkupRenderer.js +64 -0
- package/dist/react/MarkupRenderer.js.map +1 -0
- package/dist/react/TypingText.d.ts +14 -0
- package/dist/react/TypingText.js +78 -0
- package/dist/react/TypingText.js.map +1 -0
- package/dist/react/useYarnRunner.js +10 -1
- package/dist/react/useYarnRunner.js.map +1 -1
- package/dist/runtime/commands.js +12 -1
- package/dist/runtime/commands.js.map +1 -1
- package/dist/runtime/results.d.ts +3 -0
- package/dist/runtime/runner.d.ts +7 -0
- package/dist/runtime/runner.js +161 -14
- package/dist/runtime/runner.js.map +1 -1
- package/dist/tests/custom_functions.test.d.ts +1 -0
- package/dist/tests/custom_functions.test.js +129 -0
- package/dist/tests/custom_functions.test.js.map +1 -0
- package/dist/tests/markup.test.d.ts +1 -0
- package/dist/tests/markup.test.js +46 -0
- package/dist/tests/markup.test.js.map +1 -0
- package/dist/tests/nodes_lines.test.js +25 -1
- package/dist/tests/nodes_lines.test.js.map +1 -1
- package/dist/tests/options.test.js +30 -1
- package/dist/tests/options.test.js.map +1 -1
- package/dist/tests/story_end.test.d.ts +1 -0
- package/dist/tests/story_end.test.js +37 -0
- package/dist/tests/story_end.test.js.map +1 -0
- package/dist/tests/typing-text.test.d.ts +1 -0
- package/dist/tests/typing-text.test.js +12 -0
- package/dist/tests/typing-text.test.js.map +1 -0
- package/docs/actor-transition.md +34 -0
- package/docs/markup.md +34 -19
- package/docs/scenes-actors-setup.md +1 -0
- package/docs/typing-animation.md +44 -0
- package/eslint.config.cjs +3 -0
- package/examples/browser/index.html +1 -1
- package/examples/browser/main.tsx +0 -2
- package/package.json +1 -1
- package/src/compile/compiler.ts +4 -4
- package/src/compile/ir.ts +3 -2
- package/src/index.ts +3 -0
- package/src/markup/parser.ts +372 -0
- package/src/markup/types.ts +22 -0
- package/src/model/ast.ts +17 -13
- package/src/parse/parser.ts +60 -8
- package/src/react/DialogueExample.tsx +27 -51
- package/src/react/DialogueScene.tsx +143 -44
- package/src/react/DialogueView.tsx +150 -14
- package/src/react/MarkupRenderer.tsx +110 -0
- package/src/react/TypingText.tsx +127 -0
- package/src/react/dialogue.css +26 -13
- package/src/react/useYarnRunner.tsx +13 -1
- package/src/runtime/commands.ts +14 -1
- package/src/runtime/results.ts +3 -1
- package/src/runtime/runner.ts +170 -14
- package/src/tests/custom_functions.test.ts +140 -0
- package/src/tests/markup.test.ts +62 -0
- package/src/tests/nodes_lines.test.ts +35 -1
- package/src/tests/options.test.ts +39 -1
- package/src/tests/story_end.test.ts +42 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { test } from "node:test";
|
|
2
|
-
import { strictEqual } from "node:assert";
|
|
2
|
+
import { strictEqual, ok } from "node:assert";
|
|
3
3
|
import { parseYarn, compile, YarnRunner } from "../index.js";
|
|
4
4
|
|
|
5
5
|
test("options selection", () => {
|
|
@@ -32,3 +32,41 @@ Narrator: Choose one
|
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
test("option markup is exposed", () => {
|
|
38
|
+
const script = `
|
|
39
|
+
title: Start
|
|
40
|
+
---
|
|
41
|
+
Narrator: Choose
|
|
42
|
+
-> [b]Bold[/b]
|
|
43
|
+
Narrator: Bold
|
|
44
|
+
-> [wave intensity=5]Custom[/wave]
|
|
45
|
+
Narrator: Custom
|
|
46
|
+
===
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
const doc = parseYarn(script);
|
|
50
|
+
const ir = compile(doc);
|
|
51
|
+
const runner = new YarnRunner(ir, { startAt: "Start" });
|
|
52
|
+
|
|
53
|
+
runner.advance(); // move to options
|
|
54
|
+
const result = runner.currentResult;
|
|
55
|
+
ok(result && result.type === "options", "Expected options result");
|
|
56
|
+
const options = result!.options;
|
|
57
|
+
ok(options[0].markup, "Expected markup on first option");
|
|
58
|
+
ok(options[1].markup, "Expected markup on second option");
|
|
59
|
+
const boldMarkup = options[0].markup!;
|
|
60
|
+
strictEqual(boldMarkup.text, "Bold");
|
|
61
|
+
ok(
|
|
62
|
+
boldMarkup.segments.some((segment) =>
|
|
63
|
+
segment.wrappers.some((wrapper) => wrapper.name === "b" && wrapper.type === "default")
|
|
64
|
+
),
|
|
65
|
+
"Expected bold wrapper"
|
|
66
|
+
);
|
|
67
|
+
const customWrapper = options[1].markup!.segments
|
|
68
|
+
.flatMap((segment) => segment.wrappers)
|
|
69
|
+
.find((wrapper) => wrapper.name === "wave");
|
|
70
|
+
ok(customWrapper, "Expected custom wrapper on second option");
|
|
71
|
+
strictEqual(customWrapper!.properties.intensity, 5);
|
|
72
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import { ok, strictEqual } from "node:assert";
|
|
3
|
+
import { parseYarn, compile, YarnRunner } from "../index.js";
|
|
4
|
+
|
|
5
|
+
test("onStoryEnd receives variables snapshot", () => {
|
|
6
|
+
const script = `
|
|
7
|
+
title: Start
|
|
8
|
+
---
|
|
9
|
+
Narrator: Beginning
|
|
10
|
+
<<set $score = 42>>
|
|
11
|
+
Narrator: Done
|
|
12
|
+
===
|
|
13
|
+
`;
|
|
14
|
+
let payload: { variables: Readonly<Record<string, unknown>>; storyEnd: true } | undefined;
|
|
15
|
+
const doc = parseYarn(script);
|
|
16
|
+
const ir = compile(doc);
|
|
17
|
+
const runner = new YarnRunner(ir, {
|
|
18
|
+
startAt: "Start",
|
|
19
|
+
onStoryEnd: (info) => {
|
|
20
|
+
payload = info;
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
let result = runner.currentResult;
|
|
25
|
+
ok(result && result.type === "text");
|
|
26
|
+
|
|
27
|
+
runner.advance();
|
|
28
|
+
result = runner.currentResult;
|
|
29
|
+
ok(result && result.type === "command");
|
|
30
|
+
|
|
31
|
+
runner.advance();
|
|
32
|
+
result = runner.currentResult;
|
|
33
|
+
ok(result && result.type === "text");
|
|
34
|
+
|
|
35
|
+
runner.advance();
|
|
36
|
+
result = runner.currentResult;
|
|
37
|
+
ok(result && result.isDialogueEnd === true);
|
|
38
|
+
|
|
39
|
+
strictEqual(payload?.storyEnd, true);
|
|
40
|
+
const variables = payload?.variables ?? {};
|
|
41
|
+
strictEqual((variables as Record<string, unknown>)["score"], 42);
|
|
42
|
+
});
|