rpg-engine 0.4.1 → 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 (231) hide show
  1. package/README.md +1 -1
  2. package/dist/campaign/settings.d.ts +1 -0
  3. package/dist/campaign/settings.js +6 -5
  4. package/dist/command-line.js +12 -5
  5. package/dist/commands/advance.js +1 -1
  6. package/dist/commands/ask.d.ts +37 -2
  7. package/dist/commands/ask.js +106 -35
  8. package/dist/commands/change.js +28 -17
  9. package/dist/commands/config.d.ts +1 -1
  10. package/dist/commands/config.js +69 -21
  11. package/dist/commands/effect.js +42 -23
  12. package/dist/commands/find.js +1 -1
  13. package/dist/commands/game-adventures.js +2 -2
  14. package/dist/commands/game-catalog.d.ts +13 -0
  15. package/dist/commands/game-catalog.js +26 -2
  16. package/dist/commands/game-checks.js +23 -21
  17. package/dist/commands/{game-hit-dice.d.ts → game-dice-pool.d.ts} +3 -3
  18. package/dist/commands/{game-hit-dice.js → game-dice-pool.js} +7 -7
  19. package/dist/commands/game-effects.d.ts +12 -4
  20. package/dist/commands/game-effects.js +21 -13
  21. package/dist/commands/game-examples.d.ts +22 -0
  22. package/dist/commands/game-examples.js +72 -0
  23. package/dist/commands/game-extension-list.d.ts +31 -3
  24. package/dist/commands/game-extension-list.js +94 -6
  25. package/dist/commands/game-images.d.ts +1 -1
  26. package/dist/commands/game-images.js +3 -2
  27. package/dist/commands/game-library.d.ts +3 -0
  28. package/dist/commands/game-library.js +2 -2
  29. package/dist/commands/game-mode.js +1 -1
  30. package/dist/commands/game-package-code.d.ts +87 -0
  31. package/dist/commands/game-package-code.js +648 -0
  32. package/dist/commands/game-package-hooks.d.ts +37 -0
  33. package/dist/commands/game-package-hooks.js +116 -0
  34. package/dist/commands/game-recipes.js +2 -2
  35. package/dist/commands/game-reminders.d.ts +5 -2
  36. package/dist/commands/game-reminders.js +7 -4
  37. package/dist/commands/game-rules.d.ts +4 -1
  38. package/dist/commands/game-rules.js +7 -1
  39. package/dist/commands/game-upkeep.js +3 -3
  40. package/dist/commands/game-view-place.d.ts +8 -20
  41. package/dist/commands/game-view-place.js +16 -35
  42. package/dist/commands/game-widgets.d.ts +42 -8
  43. package/dist/commands/game-widgets.js +182 -31
  44. package/dist/commands/game-world.d.ts +32 -3
  45. package/dist/commands/game-world.js +113 -24
  46. package/dist/commands/image.js +1 -1
  47. package/dist/commands/init.js +2 -2
  48. package/dist/commands/mode.d.ts +1 -1
  49. package/dist/commands/package.d.ts +15 -1
  50. package/dist/commands/package.js +96 -24
  51. package/dist/commands/progression.d.ts +2 -0
  52. package/dist/commands/progression.js +7 -2
  53. package/dist/commands/roll.d.ts +2 -0
  54. package/dist/commands/roll.js +50 -24
  55. package/dist/commands/rules.js +6 -4
  56. package/dist/commands/scene.d.ts +2 -2
  57. package/dist/commands/scene.js +13 -10
  58. package/dist/commands/sheet.js +10 -1
  59. package/dist/commands/status.d.ts +1 -0
  60. package/dist/commands/status.js +14 -4
  61. package/dist/commands/trade.js +6 -4
  62. package/dist/commands/translate.js +2 -2
  63. package/dist/commands/travel.js +1 -1
  64. package/dist/commands/validate.js +2 -2
  65. package/dist/commands/view.d.ts +12 -4
  66. package/dist/commands/view.js +11 -8
  67. package/dist/commands/worked-out.js +11 -5
  68. package/dist/commands/write.d.ts +8 -1
  69. package/dist/commands/write.js +84 -25
  70. package/dist/core/command-reference.js +3 -2
  71. package/dist/core/consents.d.ts +18 -0
  72. package/dist/core/consents.js +93 -0
  73. package/dist/core/context.d.ts +68 -27
  74. package/dist/core/context.js +3 -1
  75. package/dist/core/examples.d.ts +25 -0
  76. package/dist/core/examples.js +19 -0
  77. package/dist/core/files.d.ts +2 -0
  78. package/dist/core/files.js +10 -1
  79. package/dist/core/package-api.d.ts +388 -0
  80. package/dist/core/package-declarations.d.ts +102 -0
  81. package/dist/core/package-declarations.js +81 -0
  82. package/dist/core/registry.d.ts +4 -0
  83. package/dist/core/text.d.ts +5 -0
  84. package/dist/core/text.js +12 -0
  85. package/dist/dashboard/acts.js +31 -24
  86. package/dist/dashboard/address.js +4 -1
  87. package/dist/dashboard/api.js +65 -3
  88. package/dist/dashboard/app.js +222 -98
  89. package/dist/dashboard/ask-card.js +169 -0
  90. package/dist/dashboard/asked-dice.js +57 -0
  91. package/dist/dashboard/dice/tray.js +6 -4
  92. package/dist/dashboard/extension-widgets.js +136 -16
  93. package/dist/dashboard/faces.js +6 -4
  94. package/dist/dashboard/help.js +10 -3
  95. package/dist/dashboard/i18n/ar.json +34 -29
  96. package/dist/dashboard/i18n/cs.json +34 -29
  97. package/dist/dashboard/i18n/da.json +34 -29
  98. package/dist/dashboard/i18n/de.json +34 -29
  99. package/dist/dashboard/i18n/el.json +34 -29
  100. package/dist/dashboard/i18n/es.json +34 -29
  101. package/dist/dashboard/i18n/fi.json +34 -29
  102. package/dist/dashboard/i18n/fr.json +34 -29
  103. package/dist/dashboard/i18n/he.json +34 -29
  104. package/dist/dashboard/i18n/hi.json +34 -29
  105. package/dist/dashboard/i18n/hu.json +34 -29
  106. package/dist/dashboard/i18n/is.json +34 -29
  107. package/dist/dashboard/i18n/it.json +34 -29
  108. package/dist/dashboard/i18n/ja.json +34 -29
  109. package/dist/dashboard/i18n/ko.json +34 -29
  110. package/dist/dashboard/i18n/nb.json +34 -29
  111. package/dist/dashboard/i18n/nl.json +34 -29
  112. package/dist/dashboard/i18n/pl.json +34 -29
  113. package/dist/dashboard/i18n/pt.json +34 -29
  114. package/dist/dashboard/i18n/ro.json +34 -29
  115. package/dist/dashboard/i18n/ru.json +34 -29
  116. package/dist/dashboard/i18n/sv.json +34 -29
  117. package/dist/dashboard/i18n/tr.json +34 -29
  118. package/dist/dashboard/i18n/uk.json +34 -29
  119. package/dist/dashboard/i18n/zh.json +34 -29
  120. package/dist/dashboard/icons.js +4 -1
  121. package/dist/dashboard/kit.js +35 -0
  122. package/dist/dashboard/labels.js +1 -0
  123. package/dist/dashboard/pack-card.js +97 -0
  124. package/dist/dashboard/package-page.js +50 -0
  125. package/dist/dashboard/packages.js +180 -24
  126. package/dist/dashboard/page-code.js +248 -0
  127. package/dist/dashboard/party.js +13 -14
  128. package/dist/dashboard/people.js +4 -0
  129. package/dist/dashboard/person-panel.js +110 -0
  130. package/dist/dashboard/place-map-view.js +11 -6
  131. package/dist/dashboard/rolls.js +2 -2
  132. package/dist/dashboard/scene.js +12 -9
  133. package/dist/dashboard/settings.js +55 -9
  134. package/dist/dashboard/sheet.js +21 -13
  135. package/dist/dashboard/status.js +69 -15
  136. package/dist/dashboard/style.css +859 -574
  137. package/dist/dashboard/top.js +75 -25
  138. package/dist/dashboard/turns.js +34 -13
  139. package/dist/dashboard/widgets.js +9 -2
  140. package/dist/dashboard-server.js +246 -11
  141. package/dist/dice/roll-dice.js +1 -1
  142. package/dist/effects/effect.d.ts +7 -4
  143. package/dist/effects/effect.js +12 -9
  144. package/dist/extensions/engine.d.ts +4 -0
  145. package/dist/extensions/engine.js +74 -0
  146. package/dist/extensions/extension.d.ts +28 -33
  147. package/dist/extensions/extension.js +37 -46
  148. package/dist/extensions/index.d.ts +4 -3
  149. package/dist/extensions/index.js +5 -2
  150. package/dist/extensions/packages.d.ts +14 -0
  151. package/dist/extensions/packages.js +148 -12
  152. package/dist/extensions/words.d.ts +2 -1
  153. package/dist/extensions/words.js +5 -4
  154. package/dist/index.d.ts +1 -3
  155. package/dist/mcp-server.js +52 -15
  156. package/dist/page-words.d.ts +4 -0
  157. package/dist/page-words.js +4 -4
  158. package/dist/page.d.ts +218 -0
  159. package/dist/page.js +2 -0
  160. package/dist/pages/index.d.ts +1 -1
  161. package/dist/pages/index.js +1 -1
  162. package/dist/pages/load.d.ts +7 -1
  163. package/dist/pages/load.js +10 -5
  164. package/dist/pages/page-file.js +1 -1
  165. package/dist/pages/stack-writes.js +5 -4
  166. package/dist/pages/standard-fields.d.ts +2 -0
  167. package/dist/pages/standard-fields.js +8 -1
  168. package/dist/pages/world.d.ts +8 -0
  169. package/dist/pages/world.js +9 -2
  170. package/dist/systems/game-system.d.ts +61 -30
  171. package/dist/systems/game-system.js +159 -50
  172. package/dist/systems/index.d.ts +3 -3
  173. package/dist/systems/index.js +3 -3
  174. package/dist/systems/system-code.d.ts +29 -88
  175. package/dist/systems/system-code.js +68 -23
  176. package/dist/systems/words.d.ts +2 -0
  177. package/dist/systems/words.js +11 -0
  178. package/dist/testing.d.ts +76 -0
  179. package/dist/testing.js +197 -0
  180. package/instructions/combat.md +2 -2
  181. package/instructions/core.md +2 -2
  182. package/instructions/dashboard.md +1 -1
  183. package/instructions/mentor-tutorial.md +1 -1
  184. package/instructions/play.md +2 -2
  185. package/instructions/setup.md +1 -1
  186. package/package.json +15 -2
  187. package/systems/5e/LICENSE.md +13 -3
  188. package/systems/5e/dist/dying.js +83 -16
  189. package/systems/5e/dist/index.js +2 -2
  190. package/systems/5e/dist/page-style.js +634 -0
  191. package/systems/5e/dist/page.js +166 -0
  192. package/systems/5e/dist/shown.js +23 -0
  193. package/systems/5e/instructions/combat.md +1 -0
  194. package/systems/5e/package.json +4 -2
  195. package/systems/5e/system.yaml +35 -7
  196. package/systems/5e/versions/srd-5.1/system.yaml +2 -0
  197. package/systems/5e/words/ar.yaml +30 -0
  198. package/systems/5e/words/cs.yaml +30 -0
  199. package/systems/5e/words/da.yaml +30 -0
  200. package/systems/5e/words/de.yaml +30 -0
  201. package/systems/5e/words/el.yaml +30 -0
  202. package/systems/5e/words/es.yaml +30 -0
  203. package/systems/5e/words/fi.yaml +30 -0
  204. package/systems/5e/words/fr.yaml +30 -0
  205. package/systems/5e/words/he.yaml +30 -0
  206. package/systems/5e/words/hi.yaml +30 -0
  207. package/systems/5e/words/hu.yaml +30 -0
  208. package/systems/5e/words/is.yaml +30 -0
  209. package/systems/5e/words/it.yaml +30 -0
  210. package/systems/5e/words/ja.yaml +30 -0
  211. package/systems/5e/words/ko.yaml +30 -0
  212. package/systems/5e/words/nb.yaml +30 -0
  213. package/systems/5e/words/nl.yaml +30 -0
  214. package/systems/5e/words/pl.yaml +30 -0
  215. package/systems/5e/words/pt.yaml +30 -0
  216. package/systems/5e/words/ro.yaml +30 -0
  217. package/systems/5e/words/ru.yaml +30 -0
  218. package/systems/5e/words/sv.yaml +30 -0
  219. package/systems/5e/words/tr.yaml +30 -0
  220. package/systems/5e/words/uk.yaml +30 -0
  221. package/systems/5e/words/zh.yaml +30 -0
  222. package/dist/commands/game-extensions.d.ts +0 -34
  223. package/dist/commands/game-extensions.js +0 -182
  224. package/dist/commands/game-system-code.d.ts +0 -25
  225. package/dist/commands/game-system-code.js +0 -172
  226. package/dist/dashboard/death-save.js +0 -67
  227. package/dist/dashboard/dying.js +0 -46
  228. package/dist/dashboard/save-outcome.js +0 -42
  229. package/dist/dashboard/spend.js +0 -115
  230. package/dist/extensions/api.d.ts +0 -155
  231. /package/dist/{extensions/api.js → core/package-api.js} +0 -0
