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
@@ -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,19 +288,19 @@ 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
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,
272
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, layers) {
296
+ export function findCampaignSystem(folders, name, layers, ruleset) {
275
297
  const found = systemFolders(folders).find((candidate) => comparableText(candidate.name) === comparableText(name.trim()));
276
298
  const given = layers.filter((layer) => campaignDataNames.some((key) => layer.data[key] !== undefined && layer.data[key] !== null));
277
299
  if (found === undefined) {
278
300
  return { refused: [] };
279
301
  }
280
302
  try {
281
- return { system: readSystem(found.folder, found.name, given), refused: [] };
303
+ return { system: readSystem(found.folder, found.name, given, ruleset), refused: [] };
282
304
  }
283
305
  catch {
284
306
  // One layer at a time, to leave out only those that do not read.
@@ -287,7 +309,7 @@ export function findCampaignSystem(folders, name, layers) {
287
309
  const refused = [];
288
310
  for (const layer of given) {
289
311
  try {
290
- readSystem(found.folder, found.name, [...kept, layer]);
312
+ readSystem(found.folder, found.name, [...kept, layer], ruleset);
291
313
  kept.push(layer);
292
314
  }
293
315
  catch (error) {
@@ -295,17 +317,27 @@ export function findCampaignSystem(folders, name, layers) {
295
317
  refused.push({ from: layer.from, problem: message.replace(/^The game system .*? cannot be read, because .*? is not valid:\s*/s, "") });
296
318
  }
297
319
  }
298
- return { system: readSystem(found.folder, found.name, kept), refused };
320
+ return { system: readSystem(found.folder, found.name, kept, ruleset), refused };
299
321
  }
300
- /** The installed system with this name, ignoring case, from the nearest folder that has it; undefined when none is. Only its own system.yaml is read. */
301
- export function findSystem(folders, name) {
322
+ /**
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.
325
+ */
326
+ export function findSystem(folders, name, ruleset) {
302
327
  const found = systemFolders(folders).find((candidate) => comparableText(candidate.name) === comparableText(name.trim()));
303
- return found === undefined ? undefined : readSystem(found.folder, found.name);
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];
304
333
  }
305
- function readSystem(folder, name, layers = []) {
334
+ function readSystem(folder, name, layers = [], ruleset) {
306
335
  const file = join(folder, systemFileName);
307
- const path = layers.length === 0 ? file : `${file} with the additions of ${layers.map((layer) => layer.from).join(", ")}`;
308
- 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);
309
341
  let merged = raw;
310
342
  try {
311
343
  merged = layers.reduce((below, layer) => withCampaignData(below, layer.data), raw);
@@ -315,9 +347,15 @@ function readSystem(folder, name, layers = []) {
315
347
  }
316
348
  const parsed = systemSchema.safeParse(merged);
317
349
  if (!parsed.success) {
318
- 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}.`}`);
319
353
  }
320
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
+ }
321
359
  // What a counter shields is no limit of it: a counter with only that has none (DAT-14).
322
360
  const limited = Object.entries(data.counters ?? {}).flatMap(([counter, { min, max, refill }]) => min === undefined && max === undefined && refill === undefined ? [] : [[counter, { min, max, refill }]]);
323
361
  const formulas = systemFormulas({ ...data, counters: Object.fromEntries(limited) }, name, path);
@@ -339,13 +377,12 @@ function readSystem(folder, name, layers = []) {
339
377
  ...(data.keeping === undefined ? [] : [{ where: "keeping.counter", field: data.keeping.counter }]),
340
378
  ...(data.damage === undefined ? [] : [{ where: "damage.counter", field: data.damage.counter }]),
341
379
  ...(data.combat === undefined ? [] : [{ where: "combat.track", field: data.combat.track }]),
342
- ...(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] }]),
343
381
  ...Object.entries(data.counters ?? {}).flatMap(([counter, limits]) => (limits.shields === undefined ? [] : [{ where: `counters.${counter}.shields`, field: limits.shields }])),
344
382
  ].find((entry) => kindOf(entry.field) !== "counter");
