rpg-engine 0.20.0 → 0.21.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.
Files changed (160) hide show
  1. package/dist/adventures/index.d.ts +1 -1
  2. package/dist/adventures/index.js +1 -1
  3. package/dist/adventures/source.d.ts +3 -0
  4. package/dist/adventures/source.js +11 -49
  5. package/dist/campaign/create-campaign.d.ts +1 -1
  6. package/dist/campaign/create-campaign.js +3 -2
  7. package/dist/campaign/find-campaign.d.ts +2 -0
  8. package/dist/campaign/find-campaign.js +2 -0
  9. package/dist/campaign/index.d.ts +1 -1
  10. package/dist/campaign/index.js +1 -1
  11. package/dist/campaign/settings.js +2 -2
  12. package/dist/commands/book.d.ts +16 -35
  13. package/dist/commands/book.js +86 -62
  14. package/dist/commands/config/config.js +1 -1
  15. package/dist/commands/config/dashboard.d.ts +2 -2
  16. package/dist/commands/config/dashboard.js +9 -3
  17. package/dist/commands/config/words.js +1 -1
  18. package/dist/commands/image.d.ts +5 -0
  19. package/dist/commands/image.js +6 -3
  20. package/dist/commands/package/data.d.ts +35 -0
  21. package/dist/commands/package/data.js +117 -0
  22. package/dist/commands/package/here.d.ts +7 -2
  23. package/dist/commands/package/here.js +23 -11
  24. package/dist/commands/package/install.js +14 -15
  25. package/dist/commands/package/language.d.ts +15 -0
  26. package/dist/commands/package/language.js +109 -0
  27. package/dist/commands/package/package.js +20 -10
  28. package/dist/commands/package/result.d.ts +19 -0
  29. package/dist/commands/package/theme.d.ts +13 -0
  30. package/dist/commands/package/theme.js +66 -0
  31. package/dist/commands/package/uninstall.d.ts +4 -1
  32. package/dist/commands/package/uninstall.js +29 -9
  33. package/dist/commands/scene/close.d.ts +1 -1
  34. package/dist/commands/scene/close.js +15 -8
  35. package/dist/commands/shared/books/adventures.d.ts +0 -4
  36. package/dist/commands/shared/books/adventures.js +2 -31
  37. package/dist/commands/shared/books/words.js +3 -2
  38. package/dist/commands/shared/campaign/book.d.ts +21 -8
  39. package/dist/commands/shared/campaign/book.js +65 -42
  40. package/dist/commands/shared/campaign/saves.js +2 -2
  41. package/dist/commands/shared/campaign/world.js +2 -1
  42. package/dist/commands/shared/packages/catalog.d.ts +3 -3
  43. package/dist/commands/shared/packages/catalog.js +98 -42
  44. package/dist/commands/shared/packages/unpacked.d.ts +50 -0
  45. package/dist/commands/shared/packages/unpacked.js +146 -0
  46. package/dist/core/archive.d.ts +13 -0
  47. package/dist/core/archive.js +76 -0
  48. package/dist/core/context.d.ts +2 -0
  49. package/dist/core/context.js +1 -0
  50. package/dist/core/store.d.ts +5 -1
  51. package/dist/core/store.js +15 -2
  52. package/dist/dashboard/api.js +24 -1
  53. package/dist/dashboard/app.js +7 -2
  54. package/dist/dashboard/guide/ar.md +8 -8
  55. package/dist/dashboard/guide/cs.md +8 -8
  56. package/dist/dashboard/guide/da.md +9 -9
  57. package/dist/dashboard/guide/de.md +8 -8
  58. package/dist/dashboard/guide/el.md +8 -8
  59. package/dist/dashboard/guide/en.md +7 -7
  60. package/dist/dashboard/guide/es.md +8 -8
  61. package/dist/dashboard/guide/fi.md +8 -8
  62. package/dist/dashboard/guide/fr.md +8 -8
  63. package/dist/dashboard/guide/he.md +8 -8
  64. package/dist/dashboard/guide/hi.md +8 -8
  65. package/dist/dashboard/guide/hu.md +8 -8
  66. package/dist/dashboard/guide/is.md +8 -8
  67. package/dist/dashboard/guide/it.md +8 -8
  68. package/dist/dashboard/guide/ja.md +8 -8
  69. package/dist/dashboard/guide/ko.md +8 -8
  70. package/dist/dashboard/guide/nb.md +9 -9
  71. package/dist/dashboard/guide/nl.md +8 -8
  72. package/dist/dashboard/guide/pl.md +8 -8
  73. package/dist/dashboard/guide/pt.md +8 -8
  74. package/dist/dashboard/guide/ro.md +8 -8
  75. package/dist/dashboard/guide/ru.md +9 -9
  76. package/dist/dashboard/guide/sv.md +8 -8
  77. package/dist/dashboard/guide/tr.md +8 -8
  78. package/dist/dashboard/guide/uk.md +9 -9
  79. package/dist/dashboard/guide/zh.md +8 -8
  80. package/dist/dashboard/i18n/ar.json +33 -5
  81. package/dist/dashboard/i18n/cs.json +33 -5
  82. package/dist/dashboard/i18n/da.json +33 -5
  83. package/dist/dashboard/i18n/de.json +33 -5
  84. package/dist/dashboard/i18n/el.json +33 -5
  85. package/dist/dashboard/i18n/es.json +33 -5
  86. package/dist/dashboard/i18n/fi.json +33 -5
  87. package/dist/dashboard/i18n/fr.json +33 -5
  88. package/dist/dashboard/i18n/he.json +33 -5
  89. package/dist/dashboard/i18n/hi.json +33 -5
  90. package/dist/dashboard/i18n/hu.json +33 -5
  91. package/dist/dashboard/i18n/is.json +33 -5
  92. package/dist/dashboard/i18n/it.json +33 -5
  93. package/dist/dashboard/i18n/ja.json +33 -5
  94. package/dist/dashboard/i18n/ko.json +33 -5
  95. package/dist/dashboard/i18n/nb.json +33 -5
  96. package/dist/dashboard/i18n/nl.json +33 -5
  97. package/dist/dashboard/i18n/pl.json +33 -5
  98. package/dist/dashboard/i18n/pt.json +33 -5
  99. package/dist/dashboard/i18n/ro.json +33 -5
  100. package/dist/dashboard/i18n/ru.json +33 -5
  101. package/dist/dashboard/i18n/sv.json +33 -5
  102. package/dist/dashboard/i18n/tr.json +33 -5
  103. package/dist/dashboard/i18n/uk.json +33 -5
  104. package/dist/dashboard/i18n/zh.json +33 -5
  105. package/dist/dashboard/journal/book.js +3 -2
  106. package/dist/dashboard/journal/journal.js +8 -5
  107. package/dist/dashboard/kit.js +1 -1
  108. package/dist/dashboard/packages/catalog.js +31 -14
  109. package/dist/dashboard/packages/engine.js +46 -2
  110. package/dist/dashboard/packages/installed.js +13 -0
  111. package/dist/dashboard/packages/outcomes.js +21 -0
  112. package/dist/dashboard/packages/packages.js +41 -18
  113. package/dist/dashboard/packages/rows.js +3 -1
  114. package/dist/dashboard/parts/icons.js +3 -0
  115. package/dist/dashboard/parts/picture.js +89 -0
  116. package/dist/dashboard/parts/refusals.js +8 -1
  117. package/dist/dashboard/parts/widgets.js +2 -1
  118. package/dist/dashboard/play/scene.js +8 -5
  119. package/dist/dashboard/settings/settings.js +23 -13
  120. package/dist/dashboard/sheet/party.js +5 -2
  121. package/dist/dashboard/sheet/sheet.js +2 -1
  122. package/dist/dashboard/shell/notices.js +2 -2
  123. package/dist/dashboard/shell/system-style.js +45 -12
  124. package/dist/dashboard/shell/tooltip.js +223 -0
  125. package/dist/dashboard/style.css +283 -132
  126. package/dist/dashboard/world/lore.js +4 -3
  127. package/dist/dashboard/world/place-card.js +2 -1
  128. package/dist/languages/index.d.ts +1 -1
  129. package/dist/languages/index.js +1 -1
  130. package/dist/languages/pack.d.ts +4 -1
  131. package/dist/languages/pack.js +16 -5
  132. package/dist/packages/engine.d.ts +7 -0
  133. package/dist/packages/engine.js +32 -1
  134. package/dist/packages/index.d.ts +1 -1
  135. package/dist/packages/index.js +1 -1
  136. package/dist/server/dashboard/engine.d.ts +18 -0
  137. package/dist/server/dashboard/engine.js +31 -0
  138. package/dist/server/dashboard/files.d.ts +8 -1
  139. package/dist/server/dashboard/files.js +30 -10
  140. package/dist/server/dashboard/index.d.ts +3 -0
  141. package/dist/server/dashboard/index.js +10 -1
  142. package/dist/server/dashboard/pictures.d.ts +7 -0
  143. package/dist/server/dashboard/pictures.js +62 -0
  144. package/dist/server/dashboard/writes.d.ts +5 -3
  145. package/dist/server/dashboard/writes.js +45 -14
  146. package/dist/testing/index.js +1 -0
  147. package/dist/themes/index.d.ts +2 -1
  148. package/dist/themes/index.js +4 -2
  149. package/dist/themes/installed.d.ts +14 -0
  150. package/dist/themes/installed.js +28 -0
  151. package/dist/themes/theme.d.ts +7 -0
  152. package/dist/themes/theme.js +22 -0
  153. package/instructions/core.md +3 -3
  154. package/instructions/dashboard-guide.md +1 -0
  155. package/instructions/mentor-hints.md +1 -1
  156. package/instructions/mentor-tutorial.md +1 -1
  157. package/instructions/party.md +1 -1
  158. package/instructions/play.md +2 -2
  159. package/package.json +1 -1
  160. package/systems/free/instructions/outcomes-told.md +1 -1
