rpg-engine 0.4.0 → 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 (87) 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/change.d.ts +7 -0
  5. package/dist/commands/change.js +34 -8
  6. package/dist/commands/config.js +4 -2
  7. package/dist/commands/game-extension-list.js +12 -0
  8. package/dist/commands/game-extensions.d.ts +1 -1
  9. package/dist/commands/game-extensions.js +242 -17
  10. package/dist/commands/game-master-rolls.d.ts +2 -0
  11. package/dist/commands/game-master-rolls.js +2 -0
  12. package/dist/commands/game-system-code.d.ts +9 -1
  13. package/dist/commands/game-system-code.js +27 -11
  14. package/dist/commands/game-widgets.d.ts +6 -1
  15. package/dist/commands/game-widgets.js +52 -4
  16. package/dist/commands/game-world.d.ts +15 -3
  17. package/dist/commands/game-world.js +45 -14
  18. package/dist/commands/package.d.ts +7 -1
  19. package/dist/commands/package.js +17 -2
  20. package/dist/commands/roll.js +2 -2
  21. package/dist/commands/scene.d.ts +1 -1
  22. package/dist/commands/view.d.ts +4 -0
  23. package/dist/commands/view.js +5 -3
  24. package/dist/core/context.d.ts +19 -0
  25. package/dist/core/files.d.ts +2 -0
  26. package/dist/core/files.js +10 -1
  27. package/dist/core/registry.d.ts +2 -0
  28. package/dist/dashboard/api.js +11 -3
  29. package/dist/dashboard/app.js +88 -8
  30. package/dist/dashboard/ask-card.js +118 -0
  31. package/dist/dashboard/dice/tray.js +5 -3
  32. package/dist/dashboard/extension-widgets.js +35 -9
  33. package/dist/dashboard/faces.js +6 -4
  34. package/dist/dashboard/help.js +10 -3
  35. package/dist/dashboard/i18n/ar.json +10 -1
  36. package/dist/dashboard/i18n/cs.json +9 -0
  37. package/dist/dashboard/i18n/da.json +9 -0
  38. package/dist/dashboard/i18n/de.json +9 -0
  39. package/dist/dashboard/i18n/el.json +10 -1
  40. package/dist/dashboard/i18n/es.json +9 -0
  41. package/dist/dashboard/i18n/fi.json +9 -0
  42. package/dist/dashboard/i18n/fr.json +9 -0
  43. package/dist/dashboard/i18n/he.json +10 -1
  44. package/dist/dashboard/i18n/hi.json +10 -1
  45. package/dist/dashboard/i18n/hu.json +9 -0
  46. package/dist/dashboard/i18n/is.json +9 -0
  47. package/dist/dashboard/i18n/it.json +9 -0
  48. package/dist/dashboard/i18n/ja.json +10 -1
  49. package/dist/dashboard/i18n/ko.json +10 -1
  50. package/dist/dashboard/i18n/nb.json +9 -0
  51. package/dist/dashboard/i18n/nl.json +9 -0
  52. package/dist/dashboard/i18n/pl.json +9 -0
  53. package/dist/dashboard/i18n/pt.json +9 -0
  54. package/dist/dashboard/i18n/ro.json +9 -0
  55. package/dist/dashboard/i18n/ru.json +9 -0
  56. package/dist/dashboard/i18n/sv.json +9 -0
  57. package/dist/dashboard/i18n/tr.json +9 -0
  58. package/dist/dashboard/i18n/uk.json +9 -0
  59. package/dist/dashboard/i18n/zh.json +11 -2
  60. package/dist/dashboard/markdown.js +15 -4
  61. package/dist/dashboard/pack-card.js +92 -0
  62. package/dist/dashboard/packages.js +11 -4
  63. package/dist/dashboard/rolls.js +2 -2
  64. package/dist/dashboard/scene.js +21 -10
  65. package/dist/dashboard/style.css +524 -4
  66. package/dist/dashboard-server.js +57 -1
  67. package/dist/extensions/api.d.ts +148 -17
  68. package/dist/extensions/extension.d.ts +10 -3
  69. package/dist/extensions/extension.js +16 -3
  70. package/dist/extensions/index.d.ts +3 -3
  71. package/dist/extensions/index.js +2 -2
  72. package/dist/extensions/packages.d.ts +8 -0
  73. package/dist/extensions/packages.js +48 -1
  74. package/dist/extensions/words.d.ts +2 -1
  75. package/dist/extensions/words.js +5 -4
  76. package/dist/index.d.ts +1 -1
  77. package/dist/mcp-server.js +1 -1
  78. package/dist/pages/index.d.ts +1 -1
  79. package/dist/pages/index.js +1 -1
  80. package/dist/pages/standard-fields.d.ts +2 -0
  81. package/dist/pages/standard-fields.js +8 -1
  82. package/dist/systems/game-system.d.ts +14 -9
  83. package/dist/systems/game-system.js +29 -19
  84. package/dist/systems/index.d.ts +1 -1
  85. package/dist/testing.d.ts +61 -0
  86. package/dist/testing.js +162 -0
  87. package/package.json +7 -2
