rpg-engine 0.5.0 → 0.6.1

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 +2 -2
  171. package/instructions/mentor-tutorial.md +1 -1
  172. package/instructions/play.md +3 -3
  173. package/instructions/setup.md +1 -1
  174. package/package.json +10 -2
  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 +37 -9
  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
@@ -1,24 +1,29 @@
1
- // The widgets of the campaign's extensions on the dashboard (D-502): where each stands, as its extension.yaml puts it and campaign.yaml moves it, and what its
2
- // code's hook shows now, checked and kept short, in the campaign's language. The extension's state never reaches the page: only what its hook gives.
1
+ // The widgets of the campaign's packages on the dashboard (D-502, D-514), its game system's and its extensions': where each stands, as its extension.yaml or
2
+ // system.yaml puts it and campaign.yaml moves it, and what its code's hook shows now, checked and kept short, in the campaign's language. The package's state
3
+ // never reaches the page: only what its hook gives.
3
4
  import { basename } from "node:path";
4
5
  import { z } from "zod";
5
6
  import { campaignFileName, readOneSetting, readTextSetting } from "../campaign/index.js";
7
+ import { widgetPlaces } from "../core/package-declarations.js";
6
8
  import { files } from "../core/store.js";
7
9
  import { comparableText } from "../core/text.js";
8
- import { extensionWords, widgetPages, widgetPlaces, wordIn, } from "../extensions/index.js";
10
+ import { wordIn } from "../extensions/index.js";
9
11
  import { findImage } from "../images/index.js";
10
- import { campaignExtensions } from "./game-extension-list.js";
11
- import { extensionCode, gameViewOf } from "./game-extensions.js";
12
+ import { cardPages } from "../page.js";
13
+ import { isInParty } from "../pages/index.js";
14
+ import { campaignExtensions, packageWords, pageAddress, runsCode } from "./game-extension-list.js";
15
+ import { campaignPackages, gameViewOf, packageCode } from "./game-package-code.js";
16
+ import { campaignWorld } from "./game-world.js";
12
17
  /** 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. */
13
- export const widgetSpots = [...widgetPlaces.filter((place) => place !== "page"), ...widgetPages, "off"];
18
+ export const widgetSpots = [...widgetPlaces.filter((place) => place !== "page" && place !== "card"), ...cardPages, "off"];
14
19
  // How long the hooks may take, all together, before the page goes on without those still at work, and the most a widget may give, as JSON.
15
20
  const hookTime = 2000;
16
21
  const mostShown = 12_000;
17
22
  // The hooks still at work, by campaign, extension and widget: a reading that comes meanwhile waits on the same call, never calls again.
18
23
  const working = new Map();
19
24
  /**
20
- * 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
21
- * hooks run together, within one time for all; one that takes longer shows nothing this time, and is not called again while it works.
25
+ * 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
26
+ * 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.
22
27
  */
23
28
  export async function campaignWidgets(root, context) {
24
29
  const spots = campaignSpots(root);
@@ -28,9 +33,9 @@ export async function campaignWidgets(root, context) {
28
33
  timer = setTimeout(() => done("late"), hookTime).unref();
29
34
  });
30
35
  const reading = [];
