rpg-engine 0.4.1 → 0.5.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 (80) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/ask.d.ts +37 -2
  3. package/dist/commands/ask.js +46 -17
  4. package/dist/commands/config.js +4 -2
  5. package/dist/commands/game-extension-list.js +12 -0
  6. package/dist/commands/game-extensions.d.ts +1 -1
  7. package/dist/commands/game-extensions.js +242 -17
  8. package/dist/commands/game-system-code.d.ts +9 -1
  9. package/dist/commands/game-system-code.js +27 -11
  10. package/dist/commands/game-widgets.d.ts +6 -1
  11. package/dist/commands/game-widgets.js +52 -4
  12. package/dist/commands/game-world.d.ts +15 -3
  13. package/dist/commands/game-world.js +45 -14
  14. package/dist/commands/package.d.ts +7 -1
  15. package/dist/commands/package.js +17 -2
  16. package/dist/commands/scene.d.ts +1 -1
  17. package/dist/commands/view.d.ts +4 -0
  18. package/dist/commands/view.js +5 -3
  19. package/dist/core/context.d.ts +19 -0
  20. package/dist/core/files.d.ts +2 -0
  21. package/dist/core/files.js +10 -1
  22. package/dist/core/registry.d.ts +2 -0
  23. package/dist/dashboard/api.js +11 -3
  24. package/dist/dashboard/app.js +88 -8
  25. package/dist/dashboard/ask-card.js +118 -0
  26. package/dist/dashboard/dice/tray.js +5 -3
  27. package/dist/dashboard/extension-widgets.js +35 -9
  28. package/dist/dashboard/faces.js +6 -4
  29. package/dist/dashboard/help.js +10 -3
  30. package/dist/dashboard/i18n/ar.json +9 -0
  31. package/dist/dashboard/i18n/cs.json +9 -0
  32. package/dist/dashboard/i18n/da.json +9 -0
  33. package/dist/dashboard/i18n/de.json +9 -0
  34. package/dist/dashboard/i18n/el.json +9 -0
  35. package/dist/dashboard/i18n/es.json +9 -0
  36. package/dist/dashboard/i18n/fi.json +9 -0
  37. package/dist/dashboard/i18n/fr.json +9 -0
  38. package/dist/dashboard/i18n/he.json +9 -0
  39. package/dist/dashboard/i18n/hi.json +9 -0
  40. package/dist/dashboard/i18n/hu.json +9 -0
  41. package/dist/dashboard/i18n/is.json +9 -0
  42. package/dist/dashboard/i18n/it.json +9 -0
  43. package/dist/dashboard/i18n/ja.json +9 -0
  44. package/dist/dashboard/i18n/ko.json +9 -0
  45. package/dist/dashboard/i18n/nb.json +9 -0
  46. package/dist/dashboard/i18n/nl.json +9 -0
  47. package/dist/dashboard/i18n/pl.json +9 -0
  48. package/dist/dashboard/i18n/pt.json +9 -0
  49. package/dist/dashboard/i18n/ro.json +9 -0
  50. package/dist/dashboard/i18n/ru.json +9 -0
  51. package/dist/dashboard/i18n/sv.json +9 -0
  52. package/dist/dashboard/i18n/tr.json +9 -0
  53. package/dist/dashboard/i18n/uk.json +9 -0
  54. package/dist/dashboard/i18n/zh.json +9 -0
  55. package/dist/dashboard/pack-card.js +92 -0
  56. package/dist/dashboard/packages.js +11 -4
  57. package/dist/dashboard/rolls.js +2 -2
  58. package/dist/dashboard/style.css +521 -3
  59. package/dist/dashboard-server.js +57 -1
  60. package/dist/extensions/api.d.ts +148 -17
  61. package/dist/extensions/extension.d.ts +10 -3
  62. package/dist/extensions/extension.js +16 -3
  63. package/dist/extensions/index.d.ts +3 -3
  64. package/dist/extensions/index.js +2 -2
  65. package/dist/extensions/packages.d.ts +8 -0
  66. package/dist/extensions/packages.js +48 -1
  67. package/dist/extensions/words.d.ts +2 -1
  68. package/dist/extensions/words.js +5 -4
  69. package/dist/index.d.ts +1 -1
  70. package/dist/mcp-server.js +1 -1
  71. package/dist/pages/index.d.ts +1 -1
  72. package/dist/pages/index.js +1 -1
  73. package/dist/pages/standard-fields.d.ts +2 -0
  74. package/dist/pages/standard-fields.js +8 -1
  75. package/dist/systems/game-system.d.ts +14 -9
  76. package/dist/systems/game-system.js +29 -19
  77. package/dist/systems/index.d.ts +1 -1
  78. package/dist/testing.d.ts +61 -0
  79. package/dist/testing.js +162 -0
  80. package/package.json +7 -2
