@datamoc/mw_games 0.12.0 → 0.13.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/core/DialogueText.d.ts +47 -0
  3. package/dist/core/DialogueText.d.ts.map +1 -0
  4. package/dist/core/DialogueText.js +43 -0
  5. package/dist/core/DialogueText.js.map +1 -0
  6. package/dist/core/Twee.d.ts +67 -0
  7. package/dist/core/Twee.d.ts.map +1 -0
  8. package/dist/core/Twee.js +140 -0
  9. package/dist/core/Twee.js.map +1 -0
  10. package/dist/core/index.d.ts +4 -0
  11. package/dist/core/index.d.ts.map +1 -1
  12. package/dist/core/index.js +2 -0
  13. package/dist/core/index.js.map +1 -1
  14. package/dist/mw_games.global.js +108 -107
  15. package/dist/rpg/EventRunner.d.ts +20 -0
  16. package/dist/rpg/EventRunner.d.ts.map +1 -1
  17. package/dist/rpg/EventRunner.js +52 -11
  18. package/dist/rpg/EventRunner.js.map +1 -1
  19. package/dist/rpg/dialogue-text.d.ts +81 -0
  20. package/dist/rpg/dialogue-text.d.ts.map +1 -0
  21. package/dist/rpg/dialogue-text.js +88 -0
  22. package/dist/rpg/dialogue-text.js.map +1 -0
  23. package/dist/rpg/index.d.ts +4 -1
  24. package/dist/rpg/index.d.ts.map +1 -1
  25. package/dist/rpg/index.js +2 -0
  26. package/dist/rpg/index.js.map +1 -1
  27. package/dist/rpg/twee-events.d.ts +48 -0
  28. package/dist/rpg/twee-events.d.ts.map +1 -0
  29. package/dist/rpg/twee-events.js +35 -0
  30. package/dist/rpg/twee-events.js.map +1 -0
  31. package/dist/two-d/stage/dialogue-text.d.ts +81 -0
  32. package/dist/two-d/stage/dialogue-text.d.ts.map +1 -0
  33. package/dist/two-d/stage/dialogue-text.js +95 -0
  34. package/dist/two-d/stage/dialogue-text.js.map +1 -0
  35. package/dist/two-d/stage/index.d.ts +1 -0
  36. package/dist/two-d/stage/index.d.ts.map +1 -1
  37. package/dist/two-d/stage/index.js +1 -0
  38. package/dist/two-d/stage/index.js.map +1 -1
  39. package/dist/two-d/stage/twee.d.ts +7 -25
  40. package/dist/two-d/stage/twee.d.ts.map +1 -1
  41. package/dist/two-d/stage/twee.js +10 -162
  42. package/dist/two-d/stage/twee.js.map +1 -1
  43. package/dist/version.d.ts +1 -1
  44. package/dist/version.js +1 -1
  45. package/package.json +1 -1