@@ -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. */
@@ -8,7 +8,7 @@ import { readCounter } from "../counters/index.js";
8
8
  import { askOracle, DiceError, rollDice, sha256 } from "../dice/index.js";
9
9
  import { declaredKind, findPage, pagesWithName, writePage } from "../pages/index.js";
10
10
  import { effectiveFields, effectsOf } from "./effect-layer.js";
11
- import { behindTheScreen, namesNoOne, ofTheParty, screenUp, sealHiddenRoll } from "./game-master-rolls.js";
11
+ import { behindTheScreen, namesNoOne, ofTheParty, screenNote, screenUp, sealHiddenRoll } from "./game-master-rolls.js";
12
12
  import { copyPage, readOpenScene } from "./game-scene.js";
13
13
  import { systemRolled } from "./game-system-code.js";
14
14
  import { rollPageTable } from "./game-tables.js";
@@ -114,7 +114,7 @@ export const roll = defineCommand({
114
114
  }
115
115
  const note = [output.kept, output.note].filter((line) => line !== undefined).map((line) => `\n${line}`).join("");
116
116
  if (output.hidden) {
117
- const screen = output.screened === true ? ". Behind the screen, as master-rolls says: tell only the outcome, in the story." : "";
117
+ const screen = output.screened === true ? `. ${screenNote}` : "";
118
118
  const stranger = output.stranger === true
119
119
  ? `\n${output.who} names no page nor copy in the scene: hidden as a stranger's. If ${output.who} is of the party, roll --reveal ${output.id}, and give who as their page's name.`
120
120
  : "";
@@ -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) {
@@ -8,7 +8,8 @@ import { ActSheet } from "./act-sheet.js";
8
8
  import { ActStrip } from "./act-strip.js";
9
9
  import { saidStates } from "./acts.js";
10
10
  import { readAddress, sectionAddress } from "./address.js";
11
- import { answer, readActs, readAsked, readView, readWidgets, sayAct, sendSeen, withdrawAct } from "./api.js";
11
+ import { answer, closeCard, readActs, readAsked, readView, readWidgets, sayAct, sendSeen, withdrawAct } from "./api.js";
12
+ import { AskCard } from "./ask-card.js";
12
13
  import { AskedBanner } from "./asked.js";
13
14
  import { useMedia } from "./card.js";
14
15
  import { DeathSaveCard } from "./death-save.js";
@@ -19,7 +20,9 @@ import { readFree, withFree, writeFree } from "./free-rolls.js";
19
20
  import { Help } from "./help.js";
20
21
  import { Icon } from "./icons.js";
21
22
  import { FollowedQuests, JournalView, QuestEndings } from "./journal.js";
23
+ import { checkOf } from "./labels.js";
22
24
  import { gameNotices, importNotices, Notices } from "./notices.js";
25
+ import { inCard, nextPackCard } from "./pack-card.js";
23
26
  import { PackagesPage } from "./packages.js";
24
27
  import { About } from "./pages.js";
25
28
  import { PartyStrip } from "./party.js";
@@ -101,6 +104,9 @@ function App() {
101
104
  // were when a reading of them fails, and an answer older than one shown left out.
102
105
  const [widgets, setWidgets] = useState([]);
103
106
  const widgetReading = useRef({ asked: 0, shown: 0 });
107
+ // The card of a package's question as last read, even while the dice that changed it fly; the attempts the player let go, with the question then (D-507).
108
+ const packNow = useRef();
109
+ const packsGone = useRef(new Map());
104
110
  // Reads view again for whom the address names, or the player character the master calls, and what the master asks; an answer that comes after a newer one
105
111
  // is left out.
106
112
  const read = async () => {
@@ -113,8 +119,8 @@ function App() {
113
119
  }
114
120
  }, () => undefined);
115
121
  try {
116
- const [first, told, actsNow] = await Promise.all([readView(undefined, rollsAsked.current), readAsked().catch(() => undefined), readActs().catch(() => undefined)]);
117
- const asked = told;
122
+ const [first, askedNow, actsNow] = await Promise.all([readView(undefined, rollsAsked.current), readAsked().catch(() => undefined), readActs().catch(() => undefined)]);
123
+ const asked = askedNow === undefined ? undefined : askedNow.asked ?? undefined;
118
124
  // With more than one player character, a question for one elsewhere puts them in the foreground: the place, the map and the squares are theirs (VIEW-12).
119
125
  const here = first.kind === "overview" && (first.place?.here ?? []).some((one) => one.name === asked?.who);
120
126
  const focus = first.kind === "overview" && first.foreground !== undefined && asked?.who !== first.foreground && !here ? playerNamed(first.party, asked?.who)?.name : undefined;
@@ -178,9 +184,11 @@ function App() {
178
184
  const shownCard = card?.roll !== undefined && card.outcome === undefined ? toldCard(card, party) : card;
179
185
  savingNow.current = shownCard;
180
186
  setSaving(shownCard);
181
- // So does a die of a rest the player spends, whose card shows it once it lands (D-492).
187
+ // So does a die of a rest the player spends, whose card shows it once it lands (D-492); and a roll from a package's card, its marks (D-507).
182
188
  const spent = asked?.spend?.rolls.some((roll) => roll.id === asking?.id) === true;
183
- if (asking !== undefined && ((card !== undefined && card.roll === undefined) || spent) && holding.current === undefined) {
189
+ const packRolled = packNow.current?.sent !== undefined;
190
+ const pack = askedNow === undefined ? packNow.current : packOf(askedNow);
191
+ if (asking !== undefined && ((card !== undefined && card.roll === undefined) || spent || packRolled) && holding.current === undefined) {
184
192
  holding.current = { roll: asking, timer: window.setTimeout(() => land(asking.id), longestHold) };
185
193
  }
186
194
  setShown((before) => withHeld(before, {
@@ -203,6 +211,7 @@ function App() {
203
211
  place: overview.kind === "overview" ? overview.place : undefined,
204
212
  openScene: overview.kind === "overview" ? overview.openScene : undefined,
205
213
  asked,
214
+ pack,
206
215
  version: before.version + 1,
207
216
  readAt: new Date(),
208
217
  noCharacter: overview.kind === "none",
@@ -217,6 +226,75 @@ function App() {
217
226
  }
218
227
  }
219
228
  };
229
+ // The card of a package's question after a reading (D-507): an attempt asked again is no longer let go; one whose card went unanswered is.
230
+ const packOf = (told) => {
231
+ const key = told.asked?.card?.key;
232
+ if (key !== undefined && packsGone.current.has(key) && packsGone.current.get(key) !== told.asked?.id) {
233
+ packsGone.current.delete(key);
234
+ }
235
+ const next = nextPackCard(packNow.current, told, packsGone.current);
236
+ if (next.let !== undefined) {
237
+ packsGone.current.set(next.let, undefined);
238
+ }
239
+ packNow.current = next.card;
240
+ return next.card;
241
+ };
242
+ // The card shown, and as last read, the same: pressed, closed.
243
+ const setPack = (pack) => {
244
+ packNow.current = pack;
245
+ setShown((before) => ({ ...before, pack, ...(before.pending === undefined ? {} : { pending: { ...before.pending, pack } }) }));
246
+ };
247
+ // A button of a package's card (D-507): the card waits with it pressed while the answer goes; the core's change of mind takes the card away with it.
248
+ const answerPack = async (index) => {
249
+ const card = packNow.current;
250
+ const asked = card?.asked;
251
+ if (card === undefined || asked === undefined || card.ended === true || card.sent !== undefined) {
252
+ return;
253
+ }
254
+ const leaves = checkOf(asked.labels[index] ?? "", asked.title) === undefined && (asked.buttons?.[index] ?? undefined) === undefined;
255
+ if (leaves) {
256
+ packsGone.current.set(card.key, asked.id);
257
+ }
258
+ setPack(leaves ? undefined : { ...card, sent: index });
259
+ try {
260
+ await answer(asked.id, index);
261
+ }
262
+ catch {
263
+ packsGone.current.delete(card.key);
264
+ setPack({ ...card, sent: undefined });
265
+ }
266
+ void read();
267
+ };
268
+ // The player's own words in place of a button (ASK-10): taken, the card goes with its question, as the master hears them.
269
+ const sayPack = async (text, focused) => {
270
+ const card = packNow.current;
271
+ const asked = card?.asked;
272
+ if (card === undefined || asked === undefined || card.ended === true || card.sent !== undefined) {
273
+ return false;
274
+ }
275
+ const taken = await answer(asked.id, text).catch(() => false);
276
+ if (taken) {
277
+ packsGone.current.set(card.key, asked.id);
278
+ setPack(undefined);
279
+ if (focused) {
280
+ focusAfterCard();
281
+ }
282
+ }
283
+ void read();
284
+ return taken;
285
+ };
286
+ const closePack = (focused) => {
287
+ const key = packNow.current?.key;
288
+ if (key !== undefined) {
289
+ packsGone.current.set(key, undefined);
290
+ // Closed for the server too: no reading, here or on another page, brings it back.
291
+ void closeCard(key);
292
+ }
293
+ setPack(undefined);
294
+ if (focused) {
295
+ focusAfterCard();
296
+ }
297
+ };
220
298
  // The death save's dice, or a rest's die, have landed: its outcome on the card, and the sheet as the roll left it (D-461, D-492).
221
299
  const land = (roll) => {
222
300
  const held = holding.current;
@@ -346,7 +424,8 @@ function App() {
346
424
  void read();
347
425
  return taken;
348
426
  };
349
- const requested = live ? requestedOf(answering === shown.asked?.id ? undefined : shown.asked, (index) => void answerFrom(index)) : undefined;
427
+ // A package's question is answered from its card alone (D-507).
428
+ const requested = live ? requestedOf(answering === shown.asked?.id || inCard(shown.asked) ? undefined : shown.asked, (index) => void answerFrom(index)) : undefined;
350
429
  // The open scene goes by turns, as a fight, and whether the turn is a player character's (D-314, D-315, D-444); whose, by name, when there are more.
351
430
  const fight = hasTurns(shown.openScene);
352
431
  const turnOf = fight ? playerNamed(shown.party, shown.openScene?.turn) : undefined;
@@ -456,13 +535,13 @@ function App() {
456
535
  setFree([]);
457
536
  writeFree(shown.campaign, []);
458
537
  } }, shown.campaign));
459
- return (_jsx(RequestedRoll.Provider, { value: requested, children: _jsx(WidgetsContext.Provider, { value: widgets, children: _jsx(PlayerActsContext.Provider, { value: playerActs, children: _jsxs("div", { class: live ? "page" : "page stale", children: [!inSetup && (_jsx(Top, { campaign: shown.campaign, product: productName, system: shown.system?.name, now: shown.now, calendar: shown.calendar, path: shown.place === undefined ? undefined : [...shown.place.within, shown.place.name], live: live, mood: shown.masterMood, moment: moment, asleep: !live && shown.readAt !== undefined, section: address.section, fight: fight, yourTurn: yourTurn, turnName: turnName })), inSetup && _jsx(SetupCorner, { live: live }), _jsx(Notices, { notices: notices }), live && saving !== undefined && (_jsx(DeathSaveCard, { asked: saving.asked, save: saving.save, member: dying, name: several ? dying?.name : undefined, roll: saving.roll, outcome: saving.outcome, rolling: saving.sent === true || answering === saving.asked.id || shown.asked?.id !== saving.asked.id, onRoll: () => void rollSave(), onClose: closeSave }, saving.asked.id)), live && saving === undefined && shown.asked?.spend !== undefined && (_jsx(SpendCard, { asked: shown.asked, spend: shown.asked.spend, member: shown.party.find((candidate) => candidate.name === shown.asked?.spend?.who), flying: holding.current?.roll.id, onSpend: (field) => answerSpend(shown.asked?.id, { spend: field }), onDone: async (focused) => {
538
+ return (_jsx(RequestedRoll.Provider, { value: requested, children: _jsx(WidgetsContext.Provider, { value: shown.pack === undefined ? widgets : widgets.filter((widget) => widget.id !== shown.pack?.widget), children: _jsx(PlayerActsContext.Provider, { value: playerActs, children: _jsxs("div", { class: live ? "page" : "page stale", children: [!inSetup && (_jsx(Top, { campaign: shown.campaign, product: productName, system: shown.system?.name, now: shown.now, calendar: shown.calendar, path: shown.place === undefined ? undefined : [...shown.place.within, shown.place.name], live: live, mood: shown.masterMood, moment: moment, asleep: !live && shown.readAt !== undefined, section: address.section, fight: fight, yourTurn: yourTurn, turnName: turnName })), inSetup && _jsx(SetupCorner, { live: live }), _jsx(Notices, { notices: notices }), live && saving !== undefined && (_jsx(DeathSaveCard, { asked: saving.asked, save: saving.save, member: dying, name: several ? dying?.name : undefined, roll: saving.roll, outcome: saving.outcome, rolling: saving.sent === true || answering === saving.asked.id || shown.asked?.id !== saving.asked.id, onRoll: () => void rollSave(), onClose: closeSave }, saving.asked.id)), live && saving === undefined && shown.asked?.spend !== undefined && (_jsx(SpendCard, { asked: shown.asked, spend: shown.asked.spend, member: shown.party.find((candidate) => candidate.name === shown.asked?.spend?.who), flying: holding.current?.roll.id, onSpend: (field) => answerSpend(shown.asked?.id, { spend: field }), onDone: async (focused) => {
460
539
  const taken = await answerSpend(shown.asked?.id, 0);
461
540
  if (taken && focused) {
462
541
  focusAfterCard();
463
542
  }
464
543
  return taken;
465
- } }, shown.asked.id)), live && saving === undefined && shown.asked && shown.asked.spend === undefined && (_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
544
+ } }, shown.asked.id)), live && saving === undefined && shown.pack !== undefined && (_jsx(AskCard, { card: shown.pack, name: several ? playerNamed(shown.party, shown.pack.asked?.who)?.name ?? turnName : undefined, title: widgets.find((widget) => widget.id === shown.pack?.widget)?.title, onAnswer: (index) => void answerPack(index), onWords: sayPack, onClose: closePack }, shown.pack.key)), live && saving === undefined && 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
466
545
  ? _jsx(SetupView, { setup: setup })
467
546
  : (_jsxs(_Fragment, { children: [live && yourTurn && address.section !== "scene" && shown.asked === undefined && saving === 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) => {
468
547
  handed.current = { who: name, turn: turnKey(shown.openScene) };
@@ -530,6 +609,7 @@ function withHeld(before, next, hold) {
530
609
  knownBy: shown.knownBy,
531
610
  story: shown.story,
532
611
  openScene: shown.openScene,
612
+ pack: shown.pack,
533
613
  });
534
614
  return { ...next, ...steady(before), pending: steady(next) };
535
615
  }