@datamoc/mw_games 0.11.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 +84 -0
- package/dist/audio/Playable.d.ts +2 -0
- package/dist/audio/Playable.d.ts.map +1 -1
- package/dist/audio/Playable.js.map +1 -1
- package/dist/audio/Sound.d.ts +7 -1
- package/dist/audio/Sound.d.ts.map +1 -1
- package/dist/audio/Sound.js +8 -1
- package/dist/audio/Sound.js.map +1 -1
- 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 +116 -115
- package/dist/rpg/EventRunner.d.ts +24 -0
- package/dist/rpg/EventRunner.d.ts.map +1 -1
- package/dist/rpg/EventRunner.js +56 -15
- package/dist/rpg/EventRunner.js.map +1 -1
- package/dist/rpg/GridMover.d.ts +6 -0
- package/dist/rpg/GridMover.d.ts.map +1 -1
- package/dist/rpg/GridMover.js +17 -0
- package/dist/rpg/GridMover.js.map +1 -1
- package/dist/rpg/MoveRoute.d.ts +87 -0
- package/dist/rpg/MoveRoute.d.ts.map +1 -0
- package/dist/rpg/MoveRoute.js +110 -0
- package/dist/rpg/MoveRoute.js.map +1 -0
- 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 +6 -1
- package/dist/rpg/index.d.ts.map +1 -1
- package/dist/rpg/index.js +3 -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/two-d/ui/EventDialogue.d.ts.map +1 -1
- package/dist/two-d/ui/EventDialogue.js +7 -1
- package/dist/two-d/ui/EventDialogue.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventDialogue.d.ts","sourceRoot":"","sources":["../../../src/two-d/ui/EventDialogue.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"EventDialogue.d.ts","sourceRoot":"","sources":["../../../src/two-d/ui/EventDialogue.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,MAAM,WAAW,0BAA0B;IAC1C,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAC;CACrC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,GAAE,0BAA+B,GAAG,iBAAiB,CAqBrH"}
|
|
@@ -17,7 +17,13 @@ export function messageBoxPresenter(windows, options = {}) {
|
|
|
17
17
|
width: options.width ?? 480,
|
|
18
18
|
height: options.height ?? 120,
|
|
19
19
|
speed: options.speed ?? 45,
|
|
20
|
-
pages: [
|
|
20
|
+
pages: [
|
|
21
|
+
{
|
|
22
|
+
text: request.text,
|
|
23
|
+
speaker: request.speaker,
|
|
24
|
+
portrait: request.portrait,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
21
27
|
choices: request.choices,
|
|
22
28
|
anchor: options.anchor ?? 'bottom',
|
|
23
29
|
onDone: (chosen) => resolve(chosen),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventDialogue.js","sourceRoot":"","sources":["../../../src/two-d/ui/EventDialogue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"EventDialogue.js","sourceRoot":"","sources":["../../../src/two-d/ui/EventDialogue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAa7C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAoB,EAAE,OAAO,GAA+B,EAAE;IACjG,OAAO,CAAC,OAAO,EAAE,EAAE,CAClB,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QACvB,OAAO,CAAC,IAAI,CACX,IAAI,UAAU,CAAC;YACd,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,GAAG;YAC3B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,GAAG;YAC7B,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;YAC1B,KAAK,EAAE;gBACN;oBACC,IAAI,EAAE,OAAO,CAAC,IAAI;oBAClB,OAAO,EAAE,OAAO,CAAC,OAAO;oBACxB,QAAQ,EAAE,OAAO,CAAC,QAAiC;iBACnD;aACD;YACD,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,QAAQ;YAClC,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC;SACnC,CAAC,CACF,CAAC;IACH,CAAC,CAAC,CAAC;AACL,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": {
|
|
@@ -247,7 +247,7 @@
|
|
|
247
247
|
"webpage:examples": "node tools/build-webpage-examples.mjs",
|
|
248
248
|
"webpage:docs": "node tools/build-webpage-docs.mjs",
|
|
249
249
|
"webpage:diagrams": "node tools/make-example-diagrams.mjs && node tools/make-architecture-diagrams.mjs",
|
|
250
|
-
"mobile:build": "
|
|
250
|
+
"mobile:build": "vite build --config examples/tower-defense/vite.config.ts && node tools/emit-page.mjs examples/tower-defense --no-compress",
|
|
251
251
|
"cap:cli": "node --require ./tools/capacitor-node-workaround.cjs ./node_modules/@capacitor/cli/bin/capacitor",
|
|
252
252
|
"cap:add:android": "npm run mobile:build && npm run cap:cli -- add android",
|
|
253
253
|
"cap:add:ios": "npm run mobile:build && npm run cap:cli -- add ios",
|