31
- for (const extension of campaignExtensions(root, context).extensions) {
36
+ for (const extension of campaignPackages(root, context)) {
32
37
  const words = wordsOf(extension, language);
33
- const code = extension.widgets.length === 0 ? undefined : extensionCode(extension).then((loaded) => ({ loaded }), (error) => ({ error: messageOf(error) }));
38
+ const code = extension.widgets.length === 0 ? undefined : packageCode(extension, context).then((loaded) => ({ loaded }), (error) => ({ error: messageOf(error) }));
34
39
  for (const widget of extension.widgets) {
35
40
  const id = `${extension.name}.${widget.name}`;
36
41
  const own = ownSpot(widget);
@@ -45,12 +50,17 @@ export async function campaignWidgets(root, context) {
45
50
  own,
46
51
  ...(widget.icon === undefined ? {} : { icon: extension.icons[widget.icon] }),
47
52
  ...(words.problem === undefined ? {} : { problem: words.problem }),
53
+ ...pageOf(extension),
54
+ // Its words for its page code's own words, in the campaign's language (D-510).
55
+ ...(extension.page === undefined || words.read === undefined || Object.keys(words.read.words).length === 0 ? {} : { words: words.read.words }),
48
56
  };
49
- if (spot.place === "off" || code === undefined) {
57
+ // A widget only of the cards of questions is read when one asks in it, never here.
58
+ if (spot.place === "off" || spot.place === "card" || code === undefined) {
50
59
  reading.push(Promise.resolve(base));
51
60
  continue;
52
61
  }
53
- reading.push(code.then((loaded) => widgetNow(root, context, extension, widget.name, base, loaded, words.read, late)));
62
+ const party = spot.place === "person" ? partyNames(root, context) : undefined;
63
+ reading.push(code.then((loaded) => widgetNow(root, context, extension, widget.name, base, loaded, words.read, late, party)));
54
64
  }
55
65
  }
56
66
  try {
@@ -69,12 +79,15 @@ export function extensionWordsProblems(root, context) {
69
79
  });
70
80
  }
71
81
  /** A widget with what its hook shows now, or why it shows nothing: its code, a hook it lacks, a hook that failed or was late, what it gave. */
72
- async function widgetNow(root, context, extension, name, base, loaded, words, late) {
82
+ async function widgetNow(root, context, extension, name, base, loaded, words, late, party) {
73
83
  const hook = "error" in loaded ? undefined : loaded.loaded?.widgets?.[name];
74
84
  if (hook === undefined) {
75
85
  const problem = "error" in loaded ? `its code cannot be used: ${loaded.error}` : loaded.loaded === undefined ? "its code does not run in this campaign" : `its code gives nothing for the widget ${name}`;
76
86
  return { ...base, problem };
77
87
  }
88
+ if (party !== undefined) {
89
+ return await peopleNow(root, context, extension, name, base, hook, words, late, party);
90
+ }
78
91
  try {
79
92
  const answer = await Promise.race([hookCall(root, extension, name, () => hook(gameViewOf(root, context, extension))), late]);
80
93
  if (answer === "late") {
@@ -87,6 +100,32 @@ async function widgetNow(root, context, extension, name, base, loaded, words, la
87
100
  return { ...base, problem: messageOf(error) };
88
101
  }
89
102
  }
103
+ /**
104
+ * A widget in place person with what its hook shows on each of the party, by name (D-514): one called for each, together; one that fails or is late shows
105
+ * nothing on them, and the first problem says why.
106
+ */
107
+ async function peopleNow(root, context, extension, name, base, hook, words, late, party) {
108
+ const shown = await Promise.all(party.map(async (who) => {
109
+ try {
110
+ const answer = await Promise.race([hookCall(root, extension, `${name}#person#${who}`, () => hook(gameViewOf(root, context, extension), { who })), late]);
111
+ if (answer === "late") {
112
+ return { problem: `it gave nothing in ${hookTime / 1000} seconds` };
113
+ }
114
+ return answer === undefined ? {} : { shows: [who, shownContent(extension, words, answer)] };
115
+ }
116
+ catch (error) {
117
+ return { problem: messageOf(error) };
118
+ }
119
+ }));
120
+ const people = Object.fromEntries(shown.flatMap((one) => (one.shows === undefined ? [] : [one.shows])));
121
+ // The first in the party's order, whichever answered first.
122
+ const problem = shown.find((one) => one.problem !== undefined)?.problem;
123
+ return { ...base, ...(Object.keys(people).length === 0 ? {} : { people }), ...(problem === undefined ? {} : { problem }) };
124
+ }
125
+ /** The names of the party, the player's characters and their companions, in the order of the pages. */
126
+ function partyNames(root, context) {
127
+ return campaignWorld(root, context).pages.filter(isInParty).map((page) => page.name);
128
+ }
90
129
  /** A hook's call, or the one already at work for the same widget of the same campaign. */
91
130
  function hookCall(root, extension, widget, call) {
92
131
  const key = `${root}|${extension.package}@${extension.version}|${widget}`;
@@ -98,21 +137,31 @@ function hookCall(root, extension, widget, call) {
98
137
  working.set(key, started);
99
138
  return started;
100
139
  }
101
- /** The widgets of the campaign's extensions by the names campaign.yaml gives them, as weather.today, with where each extension puts it. */
140
+ /** The widgets of the campaign's packages by the names campaign.yaml gives them, as weather.today, with where each package puts it. */
102
141
  export function campaignWidgetNames(root, context) {
103
- return Object.fromEntries(campaignExtensions(root, context).extensions.flatMap((extension) => extension.widgets.map((widget) => [`${extension.name}.${widget.name}`, ownSpot(widget)])));
142
+ return Object.fromEntries(campaignPackages(root, context).flatMap((extension) => extension.widgets.map((widget) => [`${extension.name}.${widget.name}`, ownSpot(widget)])));
104
143
  }
105
144
  /**
106
145
  * 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
107
146
  * dashboard has. It throws what is wrong, and how to write it.
108
147
  */
109
148
  export function checkWidgetSpots(root, context, entries) {
110
- const known = Object.keys(campaignWidgetNames(root, context));
149
+ const spots = campaignWidgetNames(root, context);
150
+ const known = Object.keys(spots);
111
151
  for (const [name, value] of Object.entries(entries)) {
112
- if (!known.some((one) => comparableText(one) === comparableText(name))) {
113
- const names = known.length === 0 ? "the campaign's extensions have none" : `the campaign's are ${known.join(", ")}`;
152
+ const own = Object.entries(spots).find(([one]) => comparableText(one) === comparableText(name))?.[1];
153
+ if (own === undefined) {
154
+ const names = known.length === 0 ? "the campaign's packages have none" : `the campaign's are ${known.join(", ")}`;
114
155
  throw new Error(`There is no widget ${name}: ${names}. Write one as ${known[0] ?? "weather.today"}: side. Nothing changed.`);
115
156
  }
157
+ // A widget made for each of the party shows only there, or nowhere, as its hook needs who (D-514); another may come there too (D-516).
158
+ const place = typeof value === "string" ? value : value !== null && typeof value === "object" && "place" in value ? value.place : undefined;
159
+ if (own.place === "person" && place !== "person" && place !== "off") {
160
+ throw new Error(`${name} stands on each of the party: write ${name}: off, or ${name}: person. Nothing changed.`);
161
+ }
162
+ if (own.place === "card") {
163
+ throw new Error(`${name} shows only in the card its package asks a roll in, so it has no place to choose: take ${name} out of widgets. Nothing changed.`);
164
+ }
116
165
  if (!spotSchema.safeParse(value).success) {
117
166
  // Of a place written as its parts, what is wrong with them, as an order that is no whole number.
118
167
  const issue = value !== null && typeof value === "object" ? spotObject.safeParse(value).error?.issues[0] : undefined;
@@ -121,12 +170,14 @@ export function checkWidgetSpots(root, context, entries) {
121
170
  }
122
171
  }
123
172
  }
173
+ // The places campaign.yaml may give a widget.
174
+ const spotPlaces = [...widgetPlaces.filter((place) => place !== "card"), "off"];
124
175
  // The most and least order of a card among those of its place.
125
176
  const orderWords = "is a whole number from -100 to 100";
126
177
  /** A widget's place in campaign.yaml as its place, page and order. */
127
178
  const spotObject = z.object({
128
- place: z.enum([...widgetPlaces, "off"], { error: `is ${[...widgetPlaces, "off"].join(", ")}` }).optional(),
129
- page: z.enum(widgetPages, { error: `is ${widgetPages.join(", ")}` }).optional(),
179
+ place: z.enum(spotPlaces, { error: `is ${spotPlaces.join(", ")}` }).optional(),
180
+ page: z.enum(cardPages, { error: `is ${cardPages.join(", ")}` }).optional(),
130
181
  order: z.int({ error: orderWords }).min(-100, { error: orderWords }).max(100, { error: orderWords }).optional(),
131
182
  }, { error: (issue) => (issue.code === "unrecognized_keys" ? `has no ${issue.keys.join(", ")}: only place, page and order` : undefined) }).strict().refine((spot) => spot.place !== "page" || spot.page !== undefined, { error: "a card in place page names its page: scene, sheet, world or journal" });
132
183
  /** A widget's place in campaign.yaml: a word, or its place, page and order. */
@@ -151,20 +202,28 @@ function ownSpot(widget) {
151
202
  }
152
203
  /** Where the campaign puts a widget: a page's name is a card in that page; a place without its page keeps the extension's page, else the Scene. */
153
204
  function spotOf(given, own) {
205
+ // A widget made for each of the party is there or off, as its hook needs who; another may come there too, a small card on each (D-516).
206
+ const named = typeof given === "string" ? given : given.place;
207
+ if (own.place === "person") {
208
+ return named === "off" ? { place: "off", order: own.order } : own;
209
+ }
210
+ if (own.place === "card") {
211
+ return own;
212
+ }
154
213
  if (typeof given === "string") {
155
- return widgetPages.includes(given) ? { place: "page", page: given, order: own.order } : { place: given, order: own.order };
214
+ return cardPages.includes(given) ? { place: "page", page: given, order: own.order } : { place: given, order: own.order };
156
215
  }
157
216
  const place = given.place ?? (given.page === undefined ? own.place : "page");
158
217
  const page = place === "page" ? given.page ?? own.page ?? "scene" : undefined;
159
218
  return { place, ...(page === undefined ? {} : { page }), order: given.order ?? own.order };
160
219
  }
161
- /** An extension's words in the campaign's language, none where it is written in it; or why they cannot be read, with their file. */
220
+ /** A package's words in the campaign's language, none where it is written in it; or why they cannot be read, with their file. */
162
221
  function wordsOf(extension, language) {
163
222
  if (language === undefined || language.split("-")[0] === extension.language.split("-")[0]) {
164
223
  return {};
165
224
  }
166
225
  try {
167
- const read = extensionWords(extension.folder, language);
226
+ const read = packageWords(extension, language);
168
227
  return read === undefined ? {} : { read };
169
228
  }
170
229
  catch (error) {
@@ -186,7 +245,8 @@ const textSchema = z.union([
186
245
  const iconName = z.string().regex(/^[a-z][a-z0-9-]*$/);
187
246
  const toneSchema = z.enum(["good", "bad"]);
188
247
  const partSchema = z.union([
189
- z.object({ lead: textSchema, icon: iconName.optional(), value: valueSchema.optional(), tone: toneSchema.optional() }).strict(),
248
+ z.object({ lead: textSchema, icon: iconName.optional(), value: valueSchema.optional(), tone: toneSchema.optional(), figure: iconName.optional() }).strict(),
249
+ z.object({ who: text(80), does: textSchema.optional() }).strict(),
190
250
  z.object({ text: textSchema }).strict(),
191
251
  z.object({ facts: z.array(textSchema).max(12) }).strict(),
192
252
  z.object({ values: z.array(z.object({ label: textSchema, value: valueSchema }).strict()).max(12) }).strict(),
@@ -201,6 +261,8 @@ const partSchema = z.union([
201
261
  coming: z.int().min(0).optional(),
202
262
  stage: z.enum(["start", "center", "end"]).optional(),
203
263
  tone: toneSchema.optional(),
264
+ figure: iconName.optional(),
265
+ field: z.string().min(1).max(60).optional(),
204
266
  }).strict(),
205
267
  }).strict(),
206
268
  z.object({ rows: z.array(z.object({ label: textSchema, value: valueSchema.optional(), note: textSchema.optional() }).strict()).max(24) }).strict(),
@@ -208,13 +270,18 @@ const partSchema = z.union([
208
270
  z.object({ image: z.string().regex(/^[\w .-]+\.(png|jpe?g|webp|svg)$/i), alt: textSchema }).strict(),
209
271
  ]);
210
272
  const widgetSchema = z.object({
273
+ // JSON for the page code alone, its size held by the most a widget gives.
274
+ data: z.json().optional(),
275
+ body: iconName.optional(),
211
276
  icon: iconName.optional(),
212
277
  chip: textSchema.optional(),
278
+ dead: z.boolean().optional(),
279
+ tint: z.enum(["low", "ally", "gold", "muted"], { error: "a card's tint is low, ally, gold or muted" }).optional(),
213
280
  says: textSchema.optional(),
214
281
  note: textSchema.optional(),
215
282
  parts: z.array(partSchema).max(12).optional(),
216
283
  }).strict();
217
- /** What a hook gave, checked, translated, its icons and pictures found; it throws what the dashboard cannot show, for whoever made the extension. */
284
+ /** What a hook gave, checked, translated, its icons and pictures found; it throws what the dashboard cannot show, for whoever made the package. */
218
285
  function shownContent(extension, words, given) {
219
286
  const parsed = widgetSchema.safeParse(given);
220
287
  if (!parsed.success) {
@@ -226,17 +293,29 @@ function shownContent(extension, words, given) {
226
293
  }
227
294
  const icon = (name) => {
228
295
  if (name !== undefined && extension.icons[name] === undefined) {
229
- throw new Error(`it names the icon ${name}, which its extension.yaml does not have`);
296
+ throw new Error(`it names the icon ${name}, which its ${fileOf(extension)} does not have`);
230
297
  }
231
298
  return name === undefined ? undefined : extension.icons[name];
232
299
  };
233
300
  const said = (one) => (typeof one === "string" ? wordIn(words, one) : { text: wordIn(words, one.text), values: Object.fromEntries(Object.entries(one.values).map(([name, value]) => [name, valueIn(value)])) });
234
301
  const valueIn = (value) => typeof value === "number" ? value : typeof value === "string" ? wordIn(words, value) : value.unit === undefined ? value : { ...value, unit: wordIn(words, value.unit) };
235
- const { icon: ownIcon, chip, says, note, parts } = parsed.data;
302
+ // A figure it names is one its package declares, for its page code to draw.
303
+ const figure = (name) => {
304
+ if (name !== undefined && extension.figures[name] === undefined) {
305
+ throw new Error(`it names the figure ${name}, which its ${fileOf(extension)} does not declare in figures`);
306
+ }
307
+ return name === undefined ? {} : { figure: name };
308
+ };
309
+ const { icon: ownIcon, chip, dead, tint, says, note, parts, data, body } = parsed.data;
236
310
  const shownIcon = icon(ownIcon);
311
+ const inside = body === undefined ? {} : { body: figure(body).figure };
237
312
  return {
313
+ ...(data === undefined ? {} : { data }),
314
+ ...inside,
238
315
  ...(shownIcon === undefined ? {} : { icon: shownIcon }),
239
316
  ...(chip === undefined ? {} : { chip: said(chip) }),
317
+ ...(dead === true ? { dead: true } : {}),
318
+ ...(tint === undefined ? {} : { tint }),
240
319
  ...(says === undefined ? {} : { says: said(says) }),
241
320
  ...(note === undefined ? {} : { note: said(note) }),
242
321
  ...(parts === undefined ? {} : {
@@ -244,7 +323,10 @@ function shownContent(extension, words, given) {
244
323
  if ("lead" in part) {
245
324
  const leadIcon = icon(part.icon);
246
325
  const tone = part.tone === undefined ? {} : { tone: part.tone };
247
- return { lead: said(part.lead), ...(leadIcon === undefined ? {} : { icon: leadIcon }), ...(part.value === undefined ? {} : { value: valueIn(part.value) }), ...tone };
326
+ return { lead: said(part.lead), ...(leadIcon === undefined ? {} : { icon: leadIcon }), ...(part.value === undefined ? {} : { value: valueIn(part.value) }), ...tone, ...figure(part.figure) };
327
+ }
328
+ if ("who" in part) {
329
+ return { who: part.who, ...(part.does === undefined ? {} : { does: said(part.does) }) };
248
330
  }
249
331
  if ("text" in part) {
250
332
  return { text: said(part.text) };
@@ -256,7 +338,7 @@ function shownContent(extension, words, given) {
256
338
  return { values: part.values.map((one) => ({ label: said(one.label), value: valueIn(one.value) })) };
257
339
  }
258
340
  if ("track" in part) {
259
- return { track: shownTrack({ ...part.track, label: said(part.track.label) }) };
341
+ return { track: shownTrack({ ...part.track, label: said(part.track.label), ...figure(part.track.figure) }) };
260
342
  }
261
343
  if ("rows" in part) {
262
344
  return {
@@ -288,12 +370,24 @@ function shownTrack(track) {
288
370
  return { ...track, value, ...(held === undefined ? {} : { held }), ...(marked === undefined ? {} : { marked }), ...(coming === undefined ? {} : { coming }) };
289
371
  }
290
372
  /**
291
- * What one widget of an extension shows now, for the card of a question (D-507): read as the dashboard reads it, in the campaign's language; nothing when its
373
+ * 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
292
374
  * hook is not there, fails, gives what no part draws, or is late.
293
375
  */
294
- export async function widgetCard(root, context, extension, name, key) {
376
+ export async function widgetCard(root, context, extension, name, key, who) {
377
+ return await widgetFor(root, context, extension, name, { key, ...(who === undefined ? {} : { who }) });
378
+ }
379
+ /**
380
+ * 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
381
+ * by it; nothing when either is not the campaign's, or as for a card of a question.
382
+ */
383
+ export async function packageWidget(root, context, packageName, name, who) {
384
+ const owner = campaignPackages(root, context).find((one) => one.package === packageName);
385
+ return owner === undefined || !owner.widgets.some((widget) => widget.name === name) ? undefined : await widgetFor(root, context, owner, name, who === undefined ? {} : { who });
386
+ }
387
+ /** What a widget shows for a card: for a question, by its key, the attempt; for a card of the page code, by who it shows. */
388
+ async function widgetFor(root, context, extension, name, asked) {
295
389
  try {
296
- const hook = (await extensionCode(extension))?.widgets?.[name];
390
+ const hook = (await packageCode(extension, context))?.widgets?.[name];
297
391
  if (hook === undefined) {
298
392
  return undefined;
299
393
  }
@@ -301,15 +395,20 @@ export async function widgetCard(root, context, extension, name, key) {
301
395
  const late = new Promise((done) => {
302
396
  timer = setTimeout(() => done("late"), hookTime).unref();
303
397
  });
304
- // Its own call for its key, never one at work for the column or another card.
305
- const answer = await Promise.race([hookCall(root, extension, `${name}#${key}`, () => hook(gameViewOf(root, context, extension), { key })), late]).finally(() => clearTimeout(timer));
398
+ // Its own call for its key or who, never one at work for the column or another card.
399
+ const answer = await Promise.race([hookCall(root, extension, `${name}#${asked.key ?? ""}#${asked.who ?? ""}`, () => hook(gameViewOf(root, context, extension), asked)), late]).finally(() => clearTimeout(timer));
306
400
  return answer === "late" || answer === undefined ? undefined : shownContent(extension, wordsOf(extension, readTextSetting(root, "language")).read, answer);
307
401
  }
308
402
  catch {
309
403
  return undefined;
310
404
  }
311
405
  }
312
- /** A picture of the extension's images/, as the dashboard serves it at an address of the extension's own; it throws when the extension has none by that name. */
406
+ /** Where a widget's page code is, when its package has some and its code runs (D-510): its module's address, its version, its figures. */
407
+ function pageOf(extension) {
408
+ const module = extension.page === undefined || !runsCode(extension) ? {} : { module: pageAddress(extension.package, extension.version, extension.page) };
409
+ return { version: extension.version, ...module, ...(Object.keys(extension.figures).length === 0 ? {} : { figures: extension.figures }) };
410
+ }
411
+ /** A picture of the package's images/, as the dashboard serves it at an address of the package's own; it throws when the package has none by that name. */
313
412
  function pictureOf(extension, name) {
314
413
  const file = findImage([extension.folder], name);
315
414
  if (file === undefined) {
@@ -317,6 +416,10 @@ function pictureOf(extension, name) {
317
416
  }
318
417
  return { extension: extension.name, file: basename(file), version: Math.trunc(files().modified(file) ?? 0) };
319
418
  }
419
+ /** The file a package declares its widgets, icons and figures in. */
420
+ function fileOf(extension) {
421
+ return extension.kind === "system" ? "system.yaml" : "extension.yaml";
422
+ }
320
423
  function messageOf(error) {
321
424
  return (error instanceof Error ? error.message : String(error)).split("\n")[0];
322
425
  }
@@ -10,6 +10,11 @@ export declare function campaignWorld(root: string, context: Context): World;
10
10
  * fields the campaign's extensions add, from their words, layered as their additions are (CAM-2, D-505).
11
11
  */
12
12
  export declare function systemWordsOf(root: string, system: GameSystem, language: string, context: Context): SystemWords | undefined;
13
+ /**
14
+ * The game system's words in the campaign's language, by their English (D-403), by which a name written in it is the system's, Prono its Prone; none without a
15
+ * language, or when they do not read. Kept until campaign.yaml, an extension or a translation of this computer changes.
16
+ */
17
+ export declare function campaignSystemWords(root: string, context: Context): Record<string, string> | undefined;
13
18
  /**
14
19
  * The installed game system that campaign.yaml names, with what the campaign adds to it (CAM-1, CAM-2): alone when the additions do not read (CAM-3). Undefined
15
20
  * when it names none, or one that is not installed (SYS-1).
@@ -26,6 +31,13 @@ export declare function playedLayers(root: string, context: Context): {
26
31
  export declare function extensionLayer(name: string): string;
27
32
  /** A setting the campaign's game system adds to the setup (DAT-10), by its name in any case; undefined when the system has none by that name. */
28
33
  export declare function systemSetting(root: string, context: Context, name: string): SystemSetting | undefined;
34
+ /**
35
+ * The value a setting of the system has in the campaign (DAT-10): the one campaign.yaml gives, when the system has it; for the version of the rules, once the game
36
+ * has begun, the one it plays unwritten, the first (VER-2). Undefined while it is still to be chosen.
37
+ */
38
+ export declare function playedSettingValue(root: string, context: Context, setting: SystemSetting): string | undefined;
39
+ /** The names of the player characters the game has begun with (D-519): from the first, the campaign keeps its system and the version of its rules (SYS-9, VER-4). */
40
+ export declare function playersOfTheGame(root: string, context: Context): string[];
29
41
  /** The value campaign.yaml gives a setting of the system, when it is one the system has (DAT-10). */
30
42
  export declare function systemSettingValue(root: string, setting: SystemSetting): string | undefined;
31
43
  /** "xp is not kept with advancement milestones": said when a field the campaign's settings leave out is written or changed (DAT-10); undefined for any other. */
@@ -73,6 +85,11 @@ export declare function missingWithSystems(root: string, missing: string[], cont
73
85
  * one that is not installed says so, with the fix (D-167). Undefined when campaign.yaml names none.
74
86
  */
75
87
  export declare function systemInStatus(root: string, context: Context): string | undefined;
88
+ /**
89
+ * ", the second rules": the version of its rules a system is played with, when it has more than one to choose from (VER-1), or that it is still to ask, so
90
+ * that the first, read meanwhile, is never taken as chosen; empty otherwise.
91
+ */
92
+ export declare function playedRules(root: string, context: Context, system: GameSystem): string;
76
93
  /** A language as messages name it, such as English for en. */
77
94
  export declare function languageName(code: string): string;
78
95
  /** What the game system counts itself, for a rigor's meaning (UPK-1, UPK-3): the day's food, and what burns, by its first name. */
@@ -1,12 +1,13 @@
1
1
  import { join, resolve } from "node:path";
2
2
  import { campaignFileName, readCampaignData, readOneSetting, readTextSetting } from "../campaign/index.js";
3
+ import { ourSystems } from "../core/package-declarations.js";
3
4
  import { files, isInside } from "../core/store.js";
4
5
  import { comparableText } from "../core/text.js";
5
6
  import { extensionWords } from "../extensions/index.js";
6
7
  import { languagePackFor, packSystemFolder } from "../languages/index.js";
7
8
  import { homeSystemWords } from "../page-words.js";
8
- import { loadWorld, searchSystemPages, worldFolderName } from "../pages/index.js";
9
- import { findCampaignSystem, findSystem, installedSystems, systemWords, withSettings } from "../systems/index.js";
9
+ import { loadWorld, playerCharacters, searchSystemPages, worldFolderName } from "../pages/index.js";
10
+ import { findCampaignSystem, findSystem, installedSystems, layeredSystemWords, rulesetSetting, systemContentFolders, systemWords, withSettings, } from "../systems/index.js";
10
11
  import { campaignExtensions, extensionSources, layeredParts } from "./game-extension-list.js";
11
12
  /** The world of the campaign in `root`, with the pages of its game system when campaign.yaml names one that is installed (SYS-1, SYS-3). */
12
13
  export function campaignWorld(root, context) {
@@ -19,6 +20,7 @@ export function campaignWorld(root, context) {
19
20
  return loadWorld(root, {
20
21
  system,
21
22
  language: readTextSetting(root, "language"),
23
+ words: campaignSystemWords(root, context),
22
24
  missingSystem: system === undefined ? named : undefined,
23
25
  noSystem: named === undefined,
24
26
  rigor: readTextSetting(root, "rigor"),
@@ -33,10 +35,29 @@ export function systemWordsOf(root, system, language, context) {
33
35
  // A language package's words come first, then the system's own, then those translated on the fly (D-485 (3)).
34
36
  const pack = languagePackFor(context.extensionFolders ?? [], language);
35
37
  const packed = pack === undefined ? undefined : packSystemFolder(pack, system.name);
36
- const own = (packed === undefined ? undefined : systemWords(packed, language)) ?? systemWords(system.folder, language) ?? homeSystemWords(context.home, system, language);
38
+ const own = (packed === undefined ? undefined : systemWords(packed, language)) ?? layeredSystemWords(systemContentFolders(system), language) ?? homeSystemWords(context.home, system, language);
37
39
  const added = campaignExtensions(root, context).extensions.reduce((fields, extension) => ({ ...fields, ...extensionFieldWords(extension, language) }), {});
38
40
  return Object.keys(added).length === 0 ? own : { ...(own ?? { groups: {}, words: {} }), fields: { ...own?.fields, ...added } };
39
41
  }
42
+ /**
43
+ * The game system's words in the campaign's language, by their English (D-403), by which a name written in it is the system's, Prono its Prone; none without a
44
+ * language, or when they do not read. Kept until campaign.yaml, an extension or a translation of this computer changes.
45
+ */
46
+ export function campaignSystemWords(root, context) {
47
+ const sources = extensionSources(root, context);
48
+ const translated = context.home === undefined ? undefined : resolve(join(context.home, "systems"));
49
+ const dependsOn = (path) => sources(path) || (translated !== undefined && (isInside(translated, path) || isInside(path, translated)));
50
+ return files().remember(`system words ${resolve(root)}`, dependsOn, () => {
51
+ const system = campaignSystem(root, context);
52
+ const language = readTextSetting(root, "language");
53
+ try {
54
+ return system === undefined || language === undefined ? undefined : systemWordsOf(root, system, language, context)?.words;
55
+ }
56
+ catch {
57
+ return undefined;
58
+ }
59
+ });
60
+ }
40
61
  /**
41
62
  * The installed game system that campaign.yaml names, with what the campaign adds to it (CAM-1, CAM-2): alone when the additions do not read (CAM-3). Undefined
42
63
  * when it names none, or one that is not installed (SYS-1).
@@ -52,7 +73,7 @@ function systemOf(root, context) {
52
73
  // campaign.yaml, and the extensions' packages, whose parts and additions it gives.
53
74
  return files().remember(`system ${resolve(root)}`, extensionSources(root, context), () => {
54
75
  const name = readTextSetting(root, "system");
55
- const found = name === undefined ? { refused: [] } : findCampaignSystem(context.systemFolders, name, systemLayers(root, context, readCampaignData(root)));
76
+ const found = name === undefined ? { refused: [] } : findCampaignSystem(context.systemFolders, name, systemLayers(root, context, readCampaignData(root)), readTextSetting(root, rulesetSetting));
56
77
  // And the parts of the instructions of its extensions over its own (D-121).
57
78
  const played = found.system === undefined ? undefined : withSettings(found.system, (setting) => readTextSetting(root, setting));
58
79
  return played === undefined ? found : { ...found, system: { ...played, parts: layeredParts(played.parts, campaignExtensions(root, context).extensions) } };
@@ -85,6 +106,18 @@ function extensionFieldWords(extension, language) {
85
106
  export function systemSetting(root, context, name) {
86
107
  return campaignSystem(root, context)?.settings.find((setting) => comparableText(setting.name) === comparableText(name.trim()));
87
108
  }
109
+ /**
110
+ * The value a setting of the system has in the campaign (DAT-10): the one campaign.yaml gives, when the system has it; for the version of the rules, once the game
111
+ * has begun, the one it plays unwritten, the first (VER-2). Undefined while it is still to be chosen.
112
+ */
113
+ export function playedSettingValue(root, context, setting) {
114
+ const written = systemSettingValue(root, setting);
115
+ return written !== undefined || setting.name !== rulesetSetting || playersOfTheGame(root, context).length === 0 ? written : campaignSystem(root, context)?.version?.name;
116
+ }
117
+ /** The names of the player characters the game has begun with (D-519): from the first, the campaign keeps its system and the version of its rules (SYS-9, VER-4). */
118
+ export function playersOfTheGame(root, context) {
119
+ return playerCharacters(campaignWorld(root, context)).map((page) => page.name);
120
+ }
88
121
  /** The value campaign.yaml gives a setting of the system, when it is one the system has (DAT-10). */
89
122
  export function systemSettingValue(root, setting) {
90
123
  const written = readTextSetting(root, setting.name);
@@ -149,19 +182,33 @@ export function systemProblems(root, context) {
149
182
  if (name === undefined || found?.system !== undefined) {
150
183
  return [];
151
184
  }
152
- const [first] = installedSystems(context.systemFolders);
153
185
  return [{
154
186
  path: "campaign.yaml",
155
187
  message: `The system ${name} is not installed: no creatures, items or rules come from a system. ${installedText(context)}`,
156
- fix: first === undefined ? "install the game system" : `ask the player which game you play, then config, setting system, value ${first.name}`,
188
+ fix: missingSystemFix(name, context),
157
189
  }];
158
190
  }
191
+ /** How a campaign gets the system it names that is not installed: one of ours with package install (D-513), else another of those installed, asked of the player. */
192
+ function missingSystemFix(name, context) {
193
+ const ours = ourSystems.find((one) => comparableText(one.name) === comparableText(name.trim()));
194
+ if (ours !== undefined) {
195
+ return `install it, one of RPG Engine's own, with package install ${ours.name}; until then, play on without its pages`;
196
+ }
197
+ const [first] = installedSystems(context.systemFolders);
198
+ return first === undefined ? "install the game system" : `ask the player which game you play, then config, setting system, value ${first.name}`;
199
+ }
159
200
  /** The name of an installed game system, as it is installed; refused, with those that are, when none has it (D-167). */
160
201
  export function installedSystemName(name, context, how) {
161
202
  const system = findSystem(context.systemFolders, name);
162
203
  if (system === undefined) {
163
204
  const [first] = installedSystems(context.systemFolders);
164
- const example = first === undefined ? "" : ` Give one of them, such as ${how === "init" ? "system" : "setting system, value"} ${first.name}.`;
205
+ const ours = ourSystems.find((one) => comparableText(one.name) === comparableText(name.trim()));
206
+ // One of ours is installed first, once the player wants it (D-513 (1)).
207
+ const example = ours !== undefined
208
+ ? ` It is one of RPG Engine's own: install it with package install ${ours.name} once the player wants it, then give it again.`
209
+ : first === undefined
210
+ ? ""
211
+ : ` Give one of them, such as ${how === "init" ? "system" : "setting system, value"} ${first.name}.`;
165
212
  throw new Error(`"${name}" is not an installed system. ${installedText(context)}${example} Nothing changed.`);
166
213
  }
167
214
  return system.name;
@@ -225,7 +272,7 @@ export function missingWithSystems(root, missing, context) {
225
272
  const names = installedSystems(context.systemFolders).map((system) => system.name);
226
273
  const system = names.length > 0 ? `system (installed: ${names.join(", ")})` : "system";
227
274
  // What the system adds to the setup, with its values: config says what each means (DAT-10).
228
- const added = (campaignSystem(root, context)?.settings ?? []).filter((setting) => systemSettingValue(root, setting) === undefined).map((setting) => `${setting.name} (${valuesText(setting)})`);
275
+ const added = (campaignSystem(root, context)?.settings ?? []).filter((setting) => playedSettingValue(root, context, setting) === undefined).map((setting) => `${setting.name} (${valuesText(setting)})`);
229
276
  // The system first (D-167): the other settings may depend on the game.
230
277
  return [...(missing.includes("system") ? [system, ...missing.filter((name) => name !== "system")] : missing), ...added];
231
278
  }
@@ -235,12 +282,23 @@ export function missingWithSystems(root, missing, context) {
235
282
  */
236
283
  export function systemInStatus(root, context) {
237
284
  const name = readTextSetting(root, "system");
238
- const system = name === undefined ? undefined : findSystem(context.systemFolders, name);
285
+ const system = name === undefined ? undefined : findSystem(context.systemFolders, name, readTextSetting(root, rulesetSetting));
286
+ // With the version of its rules the campaign plays (VER-1).
239
287
  if (name === undefined || system !== undefined) {
240
- return system === undefined ? undefined : `${system.name}, ${system.title}`;
288
+ return system === undefined ? undefined : `${system.name}, ${system.title}${playedRules(root, context, system)}`;
241
289
  }
242
- const [first] = installedSystems(context.systemFolders);
243
- return `${name} ${first === undefined ? "(not installed)" : `(not installed: ask the player, then config, setting system, value ${first.name})`}`;
290
+ return `${name} (not installed: ${missingSystemFix(name, context)})`;
291
+ }
292
+ /**
293
+ * ", the second rules": the version of its rules a system is played with, when it has more than one to choose from (VER-1), or that it is still to ask, so
294
+ * that the first, read meanwhile, is never taken as chosen; empty otherwise.
295
+ */
296
+ export function playedRules(root, context, system) {
297
+ const setting = system.settings.find((one) => one.name === rulesetSetting);
298
+ if (system.version === undefined || setting === undefined) {
299
+ return "";
300
+ }
301
+ return playedSettingValue(root, context, setting) === undefined ? ", the version of its rules still to ask" : `, ${system.version.title ?? system.version.name}`;
244
302
  }
245
303
  /** A language as messages name it, such as English for en. */
246
304
  export function languageName(code) {
@@ -16,7 +16,7 @@ import { sheetHeadline } from "./sheet.js";
16
16
  export const image = defineCommand({
17
17
  name: "image",
18
18
  description: "Give a page its picture: a portrait for a character, an image for a creature, an item or a place, as the dashboard will show it in a round token. "
19
- + "It copies the file into the campaign and links it in the page's image field; a page without one shows the picture of the page it derives from, such as a goblin's icon. "
19
+ + "It copies the file into the campaign and links it in the page's image field; a page without one shows the picture of the page it derives from, such as a wolf's icon. "
20
20
  + "Use it when the player gives you a picture, or after you made or downloaded one with your own tools. "
21
21
  + "For a place, a quest, a character or a creature of the campaign, describe instead of file has the picture made on this computer, as the campaign's pictures setting allows: "
22
22
  + "for the player character or a companion only when the player asks; for a creature once for each kind, whose copies show it. "
@@ -12,14 +12,14 @@ export const init = defineCommand({
12
12
  description: "Create a new campaign. "
13
13
  + "It writes the settings, the log, the world's folders, and the .mcp.json, AGENTS.md and CLAUDE.md through which an AI host finds these tools. "
14
14
  + "Use it once, when the player starts a new campaign; then ask the player for the missing settings and set them with config. "
15
- + 'Example: name "The Salt Isles", language en, system 5e.',
15
+ + 'Example: name "The Salt Isles", language en.',
16
16
  group: "campaign",
17
17
  positionals: ["folder"],
18
18
  input: z.object({
19
19
  folder: z.string().optional().describe("folder of the new campaign; the current folder if left out"),
20
20
  name: z.string().optional().describe("name of the campaign; the folder's name if left out"),
21
21
  language: z.string().optional().describe("language of the game, as a code such as it or en"),
22
- system: z.string().optional().describe("game system: one of those installed, such as 5e"),
22
+ system: z.string().optional().describe("game system: one of those installed"),
23
23
  difficulty: z.enum(difficulties).optional().describe(`how hard the world plays: ${difficulties.join(", ")}`),
24
24
  lethality: z.enum(lethalities).optional().describe(`what a fall means: ${lethalities.join(", ")}`),
25
25
  }),
@@ -3,8 +3,8 @@ import { type Mode } from "./game-mode.ts";
3
3
  import { type ResetPoint } from "./game-saves.ts";
4
4
  export declare const mode: import("../core/registry.ts").Command<z.ZodObject<{
5
5
  to: z.ZodEnum<{
6
- setup: "setup";
7
6
  "session zero": "session zero";
7
+ setup: "setup";
8
8
  play: "play";
9
9
  }>;
10
10
  }, z.core.$strip>, {
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { type Context } from "../core/context.ts";
2
3
  import { type Extension } from "../extensions/index.ts";
3
4
  import { type AdventureExported, type AdventureInstalled } from "./game-adventures.ts";
4
5
  type PackageResult = {
@@ -105,6 +106,11 @@ interface Available {
105
106
  verified: boolean;
106
107
  installed?: string;
107
108
  update: boolean;
109
+ /** Its latest version, which needs a newer rpg-engine (D-515 (2)). */
110
+ newer?: {
111
+ version: string;
112
+ engine?: string;
113
+ };
108
114
  }
109
115
  export declare const packageCommand: import("../core/registry.ts").Command<z.ZodObject<{
110
116
  action: z.ZodEnum<{
@@ -119,6 +125,8 @@ export declare const packageCommand: import("../core/registry.ts").Command<z.Zod
119
125
  author: z.ZodOptional<z.ZodString>;
120
126
  license: z.ZodOptional<z.ZodString>;
121
127
  }, z.core.$strip>, PackageResult>;
128
+ /** Whether a package is on this computer, by its name as package takes it: an extension, a game system or a language npm installed (D-510). */
129
+ export declare function isInstalledPackage(context: Context, name: string): boolean;
122
130
  /** What the master hears of an adventure installed (D-483 (5)): what it is in a few lines, then what to read and where it starts, never its text. */
123
131
  export declare function adventureText(result: AdventureInstalled): string;
124
132
  export {};