@@ -25,11 +25,11 @@ export function createWorld(root) {
25
25
  */
26
26
  export function loadWorld(root, options = {}) {
27
27
  const campaign = readPages(root);
28
- const { system, language, missingSystem, noSystem, rigor } = options;
28
+ const { system, language, words, missingSystem, noSystem, rigor } = options;
29
29
  if (system === undefined) {
30
30
  return frozen({ root, ...campaign, language, missingSystem, noSystem, ...(rigor === undefined ? {} : { rigor }) });
31
31
  }
32
- const systemPages = packagePages(system.folder, system.name);
32
+ const systemPages = system.version === undefined ? packagePages(system.folder, system.name) : versionPages(packagePages(system.folder, system.name), packagePages(system.version.folder, system.name));
33
33
  const { name, title, fields, formulas, progression, itemFormulas, alwaysIn, uses, statusLine, load, lengthUnit, bonusLists, bonusWhile } = system;
34
34
  const problems = [...campaign.problems, ...systemPages.problems];
35
35
  return frozen({
@@ -38,6 +38,7 @@ export function loadWorld(root, options = {}) {
38
38
  problems,
39
39
  system: { name, title, language: system.language, fields, formulas, progression, itemFormulas, alwaysIn, uses, statusLine, load, lengthUnit, bonusLists, bonusWhile, pages: systemPages.pages },
40
40
  language,
41
+ ...(words === undefined ? {} : { words }),
41
42
  ...(rigor === undefined ? {} : { rigor }),
42
43
  });
43
44
  }
@@ -341,6 +342,12 @@ function packagePages(folder, system) {
341
342
  return known;
342
343
  }
343
344
  const packages = new Map();
345
+ /** A system's pages with those of the version of its rules over them (VER-3): a page of the version takes the place of a common one with its name. */
346
+ function versionPages(common, version) {
347
+ const names = new Set(version.pages.map((page) => comparableText(page.name)));
348
+ const pages = [...common.pages.filter((page) => !names.has(comparableText(page.name))), ...version.pages].sort((first, second) => (first.path < second.path ? -1 : 1));
349
+ return { pages, problems: [...common.problems, ...version.problems] };
350
+ }
344
351
  function readPages(root, system) {
345
352
  const pages = [];
346
353
  const problems = [];
@@ -2,15 +2,32 @@ import { type FieldKind } from "../core/field-kind.ts";
2
2
  import { type Formula, type SystemFormulas } from "../core/formula.ts";
3
3
  import { type InstructionPart } from "../core/instruction-parts.ts";
4
4
  import { type ImperialUnits } from "../core/length.ts";
5
+ import { type DeclaredWidget, type FigureSize } from "../core/package-declarations.ts";
5
6
  import type { ProgressionRule } from "../core/progression-rule.ts";
6
7
  /** The file that makes a folder a game system and says what it is. */
7
8
  export declare const systemFileName = "system.yaml";
9
+ /** The setting by which a campaign plays one of the versions of its system's rules (VER-1): the engine's name for it, whatever the system. */
10
+ export declare const rulesetSetting = "ruleset";
8
11
  /**
9
12
  * What the player does with an item of the sheet on the dashboard, said as their own sentence to the master (D-495): the engine's verbs, whose sentences
10
- * the page has in every language; a system says which fields take which. Talking to someone comes from the people, never from the sheet.
13
+ * the page has in every language; a system declares its own beside them in sheet-verbs (D-514), and says which fields take which. Talking to someone comes
14
+ * from the people, never from the sheet.
11
15
  */
12
- export declare const actVerbs: readonly ["attack", "cast", "use", "equip", "unequip", "prepare"];
13
- export type ActVerb = (typeof actVerbs)[number];
16
+ export declare const actVerbs: readonly ["attack", "use", "equip", "unequip"];
17
+ /** One of the engine's verbs, or one the system declares. */
18
+ export type ActVerb = string;
19
+ /**
20
+ * A verb a system declares (D-514), in its language, its words translating it: its name alone, what it does with a thing, the player's sentence, and the
21
+ * sentences on someone, at a square and on oneself when it lets the player choose one.
22
+ */
23
+ export interface SheetVerb {
24
+ label: string;
25
+ title: string;
26
+ says: string;
27
+ on?: string;
28
+ at?: string;
29
+ self?: string;
30
+ }
14
31
  /** A recipe of the system (D-185, DAT-4): the fields it brings to their maximum or to a value, the occasions it ends, the rules to read for the rest. */
15
32
  export interface Recipe {
16
33
  name: string;
@@ -88,24 +105,10 @@ export interface SystemCheck {
88
105
  needs: CheckAtom;
89
106
  say: string;
90
107
  }
91
- /**
92
- * When the dashboard shows the panel of the dying, and its counters by their sides (D-314, D-461): at a counter's value, such as hp 0. What the dying point
93
- * does is the system's code (D-448).
94
- */
95
- export interface Dying {
108
+ /** When one of the party is down, at a counter's value or under it, such as hp 0 (D-314, D-516). What being down does is the system's code (D-448). */
109
+ export interface Down {
96
110
  field: string;
97
111
  value: number;
98
- show: {
99
- successes?: string;
100
- failures?: string;
101
- };
102
- /** What the dashboard calls one whose successes are full, as the 5e's Stable. */
103
- stable?: string;
104
- /** The short words of each side's marks, as Successes; the field's label where none. */
105
- marks: {
106
- successes?: string;
107
- failures?: string;
108
- };
109
112
  }
110
113
  /** A threshold (D-184, DAT-3): a field, the value at which it matters, or none for every change, and the title of the rule to read. */
111
114
  export interface Threshold {
@@ -200,6 +203,12 @@ export interface GameSystem {
200
203
  name: string;
201
204
  /** The folder that holds its system.yaml and its pages. */
202
205
  folder: string;
206
+ /** The version of its rules it is read with, when it has versions (VER-1): its name, its title, and its folder, whose pages win over the common ones (VER-3). */
207
+ version?: {
208
+ name: string;
209
+ title?: string;
210
+ folder: string;
211
+ };
203
212
  /** Whether it brings code of its own, as its package.json says (D-448): the engine has loaded it, and calls its hooks. */
204
213
  code: boolean;
205
214
  /** What it is, for messages: "the fifth edition, from the SRD 5.1". */
@@ -227,6 +236,7 @@ export interface GameSystem {
227
236
  limit: Formula;
228
237
  coins?: number;
229
238
  weightless?: string;
239
+ bundle?: string;
230
240
  stages?: {
231
241
  name: string;
232
242
  formula: Formula;
@@ -277,6 +287,8 @@ export interface GameSystem {
277
287
  };
278
288
  /** The fields whose items the player acts with on the dashboard, each with its verbs, the first the one a click says (D-495). */
279
289
  sheetActions?: Record<string, ActVerb[]>;
290
+ /** Its own verbs beside the engine's, by name (D-514). */
291
+ sheetVerbs: Record<string, SheetVerb>;
280
292
  /** The names a list field accepts, by field, such as the skills of save-proficiencies (SYS-8). */
281
293
  values: Record<string, string[]>;
282
294
  /** The names a list field accepts on a page that keeps the sheet, the player character's and a companion's, as the languages (D-435). */
@@ -292,8 +304,12 @@ export interface GameSystem {
292
304
  recipes: Recipe[];
293
305
  /** The names of its conditions (D-186, DAT-6). */
294
306
  conditions: string[];
295
- /** By condition, its drawing on a token and in Combat (D-419): the d of an SVG path on a grid of 24. */
307
+ /** By the name of a condition or any effect, its drawing on a token, in Combat and in its chip (D-419, D-516): the d of an SVG path on a grid of 24. */
296
308
  conditionIcons: Record<string, string>;
309
+ /** Its icons, widgets and figures on the dashboard, as an extension's (D-502, D-510, D-514): its code's hooks show its widgets. */
310
+ icons: Record<string, string>;
311
+ widgets: DeclaredWidget[];
312
+ figures: Record<string, FigureSize>;
297
313
  /** What can break what someone keeps alive, when the game has it (EFF-14). */
298
314
  /** The lists a character binds items in, as attunement (BND-1): at most so many, each an item whose field asks for it, with the rules to read. */
299
315
  bonds: Record<string, {
@@ -330,8 +346,8 @@ export interface GameSystem {
330
346
  keeping?: Keeping;
331
347
  /** What a fight follows on the dashboard (D-314). */
332
348
  combat?: CombatData;
333
- /** The panel of the dying on the dashboard (D-314). */
334
- dying?: Dying;
349
+ /** When one of the party is down (D-516). */
350
+ down?: Down;
335
351
  /** What cannot be true together, which the engine says to the master (CHK-2). */
336
352
  checks: SystemCheck[];
337
353
  /** By counter, the counter it shields, which loses from it first, as temp-hp shields hp (DAT-14). */
@@ -371,19 +387,34 @@ export declare function rollName(system: GameSystem, dice: string, language: str
371
387
  /** The systems installed in these folders, nearest folder first: each folder in them with a system.yaml. A name found twice is the nearest one. */
372
388
  export declare function installedSystems(folders: string[]): GameSystem[];
373
389
  /** What a campaign may add to its game system in campaign.yaml (CAM-1): its own fields, tables, formulas, counters, recipes, line of the player character and travel. */
374
- export declare const campaignDataNames: readonly ["fields", "tables", "computed", "counters", "recipes", "status-line", "travel", "values"];
390
+ export declare const campaignDataNames: readonly ["fields", "tables", "computed", "counters", "recipes", "status-line", "travel", "values", "condition-icons"];
375
391
  /** What campaign.yaml adds to the game system, as it writes it: checked when the system is read with it (CAM-3). */
376
392
  export type CampaignData = Partial<Record<(typeof campaignDataNames)[number], unknown>>;
393
+ /** What an extension or the campaign adds to the game system (CAM-1, CAM-2): from where, as messages name it, and what. */
394
+ export interface SystemLayer {
395
+ from: string;
396
+ data: CampaignData;
397
+ }
377
398
  /**
378
- * The installed system with what the campaign adds to it, the nearest layer winning (CAM-2); when the additions do not read, the system alone and why (CAM-3).
379
- * Undefined as a system when none is installed by that name.
399
+ * The installed system with the layers over it, in order, the nearest to the campaign last and winning (CAM-2); a layer with which it does not read is left out,
400
+ * with why, and the others stay (CAM-3). Undefined as a system when none is installed by that name.
380
401
  */
381
- export declare function findCampaignSystem(folders: string[], name: string, data: CampaignData): {
402
+ export declare function findCampaignSystem(folders: string[], name: string, layers: SystemLayer[], ruleset?: string): {
382
403
  system?: GameSystem;
383
- problem?: string;
404
+ refused: {
405
+ from: string;
406
+ problem: string;
407
+ }[];
384
408
  };
385
409
  /**
386
- * The installed system with this name, ignoring case, from the nearest folder that has it, with what a campaign adds to it; undefined when none is. Only its own
387
- * system.yaml is read.
410
+ * The installed system with this name, ignoring case, from the nearest folder that has it, with the version of its rules asked, else its first (VER-2); undefined
411
+ * when none is. Only its own system.yaml is read, and its version's.
388
412
  */
389
- export declare function findSystem(folders: string[], name: string, data?: CampaignData): GameSystem | undefined;
413
+ export declare function findSystem(folders: string[], name: string, ruleset?: string): GameSystem | undefined;
414
+ /** The folders a system's pages, rules, words, pictures and instructions come from, in order: its own, then its version's, which wins by name (VER-3). */
415
+ export declare function systemContentFolders(system: {
416
+ folder: string;
417
+ version?: {
418
+ folder: string;
419
+ };
420
+ }): string[];
@@ -5,17 +5,24 @@ import { formulaOf, parseFormula, readFormulas } from "../core/formula.js";
5
5
  import { frozen } from "../core/frozen.js";
6
6
  import { readParts } from "../core/instruction-parts.js";
7
7
  import { lengthHelp, readLength, readSpeed, speedHelp } from "../core/length.js";
8
+ import { declaredWidgets, packagePartsIssues, packagePartsShape } from "../core/package-declarations.js";
9
+ import { files } from "../core/store.js";
8
10
  import { comparableText, sameName } from "../core/text.js";
9
11
  import { readYamlValues } from "../core/yaml-file.js";
10
- import { systemHasCode } from "./system-code.js";
12
+ import { systemApiProblem, systemHasCode } from "./system-code.js";
11
13
  import { systemFolders } from "./system-folders.js";
12
14
  /** The file that makes a folder a game system and says what it is. */
13
15
  export const systemFileName = "system.yaml";
16
+ /** The setting by which a campaign plays one of the versions of its system's rules (VER-1): the engine's name for it, whatever the system. */
17
+ export const rulesetSetting = "ruleset";
18
+ // The folder that holds a system's versions of its rules, each in a folder named after it (VER-1).
19
+ const versionsFolderName = "versions";
14
20
  /**
15
21
  * What the player does with an item of the sheet on the dashboard, said as their own sentence to the master (D-495): the engine's verbs, whose sentences
16
- * the page has in every language; a system says which fields take which. Talking to someone comes from the people, never from the sheet.
22
+ * the page has in every language; a system declares its own beside them in sheet-verbs (D-514), and says which fields take which. Talking to someone comes
23
+ * from the people, never from the sheet.
17
24
  */
18
- export const actVerbs = ["attack", "cast", "use", "equip", "unequip", "prepare"];
25
+ export const actVerbs = ["attack", "use", "equip", "unequip"];
19
26
  // An entry of the sheet: a field, ? when it is written only when it applies, and a field shown beside it in parentheses.
20
27
  const sheetEntryPattern = /^([^\s()?]+)(\?)?(?: \(([^\s()?]+)\))?$/;
21
28
  // The dice a number of the sheet is rolled with: dice alone, as 1d20 or 2d6+1d4 (D-280).
@@ -26,6 +33,11 @@ const rollNamePattern = /^\d*d(?:\d+|%)(?:[kd][hl]\d*)?$/i;
26
33
  const headlineFieldPattern = /\{([^{}]+)\}/g;
27
34
  // A group's icon on the dashboard: the d of an SVG path, its letters and numbers alone (D-284).
28
35
  const iconPattern = /^[Mm][MmLlHhVvCcSsQqTtAaZz\d.,\s+-]*$/;
36
+ /** A sentence of a system's verb, with the {names} the page fills (D-514). */
37
+ function phraseWith(names) {
38
+ const shown = names.map((name) => `{${name}}`).join(" and ");
39
+ return z.string().min(1).refine((text) => names.every((name) => text.includes(`{${name}}`)), `write it with ${shown}, which the page fills`);
40
+ }
29
41
  const recipeSchema = z.object({
30
42
  set: z.record(z.string(), z.union([z.literal("max"), z.number().int()])).optional(),
31
43
  regain: z.record(z.string(), z.union([z.number(), z.string().min(1)])).optional(),
@@ -77,6 +89,11 @@ const gridSchema = z.object({
77
89
  footprints: z.record(z.string().min(1), z.number().int().min(1)).optional(),
78
90
  leaving: z.string().min(1).optional(),
79
91
  }, { error: "write it as a square's length, a diagonal step's cost in squares, the factor of difficult ground and the field of the speed, such as {square: 1.5 m, diagonal: 1, difficult: 2, speed: speed}" }).strict();
92
+ // A setting the setup asks (DAT-10), or the versions of the rules (VER-1): what it is to the player, then its values, each with what it means: a setting at
93
+ // least two, the versions at least one.
94
+ function settingSchema(fewest) {
95
+ return z.record(z.string().min(1), z.union([z.string().min(1), z.object({ means: z.string().min(1), player: z.string().min(1).optional(), without: z.array(z.string().min(1)).optional() }).strict()])).refine((values) => Object.entries(values).every(([key, value]) => (key === "about") === (typeof value === "string")), "give about as what the setting is to the player, in a few words, and each value with what it means, such as {about: how your character levels up, xp: {means: ...}}").refine((values) => Object.keys(values).filter((key) => key !== "about").length >= fewest, fewest === 1 ? "give at least one version, with what it means, such as {srd-5.1: {means: ...}}" : "give at least two values, each with what it means, such as {xp: {means: ...}, milestones: {means: ...}}");
96
+ }
80
97
  const systemSchema = z.object({
81
98
  title: z.string().min(1),
82
99
  language: z.string().regex(/^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/),
@@ -93,9 +110,10 @@ const systemSchema = z.object({
93
110
  limit: z.union([z.string().min(1), z.array(z.union([z.string().min(1), z.number()])).min(1)]),
94
111
  coins: z.number().int().positive().optional(),
95
112
  weightless: z.string().min(1).optional(),
113
+ bundle: z.string().min(1).optional(),
96
114
  stages: z.array(z.object({ name: z.string().min(1), when: z.string().min(1) }).strict()).optional(),
97
115
  }, {
98
- error: "write it as the field of an item's weight, the formula of the limit, and how many coins weigh one unit, such as {field: weight, limit: str * 15, coins: 50}; weightless names the field of an item whose contents weigh nothing; "
116
+ error: "write it as the field of an item's weight, the formula of the limit, and how many coins weigh one unit, such as {field: weight, limit: str * 15, coins: 50}; weightless names the field of an item whose contents weigh nothing, bundle the field of how many pieces one of a kind sold by the bundle holds; "
99
117
  + "stages lists what a load makes a character, the heaviest last, each with when, the formula that says so above 0, such as [{name: Encumbered, when: ceil(load - 5 * str)}]",
100
118
  }).strict().optional(),
101
119
  travel: travelSchema.optional(),
@@ -107,9 +125,19 @@ const systemSchema = z.object({
107
125
  "sheet-cards": z.object({ rail: z.array(z.string().min(1)).optional(), order: z.array(z.string().min(1)).optional(), "at-hand": z.array(z.string().min(1)).optional() }, {
108
126
  error: "write it as the groups the dashboard puts in its rail, the order of the others, and the fields and groups at hand in a fight, such as {rail: [Abilities], order: [Skills, Combat], at-hand: [ac, hp, Attacks]}",
109
127
  }).strict().optional(),
110
- "sheet-actions": z.record(z.string().min(1), z.array(z.enum(actVerbs)).min(1), {
111
- error: `write it as the fields whose items the player acts with on the dashboard, each with its verbs among ${actVerbs.join(", ")}, such as {spells: [cast], inventory: [use, equip]}`,
128
+ "sheet-actions": z.record(z.string().min(1), z.array(z.string().min(1)).min(1), {
129
+ error: `write it as the fields whose items the player acts with on the dashboard, each with its verbs, among ${actVerbs.join(", ")} and those of sheet-verbs, such as {inventory: [use, equip]}`,
112
130
  }).optional(),
131
+ "sheet-verbs": z.record(z.string().regex(/^[a-z][a-z-]*$/, "write a verb's name in lowercase, such as invoke"), z.object({
132
+ label: z.string().min(1),
133
+ title: phraseWith(["item"]),
134
+ says: phraseWith(["item"]),
135
+ "says-on": phraseWith(["item", "target"]).optional(),
136
+ "says-at": phraseWith(["item", "square"]).optional(),
137
+ "says-self": phraseWith(["item"]).optional(),
138
+ }).strict().refine((verb) => [verb["says-on"], verb["says-at"], verb["says-self"]].every((said, _index, all) => (said === undefined) === (all[0] === undefined)), {
139
+ message: "give says-on, says-at and says-self together, for a verb that lets the player choose on whom, or none of them",
140
+ }), { error: 'write it as the system\'s own verbs, each with its words, such as {invoke: {label: Invoke, title: "Invoke {item}", says: "I invoke {item}."}}' }).optional(),
113
141
  "sheet-headline": z.string().min(1).regex(/\{[^{}\s]+\}/, "write it as words with fields in braces, such as Level {level} {classes}").optional(),
114
142
  "sheet-icons": z.record(z.string().min(1), z.string().max(2000).regex(iconPattern, "write it as the d of an SVG path on a grid of 24, its letters and numbers alone, such as M4 12h16")).optional(),
115
143
  "token-icons": z.object({
@@ -182,19 +210,9 @@ const systemSchema = z.object({
182
210
  error: "write it as the counter a fight follows, the words the player hears a foe's in, from full to 0, and the conditions that keep from acting, "
183
211
  + "such as {track: hp, in-words: [unhurt, hurt, badly hurt, down], inactive: [Stunned]}",
184
212
  }).strict().optional(),
185
- dying: z.object({
186
- at: z.string().regex(/^[^\s]+ -?\d+$/, 'write it as "hp 0"'),
187
- show: z.object({ successes: z.string().min(1).optional(), failures: z.string().min(1).optional() }).strict(),
188
- stable: z.string().min(1).optional(),
189
- marks: z.object({ successes: z.string().min(1).optional(), failures: z.string().min(1).optional() }).strict().optional(),
190
- }, {
191
- error: "write it as when the dying begins, the counters the dashboard shows by their sides, what it calls one whose successes are full, and the short words of "
192
- + "each side's marks, such as {at: hp 0, show: {successes: death-successes, failures: death-failures}, stable: Stable, marks: {successes: Successes, failures: Failures}}; "
193
- + "what the dying point does is the system's code (D-448)",
194
- }).strict().refine((dying) => dying.show.successes === undefined || dying.stable !== undefined, {
195
- message: "name what full successes make, which the dashboard says, such as stable: Stable",
196
- path: ["stable"],
197
- }).optional(),
213
+ down: z.object({ at: z.string().regex(/^[^\s]+ -?\d+$/, 'write it as "hp 0"') }, {
214
+ error: "write it as when one of the party is down, such as {at: hp 0}; what being down does, and how the dashboard draws it, is the system's code (D-448, D-516)",
215
+ }).strict().optional(),
198
216
  checks: z.array(z.object({ when: checkAtomSchema, needs: checkAtomSchema, say: z.string().min(1) }, {
199
217
  error: 'write each as what holds, what must hold with it, and the line for the master, such as {when: Stable, needs: hp <= 0, say: "{page} is Stable with {hp}: effect end {page} Stable."}',
200
218
  }).strict()).optional(),
@@ -207,7 +225,10 @@ const systemSchema = z.object({
207
225
  parts: z.object({ list: z.string().min(1), field: z.string().min(1), lists: z.array(z.string().min(1)).optional() }).strict().optional(),
208
226
  experience: z.object({ field: z.string().min(1), table: z.string().min(1), rules: z.string().min(1).optional() }).strict().optional(),
209
227
  }).strict().optional(),
210
- settings: z.record(z.string().min(1), z.record(z.string().min(1), z.union([z.string().min(1), z.object({ means: z.string().min(1), player: z.string().min(1).optional(), without: z.array(z.string().min(1)).optional() }).strict()])).refine((values) => Object.entries(values).every(([key, value]) => (key === "about") === (typeof value === "string")), "give about as what the setting is to the player, in a few words, and each value with what it means, such as {about: how your character levels up, xp: {means: ...}}").refine((values) => Object.keys(values).filter((key) => key !== "about").length >= 2, "give at least two values, each with what it means, such as {xp: {means: ...}, milestones: {means: ...}}")).optional(),
228
+ settings: z.record(z.string().min(1).refine((name) => comparableText(name) !== rulesetSetting, `${rulesetSetting} is the engine's setting of the versions: give this one another name`), settingSchema(2))
229
+ .optional(),
230
+ // Its versions of the rules, each a folder in versions/ (VER-1): a setting of their own, ruleset.
231
+ versions: settingSchema(1).optional(),
211
232
  rewards: z.record(z.string().min(1), z.object({ from: z.string().min(1), overcome: z.string().regex(/^[^\s]+ -?\d+$/, 'write it as "hp 0"') }).strict()).optional(),
212
233
  "item-formulas": z.record(z.string().min(1), z.array(z.string().min(1)).min(1)).optional(),
213
234
  "always-in": z.record(z.string().min(1), z.array(z.string().min(1)).min(1), { error: "write it as lists, each with the names of the pages in it, such as equipped: [Unarmed Strike]" }).optional(),
@@ -218,6 +239,7 @@ const systemSchema = z.object({
218
239
  refill: z.union([z.string().min(1), z.record(z.string().min(1), z.union([z.number(), z.string().min(1)]))]).optional(),
219
240
  shields: z.string().min(1).optional(),
220
241
  }).strict()).optional(),
242
+ ...packagePartsShape,
221
243
  }).strict();
222
244
  /**
223
245
  * The system as a campaign plays it, with the values its settings have (DAT-10): the fields a value leaves out are gone from the sheet, the line, the experience
@@ -266,48 +288,74 @@ export function installedSystems(folders) {
266
288
  return systems;
267
289
  }
268
290
  /** What a campaign may add to its game system in campaign.yaml (CAM-1): its own fields, tables, formulas, counters, recipes, line of the player character and travel. */
269
- export const campaignDataNames = ["fields", "tables", "computed", "counters", "recipes", "status-line", "travel", "values"];
291
+ export const campaignDataNames = ["fields", "tables", "computed", "counters", "recipes", "status-line", "travel", "values", "condition-icons"];
270
292
  /**
271
- * The installed system with what the campaign adds to it, the nearest layer winning (CAM-2); when the additions do not read, the system alone and why (CAM-3).
272
- * Undefined as a system when none is installed by that name.
293
+ * The installed system with the layers over it, in order, the nearest to the campaign last and winning (CAM-2); a layer with which it does not read is left out,
294
+ * with why, and the others stay (CAM-3). Undefined as a system when none is installed by that name.
273
295
  */
274
- export function findCampaignSystem(folders, name, data) {
275
- const system = findSystem(folders, name);
276
- if (system === undefined || campaignDataNames.every((key) => data[key] === undefined || data[key] === null)) {
277
- return { system };
296
+ export function findCampaignSystem(folders, name, layers, ruleset) {
297
+ const found = systemFolders(folders).find((candidate) => comparableText(candidate.name) === comparableText(name.trim()));
298
+ const given = layers.filter((layer) => campaignDataNames.some((key) => layer.data[key] !== undefined && layer.data[key] !== null));
299
+ if (found === undefined) {
300
+ return { refused: [] };
278
301
  }
279
302
  try {
280
- return { system: findSystem(folders, name, data) };
303
+ return { system: readSystem(found.folder, found.name, given, ruleset), refused: [] };
281
304
  }
282
- catch (error) {
283
- const message = error instanceof Error ? error.message : String(error);
284
- return { system, problem: message.replace(/^The game system .*? cannot be read, because .*? is not valid:\s*/s, "") };
305
+ catch {
306
+ // One layer at a time, to leave out only those that do not read.
285
307
  }
308
+ const kept = [];
309
+ const refused = [];
310
+ for (const layer of given) {
311
+ try {
312
+ readSystem(found.folder, found.name, [...kept, layer], ruleset);
313
+ kept.push(layer);
314
+ }
315
+ catch (error) {
316
+ const message = error instanceof Error ? error.message : String(error);
317
+ refused.push({ from: layer.from, problem: message.replace(/^The game system .*? cannot be read, because .*? is not valid:\s*/s, "") });
318
+ }
319
+ }
320
+ return { system: readSystem(found.folder, found.name, kept, ruleset), refused };
286
321
  }
287
322
  /**
288
- * The installed system with this name, ignoring case, from the nearest folder that has it, with what a campaign adds to it; undefined when none is. Only its own
289
- * system.yaml is read.
323
+ * The installed system with this name, ignoring case, from the nearest folder that has it, with the version of its rules asked, else its first (VER-2); undefined
324
+ * when none is. Only its own system.yaml is read, and its version's.
290
325
  */
291
- export function findSystem(folders, name, data) {
326
+ export function findSystem(folders, name, ruleset) {
292
327
  const found = systemFolders(folders).find((candidate) => comparableText(candidate.name) === comparableText(name.trim()));
293
- return found === undefined ? undefined : readSystem(found.folder, found.name, data);
328
+ return found === undefined ? undefined : readSystem(found.folder, found.name, [], ruleset);
329
+ }
330
+ /** The folders a system's pages, rules, words, pictures and instructions come from, in order: its own, then its version's, which wins by name (VER-3). */
331
+ export function systemContentFolders(system) {
332
+ return system.version === undefined ? [system.folder] : [system.folder, system.version.folder];
294
333
  }
295
- function readSystem(folder, name, additions) {
334
+ function readSystem(folder, name, layers = [], ruleset) {
296
335
  const file = join(folder, systemFileName);
297
- const path = additions === undefined ? file : `${file} with the additions of campaign.yaml`;
298
- const raw = readYamlValues(file, 'what the system is, such as "title: ..."');
336
+ const own = readYamlValues(file, 'what the system is, such as "title: ..."');
337
+ const version = chosenVersion(own, file, name, ruleset);
338
+ const read = version === undefined ? file : `${file} with its version ${version.name}`;
339
+ const path = layers.length === 0 ? read : `${read} with the additions of ${layers.map((layer) => layer.from).join(", ")}`;
340
+ const raw = version === undefined || !isMap(own) ? own : withVersion(own, version.data);
299
341
  let merged = raw;
300
342
  try {
301
- merged = additions === undefined ? raw : withCampaignData(raw, additions);
343
+ merged = layers.reduce((below, layer) => withCampaignData(below, layer.data), raw);
302
344
  }
303
345
  catch (error) {
304
346
  throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: ${error instanceof Error ? error.message : String(error)}`);
305
347
  }
306
348
  const parsed = systemSchema.safeParse(merged);
307
349
  if (!parsed.success) {
308
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: ${issuesText(parsed.error)}`);
350
+ // One made for a newer API may declare what this engine does not know yet (D-515).
351
+ const unread = systemApiProblem(folder);
352
+ throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: ${issuesText(parsed.error)}${unread === undefined ? "" : ` Besides, ${unread}.`}`);
309
353
  }
310
354
  const data = parsed.data;
355
+ const parts = packagePartsIssues(data, "a game system")[0];
356
+ if (parts !== undefined) {
357
+ throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: ${[...parts.path, ""].join(".").replace(/\.$/, ": ")}${parts.message}.`);
358
+ }
311
359
  // What a counter shields is no limit of it: a counter with only that has none (DAT-14).
312
360
  const limited = Object.entries(data.counters ?? {}).flatMap(([counter, { min, max, refill }]) => min === undefined && max === undefined && refill === undefined ? [] : [[counter, { min, max, refill }]]);
313
361
  const formulas = systemFormulas({ ...data, counters: Object.fromEntries(limited) }, name, path);
@@ -329,13 +377,12 @@ function readSystem(folder, name, additions) {
329
377
  ...(data.keeping === undefined ? [] : [{ where: "keeping.counter", field: data.keeping.counter }]),
330
378
  ...(data.damage === undefined ? [] : [{ where: "damage.counter", field: data.damage.counter }]),
331
379
  ...(data.combat === undefined ? [] : [{ where: "combat.track", field: data.combat.track }]),
332
- ...(data.dying === undefined ? [] : [data.dying.at.split(" ")[0], ...Object.values(data.dying.show)].map((field) => ({ where: "dying", field }))),
380
+ ...(data.down === undefined ? [] : [{ where: "down.at", field: data.down.at.split(" ")[0] }]),
333
381
  ...Object.entries(data.counters ?? {}).flatMap(([counter, limits]) => (limits.shields === undefined ? [] : [{ where: `counters.${counter}.shields`, field: limits.shields }])),
334
382
  ].find((entry) => kindOf(entry.field) !== "counter");
335
383
  const unknownCondition = [
336
384
  ...(data.keeping?.conditions ?? []).map((condition) => ({ where: "keeping.conditions", condition })),
337
385
  ...(data.combat?.inactive ?? []).map((condition) => ({ where: "combat.inactive", condition })),
338
- ...Object.keys(data["condition-icons"] ?? {}).map((condition) => ({ where: "condition-icons", condition })),
339
386
  ].find((entry) => !(data.conditions ?? []).some((named) => comparableText(named) === comparableText(entry.condition)));
340
387
  if (unknownCondition !== undefined) {
341
388
  const named = (data.conditions ?? []).length === 0 ? "" : ` (${(data.conditions ?? []).join(", ")})`;
@@ -405,6 +452,17 @@ function readSystem(folder, name, additions) {
405
452
  if (actless !== undefined) {
406
453
  throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: sheet-actions: the sheet has no field ${actless}.`);
407
454
  }
455
+ // Each verb is the engine's or one the system declares, never both (D-514).
456
+ const ownVerbs = Object.keys(data["sheet-verbs"] ?? {});
457
+ const taken = ownVerbs.find((verb) => actVerbs.includes(verb));
458
+ const verbs = [...actVerbs, ...ownVerbs];
459
+ const unknownVerb = Object.entries(data["sheet-actions"] ?? {}).flatMap(([field, listed]) => listed.filter((verb) => !verbs.includes(verb)).map((verb) => `${field}: ${verb}`))[0];
460
+ if (taken !== undefined) {
461
+ throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: sheet-verbs: ${taken} is one of the engine's verbs, whose words the dashboard has; leave it out.`);
462
+ }
463
+ if (unknownVerb !== undefined) {
464
+ throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: sheet-actions.${unknownVerb} is no verb: give one of ${verbs.join(", ")}, or declare it in sheet-verbs.`);
465
+ }
408
466
  // Each field the headline names is a declared one (D-288).
409
467
  const unnamed = [...(data["sheet-headline"] ?? "").matchAll(headlineFieldPattern)].map((match) => match[1]).find((field) => kindOf(field) === undefined);
410
468
  if (unnamed !== undefined) {
@@ -422,6 +480,7 @@ function readSystem(folder, name, additions) {
422
480
  return frozen({
423
481
  name,
424
482
  folder,
483
+ ...(version === undefined ? {} : { version: { name: version.name, ...(version.title === undefined ? {} : { title: version.title }), folder: version.folder } }),
425
484
  code: systemHasCode(folder),
426
485
  title: data.title,
427
486
  language: data.language,
@@ -444,6 +503,7 @@ function readSystem(folder, name, additions) {
444
503
  : parseFormula(data.load.limit),
445
504
  ...(data.load.coins === undefined ? {} : { coins: data.load.coins }),
446
505
  ...(data.load.weightless === undefined ? {} : { weightless: data.load.weightless }),
506
+ ...(data.load.bundle === undefined ? {} : { bundle: data.load.bundle }),
447
507
  ...(data.load.stages === undefined ? {} : { stages: data.load.stages.map((stage) => ({ name: stage.name, formula: parseFormula(stage.when) })) }),
448
508
  },
449
509
  }),
@@ -467,6 +527,7 @@ function readSystem(folder, name, additions) {
467
527
  ...(data["sheet-headline"] === undefined ? {} : { sheetHeadline: data["sheet-headline"] }),
468
528
  ...(data["token-icons"] === undefined ? {} : { tokenIcons: data["token-icons"] }),
469
529
  ...(data["sheet-actions"] === undefined ? {} : { sheetActions: data["sheet-actions"] }),
530
+ sheetVerbs: Object.fromEntries(Object.entries(data["sheet-verbs"] ?? {}).map(([verb, words]) => [verb, sheetVerbOf(words)])),
470
531
  ...(data["sheet-cards"] === undefined ? {} : { sheetCards: { rail: data["sheet-cards"].rail ?? [], order: data["sheet-cards"].order ?? [], atHand: data["sheet-cards"]["at-hand"] ?? [] } }),
471
532
  values,
472
533
  sheetValues,
@@ -490,6 +551,9 @@ function readSystem(folder, name, additions) {
490
551
  })),
491
552
  conditions: data.conditions ?? [],
492
553
  conditionIcons: data["condition-icons"] ?? {},
554
+ icons: data.icons ?? {},
555
+ widgets: declaredWidgets(data.widgets),
556
+ figures: data.figures ?? {},
493
557
  bonds: data.bonds ?? {},
494
558
  ...(data.upkeep === undefined ? {} : { upkeep: data.upkeep }),
495
559
  burning: data.burning ?? {},
@@ -507,7 +571,7 @@ function readSystem(folder, name, additions) {
507
571
  ...(data.damage === undefined ? {} : { damage: data.damage }),
508
572
  ...(data.keeping === undefined ? {} : { keeping: { counter: data.keeping.counter, conditions: data.keeping.conditions ?? [], rules: data.keeping.rules } }),
509
573
  ...(data.combat === undefined ? {} : { combat: { track: data.combat.track, inWords: data.combat["in-words"] ?? [], inactive: data.combat.inactive ?? [] } }),
510
- ...(data.dying === undefined ? {} : { dying: dyingRule(data.dying) }),
574
+ ...(data.down === undefined ? {} : { down: downRule(data.down.at) }),
511
575
  checks: (data.checks ?? []).map((check) => ({ when: checkAtom(check.when), needs: checkAtom(check.needs), say: check.say })),
512
576
  shields: Object.fromEntries(Object.entries(data.counters ?? {}).flatMap(([counter, limits]) => (limits.shields === undefined ? [] : [[counter, limits.shields]]))),
513
577
  formulas,
@@ -515,7 +579,8 @@ function readSystem(folder, name, additions) {
515
579
  itemFormulas: data["item-formulas"] ?? {},
516
580
  alwaysIn: data["always-in"] ?? {},
517
581
  uses: usesOf(data),
518
- settings: Object.entries(data.settings ?? {}).map(([setting, values]) => ({
582
+ // The versions first, as the setup asks them before what they may change; one alone is no choice, and no setting (VER-1).
583
+ settings: [...(Object.keys(data.versions ?? {}).filter((key) => key !== "about").length < 2 ? [] : [[rulesetSetting, data.versions ?? {}]]), ...Object.entries(data.settings ?? {})].map(([setting, values]) => ({
519
584
  name: setting,
520
585
  ...(typeof values.about === "string" ? { about: values.about } : {}),
521
586
  values: Object.entries(values).flatMap(([value, meaning]) => typeof meaning === "string" ? [] : [{
@@ -530,9 +595,48 @@ function readSystem(folder, name, additions) {
530
595
  const [counter, value] = reward.overcome.split(" ");
531
596
  return { field, from: reward.from, counter, value: Number(value) };
532
597
  }),
533
- parts: readParts(folder, `The game system ${name}`),
598
+ // A part of its version takes the place of its own of that name (VER-3).
599
+ parts: { ...readParts(folder, `The game system ${name}`), ...(version === undefined ? {} : readParts(version.folder, `The game system ${name}, its version ${version.name},`)) },
534
600
  });
535
601
  }
602
+ /**
603
+ * The version of its rules a system is read with (VER-1, VER-2): the one asked, by any case, else the first it lists; none for a system without versions.
604
+ * Each version it lists has its folder in versions/, with a system.yaml of what it changes, if any, and a title of its own.
605
+ */
606
+ function chosenVersion(own, file, name, asked) {
607
+ const versions = isMap(own) && isMap(own.versions) ? Object.keys(own.versions).filter((key) => key !== "about") : [];
608
+ const folder = join(file, "..");
609
+ const unfound = versions.find((version) => files().files(join(folder, versionsFolderName, version), () => true).length === 0);
610
+ if (unfound !== undefined) {
611
+ throw new Error(`The game system ${name} cannot be read, because ${file} is not valid: versions.${unfound}: there is no folder ${versionsFolderName}/${unfound} with files beside it; give each version its folder, with what it changes.`);
612
+ }
613
+ const chosen = versions.find((version) => asked !== undefined && comparableText(version) === comparableText(asked.trim())) ?? versions[0];
614
+ if (chosen === undefined) {
615
+ return undefined;
616
+ }
617
+ const at = join(folder, versionsFolderName, chosen);
618
+ const versionFile = join(at, systemFileName);
619
+ const data = files().exists(versionFile) ? (readYamlValues(versionFile, 'what the version changes, such as "title: ..."') ?? {}) : {};
620
+ if (!isMap(data) || data.versions !== undefined) {
621
+ const why = isMap(data) ? "a version lists no versions of its own" : "write it as the keys of system.yaml the version changes, such as title: the second rules";
622
+ throw new Error(`The game system ${name} cannot be read, because ${versionFile} is not valid: ${why}.`);
623
+ }
624
+ const { title, ...changes } = data;
625
+ return { name: chosen, ...(typeof title === "string" ? { title } : {}), folder: at, data: changes };
626
+ }
627
+ /** A system's data with its version's over it (VER-3): a map by its names, at every depth, the version's winning; a list or a value in the place of the common one. */
628
+ function withVersion(below, over) {
629
+ const taken = new Set();
630
+ const merged = Object.entries(below).map(([key, value]) => {
631
+ const named = nameIn(over, key);
632
+ if (named === undefined) {
633
+ return [key, value];
634
+ }
635
+ taken.add(named);
636
+ return [named, isMap(value) && isMap(over[named]) ? withVersion(value, over[named]) : over[named]];
637
+ });
638
+ return Object.fromEntries([...merged, ...Object.entries(over).filter(([key]) => !taken.has(key))]);
639
+ }
536
640
  /**
537
641
  * "counters.bulwark-dice: unknown key "Bulwark)", a formula with commas goes in quotes": the problems of a system's data, one after the other on
538
642
  * a line, each at its place.
@@ -617,7 +721,7 @@ function sheetOf(data, name, path) {
617
721
  function withCampaignData(raw, data) {
618
722
  const base = isMap(raw) ? raw : {};
619
723
  const merged = { ...base };
620
- for (const key of ["fields", "tables", "computed", "counters"]) {
724
+ for (const key of ["fields", "tables", "computed", "counters", "condition-icons"]) {
621
725
  const added = mapOf(data[key], key);
622
726
  merged[key] = added === undefined ? base[key] : { ...withoutNames(isMap(base[key]) ? base[key] : {}, Object.keys(added)), ...added };
623
727
  }
@@ -693,6 +797,11 @@ function withoutNames(map, names) {
693
797
  function nameIn(map, name) {
694
798
  return sameName(Object.keys(map), name);
695
799
  }
800
+ /** A verb of the system as the dashboard reads it (D-514): with its sentences on someone, at a square and on oneself only when it lets the player choose. */
801
+ function sheetVerbOf(words) {
802
+ const choosing = words["says-on"] === undefined ? {} : { on: words["says-on"], at: words["says-at"], self: words["says-self"] };
803
+ return { label: words.label, title: words.title, says: words.says, ...choosing };
804
+ }
696
805
  /** How the system's map of a place counts, as the engine reads it (GRD-4): the square in metres. */
697
806
  function gridOf(data) {
698
807
  const { square, size, footprints, leaving, ...rest } = data;
@@ -764,8 +873,8 @@ function checkAtom(text) {
764
873
  const field = checkFieldPattern.exec(text.trim());
765
874
  return field === null ? { effect: text.trim() } : { field: field[1], op: field[2], value: Number(field[3]) };
766
875
  }
767
- /** The dying as the system writes them: "hp 0" read as a field and a number. */
768
- function dyingRule(data) {
769
- const [field, value] = data.at.split(" ");
770
- return { field, value: Number(value), show: data.show, ...(data.stable === undefined ? {} : { stable: data.stable }), marks: data.marks ?? {} };
876
+ /** When one is down as the system writes it: "hp 0" read as a field and a number. */
877
+ function downRule(at) {
878
+ const [field, value] = at.split(" ");
879
+ return { field, value: Number(value) };
771
880
  }
@@ -1,4 +1,4 @@
1
- export { type ActVerb, actVerbs, type CampaignData, campaignDataNames, type CheckAtom, type CheckOperator, type DamageRule, findCampaignSystem, findSystem, type GameSystem, type GridRules, installedSystems, type Lifestyle, type Recipe, type Reward, rollName, type SheetEntry, type SheetGroup, type SystemCheck, systemFileName, type SystemSetting, type Threshold, type Travel, type TravelKind, type TurnUse, withSettings, } from "./game-system.ts";
2
- export { type CounterChange, type LoadedSystemCode, loadSystemCode, type RollMade, type SystemEntry, type SystemGame, systemHasCode, type SystemHooks, type SystemPage, type SystemReader } from "./system-code.ts";
1
+ export { type ActVerb, actVerbs, type CampaignData, campaignDataNames, type CheckAtom, type CheckOperator, type DamageRule, findCampaignSystem, findSystem, type GameSystem, type GridRules, installedSystems, type Lifestyle, type Recipe, type Reward, rollName, rulesetSetting, type SheetEntry, type SheetGroup, type SheetVerb, type SystemCheck, systemContentFolders, systemFileName, type SystemLayer, type SystemSetting, type Threshold, type Travel, type TravelKind, type TurnUse, withSettings, } from "./game-system.ts";
2
+ export { givenCode, type LoadedSystemCode, loadSystemCode, systemApiProblem, systemHasCode, type SystemPackage, systemPackage, systemPageModule } from "./system-code.ts";
3
3
  export { type SystemFolder, systemFolders } from "./system-folders.ts";
4
- export { type SystemWords, systemWords } from "./words.ts";
4
+ export { layeredSystemWords, type SystemWords, systemWords } from "./words.ts";
@@ -1,5 +1,5 @@
1
1
  // The game systems installed beside the engine (D-27, SYS-1): which they are and what each declares. Their pages are read by the pages module.
2
- export { actVerbs, campaignDataNames, findCampaignSystem, findSystem, installedSystems, rollName, systemFileName, withSettings, } from "./game-system.js";
3
- export { loadSystemCode, systemHasCode } from "./system-code.js";
2
+ export { actVerbs, campaignDataNames, findCampaignSystem, findSystem, installedSystems, rollName, rulesetSetting, systemContentFolders, systemFileName, withSettings, } from "./game-system.js";
3
+ export { givenCode, loadSystemCode, systemApiProblem, systemHasCode, systemPackage, systemPageModule } from "./system-code.js";
4
4
  export { systemFolders } from "./system-folders.js";
5
- export { systemWords } from "./words.js";
5
+ export { layeredSystemWords, systemWords } from "./words.js";