rpg-engine 0.9.0 → 0.10.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 (115) hide show
  1. package/dist/adventures/source.js +6 -5
  2. package/dist/commands/find.d.ts +1 -0
  3. package/dist/commands/find.js +3 -2
  4. package/dist/commands/package.d.ts +3 -3
  5. package/dist/commands/package.js +72 -35
  6. package/dist/commands/rules.js +4 -2
  7. package/dist/commands/shared/adventures.js +20 -11
  8. package/dist/commands/shared/library.js +13 -5
  9. package/dist/commands/shared/packages/catalog.d.ts +2 -0
  10. package/dist/commands/shared/packages/catalog.js +1 -0
  11. package/dist/commands/shared/rules.js +29 -5
  12. package/dist/commands/view/place.d.ts +2 -0
  13. package/dist/commands/view/place.js +8 -2
  14. package/dist/core/context.d.ts +2 -0
  15. package/dist/core/refusal.d.ts +12 -0
  16. package/dist/core/refusal.js +17 -0
  17. package/dist/dashboard/api.js +37 -81
  18. package/dist/dashboard/app.js +10 -3
  19. package/dist/dashboard/asked.js +6 -3
  20. package/dist/dashboard/assets/master.svg +1 -2
  21. package/dist/dashboard/card.js +1 -1
  22. package/dist/dashboard/dice/load.js +6 -1
  23. package/dist/dashboard/dice/throw.js +5 -1
  24. package/dist/dashboard/dice/tray.js +5 -1
  25. package/dist/dashboard/footer.js +2 -2
  26. package/dist/dashboard/game-words.js +32 -32
  27. package/dist/dashboard/guide/ar.md +5 -5
  28. package/dist/dashboard/guide/cs.md +7 -7
  29. package/dist/dashboard/guide/da.md +5 -5
  30. package/dist/dashboard/guide/de.md +5 -5
  31. package/dist/dashboard/guide/el.md +7 -7
  32. package/dist/dashboard/guide/en.md +2 -2
  33. package/dist/dashboard/guide/es.md +6 -6
  34. package/dist/dashboard/guide/fi.md +5 -5
  35. package/dist/dashboard/guide/fr.md +6 -6
  36. package/dist/dashboard/guide/he.md +7 -7
  37. package/dist/dashboard/guide/hi.md +6 -6
  38. package/dist/dashboard/guide/hu.md +7 -7
  39. package/dist/dashboard/guide/is.md +7 -7
  40. package/dist/dashboard/guide/it.md +5 -5
  41. package/dist/dashboard/guide/ja.md +7 -7
  42. package/dist/dashboard/guide/ko.md +9 -9
  43. package/dist/dashboard/guide/nb.md +6 -6
  44. package/dist/dashboard/guide/nl.md +7 -7
  45. package/dist/dashboard/guide/pl.md +7 -7
  46. package/dist/dashboard/guide/pt.md +5 -5
  47. package/dist/dashboard/guide/ro.md +8 -8
  48. package/dist/dashboard/guide/ru.md +7 -7
  49. package/dist/dashboard/guide/sv.md +6 -6
  50. package/dist/dashboard/guide/tr.md +8 -8
  51. package/dist/dashboard/guide/uk.md +6 -6
  52. package/dist/dashboard/guide/zh.md +8 -8
  53. package/dist/dashboard/help/blocks.js +6 -0
  54. package/dist/dashboard/help/help.js +15 -3
  55. package/dist/dashboard/help/markdown.js +2 -1
  56. package/dist/dashboard/i18n/ar.json +53 -1
  57. package/dist/dashboard/i18n/cs.json +53 -1
  58. package/dist/dashboard/i18n/da.json +53 -1
  59. package/dist/dashboard/i18n/de.json +53 -1
  60. package/dist/dashboard/i18n/el.json +53 -1
  61. package/dist/dashboard/i18n/es.json +53 -1
  62. package/dist/dashboard/i18n/fi.json +53 -1
  63. package/dist/dashboard/i18n/fr.json +53 -1
  64. package/dist/dashboard/i18n/he.json +53 -1
  65. package/dist/dashboard/i18n/hi.json +53 -1
  66. package/dist/dashboard/i18n/hu.json +53 -1
  67. package/dist/dashboard/i18n/is.json +53 -1
  68. package/dist/dashboard/i18n/it.json +56 -4
  69. package/dist/dashboard/i18n/ja.json +53 -1
  70. package/dist/dashboard/i18n/ko.json +53 -1
  71. package/dist/dashboard/i18n/nb.json +53 -1
  72. package/dist/dashboard/i18n/nl.json +53 -1
  73. package/dist/dashboard/i18n/pl.json +53 -1
  74. package/dist/dashboard/i18n/pt.json +53 -1
  75. package/dist/dashboard/i18n/ro.json +53 -1
  76. package/dist/dashboard/i18n/ru.json +53 -1
  77. package/dist/dashboard/i18n/sv.json +53 -1
  78. package/dist/dashboard/i18n/tr.json +53 -1
  79. package/dist/dashboard/i18n/uk.json +53 -1
  80. package/dist/dashboard/i18n/zh.json +53 -1
  81. package/dist/dashboard/icons.js +2 -2
  82. package/dist/dashboard/journal.js +9 -4
  83. package/dist/dashboard/labels.js +5 -4
  84. package/dist/dashboard/language-choice.js +3 -3
  85. package/dist/dashboard/markdown.js +11 -4
  86. package/dist/dashboard/notes.js +4 -2
  87. package/dist/dashboard/notices.js +2 -2
  88. package/dist/dashboard/packages/ask-card.js +1 -1
  89. package/dist/dashboard/packages/packages.js +14 -10
  90. package/dist/dashboard/packages/page-code.js +11 -3
  91. package/dist/dashboard/packages/widgets.js +5 -5
  92. package/dist/dashboard/pages.js +3 -3
  93. package/dist/dashboard/place/map-sheet.js +4 -3
  94. package/dist/dashboard/place/map-view.js +17 -5
  95. package/dist/dashboard/refusals.js +61 -0
  96. package/dist/dashboard/rolls.js +3 -3
  97. package/dist/dashboard/settings.js +19 -5
  98. package/dist/dashboard/sheet.js +26 -7
  99. package/dist/dashboard/status.js +19 -13
  100. package/dist/dashboard/style.css +113 -16
  101. package/dist/dashboard/text.js +6 -2
  102. package/dist/dashboard/top.js +7 -9
  103. package/dist/dashboard/turns.js +7 -2
  104. package/dist/dashboard/world/lore.js +16 -15
  105. package/dist/dashboard/world/map.js +43 -1
  106. package/dist/dashboard/world/world.js +50 -15
  107. package/dist/extensions/extension.js +4 -1
  108. package/dist/packages/npm.js +4 -2
  109. package/dist/packages/tarball.js +8 -4
  110. package/dist/rules/rule-book.d.ts +2 -0
  111. package/dist/rules/search.d.ts +4 -1
  112. package/dist/rules/search.js +8 -2
  113. package/dist/server/dashboard/writes.js +22 -13
  114. package/dist/systems/system-code.js +5 -0
  115. package/package.json +1 -1