@@ -0,0 +1,95 @@
1
+ import { parseDialogueLines } from '../../core/DialogueText.js';
2
+ /**
3
+ * A terse, line-based text format for straight (non-branching) dialogue - the
4
+ * counterpart to `twee.ts`'s passage graphs, for the common case of a scene
5
+ * that is just a sequence of lines. `rpg` has its own wrapper around the same
6
+ * parsing engine (`core.parseDialogueLines`) for a text-only RPG's map events
7
+ * (`rpg.parseDialogueText`, targeting `EventCommand`) - declared separately
8
+ * here for the same reason `EventChoice` is declared separately from this
9
+ * module's own `Choice`: a text-only RPG built on `core` and `rpg` alone
10
+ * should not have to depend on `two-d` (and its Pixi peer dependency) just to
11
+ * parse dialogue text, and a Pixi-based visual novel that never touches map
12
+ * events should not have to pull in `rpg` either. The actual `@id`/`-`
13
+ * parsing logic lives once in `core.parseDialogueLines`, not copied between
14
+ * the two - only the final command shape (`as` here, `speaker` in `rpg`)
15
+ * differs. Three kinds of line:
16
+ *
17
+ * - `@id text` names who is speaking and says `text`; `@id` alone (no text)
18
+ * just registers the speaker, without saying anything yet.
19
+ * - `- text` continues the two-speaker exchange the first two `@id` lines
20
+ * opened, alternating speaker on every line: the first `-` after the two
21
+ * openers goes to whichever of them did not speak last, and so on.
22
+ * - any other non-blank line narrates, with no speaker.
23
+ *
24
+ * ```
25
+ * @alice Hello.
26
+ * @bob Hi!
27
+ * - How are you?
28
+ * - Fine, and you?
29
+ * ```
30
+ *
31
+ * The `-` shorthand is deliberately capped at two speakers: it exists for the
32
+ * two-character back-and-forth, not as a guess at which of three or more
33
+ * people talks next. A third distinct `@id` anywhere in the source is a
34
+ * parse error rather than a silent guess; a scene with more than two
35
+ * speakers writes `@id` on every line instead, same as it does today.
36
+ *
37
+ * Like `twee.ts`, lines reach `StageCommand.say` as plain, untranslated
38
+ * text - a game's own translation step decides how that text reaches a
39
+ * player, the same seam MWL's own `_("...")`-marked strings use (the source
40
+ * text doubles as the catalog key). `extractDialogueCatalog` builds that
41
+ * catalog the same way MWL's `extractCatalog` does, for a game that wants a
42
+ * translator-ready file to start from.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * import { parseDialogueText, StageScript } from '@datamoc/mw_games/two-d';
47
+ *
48
+ * declare const script: StageScript;
49
+ *
50
+ * const commands = parseDialogueText(`
51
+ * @alice Hello.
52
+ * @bob Hi!
53
+ * - How are you?
54
+ * - Fine, and you?
55
+ * `);
56
+ * await script.run(commands);
57
+ * ```
58
+ */
59
+ export function parseDialogueText(source) {
60
+ return parseDialogueLines(source).map((line) => line.speaker === undefined ? { say: line.text } : { say: line.text, as: line.speaker });
61
+ }
62
+ /**
63
+ * Collects every `say`/`ask` line's text into an identity catalog - each key
64
+ * mapping to itself, the same shape MWL's own `extractCatalog` builds from
65
+ * `_("...")`-marked strings - so a translator has real entries to work from
66
+ * instead of a wall of untranslated dialogue. Accepts either a flat command
67
+ * list (`parseDialogueText`'s own output) or a `StoryScript` graph
68
+ * (`importTwee`'s), so the same extraction step covers both dialogue paths.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * import { parseDialogueText, extractDialogueCatalog } from '@datamoc/mw_games/two-d';
73
+ *
74
+ * const commands = parseDialogueText('@alice Hello.\n');
75
+ * console.log(extractDialogueCatalog(commands).messages); // { 'Hello.': 'Hello.' }
76
+ * ```
77
+ */
78
+ export function extractDialogueCatalog(commands, options = {}) {
79
+ const messages = {};
80
+ const collect = (list) => {
81
+ for (const command of list) {
82
+ if ('say' in command)
83
+ messages[command.say] = command.say;
84
+ else if ('ask' in command)
85
+ messages[command.ask] = command.ask;
86
+ }
87
+ };
88
+ if (Array.isArray(commands))
89
+ collect(commands);
90
+ else
91
+ for (const list of Object.values(commands))
92
+ collect(list);
93
+ return { locale: options.locale ?? 'en', direction: options.direction ?? 'ltr', messages };
94
+ }
95
+ //# sourceMappingURL=dialogue-text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dialogue-text.js","sourceRoot":"","sources":["../../../src/two-d/stage/dialogue-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAIhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC/C,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAC9C,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,CACtF,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,sBAAsB,CACrC,QAA+C,EAC/C,OAAO,GAA+C,EAAE;IAExD,MAAM,QAAQ,GAA2B,EAAE,CAAC;IAC5C,MAAM,OAAO,GAAG,CAAC,IAA6B,EAAQ,EAAE;QACvD,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;YAC5B,IAAI,KAAK,IAAI,OAAO;gBAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;iBACrD,IAAI,KAAK,IAAI,OAAO;gBAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;QAChE,CAAC;IACF,CAAC,CAAC;IACF,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;QAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;;QAC1C,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/D,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,KAAK,EAAE,QAAQ,EAAE,CAAC;AAC5F,CAAC"}
@@ -4,6 +4,7 @@ export { StageScript } from './script.ts';
4
4
  export type { StageCommand, StageChoice, StoryScript, ScriptOptions, ScriptState, HistoryEntry } from './script.ts';