345
383
  const unknownCondition = [
346
384
  ...(data.keeping?.conditions ?? []).map((condition) => ({ where: "keeping.conditions", condition })),
347
385
  ...(data.combat?.inactive ?? []).map((condition) => ({ where: "combat.inactive", condition })),
348
- ...Object.keys(data["condition-icons"] ?? {}).map((condition) => ({ where: "condition-icons", condition })),
349
386
  ].find((entry) => !(data.conditions ?? []).some((named) => comparableText(named) === comparableText(entry.condition)));
350
387
  if (unknownCondition !== undefined) {
351
388
  const named = (data.conditions ?? []).length === 0 ? "" : ` (${(data.conditions ?? []).join(", ")})`;
@@ -415,6 +452,17 @@ function readSystem(folder, name, layers = []) {
415
452
  if (actless !== undefined) {
416
453
  throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: sheet-actions: the sheet has no field ${actless}.`);
417
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
+ }
418
466
  // Each field the headline names is a declared one (D-288).
419
467
  const unnamed = [...(data["sheet-headline"] ?? "").matchAll(headlineFieldPattern)].map((match) => match[1]).find((field) => kindOf(field) === undefined);
420
468
  if (unnamed !== undefined) {
@@ -432,6 +480,7 @@ function readSystem(folder, name, layers = []) {
432
480
  return frozen({
433
481
  name,
434
482
  folder,
483
+ ...(version === undefined ? {} : { version: { name: version.name, ...(version.title === undefined ? {} : { title: version.title }), folder: version.folder } }),
435
484
  code: systemHasCode(folder),
436
485
  title: data.title,
437
486
  language: data.language,
@@ -454,6 +503,7 @@ function readSystem(folder, name, layers = []) {
454
503
  : parseFormula(data.load.limit),
455
504
  ...(data.load.coins === undefined ? {} : { coins: data.load.coins }),
456
505
  ...(data.load.weightless === undefined ? {} : { weightless: data.load.weightless }),
506
+ ...(data.load.bundle === undefined ? {} : { bundle: data.load.bundle }),
457
507
  ...(data.load.stages === undefined ? {} : { stages: data.load.stages.map((stage) => ({ name: stage.name, formula: parseFormula(stage.when) })) }),
458
508
  },
459
509
  }),
@@ -477,6 +527,7 @@ function readSystem(folder, name, layers = []) {
477
527
  ...(data["sheet-headline"] === undefined ? {} : { sheetHeadline: data["sheet-headline"] }),
478
528
  ...(data["token-icons"] === undefined ? {} : { tokenIcons: data["token-icons"] }),
479
529
  ...(data["sheet-actions"] === undefined ? {} : { sheetActions: data["sheet-actions"] }),
530
+ sheetVerbs: Object.fromEntries(Object.entries(data["sheet-verbs"] ?? {}).map(([verb, words]) => [verb, sheetVerbOf(words)])),
480
531
  ...(data["sheet-cards"] === undefined ? {} : { sheetCards: { rail: data["sheet-cards"].rail ?? [], order: data["sheet-cards"].order ?? [], atHand: data["sheet-cards"]["at-hand"] ?? [] } }),
481
532
  values,
482
533
  sheetValues,
@@ -500,6 +551,9 @@ function readSystem(folder, name, layers = []) {
500
551
  })),
501
552
  conditions: data.conditions ?? [],
502
553
  conditionIcons: data["condition-icons"] ?? {},
554
+ icons: data.icons ?? {},
555
+ widgets: declaredWidgets(data.widgets),
556
+ figures: data.figures ?? {},
503
557
  bonds: data.bonds ?? {},
504
558
  ...(data.upkeep === undefined ? {} : { upkeep: data.upkeep }),
505
559
  burning: data.burning ?? {},
@@ -517,7 +571,7 @@ function readSystem(folder, name, layers = []) {
517
571
  ...(data.damage === undefined ? {} : { damage: data.damage }),
518
572
  ...(data.keeping === undefined ? {} : { keeping: { counter: data.keeping.counter, conditions: data.keeping.conditions ?? [], rules: data.keeping.rules } }),
519
573
  ...(data.combat === undefined ? {} : { combat: { track: data.combat.track, inWords: data.combat["in-words"] ?? [], inactive: data.combat.inactive ?? [] } }),
520
- ...(data.dying === undefined ? {} : { dying: dyingRule(data.dying) }),
574
+ ...(data.down === undefined ? {} : { down: downRule(data.down.at) }),
521
575
  checks: (data.checks ?? []).map((check) => ({ when: checkAtom(check.when), needs: checkAtom(check.needs), say: check.say })),
522
576
  shields: Object.fromEntries(Object.entries(data.counters ?? {}).flatMap(([counter, limits]) => (limits.shields === undefined ? [] : [[counter, limits.shields]]))),
523
577
  formulas,
@@ -525,7 +579,8 @@ function readSystem(folder, name, layers = []) {
525
579
  itemFormulas: data["item-formulas"] ?? {},
526
580
  alwaysIn: data["always-in"] ?? {},
527
581
  uses: usesOf(data),
528
- 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]) => ({
529
584
  name: setting,
530
585
  ...(typeof values.about === "string" ? { about: values.about } : {}),
531
586
  values: Object.entries(values).flatMap(([value, meaning]) => typeof meaning === "string" ? [] : [{
@@ -540,9 +595,48 @@ function readSystem(folder, name, layers = []) {
540
595
  const [counter, value] = reward.overcome.split(" ");
541
596
  return { field, from: reward.from, counter, value: Number(value) };
542
597
  }),
543
- 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},`)) },
544
600
  });
