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
package/README.md CHANGED
@@ -85,7 +85,7 @@ The code is under the [MIT](https://github.com/stefanocaronia/rpg-engine/blob/ma
85
85
 
86
86
  The 5e system, in `systems/5e/`, is under the Creative Commons Attribution 4.0 International License ([its license](https://github.com/stefanocaronia/rpg-engine/blob/main/systems/5e/LICENSE.md)): This work includes material taken from the System Reference Document 5.1 ("SRD 5.1") by Wizards of the Coast LLC and available at https://dnd.wizards.com/resources/systems-reference-document. The SRD 5.1 is licensed under the Creative Commons Attribution 4.0 International License available at https://creativecommons.org/licenses/by/4.0/legalcode. Its creatures' icons are from game-icons.net, under the Creative Commons Attribution 3.0 Unported License, by the authors its license names. rpg-engine is compatible with fifth edition.
87
87
 
88
- The weather extension, in `extensions/weather/` and published apart as `@rpgengine/weather`, is Weather by the climate score, by Stefano Caronia, CC BY 4.0, with its code under MIT ([its license](https://github.com/stefanocaronia/rpg-engine/blob/main/extensions/weather/LICENSE.md)).
88
+ Our extensions are packages of their own, installed only when a campaign wants them: [weather](https://github.com/stefanocaronia/rpg-engine-weather) (`@rpgengine/weather`), Weather by the climate score, and [lockpicking](https://github.com/stefanocaronia/rpg-engine-lockpicking) (`@rpgengine/lockpicking`), Lockpicking by complexity, both by Stefano Caronia under CC BY 4.0, with their code under MIT; each repo has its license.
89
89
 
90
90
  rpg-engine ships only original or open-licensed content: for fifth edition, the SRD 5.1 under CC BY 4.0. Anything else that appears in your game is written by your AI or by you, as pages of your campaign on your computer: it is not part of rpg-engine, and we do not distribute it.
91
91
 
@@ -1,16 +1,18 @@
1
1
  import { z } from "zod";
2
- import type { Context, Rows, Said } from "../core/context.ts";
2
+ import type { CardAsked, Context, Rows, Said } from "../core/context.ts";
3
3
  type InWords = {
4
4
  kind: "unanswered" | "unavailable" | "absent" | "physical" | "dice in words";
5
5
  asked: string;
6
6
  };
7
- type AskResult = {
7
+ /** What the player answered, or the question to ask them in words. */
8
+ export type AskResult = {
8
9
  kind: "roll";
9
10
  id: string;
10
11
  who: string;
11
12
  check: string;
12
13
  text: string;
13
14
  total: number;
15
+ faces: number[];
14
16
  notes?: string[];
15
17
  } | {
16
18
  kind: "changed";
@@ -36,6 +38,39 @@ export declare const ask: import("../core/registry.ts").Command<z.ZodObject<{
36
38
  square: z.ZodOptional<z.ZodBoolean>;
37
39
  recipe: z.ZodOptional<z.ZodString>;
38
40
  }, z.core.$strip>, AskResult>;
41
+ /**
42
+ * A roll of the player's character asked with buttons (ASK-3, ASK-8, ASK-12): for ask, and for an extension's code (D-505). With physical dice it is the question
43
+ * to ask in words; a call stopped logs nothing (ASK-9).
44
+ */
45
+ export declare function askedRoll(root: string, context: Context, question: string, checks: {
46
+ label: string;
47
+ notation?: string;
48
+ }[], given: string | undefined, told?: Told): Promise<AskResult>;
49
+ /** What an extension's roll asked tells in its own words (D-505): the button that turns it down, and what the faces mean, logged in place of the total. */
50
+ export interface Told {
51
+ /** The roll's button in place of the core's words, with a note under it. */
52
+ roll?: Button;
53
+ /** The button that turns it down, renamed; false for none, when the roll is forced (D-507). */
54
+ decline?: Button | false;
55
+ /** The rule under the buttons, in a line. */
56
+ rule?: string;
57
+ /** The card of a widget the page asks it in (D-507). */
58
+ card?: CardAsked;
59
+ says?: (faces: number[]) => string;
60
+ /** How each die turned out, by its face in order: kept in the roll's line only when there is one for each, good, bad or none. */
61
+ tones?: (faces: number[]) => unknown[];
62
+ }
63
+ /** A button's name, and the note under it. */
64
+ export interface Button {
65
+ name: string;
66
+ note?: string;
67
+ }
68
+ /** How the dice turned out, for the roll's line: one for each face, good, bad or none; nothing for any other list, which a package gave wrong. */
69
+ export declare function tonesOf(given: unknown[] | undefined, faces: number[]): {
70
+ tones?: ("good" | "bad" | null)[];
71
+ };
72
+ /** Whether a text is the dice of a check, as 1d20+5 or 1d20+athletics (ASK-2, ASK-12). */
73
+ export declare function isCheckDice(text: string): boolean;
39
74
  /**
40
75
  * The player's answer, on the dashboard's page and in the host's form at once, where both are (ASK-13, D-455): the first answer wins and takes the other
41
76
  * away; one that never showed, a page not open or a form the host does not show, leaves the other to answer. Neither shown is absent: the master asks in words.
@@ -75,7 +75,7 @@ export const ask = defineCommand({
75
75
  throw new Error("The player cannot be asked with buttons here: ask them in words, without a word about buttons, and stop.");
76
76
  }
77
77
  const question = input.question.trim();
78
- const words = buttonWords[(readSettings(root).language ?? "en").split("-")[0]] ?? buttonWords.en;
78
+ const words = buttonWordsOf(root);
79
79
  if (question === "") {
80
80
  throw new Error("Give the question: for a roll, what is at stake either way; for a choice, what the player chooses.");
81
81
  }
@@ -103,13 +103,7 @@ export const ask = defineCommand({
103
103
  if (checks.length < options.length) {
104
104
  throw new Error(`Give every check its dice, such as Atletica 1d20+5; for a choice, give only the answers, such as Sì and No. A roll already has its button to change one's mind (${words.change}): leave out an answer such as No.`);
105
105
  }
106
- const who = playerCharacter(loadWorld(root), input.who);
107
- const worked = sheetChecks(root, context, checks, who);
108
- // The player rolls their own dice: a roll is asked in words, and they tell the values (ASK-8).
109
- if (readSettings(root).dice === "physical") {
110
- return { kind: "physical", asked: askedText(question, "checks", worked) };
111
- }
112
- return rollChosen(root, context, question, worked, who, words);
106
+ return askedRoll(root, context, question, checks, input.who);
113
107
  },
114
108
  format(result) {
115
109
  switch (result.kind) {
@@ -140,18 +134,51 @@ export const ask = defineCommand({
140
134
  }
141
135
  },
142
136
  });
137
+ /**
138
+ * A roll of the player's character asked with buttons (ASK-3, ASK-8, ASK-12): for ask, and for an extension's code (D-505). With physical dice it is the question
139
+ * to ask in words; a call stopped logs nothing (ASK-9).
140
+ */
141
+ export async function askedRoll(root, context, question, checks, given, told = {}) {
142
+ const who = playerCharacter(loadWorld(root), given);
143
+ const worked = sheetChecks(root, context, checks, who);
144
+ // The player rolls their own dice: a roll is asked in words, and they tell the values (ASK-8).
145
+ if (readSettings(root).dice === "physical") {
146
+ return { kind: "physical", asked: askedText(question, "checks", worked) };
147
+ }
148
+ return rollChosen(root, context, question, worked, who, buttonWordsOf(root), told);
149
+ }
150
+ /** How the dice turned out, for the roll's line: one for each face, good, bad or none; nothing for any other list, which a package gave wrong. */
151
+ export function tonesOf(given, faces) {
152
+ const known = (tone) => tone === "good" || tone === "bad" || tone === undefined || tone === null;
153
+ return given === undefined || !Array.isArray(given) || given.length !== faces.length || !given.every(known) || given.every((tone) => tone === undefined || tone === null)
154
+ ? {}
155
+ : { tones: given.map((tone) => (tone === "good" || tone === "bad" ? tone : null)) };
156
+ }
157
+ /** Whether a text is the dice of a check, as 1d20+5 or 1d20+athletics (ASK-2, ASK-12). */
158
+ export function isCheckDice(text) {
159
+ return isDice(namesAsZero(text));
160
+ }
161
+ /** The words of the buttons in the campaign's language (ASK-7). */
162
+ function buttonWordsOf(root) {
163
+ return buttonWords[(readSettings(root).language ?? "en").split("-")[0]] ?? buttonWords.en;
164
+ }
143
165
  /**
144
166
  * The buttons of a roll: the checks and a change of mind (ASK-3, ASK-4); a death save, only its check, as no one turns it down (D-460). The chosen check is
145
167
  * rolled with the engine's dice and logged as the player's roll.
146
168
  */
147
- async function rollChosen(root, context, question, checks, who, words) {
169
+ async function rollChosen(root, context, question, checks, who, words, told = {}) {
148
170
  const system = campaignSystem(root, context);
149
171
  const save = systemAsking(root, context, { who, notations: checks.map((check) => check.notation ?? "") });
150
- const change = save === undefined ? [words.change] : [];
172
+ const decline = told.decline === false ? undefined : told.decline?.name ?? words.change;
173
+ const change = save === undefined && decline !== undefined ? [decline] : [];
151
174
  const labels = [...checks.map((check) => `${words.roll}: ${check.label} (${check.notation})`), ...change];
152
175
  const language = readSettings(root).language ?? system?.language ?? "en";
153
- const shown = [...checks.map((check) => formLabel(check, (dice) => (system === undefined ? undefined : rollName(system, dice, language)))), ...change];
154
- const rows = { who, fields: [...checks.map((check) => check.field ?? null), ...change.map(() => null)], ...(save === undefined ? {} : { save }) };
176
+ const formed = (check) => told.roll?.name ?? formLabel(check, (dice) => (system === undefined ? undefined : rollName(system, dice, language)));
177
+ const shown = [...checks.map(formed), ...change];
178
+ // A package's words for its buttons, its rule and its card, for the page (D-507).
179
+ const buttons = told.roll === undefined && typeof told.decline !== "object" ? {} : { buttons: [...checks.map(() => told.roll ?? null), ...change.map(() => (typeof told.decline === "object" ? told.decline : null))] };
180
+ const own = { ...buttons, ...(told.rule === undefined ? {} : { rule: told.rule }), ...(told.card === undefined ? {} : { card: told.card }) };
181
+ const rows = { who, fields: [...checks.map((check) => check.field ?? null), ...change.map(() => null)], ...(save === undefined ? {} : { save }), ...own };
155
182
  const chosen = await chooseAnswer(context, question, words.roll, labels, rows, shown);
156
183
  const asked = askedText(question, "checks", checks);
157
184
  // A call the user stopped logs nothing (ASK-9).
@@ -167,16 +194,18 @@ async function rollChosen(root, context, question, checks, who, words) {
167
194
  }
168
195
  const check = chosen === undefined ? undefined : checks[chosen];
169
196
  if (check?.notation === undefined) {
170
- logAnswer(root, context, question, labels, chosen === checks.length ? words.change : undefined);
197
+ logAnswer(root, context, question, labels, chosen === checks.length ? decline : undefined);
171
198
  return chosen === checks.length ? { kind: "changed" } : { kind: "unanswered", asked };
172
199
  }
173
200
  const diceRoll = rollDice(check.notation, { random: context.random });
174
- const data = { notation: diceRoll.notation, total: diceRoll.total, result: diceRoll.text, why: `${check.label}: ${question}`, check: check.label, who, physical: false, dice: diceRoll.dice };
201
+ const says = told.says === undefined ? {} : { says: told.says(diceRoll.faces) };
202
+ const tones = tonesOf(told.tones?.(diceRoll.faces), diceRoll.faces);
203
+ const data = { notation: diceRoll.notation, total: diceRoll.total, result: diceRoll.text, ...says, ...tones, why: `${check.label}: ${question}`, check: check.label, who, physical: false, dice: diceRoll.dice };
175
204
  const entry = newDatedLogEntry(root, { ...context, actor: "player" }, "roll", "public", data);
176
205
  appendLogEntry(root, entry);
177
206
  // A check of a dying character is their death save, which the engine writes (DIE-4, D-460).
178
207
  const notes = allSaid(systemRolled(root, context, { who, notation: diceRoll.notation, total: diceRoll.total, dice: diceRoll.dice }));
179
- return { kind: "roll", id: entry.id, who, check: check.label, text: diceRoll.text, total: diceRoll.total, ...(notes.length === 0 ? {} : { notes }) };
208
+ return { kind: "roll", id: entry.id, who, check: check.label, text: diceRoll.text, total: diceRoll.total, faces: diceRoll.faces, ...(notes.length === 0 ? {} : { notes }) };
180
209
  }
181
210
  /**
182
211
  * Where the player's character moves on the map of its place (ASK-11): only the page can show the map; the square touched moves it, as move with at, and the
@@ -250,7 +279,7 @@ async function diceSpent(root, context, question, recipeName, given, words) {
250
279
  if (context.page?.spendDice === undefined) {
251
280
  return { kind: "dice in words", asked: inWords };
252
281
  }
253
- const fieldWords = systemWordsOf(system, settings.language ?? system.language ?? "en", context)?.fields ?? {};
282
+ const fieldWords = systemWordsOf(root, system, settings.language ?? system.language ?? "en", context)?.fields ?? {};
254
283
  const label = (field) => String(valueNamed(fieldWords, field) ?? field);
255
284
  const from = counterOn(world, who, gives)?.value ?? 0;
256
285
  const rolls = [];
@@ -454,7 +483,7 @@ function readOption(text) {
454
483
  // The dice from the first word that is a die, so that 1d20+athletics - 1 and 1d20 + athletics are dice too; else the last word.
455
484
  const spaced = /^(.+?)\s+(\d*d(?:\d+|%|F)\S*(?:\s*[+-]\s*\S+)*)$/i.exec(text);
456
485
  const last = /^(.+?)\s+(\S+)$/.exec(text);
457
- const match = [spaced, last].find((candidate) => candidate !== null && isDice(namesAsZero(candidate[2])));
486
+ const match = [spaced, last].find((candidate) => candidate !== null && isCheckDice(candidate[2]));
458
487
  return match === undefined || match === null ? { label: text } : { label: match[1].trim(), notation: match[2] };
459
488
  }
460
489
  /**
@@ -38,6 +38,7 @@ export declare const change: import("../core/registry.ts").Command<z.ZodObject<{
38
38
  /** What the change may break that someone keeps alive, and what shields the counter it lowered (EFF-14, DAT-14). */
39
39
  reminders: string[];
40
40
  } | {
41
+ hiddenRoll?: HiddenDice | undefined;
41
42
  rolled: string;
42
43
  problems: string[];
43
44
  page: string;
@@ -57,6 +58,12 @@ export declare const change: import("../core/registry.ts").Command<z.ZodObject<{
57
58
  /** What the change may break that someone keeps alive, and what shields the counter it lowered (EFF-14, DAT-14). */
58
59
  reminders: string[];
59
60
  }>;
61
+ /** The dice in by, hidden: the roll's id, the fingerprint the player may ask for, and whether master-rolls hid them. */
62
+ interface HiddenDice {
63
+ id: string;
64
+ fingerprint: string;
65
+ screened: boolean;
66
+ }
60
67
  /** What a step did to a counter or to money. */
61
68
  interface StepOutcome {
62
69
  page: string;
@@ -13,6 +13,7 @@ import { checkEffectsReadable, saveEffects } from "./game-effects.js";
13
13
  import { fireEvents, nowDueNote } from "./game-events.js";
14
14
  import { experienceOf, newLevelNotes } from "./game-experience.js";
15
15
  import { spendableDice, spendDice } from "./game-hit-dice.js";
16
+ import { screenNote, screenUp, sealHiddenRoll } from "./game-master-rolls.js";
16
17
  import { campaignCoins } from "./game-money.js";
17
18
  import { logRecipeApplied, tooSoonNote } from "./game-recipe-pace.js";
18
19
  import { effectsAtRecipe, notBroughtBack, partyPages, recipeChoices, recipeNamed, recipeTargets } from "./game-recipes.js";
@@ -43,7 +44,7 @@ export const change = defineCommand({
43
44
  input: z.object({
44
45
  page: z.string().optional().describe("page that holds the counter or the money; with a recipe, left out for the player character and the companions with them"),
45
46
  field: z.string().optional().describe("the counter or the money, such as hp, or the kind of a stack, such as Torch; none with a recipe"),
46
- by: z.union([wholeNumber, z.string()]).optional().describe("how much to add, or to take away when negative, or coins; stops at a limit (damage, healing); on the command line write --by=-7. Dice are rolled here, as the player sees: by -(2d6+3) takes away 2d6+3, by -2d6 a die alone, as the game's rules have them rolled"),
47
+ by: z.union([wholeNumber, z.string()]).optional().describe("how much to add, or to take away when negative, or coins; stops at a limit (damage, healing); on the command line write --by=-7. Dice are rolled here: by -(2d6+3) takes away 2d6+3, by -2d6 a die alone, as the game's rules have them rolled; taking away from the party, the master's roll, hidden or shown as master-rolls says"),
47
48
  spend: z.union([wholeNumber, z.string()]).optional().describe("how much is paid or used up, or coins; refused when there is not enough"),
48
49
  to: z.union([z.number().int(), z.string()]).optional().describe("the new value, even outside the limits: a number, max, current/max such as 15/15 (the maximum changes too), or coins; on the command line write --to=-3"),
49
50
  why: z.string().optional().describe("what the change is for"),
@@ -63,16 +64,15 @@ export const change = defineCommand({
63
64
  if (input.page === undefined || input.field === undefined) {
64
65
  throw new Error('Give the page and the field, such as page Bruna, field hp, by -7; or a recipe of the game system, such as recipe "long rest".');
65
66
  }
66
- // Dice in by are rolled first and logged once the change is made, as a roll the player sees (D-459): one call for a roll and its damage.
67
+ // Dice in by are rolled first and logged once the change is made (D-459): one call for a roll and its damage.
67
68
  const roll = diceBy(input.by, context);
69
+ const hiding = roll === undefined ? undefined : diceHiding(root, world, input.page, roll.taking);
68
70
  const { hitCounter, ...result } = changeField(root, context, world, { ...input, page: input.page, field: input.field, ...(roll === undefined ? {} : { by: roll.by }) });
69
- if (roll !== undefined) {
70
- appendLogEntry(root, newDatedLogEntry(root, context, "roll", "public", { ...roll.data, why: input.why ?? `${input.field} of ${input.page}` }));
71
- }
71
+ const hiddenRoll = roll === undefined ? undefined : logDiceBy(root, context, { ...roll.data, why: input.why ?? `${input.field} of ${input.page}` }, hiding);
72
72
  // The game system's code follows the change, after the roll that made it (D-448): as the 5e's dying point.
73
73
  const lines = hitCounter === undefined ? [] : allSaid(systemCounterChanged(root, context, hitCounter));
74
74
  const told = lines.length === 0 ? result : { ...result, reminders: [...result.reminders, ...lines] };
75
- return roll === undefined ? told : { ...told, rolled: roll.data.result };
75
+ return roll === undefined ? told : { ...told, rolled: roll.data.result, ...(hiddenRoll === undefined ? {} : { hiddenRoll }) };
76
76
  },
77
77
  format(result) {
78
78
  if ("recipe" in result) {
@@ -83,7 +83,7 @@ export const change = defineCommand({
83
83
  const summary = result.changed ? `${result.page}: ${result.field} ${result.before} → ${after}${note}.` : `Nothing changed: ${result.field} on ${result.page} is ${after}${note}.`;
84
84
  // A rule's text, of several lines, comes after the lines of the change.
85
85
  const notes = stepNotes(result);
86
- const lines = [...("rolled" in result && result.rolled !== undefined ? [`Rolled ${result.rolled}.`] : []), summary, ...notes.filter((line) => !line.includes("\n"))];
86
+ const lines = [...("rolled" in result && result.rolled !== undefined ? [rolledText(result.rolled, result.hiddenRoll)] : []), summary, ...notes.filter((line) => !line.includes("\n"))];
87
87
  return [lines.join("\n"), ...notes.filter((line) => line.includes("\n")), skippedPagesNote(result.problems)].filter((block) => block !== "").join("\n\n");
88
88
  },
89
89
  });
@@ -151,7 +151,33 @@ function diceBy(by, context) {
151
151
  }
152
152
  const rolled = rollDice(notation, { random: context.random });
153
153
  const total = Math.max(0, rolled.total);
154
- return { by: text.startsWith("-") ? -total : total, data: { notation, total: rolled.total, result: rolled.text, physical: false, dice: rolled.dice } };
154
+ return { by: text.startsWith("-") ? -total : total, taking: text.startsWith("-"), data: { notation, total: rolled.total, result: rolled.text, physical: false, dice: rolled.dice } };
155
+ }
156
+ /**
157
+ * Why the dice in by are hidden, or undefined when shown (D-287): with their change, on a page that does not concern the player, whatever master-rolls says;
158
+ * behind the screen, taking away from the player character or a companion, as a foe's or a trap's do. Healing them, or dice on a copy in the scene, are shown.
159
+ */
160
+ function diceHiding(root, world, name, taking) {
161
+ const holder = holderNamed(root, world, name);
162
+ if (holder.kind === "copy") {
163
+ return undefined;
164
+ }
165
+ if (holder.visibility === "hidden") {
166
+ return "secret";
167
+ }
168
+ return taking && screenUp(root) && isPartyMember(holder.page) ? "screen" : undefined;
169
+ }
170
+ /** Logs the roll of the dice in by, sealed when hidden as roll seals one; what the master is told of it when hidden. */
171
+ function logDiceBy(root, context, data, hiding) {
172
+ const entry = newDatedLogEntry(root, context, "roll", hiding === undefined ? "public" : "hidden", data);
173
+ const fingerprint = hiding === undefined ? undefined : sealHiddenRoll(entry, data.result, context);
174
+ appendLogEntry(root, entry);
175
+ return fingerprint === undefined ? undefined : { id: entry.id, fingerprint, screened: hiding === "screen" };
176
+ }
177
+ /** "Rolled 2d6+3 = 11 [5, 3] + 3.", or the hidden roll as roll tells it, only for the master. */
178
+ function rolledText(rolled, hidden) {
179
+ const screen = hidden?.screened === true ? `. ${screenNote}` : "";
180
+ return hidden === undefined ? `Rolled ${rolled}.` : `Hidden roll ${hidden.id}, only for the master: ${rolled}${screen}\nIts fingerprint, only if the player asks for it: ${hidden.fingerprint}`;
155
181
  }
156
182
  /** Whether a text reads as dice, such as 2d6+3: coins and names of fields do not. */
157
183
  function isDiceNotation(text) {
@@ -19,7 +19,7 @@ import { campaignCoins, coinsShown } from "./game-money.js";
19
19
  import { readOpenScene } from "./game-scene.js";
20
20
  import { campaignCalendar, newDatedLogEntry } from "./game-time.js";
21
21
  import { checkWidgetSpots } from "./game-widgets.js";
22
- import { campaignSystem, campaignWorld, countedByGame, installedSystemName, systemSetting, systemSettingValue, valuesText } from "./game-world.js";
22
+ import { campaignSystem, campaignWorld, countedByGame, installedSystemName, systemLayers, systemSetting, systemSettingValue, valuesText } from "./game-world.js";
23
23
  import { mentorPart, stylePart } from "./parts.js";
24
24
  // A use whose maximum reads what gives it, in quotes for its commas (CAM-1).
25
25
  const counterExample = 'bulwark-dice: {max: "4 * has(features, Bulwark)", refill: short rest}';
@@ -665,7 +665,9 @@ function checkAdditions(root, context, setting, change) {
665
665
  const held = data[setting] !== null && typeof data[setting] === "object" && !Array.isArray(data[setting]) ? data[setting] : {};
666
666
  const dropped = [...(change.remove ?? []), ...Object.keys(change.set ?? {})];
667
667
  const entries = { ...Object.fromEntries(Object.entries(held).filter(([name]) => !dropped.some((other) => comparableText(other) === comparableText(name)))), ...change.set };
668
- const problem = findCampaignSystem(context.systemFolders, system, { ...data, [setting]: entries }).problem;
668
+ // Over what the campaign's extensions add, as the campaign plays it (CAM-2).
669
+ const layers = systemLayers(root, context, { ...data, [setting]: entries });
670
+ const problem = findCampaignSystem(context.systemFolders, system, layers).refused.find((layer) => layer.from === layers.at(-1)?.from)?.problem;
669
671
  if (problem !== undefined) {
670
672
  throw new Error(`With this, the system ${system} would not read: ${problem} Nothing changed.`);
671
673
  }
@@ -5,6 +5,7 @@ import { campaignFileName, readOneSetting, readTextSetting } from "../campaign/i
5
5
  import { files, isInside } from "../core/store.js";
6
6
  import { comparableText } from "../core/text.js";
7
7
  import { findExtension, isVerified } from "../extensions/index.js";
8
+ import { isCoreField } from "../pages/index.js";
8
9
  /**
9
10
  * The extensions campaign.yaml lists (D-27), each as installed on this computer, in the order written: the nearest layer last. One not installed, that does not
10
11
  * read, that needs another game system or has the name of another is left out, with its problem: the campaign plays without it.
@@ -54,6 +55,10 @@ export function extensionsLine(root, context) {
54
55
  const { extensions } = campaignExtensions(root, context);
55
56
  return extensions.length === 0 ? "" : `Extensions: ${extensions.map((extension) => `${extension.name} (${extension.about})`).join("; ")}.`;
56
57
  }
58
+ /** The fields of the core an extension declares among its fields or counters, which no extension may write (D-505). */
59
+ function coreFieldsOf(extension) {
60
+ return [...Object.keys(extension.adds.fields ?? {}), ...Object.keys(extension.adds.counters ?? {})].filter(isCoreField);
61
+ }
57
62
  function readCampaignExtensions(root, context) {
58
63
  const extensions = [];
59
64
  const problems = [];
@@ -77,6 +82,13 @@ function readCampaignExtensions(root, context) {
77
82
  fix: `take it away with package remove ${extension.name}`,
78
83
  });
79
84
  }
85
+ else if (coreFieldsOf(extension).length > 0) {
86
+ problems.push({
87
+ path: campaignFileName,
88
+ message: `The extension ${name} declares ${coreFieldsOf(extension).join(", ")}, which the engine's own pages hold: it is left out.`,
89
+ fix: `install another version of it with package install ${extension.name}, or take it away with package remove ${extension.name}`,
90
+ });
91
+ }
80
92
  else if (extensions.some((other) => other.name === extension.name)) {
81
93
  problems.push({
82
94
  path: campaignFileName,
@@ -30,5 +30,5 @@ export declare function timePassedLines(root: string, context: Context, from: Ga
30
30
  * an extension that ships its source too is loaded from it.
31
31
  */
32
32
  export declare function extensionCode(extension: Extension): Promise<ExtensionCode | undefined>;
33
- /** The game as a widget of an extension reads it (D-502): the game its commands reach, without the dice, the log or writing. */
33
+ /** The game as a widget of an extension reads it (D-502, D-505): the time, where the party is and who is in it, a page, the scene and the extension's state. */
34
34
  export declare function gameViewOf(root: string, context: Context, extension: Extension): GameView;