rpg-engine 0.16.0 → 0.17.1
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/adventures/source.d.ts +3 -1
- package/dist/adventures/source.js +31 -1
- package/dist/campaign/find-campaign.js +8 -4
- package/dist/commands/import/import.js +23 -1
- package/dist/commands/package/package.js +43 -9
- package/dist/commands/package/result.d.ts +3 -4
- package/dist/commands/save.d.ts +1 -1
- package/dist/commands/shared/books/adventure-layers.d.ts +89 -0
- package/dist/commands/shared/books/adventure-layers.js +201 -0
- package/dist/commands/shared/books/adventures.d.ts +25 -8
- package/dist/commands/shared/books/adventures.js +60 -22
- package/dist/commands/shared/characters/thoughts.d.ts +7 -4
- package/dist/commands/shared/characters/thoughts.js +15 -5
- package/dist/commands/shared/scene/scene.js +3 -1
- package/dist/commands/shared/sheet/sheet.d.ts +2 -0
- package/dist/commands/show.d.ts +6 -0
- package/dist/commands/show.js +16 -2
- package/dist/commands/thoughts.d.ts +1 -0
- package/dist/commands/thoughts.js +23 -15
- package/dist/commands/view/layers.d.ts +36 -0
- package/dist/commands/view/layers.js +53 -0
- package/dist/commands/view/memory.js +12 -6
- package/dist/commands/view/page.js +4 -1
- package/dist/commands/view/result.d.ts +8 -1
- package/dist/commands/view/view.d.ts +3 -0
- package/dist/commands/view/view.js +5 -2
- package/dist/commands/write/inheritance.js +1 -5
- package/dist/commands/write/layer.d.ts +11 -3
- package/dist/commands/write/layer.js +27 -7
- package/dist/commands/write/write.d.ts +1 -0
- package/dist/commands/write/write.js +6 -2
- package/dist/core/length.d.ts +4 -1
- package/dist/core/length.js +13 -2
- package/dist/core/text.d.ts +2 -0
- package/dist/core/text.js +4 -0
- package/dist/dashboard/api.js +18 -0
- package/dist/dashboard/app.js +5 -1
- package/dist/dashboard/guide/ar.md +3 -1
- package/dist/dashboard/guide/cs.md +5 -3
- package/dist/dashboard/guide/da.md +5 -3
- package/dist/dashboard/guide/de.md +3 -1
- package/dist/dashboard/guide/el.md +5 -3
- package/dist/dashboard/guide/en.md +2 -0
- package/dist/dashboard/guide/es.md +5 -3
- package/dist/dashboard/guide/fi.md +5 -3
- package/dist/dashboard/guide/fr.md +5 -3
- package/dist/dashboard/guide/he.md +4 -2
- package/dist/dashboard/guide/hi.md +5 -3
- package/dist/dashboard/guide/hu.md +5 -3
- package/dist/dashboard/guide/is.md +5 -3
- package/dist/dashboard/guide/it.md +3 -1
- package/dist/dashboard/guide/ja.md +3 -1
- package/dist/dashboard/guide/ko.md +3 -1
- package/dist/dashboard/guide/nb.md +5 -3
- package/dist/dashboard/guide/nl.md +4 -2
- package/dist/dashboard/guide/pl.md +5 -3
- package/dist/dashboard/guide/pt.md +4 -2
- package/dist/dashboard/guide/ro.md +5 -3
- package/dist/dashboard/guide/ru.md +4 -2
- package/dist/dashboard/guide/sv.md +5 -3
- package/dist/dashboard/guide/tr.md +4 -2
- package/dist/dashboard/guide/uk.md +5 -3
- package/dist/dashboard/guide/zh.md +4 -2
- package/dist/dashboard/i18n/ar.json +25 -0
- package/dist/dashboard/i18n/cs.json +25 -0
- package/dist/dashboard/i18n/da.json +25 -0
- package/dist/dashboard/i18n/de.json +25 -0
- package/dist/dashboard/i18n/el.json +25 -0
- package/dist/dashboard/i18n/es.json +25 -0
- package/dist/dashboard/i18n/fi.json +25 -0
- package/dist/dashboard/i18n/fr.json +25 -0
- package/dist/dashboard/i18n/he.json +25 -0
- package/dist/dashboard/i18n/hi.json +25 -0
- package/dist/dashboard/i18n/hu.json +25 -0
- package/dist/dashboard/i18n/is.json +25 -0
- package/dist/dashboard/i18n/it.json +25 -0
- package/dist/dashboard/i18n/ja.json +25 -0
- package/dist/dashboard/i18n/ko.json +25 -0
- package/dist/dashboard/i18n/nb.json +25 -0
- package/dist/dashboard/i18n/nl.json +25 -0
- package/dist/dashboard/i18n/pl.json +25 -0
- package/dist/dashboard/i18n/pt.json +25 -0
- package/dist/dashboard/i18n/ro.json +25 -0
- package/dist/dashboard/i18n/ru.json +25 -0
- package/dist/dashboard/i18n/sv.json +25 -0
- package/dist/dashboard/i18n/tr.json +25 -0
- package/dist/dashboard/i18n/uk.json +25 -0
- package/dist/dashboard/i18n/zh.json +25 -0
- package/dist/dashboard/packages/changes.js +111 -0
- package/dist/dashboard/packages/installed.js +2 -2
- package/dist/dashboard/packages/packages.js +12 -7
- package/dist/dashboard/parts/changed.js +37 -0
- package/dist/dashboard/parts/refusals.js +4 -0
- package/dist/dashboard/parts/widgets.js +3 -1
- package/dist/dashboard/play/choices.js +3 -2
- package/dist/dashboard/sheet/sheet.js +10 -7
- package/dist/dashboard/shell/shown.js +1 -0
- package/dist/dashboard/style.css +214 -1
- package/dist/dashboard/world/lore.js +5 -1
- package/dist/pages/index.d.ts +3 -3
- package/dist/pages/index.js +3 -3
- package/dist/pages/layers.d.ts +5 -3
- package/dist/pages/layers.js +15 -7
- package/dist/pages/load.d.ts +2 -0
- package/dist/pages/load.js +16 -3
- package/dist/pages/markdown.d.ts +5 -1
- package/dist/pages/markdown.js +13 -1
- package/dist/pages/write-layer.d.ts +5 -0
- package/dist/pages/write-layer.js +59 -5
- package/dist/server/dashboard/choices.d.ts +2 -0
- package/dist/server/dashboard/choices.js +4 -2
- package/dist/server/dashboard/index.js +5 -1
- package/dist/server/dashboard/writes.d.ts +7 -0
- package/dist/server/dashboard/writes.js +39 -0
- package/instructions/voices.md +1 -1
- package/package.json +1 -1
package/dist/pages/layers.js
CHANGED
|
@@ -3,7 +3,7 @@ import { join } from "node:path";
|
|
|
3
3
|
import { frozen } from "../core/frozen.js";
|
|
4
4
|
import { comparableText } from "../core/text.js";
|
|
5
5
|
import { isNeverInherited } from "./inheritance.js";
|
|
6
|
-
import { introductionText, partContent, textParts, writeText } from "./markdown.js";
|
|
6
|
+
import { introductionText, partContent, sectionAbove, textParts, writeText } from "./markdown.js";
|
|
7
7
|
import { kindIn } from "./system-pages.js";
|
|
8
8
|
/** The folder of a campaign that holds its layers, one folder for each game system. */
|
|
9
9
|
export const layersFolderName = "layers";
|
|
@@ -31,8 +31,9 @@ export function layeredPages(pages, layers, prefix, declared) {
|
|
|
31
31
|
return { pages: merged, stray };
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
* A page of the game system with a layer over it: the layer's fields take the place of the page's, a section of the layer that of the section with its name,
|
|
35
|
-
*
|
|
34
|
+
* A page of the game system with a layer over it: the layer's fields take the place of the page's, the text of a section of the layer that of the section with its name,
|
|
35
|
+
* at any level, or the section is added, inside the one the layer writes it under when the page has that one; and its introduction, when it has one, that of the
|
|
36
|
+
* page's. A heading with no text of its own takes nothing away. The translated text changes the same way where it has the section, else it goes, so that the
|
|
36
37
|
* campaign's text is never hidden. The page stays the system's.
|
|
37
38
|
*/
|
|
38
39
|
export function layeredPage(page, layer, path, declared) {
|
|
@@ -49,7 +50,12 @@ export function layeredPage(page, layer, path, declared) {
|
|
|
49
50
|
let body = page.body;
|
|
50
51
|
let translated = page.translated;
|
|
51
52
|
for (const part of parts) {
|
|
52
|
-
|
|
53
|
+
const there = partContent(body, part.name) !== undefined;
|
|
54
|
+
// A heading without text only says where the sections under it go: the page's text under that name stays, and with nothing under it it is no section.
|
|
55
|
+
if (part.content === "" && (there || !parts.some((other) => comparableText(other.under ?? "") === comparableText(part.name)))) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
body = writeText(body, part.content, { section: part.name, mode: "replace", secret: part.secret && !there, under: part.under });
|
|
53
59
|
translated = translated === undefined || partContent(translated, part.name) === undefined
|
|
54
60
|
? undefined
|
|
55
61
|
: writeText(translated, part.content, { section: part.name, mode: "replace", secret: false });
|
|
@@ -58,7 +64,8 @@ export function layeredPage(page, layer, path, declared) {
|
|
|
58
64
|
body = writeText(body, introduction, { mode: "replace" });
|
|
59
65
|
translated = translated === undefined ? undefined : writeText(translated, introduction, { mode: "replace" });
|
|
60
66
|
}
|
|
61
|
-
const
|
|
67
|
+
const sections = parts.filter((part) => part.content !== "").map((part) => part.name);
|
|
68
|
+
const layered = { path, fields: given.map(([field]) => field), sections, introduction: introduction !== "", ignored };
|
|
62
69
|
const merged = { ...page, fields, body, translated, layer: layered };
|
|
63
70
|
// A translation the layer could not follow goes, so that the campaign's text is never hidden.
|
|
64
71
|
if (translated === undefined) {
|
|
@@ -82,11 +89,12 @@ export function layerTakes(page, field, value, declared) {
|
|
|
82
89
|
const counted = (name, given) => isUses(given) && [undefined, "counter"].includes(kindIn(declared, name));
|
|
83
90
|
return page.type !== "item" || !counted(field, value) || Object.entries(page.fields).some(([name, given]) => counted(name, given));
|
|
84
91
|
}
|
|
85
|
-
/** The sections and secrets of a layer's text, each with its own text
|
|
92
|
+
/** The sections and secrets of a layer's text, in order: each with its own text, none for a heading that only holds others, whether it is a secret, and the section it is written under. */
|
|
86
93
|
export function layerParts(body) {
|
|
87
94
|
return textParts(body).filter((part) => part.name !== "").flatMap((part) => {
|
|
88
95
|
const own = partContent(body, part.name);
|
|
89
|
-
|
|
96
|
+
const under = own === undefined || own.secret ? undefined : sectionAbove(body, part.name);
|
|
97
|
+
return own === undefined ? [] : [{ name: part.name, ...own, ...(under === undefined ? {} : { under }) }];
|
|
90
98
|
});
|
|
91
99
|
}
|
|
92
100
|
const originals = new WeakMap();
|
package/dist/pages/load.d.ts
CHANGED
|
@@ -13,5 +13,7 @@ export interface LoadRule {
|
|
|
13
13
|
export declare function carriedWeight(world: World, rule: LoadRule, holder: Page): number;
|
|
14
14
|
/** The unit the system's weights are written in, as lb; undefined when no page says. */
|
|
15
15
|
export declare function weightUnit(world: World, field: string): string | undefined;
|
|
16
|
+
/** A weight written in pounds told in kilograms at the system's pound, its note kept: 6 lb is 3 kg, 5 lb (full) 2.5 kg (full); any other text unchanged. */
|
|
17
|
+
export declare function poundsInKilograms(text: string, pound: number): string;
|
|
16
18
|
/** How many pieces one of a kind holds, by the field the system declares for its bundle: 1 for a kind not sold by the bundle (STK-2). */
|
|
17
19
|
export declare function bundleOf(field: string | undefined, kind: Page): number;
|
package/dist/pages/load.js
CHANGED
|
@@ -14,6 +14,15 @@ export function weightUnit(world, field) {
|
|
|
14
14
|
const written = (world.system?.pages ?? []).map((page) => page.fields[field]).find((value) => typeof value === "string" && /\p{L}/u.test(value));
|
|
15
15
|
return typeof written === "string" ? /(\p{L}[\p{L}.]*)\s*$/u.exec(written)?.[1] : undefined;
|
|
16
16
|
}
|
|
17
|
+
/** A weight written in pounds told in kilograms at the system's pound, its note kept: 6 lb is 3 kg, 5 lb (full) 2.5 kg (full); any other text unchanged. */
|
|
18
|
+
export function poundsInKilograms(text, pound) {
|
|
19
|
+
const match = /^\s*([\d,]*(?:\.\d+)?)\s*(½|¼|¾|\d+\/\d+)?\s*(?:lbs?\.?|pounds?)\s*(\([^()]*\))?\s*$/iu.exec(text);
|
|
20
|
+
if (match === null || (match[1] === "" && match[2] === undefined)) {
|
|
21
|
+
return text;
|
|
22
|
+
}
|
|
23
|
+
const kilograms = Math.round(writtenWeight(match[1], match[2]) * pound * 1000) / 1000;
|
|
24
|
+
return match[3] === undefined ? `${kilograms} kg` : `${kilograms} kg ${match[3]}`;
|
|
25
|
+
}
|
|
17
26
|
/** How many pieces one of a kind holds, by the field the system declares for its bundle: 1 for a kind not sold by the bundle (STK-2). */
|
|
18
27
|
export function bundleOf(field, kind) {
|
|
19
28
|
const pieces = field === undefined ? Number.NaN : Number(valueNamed(kind.fields, field));
|
|
@@ -56,10 +65,14 @@ function weightOf(world, field, page) {
|
|
|
56
65
|
if (match === null || (match[1] === "" && match[2] === undefined)) {
|
|
57
66
|
return 0;
|
|
58
67
|
}
|
|
68
|
+
return writtenWeight(match[1], match[2]);
|
|
69
|
+
}
|
|
70
|
+
/** A weight's number from its whole part and its fraction, as written: 1,000, 0,5, 1 and ½, and 1/4. */
|
|
71
|
+
function writtenWeight(whole, fraction) {
|
|
59
72
|
// A comma before three digits groups thousands, as 1,000; any other is a decimal comma, as 0,5.
|
|
60
|
-
const
|
|
61
|
-
const part =
|
|
62
|
-
return
|
|
73
|
+
const number = whole === "" ? 0 : Number(whole.replace(/,(?=\d{3}(?!\d))/g, "").replace(",", "."));
|
|
74
|
+
const part = fraction === undefined ? 0 : { "½": 0.5, "¼": 0.25, "¾": 0.75 }[fraction] ?? Number(fraction.split("/")[0]) / Number(fraction.split("/")[1]);
|
|
75
|
+
return number + part;
|
|
63
76
|
}
|
|
64
77
|
/** What the coins of a purse weigh, as many coins as the system says make one unit of weight; 0 when it says none. */
|
|
65
78
|
function coinsWeight(fields, perUnit) {
|
package/dist/pages/markdown.d.ts
CHANGED
|
@@ -21,18 +21,22 @@ export declare function partContent(text: string, name: string): {
|
|
|
21
21
|
secret: boolean;
|
|
22
22
|
content: string;
|
|
23
23
|
} | undefined;
|
|
24
|
+
/** The section a section is written under: the nearest heading above its own, of a higher level; undefined for one at the top, a secret, or a name the text lacks. */
|
|
25
|
+
export declare function sectionAbove(text: string, name: string): string | undefined;
|
|
24
26
|
/** A section with its subsections, down to the next heading of the same or a higher level, or a secret block. Names ignore case. */
|
|
25
27
|
export declare function readSection(text: string, title: string): string | undefined;
|
|
26
28
|
/** How text is written: in place of the old text, added at its end, or, empty, removing a section or secret. */
|
|
27
29
|
export type TextMode = "replace" | "append" | "remove";
|
|
28
30
|
/**
|
|
29
31
|
* Writes the introduction (the text before the first heading), a section's own text (its subsections stay) or a secret block.
|
|
30
|
-
* Secret blocks inside a rewritten text stay, after the new text. A missing section is added at the end: at the page's top heading level, or as a secret block
|
|
32
|
+
* Secret blocks inside a rewritten text stay, after the new text. A missing section is added at the end: at the page's top heading level, or as a secret block;
|
|
33
|
+
* with `under`, a section the text has, at the end of that one, a level below it.
|
|
31
34
|
*/
|
|
32
35
|
export declare function writeText(text: string, newText: string, options: {
|
|
33
36
|
section?: string;
|
|
34
37
|
mode: TextMode;
|
|
35
38
|
secret?: boolean;
|
|
39
|
+
under?: string;
|
|
36
40
|
}): string;
|
|
37
41
|
/** The pages a text links to, as in [[Page]], [[Page#Section]], [[Page|label]] or [[folder/Page.md]]. Links in code and in %% comments %% do not count. */
|
|
38
42
|
export declare function linkedPages(text: string): string[];
|
package/dist/pages/markdown.js
CHANGED
|
@@ -66,6 +66,12 @@ export function partContent(text, name) {
|
|
|
66
66
|
const secret = findSecret(lines, name);
|
|
67
67
|
return secret === undefined ? undefined : { secret: true, content: trimBlankLines(lines.slice(secret.start + 1, secret.end).map((line) => line.replace(quotePattern, "")).join("\n")) };
|
|
68
68
|
}
|
|
69
|
+
/** The section a section is written under: the nearest heading above its own, of a higher level; undefined for one at the top, a secret, or a name the text lacks. */
|
|
70
|
+
export function sectionAbove(text, name) {
|
|
71
|
+
const headings = headingsOf(text.split("\n"));
|
|
72
|
+
const index = headings.findIndex((heading) => comparableText(heading.title) === comparableText(name.trim()));
|
|
73
|
+
return index === -1 ? undefined : headings.slice(0, index).findLast((other) => other.level < headings[index].level)?.title;
|
|
74
|
+
}
|
|
69
75
|
/** A section with its subsections, down to the next heading of the same or a higher level, or a secret block. Names ignore case. */
|
|
70
76
|
export function readSection(text, title) {
|
|
71
77
|
const lines = text.split("\n");
|
|
@@ -74,7 +80,8 @@ export function readSection(text, title) {
|
|
|
74
80
|
}
|
|
75
81
|
/**
|
|
76
82
|
* Writes the introduction (the text before the first heading), a section's own text (its subsections stay) or a secret block.
|
|
77
|
-
* Secret blocks inside a rewritten text stay, after the new text. A missing section is added at the end: at the page's top heading level, or as a secret block
|
|
83
|
+
* Secret blocks inside a rewritten text stay, after the new text. A missing section is added at the end: at the page's top heading level, or as a secret block;
|
|
84
|
+
* with `under`, a section the text has, at the end of that one, a level below it.
|
|
78
85
|
*/
|
|
79
86
|
export function writeText(text, newText, options) {
|
|
80
87
|
const lines = text.split("\n");
|
|
@@ -106,6 +113,11 @@ export function writeText(text, newText, options) {
|
|
|
106
113
|
if (options.mode === "remove") {
|
|
107
114
|
throw new Error(`There is no section or secret "${title}" to remove: show the page to see their names, or give some text to create it.`);
|
|
108
115
|
}
|
|
116
|
+
const parent = options.under === undefined || options.secret ? undefined : findSection(lines, options.under, "whole");
|
|
117
|
+
if (parent !== undefined) {
|
|
118
|
+
const level = Math.min(6, (headingPattern.exec(lines[parent.start])?.[1].length ?? 1) + 1);
|
|
119
|
+
return joinBlocks(lines.slice(0, parent.end).join("\n"), `${"#".repeat(level)} ${title}\n\n${newText}`, lines.slice(parent.end).join("\n"));
|
|
120
|
+
}
|
|
109
121
|
const block = options.secret ? [`> [!secret] ${title}`, ...quoteLines(newText)].join("\n") : `${"#".repeat(topHeadingLevel(lines))} ${title}\n\n${newText}`;
|
|
110
122
|
return joinBlocks(text, block);
|
|
111
123
|
}
|
|
@@ -16,3 +16,8 @@ export interface LayerWrite {
|
|
|
16
16
|
* from the system. unset, or an empty text, takes the layer's own value or section away, and the page reads the system's again. The system's files never change.
|
|
17
17
|
*/
|
|
18
18
|
export declare function writeLayer(world: World, page: Page, change: PageChange): LayerWrite;
|
|
19
|
+
/**
|
|
20
|
+
* Takes the campaign's whole layer off a page of its game system (SYS-11): its file goes, one that does not read too, and the page reads as the system writes it
|
|
21
|
+
* again. Refused when the page has none.
|
|
22
|
+
*/
|
|
23
|
+
export declare function removeLayer(world: World, page: Page): LayerWrite;
|
|
@@ -4,8 +4,8 @@ import { files } from "../core/store.js";
|
|
|
4
4
|
import { comparableText, sameName, valueNamed } from "../core/text.js";
|
|
5
5
|
import { changedFields, changeFields, joinPageFile, readFields, splitPageFile } from "./file.js";
|
|
6
6
|
import { isNeverInherited } from "./inheritance.js";
|
|
7
|
-
import { layersFolderName, layerTakes, systemOriginal } from "./layers.js";
|
|
8
|
-
import { introductionText, partContent, writeText } from "./markdown.js";
|
|
7
|
+
import { layerParts, layersFolderName, layerTakes, systemOriginal } from "./layers.js";
|
|
8
|
+
import { introductionText, partContent, readSection, repeatedNames, sectionTitles, writeText } from "./markdown.js";
|
|
9
9
|
import { systemLabel } from "./system-pages.js";
|
|
10
10
|
/**
|
|
11
11
|
* Writes the campaign's layer over a page of its game system (SYS-11): the change is read on the page as the campaign has it, and the layer keeps only what then differs
|
|
@@ -23,7 +23,8 @@ export function writeLayer(world, page, change) {
|
|
|
23
23
|
const held = readFields(file.frontmatter, path);
|
|
24
24
|
const fields = layerFields(world, page, original, held, change);
|
|
25
25
|
const frontmatter = fields.set.length + fields.unsetKeys.length === 0 ? file.frontmatter : changeFields(file.frontmatter, { set: fields.values, unset: fields.unsetKeys }, path);
|
|
26
|
-
const body = change.text === undefined ? file.body : layerText(page, original, file.body, change);
|
|
26
|
+
const body = change.text === undefined ? file.body : withoutIdleSections(layerText(page, original, file.body, change), original.body);
|
|
27
|
+
checkNamedOnce(page, file.body, body);
|
|
27
28
|
const empty = (frontmatter ?? "").trim() === "" && body.trim() === "";
|
|
28
29
|
const text = joinPageFile({ frontmatter, body });
|
|
29
30
|
const changed = empty ? before !== undefined : text !== (before === undefined ? undefined : joinPageFile(file));
|
|
@@ -35,6 +36,22 @@ export function writeLayer(world, page, change) {
|
|
|
35
36
|
}
|
|
36
37
|
return { path, changed, removed: empty && before !== undefined, set: fields.set, again: fields.again, unset: fields.unset };
|
|
37
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Takes the campaign's whole layer off a page of its game system (SYS-11): its file goes, one that does not read too, and the page reads as the system writes it
|
|
41
|
+
* again. Refused when the page has none.
|
|
42
|
+
*/
|
|
43
|
+
export function removeLayer(world, page) {
|
|
44
|
+
if (page.system === undefined) {
|
|
45
|
+
throw new Error(`${page.name} is a page of the campaign, which has no layer: a layer changes a page of the game system for the whole campaign. Nothing changed.`);
|
|
46
|
+
}
|
|
47
|
+
const path = page.layer?.path ?? `${layersFolderName}/${page.system}/${systemOriginal(page).path}`;
|
|
48
|
+
const fullPath = join(world.root, path);
|
|
49
|
+
if (files().fresh(fullPath) === undefined) {
|
|
50
|
+
throw new Error(`The campaign has no layer over ${page.name} to take off: it already reads as the system ${page.system} writes it. Nothing changed.`);
|
|
51
|
+
}
|
|
52
|
+
files().remove(fullPath);
|
|
53
|
+
return { path, changed: true, removed: true, set: [], again: page.layer?.fields ?? [], unset: [] };
|
|
54
|
+
}
|
|
38
55
|
/** The fields a change gives the layer: those that differ from the system's go in, those equal to it come out, unset takes the layer's own away. */
|
|
39
56
|
function layerFields(world, page, original, held, change) {
|
|
40
57
|
const lists = Object.fromEntries([...Object.keys(change.add ?? {}), ...Object.keys(change.remove ?? {})].map((field) => {
|
|
@@ -95,14 +112,51 @@ function layerText(page, original, body, change) {
|
|
|
95
112
|
const systemText = typeof system === "string" ? system : system?.content;
|
|
96
113
|
if (content === "" || content === systemText) {
|
|
97
114
|
if (own === undefined || own === "") {
|
|
98
|
-
const
|
|
115
|
+
const under = section === undefined ? [] : layerParts(body).filter((part) => part.content !== "" && comparableText(part.under ?? "") === comparableText(section)).map((part) => part.name);
|
|
116
|
+
const remedy = content !== ""
|
|
117
|
+
? ""
|
|
118
|
+
: under.length > 0
|
|
119
|
+
? `: what the layer writes under it, ${under.join(", ")}, goes by its own name`
|
|
120
|
+
: systemText !== undefined && systemText !== ""
|
|
121
|
+
? `: the system's text cannot be removed, only written over with another`
|
|
122
|
+
: "";
|
|
99
123
|
throw new Error(content === "" ? `The campaign's layer over ${page.name} has no ${where} of its own to remove${remedy}. Nothing changed.` : `${where} of ${page.name} already reads like that. Nothing changed.`);
|
|
100
124
|
}
|
|
101
|
-
|
|
125
|
+
// A section loses its own text alone: what the layer writes under it stays, and a heading left with nothing goes with the idle ones.
|
|
126
|
+
return section === undefined ? writeText(body, "", { mode: "replace" }) : writeText(body, "", { section, mode: partContent(body, section)?.secret === true ? "remove" : "replace" });
|
|
102
127
|
}
|
|
103
128
|
const secret = change.secret === true || (typeof system === "object" && system.secret);
|
|
104
129
|
return writeText(body, content, { mode: "replace", ...(section === undefined ? {} : { section, secret: own === undefined && secret }) });
|
|
105
130
|
}
|
|
131
|
+
/** Refuses a text that gives the layer a section or secret it already holds, as a heading of one written before: Page#Name finds one place. */
|
|
132
|
+
function checkNamedOnce(page, before, after) {
|
|
133
|
+
const already = repeatedNames(before).map(comparableText);
|
|
134
|
+
const [repeated] = repeatedNames(after).filter((name) => !already.includes(comparableText(name)));
|
|
135
|
+
if (repeated !== undefined) {
|
|
136
|
+
throw new Error(`The campaign's layer over ${page.name} would hold "${repeated}" twice, and each section is written once: to change it, write ${page.name}#${repeated} with layer; for a new one, pick another name. Nothing changed.`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* A layer's text without the sections that give nothing (SYS-11): the text of one that says what the system's says comes out, and a heading left with no text,
|
|
141
|
+
* no section under it and no secret goes, from the last, so that the one it was written under goes with it.
|
|
142
|
+
*/
|
|
143
|
+
function withoutIdleSections(body, system) {
|
|
144
|
+
let text = body;
|
|
145
|
+
for (const name of [...sectionTitles(body)].reverse()) {
|
|
146
|
+
const own = partContent(text, name);
|
|
147
|
+
if (own === undefined || own.secret) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (own.content !== "" && own.content === partContent(system, name)?.content) {
|
|
151
|
+
text = writeText(text, "", { section: name, mode: "replace" });
|
|
152
|
+
}
|
|
153
|
+
// Its heading alone: no text, no section under it, no secret.
|
|
154
|
+
if (readSection(text, name)?.includes("\n") === false) {
|
|
155
|
+
text = writeText(text, "", { section: name, mode: "remove" });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return text;
|
|
159
|
+
}
|
|
106
160
|
function pick(lists, field) {
|
|
107
161
|
return lists?.[field] === undefined ? undefined : { [field]: lists[field] };
|
|
108
162
|
}
|
|
@@ -12,6 +12,8 @@ export interface OptionPage {
|
|
|
12
12
|
name: string;
|
|
13
13
|
title: string;
|
|
14
14
|
opening: string;
|
|
15
|
+
/** It is, or derives from, a page of the game system the campaign changed with a layer (SYS-11). */
|
|
16
|
+
layered?: true;
|
|
15
17
|
}
|
|
16
18
|
/** A set of choices as the page shows it. */
|
|
17
19
|
export interface ShownChoices {
|
|
@@ -2,8 +2,9 @@ import { z } from "zod";
|
|
|
2
2
|
import { findCampaign, readChoices, readSettings, writeChoices } from "../../campaign/index.js";
|
|
3
3
|
import { confirmedNotes, offeredPages, optionParts } from "../../commands/choices.js";
|
|
4
4
|
import { campaignSystem, campaignWorld } from "../../commands/shared/campaign/world.js";
|
|
5
|
-
import { knownIntroduction, playerKnowledge, withPagesKnown } from "../../commands/shared/characters/knowledge.js";
|
|
5
|
+
import { knownIntroduction, knowsPage, playerKnowledge, withPagesKnown } from "../../commands/shared/characters/knowledge.js";
|
|
6
6
|
import { newDatedLogEntry } from "../../commands/shared/time/time.js";
|
|
7
|
+
import { isLayered } from "../../commands/view/layers.js";
|
|
7
8
|
import { appendLogEntry } from "../../core/log.js";
|
|
8
9
|
import { withFiles } from "../../core/store.js";
|
|
9
10
|
import { firstSentence } from "../../core/text.js";
|
|
@@ -90,7 +91,8 @@ function shownOption(world, knowledge, option) {
|
|
|
90
91
|
const found = parts.pages.map((name) => findPage(world, name)).filter((page) => page !== undefined);
|
|
91
92
|
const pages = found.filter((page, index) => found.findIndex((other) => other.name === page.name) === index).map((page) => {
|
|
92
93
|
const introduction = knowledge === undefined ? withoutComments(introductionText(page.translated ?? page.body)) : knownIntroduction(world, knowledge, page);
|
|
93
|
-
|
|
94
|
+
const layered = isLayered(world, page, (base) => knowledge === undefined || knowsPage(knowledge, base)) ? { layered: true } : {};
|
|
95
|
+
return { name: page.name, title: page.title ?? page.name, opening: firstSentence(linkWords(world, introduction).replace(/\s+/g, " ").trim()), ...layered };
|
|
94
96
|
});
|
|
95
97
|
return {
|
|
96
98
|
text: option,
|
|
@@ -21,7 +21,7 @@ import { builtPage, packagePageFile, pageFile, pageHtml, pageModulesOf, pagePoli
|
|
|
21
21
|
import { act, deliverActs, keepProblems, listenForBell, notes, pageNews, setupWord, story } from "./news.js";
|
|
22
22
|
import { answerAsked, closeCard, listenForChanges, pagePlayer, pageSeen, rollNamesOf, spendShown } from "./player.js";
|
|
23
23
|
import { campaignPorts } from "./ports.js";
|
|
24
|
-
import { addPackage, catalogNow, changeLibrary, changePackage, changeSaves, changeSetting, engineNow, exportCampaign, exportedFile, libraryNow, packagesNow, runForPlayer } from "./writes.js";
|
|
24
|
+
import { addPackage, catalogNow, changeLibrary, changePackage, changeSaves, changeSetting, engineNow, exportCampaign, exportedFile, libraryNow, packagesNow, runForPlayer, takeLayerOff, } from "./writes.js";
|
|
25
25
|
export { campaignPorts, dashboardPorts } from "./ports.js";
|
|
26
26
|
// The commands the page may run: what the player may see, never the master's (VIEW-1). Roles will say more (phase 2).
|
|
27
27
|
const playerCommands = [view];
|
|
@@ -261,6 +261,10 @@ async function answer(request, response, served) {
|
|
|
261
261
|
await changeSaves(request, response, served);
|
|
262
262
|
return;
|
|
263
263
|
}
|
|
264
|
+
if (request.method === "POST" && path === "/api/layer" && origin !== undefined) {
|
|
265
|
+
await takeLayerOff(request, response, served);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
264
268
|
if (path === "/api/words" && (request.method === "GET" || (request.method === "POST" && origin !== undefined))) {
|
|
265
269
|
await pageWords(request, response, served, url);
|
|
266
270
|
return;
|
|
@@ -19,6 +19,13 @@ export declare function changeSetting(request: IncomingMessage, response: Server
|
|
|
19
19
|
* mode of saves allows it or refuses it as in the chat, and starting over needs the campaign's name written. The master hears of it at their next call (D-359).
|
|
20
20
|
*/
|
|
21
21
|
export declare function changeSaves(request: IncomingMessage, response: ServerResponse, served: Served): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* A layer of the campaign the player takes off a page of the game system on the page (SYS-11), as write does with layer and reset, with the player as who did it;
|
|
24
|
+
* the master hears of it at their next call. Off any page the view lists, one the player may not read too (D-565); any other name gets one answer. Every
|
|
25
|
+
* page waits while a scene is open, whoever is in it: what derives from the page would change in the middle of it, and a refusal for its copies alone would
|
|
26
|
+
* tell what the scene holds (D-254).
|
|
27
|
+
*/
|
|
28
|
+
export declare function takeLayerOff(request: IncomingMessage, response: ServerResponse, served: Served): Promise<void>;
|
|
22
29
|
/**
|
|
23
30
|
* The packages as the page shows them (D-475): the game system, those on this computer with whether the campaign uses them, those it lists and lacks, what npm
|
|
24
31
|
* has when asked, and the one the player is working on now.
|
|
@@ -14,6 +14,9 @@ import { exportsFolderName, resetPoints } from "../../commands/shared/campaign/s
|
|
|
14
14
|
import { campaignSystem, campaignWorld } from "../../commands/shared/campaign/world.js";
|
|
15
15
|
import { catalog } from "../../commands/shared/packages/catalog.js";
|
|
16
16
|
import { packageCommands } from "../../commands/shared/packages/code.js";
|
|
17
|
+
import { readOpenScene } from "../../commands/shared/scene/scene.js";
|
|
18
|
+
import { listedLayer } from "../../commands/view/layers.js";
|
|
19
|
+
import { write } from "../../commands/write/write.js";
|
|
17
20
|
import { packagesFolder } from "../../core/context.js";
|
|
18
21
|
import { Refusal, refusalBody } from "../../core/refusal.js";
|
|
19
22
|
import { files, withFiles } from "../../core/store.js";
|
|
@@ -171,6 +174,42 @@ export async function changeSaves(request, response, served) {
|
|
|
171
174
|
sendJson(response, 400, { error: error instanceof Error ? error.message : String(error) });
|
|
172
175
|
}
|
|
173
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* A layer of the campaign the player takes off a page of the game system on the page (SYS-11), as write does with layer and reset, with the player as who did it;
|
|
179
|
+
* the master hears of it at their next call. Off any page the view lists, one the player may not read too (D-565); any other name gets one answer. Every
|
|
180
|
+
* page waits while a scene is open, whoever is in it: what derives from the page would change in the middle of it, and a refusal for its copies alone would
|
|
181
|
+
* tell what the scene holds (D-254).
|
|
182
|
+
*/
|
|
183
|
+
export async function takeLayerOff(request, response, served) {
|
|
184
|
+
const parsed = z.object({ page: z.string().trim().min(1).max(mostSaid) }).strict().safeParse(await readBody(request));
|
|
185
|
+
if (!parsed.success) {
|
|
186
|
+
sendJson(response, 400, { error: "Send the page of the game system whose change to take off: { page }." });
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
await served.session.ready();
|
|
191
|
+
const done = await withFiles(served.session, async () => {
|
|
192
|
+
const root = requireCampaign(served.context.folder);
|
|
193
|
+
const world = campaignWorld(root, served.context);
|
|
194
|
+
const page = listedLayer(world, parsed.data.page);
|
|
195
|
+
if (page === undefined) {
|
|
196
|
+
throw new Refusal(`The campaign changes no page of the game system named ${parsed.data.page}: reload the page.`, "no-layer", { page: parsed.data.page });
|
|
197
|
+
}
|
|
198
|
+
const open = readOpenScene(root);
|
|
199
|
+
// A scene that does not read counts as open.
|
|
200
|
+
if (open.scene !== undefined || open.problem !== undefined) {
|
|
201
|
+
throw new Refusal(`A scene is being played: take the campaign's change off ${page.name} once it is over.`, "scene-open", { page: page.name });
|
|
202
|
+
}
|
|
203
|
+
return await write.run(write.input.parse({ page: page.name, layer: true, reset: true }), { ...served.context, actor: "player" });
|
|
204
|
+
});
|
|
205
|
+
const followers = done.followers.length === 0 ? "" : ` What reads from it changed with it: ${done.followers.join(", ")}.`;
|
|
206
|
+
served.events.push(`The player, on the dashboard, took the campaign's change off ${done.page}: it reads as the system writes it again.${followers}`);
|
|
207
|
+
sendJson(response, 202, {});
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
sendJson(response, error instanceof Refusal && error.code === "scene-open" ? 409 : 400, refusalBody(error));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
174
213
|
/**
|
|
175
214
|
* The packages as the page shows them (D-475): the game system, those on this computer with whether the campaign uses them, those it lists and lacks, what npm
|
|
176
215
|
* has when asked, and the one the player is working on now.
|
package/instructions/voices.md
CHANGED
|
@@ -11,4 +11,4 @@ Once per moment; again only when something new is put to them: a proof, an offer
|
|
|
11
11
|
|
|
12
12
|
Before you ask, roll what the moment needs, the player's rolls as Play says under Rolls. Begin with their name, then write to them in the campaign's language, in the second person, present: what they see and hear now, what was said to them word for word, how it landed (a roll as how it felt, never its number), and the question: what they do and say, never their secrets offered as a choice. Never another's secrets, nor your plans. A secret of their page that they know reaches them only through `reveal`: if it is not yet theirs, reveal it to them before you ask. What their page decides about them for you ("breaks before two proofs") is no secret of theirs: write it as their nature ("two proofs, and you cannot hold it any longer"), never as a rule.
|
|
13
13
|
|
|
14
|
-
Their words and choice bind you: say their words, shortened if need be, never softened or rewritten; add only gestures that fit; a no stays no. What they keep stays behind the scenes: it reaches the player only through what they do, or a roll that earns it. The story, the rules, the dice and what follows are yours. Record what they decided or learned (`write`, `reveal`, `mood`)
|
|
14
|
+
Their words and choice bind you: say their words, shortened if need be, never softened or rewritten; add only gestures that fit; a no stays no. What they keep stays behind the scenes: it reaches the player only through what they do, or a roll that earns it. The story, the rules, the dice and what follows are yours. Record what they decided or learned (`write`, `reveal`, `mood`). What they keep, when it is a new fact or plan, write as their secret; when the moment changed them, write how they took it and whom they trust or fear now in their diary (`thoughts`), in their voice, never the secret again: they read it back next time. If their choice breaks an established fact, ask again with that fact; never overrule them. What they claim of others or of the world is their belief, not a fact: the truth is yours. Only what you record becomes canon: a detail of their own that their page left blank, and that holds, write on their page.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rpg-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.1",
|
|
4
4
|
"description": "Play a tabletop role-playing game with an AI as your game master: the AI tells the story; RPG Engine remembers the world, rolls the dice and keeps the accounts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|