@@ -1,6 +1,7 @@
1
- // The catalog of the packages one may add (D-485, D-486): what npm has for this rpg-engine, extensions, game systems and languages, and the adventures
2
- // GitHub has by their topic, each with what the player needs to trust it and whether it is here already.
1
+ // The catalog of the packages one may add (D-485, D-486): what npm has for this rpg-engine, extensions, game systems and languages, and the packages of data
2
+ // alone GitHub has by their topic, adventures, themes and languages, each with what the player needs to trust it and whether it is here already.
3
3
  import { join } from "node:path";
4
+ import { parse } from "yaml";
4
5
  import { readManifest } from "../../../adventures/index.js";
5
6
  import { ourSystems, readsApi } from "../../../core/packages/declarations.js";
6
7
  import { files } from "../../../core/store.js";
@@ -11,6 +12,7 @@ import { installedLanguages } from "../../../languages/index.js";
11
12
  import { isVerified } from "../../../packages/index.js";
12
13
  import { systemFolders } from "../../../systems/index.js";
13
14
  import { installedAdventures } from "../books/adventures.js";
15
+ import { isDataLanguage, isSameSource, languageFolders, themesHere, unpackedSource } from "./unpacked.js";
14
16
  // How long the setup waits for npm before it offers ours alone.
15
17
  const systemsWait = 5000;
16
18
  /** The game systems npm has that this computer has not, ours first, with ours from the engine's list beside them, npm answering in time or not (D-513 (1)). */
@@ -34,10 +36,14 @@ export async function installableSystems(context) {
34
36
  const here = systemFolders(context.systemFolders).map((one) => comparableText(one.name));
35
37
  return listed.filter((system) => !here.includes(installedName(system))).sort((first, second) => Number(second.verified) - Number(first.verified) || first.name.localeCompare(second.name));
36
38
  }
37
- /** The topic a GitHub repository carries to be found as an adventure (D-485 (4)). */
38
- const adventureTopic = "rpg-engine-adventure";
39
- // How many repositories are read, each with its adventure.yaml: GitHub answers without a login only so many times an hour.
40
- const mostAdventures = 30;
39
+ /** The topic a GitHub repository carries to be found, by the kind of package of data alone it is (D-485 (4)), and the file at its top that says what it is. */
40
+ const githubTopics = [
41
+ { kind: "adventure", topic: "rpg-engine-adventure", file: "adventure.yaml" },
42
+ { kind: "theme", topic: "rpg-engine-theme", file: "theme.yaml" },
43
+ { kind: "language", topic: "rpg-engine-language", file: "language.yaml" },
44
+ ];
45
+ // How many repositories of each topic are read, each with the file at its top: GitHub answers a search without a login only so many times an hour.
46
+ const mostRepositories = 20;
41
47
  const kinds = new Set(["system", "extension", "language"]);
