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
@@ -2,17 +2,17 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-ru
2
2
  // The player's dashboard (D-269, D-272, D-276): the master and the campaign on top, the party's strip, what the master asks, the sheet of whom the address
3
3
  // names and the table beside it, the turns of a fight, the followed quest and the rolls (D-279), read again whenever the server says something changed.
4
4
  import { render } from "preact";
5
- import { useEffect, useRef, useState } from "preact/hooks";
5
+ import { useEffect, useMemo, useRef, useState } from "preact/hooks";
6
6
  import { PlayerActsContext } from "./act-names.js";
7
7
  import { ActSheet } from "./act-sheet.js";
8
8
  import { ActStrip } from "./act-strip.js";
9
- import { saidStates } from "./acts.js";
9
+ import { saidStates, setSystemVerbs } from "./acts.js";
10
10
  import { readAddress, sectionAddress } from "./address.js";
11
- import { answer, closeCard, readActs, readAsked, readView, readWidgets, sayAct, sendSeen, withdrawAct } from "./api.js";
11
+ import { answer, closeCard, readActs, readAsked, readModules, readView, readWidgets, sayAct, sendSeen, withdrawAct } from "./api.js";
12
12
  import { AskCard } from "./ask-card.js";
13
+ import { AskedDice } from "./asked-dice.js";
13
14
  import { AskedBanner } from "./asked.js";
14
15
  import { useMedia } from "./card.js";
15
- import { DeathSaveCard } from "./death-save.js";
16
16
  import { DiceTray } from "./dice/tray.js";
17
17
  import { WidgetCards, WidgetsContext } from "./extension-widgets.js";
18
18
  import { PageFoot } from "./footer.js";
@@ -23,19 +23,20 @@ import { FollowedQuests, JournalView, QuestEndings } from "./journal.js";
23
23
  import { checkOf } from "./labels.js";
24
24
  import { gameNotices, importNotices, Notices } from "./notices.js";
25
25
  import { inCard, nextPackCard } from "./pack-card.js";
26
+ import { PackagePage } from "./package-page.js";
26
27
  import { PackagesPage } from "./packages.js";
28
+ import { codeOfModule, ModulesContext, ownKey, preloadModules, useNavPages } from "./page-code.js";
27
29
  import { About } from "./pages.js";
28
30
  import { PartyStrip } from "./party.js";
31
+ import { PeopleContext } from "./people.js";
29
32
  import { rollReaction } from "./reactions.js";
30
33
  import { requestedOf, RequestedRoll } from "./requested.js";
31
34
  import { RollLog } from "./rolls.js";
32
- import { saveOutcome } from "./save-outcome.js";
33
35
  import { SavesView } from "./saves.js";
34
36
  import { SceneView } from "./scene.js";
35
37
  import { SettingsView } from "./settings.js";
36
38
  import { SetupView, useSetup } from "./setup.js";
37
39
  import { MemberSheet } from "./sheet.js";
38
- import { SpendCard } from "./spend.js";
39
40
  import { PlayTable, tableBeside, TableTab, useTableAway } from "./table.js";
40
41
  import { browserLanguage, pageDirection, setLanguage, setSystemWords, t } from "./text.js";
41
42
  import { restoreTheme } from "./theme.js";
@@ -46,7 +47,7 @@ import { WorldView } from "./world.js";
46
47
  const productName = "RPG Engine";
47
48
  // How many of the last rolls the page reads at first, and how many more each time the player asks for older ones (D-302).
48
49
  const firstRolls = 20;
49
- // How long at most what a death save or a die of a rest changed waits for its dice, when they never land.
50
+ // How long at most what a roll from a card or a die of a rest changed waits for its dice, when they never land.
50
51
  const longestHold = 15_000;
51
52
  // How long a sentence the master heard, or one copied for the chat, stays in the strip (D-495).
52
53
  const heardTime = 6000;
