squiffy-compiler 7.0.0-beta.6 → 7.0.0-beta.7
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/dist/analyse.d.ts +3 -0
- package/dist/analyse.js +42 -0
- package/dist/compiler.d.ts +1 -0
- package/dist/compiler.js +1 -0
- package/dist/css-urls.d.ts +4 -0
- package/dist/css-urls.js +59 -0
- package/dist/emit.d.ts +7 -0
- package/dist/emit.js +28 -0
- package/dist/language-service.d.ts +1 -0
- package/dist/language-service.js +22 -10
- package/dist/parse.d.ts +3 -0
- package/dist/parse.js +14 -0
- package/dist/project.d.ts +2 -0
- package/dist/project.js +3 -0
- package/dist/quest/convert.js +38 -9
- package/dist/quest/scripts.js +7 -3
- package/dist/setters.d.ts +4 -0
- package/dist/setters.js +7 -5
- package/dist/syntax.d.ts +14 -1
- package/dist/text.js +17 -10
- package/dist/twine/audio.d.ts +21 -0
- package/dist/twine/audio.js +80 -0
- package/dist/twine/convert.d.ts +10 -3
- package/dist/twine/convert.js +104 -26
- package/dist/twine/expression.d.ts +20 -1
- package/dist/twine/expression.js +98 -7
- package/dist/twine/harlowe.d.ts +9 -0
- package/dist/twine/harlowe.js +363 -60
- package/dist/twine/sugarcube.d.ts +3 -0
- package/dist/twine/sugarcube.js +348 -83
- package/package.json +2 -2
- package/syntaxes/squiffy.tmLanguage.json +8 -3
package/dist/analyse.d.ts
CHANGED
package/dist/analyse.js
CHANGED
|
@@ -109,6 +109,27 @@ class TextContainer {
|
|
|
109
109
|
writable: true,
|
|
110
110
|
value: []
|
|
111
111
|
});
|
|
112
|
+
// @music (#444): the file to play, or null for @music stop. Undefined leaves it as it is.
|
|
113
|
+
Object.defineProperty(this, "music", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true,
|
|
116
|
+
writable: true,
|
|
117
|
+
value: void 0
|
|
118
|
+
});
|
|
119
|
+
// @sound: the files to play once, in order, with "stop" for @sound stop
|
|
120
|
+
Object.defineProperty(this, "sounds", {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
configurable: true,
|
|
123
|
+
writable: true,
|
|
124
|
+
value: []
|
|
125
|
+
});
|
|
126
|
+
// @class (#449): classes on the story's element while the section is the current one
|
|
127
|
+
Object.defineProperty(this, "classes", {
|
|
128
|
+
enumerable: true,
|
|
129
|
+
configurable: true,
|
|
130
|
+
writable: true,
|
|
131
|
+
value: []
|
|
132
|
+
});
|
|
112
133
|
// The text after links have been converted
|
|
113
134
|
Object.defineProperty(this, "output", {
|
|
114
135
|
enumerable: true,
|
|
@@ -417,6 +438,27 @@ export async function analyse(settings) {
|
|
|
417
438
|
}
|
|
418
439
|
return true;
|
|
419
440
|
}
|
|
441
|
+
case "sound": {
|
|
442
|
+
const target = passage ?? (section = ensureSectionExists(lineCount));
|
|
443
|
+
if (!target)
|
|
444
|
+
return sectionRequired(node);
|
|
445
|
+
const value = node.value.trim();
|
|
446
|
+
if (node.directive == "sound")
|
|
447
|
+
target.sounds.push(value);
|
|
448
|
+
else
|
|
449
|
+
target.music = value == "stop" ? null : value;
|
|
450
|
+
return true;
|
|
451
|
+
}
|
|
452
|
+
case "class": {
|
|
453
|
+
const target = passage ?? (section = ensureSectionExists(lineCount));
|
|
454
|
+
if (!target)
|
|
455
|
+
return sectionRequired(node);
|
|
456
|
+
for (const name of node.value.split(/\s+/)) {
|
|
457
|
+
if (name && !target.classes.includes(name))
|
|
458
|
+
target.classes.push(name);
|
|
459
|
+
}
|
|
460
|
+
return true;
|
|
461
|
+
}
|
|
420
462
|
case "attribute": {
|
|
421
463
|
section = ensureSectionExists(lineCount);
|
|
422
464
|
let attribute;
|
package/dist/compiler.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export type { AnalyseSettings, Analysis, ExternalFiles, SectionSymbol, PassageSy
|
|
|
19
19
|
export { emit } from "./emit.js";
|
|
20
20
|
export type { EmitSettings, Output, UiInfo, CompileSuccess } from "./emit.js";
|
|
21
21
|
export { formatDiagnostic } from "./syntax.js";
|
|
22
|
+
export { findCssUrls, isRelativeUrl, resolveCssUrl, rewriteCssUrls } from "./css-urls.js";
|
|
22
23
|
export { PROJECT_FILENAME, PROJECT_FILE_VERSION, PROJECT_SCHEMA_URL, parseProjectFile, getStoryFiles, isExcluded, isAlwaysSkipped, formatProjectFile, updateProjectFile, PAGE_STRINGS, PANEL_ICONS, storyFileList, BUILD_FOLDER, } from "./project.js";
|
|
23
24
|
export type { MapPositions, PageStringName, PageStrings, Panel, PanelIcon, ProjectFile, ParsedProjectFile, StoryFiles } from "./project.js";
|
|
24
25
|
export type * from "./syntax.js";
|
package/dist/compiler.js
CHANGED
|
@@ -14,6 +14,7 @@ export { parse } from "./parse.js";
|
|
|
14
14
|
export { analyse, ParseCache } from "./analyse.js";
|
|
15
15
|
export { emit } from "./emit.js";
|
|
16
16
|
export { formatDiagnostic } from "./syntax.js";
|
|
17
|
+
export { findCssUrls, isRelativeUrl, resolveCssUrl, rewriteCssUrls } from "./css-urls.js";
|
|
17
18
|
export { PROJECT_FILENAME, PROJECT_FILE_VERSION, PROJECT_SCHEMA_URL, parseProjectFile, getStoryFiles, isExcluded, isAlwaysSkipped, formatProjectFile, updateProjectFile, PAGE_STRINGS, PANEL_ICONS, storyFileList, BUILD_FOLDER, } from "./project.js";
|
|
18
19
|
export async function compile(settings) {
|
|
19
20
|
const analysis = await analyse(settings);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function isRelativeUrl(url: string): boolean;
|
|
2
|
+
export declare function rewriteCssUrls(css: string, replace: (url: string) => string | undefined): string;
|
|
3
|
+
export declare function findCssUrls(css: string): string[];
|
|
4
|
+
export declare function resolveCssUrl(sheetPath: string, url: string): string | null;
|
package/dist/css-urls.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// The url()s in a story's own stylesheets, such as a font's files or a background image. A
|
|
2
|
+
// stylesheet refers to them by their path from its own folder, as a web page's CSS does. That
|
|
3
|
+
// works as it is in a published story, whose stylesheets are separate files, but a one-file
|
|
4
|
+
// export or the editor's preview has to swap each for something it can load.
|
|
5
|
+
const URL_PATTERN = /url\(\s*(?:"((?:[^"\\\n]|\\.)*)"|'((?:[^'\\\n]|\\.)*)'|([^)"'\s]*))\s*\)/gi;
|
|
6
|
+
// A url() that's a path to a file beside the stylesheet, rather than a web address, a data: URI,
|
|
7
|
+
// an absolute path or a reference to an SVG element like "#gradient"
|
|
8
|
+
export function isRelativeUrl(url) {
|
|
9
|
+
return url != "" && !/^(?:[a-z][a-z\d+.-]*:|\/|#)/i.test(url);
|
|
10
|
+
}
|
|
11
|
+
// Replaces each relative url() in css with what replace returns for it, or leaves it as it is if
|
|
12
|
+
// replace returns undefined
|
|
13
|
+
export function rewriteCssUrls(css, replace) {
|
|
14
|
+
return css.replace(URL_PATTERN, (match, double, single, bare) => {
|
|
15
|
+
const url = (double ?? single ?? bare ?? "").trim();
|
|
16
|
+
if (!isRelativeUrl(url))
|
|
17
|
+
return match;
|
|
18
|
+
const replacement = replace(url);
|
|
19
|
+
return replacement === undefined ? match : `url("${replacement.replace(/["\\\n]/g, c => c == "\n" ? "\\a " : `\\${c}`)}")`;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
// The relative url()s in css
|
|
23
|
+
export function findCssUrls(css) {
|
|
24
|
+
const urls = [];
|
|
25
|
+
rewriteCssUrls(css, url => {
|
|
26
|
+
urls.push(url);
|
|
27
|
+
return undefined;
|
|
28
|
+
});
|
|
29
|
+
return urls;
|
|
30
|
+
}
|
|
31
|
+
// The path, from the story's folder, of a url() in the stylesheet at sheetPath (also from the
|
|
32
|
+
// story's folder), e.g. "fonts/literata/latin-400-normal.woff2" for "latin-400-normal.woff2" in
|
|
33
|
+
// "fonts/literata/literata.css". Null if it's outside the story's folder. A query or #fragment,
|
|
34
|
+
// such as the "?#iefix" some older @font-face rules have, isn't part of the path.
|
|
35
|
+
export function resolveCssUrl(sheetPath, url) {
|
|
36
|
+
let path = url.replace(/[?#].*$/, "");
|
|
37
|
+
try {
|
|
38
|
+
path = decodeURI(path);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Not valid percent-encoding: use it as it is
|
|
42
|
+
}
|
|
43
|
+
const sheet = sheetPath.replace(/\\/g, "/").split("/");
|
|
44
|
+
sheet.pop();
|
|
45
|
+
const parts = sheet.filter(part => part != "" && part != ".");
|
|
46
|
+
for (const part of path.replace(/\\/g, "/").split("/")) {
|
|
47
|
+
if (part == "" || part == ".")
|
|
48
|
+
continue;
|
|
49
|
+
if (part == "..") {
|
|
50
|
+
if (!parts.length || parts[parts.length - 1] == "..")
|
|
51
|
+
return null;
|
|
52
|
+
parts.pop();
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
parts.push(part);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return parts.length ? parts.join("/") : null;
|
|
59
|
+
}
|
package/dist/emit.d.ts
CHANGED
|
@@ -13,10 +13,14 @@ interface OutputStory {
|
|
|
13
13
|
expressions?: boolean;
|
|
14
14
|
panels?: Panel[];
|
|
15
15
|
sections: Record<string, OutputSection>;
|
|
16
|
+
audio?: string[];
|
|
16
17
|
}
|
|
17
18
|
interface OutputSection {
|
|
18
19
|
text?: string;
|
|
19
20
|
clear?: boolean;
|
|
21
|
+
music?: string | null;
|
|
22
|
+
sounds?: string[];
|
|
23
|
+
classes?: string[];
|
|
20
24
|
attributes?: string[];
|
|
21
25
|
jsIndex?: number;
|
|
22
26
|
passages?: Record<string, OutputPassage>;
|
|
@@ -25,6 +29,9 @@ interface OutputSection {
|
|
|
25
29
|
interface OutputPassage {
|
|
26
30
|
text?: string;
|
|
27
31
|
clear?: boolean;
|
|
32
|
+
music?: string | null;
|
|
33
|
+
sounds?: string[];
|
|
34
|
+
classes?: string[];
|
|
28
35
|
repeat?: boolean;
|
|
29
36
|
attributes?: string[];
|
|
30
37
|
jsIndex?: number;
|
package/dist/emit.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import pkg from "../package.json" with { type: "json" };
|
|
2
2
|
import { analysisInternals } from "./analyse.js";
|
|
3
3
|
const version = pkg.version;
|
|
4
|
+
// {{music "file"}} or {{sound "file"}}
|
|
5
|
+
const SOUND_HELPER = /\{\{\s*(?:music|sound)\s+(["'])([^"'{}]+)\1/g;
|
|
6
|
+
// @music and @sound (#444), and the files they and the text name, for OutputStory.audio
|
|
7
|
+
function addSounds(output, from, audio) {
|
|
8
|
+
if (from.music !== undefined)
|
|
9
|
+
output.music = from.music;
|
|
10
|
+
if (from.sounds.length)
|
|
11
|
+
output.sounds = from.sounds;
|
|
12
|
+
if (from.music)
|
|
13
|
+
audio.add(from.music);
|
|
14
|
+
from.sounds.forEach(file => { if (file != "stop")
|
|
15
|
+
audio.add(file); });
|
|
16
|
+
for (const match of from.output.matchAll(SOUND_HELPER))
|
|
17
|
+
audio.add(match[2]);
|
|
18
|
+
}
|
|
4
19
|
// Produces the story data and JavaScript for an analysis that succeeded.
|
|
5
20
|
export function emit(analysis, settings = {}) {
|
|
6
21
|
const internals = analysisInternals.get(analysis);
|
|
@@ -32,6 +47,7 @@ export function emit(analysis, settings = {}) {
|
|
|
32
47
|
output.js.push(story.uiJs);
|
|
33
48
|
output.story.uiJsIndex = output.js.length - 1;
|
|
34
49
|
}
|
|
50
|
+
const audio = new Set();
|
|
35
51
|
for (const sectionName of Object.keys(story.sections)) {
|
|
36
52
|
const section = story.sections[sectionName];
|
|
37
53
|
const outputSection = {};
|
|
@@ -40,6 +56,9 @@ export function emit(analysis, settings = {}) {
|
|
|
40
56
|
outputSection.clear = true;
|
|
41
57
|
}
|
|
42
58
|
outputSection.text = section.output;
|
|
59
|
+
addSounds(outputSection, section, audio);
|
|
60
|
+
if (section.classes.length)
|
|
61
|
+
outputSection.classes = section.classes;
|
|
43
62
|
if (section.attributes.length > 0) {
|
|
44
63
|
outputSection.attributes = section.attributes;
|
|
45
64
|
}
|
|
@@ -71,6 +90,9 @@ export function emit(analysis, settings = {}) {
|
|
|
71
90
|
outputPassage.repeat = true;
|
|
72
91
|
}
|
|
73
92
|
outputPassage.text = passage.output;
|
|
93
|
+
addSounds(outputPassage, passage, audio);
|
|
94
|
+
if (passage.classes.length)
|
|
95
|
+
outputPassage.classes = passage.classes;
|
|
74
96
|
if (passage.attributes.length > 0) {
|
|
75
97
|
outputPassage.attributes = passage.attributes;
|
|
76
98
|
}
|
|
@@ -80,6 +102,9 @@ export function emit(analysis, settings = {}) {
|
|
|
80
102
|
}
|
|
81
103
|
}
|
|
82
104
|
}
|
|
105
|
+
if (audio.size) {
|
|
106
|
+
output.story.audio = [...audio];
|
|
107
|
+
}
|
|
83
108
|
const getJs = async (excludeHeader) => {
|
|
84
109
|
const outputJs = [];
|
|
85
110
|
if (!excludeHeader) {
|
|
@@ -105,6 +130,9 @@ export function emit(analysis, settings = {}) {
|
|
|
105
130
|
if (output.story.panels) {
|
|
106
131
|
outputJs.push(`story.panels = ${JSON.stringify(output.story.panels, null, 4)};`);
|
|
107
132
|
}
|
|
133
|
+
if (output.story.audio) {
|
|
134
|
+
outputJs.push(`story.audio = ${JSON.stringify(output.story.audio, null, 4)};`);
|
|
135
|
+
}
|
|
108
136
|
outputJs.push(`story.start = ${JSON.stringify(output.story.start, null, 4)};`);
|
|
109
137
|
outputJs.push(`story.sections = ${JSON.stringify(output.story.sections, null, 4)};`);
|
|
110
138
|
outputJs.push("story.js = [");
|
|
@@ -75,6 +75,7 @@ export interface LanguageService {
|
|
|
75
75
|
getProjectInfo(): Promise<ProjectInfo>;
|
|
76
76
|
getAnalysis(): Promise<Analysis>;
|
|
77
77
|
getDiagnostics(path: string): Promise<Diagnostic[]>;
|
|
78
|
+
getAllDiagnostics(): Promise<Diagnostic[]>;
|
|
78
79
|
getDocumentSymbols(path: string): Promise<DocumentSymbol[]>;
|
|
79
80
|
getDefinition(path: string, position: Position): Promise<Location | undefined>;
|
|
80
81
|
getReferences(path: string, position: Position, includeDeclaration?: boolean): Promise<Location[]>;
|
package/dist/language-service.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { analyse, ParseCache } from "./analyse.js";
|
|
9
9
|
import { getStoryFiles, globToRegExp, parseProjectFile, PROJECT_FILENAME, storyFileList } from "./project.js";
|
|
10
10
|
import { convertV5Syntax, findV5Syntax } from "./v5.js";
|
|
11
|
-
import { findUnquotedText } from "./setters.js";
|
|
11
|
+
import { findUnquotedText, splitWithOffsets } from "./setters.js";
|
|
12
12
|
import { buildStoryGraph, storyGraphDiagnostics } from "./story-graph.js";
|
|
13
13
|
const sameSymbol = (a, b) => a.kind == b.kind && a.name == b.name && (a.kind == "section" || a.section == b.section);
|
|
14
14
|
const usageRange = (usage) => (usage.link ?? usage.embed ?? usage.goto ?? usage.deactivate).range;
|
|
@@ -24,6 +24,9 @@ const DIRECTIVES = [
|
|
|
24
24
|
["clear", "Clears the screen"],
|
|
25
25
|
["repeat", "Lets the player click this passage's links again"],
|
|
26
26
|
["end", "Marks this section as an ending"],
|
|
27
|
+
["music", "Plays music until it's changed, or stops it with @music stop"],
|
|
28
|
+
["sound", "Plays a sound once, or stops the sounds playing with @sound stop"],
|
|
29
|
+
["class", "Puts classes on the story while this section is shown, for its stylesheet"],
|
|
27
30
|
["ui", "JavaScript for the story's user interface"],
|
|
28
31
|
];
|
|
29
32
|
const contains = (range, pos) => comparePositions(range.start, pos) <= 0 && comparePositions(pos, range.end) <= 0;
|
|
@@ -41,8 +44,9 @@ function resolveName(target, has) {
|
|
|
41
44
|
}
|
|
42
45
|
// The name a broken link was trying to reach
|
|
43
46
|
const intendedName = (target) => target.trim().split(",")[0].trim();
|
|
47
|
+
// The attribute a setter sets, e.g. gold in gold += 1, or hero.hp in hero.hp = 10 (#442)
|
|
44
48
|
function attributeName(expression) {
|
|
45
|
-
return
|
|
49
|
+
return /^\s*(?:not\s+)?(\w+(?:\.\w+)*)/.exec(expression)?.[1] ?? "";
|
|
46
50
|
}
|
|
47
51
|
function resolvePath(baseDir, relative) {
|
|
48
52
|
const parts = baseDir ? baseDir.split("/") : [];
|
|
@@ -217,6 +221,14 @@ export function createLanguageService(options) {
|
|
|
217
221
|
if (section.node)
|
|
218
222
|
index.nodeNames.set(section.node, section.name);
|
|
219
223
|
}
|
|
224
|
+
// An attribute, and for a value inside an object, the object too: hero.hp adds hero
|
|
225
|
+
const addAttribute = (name) => {
|
|
226
|
+
const parts = name.split(".");
|
|
227
|
+
for (let i = 1; i <= parts.length; i++) {
|
|
228
|
+
if (parts[i - 1])
|
|
229
|
+
index.attributes.add(parts.slice(0, i).join("."));
|
|
230
|
+
}
|
|
231
|
+
};
|
|
220
232
|
for (const [path, file] of index.files) {
|
|
221
233
|
for (const node of [file.preamble, ...file.sections]) {
|
|
222
234
|
if (node.type == "snippet") {
|
|
@@ -226,11 +238,10 @@ export function createLanguageService(options) {
|
|
|
226
238
|
for (const container of [node, ...node.passages]) {
|
|
227
239
|
for (const link of container.links) {
|
|
228
240
|
index.usages.push({ file: path, container, sectionNode: node, link });
|
|
229
|
-
const
|
|
241
|
+
const comma = link.target.indexOf(",");
|
|
242
|
+
const setters = comma == -1 ? [] : splitWithOffsets(link.target.substring(comma + 1)).map(part => part.text);
|
|
230
243
|
for (const setter of setters) {
|
|
231
|
-
|
|
232
|
-
if (name)
|
|
233
|
-
index.attributes.add(name);
|
|
244
|
+
addAttribute(attributeName(setter));
|
|
234
245
|
}
|
|
235
246
|
}
|
|
236
247
|
for (const embed of container.embeds) {
|
|
@@ -244,9 +255,7 @@ export function createLanguageService(options) {
|
|
|
244
255
|
}
|
|
245
256
|
for (const statement of container.body) {
|
|
246
257
|
if (statement.type == "attribute") {
|
|
247
|
-
|
|
248
|
-
if (name)
|
|
249
|
-
index.attributes.add(name);
|
|
258
|
+
addAttribute(attributeName(statement.value));
|
|
250
259
|
}
|
|
251
260
|
else if (statement.type == "js") {
|
|
252
261
|
for (const match of statement.code.matchAll(/\bset\(\s*["']([^"']+)["']/g)) {
|
|
@@ -472,6 +481,9 @@ export function createLanguageService(options) {
|
|
|
472
481
|
const index = await getIndex();
|
|
473
482
|
return allDiagnostics(index).filter(d => d.file == path);
|
|
474
483
|
},
|
|
484
|
+
async getAllDiagnostics() {
|
|
485
|
+
return allDiagnostics(await getIndex());
|
|
486
|
+
},
|
|
475
487
|
async getDocumentSymbols(path) {
|
|
476
488
|
const index = await getIndex();
|
|
477
489
|
const tree = await getFile(index, path);
|
|
@@ -590,7 +602,7 @@ export function createLanguageService(options) {
|
|
|
590
602
|
.map(name => ({ label: name, kind: "passage", range: replace(typed) }));
|
|
591
603
|
};
|
|
592
604
|
let match;
|
|
593
|
-
if ((match = /\{\{~?\s
|
|
605
|
+
if ((match = /\{\{~?\s*#?embed\s+["']([^"']*)$/.exec(prefix))) {
|
|
594
606
|
return [...passageItems(match[1]), ...sectionItems(match[1])];
|
|
595
607
|
}
|
|
596
608
|
// {{seen "name"}}, (visits "name") etc., which take a section or passage (#377)
|
package/dist/parse.d.ts
CHANGED
package/dist/parse.js
CHANGED
|
@@ -13,6 +13,9 @@ export const lineRegexes = {
|
|
|
13
13
|
js: /^(\t| {4})(.*)$/,
|
|
14
14
|
continue: /^\+\+\+(.*)$/,
|
|
15
15
|
ui: /^@ui (.*)$/,
|
|
16
|
+
music: /^@music (.*)$/,
|
|
17
|
+
sound: /^@sound (.*)$/,
|
|
18
|
+
class: /^@class (.*)$/,
|
|
16
19
|
};
|
|
17
20
|
// Parses one .squiffy file into a syntax tree. This never fails: problems such as a passage
|
|
18
21
|
// with no section are reported by analyse(), which knows how the file fits into the story.
|
|
@@ -176,6 +179,17 @@ export function parse(text, filename) {
|
|
|
176
179
|
else if (match.import) {
|
|
177
180
|
add({ type: "import", pattern: match.import[1], patternRange: valueRange(i, match.import[1]), range });
|
|
178
181
|
}
|
|
182
|
+
else if (match.music || match.sound) {
|
|
183
|
+
if (!passage)
|
|
184
|
+
haveSection = true;
|
|
185
|
+
const value = (match.music ?? match.sound)[1];
|
|
186
|
+
add({ type: "sound", directive: match.music ? "music" : "sound", value, valueRange: valueRange(i, value), range });
|
|
187
|
+
}
|
|
188
|
+
else if (match.class) {
|
|
189
|
+
if (!passage)
|
|
190
|
+
haveSection = true;
|
|
191
|
+
add({ type: "class", value: match.class[1], valueRange: valueRange(i, match.class[1]), range });
|
|
192
|
+
}
|
|
179
193
|
else if (match.attributes || match.unset) {
|
|
180
194
|
haveSection = true;
|
|
181
195
|
const value = (match.attributes ?? match.unset)[1];
|
package/dist/project.d.ts
CHANGED
package/dist/project.js
CHANGED
|
@@ -21,6 +21,9 @@ export const PAGE_STRINGS = {
|
|
|
21
21
|
restartConfirm: "Are you sure you want to restart?",
|
|
22
22
|
switchToDark: "Switch to dark mode",
|
|
23
23
|
switchToLight: "Switch to light mode",
|
|
24
|
+
// The mute button, for a story with music or sounds
|
|
25
|
+
mute: "Mute",
|
|
26
|
+
unmute: "Unmute",
|
|
24
27
|
// The Saved games dialog, opened by the Save button. [name] and [time] are filled in.
|
|
25
28
|
saves: "Saved games",
|
|
26
29
|
saveName: "Name (optional)",
|
package/dist/quest/convert.js
CHANGED
|
@@ -22,6 +22,18 @@ function stringAttribute(o, name) {
|
|
|
22
22
|
const value = o.attributes.get(name);
|
|
23
23
|
return value?.type == "string" ? value.value : "";
|
|
24
24
|
}
|
|
25
|
+
// Whether a script calls a function or command, such as "play sound", anywhere in it
|
|
26
|
+
function calls(statements, fn) {
|
|
27
|
+
return statements.some(s => {
|
|
28
|
+
switch (s.k) {
|
|
29
|
+
case "call": return s.fn == fn || calls(s.callback ?? [], fn);
|
|
30
|
+
case "if": return s.branches.some(b => calls(b.body, fn)) || calls(s.otherwise ?? [], fn);
|
|
31
|
+
case "firsttime": return calls(s.body, fn) || calls(s.otherwise ?? [], fn);
|
|
32
|
+
case "switch": return s.cases.some(c => calls(c.body, fn)) || calls(s.otherwise ?? [], fn);
|
|
33
|
+
default: return false;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
25
37
|
function booleanValue(value) {
|
|
26
38
|
return value?.type == "boolean" ? value.value : undefined;
|
|
27
39
|
}
|
|
@@ -151,7 +163,19 @@ function convertGame(game, options) {
|
|
|
151
163
|
newFirstTime: () => `firsttime_${++firstTimes}`,
|
|
152
164
|
noteStyle: () => { styled = true; },
|
|
153
165
|
});
|
|
154
|
-
|
|
166
|
+
// Quest stops every sound when the player goes to another page, unless the last page with a
|
|
167
|
+
// sound was set to continue playing it (game.continuesound). That's done at the start of each
|
|
168
|
+
// page, or in the master section if the script that runs on every page plays a sound, as
|
|
169
|
+
// Quest stops sounds before running it.
|
|
170
|
+
const pageSound = (p) => scriptOnlyPages.has(p.name) ? "" : stringAttribute(p, "sound").trim();
|
|
171
|
+
const playsSound = storyPages.some(p => pageSound(p))
|
|
172
|
+
|| [...pageScripts.values(), roomEnter ?? []].some(statements => calls(statements, "play sound"));
|
|
173
|
+
const continuesSound = storyPages.some(p => pageSound(p) && booleanValue(p.attributes.get("continuesound")));
|
|
174
|
+
const continueAttribute = attribute("continuesound");
|
|
175
|
+
const stopSounds = !playsSound ? { directives: [], lines: [] }
|
|
176
|
+
: continuesSound ? { directives: [], lines: [`{{#unless ${attributeRef(continueAttribute)}}}{{stopsounds}}{{stopmusic}}{{/unless}}`] }
|
|
177
|
+
: { directives: ["@sound stop", "@music stop"], lines: [] };
|
|
178
|
+
const stopInMaster = !!roomEnter && calls(roomEnter, "play sound");
|
|
155
179
|
const sections = [];
|
|
156
180
|
for (const page of storyPages) {
|
|
157
181
|
const section = sectionNames.get(page.name);
|
|
@@ -180,8 +204,8 @@ function convertGame(game, options) {
|
|
|
180
204
|
assets.add(file);
|
|
181
205
|
},
|
|
182
206
|
};
|
|
183
|
-
const lines = [];
|
|
184
|
-
const directives = [];
|
|
207
|
+
const lines = stopInMaster ? [] : [...stopSounds.lines];
|
|
208
|
+
const directives = stopInMaster ? [] : [...stopSounds.directives];
|
|
185
209
|
if (page.name == startPage) {
|
|
186
210
|
const initial = [...dynamicLinks.values()].filter(l => l.initial !== undefined);
|
|
187
211
|
const parts = [];
|
|
@@ -266,11 +290,17 @@ function convertGame(game, options) {
|
|
|
266
290
|
if (youtube) {
|
|
267
291
|
lines.push(`<iframe class="quest-youtube" width="560" height="315" src="https://www.youtube.com/embed/${encodeURIComponent(youtube)}" allowfullscreen></iframe>`, "");
|
|
268
292
|
}
|
|
269
|
-
const sound =
|
|
293
|
+
const sound = pageSound(page);
|
|
270
294
|
if (sound) {
|
|
271
295
|
ctx.asset(sound);
|
|
272
|
-
|
|
273
|
-
|
|
296
|
+
if (continuesSound) {
|
|
297
|
+
// After the sounds are stopped at the start of the page, which is in its text
|
|
298
|
+
const continues = booleanValue(page.attributes.get("continuesound")) ?? false;
|
|
299
|
+
lines.push(`{{sound ${quote(sound)}}}{{set ${quote(continueAttribute)} ${continues}}}`);
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
directives.push(`@sound ${sound}`);
|
|
303
|
+
}
|
|
274
304
|
}
|
|
275
305
|
lines.push(convertQuestText(stringAttribute(page, "description"), ctx, "block"));
|
|
276
306
|
const links = pageLinks();
|
|
@@ -299,6 +329,8 @@ function convertGame(game, options) {
|
|
|
299
329
|
const master = [];
|
|
300
330
|
if (clearLastPage)
|
|
301
331
|
master.push("@clear");
|
|
332
|
+
if (stopInMaster)
|
|
333
|
+
master.push(...stopSounds.directives, ...stopSounds.lines);
|
|
302
334
|
if (roomEnter) {
|
|
303
335
|
const ctx = {
|
|
304
336
|
section: "",
|
|
@@ -330,9 +362,6 @@ function convertGame(game, options) {
|
|
|
330
362
|
addProblem({ text: setting, reason: `The game's "${setting}" script can't be converted yet: ${oneLine(value.value)}` });
|
|
331
363
|
}
|
|
332
364
|
}
|
|
333
|
-
if (hasSound) {
|
|
334
|
-
addProblem({ text: "sound", reason: "Each page's sound plays to the end. In Quest, it stopped when the player went to another page, unless the page was set to continue playing it." });
|
|
335
|
-
}
|
|
336
365
|
for (const file of game.javascript) {
|
|
337
366
|
addProblem({ text: file, reason: "The game's JavaScript was written for Quest, so it isn't part of the story." });
|
|
338
367
|
}
|
package/dist/quest/scripts.js
CHANGED
|
@@ -247,11 +247,15 @@ class Converter {
|
|
|
247
247
|
return [];
|
|
248
248
|
const file = this.text(args[0], "a sound");
|
|
249
249
|
ctx.asset(file);
|
|
250
|
-
|
|
251
|
-
|
|
250
|
+
// A sound that loops is music. The story stops it, and any sounds, at the next page,
|
|
251
|
+
// as Quest did.
|
|
252
|
+
if (args[2]?.k == "bool" && args[2].v)
|
|
253
|
+
return [`{{music ${quote(file)}}}`];
|
|
254
|
+
return [`{{sound ${quote(file)}}}`];
|
|
252
255
|
}
|
|
253
256
|
case "stop sound":
|
|
254
|
-
|
|
257
|
+
// Quest stops every sound, including one that loops, which is music here
|
|
258
|
+
return ["{{stopsounds}}{{stopmusic}}"];
|
|
255
259
|
case "ShowYouTube":
|
|
256
260
|
return this.show([`<iframe class="quest-youtube" width="560" height="315" src="https://www.youtube.com/embed/${encodeURIComponent(this.text(args[0], "a video"))}" allowfullscreen></iframe>`]);
|
|
257
261
|
case "DisplayHttpLink": {
|
package/dist/setters.d.ts
CHANGED
|
@@ -23,6 +23,10 @@ export interface AtAttribute {
|
|
|
23
23
|
range: Range;
|
|
24
24
|
}
|
|
25
25
|
export declare function findAtAttributes(file: SquiffyFile): AtAttribute[];
|
|
26
|
+
export declare function splitWithOffsets(setters: string): {
|
|
27
|
+
text: string;
|
|
28
|
+
offset: number;
|
|
29
|
+
}[];
|
|
26
30
|
export declare function attributesSetIn(file: SquiffyFile, text: string): Set<string>;
|
|
27
31
|
export interface UnquotedText {
|
|
28
32
|
text: string;
|
package/dist/setters.js
CHANGED
|
@@ -251,8 +251,9 @@ export function findAtAttributes(file) {
|
|
|
251
251
|
return result;
|
|
252
252
|
}
|
|
253
253
|
// Splits a list of setters with the rules of a story that uses expressions (as splitSetters in
|
|
254
|
-
// runtime/src/infixExpressions.ts does): on commas outside quotes and
|
|
255
|
-
|
|
254
|
+
// runtime/src/infixExpressions.ts does): on commas outside quotes, brackets and objects. Keeps
|
|
255
|
+
// offsets.
|
|
256
|
+
export function splitWithOffsets(setters) {
|
|
256
257
|
const result = [];
|
|
257
258
|
let depth = 0;
|
|
258
259
|
let quote = null;
|
|
@@ -267,9 +268,9 @@ function splitWithOffsets(setters) {
|
|
|
267
268
|
}
|
|
268
269
|
else if (c === "\"" || c === "'")
|
|
269
270
|
quote = c;
|
|
270
|
-
else if (c === "(")
|
|
271
|
+
else if (c === "(" || c === "[" || c === "{")
|
|
271
272
|
depth++;
|
|
272
|
-
else if (c === ")")
|
|
273
|
+
else if (c === ")" || c === "]" || c === "}")
|
|
273
274
|
depth = Math.max(0, depth - 1);
|
|
274
275
|
else if (i === setters.length || (c === "," && depth === 0)) {
|
|
275
276
|
result.push({ text: setters.slice(start, i), offset: start });
|
|
@@ -344,7 +345,8 @@ export function findUnquotedText(file, isSet) {
|
|
|
344
345
|
const result = [];
|
|
345
346
|
for (const site of setterSites(file)) {
|
|
346
347
|
// Only plain "=": text with +=, -=, *= or /= is an error whatever it's written as
|
|
347
|
-
|
|
348
|
+
// The attribute can be a value inside an object, as in hero.name = Ann (#442)
|
|
349
|
+
const match = /^(\s*)(\w+(?:\.\w+)*)(\s*=(?!=)\s*)(.*?)\s*$/.exec(site.text);
|
|
348
350
|
if (!match)
|
|
349
351
|
continue;
|
|
350
352
|
const [, leading, attribute, eq, value] = match;
|
package/dist/syntax.d.ts
CHANGED
|
@@ -121,6 +121,19 @@ export interface EndNode {
|
|
|
121
121
|
type: "end";
|
|
122
122
|
range: Range;
|
|
123
123
|
}
|
|
124
|
+
export interface SoundNode {
|
|
125
|
+
type: "sound";
|
|
126
|
+
directive: "music" | "sound";
|
|
127
|
+
value: string;
|
|
128
|
+
valueRange: Range;
|
|
129
|
+
range: Range;
|
|
130
|
+
}
|
|
131
|
+
export interface ClassNode {
|
|
132
|
+
type: "class";
|
|
133
|
+
value: string;
|
|
134
|
+
valueRange: Range;
|
|
135
|
+
range: Range;
|
|
136
|
+
}
|
|
124
137
|
export interface AttributeNode {
|
|
125
138
|
type: "attribute";
|
|
126
139
|
directive: "set" | "unset" | "inc" | "dec";
|
|
@@ -140,7 +153,7 @@ export interface TextNode {
|
|
|
140
153
|
text: string;
|
|
141
154
|
range: Range;
|
|
142
155
|
}
|
|
143
|
-
export type StatementNode = SeparatorNode | TitleNode | StartNode | ImportNode | UiBlockStartNode | UiFileNode | ClearNode | RepeatNode | EndNode | AttributeNode | JsNode | TextNode;
|
|
156
|
+
export type StatementNode = SeparatorNode | TitleNode | StartNode | ImportNode | UiBlockStartNode | UiFileNode | ClearNode | RepeatNode | EndNode | AttributeNode | SoundNode | ClassNode | JsNode | TextNode;
|
|
144
157
|
export interface LinkNode {
|
|
145
158
|
type: "link";
|
|
146
159
|
linkType: "section" | "passage";
|