@@ -91,7 +91,13 @@ function reader(root, context) {
91
91
  function game(root, context) {
92
92
  return {
93
93
  ...reader(root, context),
94
- set: (name, values, why) => setNumbers(root, context, name, values, why),
94
+ set: (name, values, why) => {
95
+ const world = campaignWorld(root, context);
96
+ const page = uniquePage(world, name);
97
+ if (page !== undefined) {
98
+ setFields(root, context, world, page, values, why);
99
+ }
100
+ },
95
101
  addEffect: (name, effect, why) => addEffect(root, context, name, effect, why),
96
102
  endEffect: (name, effect, why) => endEffect(root, context, name, effect, why),
97
103
  roll: (notation, by) => {
@@ -107,7 +113,8 @@ function game(root, context) {
107
113
  },
108
114
  };
109
115
  }
110
- function systemPage(world, page) {
116
+ /** A page as a system's code reads it: in the party or not, the player's or not, its counters with what its effects give, its effects. */
117
+ export function systemPage(world, page) {
111
118
  const fields = effectiveFields(world, page);
112
119
  return {
113
120
  name: page.name,
@@ -125,24 +132,33 @@ function uniquePage(world, name) {
125
132
  const found = pagesWithName(world, name);
126
133
  return found.length === 1 ? found[0] : undefined;
127
134
  }
128
- /** Sets numbers on a page, a counter keeping its maximum, each with its line in the log. */
129
- function setNumbers(root, context, name, values, why) {
130
- const world = campaignWorld(root, context);
131
- const page = uniquePage(world, name);
132
- if (page === undefined || Object.keys(values).length === 0) {
135
+ /**
136
+ * Sets fields on a page, numbers or text, a counter only numbers, keeping its maximum, each with its line in the log, public when the page concerns the player:
137
+ * for a system's code and an extension's (D-505).
138
+ */
139
+ export function setFields(root, context, world, page, values, why) {
140
+ if (Object.keys(values).length === 0) {
133
141
  return;
134
142
  }
143
+ // A counter takes numbers alone: text in it would read as no counter at all.
144
+ const worded = Object.entries(values).find(([field, value]) => typeof value === "string" && valueNamed(world.system?.fields ?? {}, field) === "counter");
145
+ if (worded !== undefined) {
146
+ throw new Error(`${worded[0]} is a counter: give it a number, not ${worded[1]}. Nothing changed.`);
147
+ }
135
148
  const before = effectiveFields(world, page);
136
149
  const written = Object.fromEntries(Object.entries(values).map(([field, value]) => {
137
150
  const own = readCounter(valueNamed(page.fields, field));
138
- return [field, own?.max === undefined ? value : formatCounter({ ...own, value })];
151
+ return [field, typeof value !== "number" || own?.max === undefined ? value : formatCounter({ ...own, value })];
139
152
  }));
140
153
  writePage(world, page.name, undefined, { set: written });
141
154
  const visibility = concernsPlayer(world, page) ? "public" : "hidden";
142
155
  for (const [field, after] of Object.entries(written)) {
143
- const was = readCounter(valueNamed(before, field));
144
- const shown = was === undefined ? "0" : was.max === undefined ? String(was.value) : formatCounter(was);
145
- appendLogEntry(root, newDatedLogEntry(root, context, "counter-changed", visibility, { page: page.name, field, before: shown, after: String(after), why }));
156
+ const was = valueNamed(before, field);
157
+ const counter = readCounter(was);
158
+ const shown = was === undefined ? (typeof after === "number" ? "0" : "none") : counter === undefined ? String(was) : formatCounter(counter);
159
+ // A counter whose maximum the system works out, which the page does not write, reads with it after too.
160
+ const now = typeof after === "number" && counter?.max !== undefined ? formatCounter({ value: after, max: counter.max }) : after;
161
+ appendLogEntry(root, newDatedLogEntry(root, context, "counter-changed", visibility, { page: page.name, field, before: String(shown), after: String(now), why }));
146
162
  }
147
163
  }
148
164
  /** Adds an effect without end: the engine's notes on what it breaks of what one keeps; undefined when the page has it already. */
@@ -1,6 +1,6 @@
1
1
  import type { Context } from "../core/context.ts";
2
2
  import type { Problem } from "../core/problem.ts";
3
- import { type Widget, type WidgetPage, type WidgetPlace, type WidgetText, type WidgetValue } from "../extensions/index.ts";
3
+ import { type Extension, type Widget, type WidgetPage, type WidgetPlace, type WidgetText, type WidgetValue } from "../extensions/index.ts";
4
4
  /** Where a widget stands: a place of the dashboard, with its page for a card in one, and its order among the cards there; or off. */
5
5
  export interface WidgetSpot {
6
6
  place: WidgetPlace | "off";
@@ -64,3 +64,8 @@ export declare function campaignWidgetNames(root: string, context: Context): Rec
64
64
  * dashboard has. It throws what is wrong, and how to write it.
65
65
  */
66
66
  export declare function checkWidgetSpots(root: string, context: Context, entries: Record<string, unknown>): void;
67
+ /**
68
+ * What one widget of an extension shows now, for the card of a question (D-507): read as the dashboard reads it, in the campaign's language; nothing when its
69
+ * hook is not there, fails, gives what no part draws, or is late.
70
+ */
71
+ export declare function widgetCard(root: string, context: Context, extension: Extension, name: string, key: string): Promise<ShownContent | undefined>;
@@ -184,12 +184,25 @@ const textSchema = z.union([
184
184
  z.object({ text: text(240), values: z.record(z.string().regex(/^\w+$/), valueSchema).refine((values) => Object.keys(values).length <= 8, "at most 8 values") }).strict(),
185
185
  ]);
186
186
  const iconName = z.string().regex(/^[a-z][a-z0-9-]*$/);
187
+ const toneSchema = z.enum(["good", "bad"]);
187
188
  const partSchema = z.union([
188
- z.object({ lead: textSchema, icon: iconName.optional(), value: valueSchema.optional() }).strict(),
189
+ z.object({ lead: textSchema, icon: iconName.optional(), value: valueSchema.optional(), tone: toneSchema.optional() }).strict(),
189
190
  z.object({ text: textSchema }).strict(),
190
191
  z.object({ facts: z.array(textSchema).max(12) }).strict(),
191
192
  z.object({ values: z.array(z.object({ label: textSchema, value: valueSchema }).strict()).max(12) }).strict(),
192
- z.object({ track: z.object({ label: textSchema, value: z.int().min(0), max: z.int().min(1).max(100), look: z.enum(["pips", "bar"]).optional() }).strict() }).strict(),
193
+ z.object({
194
+ track: z.object({
195
+ label: textSchema,
196
+ value: z.int().min(0),
197
+ max: z.int().min(1).max(100),
198
+ look: z.enum(["pips", "bar", "steps"]).optional(),
199
+ held: z.int().min(0).optional(),
200
+ marked: z.int().min(0).optional(),
201
+ coming: z.int().min(0).optional(),
202
+ stage: z.enum(["start", "center", "end"]).optional(),
203
+ tone: toneSchema.optional(),
204
+ }).strict(),
205
+ }).strict(),
193
206
  z.object({ rows: z.array(z.object({ label: textSchema, value: valueSchema.optional(), note: textSchema.optional() }).strict()).max(24) }).strict(),
194
207
  z.object({ table: z.object({ head: z.array(textSchema).min(1).max(6), rows: z.array(z.array(valueSchema).max(6)).max(24) }).strict() }).strict(),
195
208
  z.object({ image: z.string().regex(/^[\w .-]+\.(png|jpe?g|webp|svg)$/i), alt: textSchema }).strict(),
@@ -230,7 +243,8 @@ function shownContent(extension, words, given) {
230
243
  parts: parts.map((part) => {
231
244
  if ("lead" in part) {
232
245
  const leadIcon = icon(part.icon);
233
- return { lead: said(part.lead), ...(leadIcon === undefined ? {} : { icon: leadIcon }), ...(part.value === undefined ? {} : { value: valueIn(part.value) }) };
246
+ const tone = part.tone === undefined ? {} : { tone: part.tone };
247
+ return { lead: said(part.lead), ...(leadIcon === undefined ? {} : { icon: leadIcon }), ...(part.value === undefined ? {} : { value: valueIn(part.value) }), ...tone };
234
248
  }
235
249
  if ("text" in part) {
236
250
  return { text: said(part.text) };
@@ -242,7 +256,7 @@ function shownContent(extension, words, given) {
242
256
  return { values: part.values.map((one) => ({ label: said(one.label), value: valueIn(one.value) })) };
243
257
  }
244
258
  if ("track" in part) {
245
- return { track: { ...part.track, label: said(part.track.label), value: Math.min(part.track.value, part.track.max) } };
259
+ return { track: shownTrack({ ...part.track, label: said(part.track.label) }) };
246
260
  }
247
261
  if ("rows" in part) {
248
262
  return {
@@ -261,6 +275,40 @@ function shownContent(extension, words, given) {
261
275
  }),
262
276
  };
263
277
  }
278
+ /** A count as the page draws it: the lit ones, then those held, marked and coming, each cut to what is left of its maximum. */
279
+ function shownTrack(track) {
280
+ let left = track.max;
281
+ const fit = (count) => {
282
+ const kept = count === undefined ? undefined : Math.min(count, left);
283
+ left -= kept ?? 0;
284
+ return kept;
285
+ };
286
+ const value = fit(track.value) ?? 0;
287
+ const [held, marked, coming] = [fit(track.held), fit(track.marked), fit(track.coming)];
288
+ return { ...track, value, ...(held === undefined ? {} : { held }), ...(marked === undefined ? {} : { marked }), ...(coming === undefined ? {} : { coming }) };
289
+ }
290
+ /**
291
+ * What one widget of an extension shows now, for the card of a question (D-507): read as the dashboard reads it, in the campaign's language; nothing when its
292
+ * hook is not there, fails, gives what no part draws, or is late.
293
+ */
294
+ export async function widgetCard(root, context, extension, name, key) {
295
+ try {
296
+ const hook = (await extensionCode(extension))?.widgets?.[name];
297
+ if (hook === undefined) {
298
+ return undefined;
299
+ }
300
+ let timer;
301
+ const late = new Promise((done) => {
302
+ timer = setTimeout(() => done("late"), hookTime).unref();
303
+ });
304
+ // Its own call for its key, never one at work for the column or another card.
305
+ const answer = await Promise.race([hookCall(root, extension, `${name}#${key}`, () => hook(gameViewOf(root, context, extension), { key })), late]).finally(() => clearTimeout(timer));
306
+ return answer === "late" || answer === undefined ? undefined : shownContent(extension, wordsOf(extension, readTextSetting(root, "language")).read, answer);
307
+ }
308
+ catch {
309
+ return undefined;
310
+ }
311
+ }
264
312
  /** A picture of the extension's images/, as the dashboard serves it at an address of the extension's own; it throws when the extension has none by that name. */
265
313
  function pictureOf(extension, name) {
266
314
  const file = findImage([extension.folder], name);
@@ -2,16 +2,28 @@ import { type CountedByGame } from "../campaign/index.ts";
2
2
  import type { Context } from "../core/context.ts";
3
3
  import type { Problem } from "../core/problem.ts";
4
4
  import { type PageType, type World } from "../pages/index.ts";
5
- import { type GameSystem, type SystemSetting, type SystemWords } from "../systems/index.ts";
5
+ import { type CampaignData, type GameSystem, type SystemLayer, type SystemSetting, type SystemWords } from "../systems/index.ts";
6
6
  /** The world of the campaign in `root`, with the pages of its game system when campaign.yaml names one that is installed (SYS-1, SYS-3). */
7
7
  export declare function campaignWorld(root: string, context: Context): World;
8
- /** The game system's words in the campaign's language (D-403): its own, else those translated on the fly on this computer (D-406). */
9
- export declare function systemWordsOf(system: GameSystem, language: string, context: Context): SystemWords | undefined;
8
+ /**
9
+ * The game system's words in the campaign's language (D-403): its own, else those translated on the fly on this computer (D-406); with the names of the
10
+ * fields the campaign's extensions add, from their words, layered as their additions are (CAM-2, D-505).
11
+ */
12
+ export declare function systemWordsOf(root: string, system: GameSystem, language: string, context: Context): SystemWords | undefined;
10
13
  /**
11
14
  * The installed game system that campaign.yaml names, with what the campaign adds to it (CAM-1, CAM-2): alone when the additions do not read (CAM-3). Undefined
12
15
  * when it names none, or one that is not installed (SYS-1).
13
16
  */
14
17
  export declare function campaignSystem(root: string, context: Context): GameSystem | undefined;
18
+ /** What the campaign's extensions add to its game system, in the order campaign.yaml lists them, then the campaign's own additions, which win (CAM-2). */
19
+ export declare function systemLayers(root: string, context: Context, campaign: CampaignData): SystemLayer[];
20
+ /** The layers over the campaign's system that it plays with, in order, and by name those left out because the system would not read with them (CAM-3). */
21
+ export declare function playedLayers(root: string, context: Context): {
22
+ kept: SystemLayer[];
23
+ refused: string[];
24
+ };
25
+ /** The name of an extension's layer of additions, as messages give it. */
26
+ export declare function extensionLayer(name: string): string;
15
27
  /** A setting the campaign's game system adds to the setup (DAT-10), by its name in any case; undefined when the system has none by that name. */
16
28
  export declare function systemSetting(root: string, context: Context, name: string): SystemSetting | undefined;
17
29
  /** The value campaign.yaml gives a setting of the system, when it is one the system has (DAT-10). */
@@ -2,6 +2,7 @@ import { join, resolve } from "node:path";
2
2
  import { campaignFileName, readCampaignData, readOneSetting, readTextSetting } from "../campaign/index.js";
3
3
  import { files, isInside } from "../core/store.js";
4
4
  import { comparableText } from "../core/text.js";
5
+ import { extensionWords } from "../extensions/index.js";
5
6
  import { languagePackFor, packSystemFolder } from "../languages/index.js";
6
7
  import { homeSystemWords } from "../page-words.js";
7
8
  import { loadWorld, searchSystemPages, worldFolderName } from "../pages/index.js";
@@ -24,12 +25,17 @@ export function campaignWorld(root, context) {
24
25
  });
25
26
  });
26
27
  }
27
- /** The game system's words in the campaign's language (D-403): its own, else those translated on the fly on this computer (D-406). */
28
- export function systemWordsOf(system, language, context) {
28
+ /**
29
+ * The game system's words in the campaign's language (D-403): its own, else those translated on the fly on this computer (D-406); with the names of the
30
+ * fields the campaign's extensions add, from their words, layered as their additions are (CAM-2, D-505).
31
+ */
32
+ export function systemWordsOf(root, system, language, context) {
29
33
  // A language package's words come first, then the system's own, then those translated on the fly (D-485 (3)).
30
34
  const pack = languagePackFor(context.extensionFolders ?? [], language);
31
35
  const packed = pack === undefined ? undefined : packSystemFolder(pack, system.name);
32
- return (packed === undefined ? undefined : systemWords(packed, language)) ?? systemWords(system.folder, language) ?? homeSystemWords(context.home, system, language);
36
+ const own = (packed === undefined ? undefined : systemWords(packed, language)) ?? systemWords(system.folder, language) ?? homeSystemWords(context.home, system, language);
37
+ const added = campaignExtensions(root, context).extensions.reduce((fields, extension) => ({ ...fields, ...extensionFieldWords(extension, language) }), {});
38
+ return Object.keys(added).length === 0 ? own : { ...(own ?? { groups: {}, words: {} }), fields: { ...own?.fields, ...added } };
33
39
  }
34
40
  /**
35
41
  * The installed game system that campaign.yaml names, with what the campaign adds to it (CAM-1, CAM-2): alone when the additions do not read (CAM-3). Undefined
@@ -39,19 +45,42 @@ export function campaignSystem(root, context) {
39
45
  return systemOf(root, context).system;
40
46
  }
41
47
  /**
42
- * The game system campaign.yaml names, with its additions or why they do not read, and as its settings have it (DAT-10), read once until campaign.yaml changes:
43
- * a call asks for it many times.
48
+ * The game system campaign.yaml names, with what its extensions and then the campaign add to it (CAM-2), and the layers left out with why (CAM-3), as its
49
+ * settings have it (DAT-10), read once until campaign.yaml changes: a call asks for it many times.
44
50
  */
45
51
  function systemOf(root, context) {
46
- // campaign.yaml, and the extensions' packages, whose parts it gives.
52
+ // campaign.yaml, and the extensions' packages, whose parts and additions it gives.
47
53
  return files().remember(`system ${resolve(root)}`, extensionSources(root, context), () => {
48
54
  const name = readTextSetting(root, "system");
49
- const found = name === undefined ? {} : findCampaignSystem(context.systemFolders, name, readCampaignData(root));
55
+ const found = name === undefined ? { refused: [] } : findCampaignSystem(context.systemFolders, name, systemLayers(root, context, readCampaignData(root)));
50
56
  // And the parts of the instructions of its extensions over its own (D-121).
51
57
  const played = found.system === undefined ? undefined : withSettings(found.system, (setting) => readTextSetting(root, setting));
52
58
  return played === undefined ? found : { ...found, system: { ...played, parts: layeredParts(played.parts, campaignExtensions(root, context).extensions) } };
53
59
  });
54
60
  }
61
+ /** What the campaign's extensions add to its game system, in the order campaign.yaml lists them, then the campaign's own additions, which win (CAM-2). */
62
+ export function systemLayers(root, context, campaign) {
63
+ const extensions = campaignExtensions(root, context).extensions.map((extension) => ({ from: extensionLayer(extension.name), data: extension.adds }));
64
+ return [...extensions, { from: campaignFileName, data: campaign }];
65
+ }
66
+ /** The layers over the campaign's system that it plays with, in order, and by name those left out because the system would not read with them (CAM-3). */
67
+ export function playedLayers(root, context) {
68
+ const refused = systemOf(root, context).refused.map((layer) => layer.from);
69
+ return { kept: systemLayers(root, context, readCampaignData(root)).filter((layer) => !refused.includes(layer.from)), refused };
70
+ }
71
+ /** The name of an extension's layer of additions, as messages give it. */
72
+ export function extensionLayer(name) {
73
+ return `the extension ${name}`;
74
+ }
75
+ /** The names an extension's words give the fields it adds; none when its words do not read, which validate names. */
76
+ function extensionFieldWords(extension, language) {
77
+ try {
78
+ return extensionWords(extension.folder, language)?.fields ?? {};
79
+ }
80
+ catch {
81
+ return {};
82
+ }
83
+ }
55
84
  /** A setting the campaign's game system adds to the setup (DAT-10), by its name in any case; undefined when the system has none by that name. */
56
85
  export function systemSetting(root, context, name) {
57
86
  return campaignSystem(root, context)?.settings.find((setting) => comparableText(setting.name) === comparableText(name.trim()));
@@ -107,13 +136,15 @@ export function systemOccasions(root, context) {
107
136
  export function systemProblems(root, context) {
108
137
  const name = readTextSetting(root, "system");
109
138
  const found = name === undefined ? undefined : systemOf(root, context);
110
- // What the campaign adds that does not read: the campaign plays with the system alone (CAM-3).
111
- if (found?.problem !== undefined) {
112
- return [{
113
- path: "campaign.yaml",
114
- message: `What campaign.yaml adds to the system ${name ?? ""} does not read, so the campaign plays with the system alone: ${found.problem}`,
115
- fix: "fix it first, with the config command or by hand: until then validate does not check what the system works out on the pages",
116
- }];
139
+ // What an extension or the campaign adds that does not read: the campaign plays without it (CAM-3).
140
+ if (found !== undefined && found.refused.length > 0) {
141
+ return found.refused.map(({ from, problem }) => ({
142
+ path: campaignFileName,
143
+ message: `What ${from} adds to the system ${name ?? ""} does not read, so the campaign plays without it: ${problem}`,
144
+ fix: from === campaignFileName
145
+ ? "fix it first, with the config command or by hand: until then validate does not check what the system works out on the pages"
146
+ : `install another version of it with package install ${from.replace(/^the extension /, "")}, or take it away with package remove`,
147
+ }));
117
148
  }
118
149
  if (name === undefined || found?.system !== undefined) {
119
150
  return [];
@@ -51,7 +51,7 @@ type PackageResult = {
51
51
  } | ({
52
52
  kind: "exported";
53
53
  } & AdventureExported);
54
- /** A package on this computer, as list gives it to the master and to the dashboard; broken when it does not read (D-442). */
54
+ /** A package on this computer, as list gives it to the master and to the dashboard; broken when it does not read (D-442); with where its problems are reported. */
55
55
  type Installed = {
56
56
  name: string;
57
57
  package: string;
@@ -60,10 +60,12 @@ type Installed = {
60
60
  about: string;
61
61
  verified: boolean;
62
62
  used: boolean;
63
+ issues?: string;
63
64
  } | {
64
65
  name: string;
65
66
  package: string;
66
67
  broken: string;
68
+ issues?: string;
67
69
  };
68
70
  /** The player's yes to a package not ours, not given (D-478): they said no or closed the question, or no window could be shown here. */
69
71
  export declare class YesRefused extends Error {
@@ -80,6 +82,8 @@ export interface InstalledSystem {
80
82
  used: boolean;
81
83
  /** Whether it brings code, which runs from the next start of the game's server. */
82
84
  code: boolean;
85
+ /** Where its problems are reported, as its package.json says: the engine's own for those shipped with it. */
86
+ issues?: string;
83
87
  }
84
88
  /** A language package on this computer (D-485 (3)), for every campaign: one for each language. */
85
89
  export interface InstalledLanguage {
@@ -88,6 +92,8 @@ export interface InstalledLanguage {
88
92
  package: string;
89
93
  version: string;
90
94
  verified: boolean;
95
+ /** Where its problems are reported, as its package.json says. */
96
+ issues?: string;
91
97
  }
92
98
  /** A package on npm for this rpg-engine, with the version installed here, if any, and whether it is newer (D-442). */
93
99
  interface Available {
@@ -7,7 +7,7 @@ import { defineCommand } from "../core/registry.js";
7
7
  import { files } from "../core/store.js";
8
8
  import { comparableText } from "../core/text.js";
9
9
  import { isNewerVersion } from "../core/version.js";
10
- import { extensionApi, findExtension, installedExtensions, isLocalSpec, isTarball, isVerified, readExtension, readsApi, shortName, verifiedScope } from "../extensions/index.js";
10
+ import { extensionApi, findExtension, installedExtensions, isLocalSpec, issuesPage, isTarball, isVerified, readExtension, readsApi, shortName, verifiedScope } from "../extensions/index.js";
11
11
  import { installedLanguages, languagePackProblems, readLanguagePack } from "../languages/index.js";
12
12
  import { installedSystems, systemFolders, systemHasCode } from "../systems/index.js";
13
13
  import { exportAdventure, installAdventure, installedAdventures, isAdventureSpec, readAdventureSpec, removeAdventure, storyTouching } from "./game-adventures.js";
@@ -136,6 +136,7 @@ export const packageCommand = defineCommand({
136
136
  function listed(root, context) {
137
137
  const used = Object.keys(listedExtensions(root));
138
138
  const here = installedExtensions(context.extensionFolders ?? []).map((found) => {
139
+ const issues = issuesOf(found.folder);
139
140
  try {
140
141
  const extension = readExtension(found.folder);
141
142
  return {
@@ -146,10 +147,11 @@ function listed(root, context) {
146
147
  about: extension.about,
147
148
  verified: isVerified(extension.package, extension.linked),
148
149
  used: used.includes(extension.package),
150
+ ...issues,
149
151
  };
150
152
  }
151
153
  catch (error) {
152
- return { name: shortName(found.package), package: found.package, broken: error instanceof Error ? error.message : String(error) };
154
+ return { name: shortName(found.package), package: found.package, broken: error instanceof Error ? error.message : String(error), ...issues };
153
155
  }
154
156
  });
155
157
  const adventures = installedAdventures(root).map((one) => ({ title: one.title, version: one.version, ...(one.since === undefined ? {} : { since: one.since }), removable: storyTouching(root, one) === undefined }));
@@ -313,9 +315,21 @@ function systemsHere(root, context) {
313
315
  verified: shipped || (manifest !== undefined && isVerified(manifest.name, linked)),
314
316
  used: comparableText(system.name) === comparableText(plays),
315
317
  code: systemHasCode(system.folder),
318
+ // The engine's own are reported where the engine is: its package.json is in the folder above its systems.
319
+ ...issuesOf(shipped ? join(context.systemFolders[0], "..") : system.folder),
316
320
  };
317
321
  });
318
322
  }
323
+ /** Where the package in this folder takes reports of its problems, as its package.json says; nothing when it says none or has none that reads. */
324
+ function issuesOf(folder) {
325
+ try {
326
+ const issues = issuesPage(JSON.parse(files().text(join(folder, "package.json")) ?? ""));
327
+ return issues === undefined ? {} : { issues };
328
+ }
329
+ catch {
330
+ return {};
331
+ }
332
+ }
319
333
  /** The name and the version a package.json in this folder gives; undefined when it has none that reads. */
320
334
  function packageOf(folder) {
321
335
  try {
@@ -378,6 +392,7 @@ function languagesHere(context) {
378
392
  package: pack.package,
379
393
  version: pack.version,
380
394
  verified: isVerified(pack.package, installedFromFolder(pack.folder)),
395
+ ...issuesOf(pack.folder),
381
396
  }));
382
397
  }
383
398
  /** The folder npm installed a package in, among the extensions' folders; undefined when it is not there. */
@@ -29,12 +29,12 @@ export declare const scene: import("../core/registry.ts").Command<z.ZodObject<{
29
29
  action: z.ZodEnum<{
30
30
  next: "next";
31
31
  open: "open";
32
+ hostile: "hostile";
32
33
  add: "add";
33
34
  close: "close";
34
35
  use: "use";
35
36
  order: "order";
36
37
  now: "now";
37
- hostile: "hostile";
38
38
  leave: "leave";
39
39
  calm: "calm";
40
40
  }>;
@@ -38,6 +38,10 @@ export interface ShownRoll {
38
38
  words?: NotationPart[];
39
39
  notation: string;
40
40
  total: number;
41
+ /** What the faces mean, in place of the total, when an extension's roll says it: 4 pins, no 1 (D-505). */
42
+ says?: string;
43
+ /** How each die turned out, by its face in order, when an extension's roll says it: good, bad or none (D-507). */
44
+ tones?: ("good" | "bad" | null)[];
41
45
  text: string;
42
46
  dice: ThrownDie[];
43
47
  }
@@ -187,7 +187,7 @@ export const view = defineCommand({
187
187
  return { kind: "map", ...shownMap(sight, measuresOf(root, system), readSettings(root).name) };
188
188
  }
189
189
  const language = readSettings(root).language;
190
- const memberWords = system === undefined || language === undefined ? undefined : systemWordsOf(system, language, context);
190
+ const memberWords = system === undefined || language === undefined ? undefined : systemWordsOf(root, system, language, context);
191
191
  // Where someone is, as far as the character knows the places: elsewhere when it knows none of them (D-254).
192
192
  const member = (page) => {
193
193
  const chain = locate(world, page).chain;
@@ -237,7 +237,7 @@ export const view = defineCommand({
237
237
  const openScene = shownScene(sight);
238
238
  const settings = readSettings(root);
239
239
  const today = now === undefined ? undefined : calendarDayOf(root, context, now.day);
240
- const words = system === undefined || settings.language === undefined ? undefined : systemWordsOf(system, settings.language, context);
240
+ const words = system === undefined || settings.language === undefined ? undefined : systemWordsOf(root, system, settings.language, context);
241
241
  return {
242
242
  kind: "overview",
243
243
  campaign: settings.name,
@@ -324,7 +324,7 @@ function shownPage(root, context, world, knowledge, page, party) {
324
324
  // A companion who keeps no sheet shows the stat block of the creature it derives from (D-275).
325
325
  const sheet = withItemImages(root, context, world, withCoins(speedInUnits(!party ? [] : hasSheet(world, page) ? sheetData(world, system, page) : statBlock(world, system, page), system, measuresOf(root, system)), campaignCoins(root, context).coins, system));
326
326
  const language = readSettings(root).language;
327
- const headline = party ? sheetHeadline(world, system, page, system === undefined || language === undefined ? undefined : systemWordsOf(system, language, context)) : undefined;
327
+ const headline = party ? sheetHeadline(world, system, page, system === undefined || language === undefined ? undefined : systemWordsOf(root, system, language, context)) : undefined;
328
328
  const cards = party && hasSheet(world, page) ? system?.sheetCards : undefined;
329
329
  // Only the player's own characters act from the sheet: the others act as the master says (D-495).
330
330
  const own = isPlayerCharacter(page) && (page === knowledge.pc || knowledge.each !== undefined);
@@ -452,6 +452,8 @@ function shownRoll(world, entry, named, picture, seen) {
452
452
  notation: String(data.notation ?? ""),
453
453
  ...(words === undefined ? {} : { words }),
454
454
  total: Number(data.total ?? 0),
455
+ ...(typeof data.says === "string" && data.says.trim() !== "" ? { says: data.says } : {}),
456
+ ...(Array.isArray(data.tones) ? { tones: data.tones.map((tone) => (tone === "good" || tone === "bad" ? tone : null)) } : {}),
455
457
  text: String(data.result ?? ""),
456
458
  dice: Array.isArray(data.dice) ? data.dice : [],
457
459
  };
@@ -225,6 +225,23 @@ export interface Rows {
225
225
  who: string;
226
226
  fields: (string | null)[];
227
227
  save?: SaveAsked;
228
+ /** By button, its name and the note under it when a package words it, as Reroll and 3 left (D-507). */
229
+ buttons?: ({
230
+ name: string;
231
+ note?: string;
232
+ } | null)[];
233
+ /** The rule under the buttons, in a line. */
234
+ rule?: string;
235
+ card?: CardAsked;
236
+ }
237
+ /**
238
+ * The card of a package's widget a question is asked in (D-507): the widget, by its extension's name and its own, as lockpicking.lock, and which attempt it is;
239
+ * what it shows, read when it is asked for, never in the way of the question.
240
+ */
241
+ export interface CardAsked {
242
+ widget: string;
243
+ key: string;
244
+ shows(): Promise<unknown>;
228
245
  }
229
246
  /** A death save the question asks (DIE-4, D-460): its die, the total that succeeds, its counters as they stand, and what the lowest and highest faces do. */
230
247
  export interface SaveAsked {
@@ -294,6 +311,8 @@ export interface Player {
294
311
  spendDice?(question: string, title: string, done: string, spending: Spending, signal?: AbortSignal): Promise<0 | undefined | "absent">;
295
312
  /** Whether a question waits for the player there now, as on the dashboard's page; a form does not say. */
296
313
  asking?(): boolean;
314
+ /** As the call whose questions were asked in a card ends: the card as it is after the last dice (D-507). */
315
+ cardEnded?(card: CardAsked): void;
297
316
  }
298
317
  export declare function defaultContext(folder?: string): Context;
299
318
  /** Where the engine installs the packages, with npm, on this computer (D-436): the player's local data, beside the programs it installs (D-425). */
@@ -7,6 +7,8 @@ export declare function filesIn(folder: string, keep: (name: string) => boolean)
7
7
  * installed from a folder (D-441); never followed further.
8
8
  */
9
9
  export declare function packageFoldersIn(folders: string[]): string[];
10
+ /** A path by the folders it really is in, through any link on the way, as Node resolves a module; as given when it is not there. */
11
+ export declare function realPath(path: string): string;
10
12
  /**
11
13
  * Whether a package of npm's folder came from a folder or a file of this computer, never from npm (D-441, D-452): npm's package.json names it as file:, or it
12
14
  * is a link to the folder. Such a package is never verified, whatever its name.
@@ -1,5 +1,5 @@
1
1
  // The files of a folder and of the folders inside it, listed one folder at a time: listing a whole tree at once looks at every file again on Windows (D-194).
2
- import { existsSync, lstatSync, readdirSync, readFileSync, statSync } from "node:fs";
2
+ import { existsSync, lstatSync, readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
3
3
  import { basename, join, relative, resolve, sep } from "node:path";
4
4
  /** The full paths of `folder` and of the folders inside it, however deep; none when there is no such folder. */
5
5
  export function foldersIn(folder) {
@@ -57,6 +57,15 @@ function chosenPackages(folder) {
57
57
  return undefined;
58
58
  }
59
59
  }
60
+ /** A path by the folders it really is in, through any link on the way, as Node resolves a module; as given when it is not there. */
61
+ export function realPath(path) {
62
+ try {
63
+ return realpathSync(path);
64
+ }
65
+ catch {
66
+ return path;
67
+ }
68
+ }
60
69
  /**
61
70
  * Whether a package of npm's folder came from a folder or a file of this computer, never from npm (D-441, D-452): npm's package.json names it as file:, or it
62
71
  * is a link to the folder. Such a package is never verified, whatever its name.
@@ -16,6 +16,8 @@ export interface Command<Schema extends z.ZodObject = z.ZodObject, Result = unkn
16
16
  positionals?: string[];
17
17
  /** The command asks the player directly: it exists only where the surface can (Context.player), never on the command line. */
18
18
  needsPlayer?: boolean;
19
+ /** The command may wait for the player's answer, as an extension's that asks (D-505): the MCP server reports so meanwhile, and it runs everywhere. */
20
+ waitsForPlayer?: boolean;
19
21
  /** The command may take minutes, as an installation: the MCP server reports its progress meanwhile, so that a host does not give up on it. */
20
22
  slow?: boolean;
21
23
  run(input: z.infer<Schema>, context: Context): Result | Promise<Result>;
@@ -247,11 +247,19 @@ async function sendChange(change) {
247
247
  return t("The change did not reach the game: try again.");
248
248
  }
249
249
  }
250
- /** What the master asks the player now; undefined when nothing. */
250
+ /** What the master asks the player now, null when nothing; with nothing, the card a package's last question left (D-507). */
251
251
  export async function readAsked() {
252
252
  const response = await fetch("/api/asked");
253
- const body = await response.json();
254
- return body.asked ?? undefined;
253
+ return await response.json();
254
+ }
255
+ /** Closes a package's card once told (D-507), for every page and every reading after; a server away keeps it, closed on this page alone. */
256
+ export async function closeCard(key) {
257
+ try {
258
+ await fetch("/api/card", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ close: key }) });
259
+ }
260
+ catch {
261
+ // Closed here; another page may still show it.
262
+ }
255
263
  }
256
264
  /** Tells the server whether this page is seen now (D-455); a page that cannot tell it is taken as seen. */
257
265
  export async function sendSeen(page, seen) {