yarn-spinner-runner-ts 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/README.md +180 -0
- package/dist/compile/compiler.d.ts +9 -0
- package/dist/compile/compiler.js +172 -0
- package/dist/compile/compiler.js.map +1 -0
- package/dist/compile/ir.d.ts +47 -0
- package/dist/compile/ir.js +2 -0
- package/dist/compile/ir.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/model/ast.d.ts +72 -0
- package/dist/model/ast.js +2 -0
- package/dist/model/ast.js.map +1 -0
- package/dist/parse/lexer.d.ts +7 -0
- package/dist/parse/lexer.js +78 -0
- package/dist/parse/lexer.js.map +1 -0
- package/dist/parse/parser.d.ts +4 -0
- package/dist/parse/parser.js +433 -0
- package/dist/parse/parser.js.map +1 -0
- package/dist/runtime/commands.d.ts +31 -0
- package/dist/runtime/commands.js +157 -0
- package/dist/runtime/commands.js.map +1 -0
- package/dist/runtime/evaluator.d.ts +52 -0
- package/dist/runtime/evaluator.js +309 -0
- package/dist/runtime/evaluator.js.map +1 -0
- package/dist/runtime/results.d.ts +22 -0
- package/dist/runtime/results.js +2 -0
- package/dist/runtime/results.js.map +1 -0
- package/dist/runtime/runner.d.ts +63 -0
- package/dist/runtime/runner.js +456 -0
- package/dist/runtime/runner.js.map +1 -0
- package/dist/tests/full_featured.test.d.ts +1 -0
- package/dist/tests/full_featured.test.js +130 -0
- package/dist/tests/full_featured.test.js.map +1 -0
- package/dist/tests/index.test.d.ts +1 -0
- package/dist/tests/index.test.js +30 -0
- package/dist/tests/index.test.js.map +1 -0
- package/dist/tests/jump_detour.test.d.ts +1 -0
- package/dist/tests/jump_detour.test.js +47 -0
- package/dist/tests/jump_detour.test.js.map +1 -0
- package/dist/tests/nodes_lines.test.d.ts +1 -0
- package/dist/tests/nodes_lines.test.js +23 -0
- package/dist/tests/nodes_lines.test.js.map +1 -0
- package/dist/tests/once.test.d.ts +1 -0
- package/dist/tests/once.test.js +29 -0
- package/dist/tests/once.test.js.map +1 -0
- package/dist/tests/options.test.d.ts +1 -0
- package/dist/tests/options.test.js +32 -0
- package/dist/tests/options.test.js.map +1 -0
- package/dist/tests/variables_flow_cmds.test.d.ts +1 -0
- package/dist/tests/variables_flow_cmds.test.js +30 -0
- package/dist/tests/variables_flow_cmds.test.js.map +1 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/docs/commands.md +21 -0
- package/docs/compatibility-checklist.md +77 -0
- package/docs/css-attribute.md +47 -0
- package/docs/detour.md +24 -0
- package/docs/enums.md +25 -0
- package/docs/flow-control.md +25 -0
- package/docs/functions.md +20 -0
- package/docs/jumps.md +24 -0
- package/docs/line-groups.md +21 -0
- package/docs/lines-nodes-and-options.md +30 -0
- package/docs/logic-and-variables.md +25 -0
- package/docs/markup.md +19 -0
- package/docs/node-groups.md +13 -0
- package/docs/once.md +21 -0
- package/docs/options.md +45 -0
- package/docs/saliency.md +25 -0
- package/docs/scenes-actors-setup.md +195 -0
- package/docs/scenes.md +64 -0
- package/docs/shadow-lines.md +18 -0
- package/docs/smart-variables.md +19 -0
- package/docs/storylets-and-saliency-a-primer.md +14 -0
- package/docs/tags-metadata.md +18 -0
- package/eslint.config.cjs +33 -0
- package/examples/browser/README.md +40 -0
- package/examples/browser/index.html +23 -0
- package/examples/browser/main.tsx +16 -0
- package/examples/browser/vite.config.ts +22 -0
- package/examples/react/DialogueExample.tsx +2 -0
- package/examples/react/DialogueView.tsx +2 -0
- package/examples/react/useYarnRunner.tsx +2 -0
- package/examples/scenes/scenes.yaml +10 -0
- package/examples/yarn/full_featured.yarn +43 -0
- package/package.json +55 -0
- package/src/compile/compiler.ts +183 -0
- package/src/compile/ir.ts +28 -0
- package/src/index.ts +17 -0
- package/src/model/ast.ts +93 -0
- package/src/parse/lexer.ts +108 -0
- package/src/parse/parser.ts +435 -0
- package/src/react/DialogueExample.tsx +149 -0
- package/src/react/DialogueScene.tsx +107 -0
- package/src/react/DialogueView.tsx +160 -0
- package/src/react/dialogue.css +181 -0
- package/src/react/useYarnRunner.tsx +33 -0
- package/src/runtime/commands.ts +183 -0
- package/src/runtime/evaluator.ts +327 -0
- package/src/runtime/results.ts +27 -0
- package/src/runtime/runner.ts +480 -0
- package/src/scene/parser.ts +83 -0
- package/src/scene/types.ts +17 -0
- package/src/tests/full_featured.test.ts +131 -0
- package/src/tests/index.test.ts +34 -0
- package/src/tests/jump_detour.test.ts +47 -0
- package/src/tests/nodes_lines.test.ts +27 -0
- package/src/tests/once.test.ts +32 -0
- package/src/tests/options.test.ts +34 -0
- package/src/tests/variables_flow_cmds.test.ts +33 -0
- package/src/types.ts +4 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
import { ExpressionEvaluator } from "./evaluator.js";
|
|
2
|
+
import { CommandHandler, parseCommand } from "./commands.js";
|
|
3
|
+
const globalOnceSeen = new Set();
|
|
4
|
+
const globalNodeGroupOnceSeen = new Set(); // Track "once" nodes in groups: "title#index"
|
|
5
|
+
export class YarnRunner {
|
|
6
|
+
constructor(program, opts) {
|
|
7
|
+
this.onceSeen = globalOnceSeen;
|
|
8
|
+
this.nodeGroupOnceSeen = globalNodeGroupOnceSeen;
|
|
9
|
+
this.visitCounts = {};
|
|
10
|
+
this.ip = 0; // instruction pointer within node
|
|
11
|
+
this.currentNodeIndex = -1; // Index of selected node in group (-1 if single node)
|
|
12
|
+
this.callStack = [];
|
|
13
|
+
this.currentResult = null;
|
|
14
|
+
this.history = [];
|
|
15
|
+
this.program = program;
|
|
16
|
+
this.variables = { ...(opts.variables ?? {}) };
|
|
17
|
+
this.functions = {
|
|
18
|
+
// Default conversion helpers
|
|
19
|
+
string: (v) => String(v ?? ""),
|
|
20
|
+
number: (v) => Number(v),
|
|
21
|
+
bool: (v) => Boolean(v),
|
|
22
|
+
visited: (nodeName) => {
|
|
23
|
+
const name = String(nodeName ?? "");
|
|
24
|
+
return (this.visitCounts[name] ?? 0) > 0;
|
|
25
|
+
},
|
|
26
|
+
visited_count: (nodeName) => {
|
|
27
|
+
const name = String(nodeName ?? "");
|
|
28
|
+
return this.visitCounts[name] ?? 0;
|
|
29
|
+
},
|
|
30
|
+
format_invariant: (n) => {
|
|
31
|
+
const num = Number(n);
|
|
32
|
+
if (!isFinite(num))
|
|
33
|
+
return "0";
|
|
34
|
+
return new Intl.NumberFormat("en-US", { useGrouping: false, maximumFractionDigits: 20 }).format(num);
|
|
35
|
+
},
|
|
36
|
+
random: () => Math.random(),
|
|
37
|
+
random_range: (a, b) => {
|
|
38
|
+
const x = Number(a), y = Number(b);
|
|
39
|
+
const min = Math.min(x, y);
|
|
40
|
+
const max = Math.max(x, y);
|
|
41
|
+
return min + Math.random() * (max - min);
|
|
42
|
+
},
|
|
43
|
+
dice: (sides) => {
|
|
44
|
+
const s = Math.max(1, Math.floor(Number(sides)) || 1);
|
|
45
|
+
return Math.floor(Math.random() * s) + 1;
|
|
46
|
+
},
|
|
47
|
+
min: (a, b) => Math.min(Number(a), Number(b)),
|
|
48
|
+
max: (a, b) => Math.max(Number(a), Number(b)),
|
|
49
|
+
round: (n) => Math.round(Number(n)),
|
|
50
|
+
round_places: (n, places) => {
|
|
51
|
+
const p = Math.max(0, Math.floor(Number(places)) || 0);
|
|
52
|
+
const factor = Math.pow(10, p);
|
|
53
|
+
return Math.round(Number(n) * factor) / factor;
|
|
54
|
+
},
|
|
55
|
+
floor: (n) => Math.floor(Number(n)),
|
|
56
|
+
ceil: (n) => Math.ceil(Number(n)),
|
|
57
|
+
inc: (n) => {
|
|
58
|
+
const v = Number(n);
|
|
59
|
+
return Number.isInteger(v) ? v + 1 : Math.ceil(v);
|
|
60
|
+
},
|
|
61
|
+
dec: (n) => {
|
|
62
|
+
const v = Number(n);
|
|
63
|
+
return Number.isInteger(v) ? v - 1 : Math.floor(v);
|
|
64
|
+
},
|
|
65
|
+
decimal: (n) => {
|
|
66
|
+
const v = Number(n);
|
|
67
|
+
return Math.abs(v - Math.trunc(v));
|
|
68
|
+
},
|
|
69
|
+
int: (n) => Math.trunc(Number(n)),
|
|
70
|
+
...(opts.functions ?? {}),
|
|
71
|
+
};
|
|
72
|
+
this.handleCommand = opts.handleCommand;
|
|
73
|
+
this.evaluator = new ExpressionEvaluator(this.variables, this.functions, this.program.enums);
|
|
74
|
+
this.commandHandler = opts.commandHandler ?? new CommandHandler(this.variables);
|
|
75
|
+
this.nodeTitle = opts.startAt;
|
|
76
|
+
this.step();
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get the current node title (may resolve to a node group).
|
|
80
|
+
*/
|
|
81
|
+
getCurrentNodeTitle() {
|
|
82
|
+
return this.nodeTitle;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Resolve a node title to an actual node (handling node groups).
|
|
86
|
+
*/
|
|
87
|
+
resolveNode(title) {
|
|
88
|
+
const nodeOrGroup = this.program.nodes[title];
|
|
89
|
+
if (!nodeOrGroup)
|
|
90
|
+
throw new Error(`Node ${title} not found`);
|
|
91
|
+
// If it's a single node, return it
|
|
92
|
+
if (!("nodes" in nodeOrGroup)) {
|
|
93
|
+
this.currentNodeIndex = -1;
|
|
94
|
+
return nodeOrGroup;
|
|
95
|
+
}
|
|
96
|
+
// It's a node group - select the first matching node based on when conditions
|
|
97
|
+
const group = nodeOrGroup;
|
|
98
|
+
for (let i = 0; i < group.nodes.length; i++) {
|
|
99
|
+
const candidate = group.nodes[i];
|
|
100
|
+
if (this.evaluateWhenConditions(candidate.when, title, i)) {
|
|
101
|
+
this.currentNodeIndex = i;
|
|
102
|
+
// If "once" condition, mark as seen immediately
|
|
103
|
+
if (candidate.when?.includes("once")) {
|
|
104
|
+
this.markNodeGroupOnceSeen(title, i);
|
|
105
|
+
}
|
|
106
|
+
return candidate;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// No matching node found - throw error or return first? Docs suggest error if no match
|
|
110
|
+
throw new Error(`No matching node found in group ${title}`);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Evaluate when conditions for a node in a group.
|
|
114
|
+
*/
|
|
115
|
+
evaluateWhenConditions(conditions, nodeTitle, nodeIndex) {
|
|
116
|
+
if (!conditions || conditions.length === 0) {
|
|
117
|
+
// No when condition - available by default (but should not happen in groups)
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
// All conditions must be true (AND logic)
|
|
121
|
+
for (const condition of conditions) {
|
|
122
|
+
const trimmed = condition.trim();
|
|
123
|
+
if (trimmed === "once") {
|
|
124
|
+
// Check if this node has been visited once
|
|
125
|
+
const onceKey = `${nodeTitle}#${nodeIndex}`;
|
|
126
|
+
if (this.nodeGroupOnceSeen.has(onceKey)) {
|
|
127
|
+
return false; // Already seen once
|
|
128
|
+
}
|
|
129
|
+
// Will mark as seen when node is entered
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (trimmed === "always") {
|
|
133
|
+
// Always available
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
// Otherwise, treat as expression (e.g., "$has_sword")
|
|
137
|
+
if (!this.evaluator.evaluate(trimmed)) {
|
|
138
|
+
return false; // Condition failed
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return true; // All conditions passed
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Mark a node group node as seen (for "once" condition).
|
|
145
|
+
*/
|
|
146
|
+
markNodeGroupOnceSeen(nodeTitle, nodeIndex) {
|
|
147
|
+
const onceKey = `${nodeTitle}#${nodeIndex}`;
|
|
148
|
+
this.nodeGroupOnceSeen.add(onceKey);
|
|
149
|
+
}
|
|
150
|
+
advance(optionIndex) {
|
|
151
|
+
// If awaiting option selection, consume chosen option by pushing its block
|
|
152
|
+
if (this.currentResult?.type === "options") {
|
|
153
|
+
if (optionIndex == null)
|
|
154
|
+
throw new Error("Option index required");
|
|
155
|
+
// Resolve to actual node (handles groups)
|
|
156
|
+
const node = this.resolveNode(this.nodeTitle);
|
|
157
|
+
// We encoded options at ip-1; locate it
|
|
158
|
+
const ins = node.instructions[this.ip - 1];
|
|
159
|
+
if (ins?.op !== "options")
|
|
160
|
+
throw new Error("Invalid options state");
|
|
161
|
+
const chosen = ins.options[optionIndex];
|
|
162
|
+
if (!chosen)
|
|
163
|
+
throw new Error("Invalid option index");
|
|
164
|
+
// Push a block frame that we will resume across advances
|
|
165
|
+
this.callStack.push({ kind: "block", title: this.nodeTitle, ip: this.ip, block: chosen.block, idx: 0 });
|
|
166
|
+
if (this.resumeBlock())
|
|
167
|
+
return;
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
// If we have a pending block, resume it first
|
|
171
|
+
if (this.resumeBlock())
|
|
172
|
+
return;
|
|
173
|
+
this.step();
|
|
174
|
+
}
|
|
175
|
+
interpolate(text) {
|
|
176
|
+
return text.replace(/\{([^}]+)\}/g, (_m, expr) => {
|
|
177
|
+
try {
|
|
178
|
+
const val = this.evaluator.evaluateExpression(String(expr));
|
|
179
|
+
return String(val ?? "");
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return "";
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
resumeBlock() {
|
|
187
|
+
const top = this.callStack[this.callStack.length - 1];
|
|
188
|
+
if (!top || top.kind !== "block")
|
|
189
|
+
return false;
|
|
190
|
+
// Execute from stored idx until we emit one result or finish block
|
|
191
|
+
while (true) {
|
|
192
|
+
const ins = top.block[top.idx++];
|
|
193
|
+
if (!ins) {
|
|
194
|
+
// finished block; pop and continue main step
|
|
195
|
+
this.callStack.pop();
|
|
196
|
+
this.step();
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
switch (ins.op) {
|
|
200
|
+
case "line":
|
|
201
|
+
this.emit({ type: "text", text: this.interpolate(ins.text), speaker: ins.speaker, tags: ins.tags, isDialogueEnd: false });
|
|
202
|
+
return true;
|
|
203
|
+
case "command": {
|
|
204
|
+
try {
|
|
205
|
+
const parsed = parseCommand(ins.content);
|
|
206
|
+
this.commandHandler.execute(parsed, this.evaluator).catch(() => { });
|
|
207
|
+
if (this.handleCommand)
|
|
208
|
+
this.handleCommand(ins.content, parsed);
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
if (this.handleCommand)
|
|
212
|
+
this.handleCommand(ins.content);
|
|
213
|
+
}
|
|
214
|
+
this.emit({ type: "command", command: ins.content, isDialogueEnd: false });
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
case "options": {
|
|
218
|
+
this.emit({ type: "options", options: ins.options.map((o) => ({ text: o.text, tags: o.tags })), isDialogueEnd: false });
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
case "if": {
|
|
222
|
+
const branch = ins.branches.find((b) => (b.condition ? this.evaluator.evaluate(b.condition) : true));
|
|
223
|
+
if (branch) {
|
|
224
|
+
// Push nested block at current top position (resume after)
|
|
225
|
+
this.callStack.push({ kind: "block", title: this.nodeTitle, ip: this.ip, block: branch.block, idx: 0 });
|
|
226
|
+
return this.resumeBlock();
|
|
227
|
+
}
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
case "once": {
|
|
231
|
+
if (!this.onceSeen.has(ins.id)) {
|
|
232
|
+
this.onceSeen.add(ins.id);
|
|
233
|
+
this.callStack.push({ kind: "block", title: this.nodeTitle, ip: this.ip, block: ins.block, idx: 0 });
|
|
234
|
+
return this.resumeBlock();
|
|
235
|
+
}
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
case "jump": {
|
|
239
|
+
this.nodeTitle = ins.target;
|
|
240
|
+
this.ip = 0;
|
|
241
|
+
this.step();
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
case "detour": {
|
|
245
|
+
this.callStack.push({ kind: "detour", title: top.title, ip: top.ip });
|
|
246
|
+
this.nodeTitle = ins.target;
|
|
247
|
+
this.ip = 0;
|
|
248
|
+
this.step();
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
step() {
|
|
255
|
+
while (true) {
|
|
256
|
+
const resolved = this.resolveNode(this.nodeTitle);
|
|
257
|
+
const currentNode = { title: this.nodeTitle, instructions: resolved.instructions };
|
|
258
|
+
const ins = currentNode.instructions[this.ip];
|
|
259
|
+
if (!ins) {
|
|
260
|
+
// Node ended
|
|
261
|
+
this.visitCounts[this.nodeTitle] = (this.visitCounts[this.nodeTitle] ?? 0) + 1;
|
|
262
|
+
this.emit({ type: "text", text: "", isDialogueEnd: true });
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
this.ip++;
|
|
266
|
+
switch (ins.op) {
|
|
267
|
+
case "line":
|
|
268
|
+
this.emit({ type: "text", text: this.interpolate(ins.text), speaker: ins.speaker, tags: ins.tags, isDialogueEnd: this.lookaheadIsEnd() });
|
|
269
|
+
return;
|
|
270
|
+
case "command": {
|
|
271
|
+
try {
|
|
272
|
+
const parsed = parseCommand(ins.content);
|
|
273
|
+
this.commandHandler.execute(parsed, this.evaluator).catch(() => { });
|
|
274
|
+
if (this.handleCommand)
|
|
275
|
+
this.handleCommand(ins.content, parsed);
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
if (this.handleCommand)
|
|
279
|
+
this.handleCommand(ins.content);
|
|
280
|
+
}
|
|
281
|
+
this.emit({ type: "command", command: ins.content, isDialogueEnd: this.lookaheadIsEnd() });
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
case "jump": {
|
|
285
|
+
// Exiting current node due to jump
|
|
286
|
+
this.visitCounts[this.nodeTitle] = (this.visitCounts[this.nodeTitle] ?? 0) + 1;
|
|
287
|
+
this.nodeTitle = ins.target;
|
|
288
|
+
this.ip = 0;
|
|
289
|
+
this.currentNodeIndex = -1; // Reset node index for new resolution
|
|
290
|
+
// resolveNode will handle node groups
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
case "detour": {
|
|
294
|
+
// Save return position, jump to target node, return when it ends
|
|
295
|
+
this.callStack.push({ kind: "detour", title: this.nodeTitle, ip: this.ip });
|
|
296
|
+
this.nodeTitle = ins.target;
|
|
297
|
+
this.ip = 0;
|
|
298
|
+
this.currentNodeIndex = -1; // Reset node index for new resolution
|
|
299
|
+
// resolveNode will handle node groups
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
case "options": {
|
|
303
|
+
this.emit({ type: "options", options: ins.options.map((o) => ({ text: o.text, tags: o.tags, css: o.css })), isDialogueEnd: this.lookaheadIsEnd() });
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
case "if": {
|
|
307
|
+
const branch = ins.branches.find((b) => (b.condition ? this.evaluator.evaluate(b.condition) : true));
|
|
308
|
+
if (branch) {
|
|
309
|
+
this.callStack.push({ kind: "block", title: this.nodeTitle, ip: this.ip, block: branch.block, idx: 0 });
|
|
310
|
+
if (this.resumeBlock())
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
case "once": {
|
|
316
|
+
if (!this.onceSeen.has(ins.id)) {
|
|
317
|
+
this.onceSeen.add(ins.id);
|
|
318
|
+
this.callStack.push({ kind: "block", title: this.nodeTitle, ip: this.ip, block: ins.block, idx: 0 });
|
|
319
|
+
if (this.resumeBlock())
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
executeBlock(block) {
|
|
328
|
+
// Execute instructions of block, then resume
|
|
329
|
+
const saved = { title: this.nodeTitle, ip: this.ip };
|
|
330
|
+
this.nodeTitle = block.title;
|
|
331
|
+
const tempIpStart = 0;
|
|
332
|
+
const tempNode = { title: block.title, instructions: block.instructions };
|
|
333
|
+
// Use a temporary node context
|
|
334
|
+
const restore = () => {
|
|
335
|
+
this.nodeTitle = saved.title;
|
|
336
|
+
this.ip = saved.ip;
|
|
337
|
+
};
|
|
338
|
+
// Step through block, emitting first result
|
|
339
|
+
let idx = tempIpStart;
|
|
340
|
+
while (true) {
|
|
341
|
+
const ins = tempNode.instructions[idx++];
|
|
342
|
+
if (!ins)
|
|
343
|
+
break;
|
|
344
|
+
switch (ins.op) {
|
|
345
|
+
case "line":
|
|
346
|
+
this.emit({ type: "text", text: ins.text, speaker: ins.speaker, isDialogueEnd: false });
|
|
347
|
+
restore();
|
|
348
|
+
return;
|
|
349
|
+
case "command":
|
|
350
|
+
try {
|
|
351
|
+
const parsed = parseCommand(ins.content);
|
|
352
|
+
this.commandHandler.execute(parsed, this.evaluator).catch(() => { });
|
|
353
|
+
if (this.handleCommand)
|
|
354
|
+
this.handleCommand(ins.content, parsed);
|
|
355
|
+
}
|
|
356
|
+
catch {
|
|
357
|
+
if (this.handleCommand)
|
|
358
|
+
this.handleCommand(ins.content);
|
|
359
|
+
}
|
|
360
|
+
this.emit({ type: "command", command: ins.content, isDialogueEnd: false });
|
|
361
|
+
restore();
|
|
362
|
+
return;
|
|
363
|
+
case "options":
|
|
364
|
+
this.emit({ type: "options", options: ins.options.map((o) => ({ text: o.text })), isDialogueEnd: false });
|
|
365
|
+
// Maintain context that options belong to main node at ip-1
|
|
366
|
+
restore();
|
|
367
|
+
return;
|
|
368
|
+
case "if": {
|
|
369
|
+
const branch = ins.branches.find((b) => (b.condition ? this.evaluator.evaluate(b.condition) : true));
|
|
370
|
+
if (branch) {
|
|
371
|
+
// enqueue nested block and resume from main context
|
|
372
|
+
this.callStack.push({ kind: "block", title: this.nodeTitle, ip: this.ip, block: branch.block, idx: 0 });
|
|
373
|
+
restore();
|
|
374
|
+
if (this.resumeBlock())
|
|
375
|
+
return;
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
case "once": {
|
|
381
|
+
if (!this.onceSeen.has(ins.id)) {
|
|
382
|
+
this.onceSeen.add(ins.id);
|
|
383
|
+
this.callStack.push({ kind: "block", title: this.nodeTitle, ip: this.ip, block: ins.block, idx: 0 });
|
|
384
|
+
restore();
|
|
385
|
+
if (this.resumeBlock())
|
|
386
|
+
return;
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
case "jump": {
|
|
392
|
+
this.nodeTitle = ins.target;
|
|
393
|
+
this.ip = 0;
|
|
394
|
+
this.step();
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
case "detour": {
|
|
398
|
+
this.callStack.push({ kind: "detour", title: saved.title, ip: saved.ip });
|
|
399
|
+
this.nodeTitle = ins.target;
|
|
400
|
+
this.ip = 0;
|
|
401
|
+
this.step();
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
// Block produced no output; resume
|
|
407
|
+
restore();
|
|
408
|
+
this.step();
|
|
409
|
+
}
|
|
410
|
+
lookaheadIsEnd() {
|
|
411
|
+
// Check if current node has more emit-worthy instructions
|
|
412
|
+
const node = this.resolveNode(this.nodeTitle);
|
|
413
|
+
for (let k = this.ip; k < node.instructions.length; k++) {
|
|
414
|
+
const op = node.instructions[k]?.op;
|
|
415
|
+
if (!op)
|
|
416
|
+
break;
|
|
417
|
+
if (op === "line" || op === "options" || op === "command" || op === "if" || op === "once")
|
|
418
|
+
return false;
|
|
419
|
+
if (op === "jump" || op === "detour")
|
|
420
|
+
return false;
|
|
421
|
+
}
|
|
422
|
+
// Node is ending - mark as end (will trigger detour return if callStack exists)
|
|
423
|
+
return true;
|
|
424
|
+
}
|
|
425
|
+
emit(res) {
|
|
426
|
+
this.currentResult = res;
|
|
427
|
+
this.history.push(res);
|
|
428
|
+
// If we ended a detour node, return to caller after emitting last result
|
|
429
|
+
// Position is restored here, but we wait for next advance() to continue
|
|
430
|
+
if (res.isDialogueEnd && this.callStack.length > 0) {
|
|
431
|
+
const frame = this.callStack.pop();
|
|
432
|
+
this.nodeTitle = frame.title;
|
|
433
|
+
this.ip = frame.ip;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Get the current variable store (read-only view).
|
|
438
|
+
*/
|
|
439
|
+
getVariables() {
|
|
440
|
+
return { ...this.variables };
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Get variable value.
|
|
444
|
+
*/
|
|
445
|
+
getVariable(name) {
|
|
446
|
+
return this.variables[name];
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Set variable value.
|
|
450
|
+
*/
|
|
451
|
+
setVariable(name, value) {
|
|
452
|
+
this.variables[name] = value;
|
|
453
|
+
this.evaluator.setVariable(name, value);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runtime/runner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAU7D,MAAM,cAAc,GAAG,IAAI,GAAG,EAAU,CAAC;AACzC,MAAM,uBAAuB,GAAG,IAAI,GAAG,EAAU,CAAC,CAAC,8CAA8C;AAEjG,MAAM,OAAO,UAAU;IAsBrB,YAAY,OAAkB,EAAE,IAAmB;QAflC,aAAQ,GAAG,cAAc,CAAC;QAC1B,sBAAiB,GAAG,uBAAuB,CAAC;QAC5C,gBAAW,GAA2B,EAAE,CAAC;QAGlD,OAAE,GAAG,CAAC,CAAC,CAAC,kCAAkC;QAC1C,qBAAgB,GAAW,CAAC,CAAC,CAAC,CAAC,sDAAsD;QACrF,cAAS,GAGb,EAAE,CAAC;QAEP,kBAAa,GAAyB,IAAI,CAAC;QAC3C,YAAO,GAAoB,EAAE,CAAC;QAG5B,IAAI,CAAC,OAAO,GAAG,OAAO,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AI,EAAE,KAAK,MAAM;gBAAE,OAAO,KAAK,CAAC;YACxG,IAAI,EAAE,KAAK,MAAM,IAAI,EAAE,KAAK,QAAQ;gBAAE,OAAO,KAAK,CAAC;QACrD,CAAC;QACD,gFAAgF;QAChF,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,IAAI,CAAC,GAAkB;QAC7B,IAAI,CAAC,aAAa,GAAG,GAAG,CAAC;QACzB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvB,yEAAyE;QACzE,wEAAwE;QACxE,IAAI,GAAG,CAAC,aAAa,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACnD,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,EAAG,CAAC;YACpC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC;YAC7B,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;QACrB,CAAC;IACH,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,WAAW,CAAC,IAAY;QACtB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,WAAW,CAAC,IAAY,EAAE,KAAc;QACtC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAC7B,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import { strictEqual } from "node:assert";
|
|
3
|
+
import { parseYarn, compile, YarnRunner } from "../index.js";
|
|
4
|
+
test("full featured Yarn script with all elements", () => {
|
|
5
|
+
const script = `
|
|
6
|
+
title: Start
|
|
7
|
+
group: Demo
|
|
8
|
+
color: blue
|
|
9
|
+
---
|
|
10
|
+
Narrator: Welcome to the comprehensive Yarn test.
|
|
11
|
+
<<set score 7>>
|
|
12
|
+
{if score >= 10}
|
|
13
|
+
Narrator: High score branch.
|
|
14
|
+
{else if score >= 5}
|
|
15
|
+
Narrator: Medium score branch.
|
|
16
|
+
{else}
|
|
17
|
+
Narrator: Low score branch.
|
|
18
|
+
{endif}
|
|
19
|
+
|
|
20
|
+
<<once>>
|
|
21
|
+
Narrator: This once block should only appear the first time.
|
|
22
|
+
<<endonce>>
|
|
23
|
+
|
|
24
|
+
-> Take the main path
|
|
25
|
+
Narrator: Proceeding on the main path.
|
|
26
|
+
<<jump NextScene>>
|
|
27
|
+
-> Explore a detour
|
|
28
|
+
Narrator: Let's explore a detour first.
|
|
29
|
+
<<detour AsideInfo>>
|
|
30
|
+
Narrator: Back from detour.
|
|
31
|
+
<<jump NextScene>>
|
|
32
|
+
===
|
|
33
|
+
|
|
34
|
+
title: NextScene
|
|
35
|
+
group: Demo
|
|
36
|
+
---
|
|
37
|
+
Narrator: You have arrived in the next scene.
|
|
38
|
+
-> Ask about features
|
|
39
|
+
Player: What can this system do?
|
|
40
|
+
Narrator: It supports options, conditions, once, jump, and detour.
|
|
41
|
+
-> Finish
|
|
42
|
+
Narrator: Ending the scene.
|
|
43
|
+
===
|
|
44
|
+
|
|
45
|
+
title: AsideInfo
|
|
46
|
+
group: Demo
|
|
47
|
+
---
|
|
48
|
+
Narrator: This is detour content.
|
|
49
|
+
===
|
|
50
|
+
`;
|
|
51
|
+
const doc = parseYarn(script);
|
|
52
|
+
const ir = compile(doc);
|
|
53
|
+
// First run: once content should appear
|
|
54
|
+
let runner = new YarnRunner(ir, { startAt: "Start" });
|
|
55
|
+
// Welcome text
|
|
56
|
+
const a = runner.currentResult;
|
|
57
|
+
strictEqual(a.type, "text");
|
|
58
|
+
if (a.type === "text")
|
|
59
|
+
strictEqual(/Welcome/.test(a.text), true, "Should show welcome");
|
|
60
|
+
runner.advance();
|
|
61
|
+
// set command result
|
|
62
|
+
const b = runner.currentResult;
|
|
63
|
+
strictEqual(b.type, "command", "Should emit command");
|
|
64
|
+
runner.advance();
|
|
65
|
+
// Medium score branch (score is 7, >= 5 but < 10)
|
|
66
|
+
const c = runner.currentResult;
|
|
67
|
+
strictEqual(c.type, "text");
|
|
68
|
+
if (c.type === "text")
|
|
69
|
+
strictEqual(/Medium score branch/.test(c.text), true, "Should take medium branch");
|
|
70
|
+
runner.advance();
|
|
71
|
+
// Once block content
|
|
72
|
+
const d = runner.currentResult;
|
|
73
|
+
strictEqual(d.type, "text");
|
|
74
|
+
if (d.type === "text")
|
|
75
|
+
strictEqual(/This once block should only appear the first time\./.test(d.text), true, "Once block should appear first time");
|
|
76
|
+
runner.advance();
|
|
77
|
+
// Options
|
|
78
|
+
const e = runner.currentResult;
|
|
79
|
+
strictEqual(e.type, "options", "Should show options");
|
|
80
|
+
if (e.type === "options")
|
|
81
|
+
strictEqual(e.options.length, 2, "Should have 2 options");
|
|
82
|
+
// Choose detour path (index 1)
|
|
83
|
+
runner.advance(1);
|
|
84
|
+
// Body text before detour
|
|
85
|
+
const f = runner.currentResult;
|
|
86
|
+
strictEqual(f.type, "text");
|
|
87
|
+
if (f.type === "text")
|
|
88
|
+
strictEqual(/Let's explore a detour first/.test(f.text), true, "Should show option body");
|
|
89
|
+
runner.advance(); // detour executes
|
|
90
|
+
// Detour content should be emitted
|
|
91
|
+
const g = runner.currentResult;
|
|
92
|
+
strictEqual(g.type, "text");
|
|
93
|
+
if (g.type === "text")
|
|
94
|
+
strictEqual(/This is detour content/.test(g.text), true, "Should enter detour");
|
|
95
|
+
runner.advance(); // return from detour
|
|
96
|
+
// After detour, should continue with next line
|
|
97
|
+
const h = runner.currentResult;
|
|
98
|
+
strictEqual(h.type, "text");
|
|
99
|
+
if (h.type === "text")
|
|
100
|
+
strictEqual(/Back from detour/.test(h.text), true, "Should return from detour");
|
|
101
|
+
runner.advance(); // jump executes
|
|
102
|
+
// NextScene arrival
|
|
103
|
+
const i = runner.currentResult;
|
|
104
|
+
strictEqual(i.type, "text");
|
|
105
|
+
if (i.type === "text")
|
|
106
|
+
strictEqual(/arrived in the next scene/.test(i.text), true, "Should jump to NextScene");
|
|
107
|
+
runner.advance();
|
|
108
|
+
// Options in NextScene
|
|
109
|
+
const j = runner.currentResult;
|
|
110
|
+
strictEqual(j.type, "options", "Should show options in NextScene");
|
|
111
|
+
if (j.type === "options")
|
|
112
|
+
strictEqual(j.options.length, 2, "Should have 2 options in NextScene");
|
|
113
|
+
// Second run: once block should be skipped
|
|
114
|
+
runner = new YarnRunner(ir, { startAt: "Start" });
|
|
115
|
+
const k = runner.currentResult;
|
|
116
|
+
strictEqual(k.type, "text");
|
|
117
|
+
if (k.type === "text")
|
|
118
|
+
strictEqual(/Welcome/.test(k.text), true, "Welcome should appear");
|
|
119
|
+
runner.advance(); // command
|
|
120
|
+
runner.advance(); // branch line
|
|
121
|
+
// Should skip once and show options immediately after branch
|
|
122
|
+
let l = runner.currentResult;
|
|
123
|
+
if (l.type === "text") {
|
|
124
|
+
// Advance one more time in case an intermediate text was emitted
|
|
125
|
+
runner.advance();
|
|
126
|
+
l = runner.currentResult;
|
|
127
|
+
}
|
|
128
|
+
strictEqual(l.type, "options", "Once should be skipped on second run");
|
|
129
|
+
});
|
|
130
|
+
//# sourceMappingURL=full_featured.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"full_featured.test.js","sourceRoot":"","sources":["../../src/tests/full_featured.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE7D,IAAI,CAAC,6CAA6C,EAAE,GAAG,EA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CAAC,UAAU;IAC5B,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,cAAc;IAChC,6DAA6D;IAC7D,IAAI,CAAC,GAAG,MAAM,CAAC,aAAc,CAAC;IAC9B,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACtB,iEAAiE;QACjE,MAAM,CAAC,OAAO,EAAE,CAAC;QACjB,CAAC,GAAG,MAAM,CAAC,aAAc,CAAC;IAC5B,CAAC;IACD,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,sCAAsC,CAAC,CAAC;AACzE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import { strictEqual } from "node:assert";
|
|
3
|
+
import { parseYarn, compile, YarnRunner } from "../index.js";
|
|
4
|
+
test("basic dialogue with options", () => {
|
|
5
|
+
const dialogue = `
|
|
6
|
+
title: Start
|
|
7
|
+
---
|
|
8
|
+
Narrator: Hi
|
|
9
|
+
-> Opt A
|
|
10
|
+
Narrator: A chosen
|
|
11
|
+
-> Opt B
|
|
12
|
+
Narrator: B chosen
|
|
13
|
+
===
|
|
14
|
+
`;
|
|
15
|
+
const doc = parseYarn(dialogue);
|
|
16
|
+
const ir = compile(doc);
|
|
17
|
+
const runner = new YarnRunner(ir, { startAt: "Start" });
|
|
18
|
+
const r1 = runner.currentResult;
|
|
19
|
+
strictEqual(r1.type, "text");
|
|
20
|
+
runner.advance();
|
|
21
|
+
const r2 = runner.currentResult;
|
|
22
|
+
strictEqual(r2.type, "options");
|
|
23
|
+
runner.advance(0);
|
|
24
|
+
const r3 = runner.currentResult;
|
|
25
|
+
strictEqual(r3.type, "text");
|
|
26
|
+
if (r3.type === "text") {
|
|
27
|
+
strictEqual(r3.text.includes("A chosen"), true);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=index.test.js.map
|