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
@@ -0,0 +1,37 @@
1
+ import type { Context } from "../core/context.ts";
2
+ import type { CounterChange, Rolled } from "../core/package-api.ts";
3
+ import type { Told } from "./ask.ts";
4
+ /**
5
+ * What the packages' code said after a command's change: the system's lines, which may take the place of the engine's own note, as a death save does; the
6
+ * extensions' lines, which come after it; and apart why some did not run or failed, which the caller adds to its notes, never deciding by it.
7
+ */
8
+ export interface PackagesSaid {
9
+ lines: string[];
10
+ added: string[];
11
+ problem?: string;
12
+ }
13
+ /** All the packages' code said, its problems last. */
14
+ export declare function allSaid(said: PackagesSaid): string[];
15
+ /** After a counter of a page changed, as by change or the dice of a rest: the packages' lines. */
16
+ export declare function packagesCounterChanged(root: string, context: Context, change: CounterChange): PackagesSaid;
17
+ /** As someone's turn starts in a scene: the packages' lines. */
18
+ export declare function packagesTurnStarted(root: string, context: Context, who: string): PackagesSaid;
19
+ /** After a roll for someone was logged, never a hidden one: the packages' lines. */
20
+ export declare function packagesRolled(root: string, context: Context, roll: Rolled & {
21
+ who: string;
22
+ }): PackagesSaid;
23
+ /** After an effect was added to a page, never to a copy: the packages' lines. */
24
+ export declare function packagesEffectAdded(root: string, context: Context, added: {
25
+ page: string;
26
+ effect: string;
27
+ }): PackagesSaid;
28
+ /**
29
+ * How the packages' code asks a roll of the core's ask, or the dice of a rest (D-507, D-514): in the words of the first that gives them, the system first,
30
+ * maybe in the card of its widget. Nothing when none says anything, or one fails: ask asks as always.
31
+ */
32
+ export declare function packagesAsking(root: string, context: Context, question: {
33
+ who: string;
34
+ checks: string[];
35
+ notations: string[];
36
+ recipe?: string;
37
+ }): Told | undefined;
@@ -0,0 +1,116 @@
1
+ import { campaignExtensions } from "./game-extension-list.js";
2
+ import { campaignSystemPackage, cappedLines, codeRefused, firstLine, gameOf, gameViewOf, loadedCode, packageLabel, toldOf } from "./game-package-code.js";
3
+ import { campaignSystem } from "./game-world.js";
4
+ /** All the packages' code said, its problems last. */
5
+ export function allSaid(said) {
6
+ return [...said.lines, ...said.added, ...(said.problem === undefined ? [] : [said.problem])];
7
+ }
8
+ /** After a counter of a page changed, as by change or the dice of a rest: the packages' lines. */
9
+ export function packagesCounterChanged(root, context, change) {
10
+ return called(root, context, "this change", (code, game) => code.counterChanged?.(change, game));
11
+ }
12
+ /** As someone's turn starts in a scene: the packages' lines. */
13
+ export function packagesTurnStarted(root, context, who) {
14
+ return called(root, context, "this turn began", (code, game) => code.turnStarted?.({ who }, game));
15
+ }
16
+ /** After a roll for someone was logged, never a hidden one: the packages' lines. */
17
+ export function packagesRolled(root, context, roll) {
18
+ return called(root, context, "this roll", (code, game) => code.rolled?.(roll, game));
19
+ }
20
+ /** After an effect was added to a page, never to a copy: the packages' lines. */
21
+ export function packagesEffectAdded(root, context, added) {
22
+ return called(root, context, "this effect", (code, game) => code.effectAdded?.(added, game));
23
+ }
24
+ /**
25
+ * How the packages' code asks a roll of the core's ask, or the dice of a rest (D-507, D-514): in the words of the first that gives them, the system first,
26
+ * maybe in the card of its widget. Nothing when none says anything, or one fails: ask asks as always.
27
+ */
28
+ export function packagesAsking(root, context, question) {
29
+ for (const { own, code } of hooked(root, context)) {
30
+ const told = attempt(() => {
31
+ const asking = code?.asking?.(question, gameViewOf(root, context, own));
32
+ return asking === undefined || isPromise(asking) ? undefined : toldOf(root, context, own, asking, question.who);
33
+ });
34
+ if (told !== undefined) {
35
+ return told;
36
+ }
37
+ }
38
+ return undefined;
39
+ }
40
+ // Hooks at work: a change made from inside one, as with game.change, calls no hook again. And what was said once of code that is refused.
41
+ let calling = 0;
42
+ const saidOnce = new Set();
43
+ /** What a call gives, or nothing when it throws; a promise it gives is let go, its failure caught. */
44
+ function attempt(call) {
45
+ try {
46
+ const given = call();
47
+ if (isPromise(given)) {
48
+ given.then(undefined, () => undefined);
49
+ return undefined;
50
+ }
51
+ return given;
52
+ }
53
+ catch {
54
+ return undefined;
55
+ }
56
+ }
57
+ /**
58
+ * A hook called with each package's game: the system's lines and the extensions', each cut at the most a package says; apart, a line for each that fails or
59
+ * gives a promise, and for code that should run and is not there, said once for code that is refused.
60
+ */
61
+ function called(root, context, after, call) {
62
+ const said = { lines: [], added: [] };
63
+ const problems = [];
64
+ if (calling > 0) {
65
+ return said;
66
+ }
67
+ for (const { own, code, why } of hooked(root, context)) {
68
+ const byHand = `meanwhile apply its rules yourself, as its ${own.kind === "system" ? "pages" : "instructions"} say`;
69
+ const name = packageLabel(own);
70
+ const lines = own.kind === "system" ? said.lines : said.added;
71
+ if (why !== undefined) {
72
+ const key = `${own.package}@${own.version}: ${why}`;
73
+ if (!codeRefused(own, context) || !saidOnce.has(key)) {
74
+ problems.push(`The ${name}'s code ${why}, so nothing of it followed ${after}; ${byHand}.`);
75
+ saidOnce.add(key);
76
+ }
77
+ continue;
78
+ }
79
+ let given;
80
+ calling += 1;
81
+ try {
82
+ given = call(code ?? {}, gameOf(root, context, own, { hook: true }));
83
+ }
84
+ catch (error) {
85
+ problems.push(`The ${name} failed after ${after}: ${firstLine(error)}. It is done all the same; ${byHand}.`);
86
+ continue;
87
+ }
88
+ finally {
89
+ calling -= 1;
90
+ }
91
+ if (isPromise(given)) {
92
+ // Never a rejection that nothing handles: the process would end with it.
93
+ given.then(undefined, () => undefined);
94
+ problems.push(`The ${name} gave a promise after ${after}: its hooks give their lines at once, never waiting, so nothing of it followed; ${byHand}.`);
95
+ }
96
+ else if (given !== undefined && (!Array.isArray(given) || !given.every((line) => typeof line === "string"))) {
97
+ problems.push(`The ${name} gave no lines after ${after}: its hooks give a list of lines. It is done all the same; ${byHand}.`);
98
+ }
99
+ else {
100
+ lines.push(...cappedLines(own, (given ?? [])));
101
+ }
102
+ }
103
+ return { ...said, ...(problems.length === 0 ? {} : { problem: problems.join("\n") }) };
104
+ }
105
+ /** The campaign's packages that bring code, the system first, each with its code, or why it is not there though it should run. */
106
+ function hooked(root, context) {
107
+ const system = campaignSystem(root, context)?.code === true ? campaignSystemPackage(root, context) : undefined;
108
+ const packages = [...(system === undefined ? [] : [system]), ...campaignExtensions(root, context).extensions];
109
+ return packages.flatMap((own) => {
110
+ const code = loadedCode(own, context);
111
+ return code === undefined ? [] : [typeof code === "string" ? { own, why: code } : { own, code }];
112
+ });
113
+ }
114
+ function isPromise(value) {
115
+ return typeof value === "object" && value !== null && typeof value.then === "function";
116
+ }
@@ -69,8 +69,8 @@ export function recipeChoices(world, recipe, page) {
69
69
  export function notBroughtBack(world, system, recipe, page) {
70
70
  const atZero = (field) => system.statusLine.some((entry) => entry.whenSet && comparableText(entry.field) === comparableText(field));
71
71
  return Object.entries(effectiveFields(world, page)).flatMap(([field, value]) => {
72
- // What the recipe sets, or leaves to the player among what it regains, is not left to the master.
73
- const handled = targetOf(recipe, field) !== undefined || regainOf(recipe, field) !== undefined;
72
+ // What the recipe sets or lowers, or leaves to the player among what it regains, is not left to the master.
73
+ const handled = targetOf(recipe, field) !== undefined || regainOf(recipe, field) !== undefined || Object.keys(recipe.lower).some((name) => matches(name, field));
74
74
  const counter = isDeclaredUncounted(world, field) || handled ? undefined : readCounter(value);
75
75
  if (counter?.max === undefined || counter.value === (atZero(field) ? 0 : counter.max)) {
76
76
  return [];
@@ -4,8 +4,11 @@ import type { Scene } from "../scene/index.ts";
4
4
  import type { GameSystem } from "../systems/index.ts";
5
5
  /** "Viola keeps Eroismo (Corrado): lost 7 hp. Read rules Concentration.": what someone keeps alive, when the counter the game system names goes down by `lost` (EFF-14). */
6
6
  export declare function keepingLossNote(world: World, scene: Scene | undefined, system: GameSystem | undefined, name: string, field: string, lost: number): string;
7
- /** "Corrado keeps Scudo della fede (Viola): now Paralyzed, which breaks it…": what someone keeps alive, when they take a condition the game system names (EFF-14). */
8
- export declare function keepingConditionNote(world: World, scene: Scene | undefined, system: GameSystem | undefined, name: string, condition: string): string;
7
+ /**
8
+ * "Corrado keeps Scudo della fede (Viola): now Paralyzed, which breaks it…": what someone keeps alive, when they take a condition the game system names (EFF-14),
9
+ * maybe in the campaign's language (D-403).
10
+ */
11
+ export declare function keepingConditionNote(world: World, scene: Scene | undefined, system: GameSystem | undefined, name: string, condition: string, words: Record<string, string> | undefined): string;
9
12
  /**
10
13
  * "Malco already keeps Scudo della fede (Malco). Read rules Concentration.": someone given one more effect to keep alive, read in the world before it was added (EFF-14).
11
14
  * The same effect on another target is the same thing kept, as Bless on three.
@@ -4,7 +4,7 @@ import { comparableText } from "../core/text.js";
4
4
  import { readCounter } from "../counters/index.js";
5
5
  import { keeperOf } from "../effects/index.js";
6
6
  import { effectiveFields, effectsOf } from "./effect-layer.js";
7
- import { effectsOn, keptEffectHolders, keptEffects } from "./game-effects.js";
7
+ import { effectsOn, keptEffectHolders, keptEffects, systemNamed } from "./game-effects.js";
8
8
  /** "Viola keeps Eroismo (Corrado): lost 7 hp. Read rules Concentration.": what someone keeps alive, when the counter the game system names goes down by `lost` (EFF-14). */
9
9
  export function keepingLossNote(world, scene, system, name, field, lost) {
10
10
  const keeping = system?.keeping;
@@ -16,10 +16,13 @@ export function keepingLossNote(world, scene, system, name, field, lost) {
16
16
  const kept = keptEffects(world, scene, name);
17
17
  return kept.length === 0 ? "" : `${name} keeps ${kept.join(" · ")}: lost ${lost} ${field}. Read rules ${keeping.rules}.`;
18
18
  }
19
- /** "Corrado keeps Scudo della fede (Viola): now Paralyzed, which breaks it…": what someone keeps alive, when they take a condition the game system names (EFF-14). */
20
- export function keepingConditionNote(world, scene, system, name, condition) {
19
+ /**
20
+ * "Corrado keeps Scudo della fede (Viola): now Paralyzed, which breaks it…": what someone keeps alive, when they take a condition the game system names (EFF-14),
21
+ * maybe in the campaign's language (D-403).
22
+ */
23
+ export function keepingConditionNote(world, scene, system, name, condition, words) {
21
24
  const keeping = system?.keeping;
22
- if (keeping === undefined || !keeping.conditions.some((named) => comparableText(named) === comparableText(condition))) {
25
+ if (keeping === undefined || systemNamed(keeping.conditions, condition, words) === undefined) {
23
26
  return "";
24
27
  }
25
28
  const kept = keptEffects(world, scene, name);
@@ -1,4 +1,5 @@
1
- import type { GameSystem } from "../systems/index.ts";
1
+ import { type RuleSection } from "../rules/index.ts";
2
+ import { type GameSystem } from "../systems/index.ts";
2
3
  /** The source of the campaign's own rules, in the campaign's rules folder. */
3
4
  export declare const houseRules = "house rules";
4
5
  /** What to do when a precedent and the book disagree (D-181). */
@@ -11,6 +12,8 @@ export interface TitledRule {
11
12
  }
12
13
  /** The rule with this title: a house rule first, else the game system's; undefined when neither has a section so titled. */
13
14
  export declare function ruleTitled(root: string, system: GameSystem, title: string): TitledRule | undefined;
15
+ /** The rules of a game system, its own with those of the version of its rules (VER-3): a chapter of the version takes the place of a common one of its file. */
16
+ export declare function systemRuleBook(system: GameSystem): RuleSection[];
14
17
  /** "Poisoned is a condition of the system 5e, by a house rule:" and the text, then the precedents on it, with what to do when they disagree with the book. */
15
18
  export declare function ruleBlock(rule: TitledRule): string;
16
19
  /** The rule a precedent is about: the name before its colon, as in "Poisoned: …" (D-179); undefined when it has none. */
@@ -3,6 +3,7 @@ import { join } from "node:path";
3
3
  import { houseRulesFolderName, readListSetting } from "../campaign/index.js";
4
4
  import { comparableText } from "../core/text.js";
5
5
  import { isTitled, readRuleBook } from "../rules/index.js";
6
+ import { systemContentFolders } from "../systems/index.js";
6
7
  /** The source of the campaign's own rules, in the campaign's rules folder. */
7
8
  export const houseRules = "house rules";
8
9
  /** What to do when a precedent and the book disagree (D-181). */
@@ -11,13 +12,18 @@ export const disagreementAdvice = "When the text and a precedent disagree, tell
11
12
  export function ruleTitled(root, system, title) {
12
13
  const titled = (section) => isTitled(section, title);
13
14
  const house = readRuleBook(join(root, houseRulesFolderName), houseRules).find(titled);
14
- const section = house ?? readRuleBook(join(system.folder, "rules"), system.name).find(titled);
15
+ const section = house ?? systemRuleBook(system).find(titled);
15
16
  if (section === undefined) {
16
17
  return undefined;
17
18
  }
18
19
  const precedents = readListSetting(root, "precedents").filter((precedent) => comparableText(precedentRule(precedent) ?? "") === comparableText(title));
19
20
  return { source: section.source, text: section.text, precedents };
20
21
  }
22
+ /** The rules of a game system, its own with those of the version of its rules (VER-3): a chapter of the version takes the place of a common one of its file. */
23
+ export function systemRuleBook(system) {
24
+ const [own, version] = systemContentFolders(system).map((folder) => readRuleBook(join(folder, "rules"), system.name));
25
+ return version === undefined ? own : [...own.filter((section) => !version.some((other) => other.file === section.file)), ...version];
26
+ }
21
27
  /** "Poisoned is a condition of the system 5e, by a house rule:" and the text, then the precedents on it, with what to do when they disagree with the book. */
22
28
  export function ruleBlock(rule) {
23
29
  const precedents = rule.precedents.length === 0 ? "" : `\n\nPrecedents of the table: ${rule.precedents.join(" · ")}`;
@@ -3,7 +3,7 @@
3
3
  import { readSettings } from "../campaign/index.js";
4
4
  import { parseFormula } from "../core/formula.js";
5
5
  import { appendLogEntry } from "../core/log.js";
6
- import { comparableText, valueNamed } from "../core/text.js";
6
+ import { comparableText, valueNamed, withArticle } from "../core/text.js";
7
7
  import { formatCounter, readCounter } from "../counters/index.js";
8
8
  import { formatAmount, payCoins, readAmount, totalOf } from "../money/index.js";
9
9
  import { baseChain, heldStacksOfKind, kindNamed, locate, writePage } from "../pages/index.js";
@@ -104,12 +104,12 @@ function lifestylePaid(root, context, world, member, lifestyle) {
104
104
  const payment = payCoins(purse, price, coins);
105
105
  const before = formatAmount(purse, coins);
106
106
  if (payment === undefined) {
107
- return `${member.name} cannot pay a ${named} day, ${lifestyle.costs[named]}, with money ${before}: a poorer lifestyle, work or a debt, as you judge. Read ${lifestyle.rules}.`;
107
+ return `${member.name} cannot pay ${withArticle(named)} day, ${lifestyle.costs[named]}, with money ${before}: a poorer lifestyle, work or a debt, as you judge. Read ${lifestyle.rules}.`;
108
108
  }
109
109
  const after = formatAmount(payment.purse, coins);
110
110
  writePage(world, member.name, undefined, { set: { money: after } });
111
111
  appendLogEntry(root, newDatedLogEntry(root, context, "counter-changed", "public", { page: member.name, field: "money", before, after, why: `a ${named} day`, upkeep: true }));
112
- return `${member.name} pays a ${named} day: money ${before} → ${after}.`;
112
+ return `${member.name} pays ${withArticle(named)} day: money ${before} → ${after}.`;
113
113
  }
114
114
  /** Whether a page stands in a settlement, or in a place inside one (UPK-1). */
115
115
  function inSettlement(world, page) {
@@ -24,7 +24,7 @@ export interface ShownPerson {
24
24
  effects?: SeenEffect[];
25
25
  /** A condition keeps them from acting (D-314). */
26
26
  inactive?: true;
27
- /** At 0, as Combat tells it (D-314): one of the party at the system's dying point, another when a foe's counter in words says down. */
27
+ /** At 0, as Combat tells it (D-314): one of the party at the system's down point, another when a foe's counter in words says down. */
28
28
  down?: true;
29
29
  dead?: true;
30
30
  }
@@ -92,7 +92,7 @@ export interface ShownGrid {
92
92
  }
93
93
  /**
94
94
  * Someone in a fight as the player sees them (D-314): their counter, the party's as numbers and a foe's in words, or none; what is on them, the party's as their
95
- * line gives it, with its end, for others only the conditions anyone sees, by name; whether they cannot act; what they keep alive; the panel of the dying.
95
+ * line gives it, with its end, for others only the conditions anyone sees, by name; whether they cannot act; what they keep alive; whether down.
96
96
  */
97
97
  export interface Fighter {
98
98
  name: string;
@@ -112,19 +112,8 @@ export interface Fighter {
112
112
  effects: SeenEffect[];
113
113
  inactive?: true;
114
114
  keeps?: string[];
115
- dying?: DyingCounter[];
116
- }
117
- /** A counter of the panel of the dying (D-314): its value, and the limit the system's thresholds give it. */
118
- export interface DyingCounter {
119
- field: string;
120
- value: number;
121
- limit?: number;
122
- /** Which side of the death saves it counts, by the system's names (D-461): the successes or the failures. */
123
- side?: "successes" | "failures";
124
- /** Of the successes, what the system calls one whose counter is full, as Stable. */
125
- full?: string;
126
- /** The short word of its marks, as Successes. */
127
- mark?: string;
115
+ /** One of the party at the system's down point (D-516). */
116
+ down?: true;
128
117
  }
129
118
  /** The open scene as the player sees it (VIEW-6): who is in it as in VIEW-4, and the order of the turns. */
130
119
  export interface ShownScene {
@@ -154,6 +143,8 @@ export interface PlaceSight {
154
143
  world: World;
155
144
  knowledge: Knowledge;
156
145
  party: Page[];
146
+ /** The game system's words in the campaign's language, by their English (D-403): effects named in it are its conditions too. */
147
+ words?: Record<string, string>;
157
148
  }
158
149
  /** Where the player character is, as it knows it; none when it is in no place it knows, as in the open on a journey. */
159
150
  export declare function shownPlace(sight: PlaceSight): ShownPlace | undefined;
@@ -165,11 +156,8 @@ export declare function shownScene(sight: PlaceSight): ShownScene | undefined;
165
156
  * a character agent's is (VIEW-10).
166
157
  */
167
158
  export declare function sceneNames(sight: PlaceSight, leftOut?: Page): string[];
168
- /**
169
- * The panel of the dying of someone of the party (D-310 (7), D-314): at the value of the counter the system names, as hp 0, the counters it shows, with their
170
- * limits, or below it in a game whose counter goes below; none above it, nor for the dead.
171
- */
172
- export declare function dyingOf(world: World, system: GameSystem | undefined, page: Page): DyingCounter[] | undefined;
159
+ /** Whether someone of the party is down (D-516): at the value of the counter the system names, as hp 0, or below it; never the dead. */
160
+ export declare function isDown(world: World, system: GameSystem | undefined, page: Page): boolean;
173
161
  /** An effect on someone of the party as the player sees it: an end at someone's turn names them as the character knows them (VIEW-4), as creature 2. */
174
162
  export declare function seenEffect(sight: PlaceSight, effect: Effect): SeenEffect;
175
163
  /** The picture of one the character does not know, as strangerPicture gives it, for the scene and for the rolls (D-420, D-421). */
@@ -6,7 +6,7 @@ import { reachable, squareName, squaresApart, withoutMapBlock } from "../grid/in
6
6
  import { hiddenImageName } from "../images/index.js";
7
7
  import { environmentAt, isPlayerCharacter, locate, pagesWithName, pagesWithNameOrAlias, parsePageReference, placesAround } from "../pages/index.js";
8
8
  import { effectsOf } from "./effect-layer.js";
9
- import { conditionMark, effectParts, keptEffects } from "./game-effects.js";
9
+ import { conditionMark, effectParts, keptEffects, systemNamed } from "./game-effects.js";
10
10
  import { isTurnOf, movedThisTurn, sideOf, walkingSpeed } from "./game-grid-moves.js";
11
11
  import { placeGrid, placeLook, standing } from "./game-grids.js";
12
12
  import { imageFile, ownImage, shownImage } from "./game-images.js";
@@ -228,7 +228,7 @@ function fighterOf(sight, scene, name) {
228
228
  const effects = shownEffects(sight, system, page, party);
229
229
  const health = healthOf(sight.world, system, page, party);
230
230
  const keeps = party ? keptEffects(sight.world, readOpenScene(sight.root).scene, page.name) : [];
231
- const dying = party ? dyingOf(sight.world, system, page) : undefined;
231
+ const down = party && isDown(sight.world, system, page);
232
232
  const icon = party ? tokenIcon(sight.world, system, page) : undefined;
233
233
  return {
234
234
  name: shown,
@@ -240,39 +240,26 @@ function fighterOf(sight, scene, name) {
240
240
  ...(health === undefined ? {} : { health: health.word }),
241
241
  ...(health?.wound === undefined ? {} : { wound: health.wound }),
242
242
  effects,
243
- ...(keepsFromActing(system, effects) ? { inactive: true } : {}),
243
+ ...(keepsFromActing(system, effects, sight.words) ? { inactive: true } : {}),
244
244
  ...(keeps.length === 0 ? {} : { keeps }),
245
- ...(dying === undefined ? {} : { dying }),
245
+ ...(down ? { down: true } : {}),
246
246
  };
247
247
  }
248
- /**
249
- * The panel of the dying of someone of the party (D-310 (7), D-314): at the value of the counter the system names, as hp 0, the counters it shows, with their
250
- * limits, or below it in a game whose counter goes below; none above it, nor for the dead.
251
- */
252
- export function dyingOf(world, system, page) {
253
- const counters = pageCounters(world, page);
254
- const dying = system?.dying;
255
- const value = readCounter(counters[dying?.field ?? ""])?.value;
256
- if (dying === undefined || page.fields.status === "dead" || value === undefined || value > dying.value) {
257
- return undefined;
258
- }
259
- // Each counter by its side, as the system names them (D-461).
260
- return ["successes", "failures"].flatMap((side) => {
261
- const field = dying.show[side];
262
- const full = side === "successes" && dying.stable !== undefined ? { full: dying.stable } : {};
263
- const mark = dying.marks[side] === undefined ? {} : { mark: dying.marks[side] };
264
- return field === undefined ? [] : [{ field, value: readCounter(counters[field] ?? page.fields[field])?.value ?? 0, ...limitOf(system?.thresholds ?? [], field), side, ...full, ...mark }];
265
- });
248
+ /** Whether someone of the party is down (D-516): at the value of the counter the system names, as hp 0, or below it; never the dead. */
249
+ export function isDown(world, system, page) {
250
+ const down = system?.down;
251
+ const value = readCounter(pageCounters(world, page)[down?.field ?? ""])?.value;
252
+ return down !== undefined && page.fields.status !== "dead" && value !== undefined && value <= down.value;
266
253
  }
267
254
  /** An effect on someone of the party as the player sees it: an end at someone's turn names them as the character knows them (VIEW-4), as creature 2. */
268
255
  export function seenEffect(sight, effect) {
269
256
  const end = effect.end;
270
257
  const system = campaignSystem(sight.root, sight.context);
271
258
  if (end === undefined || !("turn" in end)) {
272
- return effectParts(sight.world, system, effect);
259
+ return effectParts(sight.world, system, effect, sight.words);
273
260
  }
274
261
  const scene = readOpenScene(sight.root).scene ?? { copies: {} };
275
- return effectParts(sight.world, system, { ...effect, end: { ...end, turn: shownTurn(sight, scene, end.turn) } });
262
+ return effectParts(sight.world, system, { ...effect, end: { ...end, turn: shownTurn(sight, scene, end.turn) } }, sight.words);
276
263
  }
277
264
  /**
278
265
  * The state a token shows (D-419): what is on them, whether a condition keeps them from acting, whether they are at 0 as Combat tells it, or dead; the party in
@@ -283,10 +270,10 @@ function stateOf(sight, page) {
283
270
  const party = sight.party.includes(page);
284
271
  const effects = shownEffects(sight, system, page, party);
285
272
  const dead = page.fields.status === "dead";
286
- const down = !dead && (party ? dyingOf(sight.world, system, page) !== undefined : healthOf(sight.world, system, page, false)?.wound === "down");
273
+ const down = !dead && (party ? isDown(sight.world, system, page) : healthOf(sight.world, system, page, false)?.wound === "down");
287
274
  return {
288
275
  ...(effects.length === 0 ? {} : { effects }),
289
- ...(keepsFromActing(system, effects) ? { inactive: true } : {}),
276
+ ...(keepsFromActing(system, effects, sight.words) ? { inactive: true } : {}),
290
277
  ...(down ? { down: true } : {}),
291
278
  ...(dead ? { dead: true } : {}),
292
279
  };
@@ -298,14 +285,13 @@ function strangerState(sight, scene, page) {
298
285
  /** What is on someone as the player sees it (D-314, D-419): the party's effects as their line gives them, with their end; of the others only the conditions anyone sees. */
299
286
  function shownEffects(sight, system, page, party) {
300
287
  return effectsOf(page).flatMap((effect) => {
301
- const mark = conditionMark(system, effect.name);
288
+ const mark = conditionMark(system, effect.name, sight.words);
302
289
  return party ? [seenEffect(sight, effect)] : mark.condition === true ? [{ name: effect.name, text: effect.name, ...mark }] : [];
303
290
  });
304
291
  }
305
292
  /** Whether one of these effects is a condition the system says keeps from acting (D-314). */
306
- function keepsFromActing(system, effects) {
307
- const inactive = new Set((system?.combat?.inactive ?? []).map(comparableText));
308
- return effects.some((effect) => inactive.has(comparableText(effect.name)));
293
+ function keepsFromActing(system, effects, words) {
294
+ return effects.some((effect) => systemNamed(system?.combat?.inactive ?? [], effect.name, words) !== undefined);
309
295
  }
310
296
  /**
311
297
  * Someone's counter in a fight as the player may know it (D-238, D-314): a foe's in the system's words when it gives them, as the 5e's hit points; else as it
@@ -335,11 +321,6 @@ function healthIndex(count, value, most) {
335
321
  }
336
322
  return 1 + Math.min(between - 1, Math.floor(((most - value) * between) / most));
337
323
  }
338
- /** The limit a threshold of the system gives a counter, as death-failures 3. */
339
- function limitOf(thresholds, field) {
340
- const limit = thresholds.find((threshold) => comparableText(threshold.field) === comparableText(field))?.value;
341
- return limit === undefined ? {} : { limit };
342
- }
343
324
  /** The mark of one the master says attacks the party, in a fight (D-415); nothing for anyone else, or outside a fight. */
344
325
  function hostileMark(scene, name) {
345
326
  const hostile = scene?.type === "combat" && (scene.hostile ?? []).some((one) => comparableText(one) === comparableText(parsePageReference(name).name));
@@ -1,18 +1,22 @@
1
1
  import type { Context } from "../core/context.ts";
2
+ import type { CardTint, Widget, WidgetText, WidgetValue } from "../core/package-api.ts";
3
+ import { type WidgetPlace } from "../core/package-declarations.ts";
2
4
  import type { Problem } from "../core/problem.ts";
3
- import { type Widget, type WidgetPage, type WidgetPlace, type WidgetText, type WidgetValue } from "../extensions/index.ts";
5
+ import { type CodePackage } from "../extensions/index.ts";
6
+ import { type CardPage, type FigureSize } from "../page.ts";
4
7
  /** Where a widget stands: a place of the dashboard, with its page for a card in one, and its order among the cards there; or off. */
5
8
  export interface WidgetSpot {
6
9
  place: WidgetPlace | "off";
7
- page?: WidgetPage;
10
+ page?: CardPage;
8
11
  order: number;
9
12
  }
10
13
  /** A widget as the dashboard shows it (D-502): which it is, whose, its title in the campaign's language, where it stands and where its extension puts it, its icon, what it shows now. */
11
14
  export interface ShownWidget extends WidgetSpot {
12
- /** Its extension's name and its own, as campaign.yaml names it: weather.today. */
15
+ /** Its package's name and its own, as campaign.yaml names it: weather.today. */
13
16
  id: string;
17
+ /** Its package's name, an extension's or the game system's. */
14
18
  extension: string;
15
- /** The extension's title, as Settings names whose it is. */
19
+ /** The package's title, as Settings names whose it is. */
16
20
  from: string;
17
21
  title: string;
18
22
  own: WidgetSpot;
@@ -20,13 +24,31 @@ export interface ShownWidget extends WidgetSpot {
20
24
  icon?: string;
21
25
  /** What it shows now; none while it has nothing to show, or is off. */
22
26
  shows?: ShownContent;
27
+ /** In place person, what it shows on each of the party, by their name: only those it shows something on (D-514). */
28
+ people?: Record<string, ShownContent>;
23
29
  /** Why it shows nothing, for whoever made it: its code failed, or gave what the dashboard does not show. */
24
30
  problem?: string;
31
+ /** Its extension's version, which an error of its page code names (D-510). */
32
+ version?: string;
33
+ /** The address of its extension's page module, when it has one and its code runs (D-510). */
34
+ module?: string;
35
+ /** The figures its extension's page code draws, by name, with the room each takes (D-510). */
36
+ figures?: Record<string, FigureSize>;
37
+ /** Its extension's words in the campaign's language, by their English, for its page code's own words; none when it is written in that language. */
38
+ words?: Record<string, string>;
25
39
  }
26
40
  /** What a widget shows, as the page draws it: its words in the campaign's language, its icons as their paths, its pictures as files. */
27
41
  export interface ShownContent {
42
+ /** What only its page code draws (D-510): JSON as its hook gave it, never read by the master. */
43
+ data?: unknown;
44
+ /** The figure that draws the whole inside of its card of a roll (D-510). */
45
+ body?: string;
28
46
  icon?: string;
29
47
  chip?: WidgetText;
48
+ /** In place person, dead by the package's rules though not marked so (D-516). */
49
+ dead?: true;
50
+ /** In the card of a question, the colour of its moment (D-517). */
51
+ tint?: CardTint;
30
52
  says?: WidgetText;
31
53
  note?: WidgetText;
32
54
  parts?: ShownPart[];
@@ -40,6 +62,8 @@ export type ShownPart = Exclude<NonNullable<Widget["parts"]>[number], {
40
62
  lead: WidgetText;
41
63
  icon?: string;
42
64
  value?: WidgetValue;
65
+ tone?: "good" | "bad";
66
+ figure?: string;
43
67
  } | {
44
68
  image: {
45
69
  extension: string;
@@ -49,18 +73,28 @@ export type ShownPart = Exclude<NonNullable<Widget["parts"]>[number], {
49
73
  alt: WidgetText;
50
74
  };
51
75
  /** The places a campaign may put a widget in, in campaign.yaml: top, side, a page, which is a card in that page, or off. */
52
- export declare const widgetSpots: readonly [...("top" | "side")[], "scene", "sheet", "world", "journal", "off"];
76
+ export declare const widgetSpots: readonly [...("top" | "side" | "person")[], "scene", "sheet", "world", "journal", "off"];
53
77
  /**
54
- * The widgets of the campaign's extensions, in the order of the extensions and of their widgets, each where it stands and with what its hook shows now. The
55
- * hooks run together, within one time for all; one that takes longer shows nothing this time, and is not called again while it works.
78
+ * The widgets of the campaign's packages, its game system's first, in the order of the packages and of their widgets, each where it stands and with what its
79
+ * hook shows now. The hooks run together, within one time for all; one that takes longer shows nothing this time, and is not called again while it works.
56
80
  */
57
81
  export declare function campaignWidgets(root: string, context: Context): Promise<ShownWidget[]>;
58
82
  /** What keeps the words of the campaign's extensions from being read in its language, for validate: the file, and how to fix it (D-502). */
59
83
  export declare function extensionWordsProblems(root: string, context: Context): Problem[];
60
- /** The widgets of the campaign's extensions by the names campaign.yaml gives them, as weather.today, with where each extension puts it. */
84
+ /** The widgets of the campaign's packages by the names campaign.yaml gives them, as weather.today, with where each package puts it. */
61
85
  export declare function campaignWidgetNames(root: string, context: Context): Record<string, WidgetSpot>;
62
86
  /**
63
87
  * Where campaign.yaml would put the widgets it names, checked before it is written: each a widget of the campaign's extensions, each place one of those the
64
88
  * dashboard has. It throws what is wrong, and how to write it.
65
89
  */
66
90
  export declare function checkWidgetSpots(root: string, context: Context, entries: Record<string, unknown>): void;
91
+ /**
92
+ * What one widget of a package shows now, for the card of a question (D-507): read as the dashboard reads it, in the campaign's language; nothing when its
93
+ * hook is not there, fails, gives what no part draws, or is late.
94
+ */
95
+ export declare function widgetCard(root: string, context: Context, extension: CodePackage, name: string, key: string, who?: string): Promise<ShownContent | undefined>;
96
+ /**
97
+ * What one widget of a package shows for a card of its page code, for the character the card shows (D-514): the package by its npm name, the widget declared
98
+ * by it; nothing when either is not the campaign's, or as for a card of a question.
99
+ */
100
+ export declare function packageWidget(root: string, context: Context, packageName: string, name: string, who: string | undefined): Promise<ShownContent | undefined>;