545
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
+ }
546
640
  /**
547
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
548
642
  * a line, each at its place.
@@ -627,7 +721,7 @@ function sheetOf(data, name, path) {
627
721
  function withCampaignData(raw, data) {
628
722
  const base = isMap(raw) ? raw : {};
629
723
  const merged = { ...base };
630
- for (const key of ["fields", "tables", "computed", "counters"]) {
724
+ for (const key of ["fields", "tables", "computed", "counters", "condition-icons"]) {
631
725
  const added = mapOf(data[key], key);
632
726
  merged[key] = added === undefined ? base[key] : { ...withoutNames(isMap(base[key]) ? base[key] : {}, Object.keys(added)), ...added };
633
727
  }
@@ -703,6 +797,11 @@ function withoutNames(map, names) {
703
797
  function nameIn(map, name) {
704
798
  return sameName(Object.keys(map), name);
705
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
+ }
706
805
  /** How the system's map of a place counts, as the engine reads it (GRD-4): the square in metres. */
707
806
  function gridOf(data) {
708
807
  const { square, size, footprints, leaving, ...rest } = data;
@@ -774,8 +873,8 @@ function checkAtom(text) {
774
873
  const field = checkFieldPattern.exec(text.trim());
775
874
  return field === null ? { effect: text.trim() } : { field: field[1], op: field[2], value: Number(field[3]) };
776
875
  }
777
- /** The dying as the system writes them: "hp 0" read as a field and a number. */
778
- function dyingRule(data) {
779
- const [field, value] = data.at.split(" ");
780
- 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) };
781
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 SystemLayer, 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";
@@ -1,97 +1,38 @@
1
- import type { SaveAsked } from "../core/context.ts";
2
- /** A die as it was thrown: its faces, what it showed, and whether it was dropped, as the lower of two kept highest. */
3
- export interface ThrownDie {
4
- sides: number | "F";
5
- value: number;
6
- dropped?: boolean;
7
- }
8
- /** A counter a command changed on a page: before and after, its maximum, and what damage took of it past what shields it. */
9
- export interface CounterChange {
10
- page: string;
11
- field: string;
12
- before: number;
13
- after: number;
14
- max?: number;
15
- lost: number;
16
- }
17
- /** A roll made for someone with a page, as the player's check or the master's roll with who: never a hidden one. */
18
- export interface RollMade {
19
- who: string;
20
- notation: string;
21
- total: number;
22
- dice: ThrownDie[];
23
- }
24
- /** A page as a system's code reads it: in the party or not, the player's character or not, its counters with what its effects give, its effects. */
25
- export interface SystemPage {
26
- name: string;
27
- party: boolean;
28
- pc: boolean;
29
- counter(field: string): {
30
- value: number;
31
- max?: number;
32
- } | undefined;
33
- has(effect: string): boolean;
34
- }
35
- /** What a system's code may read of the game. */
36
- export interface SystemReader {
37
- /** A page by its name; undefined when no page, or more than one, has it. */
38
- page(name: string): SystemPage | undefined;
39
- /** A setting of the campaign, as mentor. */
40
- setting(name: string): string | undefined;
41
- /** Whether two names are the same, as the engine compares them: case and accents aside. */
42
- sameName(one: string, other: string): boolean;
43
- }
44
- /** What a system's code may do to the game: each write with its line in the log, public or hidden as the engine shows that page to the player. */
45
- export interface SystemGame extends SystemReader {
46
- /** Sets numbers on a page: a counter keeps its maximum. */
47
- set(page: string, values: Record<string, number>, why: string): void;
48
- /** Adds an effect without end; the engine's notes on what it breaks of what one keeps, or undefined when the page has it already. */
49
- addEffect(page: string, name: string, why: string): string[] | undefined;
50
- /** Ends an effect; whether the page had it. */
51
- endEffect(page: string, name: string, why: string): boolean;
52
- /** Rolls with the engine's dice, as a roll in the log for who: public, or hidden for anyone outside the party as the master-rolls setting says (D-287). */
53
- roll(notation: string, by: {
54
- who: string;
55
- why: string;
56
- }): {
57
- total: number;
58
- dice: ThrownDie[];
59
- text: string;
60
- };
61
- }
62
- /** The hooks of a system's code, each optional, each giving lines for the command's output. Writes made through the game call no hook. */
63
- export interface SystemHooks {
64
- /** After change, or the hit dice, wrote a counter of a page. */
65
- counterChanged?(change: CounterChange, game: SystemGame): string[];
66
- /** As someone's turn starts in a scene. */
67
- turnStarted?(turn: {
68
- who: string;
69
- }, game: SystemGame): string[];
70
- /** After a roll for someone was logged. */
71
- rolled?(roll: RollMade, game: SystemGame): string[];
72
- /** After an effect was added to a page. */
73
- effectAdded?(added: {
74
- page: string;
75
- effect: string;
76
- }, game: SystemGame): string[];
77
- /** Before ask shows its buttons: what the page draws of the question, as a death save; it only reads. */
78
- asking?(question: {
79
- who: string;
80
- notations: string[];
81
- }, game: SystemReader): SaveAsked | undefined;
82
- }
83
- /** The default export of a system's code. */
84
- export type SystemEntry = () => SystemHooks;
85
- /** A system's code as loaded: its hooks, or what kept it from loading. */
86
- export type LoadedSystemCode = {
87
- hooks: SystemHooks;
1
+ import type { PackageCode } from "../core/package-api.ts";
2
+ /** A system's code as loaded: what it gives, or what kept it from loading; the version of its package, as it was loaded. */
3
+ export type LoadedSystemCode = ({
4
+ code: PackageCode;
88
5
  } | {
89
6
  problem: string;
7
+ } | {
8
+ refused: string;
9
+ }) & {
10
+ version: string;
90
11
  };
12
+ /** A system's package.json of kind system (D-448, D-511): its name and version, the main of its code and its page module, the API it is made for. */
13
+ export interface SystemPackage {
14
+ package: string;
15
+ version: string;
16
+ main?: string;
17
+ page?: string;
18
+ api?: number;
19
+ }
20
+ /** A system's package.json of kind system; undefined for a folder without one, which is data alone. */
21
+ export declare function systemPackage(folder: string): SystemPackage | undefined;
22
+ /** What a package's default export gave, refused when it is not its code, an object, as null is not. */
23
+ export declare function givenCode(given: unknown, file: string): PackageCode;
91
24
  /** Whether a system's folder brings code: a package.json of kind system with a main (D-448). */
92
25
  export declare function systemHasCode(folder: string): boolean;
26
+ /** Why this engine does not read the system in this folder, made for another API, with what to do; undefined when it does, or when it is data alone. */
27
+ export declare function systemApiProblem(folder: string): string | undefined;
28
+ /** A system's code for the dashboard's page, as its package.json declares it (D-511): its module's file, the package's name and version; undefined without one. */
29
+ export declare function systemPageModule(folder: string): {
30
+ file: string;
31
+ package: string;
32
+ version: string;
33
+ } | undefined;
93
34
  /**
94
35
  * The code of every system in these folders that brings some, by the system's name, loaded once: from its source where the engine runs from its own, as in
95
- * the tests, else from its built main. One that fails to load says why, for the command that needs it.
36
+ * the tests, else from its built main. One that fails to load, or is made for an API this engine does not read, says why, for the command that needs it.
96
37
  */
97
38
  export declare function loadSystemCode(folders: string[]): Promise<Record<string, LoadedSystemCode>>;