rpg-engine 0.20.0 → 0.22.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/dist/adventures/index.d.ts +1 -1
- package/dist/adventures/index.js +1 -1
- package/dist/adventures/source.d.ts +3 -0
- package/dist/adventures/source.js +11 -49
- package/dist/campaign/create-campaign.d.ts +1 -1
- package/dist/campaign/create-campaign.js +3 -2
- package/dist/campaign/find-campaign.d.ts +2 -0
- package/dist/campaign/find-campaign.js +2 -0
- package/dist/campaign/host-files.js +4 -1
- package/dist/campaign/index.d.ts +3 -2
- package/dist/campaign/index.js +3 -2
- package/dist/campaign/port.d.ts +6 -0
- package/dist/campaign/port.js +24 -0
- package/dist/campaign/settings.d.ts +17 -0
- package/dist/campaign/settings.js +26 -3
- package/dist/cli/cli.js +15 -0
- package/dist/commands/book.d.ts +16 -35
- package/dist/commands/book.js +86 -62
- package/dist/commands/config/config.js +16 -2
- package/dist/commands/config/dashboard.d.ts +6 -2
- package/dist/commands/config/dashboard.js +45 -8
- package/dist/commands/config/shown.js +4 -0
- package/dist/commands/config/words.d.ts +3 -1
- package/dist/commands/config/words.js +29 -2
- package/dist/commands/image.d.ts +5 -0
- package/dist/commands/image.js +6 -3
- package/dist/commands/mode.d.ts +1 -1
- package/dist/commands/package/data.d.ts +35 -0
- package/dist/commands/package/data.js +144 -0
- package/dist/commands/package/here.d.ts +7 -2
- package/dist/commands/package/here.js +23 -11
- package/dist/commands/package/install.js +14 -15
- package/dist/commands/package/language.d.ts +15 -0
- package/dist/commands/package/language.js +109 -0
- package/dist/commands/package/package.js +20 -10
- package/dist/commands/package/result.d.ts +19 -0
- package/dist/commands/package/theme.d.ts +13 -0
- package/dist/commands/package/theme.js +67 -0
- package/dist/commands/package/uninstall.d.ts +4 -1
- package/dist/commands/package/uninstall.js +29 -9
- package/dist/commands/scene/close.d.ts +1 -1
- package/dist/commands/scene/close.js +15 -8
- package/dist/commands/scene/scene.js +6 -1
- package/dist/commands/shared/books/adventures.d.ts +1 -4
- package/dist/commands/shared/books/adventures.js +3 -32
- package/dist/commands/shared/books/words.js +3 -2
- package/dist/commands/shared/campaign/book.d.ts +21 -8
- package/dist/commands/shared/campaign/book.js +65 -42
- package/dist/commands/shared/campaign/git.d.ts +25 -0
- package/dist/commands/shared/campaign/git.js +104 -0
- package/dist/commands/shared/campaign/saves.js +7 -3
- package/dist/commands/shared/campaign/world.js +2 -1
- package/dist/commands/shared/packages/catalog.d.ts +3 -3
- package/dist/commands/shared/packages/catalog.js +118 -43
- package/dist/commands/shared/packages/unpacked.d.ts +50 -0
- package/dist/commands/shared/packages/unpacked.js +146 -0
- package/dist/commands/status.d.ts +1 -0
- package/dist/commands/status.js +8 -4
- package/dist/core/archive.d.ts +13 -0
- package/dist/core/archive.js +76 -0
- package/dist/core/context.d.ts +4 -0
- package/dist/core/context.js +1 -0
- package/dist/core/store.d.ts +5 -1
- package/dist/core/store.js +15 -2
- package/dist/core/version.d.ts +2 -0
- package/dist/core/version.js +5 -0
- package/dist/dashboard/api.js +24 -1
- package/dist/dashboard/app.js +7 -2
- package/dist/dashboard/guide/ar.md +11 -9
- package/dist/dashboard/guide/cs.md +11 -9
- package/dist/dashboard/guide/da.md +12 -10
- package/dist/dashboard/guide/de.md +13 -11
- package/dist/dashboard/guide/el.md +11 -9
- package/dist/dashboard/guide/en.md +10 -8
- package/dist/dashboard/guide/es.md +11 -9
- package/dist/dashboard/guide/fi.md +11 -9
- package/dist/dashboard/guide/fr.md +11 -9
- package/dist/dashboard/guide/he.md +11 -9
- package/dist/dashboard/guide/hi.md +11 -9
- package/dist/dashboard/guide/hu.md +11 -9
- package/dist/dashboard/guide/is.md +11 -9
- package/dist/dashboard/guide/it.md +11 -9
- package/dist/dashboard/guide/ja.md +12 -10
- package/dist/dashboard/guide/ko.md +11 -9
- package/dist/dashboard/guide/nb.md +12 -10
- package/dist/dashboard/guide/nl.md +11 -9
- package/dist/dashboard/guide/pl.md +11 -9
- package/dist/dashboard/guide/pt.md +11 -9
- package/dist/dashboard/guide/ro.md +11 -9
- package/dist/dashboard/guide/ru.md +12 -10
- package/dist/dashboard/guide/sv.md +11 -9
- package/dist/dashboard/guide/tr.md +11 -9
- package/dist/dashboard/guide/uk.md +12 -10
- package/dist/dashboard/guide/zh.md +11 -9
- package/dist/dashboard/i18n/ar.json +58 -5
- package/dist/dashboard/i18n/cs.json +58 -5
- package/dist/dashboard/i18n/da.json +58 -5
- package/dist/dashboard/i18n/de.json +58 -5
- package/dist/dashboard/i18n/el.json +58 -5
- package/dist/dashboard/i18n/es.json +58 -5
- package/dist/dashboard/i18n/fi.json +58 -5
- package/dist/dashboard/i18n/fr.json +58 -5
- package/dist/dashboard/i18n/he.json +58 -5
- package/dist/dashboard/i18n/hi.json +58 -5
- package/dist/dashboard/i18n/hu.json +58 -5
- package/dist/dashboard/i18n/is.json +58 -5
- package/dist/dashboard/i18n/it.json +58 -5
- package/dist/dashboard/i18n/ja.json +58 -5
- package/dist/dashboard/i18n/ko.json +58 -5
- package/dist/dashboard/i18n/nb.json +58 -5
- package/dist/dashboard/i18n/nl.json +58 -5
- package/dist/dashboard/i18n/pl.json +58 -5
- package/dist/dashboard/i18n/pt.json +58 -5
- package/dist/dashboard/i18n/ro.json +58 -5
- package/dist/dashboard/i18n/ru.json +58 -5
- package/dist/dashboard/i18n/sv.json +58 -5
- package/dist/dashboard/i18n/tr.json +58 -5
- package/dist/dashboard/i18n/uk.json +58 -5
- package/dist/dashboard/i18n/zh.json +58 -5
- package/dist/dashboard/journal/book.js +3 -2
- package/dist/dashboard/journal/journal.js +8 -5
- package/dist/dashboard/kit.js +1 -1
- package/dist/dashboard/packages/catalog.js +31 -14
- package/dist/dashboard/packages/engine.js +46 -2
- package/dist/dashboard/packages/installed.js +13 -0
- package/dist/dashboard/packages/outcomes.js +21 -0
- package/dist/dashboard/packages/packages.js +41 -18
- package/dist/dashboard/packages/rows.js +3 -1
- package/dist/dashboard/parts/icons.js +3 -0
- package/dist/dashboard/parts/labels.js +7 -0
- package/dist/dashboard/parts/picture.js +89 -0
- package/dist/dashboard/parts/refusals.js +8 -1
- package/dist/dashboard/parts/widgets.js +2 -1
- package/dist/dashboard/play/scene.js +8 -5
- package/dist/dashboard/settings/settings.js +55 -18
- package/dist/dashboard/sheet/party.js +5 -2
- package/dist/dashboard/sheet/sheet.js +2 -1
- package/dist/dashboard/shell/notices.js +2 -2
- package/dist/dashboard/shell/system-style.js +132 -15
- package/dist/dashboard/shell/tooltip.js +224 -0
- package/dist/dashboard/style.css +497 -193
- package/dist/dashboard/world/lore.js +4 -3
- package/dist/dashboard/world/place-card.js +2 -1
- package/dist/git/git.d.ts +12 -0
- package/dist/git/git.js +175 -0
- package/dist/git/ignore.d.ts +2 -0
- package/dist/git/ignore.js +16 -0
- package/dist/git/index.d.ts +2 -0
- package/dist/git/index.js +2 -0
- package/dist/importer/index.d.ts +1 -1
- package/dist/importer/index.js +1 -1
- package/dist/languages/index.d.ts +1 -1
- package/dist/languages/index.js +1 -1
- package/dist/languages/pack.d.ts +4 -1
- package/dist/languages/pack.js +18 -6
- package/dist/packages/engine.d.ts +7 -0
- package/dist/packages/engine.js +32 -1
- package/dist/packages/index.d.ts +1 -1
- package/dist/packages/index.js +1 -1
- package/dist/server/bell-listener.d.ts +2 -1
- package/dist/server/bell-listener.js +10 -41
- package/dist/server/dashboard/engine.d.ts +18 -0
- package/dist/server/dashboard/engine.js +31 -0
- package/dist/server/dashboard/files.d.ts +11 -3
- package/dist/server/dashboard/files.js +66 -17
- package/dist/server/dashboard/index.d.ts +18 -2
- package/dist/server/dashboard/index.js +62 -23
- package/dist/server/dashboard/news.d.ts +3 -2
- package/dist/server/dashboard/news.js +19 -5
- package/dist/server/dashboard/pictures.d.ts +7 -0
- package/dist/server/dashboard/pictures.js +62 -0
- package/dist/server/dashboard/ports.d.ts +17 -2
- package/dist/server/dashboard/ports.js +60 -4
- package/dist/server/dashboard/writes.d.ts +5 -3
- package/dist/server/dashboard/writes.js +45 -14
- package/dist/server/mcp.d.ts +3 -2
- package/dist/server/mcp.js +55 -11
- package/dist/testing/index.js +1 -0
- package/dist/themes/css.d.ts +1 -1
- package/dist/themes/css.js +101 -2
- package/dist/themes/index.d.ts +2 -1
- package/dist/themes/index.js +4 -2
- package/dist/themes/installed.d.ts +14 -0
- package/dist/themes/installed.js +28 -0
- package/dist/themes/theme.d.ts +38 -0
- package/dist/themes/theme.js +192 -13
- package/instructions/core.md +4 -3
- package/instructions/dashboard-guide.md +2 -1
- package/instructions/mentor-hints.md +1 -1
- package/instructions/mentor-tutorial.md +1 -1
- package/instructions/party.md +1 -1
- package/instructions/play.md +2 -2
- package/package.json +1 -1
- package/systems/free/instructions/outcomes-told.md +1 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Packages of data alone: an adventure, a theme or a language, from an https link, a .zip or a folder of this computer, read once into its files and told by
|
|
2
|
+
// the file at its top. No npm and no code, so no player's yes; packages with code come from npm.
|
|
3
|
+
import { basename, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { parse } from "yaml";
|
|
5
|
+
import { largestAdventure, manifestFileName, readAdventureEntries } from "../../adventures/index.js";
|
|
6
|
+
import { packageEntries, topFile, unzipFiles, zipListing } from "../../core/archive.js";
|
|
7
|
+
import { filesIn } from "../../core/files.js";
|
|
8
|
+
import { Refusal } from "../../core/refusal.js";
|
|
9
|
+
import { files } from "../../core/store.js";
|
|
10
|
+
import { getVersion, newerEngineAsked } from "../../core/version.js";
|
|
11
|
+
import { languageFileName } from "../../languages/index.js";
|
|
12
|
+
import { themeFileName } from "../../themes/index.js";
|
|
13
|
+
import { installAdventure } from "../shared/books/adventures.js";
|
|
14
|
+
import { largestDataZip } from "../shared/packages/unpacked.js";
|
|
15
|
+
import { dataLanguageInstalled } from "./language.js";
|
|
16
|
+
import { themeInstalled } from "./theme.js";
|
|
17
|
+
// The file at the top of each kind, the first found telling what it is.
|
|
18
|
+
const topFiles = { adventure: manifestFileName, theme: themeFileName, language: languageFileName };
|
|
19
|
+
// The documents a master imports, never a package: their pages are written by the master (D-483 (10)).
|
|
20
|
+
const documentPattern = /\.(pdf|docx?|odt|rtf|txt|md|epub)$/i;
|
|
21
|
+
/**
|
|
22
|
+
* Whether what was given to package install is a package of data alone: a .zip, an https link, or a folder with adventure.yaml, theme.yaml, or language.yaml
|
|
23
|
+
* and no package.json for RPG Engine, which npm installs; a document says it is imported instead.
|
|
24
|
+
*/
|
|
25
|
+
export function isDataSpec(spec) {
|
|
26
|
+
if (documentPattern.test(spec)) {
|
|
27
|
+
throw new Refusal(`${spec} is a document, not a package: make an adventure from it with import; package install takes only what has adventure.yaml, theme.yaml or language.yaml. Nothing changed.`, "document", { name: spec });
|
|
28
|
+
}
|
|
29
|
+
if (/\.zip$/i.test(spec) || /^https:\/\//i.test(spec)) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
const folder = resolve(spec);
|
|
33
|
+
const has = (name) => files().exists(join(folder, name));
|
|
34
|
+
return has(manifestFileName) || has(themeFileName) || (has(languageFileName) && !isNpmPackage(folder));
|
|
35
|
+
}
|
|
36
|
+
/** The package of data a .zip, a folder or an https link gives: a GitHub repository is read as the zip of its default branch, or of the branch or tag its link names. */
|
|
37
|
+
export async function readDataSpec(spec, context) {
|
|
38
|
+
if (/^https:\/\//i.test(spec)) {
|
|
39
|
+
if (context.download === undefined) {
|
|
40
|
+
throw new Error("Only the game's server and the command line download a package: give a .zip or a folder of this computer.");
|
|
41
|
+
}
|
|
42
|
+
const repository = gitHubRepository(spec);
|
|
43
|
+
// Its kind is known only once it is read: the most an adventure may weigh, and a theme's or a language's .zip refused before it is unpacked.
|
|
44
|
+
const bytes = await context.download(repository?.zip ?? spec, largestAdventure, context.signal);
|
|
45
|
+
return zipDataPackage(bytes, spec, repository?.link ?? spec);
|
|
46
|
+
}
|
|
47
|
+
const path = resolve(spec);
|
|
48
|
+
if (/\.zip$/i.test(spec)) {
|
|
49
|
+
const bytes = files().bytes(path);
|
|
50
|
+
if (bytes === undefined) {
|
|
51
|
+
throw new Refusal(`There is no file ${path}: give the path of the package's .zip. Nothing changed.`, "not-on-computer", { name: path });
|
|
52
|
+
}
|
|
53
|
+
return zipDataPackage(bytes, basename(path), path);
|
|
54
|
+
}
|
|
55
|
+
const found = filesIn(path, () => true).map((one) => [relative(path, one).split(sep).join("/"), files().bytes(one) ?? new Uint8Array()]);
|
|
56
|
+
return { ...dataPackageOf(path, found), source: path };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A GitHub repository's link, as the catalog gives it, and the address of its zip: of its default branch, or of the branch or tag after /tree/, each part of
|
|
60
|
+
* the name written as an address writes it. Undefined for a link that is not a repository's.
|
|
61
|
+
*/
|
|
62
|
+
export function gitHubRepository(link) {
|
|
63
|
+
const found = /^https:\/\/github\.com\/([^/#?]+)\/([^/#?]+?)(?:\.git)?(?:\/tree\/([^#?]+?))?\/?(?:[#?].*)?$/i.exec(link.trim());
|
|
64
|
+
if (found === null) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
const part = (text) => encodeURIComponent(plainPart(text));
|
|
68
|
+
const reference = found[3] === undefined ? "HEAD" : found[3].split("/").map(part).join("/");
|
|
69
|
+
return { link: `https://github.com/${found[1]}/${found[2]}`, zip: `https://codeload.github.com/${part(found[1])}/${part(found[2])}/zip/${reference}` };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The package of data a .zip holds, at its top or inside one folder there, as GitHub zips a repository; it throws, saying why, when it is refused. Its names are
|
|
73
|
+
* read first: a theme's or a language's .zip that unpacks to more than they may is refused before any file is unpacked.
|
|
74
|
+
*/
|
|
75
|
+
export function zipDataPackage(bytes, label, source) {
|
|
76
|
+
const listed = zipListing(bytes, label);
|
|
77
|
+
const { kind } = dataPackageOf(label, listed.map(([name]) => [name, new Uint8Array()]));
|
|
78
|
+
const unpacks = listed.reduce((total, [, size]) => total + size, 0);
|
|
79
|
+
if (kind !== "adventure" && Math.max(unpacks, bytes.length) > largestDataZip) {
|
|
80
|
+
const why = `its .zip unpacks to ${Math.ceil(Math.max(unpacks, bytes.length) / 1024 / 1024)} MB, more than the ${largestDataZip / 1024 / 1024} MB a ${kind} may`;
|
|
81
|
+
throw new Refusal(`${label} cannot be used: ${why}. Nothing changed.`, `${kind}-refused`, { name: label, why });
|
|
82
|
+
}
|
|
83
|
+
return { ...dataPackageOf(label, unzipFiles(bytes, label, kind === "adventure" ? largestAdventure : largestDataZip, kind === "adventure" ? "an adventure" : `a ${kind}`)), source };
|
|
84
|
+
}
|
|
85
|
+
/** Installs a package of data alone, as the file at its top says it is: an adventure in the campaign, a theme or a language for every campaign on this computer. */
|
|
86
|
+
export async function installDataPackage(root, context, data, from) {
|
|
87
|
+
if (data.kind === "adventure") {
|
|
88
|
+
return { kind: "adventure-installed", ...installAdventure(root, context, readAdventureEntries(data.label, data.entries), from) };
|
|
89
|
+
}
|
|
90
|
+
checkEngine(data);
|
|
91
|
+
return data.kind === "theme" ? themeInstalled(root, context, data) : await dataLanguageInstalled(root, context, data);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Refuses a theme or a language whose file at its top asks a newer rpg-engine than this one, read loosely before any check, so that one with keys this engine
|
|
95
|
+
* does not know yet says what it needs, as an npm package made for a newer API does.
|
|
96
|
+
*/
|
|
97
|
+
function checkEngine(data) {
|
|
98
|
+
const read = looseTopFile(data);
|
|
99
|
+
const engine = newerEngineAsked(read?.engine);
|
|
100
|
+
if (engine === undefined) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const name = typeof read?.name === "string" && read.name.trim() !== "" ? read.name : data.label;
|
|
104
|
+
const version = typeof read?.version === "string" || typeof read?.version === "number" ? String(read.version) : "";
|
|
105
|
+
throw new Refusal(`${[name, version].filter((part) => part !== "").join(" ")} needs rpg-engine ${engine} or newer; this is ${getVersion()}. The player updates RPG Engine on the dashboard's Packages page, never you; then add it again. Nothing changed.`, "engine-too-old", { name, version });
|
|
106
|
+
}
|
|
107
|
+
/** The file at a package's top, read as YAML without any check; undefined when it does not read, which the checks of its kind then say. */
|
|
108
|
+
function looseTopFile(data) {
|
|
109
|
+
const bytes = topFile(data.entries, topFiles[data.kind])?.[1];
|
|
110
|
+
try {
|
|
111
|
+
return bytes === undefined ? undefined : parse(new TextDecoder().decode(bytes)) ?? undefined;
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** A part of an address as written, its %20 and such read back: a link copied from a browser or typed by hand gives the same. */
|
|
118
|
+
function plainPart(text) {
|
|
119
|
+
try {
|
|
120
|
+
return decodeURIComponent(text);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return text;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** A package's files, their paths checked, told by the file at their top; refused when none of the three is there. */
|
|
127
|
+
function dataPackageOf(label, found) {
|
|
128
|
+
const entries = packageEntries(label, found, "the package", Object.values(topFiles));
|
|
129
|
+
const kind = Object.keys(topFiles).find((one) => topFile(entries, topFiles[one]) !== undefined);
|
|
130
|
+
if (kind === undefined) {
|
|
131
|
+
throw new Refusal(`${label} has no ${Object.values(topFiles).join(", ")} at its top: it is no adventure, theme or language. A document or a folder of notes is imported by the master, `
|
|
132
|
+
+ "who writes its pages. Nothing changed.", "not-package", { name: label });
|
|
133
|
+
}
|
|
134
|
+
return { kind, label, entries };
|
|
135
|
+
}
|
|
136
|
+
/** Whether a folder is a package for npm: its package.json says what it is for RPG Engine. */
|
|
137
|
+
function isNpmPackage(folder) {
|
|
138
|
+
try {
|
|
139
|
+
return Object.hasOwn(JSON.parse(files().text(join(folder, "package.json")) ?? "{}"), "rpg-engine");
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -20,14 +20,19 @@ export interface InstalledLanguage {
|
|
|
20
20
|
package: string;
|
|
21
21
|
version: string;
|
|
22
22
|
verified: boolean;
|
|
23
|
+
/** A package of data alone, which the engine unpacked from a link, a .zip or a folder, never npm. */
|
|
24
|
+
unpacked?: true;
|
|
23
25
|
/** Where its problems are reported, as its package.json says. */
|
|
24
26
|
issues?: string;
|
|
25
27
|
}
|
|
26
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Whether a package is on this computer, by its name as package takes it: an extension, a game system or a language npm installed (D-510); a theme or a
|
|
30
|
+
* language of data alone, theme:<id> and language:<code> too.
|
|
31
|
+
*/
|
|
27
32
|
export declare function isInstalledPackage(context: Context, name: string): boolean;
|
|
28
33
|
/** The game systems on this computer, those shipped with the engine first, with the package each came in when npm installed it (D-485). */
|
|
29
34
|
export declare function systemsHere(root: string, context: Context): InstalledSystem[];
|
|
30
|
-
/** The language packages on this computer, one for each language (D-485 (3)). */
|
|
35
|
+
/** The language packages on this computer, one for each language (D-485 (3)): npm's, and those of data alone, never verified. */
|
|
31
36
|
export declare function languagesHere(context: Context): InstalledLanguage[];
|
|
32
37
|
/** Whether a game system by this name is on this computer; one whose system.yaml does not read is there too, and validate says why. */
|
|
33
38
|
export declare function isSystemHere(context: Context, name: string): boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// What is on this computer: the game systems, languages and extensions npm installed, and where each takes reports of
|
|
1
|
+
// What is on this computer: the game systems, languages and extensions npm installed, the languages and themes of data alone, and where each takes reports of
|
|
2
|
+
// its problems
|
|
2
3
|
import { join } from "node:path";
|
|
3
4
|
import { readTextSetting } from "../../campaign/index.js";
|
|
4
5
|
import { engineSystemsFolder } from "../../core/context.js";
|
|
@@ -9,8 +10,15 @@ import { findExtension, installedExtensions, readExtension, shortName } from "..
|
|
|
9
10
|
import { installedLanguages } from "../../languages/index.js";
|
|
10
11
|
import { isPackageName, issuesPage, isVerified, verifiedScope } from "../../packages/index.js";
|
|
11
12
|
import { findSystem, readableSystems, systemFolders, systemHasCode, systemInFolder, systemWords } from "../../systems/index.js";
|
|
12
|
-
|
|
13
|
+
import { findUnpacked, isDataLanguage, languageFolders } from "../shared/packages/unpacked.js";
|
|
14
|
+
/**
|
|
15
|
+
* Whether a package is on this computer, by its name as package takes it: an extension, a game system or a language npm installed (D-510); a theme or a
|
|
16
|
+
* language of data alone, theme:<id> and language:<code> too.
|
|
17
|
+
*/
|
|
13
18
|
export function isInstalledPackage(context, name) {
|
|
19
|
+
if (findUnpacked(context, name) !== undefined) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
14
22
|
const asked = name.startsWith("npm:") ? name.slice(4) : name.startsWith("@") ? name : `${verifiedScope}${name}`;
|
|
15
23
|
// An npm name only, never a path that climbs to npm's own folder (D-510).
|
|
16
24
|
return [asked, name].some((one) => isPackageName(one) && installedExtensionFolder(context, one) !== undefined);
|
|
@@ -38,16 +46,20 @@ export function systemsHere(root, context) {
|
|
|
38
46
|
};
|
|
39
47
|
});
|
|
40
48
|
}
|
|
41
|
-
/** The language packages on this computer, one for each language (D-485 (3)). */
|
|
49
|
+
/** The language packages on this computer, one for each language (D-485 (3)): npm's, and those of data alone, never verified. */
|
|
42
50
|
export function languagesHere(context) {
|
|
43
|
-
return installedLanguages(context
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
return installedLanguages(languageFolders(context)).map((pack) => {
|
|
52
|
+
const unpacked = isDataLanguage(context, pack);
|
|
53
|
+
return {
|
|
54
|
+
code: pack.code,
|
|
55
|
+
name: pack.name,
|
|
56
|
+
package: pack.package,
|
|
57
|
+
version: pack.version,
|
|
58
|
+
verified: !unpacked && isVerified(pack.package, installedFromFolder(pack.folder)),
|
|
59
|
+
...(unpacked ? { unpacked: true } : {}),
|
|
60
|
+
...issuesOf(pack.folder),
|
|
61
|
+
};
|
|
62
|
+
});
|
|
51
63
|
}
|
|
52
64
|
/** Whether a game system by this name is on this computer; one whose system.yaml does not read is there too, and validate says why. */
|
|
53
65
|
export function isSystemHere(context, name) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// Installs a package, an extension, a game system or a language, and checks what npm put there; and the system a campaign plays when this computer lacks it
|
|
2
|
-
import { join } from "node:path";
|
|
3
2
|
import { changeExtensions, findCampaign, readTextSetting } from "../../campaign/index.js";
|
|
4
3
|
import { neutralExamples } from "../../core/examples.js";
|
|
5
4
|
import { appendLogEntry } from "../../core/log.js";
|
|
@@ -15,9 +14,11 @@ import { campaignWorld } from "../shared/campaign/world.js";
|
|
|
15
14
|
import { campaignExamples } from "../shared/examples.js";
|
|
16
15
|
import { loadCampaignCode, loadNewSystemCode, packageCommandNames, packagesInstalled } from "../shared/packages/code.js";
|
|
17
16
|
import { listedExtensions, runsCode } from "../shared/packages/extensions.js";
|
|
17
|
+
import { languageFolders } from "../shared/packages/unpacked.js";
|
|
18
18
|
import { newDatedLogEntry } from "../shared/time/time.js";
|
|
19
19
|
import { playerYes } from "./consent.js";
|
|
20
20
|
import { installedAs, installedExtensionFolder, isSystemHere, languagesHere, systemsHere, unreadSystemWhy, usable } from "./here.js";
|
|
21
|
+
import { pagePhrases, takeOffLanguage } from "./language.js";
|
|
21
22
|
/**
|
|
22
23
|
* Installs the game system the campaign in this context's folder plays, when it is one of ours that is not on this computer, as package install does, from
|
|
23
24
|
* npm's cache when the registry does not answer, then loads its code (SYS-10, D-514 (3)); once for each system, as `tried` keeps them. The line that says
|
|
@@ -45,7 +46,7 @@ export async function installCampaignSystem(context, tried) {
|
|
|
45
46
|
catch (error) {
|
|
46
47
|
// npm's why, without what package install adds for the master, and without its period: the master tells the player, and the player chooses (D-514 (3)).
|
|
47
48
|
const why = (error instanceof Error ? error.message : String(error)).replace(/^\S+ could not be installed: /, "").replace(/\s*Nothing changed[^.]*\.$/, "").replace(/\.$/, "");
|
|
48
|
-
return `The campaign's game system, ${ours.name}, is not on this computer, and could not be installed: ${why}. Tell the player off-game, in
|
|
49
|
+
return `The campaign's game system, ${ours.name}, is not on this computer, and could not be installed: ${why}. Tell the player off-game, in [OOC: …] and in a table's words, `
|
|
49
50
|
+ `that this computer lacks the ${ours.name} rules and could not download them: once it is online, you install them with package install ${ours.name}, no yes needed. `
|
|
50
51
|
+ "Until then you play without its pages and the sheet's worked-out numbers, or wait, as the player chooses.";
|
|
51
52
|
}
|
|
@@ -242,7 +243,7 @@ async function languageInstalled(root, context, spec, described) {
|
|
|
242
243
|
name: described.name,
|
|
243
244
|
});
|
|
244
245
|
}
|
|
245
|
-
const before = installedLanguages(context
|
|
246
|
+
const before = installedLanguages(languageFolders(context));
|
|
246
247
|
const packages = context.packages;
|
|
247
248
|
const why = await packages.install(spec);
|
|
248
249
|
if (why !== undefined) {
|
|
@@ -270,11 +271,18 @@ async function languageInstalled(root, context, spec, described) {
|
|
|
270
271
|
const message = `${described.name} cannot be used: ${why}. ${back === undefined ? "It was taken off this computer." : `Version ${back} stays.`}`;
|
|
271
272
|
throw back === undefined ? new Refusal(message, "language-refused", { name: described.name, why }) : new Refusal(message, "language-kept", { name: described.name, why, version: back });
|
|
272
273
|
}
|
|
273
|
-
// One language, one package: the one before for the same code goes (D-485 (3)).
|
|
274
|
+
// One language, one package: the one before for the same code goes (D-485 (3)), one of data alone too.
|
|
274
275
|
const replaced = before.find((one) => one.code.toLowerCase() === pack.code.toLowerCase() && one.package !== described.name);
|
|
275
276
|
if (replaced !== undefined) {
|
|
276
|
-
|
|
277
|
-
|
|
277
|
+
try {
|
|
278
|
+
await takeOffLanguage(context, replaced);
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
// The one before stays when npm cannot take it off: the new one goes, so that nothing changed.
|
|
282
|
+
await packages.uninstall(described.name);
|
|
283
|
+
(context.extensionFolders ?? []).forEach((one) => files().refresh(one));
|
|
284
|
+
throw error;
|
|
285
|
+
}
|
|
278
286
|
}
|
|
279
287
|
const language = languagesHere(context).find((one) => one.package === described.name);
|
|
280
288
|
appendLogEntry(root, newDatedLogEntry(root, context, "package-installed", "public", { package: described.name, version: described.version, verified: language.verified, kind: "language" }));
|
|
@@ -298,15 +306,6 @@ function namesNote(root, context, system) {
|
|
|
298
306
|
const names = [counter === undefined ? undefined : `${counter} for damage`, own("rest"), coins === "" ? undefined : coins].filter((name) => name !== undefined);
|
|
299
307
|
return names.length === 0 ? "" : ` The commands' descriptions may keep neutral examples until a new chat: in ${system} use its own names, such as ${names.join(", ")}.`;
|
|
300
308
|
}
|
|
301
|
-
/** The dashboard's phrases, by their English, as its curated Italian lists them all; none where the built page is not here. */
|
|
302
|
-
function pagePhrases(context) {
|
|
303
|
-
try {
|
|
304
|
-
return JSON.parse(files().text(join(context.pageFolder ?? "", "i18n", "it.json")) ?? "{}");
|
|
305
|
-
}
|
|
306
|
-
catch {
|
|
307
|
-
return {};
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
309
|
/** A package made for an API this engine does not read: one newer than the engine, which an update of the engine reads, or one older, which a newer version of it fixes. */
|
|
311
310
|
function apiRefusal(described, unread) {
|
|
312
311
|
const newer = described.api !== undefined && described.api > packageApi;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Context } from "../../core/context.ts";
|
|
2
|
+
import { type LanguagePack } from "../../languages/index.ts";
|
|
3
|
+
import type { DataPackage } from "./data.ts";
|
|
4
|
+
import type { PackageResult } from "./result.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Installs a language of data alone for every campaign on this computer, in the folder of its code: texts the dashboard shows, never code, so no yes is asked;
|
|
7
|
+
* refused whole when its phrases lose a {name} or turn the order of a text. It takes the place of another package of the same language, from npm too.
|
|
8
|
+
*/
|
|
9
|
+
export declare function dataLanguageInstalled(root: string, context: Context, data: DataPackage): Promise<PackageResult>;
|
|
10
|
+
/** Takes a language of data alone off this computer. */
|
|
11
|
+
export declare function dataLanguageUninstalled(root: string, context: Context, found: LanguagePack): PackageResult;
|
|
12
|
+
/** Takes a language package off this computer, as it came: one of data alone by its folder, one of npm's with npm, refused when npm cannot. */
|
|
13
|
+
export declare function takeOffLanguage(context: Context, pack: LanguagePack): Promise<void>;
|
|
14
|
+
/** The dashboard's phrases, by their English, as its curated Italian lists them all; none where the built page is not here. */
|
|
15
|
+
export declare function pagePhrases(context: Context): Record<string, string>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// A language as a package of data alone: unpacked for every campaign on this computer, checked as a language from npm is, one package for each language;
|
|
2
|
+
// and what both kinds share, the page's phrases to check against and taking one off.
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { appendLogEntry } from "../../core/log.js";
|
|
5
|
+
import { Refusal } from "../../core/refusal.js";
|
|
6
|
+
import { files } from "../../core/store.js";
|
|
7
|
+
import { installedLanguages, languageFileName, languagePackProblems, readLanguagePack } from "../../languages/index.js";
|
|
8
|
+
import { dataLanguagesFolder, isDataLanguage, keptFiles, languageFolders, placeTrial, writeTrial } from "../shared/packages/unpacked.js";
|
|
9
|
+
import { newDatedLogEntry } from "../shared/time/time.js";
|
|
10
|
+
import { languagesHere } from "./here.js";
|
|
11
|
+
// The files at a language's top it uses, as their readers name them; and its licence.
|
|
12
|
+
const topFiles = [languageFileName, "phrases.json", "guide.md"];
|
|
13
|
+
const licence = /^(licen[cs]e|copying)(\.(md|txt))?$/i;
|
|
14
|
+
/**
|
|
15
|
+
* Installs a language of data alone for every campaign on this computer, in the folder of its code: texts the dashboard shows, never code, so no yes is asked;
|
|
16
|
+
* refused whole when its phrases lose a {name} or turn the order of a text. It takes the place of another package of the same language, from npm too.
|
|
17
|
+
*/
|
|
18
|
+
export async function dataLanguageInstalled(root, context, data) {
|
|
19
|
+
const folder = dataLanguagesFolder(context);
|
|
20
|
+
if (folder === undefined) {
|
|
21
|
+
throw new Error("Languages are installed only by the game's server or the command line, which keep them for every campaign on this computer.");
|
|
22
|
+
}
|
|
23
|
+
const kept = keptFiles(data.label, data.entries, isLanguageFile, "language-refused", "a language").map(([parts, bytes]) => [writtenPath(parts), bytes]);
|
|
24
|
+
// Checked where it is written, in a folder of its own that no list reads, then put where its code puts it.
|
|
25
|
+
const trial = writeTrial(folder, context, kept, data.source);
|
|
26
|
+
try {
|
|
27
|
+
const checked = checkedPack(context, trial);
|
|
28
|
+
const why = checked.problems.map((problem) => problem.replaceAll(trial, data.label)).join("; ");
|
|
29
|
+
if (checked.pack === undefined || why !== "") {
|
|
30
|
+
throw new Refusal(`${data.label} cannot be used: ${why}. Nothing changed.`, "language-refused", { name: data.label, why });
|
|
31
|
+
}
|
|
32
|
+
const code = checked.pack.code;
|
|
33
|
+
const target = join(folder, code);
|
|
34
|
+
// One language, one package: those before for the same code go, npm's first, as npm may fail to take one off; then the new one takes its place.
|
|
35
|
+
const others = installedLanguages(languageFolders(context)).filter((one) => one.code.toLowerCase() === code.toLowerCase());
|
|
36
|
+
for (const other of others.filter((one) => !isDataLanguage(context, one))) {
|
|
37
|
+
await takeOffLanguage(context, other);
|
|
38
|
+
}
|
|
39
|
+
placeTrial(trial, target, context);
|
|
40
|
+
others.filter((one) => isDataLanguage(context, one) && files().modified(one.folder) !== undefined && !isSameFolder(one.folder, target)).forEach((one) => files().removeFolder(one.folder));
|
|
41
|
+
const language = languagesHere(context).find((one) => one.unpacked === true && one.code.toLowerCase() === code.toLowerCase());
|
|
42
|
+
if (language === undefined) {
|
|
43
|
+
throw new Error(`${data.label} was unpacked in ${target}, and does not read there: install it again.`);
|
|
44
|
+
}
|
|
45
|
+
const replaced = others.find((one) => one.package !== language.package);
|
|
46
|
+
appendLogEntry(root, newDatedLogEntry(root, context, "package-installed", "public", { package: language.package, version: language.version, verified: false, kind: "language" }));
|
|
47
|
+
return { kind: "language-installed", language, ...(replaced === undefined ? {} : { replaced: replaced.package }), missing: checked.missing };
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
files().removeFolder(trial);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** Takes a language of data alone off this computer. */
|
|
54
|
+
export function dataLanguageUninstalled(root, context, found) {
|
|
55
|
+
files().removeFolder(found.folder);
|
|
56
|
+
appendLogEntry(root, newDatedLogEntry(root, context, "package-uninstalled", "public", { package: found.package, kind: "language" }));
|
|
57
|
+
return { kind: "uninstalled", name: found.name, wasUsed: false, extension: false };
|
|
58
|
+
}
|
|
59
|
+
/** Takes a language package off this computer, as it came: one of data alone by its folder, one of npm's with npm, refused when npm cannot. */
|
|
60
|
+
export async function takeOffLanguage(context, pack) {
|
|
61
|
+
if (isDataLanguage(context, pack)) {
|
|
62
|
+
files().removeFolder(pack.folder);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (context.packages === undefined) {
|
|
66
|
+
throw new Error(`${pack.package}, the language ${pack.name} from npm, is on this computer, and only the game's server and the command line, which reach npm, take it off.`);
|
|
67
|
+
}
|
|
68
|
+
const why = await context.packages.uninstall(pack.package);
|
|
69
|
+
(context.extensionFolders ?? []).forEach((folder) => files().refresh(folder));
|
|
70
|
+
if (why !== undefined) {
|
|
71
|
+
throw new Refusal(`${pack.package}, the language ${pack.name} on this computer, could not be taken off to make room for the new one: ${why}. Close what may be using its files, `
|
|
72
|
+
+ "such as another game's server or an editor, and install again. Nothing changed.", "uninstall-failed", { name: pack.package, why });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** The dashboard's phrases, by their English, as its curated Italian lists them all; none where the built page is not here. */
|
|
76
|
+
export function pagePhrases(context) {
|
|
77
|
+
try {
|
|
78
|
+
return JSON.parse(files().text(join(context.pageFolder ?? "", "i18n", "it.json")) ?? "{}");
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return {};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** A language package read from its folder and checked against the page's phrases: what keeps it from being used, and the phrases it lacks. */
|
|
85
|
+
function checkedPack(context, folder) {
|
|
86
|
+
try {
|
|
87
|
+
const pack = readLanguagePack(folder);
|
|
88
|
+
return { pack, ...languagePackProblems(pack, Object.keys(pagePhrases(context))) };
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
return { problems: [error instanceof Error ? error.message : String(error)], missing: 0 };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** Whether two paths are the same folder, as the disk of this computer tells names apart. */
|
|
95
|
+
function isSameFolder(first, second) {
|
|
96
|
+
const plain = (path) => (process.platform === "win32" || process.platform === "darwin" ? resolve(path).toLowerCase() : resolve(path));
|
|
97
|
+
return plain(first) === plain(second);
|
|
98
|
+
}
|
|
99
|
+
/** Whether a path of a package is a file a language uses: its language.yaml, phrases, Guide and licence at its top, a game system's words under systems/. */
|
|
100
|
+
function isLanguageFile(parts) {
|
|
101
|
+
if (parts.length === 1) {
|
|
102
|
+
return topFiles.includes(parts[0].toLowerCase()) || licence.test(parts[0]);
|
|
103
|
+
}
|
|
104
|
+
return parts.length === 4 && parts[0].toLowerCase() === "systems" && parts[2].toLowerCase() === "words" && /\.yaml$/i.test(parts[3]);
|
|
105
|
+
}
|
|
106
|
+
/** A language's file where its readers look for it: the names they read written as they read them. */
|
|
107
|
+
function writtenPath(parts) {
|
|
108
|
+
return parts.length === 1 ? [topFiles.find((one) => one === parts[0].toLowerCase()) ?? parts[0]] : ["systems", parts[1], "words", parts[3]];
|
|
109
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The package command: lists, asks npm, installs, removes, uninstalls and exports, and says what it did
|
|
1
|
+
// The package command: lists, asks npm, installs from npm or as data alone, removes, uninstalls and exports, and says what it did
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { requireCampaign } from "../../campaign/index.js";
|
|
4
4
|
import { readsApi } from "../../core/packages/declarations.js";
|
|
@@ -7,14 +7,17 @@ import { comparableText } from "../../core/text.js";
|
|
|
7
7
|
import { isNewerVersion } from "../../core/version.js";
|
|
8
8
|
import { installedExtensions, readExtension, shortName } from "../../extensions/index.js";
|
|
9
9
|
import { isVerified } from "../../packages/index.js";
|
|
10
|
-
import { exportAdventure,
|
|
10
|
+
import { exportAdventure, installedAdventures, removeAdventure, storyTouching } from "../shared/books/adventures.js";
|
|
11
11
|
import { listedExtensions } from "../shared/packages/extensions.js";
|
|
12
|
+
import { installDataPackage, isDataSpec, readDataSpec } from "./data.js";
|
|
12
13
|
import { issuesOf, languagesHere, systemsHere, usable } from "./here.js";
|
|
13
14
|
import { installed } from "./install.js";
|
|
15
|
+
import { themesListed } from "./theme.js";
|
|
14
16
|
import { removed, uninstalled } from "./uninstall.js";
|
|
15
17
|
export const packageCommand = defineCommand({
|
|
16
18
|
name: "package",
|
|
17
|
-
description: "The packages of the campaign: extensions such as weather, from npm, and
|
|
19
|
+
description: "The packages of the campaign: extensions such as weather, from npm; adventures, dashboard themes and languages, as a .zip, a folder or a GitHub link "
|
|
20
|
+
+ "with adventure.yaml, theme.yaml or language.yaml; a theme or a language serves every campaign on this computer. "
|
|
18
21
|
+ "list says those on this computer and those the campaign uses; available, those npm has, and updates; RPG Engine itself is updated by the player on the dashboard's Packages page, never by you. install adds or updates one, on this computer and in the campaign, "
|
|
19
22
|
+ "only once the player wants it; one not published by RPG Engine (@rpgengine/…) is someone else's: the player is asked in the host's form, or in a window of their computer. "
|
|
20
23
|
+ "An adventure is installed when you bring its hook into the story, once the player wants it as the next. "
|
|
@@ -26,7 +29,7 @@ export const packageCommand = defineCommand({
|
|
|
26
29
|
input: z.object({
|
|
27
30
|
action: z.enum(["list", "available", "install", "remove", "uninstall", "export"]).describe("list, available, install, remove, uninstall or export"),
|
|
28
31
|
name: z.string().optional().describe("the package: its name alone for one of ours, such as weather; another's npm name with its scope, or npm:name without one, its version if wanted; a folder or a .tgz "
|
|
29
|
-
+ "file on this computer; an adventure's .zip, folder or https link; an adventure's title to remove it"),
|
|
32
|
+
+ "file on this computer; an adventure's, a theme's or a language's .zip, folder or https link; an adventure's title to remove it; a theme's or a language's name to uninstall it, or theme:<id> and language:<code> when an npm package has that name too"),
|
|
30
33
|
author: z.string().min(1).optional().describe("export: who wrote the adventure, as the player wants it credited"),
|
|
31
34
|
license: z.string().min(1).optional().describe("export: the licence the player gives it, such as CC BY 4.0; without one, all rights are reserved"),
|
|
32
35
|
}),
|
|
@@ -46,7 +49,7 @@ export const packageCommand = defineCommand({
|
|
|
46
49
|
throw new Error(`Give the package to ${input.action}, such as package ${input.action} weather.`);
|
|
47
50
|
}
|
|
48
51
|
if (input.action === "install") {
|
|
49
|
-
return
|
|
52
|
+
return isDataSpec(name) ? await installDataPackage(root, context, await readDataSpec(name, context), name) : await installed(root, context, name);
|
|
50
53
|
}
|
|
51
54
|
const adventure = installedAdventures(root).find((one) => comparableText(one.title) === comparableText(name));
|
|
52
55
|
if (input.action === "remove" && adventure !== undefined) {
|
|
@@ -72,6 +75,11 @@ export const packageCommand = defineCommand({
|
|
|
72
75
|
result.missing === 0 ? "" : `The ${result.missing} phrases it lacks stay as the dashboard has them, its own or translated on the fly.`,
|
|
73
76
|
].filter((line) => line !== "").join(" ");
|
|
74
77
|
}
|
|
78
|
+
if (result.kind === "theme-installed") {
|
|
79
|
+
const { theme, replaced } = result;
|
|
80
|
+
const was = replaced === undefined ? "" : ` It takes the place of ${replaced.name}${replaced.version === undefined ? "" : ` ${replaced.version}`}.`;
|
|
81
|
+
return `Installed the theme ${theme.name}${theme.version === undefined ? "" : ` ${theme.version}`} for every campaign on this computer: the player chooses it in Settings.${was}`;
|
|
82
|
+
}
|
|
75
83
|
if (result.kind === "system-installed") {
|
|
76
84
|
const { system } = result;
|
|
77
85
|
return [
|
|
@@ -121,6 +129,8 @@ export const packageCommand = defineCommand({
|
|
|
121
129
|
`On this computer: ${installedLines.length === 0 ? "none" : installedLines.join("; ")}.`,
|
|
122
130
|
result.missing.length === 0 ? "" : `The campaign lists, not installed here: ${result.missing.join(", ")}; install each with package install.`,
|
|
123
131
|
result.adventures.length === 0 ? "" : `Its adventures: ${result.adventures.map((one) => `${one.title} ${one.version}${one.since === undefined ? "" : `, since ${one.since}`}`).join("; ")}.`,
|
|
132
|
+
result.languages.length === 0 ? "" : `Languages of the dashboard: ${result.languages.map((one) => `${one.name} (${one.code})${one.version === "" ? "" : ` ${one.version}`}`).join("; ")}.`,
|
|
133
|
+
result.themes.length === 0 ? "" : `Themes of the dashboard, which the player chooses in Settings: ${result.themes.map(themeLine).join("; ")}.`,
|
|
124
134
|
"package available says those npm has, and updates.",
|
|
125
135
|
].filter((line) => line !== "").join("\n");
|
|
126
136
|
},
|
|
@@ -204,7 +214,7 @@ function listed(root, context) {
|
|
|
204
214
|
}
|
|
205
215
|
});
|
|
206
216
|
const adventures = installedAdventures(root).map((one) => ({ title: one.title, version: one.version, ...(one.since === undefined ? {} : { since: one.since }), removable: storyTouching(root, one) === undefined }));
|
|
207
|
-
return { kind: "list", installed: here, missing: used.filter((name) => !here.some((one) => one.package === name)), adventures, systems: systemsHere(root, context), languages: languagesHere(context) };
|
|
217
|
+
return { kind: "list", installed: here, missing: used.filter((name) => !here.some((one) => one.package === name)), adventures, systems: systemsHere(root, context), languages: languagesHere(context), themes: themesListed(context) };
|
|
208
218
|
}
|
|
209
219
|
/** The extensions npm has for this rpg-engine's API, ours first, each with the version installed here and whether npm has a newer one (D-442). */
|
|
210
220
|
async function available(context) {
|
|
@@ -236,10 +246,10 @@ async function available(context) {
|
|
|
236
246
|
function codeText(loaded) {
|
|
237
247
|
return loaded === undefined ? "Its code runs from the next start of the game's server." : "runs" in loaded ? "Its code runs from now." : `Its code does not run: ${loaded.why.replace(/\.$/, "")}.`;
|
|
238
248
|
}
|
|
239
|
-
/**
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
return {
|
|
249
|
+
/** A theme as list says it: with its version, and why it is not offered while it fails a check. */
|
|
250
|
+
function themeLine(theme) {
|
|
251
|
+
const version = theme.version === undefined ? "" : ` ${theme.version}`;
|
|
252
|
+
return theme.problems === undefined ? `${theme.name}${version}` : `${theme.name}${version} (not offered: ${theme.problems[0]})`;
|
|
243
253
|
}
|
|
244
254
|
/** What the master hears of an export (ADV-7, ADV-8): the file, what it came from, the layers it carries and what stayed out. */
|
|
245
255
|
function exportText(result) {
|
|
@@ -13,6 +13,7 @@ export type PackageResult = {
|
|
|
13
13
|
}[];
|
|
14
14
|
systems: InstalledSystem[];
|
|
15
15
|
languages: InstalledLanguage[];
|
|
16
|
+
themes: ListedTheme[];
|
|
16
17
|
} | {
|
|
17
18
|
kind: "available";
|
|
18
19
|
packages: Available[];
|
|
@@ -48,6 +49,17 @@ export type PackageResult = {
|
|
|
48
49
|
language: InstalledLanguage;
|
|
49
50
|
replaced?: string;
|
|
50
51
|
missing: number;
|
|
52
|
+
} | {
|
|
53
|
+
kind: "theme-installed";
|
|
54
|
+
theme: {
|
|
55
|
+
id: string;
|
|
56
|
+
name: string;
|
|
57
|
+
version?: string;
|
|
58
|
+
};
|
|
59
|
+
replaced?: {
|
|
60
|
+
name: string;
|
|
61
|
+
version?: string;
|
|
62
|
+
};
|
|
51
63
|
} | ({
|
|
52
64
|
kind: "adventure-installed";
|
|
53
65
|
} & AdventureInstalled) | ({
|
|
@@ -87,3 +99,10 @@ export interface Available {
|
|
|
87
99
|
engine?: string;
|
|
88
100
|
};
|
|
89
101
|
}
|
|
102
|
+
/** A theme of the dashboard on this computer, for every campaign: its id, its name, and why it is not offered while it fails a check. */
|
|
103
|
+
export interface ListedTheme {
|
|
104
|
+
id: string;
|
|
105
|
+
name: string;
|
|
106
|
+
version?: string;
|
|
107
|
+
problems?: string[];
|
|
108
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Context } from "../../core/context.ts";
|
|
2
|
+
import { type InstalledTheme } from "../../themes/index.ts";
|
|
3
|
+
import type { DataPackage } from "./data.ts";
|
|
4
|
+
import type { ListedTheme, PackageResult } from "./result.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Installs a theme for every campaign on this computer, in the folder of its id, taking the place of one with the same; refused whole when it fails a check.
|
|
7
|
+
* It keeps its theme.yaml, the files that names and a licence at its top: nothing else a repository holds.
|
|
8
|
+
*/
|
|
9
|
+
export declare function themeInstalled(root: string, context: Context, data: DataPackage): PackageResult;
|
|
10
|
+
/** Takes an installed theme off this computer. */
|
|
11
|
+
export declare function themeUninstalled(root: string, context: Context, found: InstalledTheme): PackageResult;
|
|
12
|
+
/** The themes on this computer as list gives them: each with its id, and why one is not offered while it fails a check. */
|
|
13
|
+
export declare function themesListed(context: Context): ListedTheme[];
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// A theme of the dashboard as a package of its own: unpacked for every campaign on this computer, checked as a game system's theme is, listed and taken away
|
|
2
|
+
// by its name or its id. Data alone, so no player's yes.
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { topFile } from "../../core/archive.js";
|
|
5
|
+
import { appendLogEntry } from "../../core/log.js";
|
|
6
|
+
import { Refusal } from "../../core/refusal.js";
|
|
7
|
+
import { files } from "../../core/store.js";
|
|
8
|
+
import { readTheme, themeFileName, themeFilesNamed, themeId } from "../../themes/index.js";
|
|
9
|
+
import { keptFiles, placeTrial, themesFolder, themesHere, writeTrial } from "../shared/packages/unpacked.js";
|
|
10
|
+
import { newDatedLogEntry } from "../shared/time/time.js";
|
|
11
|
+
// A licence at a theme's top, beside the files its theme.yaml names.
|
|
12
|
+
const licence = /^(licen[cs]e|copying)(\.(md|txt))?$/i;
|
|
13
|
+
/**
|
|
14
|
+
* Installs a theme for every campaign on this computer, in the folder of its id, taking the place of one with the same; refused whole when it fails a check.
|
|
15
|
+
* It keeps its theme.yaml, the files that names and a licence at its top: nothing else a repository holds.
|
|
16
|
+
*/
|
|
17
|
+
export function themeInstalled(root, context, data) {
|
|
18
|
+
const folder = themesFolder(context);
|
|
19
|
+
if (folder === undefined) {
|
|
20
|
+
throw new Error("Themes are installed only by the game's server or the command line, which keep them for every campaign on this computer.");
|
|
21
|
+
}
|
|
22
|
+
const text = (bytes) => (bytes === undefined ? undefined : new TextDecoder().decode(bytes));
|
|
23
|
+
const named = new Set(themeFilesNamed(text(topFile(data.entries, themeFileName)?.[1]) ?? "", (name) => text(data.entries.find(([parts]) => parts.join("/") === name)?.[1])));
|
|
24
|
+
const keep = (parts) => isThemeYaml(parts) || named.has(parts.join("/")) || (parts.length === 1 && licence.test(parts[0]));
|
|
25
|
+
const kept = keptFiles(data.label, data.entries, keep, "theme-refused", "a theme").map(([parts, bytes]) => [isThemeYaml(parts) ? [themeFileName] : parts, bytes]);
|
|
26
|
+
// Checked where it is written, in a folder of its own that no list reads, then put where its id puts it.
|
|
27
|
+
const trial = writeTrial(folder, context, kept, data.source);
|
|
28
|
+
try {
|
|
29
|
+
const reading = readTheme(trial);
|
|
30
|
+
if (reading.theme === undefined) {
|
|
31
|
+
const why = reading.problems.map((problem) => problem.replaceAll(trial, data.label)).join("; ");
|
|
32
|
+
throw new Refusal(`${data.label} is no theme the dashboard can use: ${why}. Nothing changed.`, "theme-refused", { name: data.label, why });
|
|
33
|
+
}
|
|
34
|
+
const theme = reading.theme;
|
|
35
|
+
const id = themeId(theme.name);
|
|
36
|
+
const before = themesHere(context).find((one) => one.id === id);
|
|
37
|
+
placeTrial(trial, join(folder, id), context);
|
|
38
|
+
appendLogEntry(root, newDatedLogEntry(root, context, "package-installed", "public", { package: id, version: theme.version ?? "", verified: false, kind: "theme" }));
|
|
39
|
+
return {
|
|
40
|
+
kind: "theme-installed",
|
|
41
|
+
theme: { id, name: theme.name, ...(theme.version === undefined ? {} : { version: theme.version }) },
|
|
42
|
+
...(before === undefined ? {} : { replaced: { name: before.theme?.name ?? before.id, ...(before.theme?.version === undefined ? {} : { version: before.theme.version }) } }),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
files().removeFolder(trial);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Takes an installed theme off this computer. */
|
|
50
|
+
export function themeUninstalled(root, context, found) {
|
|
51
|
+
files().removeFolder(found.folder);
|
|
52
|
+
appendLogEntry(root, newDatedLogEntry(root, context, "package-uninstalled", "public", { package: found.id, kind: "theme" }));
|
|
53
|
+
return { kind: "uninstalled", name: found.theme?.name ?? found.id, wasUsed: false, extension: false };
|
|
54
|
+
}
|
|
55
|
+
/** The themes on this computer as list gives them: each with its id, and why one is not offered while it fails a check. */
|
|
56
|
+
export function themesListed(context) {
|
|
57
|
+
return themesHere(context).map((one) => ({
|
|
58
|
+
id: one.id,
|
|
59
|
+
name: one.theme?.name ?? one.id,
|
|
60
|
+
...(one.theme?.version === undefined ? {} : { version: one.theme.version }),
|
|
61
|
+
...(one.problems.length === 0 ? {} : { problems: one.problems }),
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
/** Whether a path of a package is its theme.yaml, at its top, in any case. */
|
|
65
|
+
function isThemeYaml(parts) {
|
|
66
|
+
return parts.length === 1 && parts[0].toLowerCase() === themeFileName;
|
|
67
|
+
}
|