42
48
  /** What npm and GitHub offer now, ours first, then by title; each source asked once, side by side. */
43
49
  export async function catalog(root, context) {
@@ -84,7 +90,7 @@ function installedVersion(context, found) {
84
90
  }
85
91
  }
86
92
  if (found.kind === "language") {
87
- return installedLanguages(context.extensionFolders ?? []).find((one) => one.package === found.name)?.version;
93
+ return installedLanguages(languageFolders(context)).find((one) => one.package === found.name)?.version;
88
94
  }
89
95
  // A system npm installed, by its package's own version.
90
96
  const folder = systemFolders(context.systemFolders).find((one) => packageIn(one.folder)?.name === found.name)?.folder;
@@ -98,47 +104,97 @@ function packageIn(folder) {
98
104
  return undefined;
99
105
  }
100
106
  }
101
- /** The adventures GitHub has by their topic, each read from its adventure.yaml; a repository without one that reads is left out. */
107
+ /**
108
+ * The adventures, themes and languages GitHub has by their topics, the three searches side by side, each repository read from the file at its top; one without
109
+ * one that reads is left out, and a search that fails leaves the others listed.
110
+ */
102
111
  async function githubEntries(root, context) {
103
- if (context.download === undefined) {
104
- return { entries: [], failed: "only the game's server and the command line reach GitHub" };
105
- }
106
112
  const download = context.download;
107
- let repositories;
108
- try {
109
- const found = JSON.parse(new TextDecoder().decode(await download(`https://api.github.com/search/repositories?q=topic:${adventureTopic}&sort=stars&per_page=${mostAdventures}`, 2 * 1024 * 1024, context.signal)));
110
- repositories = found.items ?? [];
111
- }
112
- catch (error) {
113
- return { entries: [], failed: `GitHub could not be asked: ${error instanceof Error ? error.message : String(error)}` };
113
+ if (download === undefined) {
114
+ return { entries: [], failed: "only the game's server and the command line reach GitHub" };
114
115
  }
115
- const here = installedAdventures(root);
116
- const read = await Promise.all(repositories.map(async (repository) => {
116
+ const searched = await Promise.all(githubTopics.map(async (topic) => {
117
+ try {
118
+ const url = `https://api.github.com/search/repositories?q=topic:${topic.topic}&sort=stars&per_page=${mostRepositories}`;
119
+ const found = JSON.parse(new TextDecoder().decode(await download(url, 2 * 1024 * 1024, context.signal)));
120
+ return { topic, repositories: found.items ?? [] };
121
+ }
122
+ catch (error) {
123
+ // The reason without the long address, so that three searches refused alike read as one.
124
+ const why = (error instanceof Error ? error.message : String(error)).replace(/^https:\/\/\S+ /, "").replace(/: check the address.*$/, "");
125
+ return { topic, repositories: [], failed: why };
126
+ }
127
+ }));
128
+ const here = { adventures: installedAdventures(root), themes: themesHere(context), languages: installedLanguages(languageFolders(context)).filter((one) => isDataLanguage(context, one)) };
129
+ const read = await Promise.all(searched.flatMap(({ topic, repositories }) => repositories.map(async (repository) => {
117
130
  try {
118
- const text = new TextDecoder().decode(await download(`https://raw.githubusercontent.com/${repository.full_name}/${repository.default_branch}/adventure.yaml`, 64 * 1024, context.signal));
119
- const manifest = readManifest(text, repository.full_name);
120
- const installed = here.find((one) => comparableText(one.title) === comparableText(manifest.title))?.version;
121
- const levels = manifest.levels === undefined ? undefined : manifest.levels.from === manifest.levels.to ? String(manifest.levels.from) : `${manifest.levels.from}-${manifest.levels.to}`;
122
- return {
123
- kind: "adventure",
124
- title: manifest.title,
125
- description: manifest.about,
126
- author: manifest.author ?? repository.owner?.login,
127
- version: manifest.version,
128
- verified: false,
129
- code: false,
130
- source: repository.html_url,
131
- ...(installed === undefined ? {} : { installed }),
132
- update: installed !== undefined && isNewerVersion(manifest.version, installed),
133
- ...(levels === undefined ? {} : { levels }),
134
- ...(manifest.length === undefined ? {} : { length: manifest.length }),
135
- language: manifest.language,
136
- ...(repository.stargazers_count === undefined ? {} : { stars: repository.stargazers_count }),
137
- };
131
+ const raw = `https://raw.githubusercontent.com/${repository.full_name}/${repository.default_branch}/${topic.file}`;
132
+ const text = new TextDecoder().decode(await download(raw, 64 * 1024, context.signal));
133
+ return topic.kind === "adventure"
134
+ ? adventureEntry(repository, readManifest(text, repository.full_name), here)
135
+ : topic.kind === "theme"
136
+ ? themeEntry(repository, text, here)
137
+ : languageEntry(repository, text, here);
138
138
  }
139
139
  catch {
140
140
  return undefined;
141
141
  }
142
- }));
143
- return { entries: read.filter((one) => one !== undefined) };
142
+ })));
143
+ const reasons = [...new Set(searched.flatMap((one) => (one.failed === undefined ? [] : [one.failed])))];
144
+ const failed = reasons.map((why) => `GitHub could not be asked for its ${searched.filter((one) => one.failed === why).map((one) => `${one.topic.kind}s`).join(" and ")}: ${why}`);
145
+ return { entries: read.filter((one) => one !== undefined), ...(failed.length === 0 ? {} : { failed: failed.join("; ") }) };
146
+ }
147
+ /** An adventure GitHub has, as its adventure.yaml says. */
148
+ function adventureEntry(repository, manifest, here) {
149
+ const installed = here.adventures.find((one) => comparableText(one.title) === comparableText(manifest.title))?.version;
150
+ const levels = manifest.levels === undefined ? undefined : manifest.levels.from === manifest.levels.to ? String(manifest.levels.from) : `${manifest.levels.from}-${manifest.levels.to}`;
151
+ const author = manifest.author ?? repository.owner?.login;
152
+ return {
153
+ ...githubEntry("adventure", repository, manifest.title, manifest.version, installed),
154
+ description: manifest.about,
155
+ ...(author === undefined ? {} : { author }),
156
+ ...(levels === undefined ? {} : { levels }),
157
+ ...(manifest.length === undefined ? {} : { length: manifest.length }),
158
+ language: manifest.language,
159
+ };
160
+ }
161
+ /** A theme GitHub has, by the name and version its theme.yaml gives; here only when it was installed from this repository. Its checks are made as it is installed. */
162
+ function themeEntry(repository, text, here) {
163
+ const read = parse(text);
164
+ if (typeof read?.name !== "string" || read.name.trim() === "") {
165
+ return undefined;
166
+ }
167
+ const name = read.name;
168
+ const found = here.themes.find((one) => isSameSource(unpackedSource(one.folder), repository.html_url));
169
+ return githubEntry("theme", repository, name, versionOf(read.version), found === undefined ? undefined : (found.theme?.version ?? ""));
170
+ }
171
+ /** A language GitHub has, by the code, name and version its language.yaml gives: here only when it was installed from this repository, never npm's. */
172
+ function languageEntry(repository, text, here) {
173
+ const read = parse(text);
174
+ if (typeof read?.code !== "string" || typeof read.name !== "string") {
175
+ return undefined;
176
+ }
177
+ const code = read.code;
178
+ const installed = here.languages.find((one) => isSameSource(unpackedSource(one.folder), repository.html_url))?.version;
179
+ return { ...githubEntry("language", repository, read.name, versionOf(read.version), installed), language: code };
180
+ }
181
+ /** What every package GitHub has gives: never verified, never code, added by its link; its version here, and whether GitHub's is newer: only when both are known. */
182
+ function githubEntry(kind, repository, title, version, installed) {
183
+ return {
184
+ kind,
185
+ title,
186
+ ...(typeof repository.description === "string" ? { description: repository.description } : {}),
187
+ ...(repository.owner?.login === undefined ? {} : { author: repository.owner.login }),
188
+ ...(version === undefined ? {} : { version }),
189
+ verified: false,
190
+ code: false,
191
+ source: repository.html_url,
192
+ ...(installed === undefined ? {} : { installed }),
193
+ update: installed !== undefined && installed !== "" && version !== undefined && isNewerVersion(version, installed),
194
+ ...(repository.stargazers_count === undefined ? {} : { stars: repository.stargazers_count }),
195
+ };
196
+ }
197
+ /** A version as a YAML file may write it, 1.0 a number; undefined when it gives none. */
198
+ function versionOf(value) {
199
+ return typeof value === "string" || typeof value === "number" ? String(value) : undefined;
144
200
  }
@@ -0,0 +1,50 @@
1
+ import type { PackageEntry } from "../../../core/archive.ts";
2
+ import type { Context } from "../../../core/context.ts";
3
+ import { type LanguagePack } from "../../../languages/index.ts";
4
+ import { type InstalledTheme } from "../../../themes/index.ts";
5
+ /** The most the files a theme or a language keeps may weigh, all together: faces and pictures, or phrases and a Guide. */
6
+ export declare const largestUnpacked: number;
7
+ /** The most the .zip of a theme or a language may unpack to, before what it keeps is chosen. */
8
+ export declare const largestDataZip: number;
9
+ /** The folder of the themes installed on their own; undefined where nothing installs them. */
10
+ export declare function themesFolder(context: Context): string | undefined;
11
+ /** The folder of the languages installed as data alone; undefined where nothing installs them. */
12
+ export declare function dataLanguagesFolder(context: Context): string | undefined;
13
+ /** The folders languages are read from: npm's packages first, then those of data alone. */
14
+ export declare function languageFolders(context: Context): string[];
15
+ /** The themes installed on this computer, those refused included with why. */
16
+ export declare function themesHere(context: Context): InstalledTheme[];
17
+ /** An installed theme by its id or its name; undefined when there is none. */
18
+ export declare function findTheme(context: Context, name: string): InstalledTheme | undefined;
19
+ /** A theme or a language of data alone, as a name finds it. */
20
+ export type Unpacked = {
21
+ kind: "theme";
22
+ theme: InstalledTheme;
23
+ } | {
24
+ kind: "language";
25
+ pack: LanguagePack;
26
+ };
27
+ /**
28
+ * The theme or the language of data alone a name finds: theme:<id or name> and language:<code or name> name one kind alone; an npm name, @scope/name or
29
+ * npm:name, none. Without a prefix a theme first, then a language; undefined when none is here.
30
+ */
31
+ export declare function findUnpacked(context: Context, name: string): Unpacked | undefined;
32
+ /** How a theme or a language of data alone is named to be told from an npm package of the same name: theme:<id>, language:<code>. */
33
+ export declare function unpackedName(found: Unpacked): string;
34
+ /** Where a theme or a language of data alone came from, as it was installed: a GitHub repository's link, another link, a .zip's or a folder's path. */
35
+ export declare function unpackedSource(folder: string): string | undefined;
36
+ /** Whether a link a catalog gives is where a package here came from: GitHub's links are the same in any case, with or without a slash at their end. */
37
+ export declare function isSameSource(recorded: string | undefined, link: string): boolean;
38
+ /** Whether a language package is one of data alone, unpacked by the engine rather than installed by npm. */
39
+ export declare function isDataLanguage(context: Context, pack: LanguagePack): boolean;
40
+ /** A language of data alone by its code, its name or its package's name; undefined when there is none. */
41
+ export declare function findDataLanguage(context: Context, name: string): LanguagePack | undefined;
42
+ /** The files of a package of data a theme or a language keeps, those `keep` takes; refused, with `code`, when they weigh more than `what` may, or come twice. */
43
+ export declare function keptFiles(label: string, entries: PackageEntry[], keep: (parts: string[]) => boolean, code: string, what: string): PackageEntry[];
44
+ /**
45
+ * Writes a package's files, with where it came from, into a folder of its own beside those installed, which no list reads, for it to be checked there; the
46
+ * folders an install left behind more than an hour ago go first.
47
+ */
48
+ export declare function writeTrial(folder: string, context: Context, entries: PackageEntry[], source: string): string;
49
+ /** Puts a folder checked in place of the one there, each move in one step: the one before is set aside, then taken away once the new one is there. */
50
+ export declare function placeTrial(trial: string, target: string, context: Context): void;
@@ -0,0 +1,146 @@
1
+ // Where the packages of data alone live on this computer, for every campaign: themes and languages unpacked by the engine, apart from npm's packages.
2
+ import { dirname, join } from "node:path";
3
+ import { refuseTwice } from "../../../core/archive-paths.js";
4
+ import { Refusal } from "../../../core/refusal.js";
5
+ import { files, isInside } from "../../../core/store.js";
6
+ import { comparableText } from "../../../core/text.js";
7
+ import { installedLanguages } from "../../../languages/index.js";
8
+ import { installedThemes } from "../../../themes/index.js";
9
+ /** The most the files a theme or a language keeps may weigh, all together: faces and pictures, or phrases and a Guide. */
10
+ export const largestUnpacked = 20 * 1024 * 1024;
11
+ /** The most the .zip of a theme or a language may unpack to, before what it keeps is chosen. */
12
+ export const largestDataZip = 50 * 1024 * 1024;
13
+ // The file beside a theme's or a language's own where it came from: a dot, so that no package brings one of its own.
14
+ const sourceFileName = ".source";
15
+ // How long a folder being unpacked may lie before it is taken for one an install left behind.
16
+ const staleAfter = 60 * 60 * 1000;
17
+ /** The folder of the themes installed on their own; undefined where nothing installs them. */
18
+ export function themesFolder(context) {
19
+ return context.unpacked === undefined ? undefined : join(context.unpacked, "themes");
20
+ }
21
+ /** The folder of the languages installed as data alone; undefined where nothing installs them. */
22
+ export function dataLanguagesFolder(context) {
23
+ return context.unpacked === undefined ? undefined : join(context.unpacked, "languages");
24
+ }
25
+ /** The folders languages are read from: npm's packages first, then those of data alone. */
26
+ export function languageFolders(context) {
27
+ const data = dataLanguagesFolder(context);
28
+ return [...(context.extensionFolders ?? []), ...(data === undefined ? [] : [data])];
29
+ }
30
+ /** The themes installed on this computer, those refused included with why. */
31
+ export function themesHere(context) {
32
+ const folder = themesFolder(context);
33
+ return folder === undefined ? [] : installedThemes(folder);
34
+ }
35
+ /** An installed theme by its id or its name; undefined when there is none. */
36
+ export function findTheme(context, name) {
37
+ return themesHere(context).find((one) => one.id === name.trim() || (one.theme !== undefined && comparableText(one.theme.name) === comparableText(name)));
38
+ }
39
+ /**
40
+ * The theme or the language of data alone a name finds: theme:<id or name> and language:<code or name> name one kind alone; an npm name, @scope/name or
41
+ * npm:name, none. Without a prefix a theme first, then a language; undefined when none is here.
42
+ */
43
+ export function findUnpacked(context, name) {
44
+ const prefixed = /^(theme|language):(.+)$/i.exec(name.trim());
45
+ const kind = prefixed?.[1].toLowerCase();
46
+ const asked = prefixed?.[2] ?? name;
47
+ if (prefixed === null && /^(@|npm:)/i.test(name.trim())) {
48
+ return undefined;
49
+ }
50
+ const theme = kind === "language" ? undefined : findTheme(context, asked);
51
+ const pack = kind === "theme" || theme !== undefined ? undefined : findDataLanguage(context, asked);
52
+ return theme !== undefined ? { kind: "theme", theme } : pack !== undefined ? { kind: "language", pack } : undefined;
53
+ }
54
+ /** How a theme or a language of data alone is named to be told from an npm package of the same name: theme:<id>, language:<code>. */
55
+ export function unpackedName(found) {
56
+ return found.kind === "theme" ? `theme:${found.theme.id}` : `language:${found.pack.code}`;
57
+ }
58
+ /** Where a theme or a language of data alone came from, as it was installed: a GitHub repository's link, another link, a .zip's or a folder's path. */
59
+ export function unpackedSource(folder) {
60
+ return files().text(join(folder, sourceFileName))?.trim() || undefined;
61
+ }
62
+ /** Whether a link a catalog gives is where a package here came from: GitHub's links are the same in any case, with or without a slash at their end. */
63
+ export function isSameSource(recorded, link) {
64
+ const plain = (text) => text.trim().replace(/(\.git)?\/*$/i, "").toLowerCase();
65
+ return recorded !== undefined && plain(recorded) === plain(link);
66
+ }
67
+ /** Whether a language package is one of data alone, unpacked by the engine rather than installed by npm. */
68
+ export function isDataLanguage(context, pack) {
69
+ const folder = dataLanguagesFolder(context);
70
+ return folder !== undefined && isInside(folder, pack.folder);
71
+ }
72
+ /** A language of data alone by its code, its name or its package's name; undefined when there is none. */
73
+ export function findDataLanguage(context, name) {
74
+ const wanted = comparableText(name);
75
+ return installedLanguages(languageFolders(context)).find((pack) => isDataLanguage(context, pack) && [pack.code, pack.name, pack.package].some((one) => comparableText(one) === wanted));
76
+ }
77
+ /** The files of a package of data a theme or a language keeps, those `keep` takes; refused, with `code`, when they weigh more than `what` may, or come twice. */
78
+ export function keptFiles(label, entries, keep, code, what) {
79
+ const kept = entries.filter(([parts]) => keep(parts));
80
+ refuseTwice(label, kept.map(([parts]) => parts.join("/")));
81
+ const size = kept.reduce((total, [, bytes]) => total + bytes.length, 0);
82
+ if (size > largestUnpacked) {
83
+ const why = `its files weigh ${Math.ceil(size / 1024 / 1024)} MB, more than the ${largestUnpacked / 1024 / 1024} MB ${what} may`;
84
+ throw new Refusal(`${label} cannot be used: ${why}. Nothing changed.`, code, { name: label, why });
85
+ }
86
+ return kept;
87
+ }
88
+ /**
89
+ * Writes a package's files, with where it came from, into a folder of its own beside those installed, which no list reads, for it to be checked there; the
90
+ * folders an install left behind more than an hour ago go first.
91
+ */
92
+ export function writeTrial(folder, context, entries, source) {
93
+ const now = context.now().getTime();
94
+ for (const entry of files().entries(folder)) {
95
+ const path = join(folder, entry.name);
96
+ if (entry.isFolder && /^\.(installing|replaced)-/.test(entry.name) && now - (files().modified(path) ?? now) > staleAfter) {
97
+ files().removeFolder(path);
98
+ }
99
+ }
100
+ const trial = join(folder, `.installing-${context.newId()}`);
101
+ for (const [parts, bytes] of entries) {
102
+ files().writeBytes(join(trial, ...parts), bytes);
103
+ }
104
+ files().write(join(trial, sourceFileName), `${source}\n`);
105
+ return trial;
106
+ }
107
+ /** Puts a folder checked in place of the one there, each move in one step: the one before is set aside, then taken away once the new one is there. */
108
+ export function placeTrial(trial, target, context) {
109
+ const aside = join(dirname(target), `.replaced-${context.newId()}`);
110
+ const before = files().modified(target) !== undefined;
111
+ if (before) {
112
+ moveFolder(target, aside);
113
+ }
114
+ try {
115
+ moveFolder(trial, target);
116
+ }
117
+ catch (error) {
118
+ if (before) {
119
+ moveFolder(aside, target);
120
+ }
121
+ throw error;
122
+ }
123
+ files().removeFolder(aside);
124
+ }
125
+ // How many times a folder is moved before giving up, a tenth of a second apart: an antivirus or an open window may hold it for a moment.
126
+ const moveTries = 10;
127
+ /** Moves a folder, trying again while something holds it; refused, with what to do, when it stays held. */
128
+ function moveFolder(from, to) {
129
+ for (let tried = 1;; tried++) {
130
+ try {
131
+ files().move(from, to);
132
+ return;
133
+ }
134
+ catch (error) {
135
+ const code = error.code;
136
+ if ((code !== "EPERM" && code !== "EBUSY" && code !== "EACCES") || tried === moveTries) {
137
+ const why = error instanceof Error ? error.message : String(error);
138
+ throw new Refusal(`${from} could not be moved: ${why}. Close what is using that folder, such as a window open on it, and install it again. Nothing changed.`, "folder-held", {
139
+ name: from,
140
+ why,
141
+ });
142
+ }
143
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 100);
144
+ }
145
+ }
146
+ }
@@ -0,0 +1,13 @@
1
+ /** A file of a package: its path in parts, from the package's top, and its bytes. */
2
+ export type PackageEntry = [string[], Uint8Array];
3
+ /** The files a .zip holds, by their names as written, unpacking to at most `most` bytes; it throws, saying why, when it does not read. `what` names the package: an adventure. */
4
+ export declare function unzipFiles(bytes: Uint8Array, label: string, most: number, what: string): [string, Uint8Array][];
5
+ /** The files a .zip holds, by their names as written, with what each unpacks to, none of them unpacked: to tell what it is before reading it. */
6
+ export declare function zipListing(bytes: Uint8Array, label: string): [string, number][];
7
+ /**
8
+ * A package's files: each path checked, what a computer leaves beside them dropped, and the one folder at its top that holds them all taken away while none of
9
+ * `tops`, the files that tell what it is, lies at its top. `what` names it in a refusal: the adventure.
10
+ */
11
+ export declare function packageEntries(label: string, entries: [string, Uint8Array][], what: string, tops: readonly string[]): PackageEntry[];
12
+ /** The file at a package's top named so, in any case; undefined when there is none. */
13
+ export declare function topFile(entries: PackageEntry[], name: string): PackageEntry | undefined;
@@ -0,0 +1,76 @@
1
+ // A package of data someone else made, read whole into memory (ADV-1): a .zip unpacked with its size capped and its names read as UTF-8, then each path
2
+ // checked, what a computer leaves beside files dropped, and the one folder GitHub zips a repository in taken away.
3
+ import { unzipSync } from "fflate";
4
+ import { archivePathParts } from "./archive-paths.js";
5
+ import { Refusal } from "./refusal.js";
6
+ // What a computer leaves beside files, which no one put in the package.
7
+ const litter = /^(\..*|__macosx|thumbs\.db|desktop\.ini)$/i;
8
+ /** The files a .zip holds, by their names as written, unpacking to at most `most` bytes; it throws, saying why, when it does not read. `what` names the package: an adventure. */
9
+ export function unzipFiles(bytes, label, most, what) {
10
+ let declared = 0;
11
+ let read;
12
+ try {
13
+ read = unzipSync(bytes, {
14
+ filter: (file) => {
15
+ declared += file.originalSize;
16
+ if (declared > most) {
17
+ throw new Error(`it unpacks to more than ${most / 1024 / 1024} MB, more than ${what} may`);
18
+ }
19
+ return true;
20
+ },
21
+ });
22
+ }
23
+ catch (error) {
24
+ throw new Refusal(`${label} is not a .zip that reads: ${error instanceof Error ? error.message : String(error)}. Nothing changed.`, "archive-unread", { name: label });
25
+ }
26
+ return Object.entries(read).filter(([name]) => !/[\\/]$/.test(name)).map(([name, data]) => [utf8Name(label, name), data]);
27
+ }
28
+ /** The files a .zip holds, by their names as written, with what each unpacks to, none of them unpacked: to tell what it is before reading it. */
29
+ export function zipListing(bytes, label) {
30
+ const listed = [];
31
+ try {
32
+ unzipSync(bytes, {
33
+ filter: (file) => {
34
+ listed.push([file.name, file.originalSize]);
35
+ return false;
36
+ },
37
+ });
38
+ }
39
+ catch (error) {
40
+ throw new Refusal(`${label} is not a .zip that reads: ${error instanceof Error ? error.message : String(error)}. Nothing changed.`, "archive-unread", { name: label });
41
+ }
42
+ return listed.filter(([name]) => !/[\\/]$/.test(name)).map(([name, size]) => [utf8Name(label, name), size]);
43
+ }
44
+ /**
45
+ * A package's files: each path checked, what a computer leaves beside them dropped, and the one folder at its top that holds them all taken away while none of
46
+ * `tops`, the files that tell what it is, lies at its top. `what` names it in a refusal: the adventure.
47
+ */
48
+ export function packageEntries(label, entries, what, tops) {
49
+ // What a computer leaves beside the files, as macOS's __MACOSX, goes before the folder at the top is looked for.
50
+ const checked = entries.map(([name, data]) => [archivePathParts(label, name, what), data]).filter(([parts]) => parts.length > 0 && !parts.some((part) => litter.test(part)));
51
+ const atTop = checked.some(([parts]) => parts.length === 1 && tops.includes(parts[0].toLowerCase()));
52
+ const folders = new Set(checked.map(([parts]) => parts[0]));
53
+ return !atTop && folders.size === 1 ? checked.map(([parts, data]) => [parts.slice(1), data]).filter(([parts]) => parts.length > 0) : checked;
54
+ }
55
+ /** The file at a package's top named so, in any case; undefined when there is none. */
56
+ export function topFile(entries, name) {
57
+ return entries.find(([parts]) => parts.length === 1 && parts[0].toLowerCase() === name);
58
+ }
59
+ /**
60
+ * A file's name in a .zip as it was written: one without the zip's UTF-8 mark reads byte by byte, so its UTF-8 is read again, as macOS writes it; one in an old
61
+ * code page, as Windows' own tar writes it, is refused with what to do.
62
+ */
63
+ function utf8Name(label, name) {
64
+ if (/^[\u0000-ÿ]*$/.test(name) && /[\u0080-ÿ]/.test(name)) {
65
+ try {
66
+ return new TextDecoder("utf-8", { fatal: true }).decode(Uint8Array.from(name, (character) => character.charCodeAt(0))).normalize("NFC");
67
+ }
68
+ catch {
69
+ // Not UTF-8 byte by byte: a name the zip marked as UTF-8 already, or one in an old code page.
70
+ }
71
+ }
72
+ if (/[\u0080-\u009f]/.test(name)) {
73
+ throw new Refusal(`${label} names a file with accents not written in UTF-8 (${name}): make the zip again with 7-Zip, or Compress-Archive in PowerShell. Nothing changed.`, "archive-accents", { name: label });
74
+ }
75
+ return name.normalize("NFC");
76
+ }
@@ -39,6 +39,8 @@ export interface Context {
39
39
  }>;
40
40
  /** The folders that hold the installed extensions, each a package folder or npm's node_modules (D-436); none where missing. */
41
41
  extensionFolders?: string[];
42
+ /** Where the packages of data alone are unpacked, for every campaign on this computer: themes/<id>/ and languages/<code>/; none where nothing installs them. */
43
+ unpacked?: string;
42
44
  /** The AI app the MCP server serves, by the name it gives itself, such as claude-code; missing on the command line. */
43
45
  host?: () => string | undefined;
44
46
  /** The packages the player said no to in a window in this session, by the name npm describes: never asked again until the server starts again (D-510). */
@@ -16,6 +16,7 @@ export function defaultContext(folder = process.cwd()) {
16
16
  // From src/core/ and from dist/core/ alike, the package's systems/ folder is two levels up; then those npm installed (D-485).
17
17
  systemFolders: [engineSystemsFolder, join(packagesFolder(), "node_modules")],
18
18
  extensionFolders: [join(packagesFolder(), "node_modules")],
19
+ unpacked: join(packagesFolder(), "unpacked"),
19
20
  home: userDataFolder(),
20
21
  bookIndex: join(dirname(packagesFolder()), "library"),
21
22
  // The built page is in dist/dashboard, two levels up from src/core/ and from dist/core/ alike.
@@ -58,10 +58,14 @@ export declare class FileStore {
58
58
  makeFolder(path: string): void;
59
59
  /** How many bytes a file has, as the disk says now, without reading it; undefined when there is none. */
60
60
  size(path: string): number | undefined;
61
- /** When a file last changed, in milliseconds, as the disk says now; undefined when there is none. */
61
+ /** When a file or a folder last changed, in milliseconds, as the disk says now; undefined when there is none. */
62
62
  modified(path: string): number | undefined;
63
63
  /** Removes a file. */
64
64
  remove(path: string): void;
65
+ /** Removes a folder with all it holds, if it is there: what the store kept of it goes too. */
66
+ removeFolder(path: string): void;
67
+ /** Moves a file or a folder to a path of the same disk where nothing is, in one step: no one reads it half there. */
68
+ move(from: string, to: string): void;
65
69
  protected entry(path: string): Kept;
66
70
  /**
67
71
  * A file of an installed game system as the process last read it, while it has not changed since, nor in the two seconds before; undefined for any other
@@ -1,7 +1,7 @@
1
1
  // The files as a command sees them (D-137, D-194): each read at most once in a call, kept as its text and as what it reads as, frozen; what the command writes
2
2
  // updates what is kept. A command runs inside its store, and the modules reach it with files(): the MCP server will keep one for a whole session.
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
- import { appendFileSync, closeSync, existsSync, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, rmSync, statSync, writeFileSync } from "node:fs";
4
+ import { appendFileSync, closeSync, existsSync, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
5
5
  import { basename, dirname, isAbsolute, relative, resolve, sep } from "node:path";
6
6
  import { fileOrder, filesIn } from "./files.js";
7
7
  import { frozen } from "./frozen.js";
@@ -143,7 +143,7 @@ export class FileStore {
143
143
  size(path) {
144
144
  return existsSync(path) && statSync(path).isFile() ? statSync(path).size : undefined;
145
145
  }
146
- /** When a file last changed, in milliseconds, as the disk says now; undefined when there is none. */
146
+ /** When a file or a folder last changed, in milliseconds, as the disk says now; undefined when there is none. */
147
147
  modified(path) {
148
148
  return existsSync(path) ? statSync(path).mtimeMs : undefined;
149
149
  }
@@ -153,6 +153,19 @@ export class FileStore {
153
153
  this.changed(path, { text: undefined }, false);
154
154
  markWritten();
155
155
  }
156
+ /** Removes a folder with all it holds, if it is there: what the store kept of it goes too. */
157
+ removeFolder(path) {
158
+ rmSync(path, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
159
+ this.refresh(path);
160
+ markWritten();
161
+ }
162
+ /** Moves a file or a folder to a path of the same disk where nothing is, in one step: no one reads it half there. */
163
+ move(from, to) {
164
+ renameSync(from, to);
165
+ this.refresh(from);
166
+ this.refresh(to);
167
+ markWritten();
168
+ }
156
169
  entry(path) {
157
170
  const key = resolve(path);
158
171
  let entry = this.kept.get(key);
@@ -135,7 +135,8 @@ export async function updateEngine() {
135
135
  if (response.status === 202 && body.version !== undefined) {
136
136
  return { done: true, version: body.version, restart: body.restart === "app" ? "app" : "chat" };
137
137
  }
138
- return { done: false, error: refusalText(body, t("It did not reach the game: try again.")), ...(body.code === "busy" ? { code: body.code } : {}) };
138
+ const code = body.code === "busy" || body.code === "declined" || body.code === "no-window" || body.code === "engine-failed" ? body.code : undefined;
139
+ return { done: false, error: refusalText(body, t("It did not reach the game: try again.")), ...(code === undefined ? {} : { code }) };
139
140
  }
140
141
  catch {
141
142
  return { done: false, error: t("It did not reach the game: try again.") };
@@ -226,6 +227,28 @@ export async function putPageBack(page, shown) {
226
227
  return { done: false, error: t("It did not reach the game: try again.") };
227
228
  }
228
229
  }
230
+ /** The largest picture the page sends, as the engine takes it: 5 MB. */
231
+ export const largestPicture = 5 * 1024 * 1024;
232
+ /** Gives a page the player's own picture (D-572 (3)): undefined when it is the page's now, else why not, in the page's words. */
233
+ export async function givePicture(page, file) {
234
+ if (file.size > largestPicture) {
235
+ return refusalText({ code: "picture-big", values: { size: String(largestPicture / 1024 / 1024) } }, "");
236
+ }
237
+ try {
238
+ const response = await fetch(`/api/picture?${new URLSearchParams({ page })}`, {
239
+ method: "POST",
240
+ headers: { "Content-Type": file.type || "application/octet-stream", "X-File-Name": encodeURIComponent(file.name) },
241
+ body: file,
242
+ });
243
+ if (response.ok) {
244
+ return undefined;
245
+ }
246
+ return refusalText(await response.json().catch(() => ({})), t("It did not reach the game: try again."));
247
+ }
248
+ catch {
249
+ return t("It did not reach the game: try again.");
250
+ }
251
+ }
229
252
  /** Exports the campaign as an adventure, as it was at its start (ADV-7): the address to download its .zip from, or what went wrong. */
230
253
  export async function exportCampaign(credits) {
231
254
  try {
@@ -16,6 +16,7 @@ import { Help } from "./help/help.js";
16
16
  import { FollowedQuests, JournalView, QuestEndings } from "./journal/journal.js";
17
17
  import { AskCard } from "./packages/ask-card.js";
18
18
  import { inCard, nextPackCard } from "./packages/card.js";
19
+ import { useEngineNotice } from "./packages/engine.js";
19
20
  import { PackagesPage } from "./packages/packages.js";
20
21
  import { codeOfModule, ModulesContext, ownKey, preloadModules, systemPageStyle, useNavPages } from "./packages/page-code.js";
21
22
  import { PackagePage } from "./packages/page.js";
@@ -46,6 +47,7 @@ import { calledOf, playerNamed, turnKey, withHeld } from "./shell/shown.js";
46
47
  import { gameStyleChanged, takeSystemStyle } from "./shell/system-style.js";
47
48
  import { PlayTable, tableBeside, TableTab, useTableAway } from "./shell/table.js";
48
49
  import { restoreTheme } from "./shell/theme.js";
50
+ import { startTooltips } from "./shell/tooltip.js";
49
51
  import { SetupCorner, Top } from "./shell/top.js";
50
52
  import { browserLanguage, pageDirection, pageLocale, setLanguage, setSystemWords, t } from "./text.js";
51
53
  import { WorldView } from "./world/world.js";
@@ -517,7 +519,8 @@ function App() {
517
519
  const pageWidgets = useMemo(() => (packWidget === undefined ? widgets : widgets.filter((widget) => widget.id !== packWidget)), [widgets, packWidget]);
518
520
  // While the campaign is in its setup, the page is its first configuration, as a portal's (D-370).
519
521
  const inSetup = setup?.mode === "setup";
520
- // The page's own messages, over it (D-298): a problem, the game away, a word to know.
522
+ const engineNotice = useEngineNotice(address.section);
523
+ // The page's own messages, over it (D-298): a problem, the game away, a word to know; a newer RPG Engine last (T-219).
521
524
  const notices = [
522
525
  ...(shown.problem === undefined ? [] : [{ kind: "problem", text: shown.problem }]),
523
526
  ...(!live && shown.readAt !== undefined
@@ -527,6 +530,7 @@ function App() {
527
530
  ...gameNotices(shown.problems, shown.textsTranslating),
528
531
  // In the setup an import under way is with the page's other notices, in the column of its card (D-491 (11)).
529
532
  ...(inSetup ? importNotices(shown.importing) : []),
533
+ ...engineNotice,
530
534
  ];
531
535
  // In play, under the player's turn, which counts more in a fight.
532
536
  const importing = inSetup ? [] : importNotices(shown.importing);
@@ -577,8 +581,9 @@ function App() {
577
581
  setFresh((before) => new Set([...before, roll.id]));
578
582
  } }), acting !== undefined && (_jsx(ActSheet, { start: acting.start, self: several ? member?.name : undefined, place: actsElsewhere === undefined ? shown.place : actPlace?.who === actsElsewhere ? actPlace.place : undefined, scene: shown.openScene, companions: shown.party.filter((one) => one.role === "companion").map((one) => one.name), reply: reply, asked: answeringQuestion, onSend: sendAct, onClose: closeAct })), _jsx(ActStrip, { entries: strip, problem: actProblem, onWithdraw: (id) => void withdraw(id), onCopy: copyFromStrip, onDismiss: dismissAct })] }) }) }) }) }) }));
579
583
  }
580
- // The theme the player picked before, from the start (D-300).
584
+ // The theme the player picked before, from the start (D-300); the tooltips over everything (T-228).
581
585
  restoreTheme();
586
+ startTooltips();
582
587
  const root = document.getElementById("app");
583
588
  if (root !== null) {
584
589
  render(_jsx(App, {}), root);