@@ -75,15 +76,8 @@ function App() {
75
76
  const [sheetThrow, setSheetThrow] = useState();
76
77
  // The question answered from the sheet or the tray, while the engine rolls it (D-330); the free rolls, in this browser alone.
77
78
  const [answering, setAnswering] = useState();
78
- // The death save asked of the player, a card that stays until its outcome is told (D-461): the question, whether the player rolled, its roll once landed
79
- // with what the system's code wrote of it.
80
- const [saving, setSaving] = useState();
81
- const savingNow = useRef(saving);
82
- savingNow.current = saving;
83
- // The roll that answers it while its dice fly: what it changes of the sheet waits for them (D-461).
79
+ // The roll that answers a card, or a die of a rest, while its dice fly: what it changes of the sheet waits for them (D-461).
84
80
  const holding = useRef();
85
- // The party as last read, never held back: what a death save's roll left of them.
86
- const partyNow = useRef([]);
87
81
  const [free, setFree] = useState([]);
88
82
  // On a wide screen the table stands beside the page, unless the player folded it; folded, or under that width, the turns and the followed quest go back to
89
83
  // the page.
@@ -103,10 +97,17 @@ function App() {
103
97
  // The widgets of the campaign's extensions (D-502), read beside the rest and shown as they come, so that a slow hook never holds the page back; kept as they
104
98
  // were when a reading of them fails, and an answer older than one shown left out.
105
99
  const [widgets, setWidgets] = useState([]);
100
+ const [modules, setModules] = useState([]);
106
101
  const widgetReading = useRef({ asked: 0, shown: 0 });
102
+ const moduleReading = useRef({ asked: 0, shown: 0 });
107
103
  // The card of a package's question as last read, even while the dice that changed it fly; the attempts the player let go, with the question then (D-507).
108
104
  const packNow = useRef();
109
105
  const packsGone = useRef(new Map());
106
+ // In the card of a rest's dice, how many dice were rolled as the player pressed one, until its roll lands.
107
+ const restSent = useRef();
108
+ // The widgets as read while a card's dice fly, which show only once they land, as the rest of what the roll changed: a panel on the party never tells the
109
+ // outcome of a death save before its die (D-461).
110
+ const widgetsHeld = useRef();
110
111
  // Reads view again for whom the address names, or the player character the master calls, and what the master asks; an answer that comes after a newer one
111
112
  // is left out.
112
113
  const read = async () => {
@@ -115,9 +116,27 @@ function App() {
115
116
  void readWidgets().then((read) => {
116
117
  if (widgetsAsked > widgetReading.current.shown) {
117
118
  widgetReading.current.shown = widgetsAsked;
118
- setWidgets(read);
119
+ // Their extensions' page code comes before a card of a roll needs it (D-510).
120
+ preloadModules(read);
121
+ if (holding.current !== undefined || packNow.current?.sent !== undefined) {
122
+ widgetsHeld.current = read;
123
+ }
124
+ else {
125
+ widgetsHeld.current = undefined;
126
+ setWidgets(read);
127
+ }
119
128
  }
120
129
  }, () => undefined);
130
+ // The page modules of the system and the extensions, for their cards in the pages and their own pages (D-511).
131
+ const modulesAsked = ++moduleReading.current.asked;
132
+ void readModules().then((read) => {
133
+ if (modulesAsked <= moduleReading.current.shown) {
134
+ return;
135
+ }
136
+ moduleReading.current.shown = modulesAsked;
137
+ preloadModules(read.map(codeOfModule));
138
+ setModules((before) => (JSON.stringify(before) === JSON.stringify(read) ? before : read));
139
+ }, () => undefined);
121
140
  try {
122
141
  const [first, askedNow, actsNow] = await Promise.all([readView(undefined, rollsAsked.current), readAsked().catch(() => undefined), readActs().catch(() => undefined)]);
123
142
  const asked = askedNow === undefined ? undefined : askedNow.asked ?? undefined;
@@ -126,7 +145,6 @@ function App() {
126
145
  const focus = first.kind === "overview" && first.foreground !== undefined && asked?.who !== first.foreground && !here ? playerNamed(first.party, asked?.who)?.name : undefined;
127
146
  const overview = focus === undefined ? first : await readView(undefined, rollsAsked.current, focus).catch(() => first);
128
147
  const party = overview.kind === "overview" ? overview.party : [];
129
- partyNow.current = party;
130
148
  const rolls = overview.kind === "overview" ? overview.rolls : [];
131
149
  const address = readAddress(window.location.hash);
132
150
  const scene = overview.kind === "overview" ? overview.openScene : undefined;
@@ -148,6 +166,7 @@ function App() {
148
166
  const language = (overview.kind === "overview" || overview.kind === "none" ? overview.language : undefined) ?? browserLanguage();
149
167
  await setLanguage(language);
150
168
  setSystemWords(overview.kind === "overview" ? overview.words : undefined);
169
+ setSystemVerbs(overview.kind === "overview" ? overview.verbs : undefined);
151
170
  if (number === reading.current) {
152
171
  document.documentElement.lang = language ?? "en";
153
172
  document.documentElement.dir = pageDirection();
@@ -178,17 +197,19 @@ function App() {
178
197
  setThrown(asking);
179
198
  setHeld(asking.id);
180
199
  }
181
- // A death save asked becomes its card; another question takes its place. The roll that answers it holds back what it changes (D-461).
182
- const card = asked?.save === undefined ? (asked === undefined ? savingNow.current : undefined) : savingNow.current?.asked.id === asked.id ? savingNow.current : { asked, save: asked.save };
183
- // Dice landed before what the system's code wrote was read: the outcome as soon as it is.
184
- const shownCard = card?.roll !== undefined && card.outcome === undefined ? toldCard(card, party) : card;
185
- savingNow.current = shownCard;
186
- setSaving(shownCard);
187
- // So does a die of a rest the player spends, whose card shows it once it lands (D-492); and a roll from a package's card, its marks (D-507).
200
+ // A roll from a package's card, as a death save, holds back what it changes until its dice land, its marks too (D-461, D-507); so does a die of a
201
+ // rest the player spends (D-492).
188
202
  const spent = asked?.spend?.rolls.some((roll) => roll.id === asking?.id) === true;
189
203
  const packRolled = packNow.current?.sent !== undefined;
190
- const pack = askedNow === undefined ? packNow.current : packOf(askedNow);
191
- if (asking !== undefined && ((card !== undefined && card.roll === undefined) || spent || packRolled) && holding.current === undefined) {
204
+ const next = askedNow === undefined ? packNow.current : packOf(askedNow);
205
+ // The roll that answers a card is its last, for its drawing to tell (D-510).
206
+ const pack = packRolled && asking !== undefined && next !== undefined ? { ...next, rolled: { total: asking.total, faces: asking.dice.map((die) => die.value) } } : next;
207
+ packNow.current = pack;
208
+ // A die of a rest's card whose roll came with none to wait for, as with no dice to throw: its buttons free at once.
209
+ if (restSent.current !== undefined && (pack?.asked?.spend?.rolls.length ?? 0) > restSent.current && !spent) {
210
+ window.setTimeout(unpressRest);
211
+ }
212
+ if (asking !== undefined && (spent || packRolled) && holding.current === undefined) {
192
213
  holding.current = { roll: asking, timer: window.setTimeout(() => land(asking.id), longestHold) };
193
214
  }
194
215
  setShown((before) => withHeld(before, {
@@ -251,6 +272,10 @@ function App() {
251
272
  if (card === undefined || asked === undefined || card.ended === true || card.sent !== undefined) {
252
273
  return;
253
274
  }
275
+ if (asked.spend !== undefined) {
276
+ await spendFromCard(card, asked, index);
277
+ return;
278
+ }
254
279
  const leaves = checkOf(asked.labels[index] ?? "", asked.title) === undefined && (asked.buttons?.[index] ?? undefined) === undefined;
255
280
  if (leaves) {
256
281
  packsGone.current.set(card.key, asked.id);
@@ -265,6 +290,31 @@ function App() {
265
290
  }
266
291
  void read();
267
292
  };
293
+ // A button of the card of a rest's dice (ASK-14): a die of a counter, which the question keeps; the last, the end, which takes the card away with it.
294
+ const spendFromCard = async (card, asked, index) => {
295
+ const dice = asked.spend?.dice[index];
296
+ // The die's button waits, pressed, until its roll lands (or the engine refuses it).
297
+ if (dice !== undefined) {
298
+ restSent.current = asked.spend?.rolls.length;
299
+ setPack({ ...card, sent: index });
300
+ if (!await answerSpend(asked.id, { spend: dice.field })) {
301
+ restSent.current = undefined;
302
+ setPack(packNow.current === undefined ? undefined : { ...packNow.current, sent: undefined });
303
+ }
304
+ return;
305
+ }
306
+ const focused = (document.activeElement?.closest(".ask-card") ?? null) !== null;
307
+ packsGone.current.set(card.key, asked.id);
308
+ setPack(undefined);
309
+ if (await answerSpend(asked.id, 0)) {
310
+ if (focused) {
311
+ focusAfterCard();
312
+ }
313
+ return;
314
+ }
315
+ packsGone.current.delete(card.key);
316
+ setPack(card);
317
+ };
268
318
  // The player's own words in place of a button (ASK-10): taken, the card goes with its question, as the master hears them.
269
319
  const sayPack = async (text, focused) => {
270
320
  const card = packNow.current;
@@ -295,7 +345,7 @@ function App() {
295
345
  focusAfterCard();
296
346
  }
297
347
  };
298
- // The death save's dice, or a rest's die, have landed: its outcome on the card, and the sheet as the roll left it (D-461, D-492).
348
+ // The dice of a card's roll, or a rest's die, have landed: the card and the sheet as the roll left them (D-461, D-492).
299
349
  const land = (roll) => {
300
350
  const held = holding.current;
301
351
  if (held === undefined || held.roll.id !== roll) {
@@ -303,13 +353,25 @@ function App() {
303
353
  }
304
354
  window.clearTimeout(held.timer);
305
355
  holding.current = undefined;
306
- setSaving((before) => {
307
- if (before === undefined || before.roll !== undefined) {
308
- return before;
309
- }
310
- return { ...toldCard(before, partyNow.current), roll: held.roll };
311
- });
312
356
  setShown((before) => (before.pending === undefined ? before : { ...before, ...before.pending, pending: undefined }));
357
+ unpressRest();
358
+ };
359
+ // The card of a rest's dice, its die landed: its buttons free again, and the widgets read meanwhile shown.
360
+ const unpressRest = () => {
361
+ const card = packNow.current;
362
+ restSent.current = undefined;
363
+ showHeldWidgets();
364
+ if (card?.asked?.spend !== undefined && card.sent !== undefined) {
365
+ setPack({ ...card, sent: undefined });
366
+ }
367
+ };
368
+ // The widgets read while a card's dice flew, once they have landed.
369
+ const showHeldWidgets = () => {
370
+ const held = widgetsHeld.current;
371
+ widgetsHeld.current = undefined;
372
+ if (held !== undefined) {
373
+ setWidgets(held);
374
+ }
313
375
  };
314
376
  // A card of the master's closed, the focus goes to the notice of the turn, or else to the page (D-461, D-492).
315
377
  const focusAfterCard = () => {
@@ -319,25 +381,6 @@ function App() {
319
381
  (document.querySelector(".turn-notice") ?? page)?.focus({ preventScroll: true });
320
382
  });
321
383
  };
322
- const closeSave = () => {
323
- setSaving(undefined);
324
- focusAfterCard();
325
- };
326
- // The player rolls the death save from its card, as from a check's button.
327
- const rollSave = async () => {
328
- const id = saving?.asked.id;
329
- if (id === undefined) {
330
- return;
331
- }
332
- setSaving((before) => (before === undefined ? before : { ...before, sent: true }));
333
- try {
334
- await answer(id, 0);
335
- }
336
- catch {
337
- setSaving((before) => (before === undefined ? before : { ...before, sent: false }));
338
- }
339
- void read();
340
- };
341
384
  // A new roll's face on the robot, for a moment, when the roll is remarkable (D-305, 7).
342
385
  const react = (roll, party) => {
343
386
  const reaction = rollReaction(roll, party.map((member) => member.name));
@@ -424,6 +467,10 @@ function App() {
424
467
  void read();
425
468
  return taken;
426
469
  };
470
+ // The packages' own pages, as tabs or in their menu (D-512).
471
+ const ownPages = useNavPages(modules);
472
+ // Whose portraits an extension's drawing may show (D-510): the party, then those at the place.
473
+ const people = [...shown.party, ...(shown.place?.here ?? []).filter((one) => !shown.party.some((member) => member.name === one.name))];
427
474
  // A package's question is answered from its card alone (D-507).
428
475
  const requested = live ? requestedOf(answering === shown.asked?.id || inCard(shown.asked) ? undefined : shown.asked, (index) => void answerFrom(index)) : undefined;
429
476
  // The open scene goes by turns, as a fight, and whether the turn is a player character's (D-314, D-315, D-444); whose, by name, when there are more.
@@ -433,7 +480,6 @@ function App() {
433
480
  const turnName = several ? turnOf?.name : undefined;
434
481
  // The player character the master's question is for, named on it when there are more (D-480 (7)).
435
482
  const asker = several ? playerNamed(shown.party, shown.asked?.who) : undefined;
436
- const dying = shown.party.find((candidate) => candidate.name === saving?.asked.who) ?? lead;
437
483
  // The game gone, what the master had not heard is lost with the chat: the strip says so, even once the game is back (D-495).
438
484
  useEffect(() => {
439
485
  if (!live) {
@@ -455,7 +501,7 @@ function App() {
455
501
  setActProblem(undefined);
456
502
  };
457
503
  // With a question of the master's open, the sentence answers it (ASK-10); else it rings the master, or, in a chat that hears nothing by itself, is copied.
458
- const question = saving === undefined && shown.asked !== undefined && shown.asked.spend === undefined && shown.asked.save === undefined ? shown.asked : undefined;
504
+ const question = shown.asked !== undefined && shown.asked.spend === undefined && shown.asked.forced !== true ? shown.asked : undefined;
459
505
  const reply = question !== undefined ? "answer" : acts?.bell === true ? "tell" : "copy";
460
506
  const sendAct = async (text) => {
461
507
  setActProblem(undefined);
@@ -512,6 +558,10 @@ function App() {
512
558
  document.title = shown.asked === undefined ? name : `● ${shown.asked.title} · ${name}`;
513
559
  }, [shown.campaign, shown.asked?.id]);
514
560
  const setup = useSetup(shown.version);
561
+ // While a package's card is there, its widget beside the page would show the same twice (D-507); the same list until either changes, as the cards that
562
+ // read their widget's data read it again when it does.
563
+ const packWidget = shown.pack?.widget;
564
+ const pageWidgets = useMemo(() => (packWidget === undefined ? widgets : widgets.filter((widget) => widget.id !== packWidget)), [widgets, packWidget]);
515
565
  // While the campaign is in its setup, the page is its first configuration, as a portal's (D-370).
516
566
  const inSetup = setup?.mode === "setup";
517
567
  // The page's own messages, over it (D-298): a problem, the game away, a word to know.
@@ -535,41 +585,41 @@ function App() {
535
585
  setFree([]);
536
586
  writeFree(shown.campaign, []);
537
587
  } }, shown.campaign));
538
- return (_jsx(RequestedRoll.Provider, { value: requested, children: _jsx(WidgetsContext.Provider, { value: shown.pack === undefined ? widgets : widgets.filter((widget) => widget.id !== shown.pack?.widget), children: _jsx(PlayerActsContext.Provider, { value: playerActs, children: _jsxs("div", { class: live ? "page" : "page stale", children: [!inSetup && (_jsx(Top, { campaign: shown.campaign, product: productName, system: shown.system?.name, now: shown.now, calendar: shown.calendar, path: shown.place === undefined ? undefined : [...shown.place.within, shown.place.name], live: live, mood: shown.masterMood, moment: moment, asleep: !live && shown.readAt !== undefined, section: address.section, fight: fight, yourTurn: yourTurn, turnName: turnName })), inSetup && _jsx(SetupCorner, { live: live }), _jsx(Notices, { notices: notices }), live && saving !== undefined && (_jsx(DeathSaveCard, { asked: saving.asked, save: saving.save, member: dying, name: several ? dying?.name : undefined, roll: saving.roll, outcome: saving.outcome, rolling: saving.sent === true || answering === saving.asked.id || shown.asked?.id !== saving.asked.id, onRoll: () => void rollSave(), onClose: closeSave }, saving.asked.id)), live && saving === undefined && shown.asked?.spend !== undefined && (_jsx(SpendCard, { asked: shown.asked, spend: shown.asked.spend, member: shown.party.find((candidate) => candidate.name === shown.asked?.spend?.who), flying: holding.current?.roll.id, onSpend: (field) => answerSpend(shown.asked?.id, { spend: field }), onDone: async (focused) => {
539
- const taken = await answerSpend(shown.asked?.id, 0);
540
- if (taken && focused) {
541
- focusAfterCard();
542
- }
543
- return taken;
544
- } }, shown.asked.id)), live && saving === undefined && shown.pack !== undefined && (_jsx(AskCard, { card: shown.pack, name: several ? playerNamed(shown.party, shown.pack.asked?.who)?.name ?? turnName : undefined, title: widgets.find((widget) => widget.id === shown.pack?.widget)?.title, onAnswer: (index) => void answerPack(index), onWords: sayPack, onClose: closePack }, shown.pack.key)), live && saving === undefined && shown.pack === undefined && shown.asked && shown.asked.spend === undefined && !inCard(shown.asked) && (_jsx(AskedBanner, { asked: shown.asked, yourTurn: yourTurn && (asker === undefined || asker.name === turnOf?.name), who: asker, turnName: turnName, map: shown.place?.map, place: shown.place?.name, answered: answering === shown.asked.id, onAnswered: () => void read() })), inSetup
545
- ? _jsx(SetupView, { setup: setup })
546
- : (_jsxs(_Fragment, { children: [live && yourTurn && address.section !== "scene" && shown.asked === undefined && saving === undefined && (_jsxs("a", { class: "turn-notice", href: sectionAddress("scene"), children: [_jsx(Icon, { name: "combat" }), _jsx("span", { children: [turnWords(turnName), shown.openScene?.round === undefined ? "" : t("Round {round}", { round: shown.openScene.round })].filter((part) => part !== "").join(" · ") }), _jsx("span", { class: "turn-notice-go", children: t("Go to the scene") })] })), _jsx(Notices, { notices: importing }), !table && _jsx(QuestEndings, { version: shown.version, campaign: shown.campaign }), address.section === "party" && _jsx(PartyStrip, { party: shown.party, chosen: shown.chosen, scene: shown.openScene }), _jsxs("div", { class: "body", children: [_jsxs("main", { children: [address.section === "about" && _jsx(About, { product: productName, system: shown.system }), address.section === "help" && _jsx(Help, {}), !table && address.section === "scene" && _jsx(FollowedQuests, { version: shown.version, campaign: shown.campaign }), address.section === "scene" && (_jsx(SceneView, { place: shown.place, scene: shown.openScene, actor: actor, foreground: shown.foreground, several: several, party: shown.party, turnsBeside: table, onShowCard: (name) => {
547
- handed.current = { who: name, turn: turnKey(shown.openScene) };
548
- void read();
549
- }, own: {
550
- sheet: shown.chosen === actor?.name ? shown.sheet : [],
551
- cards: shown.cards,
552
- version: shown.version,
553
- onRoll: throwFromSheet,
554
- } })), address.section === "world" && _jsx(WorldView, { version: shown.version, lead: lead, players: many ? players : undefined, tab: address.tab, item: address.name }), address.section === "settings" && _jsx(SettingsView, { version: shown.version, several: many }), address.section === "saves" && _jsx(SavesView, { version: shown.version, campaign: shown.campaign, several: many }), address.section === "packages" && _jsx(PackagesPage, { version: shown.version, tab: address.tab }), address.section === "journal" && _jsx(JournalView, { version: shown.version, campaign: shown.campaign, tab: address.tab, item: address.name }), address.section === "party" && member && (_jsx(PlayerActsContext.Provider, { value: member.role === "pc" || playerActs === undefined ? playerActs : { ...playerActs, actions: {} }, children: _jsx(MemberSheet, { member: member, headline: shown.headline, sheet: shown.sheet, cards: shown.cards, text: shown.text, knownBy: shown.knownBy, story: shown.story, version: shown.version, onRoll: throwFromSheet, scene: shown.openScene }, member.name) }))] }), table
555
- ? (_jsxs(PlayTable, { entering: tableMoved, onFold: () => {
556
- setTableMoved(true);
557
- setTableAway(true);
558
- }, children: [fight && _jsx(TurnsCard, { scene: shown.openScene, party: shown.party, several: several, beside: true }), _jsx(QuestEndings, { version: shown.version, campaign: shown.campaign, beside: true }), _jsx(FollowedQuests, { version: shown.version, campaign: shown.campaign, beside: true }), _jsx(WidgetCards, { place: "side" }), rolls] }))
559
- : wide
560
- ? (_jsx(TableTab, { fight: fight, focused: tableMoved, onOpen: () => {
561
- setTableMoved(true);
562
- setTableAway(false);
563
- } }))
564
- : (_jsxs(_Fragment, { children: [_jsx(WidgetCards, { place: "side" }), rolls] }))] }), _jsx(PageFoot, { product: productName, system: shown.system })] })), _jsx(DiceTray, { requested: thrown, sheetThrow: sheetThrow, party: shown.party, onLanded: land, onShown: (id) => {
565
- setHeld((now) => (now === id ? undefined : now));
566
- if (thrown?.id === id) {
567
- react(thrown, shown.party);
568
- }
569
- }, onFree: (roll) => {
570
- setFree((before) => withFree(shown.campaign, before, roll));
571
- setFresh((before) => new Set([...before, roll.id]));
572
- } }), acting !== undefined && (_jsx(ActSheet, { start: acting.start, self: several ? member?.name : undefined, place: actsElsewhere === undefined ? shown.place : actPlace?.who === actsElsewhere ? actPlace.place : undefined, scene: shown.openScene, companions: shown.party.filter((one) => one.role === "companion").map((one) => one.name), reply: reply, onSend: sendAct, onClose: closeAct })), _jsx(ActStrip, { entries: strip, problem: actProblem, onWithdraw: (id) => void withdraw(id), onCopy: (id, text) => void copyAct(text).then((done) => (done ? dismissAct(id) : setActProblem(t("Copy did not work: select the words and copy them yourself.")))), onDismiss: dismissAct })] }) }) }) }));
588
+ return (_jsx(ModulesContext.Provider, { value: modules, children: _jsx(PeopleContext.Provider, { value: people, children: _jsx(RequestedRoll.Provider, { value: requested, children: _jsx(WidgetsContext.Provider, { value: pageWidgets, children: _jsx(PlayerActsContext.Provider, { value: playerActs, children: _jsxs("div", { class: live ? "page" : "page stale", children: [!inSetup && (_jsx(Top, { campaign: shown.campaign, product: productName, system: shown.system?.name, now: shown.now, calendar: shown.calendar, path: shown.place === undefined ? undefined : [...shown.place.within, shown.place.name], live: live, mood: shown.masterMood, moment: moment, asleep: !live && shown.readAt !== undefined, section: address.section, fight: fight, yourTurn: yourTurn, turnName: turnName, ownPages: ownPages, ownShown: address.section === "pkg" && address.tab !== undefined && address.name !== undefined ? ownKey({ package: address.tab, name: address.name }) : undefined })), inSetup && _jsx(SetupCorner, { live: live }), _jsx(Notices, { notices: notices }), live && shown.pack !== undefined && (_jsx(AskCard, { card: shown.pack, name: several ? playerNamed(shown.party, shown.pack.asked?.who)?.name ?? turnName : undefined, widget: widgets.find((widget) => widget.id === shown.pack?.widget), onAnswer: (index) => void answerPack(index), onWords: sayPack, onClose: closePack }, shown.pack.key)), live && shown.pack === undefined && shown.asked?.spend !== undefined && !inCard(shown.asked) && (_jsx(AskedDice, { asked: shown.asked, spend: shown.asked.spend, flying: holding.current?.roll.id, onSpend: (field) => answerSpend(shown.asked?.id, { spend: field }), onDone: async (focused) => {
589
+ const taken = await answerSpend(shown.asked?.id, 0);
590
+ if (taken && focused) {
591
+ focusAfterCard();
592
+ }
593
+ return taken;
594
+ } }, shown.asked.id)), live && shown.pack === undefined && shown.asked && shown.asked.spend === undefined && !inCard(shown.asked) && (_jsx(AskedBanner, { asked: shown.asked, yourTurn: yourTurn && (asker === undefined || asker.name === turnOf?.name), who: asker, turnName: turnName, map: shown.place?.map, place: shown.place?.name, answered: answering === shown.asked.id, onAnswered: () => void read() })), inSetup
595
+ ? _jsx(SetupView, { setup: setup })
596
+ : (_jsxs(_Fragment, { children: [live && yourTurn && address.section !== "scene" && shown.asked === undefined && shown.pack === undefined && (_jsxs("a", { class: "turn-notice", href: sectionAddress("scene"), children: [_jsx(Icon, { name: "combat" }), _jsx("span", { children: [turnWords(turnName), shown.openScene?.round === undefined ? "" : t("Round {round}", { round: shown.openScene.round })].filter((part) => part !== "").join(" · ") }), _jsx("span", { class: "turn-notice-go", children: t("Go to the scene") })] })), _jsx(Notices, { notices: importing }), !table && _jsx(QuestEndings, { version: shown.version, campaign: shown.campaign }), address.section === "party" && _jsx(PartyStrip, { party: shown.party, chosen: shown.chosen, scene: shown.openScene }), _jsxs("div", { class: "body", children: [_jsxs("main", { children: [address.section === "about" && _jsx(About, { product: productName, system: shown.system }), address.section === "help" && _jsx(Help, {}), !table && address.section === "scene" && _jsx(FollowedQuests, { version: shown.version, campaign: shown.campaign }), address.section === "scene" && (_jsx(SceneView, { place: shown.place, scene: shown.openScene, actor: actor, foreground: shown.foreground, several: several, party: shown.party, turnsBeside: table, onShowCard: (name) => {
597
+ handed.current = { who: name, turn: turnKey(shown.openScene) };
598
+ void read();
599
+ }, own: {
600
+ sheet: shown.chosen === actor?.name ? shown.sheet : [],
601
+ cards: shown.cards,
602
+ version: shown.version,
603
+ onRoll: throwFromSheet,
604
+ } })), address.section === "world" && _jsx(WorldView, { version: shown.version, lead: lead, players: many ? players : undefined, tab: address.tab, item: address.name }), address.section === "settings" && _jsx(SettingsView, { version: shown.version, several: many }), address.section === "saves" && _jsx(SavesView, { version: shown.version, campaign: shown.campaign, several: many }), address.section === "packages" && _jsx(PackagesPage, { version: shown.version, tab: address.tab }), address.section === "pkg" && _jsx(PackagePage, { name: address.tab, page: address.name }), address.section === "journal" && _jsx(JournalView, { version: shown.version, campaign: shown.campaign, tab: address.tab, item: address.name }), address.section === "party" && member && (_jsx(PlayerActsContext.Provider, { value: member.role === "pc" || playerActs === undefined ? playerActs : { ...playerActs, actions: {} }, children: _jsx(MemberSheet, { member: member, headline: shown.headline, sheet: shown.sheet, cards: shown.cards, text: shown.text, knownBy: shown.knownBy, story: shown.story, version: shown.version, onRoll: throwFromSheet, scene: shown.openScene }, member.name) }))] }), table
605
+ ? (_jsxs(PlayTable, { entering: tableMoved, onFold: () => {
606
+ setTableMoved(true);
607
+ setTableAway(true);
608
+ }, children: [fight && _jsx(TurnsCard, { scene: shown.openScene, party: shown.party, several: several, beside: true }), _jsx(QuestEndings, { version: shown.version, campaign: shown.campaign, beside: true }), _jsx(FollowedQuests, { version: shown.version, campaign: shown.campaign, beside: true }), _jsx(WidgetCards, { place: "side" }), rolls] }))
609
+ : wide
610
+ ? (_jsx(TableTab, { fight: fight, focused: tableMoved, onOpen: () => {
611
+ setTableMoved(true);
612
+ setTableAway(false);
613
+ } }))
614
+ : (_jsxs(_Fragment, { children: [_jsx(WidgetCards, { place: "side" }), rolls] }))] }), _jsx(PageFoot, { product: productName, system: shown.system })] })), _jsx(DiceTray, { requested: thrown, sheetThrow: sheetThrow, party: shown.party, onLanded: land, onShown: (id) => {
615
+ setHeld((now) => (now === id ? undefined : now));
616
+ if (thrown?.id === id) {
617
+ react(thrown, shown.party);
618
+ }
619
+ }, onFree: (roll) => {
620
+ setFree((before) => withFree(shown.campaign, before, roll));
621
+ setFresh((before) => new Set([...before, roll.id]));
622
+ } }), acting !== undefined && (_jsx(ActSheet, { start: acting.start, self: several ? member?.name : undefined, place: actsElsewhere === undefined ? shown.place : actPlace?.who === actsElsewhere ? actPlace.place : undefined, scene: shown.openScene, companions: shown.party.filter((one) => one.role === "companion").map((one) => one.name), reply: reply, onSend: sendAct, onClose: closeAct })), _jsx(ActStrip, { entries: strip, problem: actProblem, onWithdraw: (id) => void withdraw(id), onCopy: (id, text) => void copyAct(text).then((done) => (done ? dismissAct(id) : setActProblem(t("Copy did not work: select the words and copy them yourself.")))), onDismiss: dismissAct })] }) }) }) }) }) }));
573
623
  }
574
624
  /** The player character of the party by their name; undefined for anyone else, or none. */
575
625
  function playerNamed(party, name) {
@@ -588,13 +638,7 @@ function calledOf(party, section, asked, scene, foreground) {
588
638
  function turnKey(scene) {
589
639
  return hasTurns(scene) ? `${scene.title} ${scene.since ?? ""} ${scene.round ?? ""} ${scene.turn ?? ""}` : "";
590
640
  }
591
- /** A death save's card with its outcome, as what the system's code wrote left who rolled it, in the party as last read (D-461). */
592
- function toldCard(card, party) {
593
- const who = card.asked.who;
594
- const after = party.find((member) => (who === undefined ? member.role === "pc" : member.name === who));
595
- return { ...card, outcome: after === undefined ? undefined : saveOutcome(card.save, after) };
596
- }
597
- /** The page as read now; while a death save's dice fly, with the sheet and the fight as they were, what the roll changed kept until they land (D-461). */
641
+ /** The page as read now; while a card's dice fly, with the sheet and the fight as they were, what the roll changed kept until they land (D-461). */
598
642
  function withHeld(before, next, hold) {
599
643
  if (!hold) {
600
644
  return { ...next, pending: undefined };
@@ -1,31 +1,36 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
2
- // The card of a package's question (D-507): its widget's parts in the frame of the master's question, which stays through the questions of one attempt. Its
3
- // counts on a stage of three places; under them the roll's button, or the choices a die asks for, and the rule; once the dice have spoken, the outcome where
4
- // the buttons were. What the dice changed moves on its marks once they land; the card stays until the player closes it.
2
+ // The card of a package's question (D-507, D-509): its widget's parts in the frame of the master's question, which stays through the questions of one attempt.
3
+ // Who acts on the left, the count drawn large in the middle, the others one over the other on the right; under them the roll's button, or the choices a die
4
+ // asks for, and the rule; once the dice have spoken, the outcome where the buttons were. Its extension's page code may draw the middle's figure, or the
5
+ // whole inside, the frame staying the page's (D-510). What the dice changed moves once they land; the card stays until the player closes it.
5
6
  import { useEffect, useRef, useState } from "preact/hooks";
6
- import { Drawn, Part, Text, textOf, Track } from "./extension-widgets.js";
7
+ import { Drawn, OwnerContext, Part, Text, textOf, Track, Who } from "./extension-widgets.js";
7
8
  import { Icon, NotationIcons } from "./icons.js";
8
- import { checkOf } from "./labels.js";
9
+ import { checkOf, fieldLabel } from "./labels.js";
9
10
  import { cardLayout, labelKey, trackChanges } from "./pack-card.js";
11
+ import { deepQuery, ExtensionRoot, figureSize, pagePropsOf, usePageModule } from "./page-code.js";
10
12
  import { t } from "./text.js";
11
13
  import { turnWords } from "./turns.js";
12
- /** The card; `name`, with more than one player character, whom it asks; `title`, its widget's, for a card the page saw no question of. */
13
- export function AskCard({ card, name, title, onAnswer, onWords, onClose }) {
14
+ /** The card; `name`, with more than one player character, whom it asks; `widget`, whose card it is, its title for a card the page saw no question of. */
15
+ export function AskCard({ card, name, widget, onAnswer, onWords, onClose }) {
14
16
  const element = useRef(null);
15
17
  // Whether the focus was on one of its buttons as it was pressed: it goes to the next question's first button, or to Close at the end.
16
18
  const pressed = useRef(false);
17
- // What the card showed before, what changed since, and that change in words for a screen reader.
19
+ // What the card showed, and before it, what changed since, and that change in words for a screen reader.
18
20
  const look = useRef({ said: "", changes: new Map(), told: "" });
19
21
  const said = JSON.stringify(card.shows);
20
22
  if (look.current.said !== said) {
21
23
  const changes = trackChanges(look.current.shows, card.shows);
22
- look.current = { said, shows: card.shows, changes, told: look.current.shows === undefined ? "" : toldText(card, changes) };
24
+ const before = look.current.shows === undefined ? {} : { before: look.current.shows };
25
+ look.current = { said, shows: card.shows, ...before, changes, told: look.current.shows === undefined ? "" : toldText(card, changes) };
23
26
  }
24
27
  const { changes, told } = look.current;
25
28
  const layout = cardLayout(card.shows);
26
29
  const asked = card.ended === true ? undefined : card.asked;
27
30
  const ruled = card.asked?.rule;
28
31
  const check = card.asked === undefined ? undefined : checkOf(card.asked.labels[0] ?? "", card.asked.title);
32
+ // The dice of a rest are asked in it one at a time, the same question until its end (ASK-14).
33
+ const rest = card.asked?.spend;
29
34
  const question = card.title ?? asked?.question;
30
35
  const prompt = asked !== undefined && question !== asked.question ? asked.question : undefined;
31
36
  // The widget's lead is the outcome once it has a tone, good or bad; before, it names who rolls, which the line on top says.
@@ -33,11 +38,16 @@ export function AskCard({ card, name, title, onAnswer, onWords, onClose }) {
33
38
  const id = card.key.replace(/[^a-z0-9-]/gi, "-");
34
39
  const ruleId = `ask-rule-${id}`;
35
40
  const state = card.ended === true ? "ended" : card.sent !== undefined ? "rolling" : "asking";
41
+ // The extension's page code, when it has one: it may draw the whole inside of this card (D-510).
42
+ const loaded = usePageModule(widget);
43
+ const body = widget?.module === undefined ? undefined : card.shows.body;
36
44
  // The player's own words, as in the master's question: while they go, and what went wrong.
37
45
  const [words, setWords] = useState("");
38
46
  const [saying, setSaying] = useState(false);
39
47
  const [problem, setProblem] = useState();
40
48
  const busy = card.sent !== undefined || saying;
49
+ // The player's own words take no forced roll's place, nor a rest's dice (D-507, ASK-14).
50
+ const takesWords = asked !== undefined && asked.forced !== true && rest === undefined;
41
51
  // While it stays in sight, the rolls beside the sheet stay in sight under it, as under the master's question (D-291); once it scrolls with the page, not.
42
52
  useEffect(() => {
43
53
  const box = element.current;
@@ -61,12 +71,13 @@ export function AskCard({ card, name, title, onAnswer, onWords, onClose }) {
61
71
  root.style.removeProperty("--asked-space");
62
72
  };
63
73
  }, [card.ended]);
64
- // The button pressed gone, the focus that was on it goes to the next question's first button, or to Close once the card has its outcome.
74
+ // The button pressed gone, the focus that was on it goes to the next question's first button, or to Close once the card has its outcome; in an
75
+ // extension's drawing too.
65
76
  useEffect(() => {
66
- if (!pressed.current || element.current === null || element.current.contains(document.activeElement)) {
77
+ if (!pressed.current || element.current === null || (element.current.contains(document.activeElement) && deepActive()?.classList.contains("ext-root") !== true)) {
67
78
  return;
68
79
  }
69
- const next = element.current.querySelector(card.ended === true ? ".ask-close" : ".ask-choices button:not([aria-disabled='true'])");
80
+ const next = deepQuery(element.current, card.ended === true ? ".ask-close" : ".ask-choices button:not([aria-disabled='true'])");
70
81
  if (next !== null) {
71
82
  pressed.current = false;
72
83
  next.focus();
@@ -93,22 +104,62 @@ export function AskCard({ card, name, title, onAnswer, onWords, onClose }) {
93
104
  setSaying(false);
94
105
  setProblem(t("The answer did not reach the game: try again."));
95
106
  };
96
- const place = (stage) => {
97
- const tracks = layout.places[stage];
98
- // The facts under the counts at the end, or in the middle when none is at the end.
99
- const facts = stage === (layout.places.end.length > 0 ? "end" : "center") ? layout.facts : [];
100
- return (_jsxs("div", { class: `ask-place at-${stage}`, children: [tracks.map((track) => _jsx(Track, { track: track, place: stage, change: changes.get(labelKey(track.label)) }, labelKey(track.label))), facts.length > 0 && (_jsx("ul", { class: "chips ask-facts", children: facts.map((fact, index) => (_jsx("li", { dir: "auto", children: _jsx(Text, { text: fact }) }, index))) }))] }));
101
- };
102
- return (_jsxs("section", { ref: element, class: `asked ask-card ${state}`, "aria-labelledby": `ask-${id}`, children: [_jsx("img", { class: "asked-robot", src: "/assets/favicon.svg", alt: "" }), _jsxs("div", { class: "asked-body", children: [card.ended === true && (_jsx("button", { type: "button", class: "icon-button ask-close", "aria-label": t("Close"), "data-tip": t("Close"), onClick: () => onClose(element.current?.contains(document.activeElement) === true), children: _jsx(Icon, { name: "close" }) })), _jsx("p", { class: "eyebrow asked-turn", children: check === undefined ? title ?? turnWords(name) : `${turnWords(name)} · ${check.check}` }), _jsx("p", { id: `ask-${id}`, class: "asked-question", role: asked !== undefined && prompt === undefined ? "alert" : undefined, children: question ?? title }), _jsxs("div", { class: "ask-stage", children: [place("start"), place("center"), place("end")] }), layout.others.length > 0 && _jsx("div", { class: "ask-others", children: layout.others.map((part, index) => _jsx(Part, { part: part }, index)) }), _jsxs("div", { class: "ask-foot", children: [asked !== undefined && (_jsxs(_Fragment, { children: [prompt !== undefined && _jsx("p", { class: "ask-prompt", role: "alert", children: prompt }), _jsx("div", { class: "ask-choices", children: asked.labels.map((label, index) => {
103
- const roll = checkOf(label, asked.title);
104
- const own = asked.buttons?.[index] ?? undefined;
105
- // A choice that says what it costs, as "it resets", in the red of what is lost; else a plain button.
106
- const kind = roll !== undefined ? "ask-roll" : own?.note !== undefined ? "button danger ask-leave" : "button ask-leave";
107
- return (_jsxs("button", { type: "button", class: card.sent === index ? `${kind} sent` : kind, "aria-disabled": card.sent === undefined ? undefined : "true", "aria-describedby": ruled === undefined ? undefined : ruleId, onClick: () => press(index), children: [roll !== undefined && _jsx(NotationIcons, { notation: roll.dice }), _jsx("span", { class: "asked-check-name", children: own?.name ?? roll?.check ?? label }), own?.note !== undefined && _jsx("span", { class: "ask-note", children: own.note }), roll !== undefined && _jsx("span", { class: "visually-hidden", children: roll.dice })] }, `${asked.id} ${index}`));
108
- }) })] })), asked === undefined && outcome !== undefined && (_jsxs("p", { class: outcome.tone === undefined ? "ask-outcome" : `ask-outcome ${outcome.tone}`, "aria-hidden": "true", children: [outcome.icon !== undefined && _jsx(Drawn, { path: outcome.icon, kind: "ask-outcome-icon" }), _jsx("span", { dir: "auto", children: _jsx(Text, { text: outcome.lead }) })] })), asked === undefined && layout.texts.map((text, index) => (_jsx("p", { class: "ask-then", dir: "auto", children: _jsx(Text, { text: text }) }, index))), ruled !== undefined && _jsx("p", { id: ruleId, class: "ask-rule", dir: "auto", children: ruled }), asked !== undefined && (_jsxs("form", { class: "asked-own ask-own", onSubmit: (event) => void say(event), children: [_jsx("input", { type: "text", value: words, maxLength: mostWords, placeholder: t("Or write what you do…"), "aria-label": t("Or write what you do"), disabled: busy, onInput: (event) => setWords(event.currentTarget.value) }), _jsx("button", { type: "submit", class: "icon-button", "aria-label": t("Send"), "data-tip": t("Send"), disabled: busy || words.trim() === "", children: _jsx(Icon, { name: "send" }) })] })), problem !== undefined && _jsx("p", { class: "asked-problem", role: "alert", children: problem })] }), _jsx("p", { class: "visually-hidden", role: "status", children: told })] })] }));
107
+ const tracksOf = (stage) => layout.places[stage].map((track) => _jsx(Track, { track: track, place: stage, change: changes.get(labelKey(track.label)) }, labelKey(track.label)));
108
+ const side = layout.places.start.length + layout.places.end.length > 0;
109
+ // The facts under the counts at the side, or in the middle when none is there.
110
+ const facts = layout.facts.length === 0 ? null : (_jsx("ul", { class: "chips ask-facts", children: layout.facts.map((fact, index) => (_jsx("li", { dir: "auto", children: _jsx(Text, { text: fact }) }, index))) }));
111
+ const choices = asked === undefined ? undefined : rest === undefined ? cardAskedOf(asked, prompt) : restAskedOf(asked, rest);
112
+ // The inside the page draws: who acts, the middle, the side; the others; the buttons, the outcome and the rule.
113
+ const inside = (_jsxs(_Fragment, { children: [_jsxs("div", { class: layout.who === undefined ? "ask-stage" : "ask-stage with-who", children: [layout.who !== undefined && (_jsx("div", { class: "ask-place at-who", children: _jsx(Who, { who: layout.who.who, does: layout.who.does }) })), _jsxs("div", { class: "ask-place at-center", children: [tracksOf("center"), !side && facts] }), side && (_jsxs("div", { class: "ask-place at-side", children: [tracksOf("start"), tracksOf("end"), facts] }))] }), layout.others.length > 0 && _jsx("div", { class: "ask-others", children: layout.others.map((part, index) => _jsx(Part, { part: part }, index)) }), _jsxs("div", { class: "ask-foot", children: [choices !== undefined && asked !== undefined && (_jsxs(_Fragment, { children: [choices.prompt !== undefined && _jsx("p", { class: "ask-prompt", role: "alert", children: choices.prompt }), _jsx(Choices, { buttons: choices.buttons, sent: card.sent, describedBy: ruled === undefined ? undefined : ruleId, onChoose: press }, asked.id)] })), asked === undefined && outcome !== undefined && (_jsxs("p", { class: outcome.tone === undefined ? "ask-outcome" : `ask-outcome ${outcome.tone}`, "aria-hidden": "true", children: [outcome.icon !== undefined && _jsx(Drawn, { path: outcome.icon, kind: "ask-outcome-icon" }), _jsx("span", { dir: "auto", children: _jsx(Text, { text: outcome.lead }) })] })), asked === undefined && layout.texts.map((text, index) => (_jsx("p", { class: "ask-then", dir: "auto", children: _jsx(Text, { text: text }) }, index))), ruled !== undefined && _jsx("p", { id: ruleId, class: "ask-rule", dir: "auto", children: ruled })] })] }));
114
+ return (_jsxs("section", { ref: element, class: `asked ask-card ${state}${card.shows.tint === undefined ? "" : ` tinted tint-${card.shows.tint}`}`, "aria-labelledby": `ask-${id}`, children: [_jsx("img", { class: "asked-robot", src: "/assets/favicon.svg", alt: "" }), _jsxs("div", { class: "asked-body", children: [card.ended === true && (_jsx("button", { type: "button", class: "icon-button ask-close", "aria-label": t("Close"), "data-tip": t("Close"), onClick: () => onClose(element.current?.contains(document.activeElement) === true), children: _jsx(Icon, { name: "close" }) })), _jsx("p", { class: "eyebrow asked-turn", children: rest !== undefined ? card.asked?.title : check === undefined ? widget?.title ?? turnWords(name) : `${turnWords(name)} · ${check.check}` }), _jsx("p", { id: `ask-${id}`, class: "asked-question", role: asked !== undefined && prompt === undefined ? "alert" : undefined, children: question ?? widget?.title }), body !== undefined && widget !== undefined
115
+ ? (_jsx(ExtensionRoot, { widget: widget, loaded: loaded, kind: "ext-card", draw: (module) => (_jsx(OwnBody, { module: module, name: body, widget: widget, shows: card.shows, before: look.current.before, rest: rest, rolled: card.rolled, asked: choices, sent: card.sent, ended: card.ended === true, answer: press })) }))
116
+ : widget === undefined
117
+ ? inside
118
+ : _jsx(OwnerContext.Provider, { value: { widget, loaded, data: card.shows.data, place: "ask" }, children: inside }), takesWords && (_jsxs("form", { class: "asked-own ask-own", onSubmit: (event) => void say(event), children: [_jsx("input", { type: "text", value: words, maxLength: mostWords, placeholder: t("Or write what you do…"), "aria-label": t("Or write what you do"), disabled: busy, onInput: (event) => setWords(event.currentTarget.value) }), _jsx("button", { type: "submit", class: "icon-button", "aria-label": t("Send"), "data-tip": t("Send"), disabled: busy || words.trim() === "", children: _jsx(Icon, { name: "send" }) })] })), problem !== undefined && _jsx("p", { class: "asked-problem", role: "alert", children: problem }), _jsx("p", { class: "visually-hidden", role: "status", children: told })] })] }));
119
+ }
120
+ /**
121
+ * The buttons of a question in a card, as the page draws them, for its own card and an extension's (D-510): a roll in gold with its dice, a choice that
122
+ * loses something with a red edge, any other plain; the one pressed marked while its answer goes, the others waiting.
123
+ */
124
+ export function Choices({ buttons, sent, describedBy, onChoose }) {
125
+ return (_jsx("div", { class: "ask-choices", children: buttons.map((button, index) => {
126
+ const kind = button.dice !== undefined ? "ask-roll" : button.danger === true ? "button danger ask-leave" : "button ask-leave";
127
+ return (_jsxs("button", { type: "button", class: sent === index ? `${kind} sent` : kind, "aria-disabled": sent === undefined ? undefined : "true", "aria-describedby": describedBy, onClick: () => onChoose(index), children: [button.dice !== undefined && _jsx(NotationIcons, { notation: button.dice }), _jsx("span", { class: "asked-check-name", children: button.name }), button.note !== undefined && _jsx("span", { class: "ask-note", children: button.note }), button.dice !== undefined && _jsx("span", { class: "visually-hidden", children: button.dice })] }, index));
128
+ }) }));
129
+ }
130
+ /** The buttons of the dice of a rest as a card shows them (ASK-14): a die of each counter, in their order, then the one that ends it. */
131
+ function restAskedOf(asked, rest) {
132
+ return { buttons: [...rest.dice.map((dice) => ({ name: fieldLabel(dice.field), dice: `1d${dice.sides}` })), { name: asked.labels[0] ?? "" }] };
133
+ }
134
+ /** The buttons of a question as a card shows them: each its name, its note and its dice when it rolls; the question a die asks, and the rule. */
135
+ export function cardAskedOf(asked, prompt) {
136
+ const buttons = asked.labels.map((label, index) => {
137
+ const roll = checkOf(label, asked.title);
138
+ const own = asked.buttons?.[index] ?? undefined;
139
+ const note = own?.note === undefined ? {} : { note: own.note };
140
+ // A choice that says what it costs, as "it resets", in the red of what is lost.
141
+ return { name: own?.name ?? roll?.check ?? label, ...note, ...(roll === undefined ? (own?.note === undefined ? {} : { danger: true }) : { dice: roll.dice }) };
142
+ });
143
+ return { buttons, ...(prompt === undefined ? {} : { prompt }), ...(asked.rule === undefined ? {} : { rule: asked.rule }) };
109
144
  }
110
145
  // How many characters the player's own words may have, as the server takes them.
111
146
  const mostWords = 500;
147
+ /** The whole inside of a card of a roll as its extension's page code draws it (D-510): its body, a figure with the question's buttons. */
148
+ function OwnBody({ module, name, widget, shows, before, rest, rolled, asked, sent, ended, answer }) {
149
+ const Drawing = module.bodies?.[name];
150
+ if (Drawing === undefined) {
151
+ throw new Error(`its page module has no body ${name}`);
152
+ }
153
+ return (_jsx(Drawing, { ...pagePropsOf(widget), name: name, data: shows.data, ...(before === undefined ? {} : { before: before.data }), place: "ask", size: figureSize(widget, name), parts: shows.parts ?? [], ...(rest === undefined ? {} : { rest }), ...(rolled === undefined ? {} : { rolled }), buttons: asked?.buttons ?? [], ...(asked?.prompt === undefined ? {} : { prompt: asked.prompt }), ...(asked?.rule === undefined ? {} : { rule: asked.rule }), ...(sent === undefined ? {} : { sent }), ended: ended, answer: answer }));
154
+ }
155
+ /** The element with the focus, inside an extension's drawing too. */
156
+ function deepActive() {
157
+ let active = document.activeElement;
158
+ while (active?.shadowRoot?.activeElement !== undefined && active.shadowRoot.activeElement !== null) {
159
+ active = active.shadowRoot.activeElement;
160
+ }
161
+ return active;
162
+ }
112
163
  /** What a look of the card changed, for a screen reader, once: its outcome, then each count that changed, as "Failed. Pins: 0 of 6. Failures: 3 of 4." */
113
164
  function toldText(card, changes) {
114
165
  const layout = cardLayout(card.shows);