5
5
  export { importTwee } from './twee.ts';
6
6
  export type { TwineStory } from './twee.ts';
7
+ export { parseDialogueText, extractDialogueCatalog } from './dialogue-text.ts';
7
8
  export { StoryScreen, StorySequence } from './StoryScreen.ts';
8
9
  export type { StoryBeat, StoryScreenOptions } from './StoryScreen.ts';
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/two-d/stage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,mBAAmB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAErF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACpH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC9D,YAAY,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/two-d/stage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,mBAAmB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAErF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACpH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE/E,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC9D,YAAY,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export { DialogueStage } from './DialogueStage.js';
2
2
  export { StageScript } from './script.js';
3
3
  export { importTwee } from './twee.js';
4
+ export { parseDialogueText, extractDialogueCatalog } from './dialogue-text.js';
4
5
  export { StoryScreen, StorySequence } from './StoryScreen.js';
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/two-d/stage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGvC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/two-d/stage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE/E,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
@@ -12,31 +12,13 @@ export interface TwineStory {
12
12
  /**
13
13
  * Reads a `.twee` file into a `StoryScript`.
14
14
  *
15
- * Twee was chosen over Twine's `<tw-passagedata>` HTML export on purpose: it is
16
- * plain text, so this stays a pure string parser with no DOM - testable under
17
- * `node --test` and loadable through `mwg/assets` like any other text asset.
18
- *
19
- * Only structure is imported, and that answers the format question the roadmap
20
- * left open: each passage's text lines become `say` commands and its
21
- * `[[links]]` become one closing `ask` whose choices jump (`[[text]]`,
22
- * `[[text->target]]` and `[[target<-text]]`) - the last text line doubles as
23
- * the question, since a choice box needs a prompt and repeating it works.
24
- * No story-format macro language
25
- * (Harlowe, SugarCube, Chapbook) is interpreted - body text reaches the stage
26
- * untouched, and a link carrying a setter throws instead of silently dropping
27
- * the behaviour the setter described.
28
- *
29
- * ```twee
30
- * :: Start
31
- * You stand at a crossroads.
32
- *
33
- * [[Take the left path->Left]]
34
- * [[Take the right path->Right]]
35
- *
36
- * :: Left
37
- * The path ends at a wall.
38
- * [[Go back->Start]]
39
- * ```
15
+ * The actual parsing (passages, `[[links]]`, `StoryData`/`StoryTitle`) lives once in
16
+ * `core.parseTwee` - `rpg.importTwee` is the same wrapper around the same engine, targeting
17
+ * `EventStoryScript` instead, declared separately for the same reason `EventChoice` already
18
+ * duplicates `two-d/ui`'s `Choice`: a text-only RPG should not have to depend on `two-d` just
19
+ * to import a branching Twee story, and a Pixi-based visual novel that never touches map
20
+ * events should not have to depend on `rpg` either. `core.parseTwee`'s own doc comment covers
21
+ * the notation itself (passages, links, what a macro-carrying link does).
40
22
  *
41
23
  * @example
42
24
  * ```ts
@@ -1 +1 @@
1
- {"version":3,"file":"twee.d.ts","sourceRoot":"","sources":["../../../src/two-d/stage/twee.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,aAAa,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,KAAK,EAAE,WAAW,CAAC;IACnB,kFAAkF;IAClF,KAAK,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CA0CrD"}
1
+ {"version":3,"file":"twee.d.ts","sourceRoot":"","sources":["../../../src/two-d/stage/twee.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,KAAK,EAAE,WAAW,CAAC;IACnB,kFAAkF;IAClF,KAAK,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAGrD"}
@@ -1,31 +1,14 @@
1
+ import { parseTwee } from '../../core/Twee.js';
1
2
  /**
2
3
  * Reads a `.twee` file into a `StoryScript`.
3
4
  *
4
- * Twee was chosen over Twine's `<tw-passagedata>` HTML export on purpose: it is
5
- * plain text, so this stays a pure string parser with no DOM - testable under
6
- * `node --test` and loadable through `mwg/assets` like any other text asset.
7
- *
8
- * Only structure is imported, and that answers the format question the roadmap
9
- * left open: each passage's text lines become `say` commands and its
10
- * `[[links]]` become one closing `ask` whose choices jump (`[[text]]`,
11
- * `[[text->target]]` and `[[target<-text]]`) - the last text line doubles as
12
- * the question, since a choice box needs a prompt and repeating it works.
13
- * No story-format macro language
14
- * (Harlowe, SugarCube, Chapbook) is interpreted - body text reaches the stage
15
- * untouched, and a link carrying a setter throws instead of silently dropping
16
- * the behaviour the setter described.
17
- *
18
- * ```twee
19
- * :: Start
20
- * You stand at a crossroads.
21
- *
22
- * [[Take the left path->Left]]
23
- * [[Take the right path->Right]]
24
- *
25
- * :: Left
26
- * The path ends at a wall.
27
- * [[Go back->Start]]
28
- * ```
5
+ * The actual parsing (passages, `[[links]]`, `StoryData`/`StoryTitle`) lives once in
6
+ * `core.parseTwee` - `rpg.importTwee` is the same wrapper around the same engine, targeting
7
+ * `EventStoryScript` instead, declared separately for the same reason `EventChoice` already
8
+ * duplicates `two-d/ui`'s `Choice`: a text-only RPG should not have to depend on `two-d` just
9
+ * to import a branching Twee story, and a Pixi-based visual novel that never touches map
10
+ * events should not have to depend on `rpg` either. `core.parseTwee`'s own doc comment covers
11
+ * the notation itself (passages, links, what a macro-carrying link does).
29
12
  *
30
13
  * @example
31
14
  * ```ts
@@ -39,142 +22,7 @@
39
22
  * ```
40
23
  */
41
24
  export function importTwee(source) {
42
- const passages = splitPassages(source);
43
- if (passages.length === 0)
44
- throw new Error('this twee source has no passages - passages start with ":: Name"');
45
- const story = {};
46
- let title;
47
- let start;
48
- for (const passage of passages) {
49
- if (passage.name === 'StoryTitle') {
50
- title = passage.body.trim() || undefined;
51
- continue;
52
- }
53
- if (passage.name === 'StoryData') {
54
- start = readStart(passage.body);
55
- continue;
56
- }
57
- if (Object.prototype.hasOwnProperty.call(story, passage.name)) {
58
- throw new Error(`this twee source defines "${passage.name}" twice`);
59
- }
60
- story[passage.name] = passageCommands(passage.name, passage.body);
61
- }
62
- const names = Object.keys(story);
63
- if (names.length === 0)
64
- throw new Error('this twee source has no story passages, only StoryTitle/StoryData');
65
- if (start !== undefined && !Object.prototype.hasOwnProperty.call(story, start)) {
66
- throw new Error(`StoryData starts at "${start}", which is not a passage in this file`);
67
- }
68
- for (const [name, commands] of Object.entries(story)) {
69
- for (const command of commands) {
70
- if ('ask' in command) {
71
- for (const choice of command.choices) {
72
- if (choice.goto !== undefined && !Object.prototype.hasOwnProperty.call(story, choice.goto)) {
73
- throw new Error(`passage "${name}" links to "${choice.goto}", which is not a passage in this file`);
74
- }
75
- }
76
- }
77
- }
78
- }
79
- return { story, start: start ?? names[0], title };
80
- }
81
- /** cuts the source at every line starting with `::`, parsing headers into names */
82
- function splitPassages(source) {
83
- const out = [];
84
- let name = null;
85
- let body = [];
86
- const flush = () => {
87
- if (name !== null)
88
- out.push({ name, body: body.join('\n') });
89
- };
90
- for (const line of source.split('\n')) {
91
- if (line.startsWith('::')) {
92
- flush();
93
- name = parseHeader(line);
94
- body = [];
95
- }
96
- else if (name !== null) {
97
- body.push(line);
98
- }
99
- }
100
- flush();
101
- return out;
102
- }
103
- /** `:: Name [tags] {"meta": true}` - only the name survives; tags and position are editor concerns */
104
- function parseHeader(line) {
105
- const rest = line.slice(2).trim();
106
- const tagAt = rest.search(/[[{]/);
107
- const name = (tagAt === -1 ? rest : rest.slice(0, tagAt)).trim();
108
- if (!name)
109
- throw new Error(`a twee passage header needs a name, got "${line}"`);
110
- return name;
111
- }
112
- /** StoryData is JSON; only `start` matters to the runner, the rest is player furniture */
113
- function readStart(body) {
114
- let data;
115
- try {
116
- data = JSON.parse(body.trim());
117
- }
118
- catch {
119
- throw new Error('StoryData must be JSON - check the braces');
120
- }
121
- if (typeof data !== 'object' || data === null || Array.isArray(data)) {
122
- throw new Error('StoryData must be a JSON object');
123
- }
124
- const start = data.start;
125
- if (start !== undefined && typeof start !== 'string') {
126
- throw new Error('StoryData "start" must be a passage name');
127
- }
128
- return start;
129
- }
130
- /** text lines speak in order; the last one doubles as the prompt when links follow it */
131
- function passageCommands(passage, body) {
132
- const lines = [];
133
- const choices = [];
134
- for (const line of body.split('\n')) {
135
- const text = extractLinks(line, choices, passage).replace(/\s+/g, ' ').trim();
136
- if (text !== '')
137
- lines.push(text);
138
- }
139
- if (choices.length === 0)
140
- return lines.map((say) => ({ say }));
141
- const prompt = lines.pop() ?? '';
142
- return [...lines.map((say) => ({ say })), { ask: prompt, choices }];
143
- }
144
- /**
145
- * Pulls `[[links]]` out of a line, leaving the surrounding text behind.
146
- * Returns the line with the links removed.
147
- */
148
- function extractLinks(line, choices, passage) {
149
- let out = '';
150
- let rest = line;
151
- for (;;) {
152
- const open = rest.indexOf('[[');
153
- if (open === -1)
154
- return out + rest;
155
- const close = rest.indexOf(']]', open);
156
- if (close === -1) {
157
- throw new Error(`passage "${passage}" has a "[[" with no closing "]]" in "${line.trim()}"`);
158
- }
159
- out += rest.slice(0, open);
160
- choices.push(parseLink(rest.slice(open + 2, close), passage));
161
- rest = rest.slice(close + 2);
162
- }
163
- }
164
- function parseLink(inner, passage) {
165
- if (inner.includes('[') || inner.includes(']')) {
166
- throw new Error(`passage "${passage}" links with a setter ("${inner.trim()}") - ` +
167
- 'story-format macros are not imported, so the link is refused rather than half-read');
168
- }
169
- const forward = inner.indexOf('->');
170
- if (forward !== -1) {
171
- return { text: inner.slice(0, forward).trim(), goto: inner.slice(forward + 2).trim() };
172
- }
173
- const backward = inner.indexOf('<-');
174
- if (backward !== -1) {
175
- return { text: inner.slice(backward + 2).trim(), goto: inner.slice(0, backward).trim() };
176
- }
177
- const target = inner.trim();
178
- return { text: target, goto: target };
25
+ const { story, start, title } = parseTwee(source);
26
+ return title === undefined ? { story, start } : { story, start, title };
179
27
  }
180
28
  //# sourceMappingURL=twee.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"twee.js","sourceRoot":"","sources":["../../../src/two-d/stage/twee.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc;IACxC,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACvC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,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,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;IAC1F,CAAC;IACD,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AACvC,CAAC"}
1
+ {"version":3,"file":"twee.js","sourceRoot":"","sources":["../../../src/two-d/stage/twee.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAc/C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc;IACxC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IAClD,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AACzE,CAAC"}
package/dist/version.d.ts CHANGED
@@ -9,5 +9,5 @@
9
9
  * this from `package.json` automatically, chosen because this project's own build already
10
10
  * has no step before `tsc`/`vite` that this would need to run ahead of.
11
11
  */
12
- export declare const version = "0.12.0";
12
+ export declare const version = "0.13.0";
13
13
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -9,5 +9,5 @@
9
9
  * this from `package.json` automatically, chosen because this project's own build already
10
10
  * has no step before `tsc`/`vite` that this would need to run ahead of.
11
11
  */
12
- export const version = '0.12.0';
12
+ export const version = '0.13.0';
13
13
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datamoc/mw_games",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "A local-file game framework: renderer-free game logic, drawn through PixiJS in 2D or Babylon.js in 3D, with mobile and desktop packaging.",
5
5
  "license": "MPL-2.0",
6
6
  "repository": {