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
@@ -5,16 +5,17 @@ import { changeSetting, readSettings } from "./api.js";
5
5
  import { diceEdgesPref, diceLook, diceSetPref, diceSets, texturePath } from "./dice/sets.js";
6
6
  import { WidgetsContext } from "./extension-widgets.js";
7
7
  import { DieSwatch, Icon } from "./icons.js";
8
- import { settingLabel, valueLabel } from "./labels.js";
8
+ import { phraseLabel, settingLabel, valueLabel } from "./labels.js";
9
9
  import { LanguageChoice, languageLine } from "./language-choice.js";
10
10
  import { PageHead } from "./pages.js";
11
11
  import { byHandPref, conditionsPref, soundPref, tokenSymbolsPref, useChoice, usePref, usePrefChange } from "./prefs.js";
12
+ import { Confirm } from "./saves.js";
12
13
  import { arrowStep, t } from "./text.js";
13
14
  import { pickTheme, shownTheme } from "./theme.js";
14
15
  // The groups of the campaign's settings, in order; a setting the game system adds goes with the dice, as whether the master's rolls are shown (D-287). How the
15
16
  // master plays holds who voices the characters (D-490) and how much the master thinks (D-462) too.
16
17
  const groups = [
17
- { names: ["difficulty", "lethality", "saves", "rigor"] },
18
+ { names: ["ruleset", "difficulty", "lethality", "saves", "rigor"] },
18
19
  { names: ["mentor", "learned"] },
19
20
  { names: ["prose", "story", "author", "style", "voices", "effort"] },
20
21
  { names: ["dice", "master-rolls", "units"], system: true },
@@ -76,17 +77,44 @@ function SettingRow({ setting, off, several = false, onChange }) {
76
77
  const said = useSaid();
77
78
  const value = picked ?? setting.value;
78
79
  const id = `setting-${idOf(setting.name)}`;
80
+ // The version of the rules changes the game's rules: it asks first (D-514 (2)).
81
+ const [asking, setAsking] = useState();
82
+ const rules = setting.name === rulesetSetting;
79
83
  useEffect(() => setPicked(undefined), [setting]);
80
84
  // A choice the arrows left still resting goes when the section closes.
81
85
  useEffect(() => () => {
82
86
  if (resting.current !== undefined) {
83
87
  clearTimeout(resting.current.timer);
84
- void onChange({ setting: setting.name, value: resting.current.choice });
88
+ // Never the rules without the player's yes.
89
+ if (!rules) {
90
+ void onChange({ setting: setting.name, value: resting.current.choice });
91
+ }
85
92
  }
86
93
  }, []);
94
+ const row = useRef(null);
95
+ // The focus on the value chosen, once the dialog that asked is gone.
96
+ const focusChosen = () => {
97
+ requestAnimationFrame(() => row.current?.querySelector("[role=radio][aria-checked=true]")?.focus());
98
+ };
87
99
  const send = (change) => {
100
+ // The arrows that rest back on the rules played change nothing, and ask nothing.
101
+ if (rules && "value" in change) {
102
+ if (change.value === setting.value) {
103
+ setPicked(undefined);
104
+ }
105
+ else {
106
+ setAsking(change.value);
107
+ }
108
+ return;
109
+ }
88
110
  void onChange(change).then(said.show);
89
111
  };
112
+ // Not changed after all: the rules played show again, with the focus.
113
+ const keep = () => {
114
+ setAsking(undefined);
115
+ setPicked(undefined);
116
+ focusChosen();
117
+ };
90
118
  // A click chooses at once; the arrows show each value and send the one they rest on, so that the game is changed once.
91
119
  const choose = (choice, byKey) => {
92
120
  setPicked(choice);
@@ -105,13 +133,30 @@ function SettingRow({ setting, off, several = false, onChange }) {
105
133
  const chosen = setting.choices?.find((choice) => choice.value === value);
106
134
  const unset = setting.most === undefined && (setting.choices === undefined ? setting.items === undefined && setting.value === undefined : chosen === undefined);
107
135
  const described = [`${id}-about`, ...(chosen?.means === undefined ? [] : [`${id}-means`]), ...(off === undefined ? [] : [`${id}-off`])].join(" ");
108
- return (_jsxs("div", { class: off === undefined ? "setting" : "setting off", children: [_jsxs("div", { class: "setting-what", children: [_jsx("span", { class: "setting-name", id: id, children: settingLabel(setting.name) }), _jsx("span", { class: "setting-about", id: `${id}-about`, children: t(setting.about) })] }), setting.choices !== undefined
109
- ? (_jsx(Segmented, { label: id, described: described, options: setting.choices.map((choice) => ({ value: choice.value, label: valueLabel(choice.value) })), value: value, onPick: choose }))
136
+ return (_jsxs("div", { ref: row, class: off === undefined ? "setting" : "setting off", children: [_jsxs("div", { class: "setting-what", children: [_jsx("span", { class: "setting-name", id: id, children: settingLabel(setting.name) }), _jsx("span", { class: "setting-about", id: `${id}-about`, children: t(setting.about) })] }), setting.choices !== undefined
137
+ ? (_jsx(Segmented, { label: id, described: described, options: setting.choices.map((choice) => ({ value: choice.value, label: choiceLabel(setting.name, choice) })), value: value, onPick: choose }))
110
138
  : setting.name === "language"
111
139
  ? _jsx(LanguageChoice, { value: value, labelledBy: id, describedBy: `${id}-about`, onPick: (code) => choose(code, false) })
112
140
  : setting.most !== undefined
113
141
  ? _jsx(TextSetting, { setting: setting, label: id, onChange: send })
114
- : _jsx(ListSetting, { setting: setting, label: id, onChange: send }), _jsxs("div", { class: "setting-after", children: [off !== undefined && _jsx("p", { class: "setting-off", id: `${id}-off`, children: off }), chosen?.means !== undefined && (_jsxs("p", { class: "setting-means", id: `${id}-means`, children: [_jsxs("strong", { children: [valueLabel(chosen.value), ":"] }), " ", meansText(setting.name, chosen.value, chosen.means, several)] })), setting.name === "language" && value !== undefined && _jsx("p", { class: "setting-means", children: languageLine(value) }), unset && _jsx("p", { class: "setting-unset", children: setting.choices === undefined ? t("Not answered yet: add them here, or the master asks you.") : t("Not chosen yet: choose here, or the master asks you.") }), setting.note !== undefined && _jsx(SettingNote, { note: setting.note }), _jsx("p", { class: said.now?.problem ? "setting-said problem" : "setting-said", role: "status", children: said.now?.text })] })] }));
142
+ : _jsx(ListSetting, { setting: setting, label: id, onChange: send }), _jsxs("div", { class: "setting-after", children: [off !== undefined && _jsx("p", { class: "setting-off", id: `${id}-off`, children: off }), chosen?.means !== undefined && !rules && (_jsxs("p", { class: "setting-means", id: `${id}-means`, children: [_jsxs("strong", { children: [valueLabel(chosen.value), ":"] }), " ", meansText(setting.name, chosen.value, chosen.means, several)] })), setting.name === "language" && value !== undefined && _jsx("p", { class: "setting-means", children: languageLine(value) }), unset && _jsx("p", { class: "setting-unset", children: setting.choices === undefined ? t("Not answered yet: add them here, or the master asks you.") : t("Not chosen yet: choose here, or the master asks you.") }), setting.note !== undefined && _jsx(SettingNote, { note: setting.note }), _jsx("p", { class: said.now?.problem ? "setting-said problem" : "setting-said", role: "status", children: said.now?.text })] }), asking !== undefined && (_jsxs(Confirm, { title: t("Play by {rules}?", { rules: choiceLabel(setting.name, setting.choices?.find((choice) => choice.value === asking) ?? { value: asking }, false) }), onClose: keep, children: [_jsx("p", { children: t("The game follows these rules from the master's next move: the sheets are worked out with them, and the master reads them.") }), _jsx("p", { class: "confirm-note", children: t("What is already in play stays as it is, and you can go back whenever you want.") }), _jsxs("div", { class: "confirm-buttons", children: [_jsx("button", { type: "button", class: "button", autoFocus: true, onClick: keep, children: t("Cancel") }), _jsx("button", { type: "button", class: "button gold", onClick: () => {
143
+ setAsking(undefined);
144
+ focusChosen();
145
+ void onChange({ setting: setting.name, value: asking }).then(said.show);
146
+ }, children: t("Change the rules") })] })] }))] }));
147
+ }
148
+ // The engine's setting of the version of a game system's rules, whatever the system (VER-1).
149
+ const rulesetSetting = "ruleset";
150
+ /**
151
+ * A value of a setting on its button: a version of the rules by what it is to the player ("The 2014 rules"), as its name says little; any other by its label.
152
+ * `capital` false keeps it as written, for inside a sentence.
153
+ */
154
+ function choiceLabel(setting, choice, capital = true) {
155
+ if (setting !== rulesetSetting || choice.means === undefined) {
156
+ return valueLabel(choice.value);
157
+ }
158
+ const means = t(choice.means);
159
+ return capital ? phraseLabel(means) : means;
115
160
  }
116
161
  /** What a change said, in its row: saved for a few seconds, what went wrong until the next change. */
117
162
  function useSaid() {
@@ -310,10 +355,11 @@ function PageSettings() {
310
355
  }
311
356
  /**
312
357
  * Where the page shows the extensions' widgets (D-502), for the campaign: each in the top, the table's column, a page, or nowhere, and which page; the place its
313
- * extension gives it sends it back there. None without a widget.
358
+ * extension gives it sends it back there. None without a widget; never one on each of the party.
314
359
  */
315
360
  function WidgetSettings({ onChange }) {
316
- const widgets = useContext(WidgetsContext);
361
+ // One on each of the party stands where its package puts it: there is nowhere else for it (D-514).
362
+ const widgets = useContext(WidgetsContext).filter((widget) => widget.own.place !== "person" && widget.own.place !== "card");
317
363
  if (widgets.length === 0) {
318
364
  return null;
319
365
  }
@@ -387,7 +433,7 @@ function exampleOf(name) {
387
433
  const examples = {
388
434
  lines: t("Add, e.g. spiders"),
389
435
  veils: t("Add, e.g. torture"),
390
- learned: t("Add what you know, e.g. Advantage"),
436
+ learned: t("Add what you know, e.g. Initiative"),
391
437
  author: t("An author's name"),
392
438
  style: t("e.g. third person, past tense; more dialogue"),
393
439
  };
@@ -1,12 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
2
- import { useEffect, useId, useRef, useState } from "preact/hooks";
2
+ import { useContext, useEffect, useId, useRef, useState } from "preact/hooks";
3
3
  import { ActName, usePlayerActs } from "./act-names.js";
4
4
  import { itemVerbs } from "./acts.js";
5
5
  import { readExplanations } from "./api.js";
6
6
  import { CardHeader, useOpen } from "./card.js";
7
7
  import { FixedColumns } from "./columns.js";
8
- import { DeathSaves } from "./dying.js";
9
- import { WidgetCards } from "./extension-widgets.js";
8
+ import { WidgetCards, WidgetsContext } from "./extension-widgets.js";
10
9
  import { besideLabel, memberPlaceLabel } from "./game-words.js";
11
10
  import { cardIcons, DieIcon, Icon } from "./icons.js";
12
11
  import { fieldLabel, groupLabels, phraseLabel, readableIds, rollLabel, shownNotation, shownText } from "./labels.js";
@@ -14,8 +13,9 @@ import { arrangedGroups, groupLayout, orderedValues, widgetOf } from "./layout.j
14
13
  import { knowersOf, Markdown, plainLine } from "./markdown.js";
15
14
  import { MoodFace, moodLabel } from "./mood.js";
16
15
  import { MemberToken } from "./party.js";
16
+ import { PersonBoxes, personBoxes, personFields, PersonPanel, personShown } from "./person-panel.js";
17
17
  import { requestedRow, useRequested } from "./requested.js";
18
- import { memberStatus } from "./status.js";
18
+ import { besideWord, memberStatus } from "./status.js";
19
19
  import { StoryBox } from "./story.js";
20
20
  import { arrowStep, listText, systemWord, t } from "./text.js";
21
21
  import { Effects, ProgressBar, ValueDrawing } from "./widgets.js";
@@ -26,30 +26,38 @@ export function MemberSheet({ member, headline, sheet, cards, text, knownBy, sto
26
26
  const { rail, others } = arrangedGroups(sheet, cards);
27
27
  const fields = sheetFields(member, sheet);
28
28
  const group = (shown) => _jsx(Group, { member: member.name, group: shown, fields: fields, version: version, onRoll: onRoll, first: shown === others[0] }, shown.name);
29
- // At the dying point its counters leave the line for their panel, large, under the name (D-310, 7).
30
- const dying = new Set(member.dying?.map((counter) => counter.field));
29
+ const widgets = useContext(WidgetsContext);
30
+ const status = memberStatus(member, scene, widgets);
31
+ // At 0 the panels of the packages' widgets that say their state, large, under the name, their counters out of the line (D-310 (7), D-516). The others
32
+ // are small cards of their packages among the line's boxes, the counters they count left out of it.
33
+ const person = personShown(widgets, member.name);
34
+ const boxes = personBoxes(widgets, member.name);
35
+ const shownApart = personFields([...person, ...boxes]);
31
36
  // The player character's story has its own card: the rest of the page's text is its description (D-386).
32
37
  const described = story !== undefined && story.trim() !== "" && text.startsWith(story) ? text.slice(story.length).trimStart() : text;
33
- return (_jsxs("section", { class: "sheet", "aria-label": member.name, children: [_jsxs("header", { class: "band", children: [_jsxs("div", { class: "identity", children: [_jsx(MemberToken, { member: member, large: true, status: memberStatus(member, scene) }), _jsxs("div", { class: "who", children: [_jsx("h2", { children: member.name }), (headline !== undefined && headline !== "") || member.mood !== undefined
38
+ return (_jsxs("section", { class: "sheet", "aria-label": member.name, children: [_jsxs("header", { class: "band", children: [_jsxs("div", { class: "identity", children: [_jsx(MemberToken, { member: member, large: true, status: status }), _jsxs("div", { class: "who", children: [_jsx("h2", { children: member.name }), (headline !== undefined && headline !== "") || member.mood !== undefined
34
39
  ? (_jsxs("p", { class: "headline", children: [headline, headline !== undefined && headline !== "" && member.mood !== undefined && " · ", member.mood !== undefined && (_jsxs("span", { class: "mood-word", children: [_jsx(MoodFace, { mood: member.mood }), moodLabel(member.mood)] }))] }))
35
- : null, member.place && (_jsxs("p", { class: "place", children: [_jsx(Icon, { name: "place" }), memberPlaceLabel(member.place)] }))] })] }), member.dying && _jsx(DeathSaves, { dying: member.dying }), _jsx(ValueLine, { values: member.counters.filter((value) => !dying.has(value.field)), fields: fields }), _jsx(Effects, { effects: member.effects })] }), _jsxs("div", { class: "sheet-body", children: [rail.length > 0 && _jsx("div", { class: "rail", children: rail.map(group) }), _jsxs("div", { class: "sheet-main", children: [_jsx(FixedColumns, { cards: others.map((shown) => ({ key: shown.name, node: group(shown) })) }), _jsxs("div", { class: "wide-cards", children: [story !== undefined && (_jsxs(Card, { name: backstoryCard, title: t("Backstory"), icon: cardIcons.backstory, layout: "lore", preview: plainLine(story) ?? t("Not written yet"), children: [story.trim() !== "" && _jsx(Markdown, { text: story }), _jsx(StoryBox, { story: story, who: member.name })] })), described.trim() !== "" && (_jsx(Card, { name: descriptionCard, title: t("Description"), icon: cardIcons.description, layout: "lore", preview: plainLine(described), children: _jsx(Markdown, { text: described, secretKnowers: knowersOf(knownBy) }) }))] }), _jsx(WidgetCards, { place: "page", page: "sheet" })] })] })] }));
40
+ : null, member.place && (_jsxs("p", { class: "place", children: [_jsx(Icon, { name: "place" }), memberPlaceLabel(member.place)] }))] })] }), person.map((shown) => _jsx(PersonPanel, { shown: shown }, shown.widget.id)), _jsx(ValueLine, { values: member.counters.filter((value) => !shownApart.has(value.field)), fields: fields, boxes: boxes }), _jsx(Effects, { effects: besideWord(member.effects, status.person) })] }), _jsxs("div", { class: "sheet-body", children: [rail.length > 0 && _jsx("div", { class: "rail", children: rail.map(group) }), _jsxs("div", { class: "sheet-main", children: [_jsx(FixedColumns, { cards: others.map((shown) => ({ key: shown.name, node: group(shown) })) }), _jsxs("div", { class: "wide-cards", children: [story !== undefined && (_jsxs(Card, { name: backstoryCard, title: t("Backstory"), icon: cardIcons.backstory, layout: "lore", preview: plainLine(story) ?? t("Not written yet"), children: [story.trim() !== "" && _jsx(Markdown, { text: story }), _jsx(StoryBox, { story: story, who: member.name })] })), described.trim() !== "" && (_jsx(Card, { name: descriptionCard, title: t("Description"), icon: cardIcons.description, layout: "lore", preview: plainLine(described), children: _jsx(Markdown, { text: described, secretKnowers: knowersOf(knownBy) }) }))] }), _jsx(WidgetCards, { place: "page", page: "sheet", who: member.name, view: member })] })] })] }));
36
41
  }
37
42
  /** What of someone's sheet the Combat section keeps at hand (D-315): the fields it names in a line of boxes, as under the name, then the groups it names as their cards. */
38
43
  export function SheetAtHand({ member, sheet, names, version, onRoll }) {
39
44
  const fields = sheetFields(member, sheet);
40
45
  const same = (name, wanted) => name.toLowerCase() === wanted.toLowerCase();
41
- const line = names.flatMap((wanted) => sheet.flatMap((group) => group.values).filter((value) => same(value.field, wanted)));
46
+ // The packages' small cards on them too, as under the name (D-516), the counters they count left out.
47
+ const boxes = personBoxes(useContext(WidgetsContext), member.name);
48
+ const counted = personFields(boxes);
49
+ const line = names.flatMap((wanted) => sheet.flatMap((group) => group.values).filter((value) => same(value.field, wanted) && !counted.has(value.field)));
42
50
  const groups = names.flatMap((wanted) => sheet.filter((group) => same(group.name, wanted)));
43
- return (_jsxs(_Fragment, { children: [line.length > 0 && _jsx(ValueLine, { values: line, fields: fields }), groups.map((group) => _jsx(Group, { member: member.name, group: group, fields: fields, version: version, onRoll: onRoll }, group.name))] }));
51
+ return (_jsxs(_Fragment, { children: [(line.length > 0 || boxes.length > 0) && _jsx(ValueLine, { values: line, fields: fields, boxes: boxes }), groups.map((group) => _jsx(Group, { member: member.name, group: group, fields: fields, version: version, onRoll: onRoll }, group.name))] }));
44
52
  }
45
53
  /** What a row shows beside its value, when it says something more: a written speed equal to the one that counts now says nothing. */
46
54
  function shownBeside(value) {
47
55
  const beside = besideLabel(value);
48
56
  return beside === value.text ? undefined : beside;
49
57
  }
50
- /** Values in a line of boxes, as under someone's name (D-299): each its label and its drawing, flashing when it changes. */
51
- function ValueLine({ values, fields }) {
52
- return (_jsx("div", { class: "line", children: values.map((value) => (_jsxs("span", { class: "line-value", children: [_jsx("span", { class: "label", children: fieldLabel(value.field, fields) }), _jsx(Changing, { text: value.text, children: _jsx(ValueDrawing, { value: value, label: fieldLabel(value.field, fields) }) }), shownBeside(value) !== undefined && widgetOf(value) !== "progress" && _jsx("span", { class: "beside num", children: shownText(shownBeside(value) ?? "") })] }, value.field))) }));
58
+ /** Values in a line of boxes, as under someone's name (D-299): each its label and its drawing, flashing when it changes; then the packages' boxes (D-516). */
59
+ function ValueLine({ values, fields, boxes = [] }) {
60
+ return (_jsxs("div", { class: "line", children: [values.map((value) => (_jsxs("span", { class: "line-value", children: [_jsx("span", { class: "label", children: fieldLabel(value.field, fields) }), _jsx(Changing, { text: value.text, children: _jsx(ValueDrawing, { value: value, label: fieldLabel(value.field, fields) }) }), shownBeside(value) !== undefined && widgetOf(value) !== "progress" && _jsx("span", { class: "beside num", children: shownText(shownBeside(value) ?? "") })] }, value.field))), _jsx(PersonBoxes, { shown: boxes })] }));
53
61
  }
54
62
  /** A group of the sheet as its card; the `first` after the rail starts open on a phone too, the one play needs most as the system orders them. */
55
63
  function Group({ member, group, fields, version, onRoll, first }) {
@@ -1,31 +1,67 @@
1
1
  import { jsx as _jsx } from "preact/jsx-runtime";
2
- import { stableWord } from "./dying.js";
3
2
  import { effectLabel } from "./game-words.js";
4
3
  import { statusIcons } from "./icons.js";
4
+ import { saysState } from "./person-panel.js";
5
5
  import { conditionsPref, useChoice } from "./prefs.js";
6
- import { dyingState, effectsBesideState } from "./save-outcome.js";
7
- import { t } from "./text.js";
6
+ import { numberText, t } from "./text.js";
7
+ /**
8
+ * The state of someone of the party as the first widget on them that gives a word says it (D-514): its chip, the icon it shows or the widget's, its lead's
9
+ * tone; none where no widget on them gives one.
10
+ */
11
+ export function personState(widgets, name) {
12
+ const shown = widgets.filter((widget) => widget.place === "person").sort((first, second) => first.order - second.order)
13
+ .flatMap((widget) => (widget.people?.[name] === undefined ? [] : [{ widget, shows: widget.people[name] }])).find(saysState);
14
+ if (shown?.shows.chip === undefined) {
15
+ return undefined;
16
+ }
17
+ const icon = shown.shows.icon ?? shown.widget.icon;
18
+ const tone = shown.shows.parts?.find((part) => "lead" in part && part.tone !== undefined);
19
+ return {
20
+ word: wordOf(shown.shows.chip),
21
+ ...(icon === undefined ? {} : { icon }),
22
+ ...(tone !== undefined && "lead" in tone && tone.tone !== undefined ? { tone: tone.tone } : {}),
23
+ ...(shown.shows.dead === true ? { dead: true } : {}),
24
+ };
25
+ }
8
26
  /** The marks of someone's state, the one that counts most first: dead, at 0, kept from acting, then the conditions, the last put on first; with `all`, their other effects after them. */
9
27
  export function statusMarks(status, all = false) {
10
- const effects = effectsBesideState(status.effects ?? [], status.counters);
11
- // At 0 one of the party has a heartbeat, dying or stable; anyone else falls to the ground. The dead a red skull (D-461).
12
- const down = status.party === true
13
- ? { icon: statusIcons.down, label: status.dying === "stable" ? stableWord(status.counters) : t("Dying"), kind: "state", tone: status.dying === "stable" ? "stable" : "dying" }
28
+ // Never the effect the word of their state already says, as a widget's Down beside the condition Down, or the 5e's Stable (D-514, playtest 11).
29
+ const effects = besideWord(status.effects ?? [], status.party === true ? status.person : undefined);
30
+ // At 0 one of the party has the word a package's widget on them gives, its tone tinting it (D-514); anyone else, or one of the party with none, falls to
31
+ // the ground. The dead a red skull (D-461).
32
+ const person = status.party === true ? status.person : undefined;
33
+ const down = person !== undefined
34
+ ? { icon: person.icon ?? statusIcons.fallen, label: person.word, kind: "state", tone: toneState(person.tone) }
14
35
  : { icon: statusIcons.fallen, label: t("down"), kind: "state", tone: "down" };
15
- const states = status.dead === true || status.dying === "dead"
36
+ const states = status.dead === true
16
37
  ? [{ icon: statusIcons.dead, label: t("dead"), kind: "state", tone: "dead", filled: true }]
17
38
  : [
18
39
  ...(status.down === true ? [down] : []),
19
40
  ...(status.inactive === true ? [{ icon: statusIcons.inactive, label: t("Can't act"), kind: "state" }] : []),
20
41
  ];
21
42
  const conditions = effects.filter((effect) => effect.condition === true).reverse().map((effect) => ({ icon: effect.icon ?? statusIcons.condition, label: effectLabel(effect), kind: "condition" }));
22
- const others = all ? effects.filter((effect) => effect.condition !== true).map((effect) => ({ icon: statusIcons.condition, label: effectLabel(effect), kind: "other" })) : [];
43
+ const others = all ? effects.filter((effect) => effect.condition !== true).map((effect) => ({ icon: effect.icon ?? statusIcons.condition, label: effectLabel(effect), kind: "other" })) : [];
23
44
  return [...states, ...conditions, ...others];
24
45
  }
25
- /** The state of one of the party: their effects, whether dead or at their dying point, and whether the open scene says they cannot act. */
26
- export function memberStatus(member, scene) {
46
+ /**
47
+ * The state of one of the party: their effects, whether dead or at the system's down point, whether the open scene says they cannot act, and what a package's
48
+ * widget on them says of it (D-514), dead by its rules too (D-516).
49
+ */
50
+ export function memberStatus(member, scene, widgets = []) {
27
51
  const inScene = scene?.fighters?.find((fighter) => fighter.name === member.name) ?? scene?.who.find((person) => person.name === member.name);
28
- return { effects: member.effects, dead: member.dead, down: member.dying !== undefined, inactive: inScene?.inactive === true, dying: dyingState(member.dying), counters: member.dying, party: true };
52
+ const person = personState(widgets, member.name);
53
+ return {
54
+ effects: member.effects,
55
+ dead: member.dead || person?.dead === true,
56
+ down: member.down === true,
57
+ inactive: inScene?.inactive === true,
58
+ party: true,
59
+ ...(person === undefined ? {} : { person }),
60
+ };
61
+ }
62
+ /** How someone at 0 is tinted, on their token and in their marks: dead; by the tone of a widget on them; else as fallen. */
63
+ export function downTint(status) {
64
+ return status.dead === true ? "dead" : status.down !== true ? undefined : status.person !== undefined ? toneState(status.person.tone) : "down";
29
65
  }
30
66
  /** The pip of someone's state on their token, its marks in its tooltip; none without a mark, or while the player keeps them off. */
31
67
  export function StatusPip({ status }) {
@@ -41,13 +77,31 @@ export function StatusPip({ status }) {
41
77
  * Each mark of someone's state as an icon with its words, for a screen reader too and for the keyboard, as Combat's order shows them (D-419); a foe's fall only
42
78
  * drawn when its words already say it.
43
79
  */
44
- export function StatusIcons({ status, downSaid = false }) {
80
+ export function StatusIcons({ status, said = [] }) {
45
81
  const marks = statusMarks(status, true);
46
82
  return marks.length === 0 ? null : (_jsx("span", { class: "status-icons", children: marks.map((mark, index) => {
47
- const said = downSaid && mark.tone === "down";
48
- return (_jsx("span", { class: ["status-icon", mark.kind, mark.tone ?? ""].filter((name) => name !== "").join(" "), ...(said ? { "aria-hidden": "true" } : { role: "img", "aria-label": mark.label, tabIndex: 0 }), "data-tip": mark.label, children: _jsx("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", children: _jsx("path", { d: mark.icon, class: mark.filled ? "filled" : undefined }) }) }, `${mark.label} ${index}`));
83
+ // A state the row already says in words, hidden from a screen reader.
84
+ const hidden = mark.kind === "state" && mark.tone !== undefined && said.includes(mark.tone);
85
+ return (_jsx("span", { class: ["status-icon", mark.kind, mark.tone ?? ""].filter((name) => name !== "").join(" "), ...(hidden ? { "aria-hidden": "true" } : { role: "img", "aria-label": mark.label, tabIndex: 0 }), "data-tip": mark.label, children: _jsx("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", children: _jsx("path", { d: mark.icon, class: mark.filled ? "filled" : undefined }) }) }, `${mark.label} ${index}`));
49
86
  }) }));
50
87
  }
88
+ /** Someone's effects but the one the word of their state already says, as a widget's Down beside the condition Down (D-514). */
89
+ export function besideWord(effects, person) {
90
+ const said = person?.word.toLowerCase();
91
+ return said === undefined ? effects : effects.filter((effect) => effectLabel(effect).toLowerCase() !== said);
92
+ }
93
+ /** A tone of a widget as the tint of a state: good as stable, bad as dying, none as fallen. */
94
+ function toneState(tone) {
95
+ return tone === "good" ? "stable" : tone === "bad" ? "dying" : "down";
96
+ }
97
+ /** A widget's words as one string, its values as they are: a mark's tooltip and name. */
98
+ function wordOf(text) {
99
+ return typeof text === "string" ? text : text.text.replace(/\{(\w+)\}/g, (whole, name) => (name in text.values ? valueWord(text.values[name]) : whole));
100
+ }
101
+ /** A value of a widget's words in a word: a number as the page writes it. */
102
+ function valueWord(value) {
103
+ return typeof value === "number" ? numberText(value) : typeof value === "string" ? value : "number" in value ? numberText(value.number) : `${numberText(value.from)}–${numberText(value.to)}`;
104
+ }
51
105
  /** The words of someone's state for a screen reader, as a token's name says them. */
52
106
  export function statusWords(status) {
53
107
  return statusMarks(status, true).map((mark) => mark.label);