rpg-engine 0.5.0 → 0.6.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 (218) hide show
  1. package/dist/campaign/settings.d.ts +1 -0
  2. package/dist/campaign/settings.js +6 -5
  3. package/dist/command-line.js +12 -5
  4. package/dist/commands/advance.js +1 -1
  5. package/dist/commands/ask.d.ts +1 -1
  6. package/dist/commands/ask.js +66 -24
  7. package/dist/commands/change.js +28 -17
  8. package/dist/commands/config.d.ts +1 -1
  9. package/dist/commands/config.js +67 -21
  10. package/dist/commands/effect.js +42 -23
  11. package/dist/commands/find.js +1 -1
  12. package/dist/commands/game-adventures.js +2 -2
  13. package/dist/commands/game-catalog.d.ts +13 -0
  14. package/dist/commands/game-catalog.js +26 -2
  15. package/dist/commands/game-checks.js +23 -21
  16. package/dist/commands/{game-hit-dice.d.ts → game-dice-pool.d.ts} +3 -3
  17. package/dist/commands/{game-hit-dice.js → game-dice-pool.js} +7 -7
  18. package/dist/commands/game-effects.d.ts +12 -4
  19. package/dist/commands/game-effects.js +21 -13
  20. package/dist/commands/game-examples.d.ts +22 -0
  21. package/dist/commands/game-examples.js +72 -0
  22. package/dist/commands/game-extension-list.d.ts +31 -3
  23. package/dist/commands/game-extension-list.js +83 -7
  24. package/dist/commands/game-images.d.ts +1 -1
  25. package/dist/commands/game-images.js +3 -2
  26. package/dist/commands/game-library.d.ts +3 -0
  27. package/dist/commands/game-library.js +2 -2
  28. package/dist/commands/game-mode.js +1 -1
  29. package/dist/commands/game-package-code.d.ts +87 -0
  30. package/dist/commands/game-package-code.js +648 -0
  31. package/dist/commands/game-package-hooks.d.ts +37 -0
  32. package/dist/commands/game-package-hooks.js +116 -0
  33. package/dist/commands/game-recipes.js +2 -2
  34. package/dist/commands/game-reminders.d.ts +5 -2
  35. package/dist/commands/game-reminders.js +7 -4
  36. package/dist/commands/game-rules.d.ts +4 -1
  37. package/dist/commands/game-rules.js +7 -1
  38. package/dist/commands/game-upkeep.js +3 -3
  39. package/dist/commands/game-view-place.d.ts +8 -20
  40. package/dist/commands/game-view-place.js +16 -35
  41. package/dist/commands/game-widgets.d.ts +39 -10
  42. package/dist/commands/game-widgets.js +138 -35
  43. package/dist/commands/game-world.d.ts +17 -0
  44. package/dist/commands/game-world.js +70 -12
  45. package/dist/commands/image.js +1 -1
  46. package/dist/commands/init.js +2 -2
  47. package/dist/commands/mode.d.ts +1 -1
  48. package/dist/commands/package.d.ts +8 -0
  49. package/dist/commands/package.js +81 -24
  50. package/dist/commands/progression.d.ts +2 -0
  51. package/dist/commands/progression.js +7 -2
  52. package/dist/commands/roll.d.ts +2 -0
  53. package/dist/commands/roll.js +50 -24
  54. package/dist/commands/rules.js +6 -4
  55. package/dist/commands/scene.d.ts +1 -1
  56. package/dist/commands/scene.js +13 -10
  57. package/dist/commands/sheet.js +10 -1
  58. package/dist/commands/status.d.ts +1 -0
  59. package/dist/commands/status.js +14 -4
  60. package/dist/commands/trade.js +6 -4
  61. package/dist/commands/translate.js +2 -2
  62. package/dist/commands/travel.js +1 -1
  63. package/dist/commands/validate.js +2 -2
  64. package/dist/commands/view.d.ts +8 -4
  65. package/dist/commands/view.js +7 -6
  66. package/dist/commands/worked-out.js +11 -5
  67. package/dist/commands/write.d.ts +8 -1
  68. package/dist/commands/write.js +84 -25
  69. package/dist/core/command-reference.js +3 -2
  70. package/dist/core/consents.d.ts +18 -0
  71. package/dist/core/consents.js +93 -0
  72. package/dist/core/context.d.ts +51 -29
  73. package/dist/core/context.js +3 -1
  74. package/dist/core/examples.d.ts +25 -0
  75. package/dist/core/examples.js +19 -0
  76. package/dist/{extensions/api.d.ts → core/package-api.d.ts} +134 -32
  77. package/dist/core/package-declarations.d.ts +102 -0
  78. package/dist/core/package-declarations.js +81 -0
  79. package/dist/core/registry.d.ts +2 -0
  80. package/dist/core/text.d.ts +5 -0
  81. package/dist/core/text.js +12 -0
  82. package/dist/dashboard/acts.js +31 -24
  83. package/dist/dashboard/address.js +4 -1
  84. package/dist/dashboard/api.js +54 -0
  85. package/dist/dashboard/app.js +140 -96
  86. package/dist/dashboard/ask-card.js +76 -25
  87. package/dist/dashboard/asked-dice.js +57 -0
  88. package/dist/dashboard/dice/tray.js +3 -3
  89. package/dist/dashboard/extension-widgets.js +104 -10
  90. package/dist/dashboard/i18n/ar.json +25 -29
  91. package/dist/dashboard/i18n/cs.json +25 -29
  92. package/dist/dashboard/i18n/da.json +25 -29
  93. package/dist/dashboard/i18n/de.json +25 -29
  94. package/dist/dashboard/i18n/el.json +25 -29
  95. package/dist/dashboard/i18n/es.json +25 -29
  96. package/dist/dashboard/i18n/fi.json +25 -29
  97. package/dist/dashboard/i18n/fr.json +25 -29
  98. package/dist/dashboard/i18n/he.json +25 -29
  99. package/dist/dashboard/i18n/hi.json +25 -29
  100. package/dist/dashboard/i18n/hu.json +25 -29
  101. package/dist/dashboard/i18n/is.json +25 -29
  102. package/dist/dashboard/i18n/it.json +25 -29
  103. package/dist/dashboard/i18n/ja.json +25 -29
  104. package/dist/dashboard/i18n/ko.json +25 -29
  105. package/dist/dashboard/i18n/nb.json +25 -29
  106. package/dist/dashboard/i18n/nl.json +25 -29
  107. package/dist/dashboard/i18n/pl.json +25 -29
  108. package/dist/dashboard/i18n/pt.json +25 -29
  109. package/dist/dashboard/i18n/ro.json +25 -29
  110. package/dist/dashboard/i18n/ru.json +25 -29
  111. package/dist/dashboard/i18n/sv.json +25 -29
  112. package/dist/dashboard/i18n/tr.json +25 -29
  113. package/dist/dashboard/i18n/uk.json +25 -29
  114. package/dist/dashboard/i18n/zh.json +25 -29
  115. package/dist/dashboard/icons.js +4 -1
  116. package/dist/dashboard/kit.js +35 -0
  117. package/dist/dashboard/labels.js +1 -0
  118. package/dist/dashboard/pack-card.js +7 -2
  119. package/dist/dashboard/package-page.js +50 -0
  120. package/dist/dashboard/packages.js +172 -23
  121. package/dist/dashboard/page-code.js +248 -0
  122. package/dist/dashboard/party.js +13 -14
  123. package/dist/dashboard/people.js +4 -0
  124. package/dist/dashboard/person-panel.js +110 -0
  125. package/dist/dashboard/place-map-view.js +11 -6
  126. package/dist/dashboard/scene.js +12 -9
  127. package/dist/dashboard/settings.js +55 -9
  128. package/dist/dashboard/sheet.js +21 -13
  129. package/dist/dashboard/status.js +69 -15
  130. package/dist/dashboard/style.css +592 -825
  131. package/dist/dashboard/top.js +75 -25
  132. package/dist/dashboard/turns.js +34 -13
  133. package/dist/dashboard/widgets.js +9 -2
  134. package/dist/dashboard-server.js +189 -10
  135. package/dist/dice/roll-dice.js +1 -1
  136. package/dist/effects/effect.d.ts +7 -4
  137. package/dist/effects/effect.js +12 -9
  138. package/dist/extensions/engine.d.ts +4 -0
  139. package/dist/extensions/engine.js +74 -0
  140. package/dist/extensions/extension.d.ts +25 -37
  141. package/dist/extensions/extension.js +26 -48
  142. package/dist/extensions/index.d.ts +3 -2
  143. package/dist/extensions/index.js +4 -1
  144. package/dist/extensions/packages.d.ts +6 -0
  145. package/dist/extensions/packages.js +100 -11
  146. package/dist/index.d.ts +1 -3
  147. package/dist/mcp-server.js +51 -14
  148. package/dist/page-words.d.ts +4 -0
  149. package/dist/page-words.js +4 -4
  150. package/dist/page.d.ts +218 -0
  151. package/dist/page.js +2 -0
  152. package/dist/pages/load.d.ts +7 -1
  153. package/dist/pages/load.js +10 -5
  154. package/dist/pages/page-file.js +1 -1
  155. package/dist/pages/stack-writes.js +5 -4
  156. package/dist/pages/world.d.ts +8 -0
  157. package/dist/pages/world.js +9 -2
  158. package/dist/systems/game-system.d.ts +52 -26
  159. package/dist/systems/game-system.js +141 -42
  160. package/dist/systems/index.d.ts +3 -3
  161. package/dist/systems/index.js +3 -3
  162. package/dist/systems/system-code.d.ts +29 -88
  163. package/dist/systems/system-code.js +68 -23
  164. package/dist/systems/words.d.ts +2 -0
  165. package/dist/systems/words.js +11 -0
  166. package/dist/testing.d.ts +20 -5
  167. package/dist/testing.js +49 -14
  168. package/instructions/combat.md +2 -2
  169. package/instructions/core.md +2 -2
  170. package/instructions/dashboard.md +1 -1
  171. package/instructions/mentor-tutorial.md +1 -1
  172. package/instructions/play.md +2 -2
  173. package/instructions/setup.md +1 -1
  174. package/package.json +9 -1
  175. package/systems/5e/LICENSE.md +13 -3
  176. package/systems/5e/dist/dying.js +83 -16
  177. package/systems/5e/dist/index.js +2 -2
  178. package/systems/5e/dist/page-style.js +634 -0
  179. package/systems/5e/dist/page.js +166 -0
  180. package/systems/5e/dist/shown.js +23 -0
  181. package/systems/5e/instructions/combat.md +1 -0
  182. package/systems/5e/package.json +4 -2
  183. package/systems/5e/system.yaml +35 -7
  184. package/systems/5e/versions/srd-5.1/system.yaml +2 -0
  185. package/systems/5e/words/ar.yaml +30 -0
  186. package/systems/5e/words/cs.yaml +30 -0
  187. package/systems/5e/words/da.yaml +30 -0
  188. package/systems/5e/words/de.yaml +30 -0
  189. package/systems/5e/words/el.yaml +30 -0
  190. package/systems/5e/words/es.yaml +30 -0
  191. package/systems/5e/words/fi.yaml +30 -0
  192. package/systems/5e/words/fr.yaml +30 -0
  193. package/systems/5e/words/he.yaml +30 -0
  194. package/systems/5e/words/hi.yaml +30 -0
  195. package/systems/5e/words/hu.yaml +30 -0
  196. package/systems/5e/words/is.yaml +30 -0
  197. package/systems/5e/words/it.yaml +30 -0
  198. package/systems/5e/words/ja.yaml +30 -0
  199. package/systems/5e/words/ko.yaml +30 -0
  200. package/systems/5e/words/nb.yaml +30 -0
  201. package/systems/5e/words/nl.yaml +30 -0
  202. package/systems/5e/words/pl.yaml +30 -0
  203. package/systems/5e/words/pt.yaml +30 -0
  204. package/systems/5e/words/ro.yaml +30 -0
  205. package/systems/5e/words/ru.yaml +30 -0
  206. package/systems/5e/words/sv.yaml +30 -0
  207. package/systems/5e/words/tr.yaml +30 -0
  208. package/systems/5e/words/uk.yaml +30 -0
  209. package/systems/5e/words/zh.yaml +30 -0
  210. package/dist/commands/game-extensions.d.ts +0 -34
  211. package/dist/commands/game-extensions.js +0 -407
  212. package/dist/commands/game-system-code.d.ts +0 -33
  213. package/dist/commands/game-system-code.js +0 -188
  214. package/dist/dashboard/death-save.js +0 -67
  215. package/dist/dashboard/dying.js +0 -46
  216. package/dist/dashboard/save-outcome.js +0 -42
  217. package/dist/dashboard/spend.js +0 -115
  218. /package/dist/{extensions/api.js → core/package-api.js} +0 -0
