rpg-engine 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/campaign/settings.d.ts +1 -0
- package/dist/campaign/settings.js +6 -5
- package/dist/command-line.js +12 -5
- package/dist/commands/advance.js +1 -1
- package/dist/commands/ask.d.ts +37 -2
- package/dist/commands/ask.js +106 -35
- package/dist/commands/change.js +28 -17
- package/dist/commands/config.d.ts +1 -1
- package/dist/commands/config.js +69 -21
- package/dist/commands/effect.js +42 -23
- package/dist/commands/find.js +1 -1
- package/dist/commands/game-adventures.js +2 -2
- package/dist/commands/game-catalog.d.ts +13 -0
- package/dist/commands/game-catalog.js +26 -2
- package/dist/commands/game-checks.js +23 -21
- package/dist/commands/{game-hit-dice.d.ts → game-dice-pool.d.ts} +3 -3
- package/dist/commands/{game-hit-dice.js → game-dice-pool.js} +7 -7
- package/dist/commands/game-effects.d.ts +12 -4
- package/dist/commands/game-effects.js +21 -13
- package/dist/commands/game-examples.d.ts +22 -0
- package/dist/commands/game-examples.js +72 -0
- package/dist/commands/game-extension-list.d.ts +31 -3
- package/dist/commands/game-extension-list.js +94 -6
- package/dist/commands/game-images.d.ts +1 -1
- package/dist/commands/game-images.js +3 -2
- package/dist/commands/game-library.d.ts +3 -0
- package/dist/commands/game-library.js +2 -2
- package/dist/commands/game-mode.js +1 -1
- package/dist/commands/game-package-code.d.ts +87 -0
- package/dist/commands/game-package-code.js +648 -0
- package/dist/commands/game-package-hooks.d.ts +37 -0
- package/dist/commands/game-package-hooks.js +116 -0
- package/dist/commands/game-recipes.js +2 -2
- package/dist/commands/game-reminders.d.ts +5 -2
- package/dist/commands/game-reminders.js +7 -4
- package/dist/commands/game-rules.d.ts +4 -1
- package/dist/commands/game-rules.js +7 -1
- package/dist/commands/game-upkeep.js +3 -3
- package/dist/commands/game-view-place.d.ts +8 -20
- package/dist/commands/game-view-place.js +16 -35
- package/dist/commands/game-widgets.d.ts +42 -8
- package/dist/commands/game-widgets.js +182 -31
- package/dist/commands/game-world.d.ts +32 -3
- package/dist/commands/game-world.js +113 -24
- package/dist/commands/image.js +1 -1
- package/dist/commands/init.js +2 -2
- package/dist/commands/mode.d.ts +1 -1
- package/dist/commands/package.d.ts +15 -1
- package/dist/commands/package.js +96 -24
- package/dist/commands/progression.d.ts +2 -0
- package/dist/commands/progression.js +7 -2
- package/dist/commands/roll.d.ts +2 -0
- package/dist/commands/roll.js +50 -24
- package/dist/commands/rules.js +6 -4
- package/dist/commands/scene.d.ts +2 -2
- package/dist/commands/scene.js +13 -10
- package/dist/commands/sheet.js +10 -1
- package/dist/commands/status.d.ts +1 -0
- package/dist/commands/status.js +14 -4
- package/dist/commands/trade.js +6 -4
- package/dist/commands/translate.js +2 -2
- package/dist/commands/travel.js +1 -1
- package/dist/commands/validate.js +2 -2
- package/dist/commands/view.d.ts +12 -4
- package/dist/commands/view.js +11 -8
- package/dist/commands/worked-out.js +11 -5
- package/dist/commands/write.d.ts +8 -1
- package/dist/commands/write.js +84 -25
- package/dist/core/command-reference.js +3 -2
- package/dist/core/consents.d.ts +18 -0
- package/dist/core/consents.js +93 -0
- package/dist/core/context.d.ts +68 -27
- package/dist/core/context.js +3 -1
- package/dist/core/examples.d.ts +25 -0
- package/dist/core/examples.js +19 -0
- package/dist/core/files.d.ts +2 -0
- package/dist/core/files.js +10 -1
- package/dist/core/package-api.d.ts +388 -0
- package/dist/core/package-declarations.d.ts +102 -0
- package/dist/core/package-declarations.js +81 -0
- package/dist/core/registry.d.ts +4 -0
- package/dist/core/text.d.ts +5 -0
- package/dist/core/text.js +12 -0
- package/dist/dashboard/acts.js +31 -24
- package/dist/dashboard/address.js +4 -1
- package/dist/dashboard/api.js +65 -3
- package/dist/dashboard/app.js +222 -98
- package/dist/dashboard/ask-card.js +169 -0
- package/dist/dashboard/asked-dice.js +57 -0
- package/dist/dashboard/dice/tray.js +6 -4
- package/dist/dashboard/extension-widgets.js +136 -16
- package/dist/dashboard/faces.js +6 -4
- package/dist/dashboard/help.js +10 -3
- package/dist/dashboard/i18n/ar.json +34 -29
- package/dist/dashboard/i18n/cs.json +34 -29
- package/dist/dashboard/i18n/da.json +34 -29
- package/dist/dashboard/i18n/de.json +34 -29
- package/dist/dashboard/i18n/el.json +34 -29
- package/dist/dashboard/i18n/es.json +34 -29
- package/dist/dashboard/i18n/fi.json +34 -29
- package/dist/dashboard/i18n/fr.json +34 -29
- package/dist/dashboard/i18n/he.json +34 -29
- package/dist/dashboard/i18n/hi.json +34 -29
- package/dist/dashboard/i18n/hu.json +34 -29
- package/dist/dashboard/i18n/is.json +34 -29
- package/dist/dashboard/i18n/it.json +34 -29
- package/dist/dashboard/i18n/ja.json +34 -29
- package/dist/dashboard/i18n/ko.json +34 -29
- package/dist/dashboard/i18n/nb.json +34 -29
- package/dist/dashboard/i18n/nl.json +34 -29
- package/dist/dashboard/i18n/pl.json +34 -29
- package/dist/dashboard/i18n/pt.json +34 -29
- package/dist/dashboard/i18n/ro.json +34 -29
- package/dist/dashboard/i18n/ru.json +34 -29
- package/dist/dashboard/i18n/sv.json +34 -29
- package/dist/dashboard/i18n/tr.json +34 -29
- package/dist/dashboard/i18n/uk.json +34 -29
- package/dist/dashboard/i18n/zh.json +34 -29
- package/dist/dashboard/icons.js +4 -1
- package/dist/dashboard/kit.js +35 -0
- package/dist/dashboard/labels.js +1 -0
- package/dist/dashboard/pack-card.js +97 -0
- package/dist/dashboard/package-page.js +50 -0
- package/dist/dashboard/packages.js +180 -24
- package/dist/dashboard/page-code.js +248 -0
- package/dist/dashboard/party.js +13 -14
- package/dist/dashboard/people.js +4 -0
- package/dist/dashboard/person-panel.js +110 -0
- package/dist/dashboard/place-map-view.js +11 -6
- package/dist/dashboard/rolls.js +2 -2
- package/dist/dashboard/scene.js +12 -9
- package/dist/dashboard/settings.js +55 -9
- package/dist/dashboard/sheet.js +21 -13
- package/dist/dashboard/status.js +69 -15
- package/dist/dashboard/style.css +859 -574
- package/dist/dashboard/top.js +75 -25
- package/dist/dashboard/turns.js +34 -13
- package/dist/dashboard/widgets.js +9 -2
- package/dist/dashboard-server.js +246 -11
- package/dist/dice/roll-dice.js +1 -1
- package/dist/effects/effect.d.ts +7 -4
- package/dist/effects/effect.js +12 -9
- package/dist/extensions/engine.d.ts +4 -0
- package/dist/extensions/engine.js +74 -0
- package/dist/extensions/extension.d.ts +28 -33
- package/dist/extensions/extension.js +37 -46
- package/dist/extensions/index.d.ts +4 -3
- package/dist/extensions/index.js +5 -2
- package/dist/extensions/packages.d.ts +14 -0
- package/dist/extensions/packages.js +148 -12
- package/dist/extensions/words.d.ts +2 -1
- package/dist/extensions/words.js +5 -4
- package/dist/index.d.ts +1 -3
- package/dist/mcp-server.js +52 -15
- package/dist/page-words.d.ts +4 -0
- package/dist/page-words.js +4 -4
- package/dist/page.d.ts +218 -0
- package/dist/page.js +2 -0
- package/dist/pages/index.d.ts +1 -1
- package/dist/pages/index.js +1 -1
- package/dist/pages/load.d.ts +7 -1
- package/dist/pages/load.js +10 -5
- package/dist/pages/page-file.js +1 -1
- package/dist/pages/stack-writes.js +5 -4
- package/dist/pages/standard-fields.d.ts +2 -0
- package/dist/pages/standard-fields.js +8 -1
- package/dist/pages/world.d.ts +8 -0
- package/dist/pages/world.js +9 -2
- package/dist/systems/game-system.d.ts +61 -30
- package/dist/systems/game-system.js +159 -50
- package/dist/systems/index.d.ts +3 -3
- package/dist/systems/index.js +3 -3
- package/dist/systems/system-code.d.ts +29 -88
- package/dist/systems/system-code.js +68 -23
- package/dist/systems/words.d.ts +2 -0
- package/dist/systems/words.js +11 -0
- package/dist/testing.d.ts +76 -0
- package/dist/testing.js +197 -0
- package/instructions/combat.md +2 -2
- package/instructions/core.md +2 -2
- package/instructions/dashboard.md +1 -1
- package/instructions/mentor-tutorial.md +1 -1
- package/instructions/play.md +2 -2
- package/instructions/setup.md +1 -1
- package/package.json +15 -2
- package/systems/5e/LICENSE.md +13 -3
- package/systems/5e/dist/dying.js +83 -16
- package/systems/5e/dist/index.js +2 -2
- package/systems/5e/dist/page-style.js +634 -0
- package/systems/5e/dist/page.js +166 -0
- package/systems/5e/dist/shown.js +23 -0
- package/systems/5e/instructions/combat.md +1 -0
- package/systems/5e/package.json +4 -2
- package/systems/5e/system.yaml +35 -7
- package/systems/5e/versions/srd-5.1/system.yaml +2 -0
- package/systems/5e/words/ar.yaml +30 -0
- package/systems/5e/words/cs.yaml +30 -0
- package/systems/5e/words/da.yaml +30 -0
- package/systems/5e/words/de.yaml +30 -0
- package/systems/5e/words/el.yaml +30 -0
- package/systems/5e/words/es.yaml +30 -0
- package/systems/5e/words/fi.yaml +30 -0
- package/systems/5e/words/fr.yaml +30 -0
- package/systems/5e/words/he.yaml +30 -0
- package/systems/5e/words/hi.yaml +30 -0
- package/systems/5e/words/hu.yaml +30 -0
- package/systems/5e/words/is.yaml +30 -0
- package/systems/5e/words/it.yaml +30 -0
- package/systems/5e/words/ja.yaml +30 -0
- package/systems/5e/words/ko.yaml +30 -0
- package/systems/5e/words/nb.yaml +30 -0
- package/systems/5e/words/nl.yaml +30 -0
- package/systems/5e/words/pl.yaml +30 -0
- package/systems/5e/words/pt.yaml +30 -0
- package/systems/5e/words/ro.yaml +30 -0
- package/systems/5e/words/ru.yaml +30 -0
- package/systems/5e/words/sv.yaml +30 -0
- package/systems/5e/words/tr.yaml +30 -0
- package/systems/5e/words/uk.yaml +30 -0
- package/systems/5e/words/zh.yaml +30 -0
- package/dist/commands/game-extensions.d.ts +0 -34
- package/dist/commands/game-extensions.js +0 -182
- package/dist/commands/game-system-code.d.ts +0 -25
- package/dist/commands/game-system-code.js +0 -172
- package/dist/dashboard/death-save.js +0 -67
- package/dist/dashboard/dying.js +0 -46
- package/dist/dashboard/save-outcome.js +0 -42
- package/dist/dashboard/spend.js +0 -115
- package/dist/extensions/api.d.ts +0 -155
- /package/dist/{extensions/api.js → core/package-api.js} +0 -0
|
@@ -0,0 +1,169 @@
|
|
|
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, 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.
|
|
6
|
+
import { useEffect, useRef, useState } from "preact/hooks";
|
|
7
|
+
import { Drawn, OwnerContext, Part, Text, textOf, Track, Who } from "./extension-widgets.js";
|
|
8
|
+
import { Icon, NotationIcons } from "./icons.js";
|
|
9
|
+
import { checkOf, fieldLabel } from "./labels.js";
|
|
10
|
+
import { cardLayout, labelKey, trackChanges } from "./pack-card.js";
|
|
11
|
+
import { deepQuery, ExtensionRoot, figureSize, pagePropsOf, usePageModule } from "./page-code.js";
|
|
12
|
+
import { t } from "./text.js";
|
|
13
|
+
import { turnWords } from "./turns.js";
|
|
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 }) {
|
|
16
|
+
const element = useRef(null);
|
|
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.
|
|
18
|
+
const pressed = useRef(false);
|
|
19
|
+
// What the card showed, and before it, what changed since, and that change in words for a screen reader.
|
|
20
|
+
const look = useRef({ said: "", changes: new Map(), told: "" });
|
|
21
|
+
const said = JSON.stringify(card.shows);
|
|
22
|
+
if (look.current.said !== said) {
|
|
23
|
+
const changes = trackChanges(look.current.shows, card.shows);
|
|
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) };
|
|
26
|
+
}
|
|
27
|
+
const { changes, told } = look.current;
|
|
28
|
+
const layout = cardLayout(card.shows);
|
|
29
|
+
const asked = card.ended === true ? undefined : card.asked;
|
|
30
|
+
const ruled = card.asked?.rule;
|
|
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;
|
|
34
|
+
const question = card.title ?? asked?.question;
|
|
35
|
+
const prompt = asked !== undefined && question !== asked.question ? asked.question : undefined;
|
|
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.
|
|
37
|
+
const outcome = layout.lead?.tone === undefined ? undefined : layout.lead;
|
|
38
|
+
const id = card.key.replace(/[^a-z0-9-]/gi, "-");
|
|
39
|
+
const ruleId = `ask-rule-${id}`;
|
|
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;
|
|
44
|
+
// The player's own words, as in the master's question: while they go, and what went wrong.
|
|
45
|
+
const [words, setWords] = useState("");
|
|
46
|
+
const [saying, setSaying] = useState(false);
|
|
47
|
+
const [problem, setProblem] = useState();
|
|
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;
|
|
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.
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
const box = element.current;
|
|
54
|
+
if (box === null) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const root = document.documentElement;
|
|
58
|
+
const publish = () => {
|
|
59
|
+
if (getComputedStyle(box).position === "sticky") {
|
|
60
|
+
root.style.setProperty("--asked-space", `${box.offsetHeight + 16}px`);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
root.style.removeProperty("--asked-space");
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const observer = new ResizeObserver(publish);
|
|
67
|
+
observer.observe(box);
|
|
68
|
+
publish();
|
|
69
|
+
return () => {
|
|
70
|
+
observer.disconnect();
|
|
71
|
+
root.style.removeProperty("--asked-space");
|
|
72
|
+
};
|
|
73
|
+
}, [card.ended]);
|
|
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.
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (!pressed.current || element.current === null || (element.current.contains(document.activeElement) && deepActive()?.classList.contains("ext-root") !== true)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const next = deepQuery(element.current, card.ended === true ? ".ask-close" : ".ask-choices button:not([aria-disabled='true'])");
|
|
81
|
+
if (next !== null) {
|
|
82
|
+
pressed.current = false;
|
|
83
|
+
next.focus();
|
|
84
|
+
}
|
|
85
|
+
}, [card.asked?.id, card.ended]);
|
|
86
|
+
const press = (index) => {
|
|
87
|
+
if (card.sent !== undefined) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
pressed.current = element.current?.contains(document.activeElement) === true;
|
|
91
|
+
onAnswer(index);
|
|
92
|
+
};
|
|
93
|
+
const say = async (event) => {
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
const text = words.trim();
|
|
96
|
+
if (text === "" || busy) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
setSaying(true);
|
|
100
|
+
setProblem(undefined);
|
|
101
|
+
if (await onWords(text, element.current?.contains(document.activeElement) === true)) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
setSaying(false);
|
|
105
|
+
setProblem(t("The answer did not reach the game: try again."));
|
|
106
|
+
};
|
|
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 }) };
|
|
144
|
+
}
|
|
145
|
+
// How many characters the player's own words may have, as the server takes them.
|
|
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
|
+
}
|
|
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." */
|
|
164
|
+
function toldText(card, changes) {
|
|
165
|
+
const layout = cardLayout(card.shows);
|
|
166
|
+
const lead = layout.lead?.tone === undefined ? "" : `${textOf(layout.lead.lead)}.`;
|
|
167
|
+
const counts = Object.values(layout.places).flat().filter((track) => changes.has(labelKey(track.label))).map((track) => `${textOf(track.label)}: ${t("{value} of {max}", { value: track.value + (track.held ?? 0), max: track.max })}.`);
|
|
168
|
+
return [lead, ...counts].filter((part) => part !== "").join(" ");
|
|
169
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
// The dice of a rest the master asks the player to spend (ASK-14), when no package draws a card for them (D-513 (6)): the master's question with a button
|
|
3
|
+
// for each counter of dice, which rolls one of its dice and stays, and the button that ends it. The engine rolls each die and the question comes back with
|
|
4
|
+
// the counters as they are; a game's own card, as the 5e's for its hit dice, comes from its page module.
|
|
5
|
+
import { useEffect, useRef, useState } from "preact/hooks";
|
|
6
|
+
import { DieIcon } from "./icons.js";
|
|
7
|
+
import { fieldLabel, signed } from "./labels.js";
|
|
8
|
+
import { numberText, t } from "./text.js";
|
|
9
|
+
export function AskedDice({ asked, spend, flying, onSpend, onDone }) {
|
|
10
|
+
const element = useRef(null);
|
|
11
|
+
// A die asked of the engine, until its roll comes back, as how many rolls there were then; the end asked.
|
|
12
|
+
const [sent, setSent] = useState();
|
|
13
|
+
const [leaving, setLeaving] = useState(false);
|
|
14
|
+
const waiting = (sent !== undefined && spend.rolls.length <= sent) || spend.rolls.some((roll) => roll.id === flying);
|
|
15
|
+
const busy = waiting || leaving;
|
|
16
|
+
// The dice as they were until the last roll's dice land.
|
|
17
|
+
const steady = useRef(spend);
|
|
18
|
+
if (!waiting) {
|
|
19
|
+
steady.current = spend;
|
|
20
|
+
}
|
|
21
|
+
const shown = steady.current;
|
|
22
|
+
const last = shown.rolls.at(-1);
|
|
23
|
+
// While it is there, the rolls beside the sheet stay in sight under it, as under the master's question (D-291).
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
const box = element.current;
|
|
26
|
+
if (box === null) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const root = document.documentElement;
|
|
30
|
+
const observer = new ResizeObserver(() => root.style.setProperty("--asked-space", `${box.offsetHeight + 16}px`));
|
|
31
|
+
observer.observe(box);
|
|
32
|
+
return () => {
|
|
33
|
+
observer.disconnect();
|
|
34
|
+
root.style.removeProperty("--asked-space");
|
|
35
|
+
};
|
|
36
|
+
}, []);
|
|
37
|
+
const spendOne = async (field) => {
|
|
38
|
+
if (busy) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
setSent(spend.rolls.length);
|
|
42
|
+
if (!await onSpend(field)) {
|
|
43
|
+
setSent(undefined);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const end = async () => {
|
|
47
|
+
if (busy) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
setLeaving(true);
|
|
51
|
+
if (!await onDone(element.current?.contains(document.activeElement) === true)) {
|
|
52
|
+
setLeaving(false);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const gives = shown.gives;
|
|
56
|
+
return (_jsxs("section", { ref: element, class: "asked asked-roll asked-rest", "aria-labelledby": `asked-${asked.id}`, children: [_jsx("img", { class: "asked-robot", src: "/assets/favicon.svg", alt: "" }), _jsxs("div", { class: "asked-body", children: [_jsx("h2", { class: "asked-title", children: asked.title }), _jsx("p", { id: `asked-${asked.id}`, class: "asked-question", role: "alert", children: asked.question }), _jsx("p", { class: "asked-gives", children: `${fieldLabel(gives.field)} ${numberText(gives.value)}${gives.max === undefined ? "" : `/${numberText(gives.max)}`}` }), _jsxs("div", { class: "asked-buttons", children: [shown.dice.map((dice) => (_jsxs("button", { type: "button", class: "asked-check", disabled: busy || dice.value <= 0, onClick: () => void spendOne(dice.field), children: [_jsx(DieIcon, { sides: dice.sides }), _jsx("span", { class: "asked-check-name", children: fieldLabel(dice.field) }), dice.adds !== 0 && _jsx("span", { class: "asked-dice", children: signed(dice.adds) }), _jsx("span", { class: "asked-roll-name", children: t("{value} of {max}", { value: dice.value, max: dice.max }) })] }, dice.field))), _jsx("button", { type: "button", class: "asked-other", disabled: busy, onClick: () => void end(), children: asked.labels[0] })] }), _jsx("p", { class: "visually-hidden", role: "status", children: last === undefined ? "" : `${fieldLabel(last.field)}: ${last.total}` })] })] }));
|
|
57
|
+
}
|
|
@@ -115,9 +115,9 @@ export function DiceTray({ requested, sheetThrow, party, onLanded, onShown, onFr
|
|
|
115
115
|
// The plate is measured, unseen, before the dice fly: they land above it, however many rows its dice take (D-366).
|
|
116
116
|
await new Promise((painted) => requestAnimationFrame(painted));
|
|
117
117
|
const plateTop = measuredPlate.current?.getBoundingClientRect().top;
|
|
118
|
-
// The header as it stands now, full at the page's top or compact below it: no die lands under it; on a wide screen nor on the card of a
|
|
119
|
-
// whose outcome comes as they land (D-461), or
|
|
120
|
-
const card = matchMedia("(min-width: 601px)").matches ? document.querySelector(".
|
|
118
|
+
// The header as it stands now, full at the page's top or compact below it: no die lands under it; on a wide screen nor on the card of a package's
|
|
119
|
+
// question, whose outcome comes as they land, as a death save's (D-461, D-507), or on a rest's dice (D-492). A phone has no room under it.
|
|
120
|
+
const card = matchMedia("(min-width: 601px)").matches ? document.querySelector(".ask-card, .asked-rest")?.getBoundingClientRect().bottom : undefined;
|
|
121
121
|
const headerBottom = Math.max(0, document.querySelector(".top")?.getBoundingClientRect().bottom ?? 0, card ?? 0);
|
|
122
122
|
if (plateTop !== undefined && plateTop > 0) {
|
|
123
123
|
loaded?.cover(window.innerHeight - plateTop, headerBottom, card !== undefined);
|
|
@@ -194,6 +194,8 @@ export function DiceTray({ requested, sheetThrow, party, onLanded, onShown, onFr
|
|
|
194
194
|
dice: requested.dice,
|
|
195
195
|
modifier: notationModifier(requested.notation),
|
|
196
196
|
total: requested.total,
|
|
197
|
+
...(requested.says === undefined ? {} : { says: requested.says }),
|
|
198
|
+
...(requested.tones === undefined ? {} : { tones: requested.tones }),
|
|
197
199
|
text: requested.text,
|
|
198
200
|
...(member === undefined ? {} : { member }),
|
|
199
201
|
roll: requested.id,
|
|
@@ -303,7 +305,7 @@ export function DiceTray({ requested, sheetThrow, party, onLanded, onShown, onFr
|
|
|
303
305
|
}
|
|
304
306
|
/** What the plate says: whose roll and which, the dice one by one with the modifier, the total large, a rare face's words, and for a screen reader the chat's text. */
|
|
305
307
|
function PlateContent({ plate }) {
|
|
306
|
-
return (_jsxs(_Fragment, { children: [_jsxs("div", { class: "plate-head", children: [plate.member && _jsx(Token, { member: plate.member }), _jsxs("span", { class: "plate-what", children: [_jsx("span", { class: "plate-title", children: plate.title }), plate.free && (_jsx("span", { class: "plate-under", children: _jsx("span", { class: "plate-tag", children: t("Free roll · not logged") }) }))] })] }), _jsx(DiceFaces, { dice: plate.dice, modifier: plate.modifier, className: "plate-dice" }), _jsx("span", { class: "plate-total num", children: shownText(String(plate.total)) }), plate.rare && _jsx("p", { class: "plate-rare", children: plate.rare.words }), _jsx("span", { class: "visually-hidden", children: plate.free ? t("{dice}, free roll, not logged", { dice: plate.text }) : plate.text })] }));
|
|
308
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { class: "plate-head", children: [plate.member && _jsx(Token, { member: plate.member }), _jsxs("span", { class: "plate-what", children: [_jsx("span", { class: "plate-title", children: plate.title }), plate.free && (_jsx("span", { class: "plate-under", children: _jsx("span", { class: "plate-tag", children: t("Free roll · not logged") }) }))] })] }), _jsx(DiceFaces, { dice: plate.dice, modifier: plate.modifier, className: "plate-dice", tones: plate.tones }), plate.says === undefined ? _jsx("span", { class: "plate-total num", children: shownText(String(plate.total)) }) : _jsx("span", { class: "plate-total plate-says", children: plate.says }), plate.rare && _jsx("p", { class: "plate-rare", children: plate.rare.words }), _jsx("span", { class: "visually-hidden", children: plate.free ? t("{dice}, free roll, not logged", { dice: plate.text }) : plate.text })] }));
|
|
307
309
|
}
|
|
308
310
|
/** A free throw as this browser's rolls keep it (D-330 (4)): whose sheet it is from, the number's label as its check, its dice and total. */
|
|
309
311
|
function pageRoll(plate, number) {
|
|
@@ -6,9 +6,14 @@ import { useContext, useEffect, useRef } from "preact/hooks";
|
|
|
6
6
|
import { sectionAddress } from "./address.js";
|
|
7
7
|
import { CardHead } from "./card.js";
|
|
8
8
|
import { iconPath } from "./icons.js";
|
|
9
|
+
import { cardsIn, codeOfModule, ExtensionRoot, figureSize, ModulesContext, pagePropsOf, usePageModule, useWidgetData } from "./page-code.js";
|
|
10
|
+
import { sideOf, Token } from "./party.js";
|
|
11
|
+
import { PeopleContext } from "./people.js";
|
|
9
12
|
import { isolated, numberText, pageDirection, t } from "./text.js";
|
|
10
13
|
/** The widgets of the campaign's extensions, as last read: every part of the page that holds some takes its own from here. */
|
|
11
14
|
export const WidgetsContext = createContext([]);
|
|
15
|
+
/** The widget whose parts are drawn here, with its page module and data, for a count its extension draws as a figure (D-510); where it stands. */
|
|
16
|
+
export const OwnerContext = createContext(undefined);
|
|
12
17
|
// The section of the page each widget's page is.
|
|
13
18
|
const pageSections = { scene: "scene", sheet: "party", world: "world", journal: "journal" };
|
|
14
19
|
// The card a chip in the top has just led to, which brings itself into view as it is drawn.
|
|
@@ -18,13 +23,42 @@ export function WidgetChips() {
|
|
|
18
23
|
const widgets = useContext(WidgetsContext);
|
|
19
24
|
return (_jsx(_Fragment, { children: inPlace(widgets, "top").filter((widget) => widget.shows !== undefined).map((widget) => _jsx(WidgetChip, { widget: widget, card: cardOf(widgets, widget) }, widget.id)) }));
|
|
20
25
|
}
|
|
21
|
-
/**
|
|
22
|
-
|
|
26
|
+
/**
|
|
27
|
+
* The cards of the widgets that stand in this place, or at the end of this page, in their order; in a page, then the cards its packages' page code puts there
|
|
28
|
+
* (D-511), given whose sheet it is and what the page shows. Nothing where none does.
|
|
29
|
+
*/
|
|
30
|
+
export function WidgetCards({ place, page, who, view }) {
|
|
23
31
|
const widgets = inPlace(useContext(WidgetsContext), place, page).filter((widget) => widget.shows?.parts !== undefined || widget.shows?.note !== undefined);
|
|
32
|
+
const own = place === "page" && page !== undefined ? _jsx(PackageCards, { page: page, who: who, view: view }) : null;
|
|
24
33
|
if (widgets.length === 0) {
|
|
25
|
-
return
|
|
34
|
+
return own;
|
|
26
35
|
}
|
|
27
|
-
return (_jsx("div", { class: `widget-cards on-${place}`, children: widgets.map((widget) => _jsx(WidgetCard, { widget: widget }, widget.id)) }));
|
|
36
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { class: `widget-cards on-${place}`, children: widgets.map((widget) => _jsx(WidgetCard, { widget: widget }, widget.id)) }), own] }));
|
|
37
|
+
}
|
|
38
|
+
/** The cards the page code of the campaign's packages puts in a page (D-511), the system's first, each package's in their order. */
|
|
39
|
+
function PackageCards({ page, who, view }) {
|
|
40
|
+
const modules = useContext(ModulesContext);
|
|
41
|
+
return modules.length === 0 ? null : _jsx("div", { class: "widget-cards on-page package-cards", children: modules.map((module) => _jsx(ModuleCards, { module: module, page: page, who: who, view: view }, module.package)) });
|
|
42
|
+
}
|
|
43
|
+
/** One package's cards in a page, once its module came; one that did not load says so in a card of its own, with its error. */
|
|
44
|
+
function ModuleCards({ module, page, who, view }) {
|
|
45
|
+
const owner = codeOfModule(module);
|
|
46
|
+
const loaded = usePageModule(owner);
|
|
47
|
+
const cards = cardsIn(loaded, page);
|
|
48
|
+
if (cards instanceof Error) {
|
|
49
|
+
const id = titleId(`${module.package}.broken`);
|
|
50
|
+
return (_jsxs("section", { class: "card widget-card package-card", "aria-labelledby": id, children: [_jsx(CardHead, { icon: iconPath("packages"), title: _jsx("h3", { id: id, children: module.package }) }), _jsx("div", { class: "card-body widget-body", children: _jsx(ExtensionRoot, { widget: owner, loaded: cards, kind: "ext-body", draw: () => null }) })] }));
|
|
51
|
+
}
|
|
52
|
+
return _jsx(_Fragment, { children: cards.map(([name, card]) => _jsx(ModuleCard, { module: module, name: name, card: card, page: page, who: who, view: view }, name)) });
|
|
53
|
+
}
|
|
54
|
+
/** One card of a package's page code, with the data of the widget it names for who, once it comes (D-514). */
|
|
55
|
+
function ModuleCard({ module, name, card, page, who, view }) {
|
|
56
|
+
const owner = codeOfModule(module);
|
|
57
|
+
const loaded = usePageModule(owner);
|
|
58
|
+
const data = useWidgetData(module.package, card.widget, who, useContext(WidgetsContext));
|
|
59
|
+
const id = titleId(`${module.package}.${name}`);
|
|
60
|
+
const Drawing = card.draw;
|
|
61
|
+
return (_jsxs("section", { class: "card widget-card package-card", "aria-labelledby": id, children: [_jsx(CardHead, { icon: card.icon ?? iconPath("packages"), title: _jsx("h3", { id: id, children: card.title }) }), _jsx("div", { class: "card-body widget-body", children: _jsx(ExtensionRoot, { widget: owner, loaded: loaded, kind: "ext-body", draw: () => _jsx(Drawing, { ...pagePropsOf(owner), name: name, page: page, ...(who === undefined ? {} : { who }), ...(view === undefined ? {} : { view }), ...(data === undefined ? {} : { data }) }) }) })] }));
|
|
28
62
|
}
|
|
29
63
|
/** A widget's title as a chip names it: with what it says whole, Weather: scattered rain, 10–15 °C. */
|
|
30
64
|
export function widgetSaid(widget) {
|
|
@@ -47,8 +81,13 @@ function WidgetChip({ widget, card }) {
|
|
|
47
81
|
const shows = widget.shows;
|
|
48
82
|
const icon = shows?.icon ?? widget.icon;
|
|
49
83
|
const said = widgetSaid(widget);
|
|
84
|
+
const loaded = usePageModule(widget);
|
|
85
|
+
// Its lead's figure in place of its icon, when its page code draws one (D-510): the frame, the words, the tip and the name stay the page's.
|
|
86
|
+
const lead = shows?.parts?.find((part) => "lead" in part && part.figure !== undefined);
|
|
50
87
|
// Named by its whole sentence, which its tip shows too: the tip's drawing would add itself to a name made of its words.
|
|
51
|
-
const inside = (_jsxs(_Fragment, { children: [
|
|
88
|
+
const inside = (_jsxs(_Fragment, { children: [lead?.figure !== undefined && widget.module !== undefined
|
|
89
|
+
? _jsx(Figure, { owner: { widget, loaded, data: shows?.data, place: "top" }, name: lead.figure, part: lead })
|
|
90
|
+
: icon !== undefined && _jsx(Drawn, { path: icon, kind: "icon" }), _jsx("span", { class: "num", children: shows?.chip === undefined ? widget.title : _jsx(Text, { text: shows.chip }) })] }));
|
|
52
91
|
// A chip leads to its extension's card where one stands in a page; else it only says.
|
|
53
92
|
return card?.page === undefined
|
|
54
93
|
? _jsx("span", { class: "status-chip widget-chip tip-below", role: "img", "aria-label": said, "data-tip": said, children: inside })
|
|
@@ -78,6 +117,8 @@ function WidgetCard({ widget }) {
|
|
|
78
117
|
const id = titleId(widget.id);
|
|
79
118
|
const title = useRef(null);
|
|
80
119
|
const shows = widget.shows;
|
|
120
|
+
const loaded = usePageModule(widget);
|
|
121
|
+
const place = widget.place === "page" ? "page" : "side";
|
|
81
122
|
// Led here by its chip from another page.
|
|
82
123
|
useEffect(() => {
|
|
83
124
|
if (wanted === widget.id && title.current !== null) {
|
|
@@ -85,10 +126,24 @@ function WidgetCard({ widget }) {
|
|
|
85
126
|
bringTitle(title.current);
|
|
86
127
|
}
|
|
87
128
|
}, []);
|
|
88
|
-
return (_jsxs("section", { class: "card widget-card", "aria-labelledby": id, children: [_jsx(CardHead, { icon: shows?.icon ?? widget.icon ?? iconPath("packages"), title: _jsx("h3", { id: id, ref: title, tabIndex: -1, children: widget.title }), ...(shows?.note === undefined ? {} : { note: _jsx(Text, { text: shows.note }) }) }), shows?.parts !== undefined && shows.parts.length > 0 && _jsx("div", { class: "card-body widget-body", children: shows.parts.map((part, index) => _jsx(Part, { part: part }, index)) })] }));
|
|
129
|
+
return (_jsxs("section", { class: "card widget-card", "aria-labelledby": id, children: [_jsx(CardHead, { icon: shows?.icon ?? widget.icon ?? iconPath("packages"), title: _jsx("h3", { id: id, ref: title, tabIndex: -1, children: widget.title }), ...(shows?.note === undefined ? {} : { note: _jsx(Text, { text: shows.note }) }) }), shows?.parts !== undefined && shows.parts.length > 0 && (_jsx(OwnerContext.Provider, { value: { widget, loaded, data: shows.data, place }, children: _jsx("div", { class: "card-body widget-body", children: shows.parts.map((part, index) => _jsx(Part, { part: part }, index)) }) }))] }));
|
|
130
|
+
}
|
|
131
|
+
/** Who acts in a card (D-509, D-510): their portrait as the page draws it, the party and those at the place known by name; their name and what they do. */
|
|
132
|
+
export function Who({ who, does }) {
|
|
133
|
+
const person = useContext(PeopleContext).find((one) => one.name === who) ?? { name: who, role: "other" };
|
|
134
|
+
const side = sideOf(person.role);
|
|
135
|
+
return (_jsxs("div", { class: "who-acts", children: [_jsx(Token, { member: person, ...(side === undefined ? {} : { side }) }), _jsxs("p", { class: "who-acts-words", dir: "auto", children: [_jsx("b", { class: "who-acts-name", children: who }), does !== undefined && (_jsx("span", { class: "who-acts-does", children: _jsx(Text, { text: does }) }))] })] }));
|
|
89
136
|
}
|
|
90
137
|
/** A part of a widget's card, as the page draws its own. */
|
|
91
|
-
function Part({ part }) {
|
|
138
|
+
export function Part({ part }) {
|
|
139
|
+
const owner = useContext(OwnerContext);
|
|
140
|
+
if ("who" in part) {
|
|
141
|
+
return _jsx(Who, { who: part.who, does: part.does });
|
|
142
|
+
}
|
|
143
|
+
if ("lead" in part && part.figure !== undefined && owner?.widget.module !== undefined) {
|
|
144
|
+
// Drawn by its extension's page code over its words and value, which stay the page's (D-510): the figure in place of its icon.
|
|
145
|
+
return (_jsxs("div", { class: "widget-lead figured", children: [_jsx(Figure, { owner: owner, name: part.figure, part: part }), _jsx("span", { class: "widget-lead-words", dir: "auto", children: _jsx(Text, { text: part.lead }) }), part.value !== undefined && _jsx(Value, { value: part.value, kind: "widget-lead-value" })] }));
|
|
146
|
+
}
|
|
92
147
|
if ("lead" in part) {
|
|
93
148
|
return (_jsxs("div", { class: "widget-lead", children: [part.icon !== undefined && _jsx(Drawn, { path: part.icon, kind: "widget-lead-icon" }), _jsx("span", { class: "widget-lead-words", dir: "auto", children: _jsx(Text, { text: part.lead }) }), part.value !== undefined && _jsx(Value, { value: part.value, kind: "widget-lead-value" })] }));
|
|
94
149
|
}
|
|
@@ -112,17 +167,82 @@ function Part({ part }) {
|
|
|
112
167
|
}
|
|
113
168
|
return _jsx("img", { class: "widget-image", src: `/images/ext/${encodeURIComponent(part.image.extension)}/${encodeURIComponent(part.image.file)}?v=${part.image.version}`, alt: textOf(part.alt), loading: "lazy" });
|
|
114
169
|
}
|
|
115
|
-
/**
|
|
116
|
-
|
|
170
|
+
/**
|
|
171
|
+
* A count as marks, or a bar, with its label; a screen reader hears the label once, in the count's name, with its value in words (D-507). Marks are pips, or
|
|
172
|
+
* tall steps of a progress with their count under them; good ones circles, bad ones squares; after those lit, the held, the marked and the coming. In a card
|
|
173
|
+
* of a question, its place there, and what changed since the card's last look, for its marks to move.
|
|
174
|
+
*/
|
|
175
|
+
export function Track({ track, place, change }) {
|
|
176
|
+
// Without a figure, its marks drawn here: a plain count needs nothing of the page around it.
|
|
177
|
+
return track.figure === undefined ? Marks({ track, place, change }) : _jsx(Figured, { track: track, figure: track.figure, place: place, change: change });
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* A count its package draws as a figure (D-510), where its page code runs: the page keeps its name, in words for a screen reader, and its count in figures
|
|
181
|
+
* under it; elsewhere its marks.
|
|
182
|
+
*/
|
|
183
|
+
function Figured({ track, figure, place, change }) {
|
|
184
|
+
const owner = useContext(OwnerContext);
|
|
185
|
+
if (owner?.widget.module === undefined) {
|
|
186
|
+
return _jsx(Marks, { track: track, place: place, change: change });
|
|
187
|
+
}
|
|
188
|
+
const { label, named, kind } = trackWords(track, place);
|
|
189
|
+
return (_jsxs("div", { class: `${kind} figured`, children: [_jsx("span", { class: "track-figure", role: "img", "aria-label": named, children: _jsx(Figure, { owner: owner, name: figure, part: { track } }) }), _jsxs("span", { class: "track-count figure-count", "aria-hidden": "true", children: [_jsx("span", { dir: "auto", children: label }), " ", _jsx("span", { class: "num", children: `${numberText(track.value + (track.held ?? 0))}/${numberText(track.max)}` })] })] }));
|
|
190
|
+
}
|
|
191
|
+
/** A count's words: its label, its name for a screen reader with the marks held, failed and coming, its value in words, and its classes. */
|
|
192
|
+
function trackWords(track, place) {
|
|
117
193
|
const label = textOf(track.label);
|
|
118
194
|
const said = t("{value} of {max}", { value: track.value, max: track.max });
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
195
|
+
const kind = [place === undefined ? "widget-track" : `ask-track track-${place}`, track.tone ?? ""].filter((name) => name !== "").join(" ");
|
|
196
|
+
const more = [
|
|
197
|
+
track.held === undefined || track.held === 0 ? "" : t("held: {count}", { count: track.held }),
|
|
198
|
+
track.marked === undefined || track.marked === 0 ? "" : t("failed: {count}", { count: track.marked }),
|
|
199
|
+
track.coming === undefined || track.coming === 0 ? "" : t("this roll: {count}", { count: track.coming }),
|
|
200
|
+
].filter((part) => part !== "");
|
|
201
|
+
return { label, said, more, named: [`${label}: ${said}`, ...more].join(", "), kind };
|
|
202
|
+
}
|
|
203
|
+
/** A count as marks, or a bar, with its label. */
|
|
204
|
+
function Marks({ track, place, change }) {
|
|
205
|
+
const { label, said, more, named, kind } = trackWords(track, place);
|
|
206
|
+
const steps = track.look === "steps";
|
|
207
|
+
const marks = track.look !== "bar" && track.max <= (steps ? mostSteps : mostPips);
|
|
208
|
+
return (_jsxs("div", { class: kind, children: [_jsx("span", { class: "widget-track-label", dir: "auto", "aria-hidden": "true", children: label }), marks
|
|
209
|
+
? (_jsx("span", { class: ["pips", steps ? "steps" : "", track.tone ?? ""].filter((name) => name !== "").join(" "), role: "img", "aria-label": named, children: Array.from({ length: track.max }, (_, index) => _jsx(Mark, { index: index, track: track, change: change }, index)) }))
|
|
210
|
+
: (_jsxs("span", { class: "bar-line", children: [_jsx("span", { class: "bar", role: "meter", "aria-label": label, "aria-valuemin": 0, "aria-valuemax": track.max, "aria-valuenow": track.value, "aria-valuetext": more.length === 0 ? said : [said, ...more].join(", "), children: _jsx("span", { class: "fill", style: { "--fill": String(track.value / track.max) } }) }), _jsx("span", { class: "num", "aria-hidden": "true", children: `${numberText(track.value)}/${numberText(track.max)}` })] })), marks && steps && _jsx("span", { class: "track-count num", "aria-hidden": "true", children: `${numberText(track.value + (track.held ?? 0))}/${numberText(track.max)}` })] }));
|
|
211
|
+
}
|
|
212
|
+
/** A figure of an extension, given what it drew before once what it draws changes, for it to move from one to the other. */
|
|
213
|
+
export function Figure({ owner, name, part }) {
|
|
214
|
+
const looks = useRef();
|
|
215
|
+
const said = JSON.stringify([part, owner.data]);
|
|
216
|
+
// The data it drew before, once what it draws changes: in a card of a roll that is once the dice land, as the card changes only then.
|
|
217
|
+
if (looks.current?.said !== said) {
|
|
218
|
+
looks.current = { said, data: owner.data, ...(looks.current === undefined ? {} : { before: looks.current.data }) };
|
|
219
|
+
}
|
|
220
|
+
const before = looks.current.before;
|
|
221
|
+
const size = figureSize(owner.widget, name);
|
|
222
|
+
return (_jsx(ExtensionRoot, { widget: owner.widget, loaded: owner.loaded, kind: `ext-figure at-${owner.place}`, size: size, draw: (module) => {
|
|
223
|
+
const Drawing = module.figures?.[name];
|
|
224
|
+
if (Drawing === undefined) {
|
|
225
|
+
throw new Error(`its page module has no figure ${name}`);
|
|
226
|
+
}
|
|
227
|
+
return _jsx(Drawing, { ...pagePropsOf(owner.widget), name: name, data: owner.data, ...(before === undefined ? {} : { before }), part: part, place: owner.place, size: size });
|
|
228
|
+
} }));
|
|
229
|
+
}
|
|
230
|
+
// How many marks a count draws at most, as pips or as steps; past that, a bar.
|
|
231
|
+
const mostPips = 10;
|
|
232
|
+
const mostSteps = 12;
|
|
233
|
+
/** One mark of a count: lit, held, marked or coming, by where it falls after the value; lit or gone out just now, its step in the order they move. */
|
|
234
|
+
function Mark({ index, track, change }) {
|
|
235
|
+
const held = track.value + (track.held ?? 0);
|
|
236
|
+
const marked = held + (track.marked ?? 0);
|
|
237
|
+
const state = index < track.value ? "on" : index < held ? "held" : index < marked ? "marked" : index < marked + (track.coming ?? 0) ? "coming" : "";
|
|
238
|
+
const lit = change?.lit.indexOf(index) ?? -1;
|
|
239
|
+
const out = change?.out.indexOf(index) ?? -1;
|
|
240
|
+
const moves = lit >= 0 ? "lit" : out >= 0 ? "out" : change?.marked.includes(index) === true ? "struck" : "";
|
|
241
|
+
const step = Math.max(lit, out, 0);
|
|
242
|
+
return _jsx("span", { class: ["pip", state, moves].filter((name) => name !== "").join(" "), style: moves === "" ? undefined : { "--step": String(step) } });
|
|
123
243
|
}
|
|
124
244
|
/** Words of an extension, its values written in the page's language, each set apart. */
|
|
125
|
-
function Text({ text }) {
|
|
245
|
+
export function Text({ text }) {
|
|
126
246
|
if (typeof text === "string") {
|
|
127
247
|
return _jsx(_Fragment, { children: text });
|
|
128
248
|
}
|
|
@@ -133,7 +253,7 @@ function Text({ text }) {
|
|
|
133
253
|
return _jsx(_Fragment, { children: pieces });
|
|
134
254
|
}
|
|
135
255
|
/** A value: a number or a range with its unit, as the page's language writes them, set apart; a word as it is. */
|
|
136
|
-
function Value({ value, kind }) {
|
|
256
|
+
export function Value({ value, kind }) {
|
|
137
257
|
return typeof value === "string"
|
|
138
258
|
? _jsx("span", { class: kind, dir: "auto", children: value })
|
|
139
259
|
: _jsx("bdi", { class: kind === undefined ? "num" : `num ${kind}`, dir: pageDirection() === "rtl" ? "ltr" : undefined, children: valueOf(value) });
|
|
@@ -155,6 +275,6 @@ function rangeText(from, to) {
|
|
|
155
275
|
return typeof format.formatRange === "function" ? format.formatRange(from, to) : `${numberText(from)}–${numberText(to)}`;
|
|
156
276
|
}
|
|
157
277
|
/** An extension's icon, drawn as the page strokes its own. */
|
|
158
|
-
function Drawn({ path, kind }) {
|
|
278
|
+
export function Drawn({ path, kind }) {
|
|
159
279
|
return (_jsx("svg", { class: kind, viewBox: "0 0 24 24", "aria-hidden": "true", children: _jsx("path", { d: path }) }));
|
|
160
280
|
}
|
package/dist/dashboard/faces.js
CHANGED
|
@@ -2,13 +2,15 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-ru
|
|
|
2
2
|
import { rareFace } from "./dice/models.js";
|
|
3
3
|
import { DieIcon } from "./icons.js";
|
|
4
4
|
import { signed } from "./labels.js";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/** The dice as chips; with how each turned out, when a package's roll says it, a good one green and a bad one red (D-507). */
|
|
6
|
+
export function DiceFaces({ dice, modifier, className, tones }) {
|
|
7
|
+
const toned = tones !== undefined && tones.length === dice.length;
|
|
8
|
+
return (_jsxs("ol", { class: className === undefined ? "dice-faces" : `dice-faces ${className}`, "aria-hidden": "true", children: [dice.map((die, index) => _jsx(DieChip, { die: die, tone: toned ? tones[index] ?? undefined : undefined }, index)), modifier !== 0 && _jsx("li", { class: "die-modifier", children: signed(modifier) })] }));
|
|
7
9
|
}
|
|
8
|
-
function DieChip({ die }) {
|
|
10
|
+
function DieChip({ die, tone }) {
|
|
9
11
|
const rare = rareFace(die);
|
|
10
12
|
const faces = die.faces !== undefined && die.faces.length > 1 ? die.faces.map((value) => faceText(die.sides, value)).join("+") : faceText(die.sides, die.value);
|
|
11
|
-
return (_jsxs("li", { class: ["die-chip", die.dropped === true ? "dropped" : "", rare === undefined ? "" : `rare-${rare}`].filter((name) => name !== "").join(" "), children: [_jsx(DieIcon, { sides: die.sides }), _jsxs("span", { children: [die.rerolledFrom !== undefined && (_jsxs(_Fragment, { children: [_jsx("s", { children: faceText(die.sides, die.rerolledFrom) }), "\u2192"] })), faces] })] }));
|
|
13
|
+
return (_jsxs("li", { class: ["die-chip", die.dropped === true ? "dropped" : "", rare === undefined ? "" : `rare-${rare}`, tone === undefined ? "" : `tone-${tone}`].filter((name) => name !== "").join(" "), children: [_jsx(DieIcon, { sides: die.sides }), _jsxs("span", { children: [die.rerolledFrom !== undefined && (_jsxs(_Fragment, { children: [_jsx("s", { children: faceText(die.sides, die.rerolledFrom) }), "\u2192"] })), faces] })] }));
|
|
12
14
|
}
|
|
13
15
|
/** A face as a chip shows it: a number, or a dF's −, 0 and +. */
|
|
14
16
|
function faceText(sides, value) {
|
package/dist/dashboard/help.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
2
|
// Help (D-409, D-413): the complete guide, in the page's language, as its markdown file has it (guide/<code>.md): what it is, an index of chips, and each of
|
|
3
|
-
// its parts a card that folds, the first two open. Its anchors are the English guide's, so that a link finds its heading in every language.
|
|
3
|
+
// its parts a card that folds, the first two open. Its anchors are the English guide's, so that a link finds its heading in every language. At its end, how to
|
|
4
|
+
// tell us what went wrong: the page's own words, so that the guide's translations stay as they are.
|
|
4
5
|
import { useEffect, useMemo, useState } from "preact/hooks";
|
|
5
|
-
import { CardHeader } from "./card.js";
|
|
6
|
+
import { CardHead, CardHeader } from "./card.js";
|
|
6
7
|
import { anchorOf, markdownBlocks, plainText } from "./guide-blocks.js";
|
|
7
8
|
import { Blocks, Inline } from "./guide-markdown.js";
|
|
8
9
|
import { Icon, iconPath, isIconName } from "./icons.js";
|
|
@@ -46,7 +47,13 @@ export function Help() {
|
|
|
46
47
|
}
|
|
47
48
|
focused?.focus({ preventScroll: true });
|
|
48
49
|
}, [sought]);
|
|
49
|
-
return (_jsxs("section", { class: "page-stack help", "aria-labelledby": "help-title", children: [_jsx(PageHead, { section: "help", id: "help-title" }), _jsx("div", { class: "help-lead", children: _jsx(Blocks, { blocks: lead, anchors: anchors, go: go }) }), _jsx("nav", { class: "help-index", "aria-label": t("Contents"), children: parts.map((part) => (_jsxs("button", { type: "button", class: "help-chip", onClick: () => go(anchors.get(part.heading) ?? ""), children: [_jsx(Icon, { name: iconOf(part.heading) }), _jsx(Inline, { text: part.heading.text, go: go })] }, part.heading.text))) }), _jsx("div", { class: "help-cards", children: parts.map((part, index) => (_jsxs("details", { id: anchors.get(part.heading), class: "group help-card", open: open.has(index), children: [_jsx(CardHeader, { icon: iconPath(iconOf(part.heading)), title: _jsx("h3", { children: part.heading.text }), preview: plainText(part.blocks.find((block) => block.kind === "paragraph")?.text ?? ""), open: open.has(index), onToggle: (event) => toggle(index, event) }), _jsx("div", { class: "guide", children: _jsx(Blocks, { blocks: part.blocks, anchors: anchors, go: go }) })] }, part.heading.text))) })] }));
|
|
50
|
+
return (_jsxs("section", { class: "page-stack help", "aria-labelledby": "help-title", children: [_jsx(PageHead, { section: "help", id: "help-title" }), _jsx("div", { class: "help-lead", children: _jsx(Blocks, { blocks: lead, anchors: anchors, go: go }) }), _jsx("nav", { class: "help-index", "aria-label": t("Contents"), children: parts.map((part) => (_jsxs("button", { type: "button", class: "help-chip", onClick: () => go(anchors.get(part.heading) ?? ""), children: [_jsx(Icon, { name: iconOf(part.heading) }), _jsx(Inline, { text: part.heading.text, go: go })] }, part.heading.text))) }), _jsx("div", { class: "help-cards", children: parts.map((part, index) => (_jsxs("details", { id: anchors.get(part.heading), class: "group help-card", open: open.has(index), children: [_jsx(CardHeader, { icon: iconPath(iconOf(part.heading)), title: _jsx("h3", { children: part.heading.text }), preview: plainText(part.blocks.find((block) => block.kind === "paragraph")?.text ?? ""), open: open.has(index), onToggle: (event) => toggle(index, event) }), _jsx("div", { class: "guide", children: _jsx(Blocks, { blocks: part.blocks, anchors: anchors, go: go }) })] }, part.heading.text))) }), _jsx(ReportCard, {})] }));
|
|
51
|
+
}
|
|
52
|
+
/** Where the issues of RPG Engine are reported, as its README says. */
|
|
53
|
+
export const issuesLink = "https://github.com/stefanocaronia/rpg-engine/issues";
|
|
54
|
+
/** The invitation to report what went wrong, said to one who may never have seen GitHub: what to write there, and that it is a public page. */
|
|
55
|
+
export function ReportCard() {
|
|
56
|
+
return (_jsxs("section", { class: "card help-report", "aria-labelledby": "help-report-title", children: [_jsx(CardHead, { icon: iconPath("chat"), title: _jsx("h3", { id: "help-report-title", children: t("Tell us") }) }), _jsxs("div", { class: "card-body", children: [_jsx("p", { children: t("Something doesn't work, confuses you or could be better? Tell us what you did, what you expected and what happened: every report helps.") }), _jsx("p", { class: "help-report-note", children: t("GitHub is the site where RPG Engine is made: you write there with a free account, as in a forum, and anyone can read it.") }), _jsxs("a", { class: "about-link", href: issuesLink, target: "_blank", rel: "noreferrer", children: [_jsx(Icon, { name: "github" }), t("Open a report on GitHub")] })] })] }));
|
|
50
57
|
}
|
|
51
58
|
/** The guide in a language, and in English for its anchors; empty until they are read. */
|
|
52
59
|
function useGuide(language) {
|