@@ -30,7 +30,8 @@ export function ruleTitled(root, system, title) {
30
30
  * In a language the system has its rules in, a chapter translated takes the place of its English one (D-542).
31
31
  */
32
32
  export function systemRuleBook(system, language) {
33
- const [own, version] = systemContentFolders(system).map((folder) => translatedBook(readRuleBook(join(folder, "rules"), system.name), translationFolder(folder, language), system.name));
33
+ const words = language === undefined ? undefined : systemWordsIn(system, language);
34
+ const [own, version] = systemContentFolders(system).map((folder) => translatedBook(readRuleBook(join(folder, "rules"), system.name), translationFolder(folder, language), system.name, words));
34
35
  return version === undefined ? own : [...own.filter((section) => !version.some((other) => other.file === section.file)), ...version];
35
36
  }
36
37
  /** Whether a game system has its rules in a language, in one of its folders (D-542). */
@@ -42,17 +43,40 @@ export function hasTranslatedRules(system, language) {
42
43
  }
43
44
  /** A word of the system in a language, by its English, as Prono for Prone; none without it, or when its words do not read, which validate says. */
44
45
  function ownWord(system, language, english) {
46
+ return language === undefined ? undefined : systemWordsIn(system, language)?.[english];
47
+ }
48
+ /** The system's words in a language, by their English; none when it has none, or they do not read, which validate says. */
49
+ function systemWordsIn(system, language) {
45
50
  try {
46
- return language === undefined ? undefined : layeredSystemWords(systemContentFolders(system), language)?.words[english];
51
+ return layeredSystemWords(systemContentFolders(system), language)?.words;
47
52
  }
48
53
  catch {
49
54
  return undefined;
50
55
  }
51
56
  }
52
- function translatedBook(book, translations, system) {
57
+ /**
58
+ * A book with its chapters in a language in place of its own; a chapter whose sections match its own one by one, at the same levels and with the titles the
59
+ * system's words give, gives each the path it has there, so that the system's own titles, as its outputs name them, still find it (D-542).
60
+ */
61
+ function translatedBook(book, translations, system, words) {
53
62
  const translated = translations === undefined ? [] : readRuleBook(join(translations, "rules"), system);
54
- const files = new Set(translated.map((section) => section.file));
55
- return files.size === 0 ? book : [...book.filter((section) => !files.has(section.file)), ...translated].sort((first, second) => (first.file < second.file ? -1 : first.file > second.file ? 1 : 0));
63
+ const files = [...new Set(translated.map((section) => section.file))];
64
+ if (files.length === 0) {
65
+ return book;
66
+ }
67
+ const aliased = files.flatMap((file) => {
68
+ const own = book.filter((section) => section.file === file);
69
+ const other = translated.filter((section) => section.file === file);
70
+ return isParallel(own, other, words) ? other.map((section, index) => ({ ...section, alias: own[index].path })) : other;
71
+ });
72
+ return [...book.filter((section) => !files.includes(section.file)), ...aliased].sort((first, second) => (first.file < second.file ? -1 : first.file > second.file ? 1 : 0));
73
+ }
74
+ /** Whether a chapter's translation has its sections in the same order: as many, at the same levels, none named otherwise than the system's words name it. */
75
+ function isParallel(own, other, words) {
76
+ return own.length === other.length && own.every((section, index) => {
77
+ const word = words?.[section.path.at(-1) ?? ""];
78
+ return section.level === other[index].level && (word === undefined || comparableText(word) === comparableText(other[index].path.at(-1) ?? ""));
79
+ });
56
80
  }
57
81
  /** "Poisoned is a condition of the system 5e, by a house rule:" and the text, then the precedents on it, with what to do when they disagree with the book. */
58
82
  export function ruleBlock(rule) {
@@ -106,6 +106,8 @@ export interface Fighter {
106
106
  /** In a fight, marked by the master as attacking the party (D-415). */
107
107
  hostile?: true;
108
108
  stranger?: true;
109
+ /** Whose turn it is: the one of two strangers seen alike, as two hooded men, whom the turn's name alone cannot tell. */
110
+ acting?: true;
109
111
  health?: string;
110
112
  /** How hard a foe heard in words is hit: low in the lower half of the system's words, down at the last. */
111
113
  wound?: "low" | "down";
@@ -233,7 +233,7 @@ function fightersOf(sight, scene) {
233
233
  const names = scene.order ?? [...scene.with.map((link) => parsePageReference(link).name), ...Object.keys(scene.copies)];
234
234
  return names.flatMap((name) => {
235
235
  const fighter = fighterOf(sight, scene, name);
236
- return fighter === undefined ? [] : [fighter];
236
+ return fighter === undefined ? [] : [scene.turn !== undefined && comparableText(name) === comparableText(scene.turn) ? { ...fighter, acting: true } : fighter];
237
237
  });
238
238
  }
239
239
  /** One in the fight (D-314): a copy as the character knows its creature, a character as it knows them; the party in full, the others by what anyone sees. */
@@ -398,7 +398,13 @@ function strangerName(scene, copy) {
398
398
  }
399
399
  /** What the character sees of a character it does not know by name, as the master said (D-416); someone when the master said nothing. */
400
400
  function seenName(scene, name) {
401
- return (scene === undefined ? undefined : seenOf(scene, name)) ?? "someone";
401
+ const said = scene === undefined ? undefined : seenOf(scene, name);
402
+ if (scene === undefined || said === undefined) {
403
+ return "someone";
404
+ }
405
+ // Two seen alike are numbered as copies are, in the order the master named them, so that the player and the master tell them apart: uomo incappucciato 2.
406
+ const alike = Object.entries(scene.seen ?? {}).filter(([, words]) => comparableText(words) === comparableText(said)).map(([key]) => comparableText(key));
407
+ return alike.length < 2 ? said : `${said} ${alike.indexOf(comparableText(parsePageReference(name).name)) + 1}`;
402
408
  }
403
409
  /** What the master said the character sees of a character or a kind of creature, by its name. */
404
410
  function seenOf(scene, name) {
@@ -103,6 +103,8 @@ export interface PackageInfo {
103
103
  kind?: string;
104
104
  /** The version of the extensions' API it is made for (D-441). */
105
105
  api?: number;
106
+ /** The game system an extension is made for, as its package.json says beside its kind, so that a catalog tells it before it is installed (D-548). */
107
+ system?: string;
106
108
  description?: string;
107
109
  /** Who wrote it, as npm gives it. */
108
110
  author?: string;
@@ -0,0 +1,12 @@
1
+ /** An error with a code and its values beside its message, for the dashboard to say in the page's language. */
2
+ export declare class Refusal extends Error {
3
+ readonly code: string;
4
+ readonly values: Record<string, string>;
5
+ constructor(message: string, code: string, values?: Record<string, string>);
6
+ }
7
+ /** What the dashboard sends of an error: its words, and its code and values when it is a refusal. */
8
+ export declare function refusalBody(error: unknown): {
9
+ error: string;
10
+ code?: string;
11
+ values?: Record<string, string>;
12
+ };
@@ -0,0 +1,17 @@
1
+ // A refusal the player may meet on the dashboard (T-162): the engine's words, which the master reads as they are, and a code with its values, which the page
2
+ // says in its own language. A code the page does not know shows the engine's words.
3
+ /** An error with a code and its values beside its message, for the dashboard to say in the page's language. */
4
+ export class Refusal extends Error {
5
+ code;
6
+ values;
7
+ constructor(message, code, values = {}) {
8
+ super(message);
9
+ this.code = code;
10
+ this.values = values;
11
+ }
12
+ }
13
+ /** What the dashboard sends of an error: its words, and its code and values when it is a refusal. */
14
+ export function refusalBody(error) {
15
+ const message = error instanceof Error ? error.message : String(error);
16
+ return error instanceof Refusal ? { error: message, code: error.code, ...(Object.keys(error.values).length === 0 ? {} : { values: error.values }) } : { error: message };
17
+ }
@@ -1,3 +1,4 @@
1
+ import { refusalText } from "./refusals.js";
1
2
  import { t } from "./text.js";
2
3
  /** A picture's address, with when its file last changed, so that it comes again only when it changes. */
3
4
  export function pictureAddress(picture) {
@@ -6,20 +7,11 @@ export function pictureAddress(picture) {
6
7
  /** What view gives: the party, with the last rolls, as many as asked, and the place of the player character `focus` names (VIEW-12); or a page. */
7
8
  export async function readView(page, rolls, focus) {
8
9
  const query = new URLSearchParams({ ...(page === undefined ? {} : { page }), ...(rolls === undefined ? {} : { rolls: String(rolls) }), ...(focus === undefined ? {} : { focus }) });
9
- const response = await fetch(query.size === 0 ? "/api/view" : `/api/view?${query}`);
10
- const body = await response.json();
11
- if ("error" in body) {
12
- throw new Error(body.error);
13
- }
14
- return body;
10
+ return await readJson(query.size === 0 ? "/api/view" : `/api/view?${query}`);
15
11
  }
16
12
  /** The world map as the player character knows it (VIEW-7). */
17
13
  export async function readMap() {
18
- const response = await fetch("/api/view?map=true");
19
- const body = await response.json();
20
- if ("error" in body) {
21
- throw new Error(body.error);
22
- }
14
+ const body = await readJson("/api/view?map=true");
23
15
  if (body.kind !== "map") {
24
16
  throw new Error(t("There is no player character yet: the map starts with one."));
25
17
  }
@@ -27,20 +19,12 @@ export async function readMap() {
27
19
  }
28
20
  /** The player's settings, with their values and what each means (D-341). */
29
21
  export async function readSettings() {
30
- const response = await fetch("/api/view?settings=true");
31
- const body = await response.json();
32
- if ("error" in body) {
33
- throw new Error(body.error);
34
- }
22
+ const body = await readJson("/api/view?settings=true");
35
23
  return body.kind === "settings" ? body.settings : [];
36
24
  }
37
25
  /** The campaign's setup: its mode and name, what the next mode needs, and the setup's questions (D-370). */
38
26
  export async function readSetup() {
39
- const response = await fetch("/api/view?setup=true");
40
- const body = await response.json();
41
- if ("error" in body) {
42
- throw new Error(body.error);
43
- }
27
+ const body = await readJson("/api/view?setup=true");
44
28
  if (body.kind !== "setup") {
45
29
  throw new Error(t("The game gave no setup: reload the page."));
46
30
  }
@@ -58,29 +42,17 @@ export async function sendSetupWord(word) {
58
42
  }
59
43
  /** The quests the character knows and the story by scenes (D-367); none before there is a player character. */
60
44
  export async function readJournal() {
61
- const response = await fetch("/api/view?journal=true");
62
- const body = await response.json();
63
- if ("error" in body) {
64
- throw new Error(body.error);
65
- }
45
+ const body = await readJson("/api/view?journal=true");
66
46
  return body.kind === "journal" ? body : undefined;
67
47
  }
68
48
  /** What the character knows, its documents and the calendar; none before there is a player character, or from a server older than the page. */
69
49
  export async function readWorld() {
70
- const response = await fetch("/api/view?world=true");
71
- const body = await response.json();
72
- if ("error" in body) {
73
- throw new Error(body.error);
74
- }
50
+ const body = await readJson("/api/view?world=true");
75
51
  return body.kind === "world" ? body : undefined;
76
52
  }
77
53
  /** The player's notes, the last written first (D-371), and those shared that the master has not heard yet, which may be taken back (D-381). */
78
54
  export async function readNotes() {
79
- const response = await fetch("/api/notes");
80
- const body = await response.json().catch(() => ({ error: t("The notes did not come ({status}): reload the page.", { status: response.status }) }));
81
- if ("error" in body) {
82
- throw new Error(body.error);
83
- }
55
+ const body = await readJson("/api/notes");
84
56
  return { notes: body.notes, pending: body.pending ?? [] };
85
57
  }
86
58
  // The notes reach the game one after another, in the order they were written.
@@ -123,11 +95,7 @@ export async function readStory(who) {
123
95
  }
124
96
  /** The campaign's saves, newest first, and what the mode lets the player do with them (D-359). */
125
97
  export async function readSaves() {
126
- const response = await fetch("/api/view?saves=true");
127
- const body = await response.json();
128
- if ("error" in body) {
129
- throw new Error(body.error);
130
- }
98
+ const body = await readJson("/api/view?saves=true");
131
99
  if (body.kind !== "saves") {
132
100
  throw new Error(t("The game gave no saves: reload the page."));
133
101
  }
@@ -150,10 +118,10 @@ export async function changeSaves(change) {
150
118
  /** RPG Engine and what npm has of it; undefined where the page is not served by the game's own server, which alone updates it. */
151
119
  export async function readEngine() {
152
120
  const response = await fetch("/api/engine");
153
- const body = await response.json();
154
121
  if (response.status === 400) {
155
122
  return undefined;
156
123
  }
124
+ const body = await response.json();
157
125
  if ("error" in body) {
158
126
  throw new Error(body.error);
159
127
  }
@@ -167,7 +135,7 @@ export async function updateEngine() {
167
135
  if (response.status === 202 && body.version !== undefined) {
168
136
  return { done: true, version: body.version, restart: body.restart === "app" ? "app" : "chat" };
169
137
  }
170
- return { done: false, error: body.error ?? t("It did not reach the game: try again."), ...(body.code === "busy" ? { code: body.code } : {}) };
138
+ return { done: false, error: refusalText(body, t("It did not reach the game: try again.")), ...(body.code === "busy" ? { code: body.code } : {}) };
171
139
  }
172
140
  catch {
173
141
  return { done: false, error: t("It did not reach the game: try again.") };
@@ -175,21 +143,11 @@ export async function updateEngine() {
175
143
  }
176
144
  /** The packages here, at once: without npm. */
177
145
  export async function readPackages() {
178
- const response = await fetch("/api/packages");
179
- const body = await response.json();
180
- if ("error" in body) {
181
- throw new Error(body.error);
182
- }
183
- return body;
146
+ return await readJson("/api/packages");
184
147
  }
185
148
  /** The widgets of the campaign's extensions (D-502), each where it stands and with what it shows now. */
186
149
  export async function readWidgets() {
187
- const response = await fetch("/api/widgets");
188
- const body = await response.json();
189
- if ("error" in body) {
190
- throw new Error(body.error);
191
- }
192
- return body.widgets;
150
+ return (await readJson("/api/widgets")).widgets;
193
151
  }
194
152
  /** What a package's widget shows for a card or a page of its page code, for who (D-514): nothing when the package or the widget is not the campaign's. */
195
153
  export async function readWidgetData(owner, widget, who) {
@@ -203,30 +161,15 @@ export async function readWidgetData(owner, widget, who) {
203
161
  }
204
162
  /** The theme of the campaign's game system (D-528): its CSS, icons and name; nothing when it names none, or refused when it does not pass its checks. */
205
163
  export async function readGameTheme() {
206
- const response = await fetch("/api/theme");
207
- const body = await response.json();
208
- if ("error" in body) {
209
- throw new Error(body.error);
210
- }
211
- return body;
164
+ return await readJson("/api/theme");
212
165
  }
213
166
  /** The page modules of the campaign's system and extensions whose code runs (D-510, D-511), the system's first. */
214
167
  export async function readModules() {
215
- const response = await fetch("/api/modules");
216
- const body = await response.json();
217
- if ("error" in body) {
218
- throw new Error(body.error);
219
- }
220
- return body.modules;
168
+ return (await readJson("/api/modules")).modules;
221
169
  }
222
170
  /** The catalog (D-486), as the server keeps it for ten minutes; `fresh` asks npm and GitHub again. */
223
171
  export async function readCatalog(fresh) {
224
- const response = await fetch(fresh ? "/api/catalog?fresh=true" : "/api/catalog");
225
- const body = await response.json();
226
- if ("error" in body) {
227
- throw new Error(body.error);
228
- }
229
- return body;
172
+ return await readJson(fresh ? "/api/catalog?fresh=true" : "/api/catalog");
230
173
  }
231
174
  /** Adds what the player wrote (D-485 (1)): a link, a GitHub repository's too, an npm name or a folder of this computer; the engine tells its kind. */
232
175
  export async function addSource(source) {
@@ -247,7 +190,8 @@ async function packageWork(send) {
247
190
  if (response.status === 202) {
248
191
  return { done: true, ...(body.kind === undefined ? {} : { kind: body.kind }) };
249
192
  }
250
- return { done: false, error: body.error ?? t("It did not reach the game: try again."), ...(body.code === undefined ? {} : { code: body.code }) };
193
+ const code = body.code === "declined" || body.code === "no-window" || body.code === "busy" ? body.code : undefined;
194
+ return { done: false, error: refusalText(body, t("It did not reach the game: try again.")), ...(code === undefined ? {} : { code }) };
251
195
  }
252
196
  catch {
253
197
  return { done: false, error: t("It did not reach the game: try again.") };
@@ -255,12 +199,7 @@ async function packageWork(send) {
255
199
  }
256
200
  /** This computer's library, with what this campaign uses, at once. */
257
201
  export async function readLibrary() {
258
- const response = await fetch("/api/library");
259
- const body = await response.json();
260
- if ("error" in body) {
261
- throw new Error(body.error);
262
- }
263
- return body;
202
+ return await readJson("/api/library");
264
203
  }
265
204
  /**
266
205
  * Turns a folder or a book of this computer on in the campaign's library, adding it to the computer first with the player's yes in a window; off; or takes it
@@ -274,7 +213,7 @@ export async function exportCampaign(credits) {
274
213
  try {
275
214
  const response = await fetch("/api/export", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(credits) });
276
215
  const body = await response.json().catch(() => ({}));
277
- return body.file === undefined ? { error: body.error ?? t("It did not reach the game: try again.") } : { download: `/api/export?file=${encodeURIComponent(body.file)}`, file: body.file };
216
+ return body.file === undefined ? { error: refusalText(body, t("It did not reach the game: try again.")) } : { download: `/api/export?file=${encodeURIComponent(body.file)}`, file: body.file };
278
217
  }
279
218
  catch {
280
219
  return { error: t("It did not reach the game: try again.") };
@@ -384,3 +323,20 @@ export async function runCommand(command, input = {}) {
384
323
  }
385
324
  return body.text ?? "";
386
325
  }
326
+ /**
327
+ * What the server answers at an address, as JSON: it throws what the server says went wrong, or, when the game cannot be reached or answers no JSON, says so
328
+ * in the page's words rather than the browser's.
329
+ */
330
+ async function readJson(address) {
331
+ let body;
332
+ try {
333
+ body = await (await fetch(address)).json();
334
+ }
335
+ catch {
336
+ throw new Error(t("It did not reach the game: try again."));
337
+ }
338
+ if (typeof body === "object" && body !== null && "error" in body && typeof body.error === "string") {
339
+ throw new Error(body.error);
340
+ }
341
+ return body;
342
+ }
@@ -40,7 +40,7 @@ import { SetupView, useSetup } from "./setup.js";
40
40
  import { MemberSheet } from "./sheet.js";
41
41
  import { gameStyleChanged, takeSystemStyle } from "./system-style.js";
42
42
  import { PlayTable, tableBeside, TableTab, useTableAway } from "./table.js";
43
- import { browserLanguage, pageDirection, setLanguage, setSystemWords, t } from "./text.js";
43
+ import { browserLanguage, pageDirection, pageLocale, setLanguage, setSystemWords, t } from "./text.js";
44
44
  import { restoreTheme } from "./theme.js";
45
45
  import { SetupCorner, Top } from "./top.js";
46
46
  import { hasTurns, TurnsCard, turnWords } from "./turns.js";
@@ -176,7 +176,14 @@ function App() {
176
176
  const page = member === undefined ? undefined : await readView(member.name);
177
177
  // The page's words in the campaign's language (D-394), its file read once; its dates and screen readers follow the language too.
178
178
  const language = (overview.kind === "overview" || overview.kind === "none" ? overview.language : undefined) ?? browserLanguage();
179
+ // A reading a newer one overtook sets no language: the newer one's stays, with its words.
180
+ if (number !== reading.current) {
181
+ return;
182
+ }
179
183
  await setLanguage(language);
184
+ if (number !== reading.current) {
185
+ return;
186
+ }
180
187
  setSystemWords(overview.kind === "overview" ? overview.words : undefined);
181
188
  setSystemVerbs(overview.kind === "overview" ? overview.verbs : undefined);
182
189
  if (number === reading.current) {
@@ -582,7 +589,7 @@ function App() {
582
589
  const notices = [
583
590
  ...(shown.problem === undefined ? [] : [{ kind: "problem", text: shown.problem }]),
584
591
  ...(!live && shown.readAt !== undefined
585
- ? [{ kind: "away", text: t("Not connected: the sheet as of {time}. It comes back when the game does.", { time: shown.readAt.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) }) }]
592
+ ? [{ kind: "away", text: t("Not connected: the sheet as of {time}. It comes back when the game does.", { time: shown.readAt.toLocaleTimeString(pageLocale(), { hour: "2-digit", minute: "2-digit" }) }) }]
586
593
  : []),
587
594
  ...(shown.noCharacter && !inSetup ? [{ kind: "info", text: t("There is no player character yet: the sheet comes when the master writes one.") }] : []),
588
595
  ...gameNotices(shown.problems),
@@ -607,7 +614,7 @@ function App() {
607
614
  return taken;
608
615
  } }, shown.asked.id)), live && shown.pack === undefined && shown.asked && shown.asked.spend === undefined && !inCard(shown.asked) && (_jsx(AskedBanner, { asked: shown.asked, yourTurn: yourTurn && (asker === undefined || asker.name === turnOf?.name), who: asker, turnName: turnName, map: shown.place?.map, place: shown.place?.name, answered: answering === shown.asked.id, onAnswered: () => void read() })), inSetup
609
616
  ? _jsx(SetupView, { setup: setup })
610
- : (_jsxs(_Fragment, { children: [live && yourTurn && address.section !== "scene" && shown.asked === undefined && shown.pack === undefined && (_jsxs("a", { class: "turn-notice", href: sectionAddress("scene"), children: [_jsx(Icon, { name: "combat" }), _jsx("span", { children: [turnWords(turnName), shown.openScene?.round === undefined ? "" : t("Round {round}", { round: shown.openScene.round })].filter((part) => part !== "").join(" · ") }), _jsx("span", { class: "turn-notice-go", children: t("Go to the scene") })] })), _jsx(Notices, { notices: importing }), !table && _jsx(QuestEndings, { version: shown.version, campaign: shown.campaign }), address.section === "party" && _jsx(PartyStrip, { party: shown.party, chosen: shown.chosen, scene: shown.openScene }), _jsxs("div", { class: "body", children: [_jsxs("main", { children: [address.section === "about" && _jsx(About, { product: productName, system: shown.system }), address.section === "help" && _jsx(Help, {}), !table && address.section === "scene" && _jsx(FollowedQuests, { version: shown.version, campaign: shown.campaign }), address.section === "scene" && (_jsx(SceneView, { place: shown.place, scene: shown.openScene, actor: actor, foreground: shown.foreground, several: several, party: shown.party, turnsBeside: table, onShowCard: (name) => {
617
+ : (_jsxs(_Fragment, { children: [live && yourTurn && address.section !== "scene" && shown.asked === undefined && shown.pack === undefined && (_jsxs("a", { class: "turn-notice", href: sectionAddress("scene"), children: [_jsx(Icon, { name: "combat" }), _jsxs("span", { children: [turnWords(turnName), shown.openScene?.round !== undefined && _jsx("span", { class: "turn-notice-round", children: ` · ${t("Round {round}", { round: shown.openScene.round })}` })] }), _jsx("span", { class: "turn-notice-go", children: t("Go to the scene") })] })), _jsx(Notices, { notices: importing }), !table && _jsx(QuestEndings, { version: shown.version, campaign: shown.campaign }), address.section === "party" && _jsx(PartyStrip, { party: shown.party, chosen: shown.chosen, scene: shown.openScene }), _jsxs("div", { class: "body", children: [_jsxs("main", { children: [address.section === "about" && _jsx(About, { product: productName, system: shown.system }), address.section === "help" && _jsx(Help, {}), !table && address.section === "scene" && _jsx(FollowedQuests, { version: shown.version, campaign: shown.campaign }), address.section === "scene" && (_jsx(SceneView, { place: shown.place, scene: shown.openScene, actor: actor, foreground: shown.foreground, several: several, party: shown.party, turnsBeside: table, onShowCard: (name) => {
611
618
  handed.current = { who: name, turn: turnKey(shown.openScene) };
612
619
  void read();
613
620
  }, own: {
@@ -297,8 +297,11 @@ export function AskedBanner({ asked, yourTurn, who, turnName, map, place, answer
297
297
  setPicking(false);
298
298
  setProblem(undefined);
299
299
  try {
300
- // A click that comes too late counts for nothing: the page reads what the master asks now.
301
- await answer(asked.id, given);
300
+ // A click that comes too late counts for nothing: the page reads what the master asks now. One the game refuses can be given again.
301
+ if (!await answer(asked.id, given)) {
302
+ setSent(undefined);
303
+ setProblem(t("The answer did not reach the game: try again."));
304
+ }
302
305
  }
303
306
  catch {
304
307
  setSent(undefined);
@@ -332,7 +335,7 @@ export function AskedBanner({ asked, yourTurn, who, turnName, map, place, answer
332
335
  const shown = asked.labels.map((label, index) => answerButton(label, index, !roomy)).filter((button) => button !== null);
333
336
  return (_jsxs("section", { ref: banner, class: classes, "aria-label": t("What the master asks"), children: [who === undefined ? _jsx("img", { class: "asked-robot", src: "/assets/favicon.svg", alt: "" }) : _jsx(AskedWho, { member: who }), _jsxs("p", { class: "asked-bar-question", children: [who !== undefined && (_jsxs(_Fragment, { children: [_jsx("b", { class: "asked-bar-name", children: who.name }), " · "] })), asked.question] }), shown.length > 0 && _jsx("div", { class: "asked-buttons", children: shown }), toggle] }));
334
337
  }
335
- return (_jsxs("section", { ref: banner, class: classes, "aria-labelledby": `asked-${asked.id}`, children: [toggle, who === undefined ? _jsx("img", { class: "asked-robot", src: "/assets/favicon.svg", alt: "" }) : _jsx(AskedWho, { member: who }), _jsxs("div", { class: "asked-body", children: [yourTurn ? _jsx("p", { class: "eyebrow asked-turn", children: turnWords(who?.name ?? turnName) }) : who !== undefined && _jsx("p", { class: "eyebrow asked-turn", children: t("For {name}", { name: who.name }) }), _jsx("h2", { class: "asked-title", children: asked.title }), _jsxs("p", { id: `asked-${asked.id}`, class: "asked-question", role: "alert", children: [who !== undefined && _jsx("span", { class: "visually-hidden", children: `${who.name}: ` }), asked.question] }), named.length > 0 && byHand && (_jsxs("p", { class: "asked-hand-note", children: [_jsx(Icon, { name: "hand" }), _jsx("span", { children: tParts("Roll {checks} yourself, on {sheet} or with the dice.", {
338
+ return (_jsxs("section", { ref: banner, class: classes, "aria-labelledby": `asked-${asked.id}`, children: [toggle, who === undefined ? _jsx("img", { class: "asked-robot", src: "/assets/favicon.svg", alt: "" }) : _jsx(AskedWho, { member: who }), _jsxs("div", { class: "asked-body", children: [yourTurn ? _jsx("p", { class: "eyebrow asked-turn", children: turnWords(who?.name ?? turnName) }) : who !== undefined && _jsx("p", { class: "eyebrow asked-turn", children: t("For {name}", { name: who.name }) }), _jsx("h2", { class: "asked-title", children: asked.title }), _jsxs("p", { id: `asked-${asked.id}`, class: "asked-question", dir: "auto", role: "alert", children: [who !== undefined && _jsx("span", { class: "visually-hidden", children: `${who.name}: ` }), asked.question] }), named.length > 0 && byHand && (_jsxs("p", { class: "asked-hand-note", children: [_jsx(Icon, { name: "hand" }), _jsx("span", { children: tParts("Roll {checks} yourself, on {sheet} or with the dice.", {
336
339
  checks: named.map((check, index) => (_jsxs(Fragment, { children: [index > 0 && (index === named.length - 1 ? ` ${t("or")} ` : ", "), _jsxs("a", { class: "asked-hand-check", href: sheetAddress(asked.who ?? ""), onClick: () => showRow(asked.fields?.[asked.labels.findIndex((label) => checkOf(label, asked.title)?.check === check.check)]), children: [_jsx(NotationIcons, { notation: check.dice }), check.check] })] }, check.check))),
337
340
  sheet: _jsx("a", { href: sheetAddress(asked.who ?? ""), children: who === undefined ? t("your sheet") : t("{name}'s sheet", { name: who.name }) }),
338
341
  }).map((part, index) => _jsx(Fragment, { children: part }, index)) })] })), _jsxs("div", { class: "asked-buttons", children: [asked.square && map !== undefined && (_jsxs("button", { type: "button", class: sent === "square" ? "asked-check sent" : "asked-check", disabled: gone, onClick: () => setPicking(true), children: [_jsx(Icon, { name: "world" }), _jsx("span", { class: "asked-check-name", children: t("Choose on the map") })] })), asked.labels.map((label, index) => answerButton(label, index))] }), _jsxs("div", { class: "asked-foot", children: [_jsxs("form", { class: "asked-own", onSubmit: own, children: [_jsx("input", { type: "text", value: words, maxLength: mostWords, placeholder: t("Or write what you do…"), "aria-label": t("Or write what you do"), disabled: gone, onInput: (event) => setWords(event.currentTarget.value) }), _jsx("button", { type: "submit", class: "icon-button", "aria-label": t("Send"), "data-tip": t("Send"), disabled: gone || words.trim() === "", children: _jsx(Icon, { name: "send" }) })] }), roll && (_jsxs("label", { class: "asked-hand", children: [_jsx("input", { type: "checkbox", role: "switch", checked: byHand, onChange: (event) => setByHand(event.currentTarget.checked) }), _jsx(Icon, { name: "hand" }), t("By hand")] }))] }), problem && _jsx("p", { class: "asked-problem", role: "alert", children: problem })] }), picking && map !== undefined && _jsx(MapSheet, { map: map, place: place ?? "", question: asked.question, onPick: (square) => void reply({ square }), onClose: () => setPicking(false) })] }));
@@ -1,5 +1,4 @@
1
- <svg class="robot" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" role="img">
2
- <title>Robot game master</title>
1
+ <svg class="robot" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" aria-hidden="true">
3
2
  <g class="robot-head">
4
3
  <g class="robot-antenna" fill="#DCAA32"><rect x="409" y="47" width="14" height="117" rx="7"/><circle cx="416" cy="45" r="19"/></g>
5
4
  <g class="robot-ears" fill="#DCAA32"><rect x="74" y="154" width="64" height="91" rx="20"/><rect x="374" y="154" width="64" height="91" rx="20"/></g>
@@ -34,7 +34,7 @@ export function useMedia(query) {
34
34
  * says what a click does; a card that stays open has no chevron and does not close.
35
35
  */
36
36
  export function CardHeader({ icon, title, preview, note, open, onToggle, fixed }) {
37
- return (_jsxs("summary", { class: fixed ? "fixed" : undefined, onClick: fixed ? (event) => event.preventDefault() : onToggle, children: [_jsx("svg", { class: "card-icon", viewBox: "0 0 24 24", "aria-hidden": "true", children: _jsx("path", { d: icon }) }), title, !open && preview !== undefined && _jsx("span", { class: "preview", "aria-hidden": "true", children: preview }), note !== undefined && _jsx("span", { class: "card-head-note", children: note }), !fixed && (_jsx("span", { class: "chevron-tip tip-left", "aria-hidden": "true", "data-tip": open ? t("Close") : t("Open"), children: _jsx("svg", { class: "chevron", viewBox: "0 0 24 24", "aria-hidden": "true", children: _jsx("path", { d: chevronPath }) }) }))] }));
37
+ return (_jsxs("summary", { class: fixed ? "fixed" : undefined, onClick: fixed ? (event) => event.preventDefault() : onToggle, children: [_jsx("svg", { class: "card-icon", viewBox: "0 0 24 24", "aria-hidden": "true", children: _jsx("path", { d: icon }) }), title, !open && preview !== undefined && _jsx("span", { class: "preview", dir: "auto", "aria-hidden": "true", children: preview }), note !== undefined && _jsx("span", { class: "card-head-note", children: note }), !fixed && (_jsx("span", { class: "chevron-tip tip-left", "aria-hidden": "true", "data-tip": open ? t("Close") : t("Open"), children: _jsx("svg", { class: "chevron", viewBox: "0 0 24 24", "aria-hidden": "true", children: _jsx("path", { d: chevronPath }) }) }))] }));
38
38
  }
39
39
  /** The header of a card that is always open (D-419): the look of a card's header, its icon, its title, a note at its end, and its own buttons after it; no toggle. */
40
40
  export function CardHead({ icon, title, note, children }) {
@@ -7,7 +7,12 @@ import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
7
7
  import { coinKind, faceNormals } from "./models.js";
8
8
  /** Loads the dice's shapes and values, and the meshes of the edges given at once, the others when first asked. */
9
9
  export async function loadDice(edges) {
10
- const read = (file) => fetch(`/assets/dice/${file}`).then(async (response) => await response.json());
10
+ const read = (file) => fetch(`/assets/dice/${file}`).then(async (response) => {
11
+ if (!response.ok) {
12
+ throw new Error(`/assets/dice/${file} did not come (${response.status}).`);
13
+ }
14
+ return await response.json();
15
+ });
11
16
  const [dice, coin] = await Promise.all([read("dice.json"), read("coin.json")]);
12
17
  const data = { ...dice, [coinKind]: coin };
13
18
  const meshes = new Map();
@@ -47,7 +47,11 @@ const floorBounce = 0.25;
47
47
  let loading;
48
48
  /** Loads the physics, once: a throw needs it. */
49
49
  export function loadPhysics() {
50
- const loaded = loading ?? RAPIER.init();
50
+ // One that failed is tried again the next time.
51
+ const loaded = loading ?? RAPIER.init().catch((error) => {
52
+ loading = undefined;
53
+ throw error;
54
+ });
51
55
  loading = loaded;
52
56
  return loaded;
53
57
  }
@@ -102,7 +102,11 @@ export function DiceTray({ requested, sheetThrow, party, campaign, onLanded, onS
102
102
  /** The dice and their stage, loaded once; undefined when the browser cannot draw them, and then the plate comes alone. */
103
103
  const loadRoller = () => {
104
104
  const surface = canvas.current;
105
- roller.current ??= surface === null ? Promise.resolve(undefined) : import("./roller.js").then((module) => module.makeRoller(surface)).catch(() => undefined);
105
+ // A load that failed, as the game away for a moment, is tried again at the next throw.
106
+ roller.current ??= surface === null ? Promise.resolve(undefined) : import("./roller.js").then((module) => module.makeRoller(surface)).catch(() => {
107
+ roller.current = undefined;
108
+ return undefined;
109
+ });
106
110
  return roller.current;
107
111
  };
108
112
  /** Throws these dice, each landing on its value, then shows the plate, and fades it all after a while; the plate alone when the dice cannot be thrown. */
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
2
  // The page's foot, under a line across the whole page as the head's: our copyright, the code on GitHub and the package on npm, a heart to support the project,
3
3
  // and the game system with the credit its source asks for (PLAN, phase 2).
4
4
  import { Icon } from "./icons.js";
5
- import { systemTitleLabel } from "./labels.js";
5
+ import { systemNameLabel, systemTitleLabel } from "./labels.js";
6
6
  import { t } from "./text.js";
7
7
  /** Where the project lives, and how to support it. */
8
8
  export const footLinks = {
@@ -13,5 +13,5 @@ export const footLinks = {
13
13
  };
14
14
  /** The foot of the page: who made it and where it lives, how to support it, and the game system's credits. */
15
15
  export function PageFoot({ product, system }) {
16
- return (_jsxs("footer", { class: "page-foot", children: [_jsxs("p", { class: "foot-own", children: [_jsxs("span", { children: ["© 2026 ", _jsx("a", { href: footLinks.author, target: "_blank", rel: "noreferrer", children: "Stefano Caronia" }), ` · ${product}`] }), _jsx("a", { href: footLinks.github, target: "_blank", rel: "noreferrer", "aria-label": t("{product} on GitHub", { product }), "data-tip": "GitHub", children: _jsx(Icon, { name: "github" }) }), _jsx("a", { href: footLinks.npm, target: "_blank", rel: "noreferrer", "aria-label": t("{product} on npm", { product }), "data-tip": "npm", children: _jsx(Icon, { name: "npm" }) }), _jsxs("a", { class: "foot-support", href: footLinks.support, target: "_blank", rel: "noreferrer", children: [_jsx(Icon, { name: "heart" }), t("Support {product}", { product })] })] }), system && (_jsxs("p", { class: "foot-system", children: [_jsx("span", { children: `${system.name} · ${systemTitleLabel(system.title)}` }), system.attribution && (_jsxs("details", { children: [_jsx("summary", { children: t("Credits") }), _jsx("p", { children: system.attribution })] }))] }))] }));
16
+ return (_jsxs("footer", { class: "page-foot", children: [_jsxs("p", { class: "foot-own", children: [_jsxs("span", { children: ["© 2026 ", _jsx("a", { href: footLinks.author, target: "_blank", rel: "noreferrer", children: "Stefano Caronia" }), ` · ${product}`] }), _jsx("a", { href: footLinks.github, target: "_blank", rel: "noreferrer", "aria-label": t("{product} on GitHub", { product }), "data-tip": "GitHub", children: _jsx(Icon, { name: "github" }) }), _jsx("a", { href: footLinks.npm, target: "_blank", rel: "noreferrer", "aria-label": t("{product} on npm", { product }), "data-tip": "npm", children: _jsx(Icon, { name: "npm" }) }), _jsxs("a", { class: "foot-support", href: footLinks.support, target: "_blank", rel: "noreferrer", children: [_jsx(Icon, { name: "heart" }), t("Support {product}", { product })] })] }), system && (_jsxs("p", { class: "foot-system", children: [_jsx("span", { children: `${systemNameLabel(system.name)} · ${systemTitleLabel(system.title)}` }), system.attribution && (_jsxs("details", { children: [_jsx("summary", { children: t("Credits") }), _jsx("p", { children: system.attribution })] }))] }))] }));
17
17
  }