@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.
- package/CHANGELOG.md +32 -0
- package/dist/core/DialogueText.d.ts +47 -0
- package/dist/core/DialogueText.d.ts.map +1 -0
- package/dist/core/DialogueText.js +43 -0
- package/dist/core/DialogueText.js.map +1 -0
- package/dist/core/Twee.d.ts +67 -0
- package/dist/core/Twee.d.ts.map +1 -0
- package/dist/core/Twee.js +140 -0
- package/dist/core/Twee.js.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -1
- package/dist/mw_games.global.js +108 -107
- package/dist/rpg/EventRunner.d.ts +20 -0
- package/dist/rpg/EventRunner.d.ts.map +1 -1
- package/dist/rpg/EventRunner.js +52 -11
- package/dist/rpg/EventRunner.js.map +1 -1
- package/dist/rpg/dialogue-text.d.ts +81 -0
- package/dist/rpg/dialogue-text.d.ts.map +1 -0
- package/dist/rpg/dialogue-text.js +88 -0
- package/dist/rpg/dialogue-text.js.map +1 -0
- package/dist/rpg/index.d.ts +4 -1
- package/dist/rpg/index.d.ts.map +1 -1
- package/dist/rpg/index.js +2 -0
- package/dist/rpg/index.js.map +1 -1
- package/dist/rpg/twee-events.d.ts +48 -0
- package/dist/rpg/twee-events.d.ts.map +1 -0
- package/dist/rpg/twee-events.js +35 -0
- package/dist/rpg/twee-events.js.map +1 -0
- package/dist/two-d/stage/dialogue-text.d.ts +81 -0
- package/dist/two-d/stage/dialogue-text.d.ts.map +1 -0
- package/dist/two-d/stage/dialogue-text.js +95 -0
- package/dist/two-d/stage/dialogue-text.js.map +1 -0
- package/dist/two-d/stage/index.d.ts +1 -0
- package/dist/two-d/stage/index.d.ts.map +1 -1
- package/dist/two-d/stage/index.js +1 -0
- package/dist/two-d/stage/index.js.map +1 -1
- package/dist/two-d/stage/twee.d.ts +7 -25
- package/dist/two-d/stage/twee.d.ts.map +1 -1
- package/dist/two-d/stage/twee.js +10 -162
- package/dist/two-d/stage/twee.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- 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;
|
|
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;
|
|
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
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* `
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
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":"
|
|
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"}
|
package/dist/two-d/stage/twee.js
CHANGED
|
@@ -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
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* `
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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
|
|
43
|
-
|
|
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":"
|
|
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
|
+
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
|
+
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.
|
|
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": {
|