@@ -10,22 +10,22 @@ import { copyNames, nextTurn, sceneTypes } from "../scene/index.js";
10
10
  import { formatGameDate } from "../time/index.js";
11
11
  import { effectiveFields, effectsOf } from "./effect-layer.js";
12
12
  import { newStateChecks } from "./game-checks.js";
13
- import { effectShown, endedByTurn, endEffects, endsWithScene, keptBy } from "./game-effects.js";
13
+ import { effectShown, endedByTurn, endEffects, endsWithScene, keptBy, systemNamed } from "./game-effects.js";
14
14
  import { surroundings, surroundingsText } from "./game-environment.js";
15
15
  import { clearCopies, offMapNote, placeGrid, standing } from "./game-grids.js";
16
16
  import { metPictureNote, picturesNote } from "./game-images.js";
17
17
  import { readJourney } from "./game-journey.js";
18
18
  import { campaignMode, checklistLine } from "./game-mode.js";
19
19
  import { movePages } from "./game-moves.js";
20
+ import { packagesTurnStarted } from "./game-package-hooks.js";
20
21
  import { isTickedOpenQuest, tickedQuestNote } from "./game-quests.js";
21
22
  import { turnEffectsNote } from "./game-reminders.js";
22
23
  import { partyLead, playersApart } from "./game-roads.js";
23
24
  import { isPlayerDead, makeSave, saveText } from "./game-saves.js";
24
25
  import { copyCounters, copyPage, openScene, rawScene, readOpenScene, saveScene, updateScene } from "./game-scene.js";
25
- import { systemTurnStarted } from "./game-system-code.js";
26
26
  import { newDatedLogEntry, readPresent } from "./game-time.js";
27
27
  import { turnUsesOf, useInTurn, usesAtTurn } from "./game-turn-uses.js";
28
- import { campaignSystem, campaignWorld, missingSystemHint, systemPagesHint } from "./game-world.js";
28
+ import { campaignSystem, campaignSystemWords, campaignWorld, missingSystemHint, systemPagesHint } from "./game-world.js";
29
29
  import { countersText, pageCounters, partyCounters } from "./page-counters.js";
30
30
  import { situationPart } from "./parts.js";
31
31
  import { hasSheet, startingAtZero } from "./worked-out.js";
@@ -69,8 +69,8 @@ export const scene = defineCommand({
69
69
  with: textList.optional().describe("open, add: the characters in the scene, the player character included, such as [[Lena]]; at open, the character and the companions with them if left out"),
70
70
  creatures: z.union([textList, z.record(z.string(), z.number().int())]).optional().describe('open, add: creatures as numbered copies: Annegato=2 (Annegato alone is one), or through MCP an object such as {"Annegato": 2}'),
71
71
  who: textList.optional().describe("leave: who leaves the scene; hostile, calm: who attacks the party, or stops; use: who uses it; characters or copies, such as Annegato 2"),
72
- uses: z.string().optional().describe("use: what of a turn, by the game's names, such as action, bonus action, reaction, attack"),
73
- by: z.string().optional().describe('use: what gives one more, or lets it in another\'s turn, such as "Action Surge"'),
72
+ uses: z.string().optional().describe("use: what of a turn, by the game's names, such as {{uses}}"),
73
+ by: z.string().optional().describe("use: what gives one more, or lets it in another's turn, such as a feature"),
74
74
  order: textList.optional().describe("order: who takes turns, in order; those left out (fallen, fled) take none"),
75
75
  now: z.string().optional().describe('open, now: what is happening now, in one line as the player sees it, such as "The bandits overturn the tables"; never what they cannot see'),
76
76
  summary: z.string().optional().describe("close: what happened, in one or two sentences, as the player saw it"),
@@ -436,8 +436,9 @@ function useOfTurn(root, world, input, context, current) {
436
436
  if (done.spends !== undefined) {
437
437
  spendOne(root, context, world, { name, copy: copy !== undefined, page }, done.spends, by ?? "");
438
438
  }
439
- // One who cannot act, as Stunned, is said so: the game's rule, which the master applies (pp. 91, 358).
440
- const inactive = effectsOf(page).map((effect) => effect.name).filter((effect) => (system?.combat?.inactive ?? []).some((condition) => comparableText(condition) === comparableText(effect)));
439
+ // One who cannot act, as Stunned, is said so: the game's rule, which the master applies (pp. 91, 358); by its name in the campaign's language too (D-403).
440
+ const words = campaignSystemWords(root, context);
441
+ const inactive = effectsOf(page).map((effect) => effect.name).filter((effect) => systemNamed(system?.combat?.inactive ?? [], effect, words) !== undefined);
441
442
  const warned = inactive.length === 0 ? "" : ` ${name} is ${inactive.join(", ")}: read what it may still do.`;
442
443
  return { action: "use", line: `${done.line}${warned}` };
443
444
  }
@@ -628,10 +629,11 @@ function withActing(root, context, before, result) {
628
629
  // The player character's turn reminds what to mark of it, which the player sees on the dashboard (TRN-1); a companion's counts went right without (playtest
629
630
  // 08); dying, the death save it starts with (DIE-5).
630
631
  const member = findPage(world, turns.turn);
631
- const turn = systemTurnStarted(root, context, turns.turn);
632
+ const turn = packagesTurnStarted(root, context, turns.turn);
632
633
  const dying = turn.lines.join(" ");
633
634
  // Who cannot act, as one stable but still Unconscious, marks nothing.
634
- const inactive = member !== undefined && effectsOf(member).some((effect) => sameName(system?.combat?.inactive ?? [], effect.name) !== undefined);
635
+ const words = campaignSystemWords(root, context);
636
+ const inactive = member !== undefined && effectsOf(member).some((effect) => systemNamed(system?.combat?.inactive ?? [], effect.name, words) !== undefined);
635
637
  const pc = member !== undefined && isPlayerCharacter(member);
636
638
  const uses = !pc || dying !== "" || inactive ? [] : turnUsesOf(system);
637
639
  const mark = uses.length > 0 ? `Mark with scene use what ${turns.turn} uses of the turn, as it happens: ${uses.join(", ")}.` : "";
@@ -639,7 +641,8 @@ function withActing(root, context, before, result) {
639
641
  const quiet = pc ? "" : "Write nothing until the round is told: what you work out stays in your thinking.";
640
642
  // What cannot be true together, once in a chat, after the system's code had its say (CHK-3).
641
643
  const checks = newStateChecks(root, context).join(" ");
642
- const acting = [effects, dying, mark, offTheMap(world, scene, turns.turn), turn.problem ?? "", checks, quiet].filter((line) => line !== "").join(" ");
644
+ // The extensions' lines come after the engine's reminder, which only the system's take the place of (D-514).
645
+ const acting = [effects, dying, mark, ...turn.added, offTheMap(world, scene, turns.turn), turn.problem ?? "", checks, quiet].filter((line) => line !== "").join(" ");
643
646
  return acting === "" ? result : { ...result, acting };
644
647
  }
645
648
  /** Who acts and stands on no square of the scene's map, when its place has one (GRD-3, playtest 07): where it stands decides reach, cover and the way. */
@@ -149,7 +149,16 @@ export function sheetHeadline(world, system, page, words) {
149
149
  return isEmptyField(value) ? "" : declaredKind(world, field) === "list" ? listItemNames(value).map(said).join(" / ") : said(valueText(world, field, value));
150
150
  };
151
151
  const named = [...headline.matchAll(/\{([^{}]+)\}/g)].map((match) => shown(match[1]));
152
- return named.every((text) => text === "") ? undefined : headline.replace(/\{([^{}]+)\}/g, (_, field) => shown(field)).replace(/\s+/g, " ").trim();
152
+ if (named.every((text) => text === "")) {
153
+ return undefined;
154
+ }
155
+ // Its parts between commas, each kept with the comma before it unless it names fields all empty: "{calling}, rank {level}" without a calling is rank 3.
156
+ const parts = headline.split(/(\s*[,;،、,]\s*)/);
157
+ const kept = parts.flatMap((part, at) => {
158
+ const fields = [...part.matchAll(/\{([^{}]+)\}/g)].map((match) => shown(match[1]));
159
+ return at % 2 === 1 || (fields.length > 0 && fields.every((text) => text === "")) ? [] : [{ text: part.replace(/\{([^{}]+)\}/g, (_, field) => shown(field)), before: parts[at - 1] ?? "" }];
160
+ });
161
+ return kept.map((part, at) => (at === 0 ? part.text : `${part.before}${part.text}`)).join("").replace(/\s+/g, " ").trim();
153
162
  }
154
163
  /**
155
164
  * The stat block of a companion who keeps no sheet, as the creature it derives from writes it (D-275): one group named after the creature, with the fields the
@@ -17,6 +17,7 @@ export declare const status: import("../core/registry.ts").Command<z.ZodObject<{
17
17
  campaign: string[];
18
18
  meanings: string[];
19
19
  note: string;
20
+ systems: string | undefined;
20
21
  premise: string | undefined;
21
22
  writing: string[];
22
23
  lines: string[];
@@ -5,25 +5,27 @@ import { defineCommand } from "../core/registry.js";
5
5
  import { isInParty, isPartyMember, isPlayerCharacter, locate, pagesWithName, parsePageReference, playerCharacters } from "../pages/index.js";
6
6
  import { bookTitles, readRuleBook } from "../rules/index.js";
7
7
  import { sceneTypes } from "../scene/index.js";
8
+ import { rulesetSetting } from "../systems/index.js";
8
9
  import { effectiveFields, effectsOf } from "./effect-layer.js";
10
+ import { installableSystems } from "./game-catalog.js";
9
11
  import { allStateChecks, markStateChecksTold } from "./game-checks.js";
10
12
  import { effectShown, keptEffects } from "./game-effects.js";
11
13
  import { surroundings, surroundingsText } from "./game-environment.js";
12
14
  import { clocksToMove, dueAdvice, dueText, isDated, isDue, plannedEvents, plannedText, worldFacts } from "./game-events.js";
13
15
  import { experienceOf, levelDueNote } from "./game-experience.js";
14
16
  import { extensionsLine } from "./game-extension-list.js";
15
- import { extensionCodeProblems } from "./game-extensions.js";
16
17
  import { picturesNote } from "./game-images.js";
17
18
  import { journeyText, readJourney } from "./game-journey.js";
18
19
  import { campaignMode, campaignNote } from "./game-mode.js";
19
20
  import { campaignCoins } from "./game-money.js";
20
21
  import { livingMood, masterMood } from "./game-moods.js";
22
+ import { packageCodeProblems } from "./game-package-code.js";
21
23
  import { isTickedOpenQuest, openQuestText } from "./game-quests.js";
22
24
  import { measuresOf, roadsOf } from "./game-roads.js";
23
25
  import { interruptedLoad } from "./game-saves.js";
24
26
  import { closedScenes, copyCounters, copyPage, partyAwayText, readOpenScene } from "./game-scene.js";
25
27
  import { datedText, problemText, readPresent } from "./game-time.js";
26
- import { campaignSystem, campaignWorld, countedByGame, systemInStatus, systemSettingValue } from "./game-world.js";
28
+ import { campaignSystem, campaignWorld, countedByGame, playedSettingValue, systemInStatus } from "./game-world.js";
27
29
  import { importLine } from "./import.js";
28
30
  import { countersText, pageCounters, partyCounters } from "./page-counters.js";
29
31
  import { campaignProblems } from "./problems.js";
@@ -44,7 +46,7 @@ export const status = defineCommand({
44
46
  input: z.object({}),
45
47
  async run(input, context) {
46
48
  const root = requireCampaign(context.folder);
47
- const codeProblems = await extensionCodeProblems(root, context, []);
49
+ const codeProblems = await packageCodeProblems(root, context, []);
48
50
  const settings = readSettings(root);
49
51
  const world = campaignWorld(root, context);
50
52
  const characters = world.pages.filter((page) => page.type === "character");
@@ -88,6 +90,8 @@ export const status = defineCommand({
88
90
  const due = events.filter((event) => isDue(event, now, facts));
89
91
  const closed = closedScenes(root);
90
92
  const mode = campaignMode(root, world);
93
+ // Before a system is chosen, those this computer can install, beside its own (D-513 (1)).
94
+ const installable = settings.system === undefined ? await installableSystems(context) : [];
91
95
  return {
92
96
  campaign: [
93
97
  settings.name,
@@ -103,7 +107,8 @@ export const status = defineCommand({
103
107
  // How much the master teaches, only when they do (D-347).
104
108
  named("mentor", settings.mentor === "off" ? undefined : settings.mentor),
105
109
  // What the system adds to the setup, as advancement xp (DAT-10).
106
- ...(system?.settings ?? []).map((setting) => named(setting.name, systemSettingValue(root, setting))),
110
+ // The version of the rules is in the system's own words above (VER-1).
111
+ ...(system?.settings ?? []).filter((setting) => setting.name !== rulesetSetting).map((setting) => named(setting.name, playedSettingValue(root, context, setting))),
107
112
  named("mode", mode),
108
113
  ].filter((part) => part !== undefined),
109
114
  // What the chosen difficulty and rigor mean in play, one line each (D-263).
@@ -113,6 +118,10 @@ export const status = defineCommand({
113
118
  }),
114
119
  // Before play, what the next mode needs and how to enter it; in play, the settings still missing (MOD-7).
115
120
  note: campaignNote(root, context),
121
+ systems: installable.length === 0
122
+ ? undefined
123
+ : `Game systems to install, if the player wants one: ${installable.map((one) => `${one.name} (${one.title}${one.verified ? "" : ", not verified"})`).join(", ")}. `
124
+ + "Install the one chosen with package install and its name, then set it with config system: the campaign keeps it once it has a player character.",
116
125
  premise: settings.premise === undefined ? undefined : `${settings.premise}${settings.preparation === undefined ? "" : ` (preparation ${settings.preparation})`}`,
117
126
  // How the master writes, as the player chose it, under the eyes at every start (D-395).
118
127
  writing: [
@@ -181,6 +190,7 @@ export const status = defineCommand({
181
190
  result.campaign.join(" · "),
182
191
  ...result.meanings,
183
192
  result.note,
193
+ result.systems ?? "",
184
194
  result.premise === undefined ? "" : `Premise: ${result.premise}`,
185
195
  result.writing.length === 0 ? "" : `Your writing: ${result.writing.join(" · ")}`,
186
196
  boundariesLine(result.lines, result.veils),
@@ -5,6 +5,7 @@ import { defineCommand } from "../core/registry.js";
5
5
  import { comparableText } from "../core/text.js";
6
6
  import { addCoins, changeFrom, formatAmount, isSafePurse, payCoins, readAmount, takeCoins, totalOf } from "../money/index.js";
7
7
  import { applyMove, canHold, concernsPlayer, countedText, declaredKind, inheritedFields, isPartyMember, kindNamed, locate, MoveStopped, ownField, pageNamed, parsePageReference, readEntry, stackName, } from "../pages/index.js";
8
+ import { coinExamples } from "./game-examples.js";
8
9
  import { campaignCoins } from "./game-money.js";
9
10
  import { afterMoves, pagesPlan } from "./game-moves.js";
10
11
  import { copyName, readOpenScene } from "./game-scene.js";
@@ -19,13 +20,13 @@ export const trade = defineCommand({
19
20
  description: "Buy, sell or barter in one go: what page gives and what it gets, items and money both ways, with the change in coins. "
20
21
  + "with is the merchant, a character, or the shop, a place that holds its goods: what is taken comes from there. "
21
22
  + "Each entry is money in the campaign's coins, a kind with how many, or an item with a story of its own; never a character. "
22
- + 'If one side lacks what it gives, nothing changes. Example: page Ettore, with Bottega di Ugo, gives "2 gp", gets ["Torch 5", "Hempen Rope"].',
23
+ + 'If one side lacks what it gives, nothing changes. Example: page Ettore, with Bottega di Ugo, gives "2 {{coin}}", gets ["Torch 5", "Hempen Rope"].',
23
24
  group: "game",
24
25
  positionals: ["page"],
25
26
  input: z.object({
26
27
  page: z.string().describe("who trades, usually the player character"),
27
28
  with: z.string().describe("the other side: a merchant, or a shop, a place that holds its goods"),
28
- gives: textList.optional().describe('what page gives: money such as "2 gp", kinds with how many such as Torch 5, items such as Mazza di Matteo'),
29
+ gives: textList.optional().describe('what page gives: money such as "2 {{coin}}", kinds with how many such as Torch 5, items such as Mazza di Matteo'),
29
30
  gets: textList.optional().describe("what page gets, written the same way"),
30
31
  why: z.string().optional().describe("what the trade is, such as bought torches at the market"),
31
32
  }),
@@ -42,7 +43,7 @@ export const trade = defineCommand({
42
43
  const gives = handed(world, coins, buyer, seller, listOf(input.gives), "page");
43
44
  const gets = handed(world, coins, seller, buyer, listOf(input.gets), "with");
44
45
  if (gives.money === undefined && gets.money === undefined && gives.stacks.length + gives.pages.length + gets.stacks.length + gets.pages.length === 0) {
45
- throw new Error(`Give what ${buyer.name} gives, gives, and what it gets, gets, such as gives "2 gp", gets "Torch 5". Nothing changed.`);
46
+ throw new Error(`Give what ${buyer.name} gives, gives, and what it gets, gets, such as gives "2 ${coinExamples(coins).coin}", gets "Torch 5". Nothing changed.`);
46
47
  }
47
48
  if (gives.money !== undefined && gets.money !== undefined) {
48
49
  throw new Error(`Money goes one way in a trade: give only the difference, on one side. To change coins, use change with to. Nothing changed.`);
@@ -104,7 +105,8 @@ function handed(world, coins, giver, taker, entries, side) {
104
105
  const money = coins === undefined ? undefined : readAmount(entry, coins);
105
106
  if (money !== undefined) {
106
107
  if (result.money !== undefined) {
107
- throw new Error(`Give the money ${giver.name} hands over as one amount, such as "2 gp 5 sp". Nothing changed.`);
108
+ const { coin, smallCoin } = coinExamples(coins);
109
+ throw new Error(`Give the money ${giver.name} hands over as one amount, such as "2 ${coin} 5 ${smallCoin}". Nothing changed.`);
108
110
  }
109
111
  result.money = money;
110
112
  continue;
@@ -19,7 +19,7 @@ export const translate = defineCommand({
19
19
  const root = requireCampaign(context.folder);
20
20
  const { home, page, language } = translationPlaces(context, readSettings(root).language?.toLowerCase());
21
21
  const found = campaignSystem(root, context);
22
- const system = found === undefined ? undefined : { name: found.name, folder: found.folder };
22
+ const system = found === undefined ? undefined : { name: found.name, folder: found.folder, ...(found.version === undefined ? {} : { version: found.version }) };
23
23
  const answer = input.phrases === undefined ? undefined : readAnswer(input.phrases);
24
24
  const saved = answer === undefined ? undefined : keepChatAnswer(home, page, language, system, answer);
25
25
  if (saved !== undefined && saved.kept === 0) {
@@ -65,7 +65,7 @@ export function translationOffer(root, context) {
65
65
  return undefined;
66
66
  }
67
67
  const found = campaignSystem(root, context);
68
- const left = chatBatch(context.home, context.pageFolder, language, found === undefined ? undefined : { name: found.name, folder: found.folder })?.left;
68
+ const left = chatBatch(context.home, context.pageFolder, language, found === undefined ? undefined : { name: found.name, folder: found.folder, ...(found.version === undefined ? {} : { version: found.version }) })?.left;
69
69
  const lacks = `The dashboard is not in ${languageName(language)} on this computer, and nothing here translates it in the background`;
70
70
  if (left === undefined) {
71
71
  return undefined;
@@ -6,11 +6,11 @@ import { directionHelp, directionName, distanceBetween, pointAlong, pointFrom, r
6
6
  import { environmentAt, locate, pageNamed, parsePageReference, playerCharacters } from "../pages/index.js";
7
7
  import { addDuration, formatGameDate, minutesBetween } from "../time/index.js";
8
8
  import { aroundLead, passedLines, passTime } from "./game-advance.js";
9
- import { timePassedLines } from "./game-extensions.js";
10
9
  import { journeyPoint, journeyStart, moversMap, moversNamed, moversPosition, readJourney, ridersOf, sameMovers, saveJourney, travelledSinceRest } from "./game-journey.js";
11
10
  import { mapKey, mapOf } from "./game-maps.js";
12
11
  import { movePages } from "./game-moves.js";
13
12
  import { acrossHint, crossedRoads, openLegs } from "./game-open.js";
13
+ import { timePassedLines } from "./game-package-code.js";
14
14
  import { nearPlaces, pointText, positionOf, regionAt } from "./game-positions.js";
15
15
  import { dayHours, durationText, goingText, hoursText, isVehicleOnly, kindOf, lengthText, measuresOf, moversOf, noWayText, paceOf, partyLead, roadsOf, sameSpot, speedOf, stepEnd, stopOf, travellingParty, unknownOnRoad, wayFor, wayText, } from "./game-roads.js";
16
16
  import { readOpenScene } from "./game-scene.js";
@@ -2,7 +2,7 @@ import { z } from "zod";
2
2
  import { requireCampaign } from "../campaign/index.js";
3
3
  import { defineCommand } from "../core/registry.js";
4
4
  import { stateCheckProblems } from "./game-checks.js";
5
- import { extensionCodeProblems } from "./game-extensions.js";
5
+ import { packageCodeProblems } from "./game-package-code.js";
6
6
  import { campaignWorld } from "./game-world.js";
7
7
  import { campaignProblems } from "./problems.js";
8
8
  export const validate = defineCommand({
@@ -16,7 +16,7 @@ export const validate = defineCommand({
16
16
  async run(input, context) {
17
17
  const root = requireCampaign(context.folder);
18
18
  // And what keeps an extension's code from being used, which only loading it tells (D-441).
19
- return { problems: [...campaignProblems(root, campaignWorld(root, context), context), ...await extensionCodeProblems(root, context, []), ...stateCheckProblems(root, context)] };
19
+ return { problems: [...campaignProblems(root, campaignWorld(root, context), context), ...await packageCodeProblems(root, context, []), ...stateCheckProblems(root, context)] };
20
20
  },
21
21
  format(result) {
22
22
  if (result.problems.length === 0) {
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import type { Mood } from "../core/mood.ts";
3
3
  import { type NotationPart, type ThrownDie } from "../dice/index.ts";
4
- import type { ActVerb, SystemWords } from "../systems/index.ts";
4
+ import type { ActVerb, SheetVerb, SystemWords } from "../systems/index.ts";
5
5
  import { type CalendarDay } from "../time/index.ts";
6
6
  import { type PlayerSetting } from "./config.ts";
7
7
  import { type SeenEffect } from "./game-effects.ts";
@@ -10,7 +10,7 @@ import { type MoodMoment } from "./game-moods.ts";
10
10
  import { type ResetPoint, type SaveMode } from "./game-saves.ts";
11
11
  import { type ShownChapter, type ShownQuest, type ShownThought } from "./game-view-journal.ts";
12
12
  import { type ShownMap } from "./game-view-map.ts";
13
- import { type DyingCounter, type ShownPlace, type ShownScene } from "./game-view-place.ts";
13
+ import { type ShownPlace, type ShownScene } from "./game-view-place.ts";
14
14
  import { type KnownEntry, type ShownCalendar, type ShownDocument } from "./game-view-world.ts";
15
15
  import { type ShownImport } from "./import.ts";
16
16
  import { type SheetGroupData, type SheetValue } from "./sheet.ts";
@@ -67,8 +67,8 @@ export interface PartyMember {
67
67
  mood?: Mood;
68
68
  /** What they are, as the line under a sheet's name says it in the campaign's language: Level 3 Cleric (D-288, D-409). */
69
69
  headline?: string;
70
- /** At the system's dying point, as hp 0, the counters the dashboard shows large in their band (D-310 (7)). */
71
- dying?: DyingCounter[];
70
+ /** At the system's down point, as hp 0 (D-516). */
71
+ down?: true;
72
72
  }
73
73
  /** What the player may see: the party, the open quests and scene and the diary; a page as the player character knows it, whole or one section; or nothing. */
74
74
  export type ViewResult = {
@@ -82,6 +82,8 @@ export type ViewResult = {
82
82
  language?: string;
83
83
  /** The game system's words in the campaign's language, when it has them (D-403). */
84
84
  words?: SystemWords;
85
+ /** The game system's own verbs of the sheet, beside the engine's, which its words translate (D-514). */
86
+ verbs?: Record<string, SheetVerb>;
85
87
  /** The game system the campaign plays, for the dashboard: its name, what it is, and what its source asks a work that uses it to say (D-284). */
86
88
  system?: {
87
89
  name: string;
@@ -238,6 +240,8 @@ export declare const view: import("../core/registry.ts").Command<z.ZodObject<{
238
240
  language?: string;
239
241
  /** The game system's words in the campaign's language, when it has them (D-403). */
240
242
  words?: SystemWords;
243
+ /** The game system's own verbs of the sheet, beside the engine's, which its words translate (D-514). */
244
+ verbs?: Record<string, SheetVerb>;
241
245
  /** The game system the campaign plays, for the dashboard: its name, what it is, and what its source asks a work that uses it to say (D-284). */
242
246
  system?: {
243
247
  name: string;
@@ -27,7 +27,7 @@ import { calendarDayOf, readPresent } from "./game-time.js";
27
27
  import { fuelLeft } from "./game-upkeep.js";
28
28
  import { questText, shownJournal } from "./game-view-journal.js";
29
29
  import { mapText, shownMap } from "./game-view-map.js";
30
- import { dyingOf, sceneNames, seenEffect, shownPlace, shownScene, strangerImage } from "./game-view-place.js";
30
+ import { isDown, sceneNames, seenEffect, shownPlace, shownScene, strangerImage } from "./game-view-place.js";
31
31
  import { knownDocuments, knownEntries, knownEntryText, shownCalendar } from "./game-view-world.js";
32
32
  import { campaignSystem, campaignWorld, systemWordsOf } from "./game-world.js";
33
33
  import { importShown } from "./import.js";
@@ -179,15 +179,15 @@ export const view = defineCommand({
179
179
  const system = campaignSystem(root, context);
180
180
  const open = readJourney(root)?.at !== undefined;
181
181
  const companions = world.pages.filter((page) => page.type === "character" && page.fields.role === "companion");
182
- const sight = { root, context, world, knowledge, party: [...players, ...companions] };
182
+ const language = readSettings(root).language;
183
+ const memberWords = system === undefined || language === undefined ? undefined : systemWordsOf(root, system, language, context);
184
+ const sight = { root, context, world, knowledge, party: [...players, ...companions], ...(memberWords === undefined ? {} : { words: memberWords.words }) };
183
185
  if (input.as !== undefined) {
184
186
  return memoryOf({ ...sight, party: isPartyMember(pc) ? world.pages.filter((page) => page.type === "character" && isPartyMember(page)) : [pc] });
185
187
  }
186
188
  if (input.map === true) {
187
189
  return { kind: "map", ...shownMap(sight, measuresOf(root, system), readSettings(root).name) };
188
190
  }
189
- const language = readSettings(root).language;
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;
@@ -196,7 +196,7 @@ export const view = defineCommand({
196
196
  const place = where.length > 0 ? where : chain.length > 0 ? "elsewhere" : open ? "open" : undefined;
197
197
  const image = shownImage(root, context, world, page, (base) => knowsPage(knowledge, base));
198
198
  const mood = livingMood(page);
199
- const dying = dyingOf(world, system, page);
199
+ const down = isDown(world, system, page);
200
200
  const headline = sheetHeadline(world, system, page, memberWords);
201
201
  const icon = tokenIcon(world, system, page);
202
202
  return {
@@ -212,7 +212,7 @@ export const view = defineCommand({
212
212
  return { ...seenEffect(sight, effect), ...(burns === undefined ? {} : { burns }) };
213
213
  }),
214
214
  ...(mood === "neutral" ? {} : { mood }),
215
- ...(dying === undefined ? {} : { dying }),
215
+ ...(down ? { down: true } : {}),
216
216
  ...(headline === undefined ? {} : { headline }),
217
217
  };
218
218
  };
@@ -243,6 +243,7 @@ export const view = defineCommand({
243
243
  campaign: settings.name,
244
244
  ...(settings.language === undefined ? {} : { language: settings.language }),
245
245
  ...(words === undefined ? {} : { words }),
246
+ ...(system === undefined || Object.keys(system.sheetVerbs).length === 0 ? {} : { verbs: system.sheetVerbs }),
246
247
  ...(system === undefined ? {} : { system: { name: system.name, title: system.title, ...(system.attribution === undefined ? {} : { attribution: system.attribution }) } }),
247
248
  ...(now === undefined ? {} : { now: formatGameDate(now) }),
248
249
  ...(today === undefined ? {} : { calendar: today }),
@@ -182,9 +182,9 @@ function progressionFields(world, scope) {
182
182
  value: value.value,
183
183
  reads: value.from.map((from) => ({ list: progression.lists[0], item: from.name, value: from.level })),
184
184
  }));
185
- const features = progression.features.length === 0 ? [] : [{
185
+ const features = progression.features.length + progression.written.length === 0 ? [] : [{
186
186
  field: progression.featuresField,
187
- value: progression.features.map((feature) => feature.name).join(", "),
187
+ value: [...progression.features.map((feature) => feature.name), ...progression.written].join(", "),
188
188
  reads: progression.from.map((from) => ({ list: from.list, item: from.name, value: from.level ?? 1 })),
189
189
  }];
190
190
  return [...values, ...features];
@@ -305,7 +305,8 @@ export function itemLines(world, fields, list, names, explained = false) {
305
305
  function progressedField(world, scope, field) {
306
306
  const found = givenFields(world, scope).find((worked) => comparableText(worked.field) === comparableText(field.trim()));
307
307
  const list = found === undefined ? undefined : itemList(world, found.field);
308
- if (found === undefined) {
308
+ // The features are written too, beside those the rows give (PRO-3).
309
+ if (found === undefined || comparableText(found.field) === comparableText(scope.progression()?.featuresField ?? "")) {
309
310
  return undefined;
310
311
  }
311
312
  // A formula of the items' pages comes from what it reads, as the bonus an item gives, and from its list (PRO-5); the rows, from the lists alone.
@@ -739,10 +740,10 @@ function formulaScope(world, fields) {
739
740
  }
740
741
  const key = keys.get(comparableText(name));
741
742
  const value = key === undefined ? undefined : fields[key];
742
- // The effects read by their names, as has(effects, Grappled) (FOR-2).
743
+ // The effects read by their names, as has(effects, Grappled) (FOR-2); one named in the campaign's language by the system's English, Afferrato as Grappled (D-403).
743
744
  if (comparableText(name) === "effects") {
744
745
  const read = readEffects(value);
745
- return "effects" in read ? read.effects.map((effect) => effect.name) : [];
746
+ return "effects" in read ? read.effects.map((effect) => systemName(world.words, effect.name)) : [];
746
747
  }
747
748
  return value === undefined ? missingValue(world, fields, name) : withAlwaysIn(world, fields, name, value);
748
749
  },
@@ -797,3 +798,8 @@ function isSystemCounter(world, field) {
797
798
  function keyOf(fields, field) {
798
799
  return sameName(Object.keys(fields), field);
799
800
  }
801
+ /** The English name the system's words give a name written in the campaign's language, Grappled for Afferrato (D-403); the name itself when they give none. */
802
+ function systemName(words, name) {
803
+ const written = comparableText(name.trim());
804
+ return Object.entries(words ?? {}).find(([, word]) => comparableText(word) === written)?.[0] ?? name;
805
+ }
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
- import { type PageType, type TextMode } from "../pages/index.ts";
2
+ import type { Context } from "../core/context.ts";
3
+ import { type Page, type PageType, type TextMode, type World } from "../pages/index.ts";
3
4
  /** What a write did, on a page or on a copy in the open scene. */
4
5
  interface WriteResult {
5
6
  page: string;
@@ -49,4 +50,10 @@ export declare const write: import("../core/registry.ts").Command<z.ZodObject<{
49
50
  here: z.ZodOptional<z.ZodBoolean>;
50
51
  why: z.ZodOptional<z.ZodString>;
51
52
  }, z.core.$strip>, WriteResult>;
53
+ /**
54
+ * Sets fields on a page for a package's code, as write --set does (D-511, D-514): the same checks, a number on a counter keeping its maximum, a field the
55
+ * system works out left out, the maxima worked out again. In the log, counter-changed for a counter, public when the page concerns the player, and
56
+ * page-updated for the other fields; nothing for a value that stays. It throws what write refuses, with how to fix it, and writes nothing.
57
+ */
58
+ export declare function writePackageFields(root: string, context: Context, world: World, page: Page, values: Record<string, number | string>, why: string): void;
52
59
  export {};
@@ -120,30 +120,7 @@ export const write = defineCommand({
120
120
  const here = input.here === true ? hereOf(root, world, reference.name, existing, type, fields) : undefined;
121
121
  const positioned = type === "place" ? positionToWrite(world, reference.name, here === undefined ? fields : hereFields(here, fields)) : { change: fields, placed: { notes: [] } };
122
122
  fields = positioned.change;
123
- conditionsAsList(existing, fields);
124
- checkFieldNames(type, fields);
125
- checkFieldChange(type, fields);
126
- environmentAsSet(world, existing, type, reference.name, fields);
127
- checkValues(fields);
128
- // A page that keeps the sheet, as it will be written, takes only the names the sheet closes (D-435).
129
- const asWritten = { name: reference.name, path: existing?.path ?? "", body: existing?.body ?? "", ...(type === undefined ? {} : { type }), fields: { ...existing?.fields, ...fields.set } };
130
- const onSheet = hasSheet(world, asWritten);
131
- checkListValues(system, fields.set ?? {}, onSheet);
132
- checkListValues(system, fields.add ?? {}, onSheet);
133
- checkKnows(world, fields);
134
- if (existing !== undefined) {
135
- if (changedFieldNames(fields).some(passesOn)) {
136
- checkNotCopied(world, open, existing);
137
- }
138
- checkCounters(world, existing, fields.set, coins);
139
- checkUses(world, system, existing, fields.set);
140
- checkClearedCounters(world, existing, ownFieldChange(world, existing, fields), coins);
141
- checkLists(world, existing, fields);
142
- }
143
- checkBase(world, existing?.name ?? reference.name, type, fields.set);
144
- checkBonds(world, system, existing, existing?.name ?? reference.name, fields);
145
- checkLimits(world, system, existing, existing?.name ?? reference.name, fields);
146
- checkEventFields(world, existing, type, fields);
123
+ checkFieldWrite(world, system, open, coins, { existing, name: reference.name, type }, fields);
147
124
  const written = writePage(world, reference.name, input.type, { ...fields, text: input.text, section, append: input.append, secret: input.secret });
148
125
  const { created, changed, mode, retyped } = written;
149
126
  if (changed) {
@@ -265,6 +242,88 @@ export const write = defineCommand({
265
242
  return [[summary, followers, ...result.notes].filter((line) => line !== "").join("\n"), skippedPagesNote(result.problems)].filter((block) => block !== "").join("\n\n");
266
243
  },
267
244
  });
245
+ /**
246
+ * Sets fields on a page for a package's code, as write --set does (D-511, D-514): the same checks, a number on a counter keeping its maximum, a field the
247
+ * system works out left out, the maxima worked out again. In the log, counter-changed for a counter, public when the page concerns the player, and
248
+ * page-updated for the other fields; nothing for a value that stays. It throws what write refuses, with how to fix it, and writes nothing.
249
+ */
250
+ export function writePackageFields(root, context, world, page, values, why) {
251
+ const { coins } = campaignCoins(root, context);
252
+ const system = campaignSystem(root, context);
253
+ if (page.system !== undefined) {
254
+ throw new Error(readOnlyMessage(page, Object.keys(values), world));
255
+ }
256
+ const kept = Object.fromEntries(Object.entries(values).map(([field, value]) => {
257
+ const own = readCounter(valueNamed(page.fields, field));
258
+ return [field, typeof value !== "number" || own?.max === undefined ? value : formatCounter({ ...own, value })];
259
+ }));
260
+ const given = withoutComputed(world, page, oneItemLists(world, kept, page.type), page.name, undefined);
261
+ if (Object.keys(given.set).length === 0) {
262
+ throw new Error(`${given.note ?? "Give the fields to set."} Nothing changed.`);
263
+ }
264
+ const positioned = page.type === "place" ? positionToWrite(world, page.name, { set: asAmounts(world, given.set, coins) }) : { change: { set: asAmounts(world, given.set, coins) }, placed: { notes: [] } };
265
+ const fields = positioned.change;
266
+ checkNoEffects(fields, page);
267
+ checkFieldWrite(world, system, readOpenScene(root), coins, { existing: page, name: page.name, type: page.type }, fields);
268
+ const before = effectiveFields(world, page);
269
+ const written = writePage(world, page.name, undefined, fields);
270
+ if (!written.changed) {
271
+ return;
272
+ }
273
+ const now = withPage(world, page, written.page);
274
+ const limits = systemProblems(root, context).length === 0 ? workedLimitsChange(system, world, page, now, written.page) : { set: {}, unset: [] };
275
+ const after = Object.keys(limits.set).length > 0 || limits.unset.length > 0 ? writePage(now, page.name, undefined, { set: limits.set, unset: limits.unset }).page : written.page;
276
+ const counters = Object.keys(fields.set ?? {}).filter((field) => readCounter(valueNamed(page.fields, field)) !== undefined || valueNamed(system?.fields ?? {}, field) === "counter");
277
+ const others = Object.fromEntries(Object.entries(fields.set ?? {}).filter(([field, value]) => !counters.includes(field) && valueNamed(page.fields, field) !== value));
278
+ const visibility = concernsPlayer(world, page) ? "public" : "hidden";
279
+ const shown = (value) => {
280
+ const counter = readCounter(value);
281
+ return value === undefined ? "0" : counter === undefined ? String(value) : String(formatCounter(counter));
282
+ };
283
+ for (const field of counters) {
284
+ const [was, is] = [shown(valueNamed(before, field)), shown(valueNamed(effectiveFields(withPage(world, page, after), after), field))];
285
+ if (was !== is) {
286
+ appendLogEntry(root, newDatedLogEntry(root, context, "counter-changed", visibility, { page: page.name, field, before: was, after: is, why }));
287
+ }
288
+ }
289
+ if (Object.keys(others).length > 0) {
290
+ appendLogEntry(root, newDatedLogEntry(root, context, "page-updated", "hidden", { page: page.name, type: page.type, set: others, why }));
291
+ }
292
+ if (positioned.placed.origin !== undefined) {
293
+ writeOrigin(root, context, withPage(world, page, after), positioned.placed.origin);
294
+ }
295
+ }
296
+ /**
297
+ * The checks of write on what it is about to write on a page, new or not, and on its fields (D-435, D-514): their names and values, the lists the sheet
298
+ * closes, a creature's copies in the open scene, counters, uses, the base, bonds, limits and an event's fields. It throws what is wrong, with how to fix it.
299
+ */
300
+ function checkFieldWrite(world, system, open, coins, target, fields) {
301
+ const { existing, name, type } = target;
302
+ conditionsAsList(existing, fields);
303
+ checkFieldNames(type, fields);
304
+ checkFieldChange(type, fields);
305
+ environmentAsSet(world, existing, type, name, fields);
306
+ checkValues(fields);
307
+ // A page that keeps the sheet, as it will be written, takes only the names the sheet closes (D-435).
308
+ const asWritten = { name, path: existing?.path ?? "", body: existing?.body ?? "", ...(type === undefined ? {} : { type }), fields: { ...existing?.fields, ...fields.set } };
309
+ const onSheet = hasSheet(world, asWritten);
310
+ checkListValues(system, fields.set ?? {}, onSheet);
311
+ checkListValues(system, fields.add ?? {}, onSheet);
312
+ checkKnows(world, fields);
313
+ if (existing !== undefined) {
314
+ if (changedFieldNames(fields).some(passesOn)) {
315
+ checkNotCopied(world, open, existing);
316
+ }
317
+ checkCounters(world, existing, fields.set, coins);
318
+ checkUses(world, system, existing, fields.set);
319
+ checkClearedCounters(world, existing, ownFieldChange(world, existing, fields), coins);
320
+ checkLists(world, existing, fields);
321
+ }
322
+ checkBase(world, existing?.name ?? name, type, fields.set);
323
+ checkBonds(world, system, existing, existing?.name ?? name, fields);
324
+ checkLimits(world, system, existing, existing?.name ?? name, fields);
325
+ checkEventFields(world, existing, type, fields);
326
+ }
268
327
  /** "torce 7" written in an inventory: a count inside a text, which nothing counts, and how goods are counted instead (STK-10). */
269
328
  function countedTextNotes(existing, page) {
270
329
  const field = containerFieldOf(page.type);
@@ -343,7 +402,7 @@ function checkNoEffects(change, page) {
343
402
  return;
344
403
  }
345
404
  if (changedFieldNames(change).some((name) => comparableText(name) === "effects")) {
346
- throw new Error('effects change only with the effect command: action add with a name, for how long and the values it gives, such as name "Scudo della fede", for 10m, set bonus-ac=2; action end to take one away. Nothing changed.');
405
+ throw new Error('effects change only with the effect command: action add with a name, for how long and the values it gives, such as name "Protezione", for 10m, set bonus-armor=2; action end to take one away. Nothing changed.');
347
406
  }
348
407
  }
349
408
  /** A standard field written in another case, such as Status, would be a field the engine does not read: refused before any other check. */
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { withExamples } from "./examples.js";
2
3
  import { firstSentence } from "./text.js";
3
4
  const generatedNotice = "<!-- Generated from the definitions of the commands: do not edit it by hand. After changing a command, run npm run docs. -->";
4
5
  /**
@@ -15,10 +16,10 @@ function commandSection(command) {
15
16
  const required = schema.required ?? [];
16
17
  const parameters = Object.entries(schema.properties ?? {}).map(([name, field]) => parameterLine(name, field, required.includes(name)));
17
18
  const positionals = command.positionals?.length ? ` Positional parameters: ${command.positionals.map(code).join(", ")}.` : "";
18
- return [`### ${command.name}`, firstSentence(command.description), `Read-only: ${command.readOnly ? "yes" : "no"}.${positionals}`, parameters.length > 0 ? parameters.join("\n") : "No parameters."].join("\n\n");
19
+ return [`### ${command.name}`, firstSentence(withExamples(command.description)), `Read-only: ${command.readOnly ? "yes" : "no"}.${positionals}`, parameters.length > 0 ? parameters.join("\n") : "No parameters."].join("\n\n");
19
20
  }
20
21
  function parameterLine(name, field, required) {
21
- const description = typeof field === "object" && field.description ? `: ${field.description}` : "";
22
+ const description = typeof field === "object" && field.description ? `: ${withExamples(field.description)}` : "";
22
23
  return `- ${code(name)} (${code(typeText(field))}, ${required ? "required" : "optional"})${description}`;
23
24
  }
24
25
  /** The type of a parameter from its JSON Schema, such as string | string[]. */
@@ -0,0 +1,18 @@
1
+ /** The npm scope of the packages RPG Engine publishes, verified: their code runs without a yes (D-441). */
2
+ export declare const ourScope = "@rpgengine/";
3
+ /**
4
+ * Whether the code of the package in this folder may run (D-478, D-511): one the engine ships, outside npm's folders; one of ours from npm; one installed from
5
+ * a folder or a file of the player's; or another's the player said yes to, at this version and with these files.
6
+ */
7
+ export declare function packageCodeMayRun(folder: string): boolean;
8
+ /**
9
+ * The fingerprint of a package's files as installed: every file but those npm or git keep beside them, by its path and its bytes. Worked out again only when
10
+ * a file's size or time changed: it is asked at each load of the package's code.
11
+ */
12
+ export declare function packageFingerprint(folder: string): string;
13
+ /** Records the player's yes to a package installed in a folder of npm's packages: its version and its files as they are now. */
14
+ export declare function recordConsent(folder: string, name: string, version: string): void;
15
+ /** Takes the player's yes to a package away, as when it leaves this computer. */
16
+ export declare function dropConsent(folder: string, name: string): void;
17
+ /** Whether the player said yes to this package's code as it is installed now: its name, its version and its files. */
18
+ export declare function hasConsent(folder: string, name: string, version: string): boolean;