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.
- 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 +1 -1
- package/dist/commands/ask.js +66 -24
- package/dist/commands/change.js +28 -17
- package/dist/commands/config.d.ts +1 -1
- package/dist/commands/config.js +67 -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 +83 -7
- 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 +39 -10
- package/dist/commands/game-widgets.js +138 -35
- package/dist/commands/game-world.d.ts +17 -0
- package/dist/commands/game-world.js +70 -12
- 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 +8 -0
- package/dist/commands/package.js +81 -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 +1 -1
- 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 +8 -4
- package/dist/commands/view.js +7 -6
- 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 +51 -29
- package/dist/core/context.js +3 -1
- package/dist/core/examples.d.ts +25 -0
- package/dist/core/examples.js +19 -0
- package/dist/{extensions/api.d.ts → core/package-api.d.ts} +134 -32
- package/dist/core/package-declarations.d.ts +102 -0
- package/dist/core/package-declarations.js +81 -0
- package/dist/core/registry.d.ts +2 -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 +54 -0
- package/dist/dashboard/app.js +140 -96
- package/dist/dashboard/ask-card.js +76 -25
- package/dist/dashboard/asked-dice.js +57 -0
- package/dist/dashboard/dice/tray.js +3 -3
- package/dist/dashboard/extension-widgets.js +104 -10
- package/dist/dashboard/i18n/ar.json +25 -29
- package/dist/dashboard/i18n/cs.json +25 -29
- package/dist/dashboard/i18n/da.json +25 -29
- package/dist/dashboard/i18n/de.json +25 -29
- package/dist/dashboard/i18n/el.json +25 -29
- package/dist/dashboard/i18n/es.json +25 -29
- package/dist/dashboard/i18n/fi.json +25 -29
- package/dist/dashboard/i18n/fr.json +25 -29
- package/dist/dashboard/i18n/he.json +25 -29
- package/dist/dashboard/i18n/hi.json +25 -29
- package/dist/dashboard/i18n/hu.json +25 -29
- package/dist/dashboard/i18n/is.json +25 -29
- package/dist/dashboard/i18n/it.json +25 -29
- package/dist/dashboard/i18n/ja.json +25 -29
- package/dist/dashboard/i18n/ko.json +25 -29
- package/dist/dashboard/i18n/nb.json +25 -29
- package/dist/dashboard/i18n/nl.json +25 -29
- package/dist/dashboard/i18n/pl.json +25 -29
- package/dist/dashboard/i18n/pt.json +25 -29
- package/dist/dashboard/i18n/ro.json +25 -29
- package/dist/dashboard/i18n/ru.json +25 -29
- package/dist/dashboard/i18n/sv.json +25 -29
- package/dist/dashboard/i18n/tr.json +25 -29
- package/dist/dashboard/i18n/uk.json +25 -29
- package/dist/dashboard/i18n/zh.json +25 -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 +7 -2
- package/dist/dashboard/package-page.js +50 -0
- package/dist/dashboard/packages.js +172 -23
- 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/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 +592 -825
- 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 +189 -10
- 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 +25 -37
- package/dist/extensions/extension.js +26 -48
- package/dist/extensions/index.d.ts +3 -2
- package/dist/extensions/index.js +4 -1
- package/dist/extensions/packages.d.ts +6 -0
- package/dist/extensions/packages.js +100 -11
- package/dist/index.d.ts +1 -3
- package/dist/mcp-server.js +51 -14
- 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/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/world.d.ts +8 -0
- package/dist/pages/world.js +9 -2
- package/dist/systems/game-system.d.ts +52 -26
- package/dist/systems/game-system.js +141 -42
- 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 +20 -5
- package/dist/testing.js +49 -14
- package/instructions/combat.md +2 -2
- package/instructions/core.md +2 -2
- package/instructions/dashboard.md +2 -2
- package/instructions/mentor-tutorial.md +1 -1
- package/instructions/play.md +3 -3
- package/instructions/setup.md +1 -1
- package/package.json +10 -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 +37 -9
- 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 -407
- package/dist/commands/game-system-code.d.ts +0 -33
- package/dist/commands/game-system-code.js +0 -188
- 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.js → core/package-api.js} +0 -0
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
// The glue between the engine and a game system's code (D-448): the game its hooks may read and change, and where the commands call them. A hook comes after
|
|
2
|
-
// the engine's own writes, each with its line in the log; one that fails, or code that is not loaded, is a line for the master, and the change stands.
|
|
3
|
-
import { readTextSetting } from "../campaign/index.js";
|
|
4
|
-
import { appendLogEntry } from "../core/log.js";
|
|
5
|
-
import { comparableText, valueNamed } from "../core/text.js";
|
|
6
|
-
import { formatCounter, readCounter } from "../counters/index.js";
|
|
7
|
-
import { rollDice } from "../dice/index.js";
|
|
8
|
-
import { withEffect } from "../effects/index.js";
|
|
9
|
-
import { concernsPlayer, isPartyMember, isPlayerCharacter, pagesWithName, writePage } from "../pages/index.js";
|
|
10
|
-
import { effectiveFields, effectsOf } from "./effect-layer.js";
|
|
11
|
-
import { saveEffects } from "./game-effects.js";
|
|
12
|
-
import { behindTheScreen, sealHiddenRoll } from "./game-master-rolls.js";
|
|
13
|
-
import { keepingConditionNote } from "./game-reminders.js";
|
|
14
|
-
import { readOpenScene } from "./game-scene.js";
|
|
15
|
-
import { newDatedLogEntry } from "./game-time.js";
|
|
16
|
-
import { campaignSystem, campaignWorld } from "./game-world.js";
|
|
17
|
-
/** All a system's code said, its problem last. */
|
|
18
|
-
export function allSaid(said) {
|
|
19
|
-
return said.problem === undefined ? said.lines : [...said.lines, said.problem];
|
|
20
|
-
}
|
|
21
|
-
/** After a counter of a page changed, as by change or the hit dice: the system's lines. */
|
|
22
|
-
export function systemCounterChanged(root, context, change) {
|
|
23
|
-
return called(root, context, "this change", (hooks, game) => hooks.counterChanged?.(change, game) ?? []);
|
|
24
|
-
}
|
|
25
|
-
/** As someone's turn starts in a scene: the system's lines. */
|
|
26
|
-
export function systemTurnStarted(root, context, who) {
|
|
27
|
-
return called(root, context, "this turn began", (hooks, game) => hooks.turnStarted?.({ who }, game) ?? []);
|
|
28
|
-
}
|
|
29
|
-
/** After a roll for someone was logged, never a hidden one: the system's lines. */
|
|
30
|
-
export function systemRolled(root, context, roll) {
|
|
31
|
-
return called(root, context, "this roll", (hooks, game) => hooks.rolled?.(roll, game) ?? []);
|
|
32
|
-
}
|
|
33
|
-
/** After an effect was added to a page, never to a copy: the system's lines. */
|
|
34
|
-
export function systemEffectAdded(root, context, added) {
|
|
35
|
-
return called(root, context, "this effect", (hooks, game) => hooks.effectAdded?.(added, game) ?? []);
|
|
36
|
-
}
|
|
37
|
-
/** What the page draws of a question, as a death save, by the system's code; undefined when it says nothing, fails or is not there: ask asks as always. */
|
|
38
|
-
export function systemAsking(root, context, question) {
|
|
39
|
-
const hooks = loadedHooks(campaignSystem(root, context), context);
|
|
40
|
-
try {
|
|
41
|
-
return typeof hooks === "string" || hooks === undefined ? undefined : hooks.asking?.(question, reader(root, context));
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/** A hook called with the game: its lines; when the code is not loaded or fails, apart, a line that says so and what to do, the engine's change made all the same. */
|
|
48
|
-
function called(root, context, after, call) {
|
|
49
|
-
const system = campaignSystem(root, context);
|
|
50
|
-
const hooks = loadedHooks(system, context);
|
|
51
|
-
const byHand = "meanwhile apply its rules yourself, as its pages say";
|
|
52
|
-
if (typeof hooks === "string") {
|
|
53
|
-
return { lines: [], problem: `The system ${system?.name}'s code ${hooks}, so nothing of it followed ${after}; ${byHand}.` };
|
|
54
|
-
}
|
|
55
|
-
if (hooks === undefined) {
|
|
56
|
-
return { lines: [] };
|
|
57
|
-
}
|
|
58
|
-
try {
|
|
59
|
-
const lines = call(hooks, game(root, context));
|
|
60
|
-
return Array.isArray(lines) ? { lines } : { lines: [], problem: `The system ${system?.name} gave no lines after ${after}: its hooks give a list. It is done all the same; ${byHand}.` };
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
const why = (error instanceof Error ? error.message : String(error)).split("\n")[0].replace(/[:.]$/, "");
|
|
64
|
-
return { lines: [], problem: `The system ${system?.name} failed after ${after}: ${why}. It is done all the same; ${byHand}.` };
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/** The hooks of the campaign's system; why not, when it has code that is not loaded or could not load; undefined when it brings none. */
|
|
68
|
-
function loadedHooks(system, context) {
|
|
69
|
-
if (system?.code !== true) {
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
const loaded = context.systemCode?.[system.name];
|
|
73
|
-
if (loaded === undefined) {
|
|
74
|
-
return "is not loaded: start the MCP server again (/mcp in Claude Code), or open a new chat";
|
|
75
|
-
}
|
|
76
|
-
return "problem" in loaded ? `cannot load (${loaded.problem}): install rpg-engine again, or run npm run build in its repository, then start the MCP server again` : loaded.hooks;
|
|
77
|
-
}
|
|
78
|
-
/** The game as a system's code reads it. */
|
|
79
|
-
function reader(root, context) {
|
|
80
|
-
return {
|
|
81
|
-
page: (name) => {
|
|
82
|
-
const world = campaignWorld(root, context);
|
|
83
|
-
const found = pagesWithName(world, name);
|
|
84
|
-
return found.length === 1 ? systemPage(world, found[0]) : undefined;
|
|
85
|
-
},
|
|
86
|
-
setting: (name) => readTextSetting(root, name),
|
|
87
|
-
sameName: (one, other) => comparableText(one) === comparableText(other),
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
/** The game as a system's code reads and changes it: each write with its line in the log, as the engine shows that page to the player. */
|
|
91
|
-
function game(root, context) {
|
|
92
|
-
return {
|
|
93
|
-
...reader(root, context),
|
|
94
|
-
set: (name, values, why) => {
|
|
95
|
-
const world = campaignWorld(root, context);
|
|
96
|
-
const page = uniquePage(world, name);
|
|
97
|
-
if (page !== undefined) {
|
|
98
|
-
setFields(root, context, world, page, values, why);
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
addEffect: (name, effect, why) => addEffect(root, context, name, effect, why),
|
|
102
|
-
endEffect: (name, effect, why) => endEffect(root, context, name, effect, why),
|
|
103
|
-
roll: (notation, by) => {
|
|
104
|
-
const rolled = rollDice(notation, { random: context.random });
|
|
105
|
-
// For anyone outside the party, hidden as the master-rolls setting says (D-287).
|
|
106
|
-
const hidden = behindTheScreen(root, context, by.who);
|
|
107
|
-
const entry = newDatedLogEntry(root, context, "roll", hidden ? "hidden" : "public", { notation: rolled.notation, total: rolled.total, result: rolled.text, why: by.why, who: by.who, physical: false, dice: rolled.dice });
|
|
108
|
-
if (hidden) {
|
|
109
|
-
sealHiddenRoll(entry, rolled.text, context);
|
|
110
|
-
}
|
|
111
|
-
appendLogEntry(root, entry);
|
|
112
|
-
return { total: rolled.total, dice: rolled.dice, text: rolled.text };
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
/** A page as a system's code reads it: in the party or not, the player's or not, its counters with what its effects give, its effects. */
|
|
117
|
-
export function systemPage(world, page) {
|
|
118
|
-
const fields = effectiveFields(world, page);
|
|
119
|
-
return {
|
|
120
|
-
name: page.name,
|
|
121
|
-
party: isPartyMember(page),
|
|
122
|
-
pc: isPlayerCharacter(page),
|
|
123
|
-
counter: (field) => {
|
|
124
|
-
const counter = readCounter(valueNamed(fields, field));
|
|
125
|
-
return counter === undefined ? undefined : { value: counter.value, ...(counter.max === undefined ? {} : { max: counter.max }) };
|
|
126
|
-
},
|
|
127
|
-
has: (effect) => effectsOf(page).some((one) => comparableText(one.name) === comparableText(effect)),
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
/** The page by a name only it has. */
|
|
131
|
-
function uniquePage(world, name) {
|
|
132
|
-
const found = pagesWithName(world, name);
|
|
133
|
-
return found.length === 1 ? found[0] : undefined;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Sets fields on a page, numbers or text, a counter only numbers, keeping its maximum, each with its line in the log, public when the page concerns the player:
|
|
137
|
-
* for a system's code and an extension's (D-505).
|
|
138
|
-
*/
|
|
139
|
-
export function setFields(root, context, world, page, values, why) {
|
|
140
|
-
if (Object.keys(values).length === 0) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
// A counter takes numbers alone: text in it would read as no counter at all.
|
|
144
|
-
const worded = Object.entries(values).find(([field, value]) => typeof value === "string" && valueNamed(world.system?.fields ?? {}, field) === "counter");
|
|
145
|
-
if (worded !== undefined) {
|
|
146
|
-
throw new Error(`${worded[0]} is a counter: give it a number, not ${worded[1]}. Nothing changed.`);
|
|
147
|
-
}
|
|
148
|
-
const before = effectiveFields(world, page);
|
|
149
|
-
const written = Object.fromEntries(Object.entries(values).map(([field, value]) => {
|
|
150
|
-
const own = readCounter(valueNamed(page.fields, field));
|
|
151
|
-
return [field, typeof value !== "number" || own?.max === undefined ? value : formatCounter({ ...own, value })];
|
|
152
|
-
}));
|
|
153
|
-
writePage(world, page.name, undefined, { set: written });
|
|
154
|
-
const visibility = concernsPlayer(world, page) ? "public" : "hidden";
|
|
155
|
-
for (const [field, after] of Object.entries(written)) {
|
|
156
|
-
const was = valueNamed(before, field);
|
|
157
|
-
const counter = readCounter(was);
|
|
158
|
-
const shown = was === undefined ? (typeof after === "number" ? "0" : "none") : counter === undefined ? String(was) : formatCounter(counter);
|
|
159
|
-
// A counter whose maximum the system works out, which the page does not write, reads with it after too.
|
|
160
|
-
const now = typeof after === "number" && counter?.max !== undefined ? formatCounter({ value: after, max: counter.max }) : after;
|
|
161
|
-
appendLogEntry(root, newDatedLogEntry(root, context, "counter-changed", visibility, { page: page.name, field, before: String(shown), after: String(now), why }));
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
/** Adds an effect without end: the engine's notes on what it breaks of what one keeps; undefined when the page has it already. */
|
|
165
|
-
function addEffect(root, context, name, effect, why) {
|
|
166
|
-
const world = campaignWorld(root, context);
|
|
167
|
-
const page = uniquePage(world, name);
|
|
168
|
-
if (page === undefined || effectsOf(page).some((one) => comparableText(one.name) === comparableText(effect))) {
|
|
169
|
-
return undefined;
|
|
170
|
-
}
|
|
171
|
-
const system = campaignSystem(root, context);
|
|
172
|
-
const keeping = keepingConditionNote(world, readOpenScene(root).scene, system, page.name, effect);
|
|
173
|
-
saveEffects(root, context, world, { page, copy: false }, withEffect(effectsOf(page), { name: effect, values: [] }));
|
|
174
|
-
appendLogEntry(root, newDatedLogEntry(root, context, "effect-added", concernsPlayer(world, page) ? "public" : "hidden", { page: page.name, effect, why }));
|
|
175
|
-
return keeping === "" ? [] : [keeping];
|
|
176
|
-
}
|
|
177
|
-
/** Ends an effect; whether the page had it. */
|
|
178
|
-
function endEffect(root, context, name, effect, why) {
|
|
179
|
-
const world = campaignWorld(root, context);
|
|
180
|
-
const page = uniquePage(world, name);
|
|
181
|
-
const effects = page === undefined ? [] : effectsOf(page);
|
|
182
|
-
if (page === undefined || !effects.some((one) => comparableText(one.name) === comparableText(effect))) {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
saveEffects(root, context, world, { page, copy: false }, effects.filter((one) => comparableText(one.name) !== comparableText(effect)));
|
|
186
|
-
appendLogEntry(root, newDatedLogEntry(root, context, "effect-ended", concernsPlayer(world, page) ? "public" : "hidden", { page: page.name, effect, why }));
|
|
187
|
-
return true;
|
|
188
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
|
|
2
|
-
// The death save the master asks of the player (D-460, D-461): a card of its own over the page, which stays until the outcome is told. The character's portrait
|
|
3
|
-
// greyed, a ring that beats and a line of the heart; the successes on one side, the failures on the other, what each face does under the one button. Once the
|
|
4
|
-
// dice land, the outcome in words, the new mark lit, the line and the portrait as it says: back in colour on the highest face, flat and grey at the last failure.
|
|
5
|
-
import { useEffect, useRef } from "preact/hooks";
|
|
6
|
-
import { CheckLabel } from "./asked.js";
|
|
7
|
-
import { HeartLine, Marks, sideLabel, Skull, stableWord } from "./dying.js";
|
|
8
|
-
import { Icon } from "./icons.js";
|
|
9
|
-
import { checkOf, fieldLabel } from "./labels.js";
|
|
10
|
-
import { Token } from "./party.js";
|
|
11
|
-
import { t } from "./text.js";
|
|
12
|
-
import { turnWords } from "./turns.js";
|
|
13
|
-
/** The card of a death save asked of the player, from the question to its outcome, which the player closes once read. */
|
|
14
|
-
export function DeathSaveCard({ asked, save, member, name, roll, outcome, rolling, onRoll, onClose }) {
|
|
15
|
-
const card = useRef(null);
|
|
16
|
-
const check = checkOf(asked.labels[0] ?? "", asked.title);
|
|
17
|
-
const successes = outcome?.successes ?? save.successes.value;
|
|
18
|
-
const failures = outcome?.failures ?? save.failures.value;
|
|
19
|
-
const highest = save.highest === undefined ? undefined : `${save.highest.value} ${fieldLabel(save.highest.field)}`;
|
|
20
|
-
const told = roll === undefined ? (rolling ? "rolling" : "asking") : outcome === undefined ? "told" : `told ${outcome.kind}`;
|
|
21
|
-
const classes = ["dying-card", told].join(" ");
|
|
22
|
-
const words = outcome === undefined ? "" : outcomeWords(outcome, highest, stableWord(member?.dying));
|
|
23
|
-
// Each side named as the panel of the dying names it, by the counters of who rolls.
|
|
24
|
-
const label = (side) => sideLabel({ field: save[side].field, mark: member?.dying?.find((counter) => counter.side === side)?.mark });
|
|
25
|
-
// While it is there, the rolls beside the sheet stay in sight under it, as under the master's question (D-291).
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
const element = card.current;
|
|
28
|
-
if (element === null) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const root = document.documentElement;
|
|
32
|
-
const observer = new ResizeObserver(() => root.style.setProperty("--asked-space", `${element.offsetHeight + 16}px`));
|
|
33
|
-
observer.observe(element);
|
|
34
|
-
return () => {
|
|
35
|
-
observer.disconnect();
|
|
36
|
-
root.style.removeProperty("--asked-space");
|
|
37
|
-
};
|
|
38
|
-
}, []);
|
|
39
|
-
return (_jsxs("section", { ref: card, class: classes, "aria-labelledby": `dying-${asked.id}`, children: [roll !== undefined && (_jsx("button", { type: "button", class: "icon-button dying-close", "aria-label": t("Close"), "data-tip": t("Close"), onClick: onClose, children: _jsx(Icon, { name: "close" }) })), _jsx("p", { class: "eyebrow asked-turn", children: check === undefined ? turnWords(name) : `${turnWords(name)} · ${check.check}` }), _jsx("p", { id: `dying-${asked.id}`, class: "asked-question", role: roll === undefined ? "alert" : undefined, children: asked.question }), _jsxs("div", { class: "dying-life", children: [_jsx(HeartLine, { line: heartLine(outcome?.kind) }), _jsx(Marks, { kind: "successes", label: label("successes"), value: successes, most: save.successes.most, lit: outcome?.kind === "success" || outcome?.kind === "stable" ? 1 : 0 }), _jsx("span", { class: "dying-token", children: member !== undefined && _jsx(Token, { member: member, large: true }) }), _jsx(Marks, { kind: "failures", label: label("failures"), value: failures, most: save.failures.most, lit: outcome?.count ?? 0 })] }), _jsxs("div", { class: "dying-foot", children: [roll === undefined && (_jsx("button", { type: "button", class: rolling ? "dying-roll sent" : "dying-roll", disabled: rolling, "aria-describedby": `dying-stakes-${asked.id}`, onClick: onRoll, children: check === undefined ? asked.labels[0] : _jsx(CheckLabel, { check: check.check, dice: check.dice, name: undefined }) })), _jsx("p", { class: "dying-word", role: "status", children: roll !== undefined && (_jsxs(_Fragment, { children: [_jsxs("span", { "aria-hidden": "true", children: [outcome === undefined ? roll.total : `${roll.total} · `, outcome?.kind === "dead" && _jsx(Skull, {}), words] }), _jsx("span", { class: "visually-hidden", children: outcome === undefined
|
|
40
|
-
? String(roll.total)
|
|
41
|
-
: `${roll.total}: ${words}. ${label("successes")}: ${t("{value} of {max}", { value: successes, max: save.successes.most })}; ${label("failures")}: ${t("{value} of {max}", { value: failures, max: save.failures.most })}.` })] })) }), _jsx("p", { id: `dying-stakes-${asked.id}`, class: "dying-stakes", children: [
|
|
42
|
-
t("{value} or more: a success", { value: save.atLeast }),
|
|
43
|
-
...(save.lowest === undefined ? [] : [save.lowest === 2 ? t("{face}: two failures", { face: 1 }) : t("{face}: {count} failures", { face: 1, count: save.lowest })]),
|
|
44
|
-
...(highest === undefined ? [] : [t("{face}: back up with {value}", { face: save.sides, value: highest })]),
|
|
45
|
-
].join(" · ") })] })] }));
|
|
46
|
-
}
|
|
47
|
-
/** The outcome in the page's words, stable as the system calls it. */
|
|
48
|
-
function outcomeWords(outcome, highest, stable) {
|
|
49
|
-
switch (outcome.kind) {
|
|
50
|
-
case "success":
|
|
51
|
-
return t("Success");
|
|
52
|
-
case "stable":
|
|
53
|
-
return stable;
|
|
54
|
-
case "failure":
|
|
55
|
-
return t("Failure");
|
|
56
|
-
case "failures":
|
|
57
|
-
return outcome.count === 2 ? t("Two failures") : t("{count} failures", { count: outcome.count });
|
|
58
|
-
case "dead":
|
|
59
|
-
return t("Dead");
|
|
60
|
-
case "back":
|
|
61
|
-
return highest === undefined ? t("Back up") : t("Back up with {value}", { value: highest });
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/** The line of the heart for an outcome: faint while it is to roll, a beat at a success, weaker at a failure, strong back on their feet, flat at the last. */
|
|
65
|
-
function heartLine(kind) {
|
|
66
|
-
return kind === undefined ? "faint" : kind === "back" ? "strong" : kind === "dead" ? "flat" : kind === "success" || kind === "stable" ? "beat" : "weak";
|
|
67
|
-
}
|
package/dist/dashboard/dying.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
-
import { statusIcons } from "./icons.js";
|
|
3
|
-
import { fieldLabel, itemLabel } from "./labels.js";
|
|
4
|
-
import { dyingState, stableName } from "./save-outcome.js";
|
|
5
|
-
import { t } from "./text.js";
|
|
6
|
-
/** The panel of the dying, from its counters by their sides: large, or in one line in a row of the turns. */
|
|
7
|
-
export function DeathSaves({ dying, compact = false }) {
|
|
8
|
-
const state = dyingState(dying) ?? "dying";
|
|
9
|
-
const successes = dying.find((counter) => counter.side === "successes");
|
|
10
|
-
const failures = dying.find((counter) => counter.side === "failures");
|
|
11
|
-
return (_jsxs("div", { class: ["death-saves", state, compact ? "compact" : ""].filter((name) => name !== "").join(" "), children: [successes !== undefined && _jsx(Marks, { kind: "successes", label: sideLabel(successes), value: successes.value, most: successes.limit ?? Math.max(successes.value, 1), lit: 0 }), _jsxs("span", { class: "death-middle", children: [_jsx(HeartLine, { line: stateLines[state] }), _jsxs("span", { class: "death-word", children: [state === "dead" && _jsx(Skull, {}), dyingWord(state, dying)] })] }), failures !== undefined && _jsx(Marks, { kind: "failures", label: sideLabel(failures), value: failures.value, most: failures.limit ?? Math.max(failures.value, 1), lit: 0 })] }));
|
|
12
|
-
}
|
|
13
|
-
/** The red skull of the dead, as on their token (D-461), before the word. */
|
|
14
|
-
export function Skull() {
|
|
15
|
-
return (_jsx("svg", { class: "dying-skull", viewBox: "0 0 24 24", "aria-hidden": "true", children: _jsx("path", { d: statusIcons.dead }) }));
|
|
16
|
-
}
|
|
17
|
-
/** Where someone at their dying point stands, in a word: stable as the system calls it, by their counters. */
|
|
18
|
-
export function dyingWord(state, counters) {
|
|
19
|
-
return state === "dead" ? t("Dead") : state === "stable" ? stableWord(counters) : t("Dying");
|
|
20
|
-
}
|
|
21
|
-
/** What the system calls one whose successes are full, in the page's language, as Stable; else the label of the successes. */
|
|
22
|
-
export function stableWord(counters) {
|
|
23
|
-
const name = stableName(counters);
|
|
24
|
-
return name === undefined ? fieldLabel(counters?.find((counter) => counter.side === "successes")?.field ?? "") : itemLabel(name);
|
|
25
|
-
}
|
|
26
|
-
/** The words of a side's marks, the system's short ones, as Successes, else its field's label. */
|
|
27
|
-
export function sideLabel(counter) {
|
|
28
|
-
return counter.mark === undefined ? fieldLabel(counter.field) : itemLabel(counter.mark);
|
|
29
|
-
}
|
|
30
|
-
/** A side's marks, named by the system: successes as circles, failures as squares; the last `lit` of those marked are new, lit as they come. */
|
|
31
|
-
export function Marks({ kind, label, value, most, lit }) {
|
|
32
|
-
return (_jsxs("div", { class: `dying-side dying-${kind}`, children: [_jsx("span", { class: "eyebrow dying-label", "aria-hidden": "true", children: label }), _jsxs("span", { class: "dying-marks", children: [Array.from({ length: most }, (_, index) => (_jsx("span", { class: ["dying-mark", index < value ? "marked" : "", index < value && index >= value - lit ? "new" : ""].filter((name) => name !== "").join(" "), "aria-hidden": "true" }, index))), _jsx("span", { class: "visually-hidden", children: `${label}: ${t("{value} of {max}", { value, max: most })}` })] })] }));
|
|
33
|
-
}
|
|
34
|
-
// The line of the heart, on a strip 420 wide and 60 high: a faint beat while dying, a stronger one at a success, weaker at a failure, flat at the last.
|
|
35
|
-
const heartLines = {
|
|
36
|
-
faint: "M0 30H130l6-6 5 10 4-4H170l5-16 7 28 5-12H260l5-5 4 8 4-3H420",
|
|
37
|
-
beat: "M0 30H120l8-4 6 4H170l6-26 8 50 6-24H240l8-4 6 4H330l6-22 8 42 6-20H420",
|
|
38
|
-
weak: "M0 30H140l6-8 6 14 4-6H300l4-6 4 8H420",
|
|
39
|
-
flat: "M0 30H420",
|
|
40
|
-
strong: "M0 30H120l8-6 6 6H160l8-34 10 60 8-30H250l8-6 6 6H320l8-30 10 54 8-24H420",
|
|
41
|
-
};
|
|
42
|
-
// The line of each state that stays.
|
|
43
|
-
const stateLines = { dying: "faint", stable: "beat", dead: "flat" };
|
|
44
|
-
export function HeartLine({ line }) {
|
|
45
|
-
return (_jsx("svg", { class: "dying-line", viewBox: "0 0 420 60", preserveAspectRatio: "none", "aria-hidden": "true", children: _jsx("path", { d: heartLines[line] }) }));
|
|
46
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The outcome of a death save from what its roll left (DIE-4): back above the dying point, failures added, the last of them dead, or a success, the last of
|
|
3
|
-
* them stable; none when it changed nothing, as when the system's code did not run.
|
|
4
|
-
*/
|
|
5
|
-
export function saveOutcome(save, after) {
|
|
6
|
-
if (after.dead === true) {
|
|
7
|
-
return { kind: "dead", successes: save.successes.value, failures: save.failures.most, count: Math.max(save.failures.most - save.failures.value, 1) };
|
|
8
|
-
}
|
|
9
|
-
if (after.dying === undefined) {
|
|
10
|
-
return { kind: "back", successes: 0, failures: 0, count: 0 };
|
|
11
|
-
}
|
|
12
|
-
const successes = sideValue(after.dying, "successes") ?? save.successes.value;
|
|
13
|
-
const failures = sideValue(after.dying, "failures") ?? save.failures.value;
|
|
14
|
-
if (failures > save.failures.value) {
|
|
15
|
-
const count = failures - save.failures.value;
|
|
16
|
-
return { kind: failures >= save.failures.most ? "dead" : count > 1 ? "failures" : "failure", successes, failures, count };
|
|
17
|
-
}
|
|
18
|
-
if (successes > save.successes.value) {
|
|
19
|
-
return { kind: successes >= save.successes.most ? "stable" : "success", successes, failures, count: 0 };
|
|
20
|
-
}
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
/** What the system calls one whose successes are full, as the 5e's Stable; none when it names nothing. */
|
|
24
|
-
export function stableName(counters) {
|
|
25
|
-
return counters?.find((counter) => counter.side === "successes")?.full;
|
|
26
|
-
}
|
|
27
|
-
/** Of someone's effects, those their marks say beside their state: never the one that names it stable, as the 5e's Stable, said once by the state (playtest 11). */
|
|
28
|
-
export function effectsBesideState(effects, counters) {
|
|
29
|
-
const stable = dyingState(counters) === "stable" ? stableName(counters)?.toLowerCase() : undefined;
|
|
30
|
-
return effects.filter((effect) => effect.name.toLowerCase() !== stable);
|
|
31
|
-
}
|
|
32
|
-
/** The state the panel of the dying says, from its counters by their sides; none when not dying. */
|
|
33
|
-
export function dyingState(counters) {
|
|
34
|
-
if (counters === undefined) {
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
const full = (side) => counters.some((counter) => counter.side === side && counter.limit !== undefined && counter.value >= counter.limit);
|
|
38
|
-
return full("failures") ? "dead" : full("successes") ? "stable" : "dying";
|
|
39
|
-
}
|
|
40
|
-
function sideValue(counters, side) {
|
|
41
|
-
return counters.find((counter) => counter.side === side)?.value;
|
|
42
|
-
}
|
package/dist/dashboard/spend.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
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 (D-492, ASK-14): a card in the frame of the master's question that stays while the player rolls, one
|
|
3
|
-
// die at a time. Who rests and the points the dice give, as a bar that keeps where the rest began; a row for each kind of die with its pips and its button;
|
|
4
|
-
// the dice rolled as chips; the one button that ends it. What a roll changes shows once its dice land.
|
|
5
|
-
import { useEffect, useRef, useState } from "preact/hooks";
|
|
6
|
-
import { DieIcon, Icon } from "./icons.js";
|
|
7
|
-
import { fieldLabel, signed } from "./labels.js";
|
|
8
|
-
import { Token } from "./party.js";
|
|
9
|
-
import { t } from "./text.js";
|
|
10
|
-
// How long the points take to climb to what a die gave.
|
|
11
|
-
const climbTime = 400;
|
|
12
|
-
export function SpendCard({ asked, spend, member, flying, onSpend, onDone }) {
|
|
13
|
-
const card = useRef(null);
|
|
14
|
-
const done = useRef(null);
|
|
15
|
-
// A die asked of the engine, until its roll comes back: its counter, and how many rolls there were then.
|
|
16
|
-
const [sent, setSent] = useState();
|
|
17
|
-
const [leaving, setLeaving] = useState(false);
|
|
18
|
-
const waiting = (sent !== undefined && spend.rolls.length <= sent.rolls) || spend.rolls.some((roll) => roll.id === flying);
|
|
19
|
-
// What the card shows: the dice as they were until the last roll's dice land.
|
|
20
|
-
const steady = useRef(spend);
|
|
21
|
-
if (!waiting) {
|
|
22
|
-
steady.current = spend;
|
|
23
|
-
}
|
|
24
|
-
const shown = steady.current;
|
|
25
|
-
const { gives } = shown;
|
|
26
|
-
const value = useClimb(gives.value);
|
|
27
|
-
const gained = gives.value - gives.from;
|
|
28
|
-
const full = gives.max !== undefined && gives.value >= gives.max;
|
|
29
|
-
const left = shown.dice.some((dice) => dice.value > 0);
|
|
30
|
-
const last = shown.rolls.at(-1);
|
|
31
|
-
const busy = waiting || leaving;
|
|
32
|
-
// While it is there, the rolls beside the sheet stay in sight under it, as under the master's question (D-291).
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
const element = card.current;
|
|
35
|
-
if (element === null) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const root = document.documentElement;
|
|
39
|
-
const observer = new ResizeObserver(() => root.style.setProperty("--asked-space", `${element.offsetHeight + 16}px`));
|
|
40
|
-
observer.observe(element);
|
|
41
|
-
return () => {
|
|
42
|
-
observer.disconnect();
|
|
43
|
-
root.style.removeProperty("--asked-space");
|
|
44
|
-
};
|
|
45
|
-
}, []);
|
|
46
|
-
// The last die spent, the focus that was on a button to roll goes to the one that ends it.
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
if (!left && card.current?.contains(document.activeElement) === true) {
|
|
49
|
-
done.current?.focus();
|
|
50
|
-
}
|
|
51
|
-
}, [left]);
|
|
52
|
-
const spendOne = async (field) => {
|
|
53
|
-
if (busy) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
setSent({ field, rolls: spend.rolls.length });
|
|
57
|
-
if (!await onSpend(field)) {
|
|
58
|
-
setSent(undefined);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const end = async () => {
|
|
62
|
-
if (busy) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
setLeaving(true);
|
|
66
|
-
if (!await onDone(card.current?.contains(document.activeElement) === true)) {
|
|
67
|
-
setLeaving(false);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
return (_jsxs("section", { ref: card, class: leaving ? "asked spend-card leaving" : "asked spend-card", "aria-labelledby": `spend-${asked.id}`, children: [_jsx("img", { class: "asked-robot", src: "/assets/favicon.svg", alt: "" }), _jsxs("div", { class: "asked-body", children: [_jsx("p", { class: "eyebrow asked-turn", children: asked.title }), _jsx("p", { id: `spend-${asked.id}`, class: "asked-question", role: "alert", children: asked.question }), _jsxs("div", { class: "spend-play", children: [_jsxs("div", { class: "spend-life", children: [_jsx("span", { class: "spend-token", children: member !== undefined && _jsx(Token, { member: member }) }), _jsxs("div", { class: "spend-points", children: [_jsxs("span", { class: "spend-points-head", children: [_jsx("span", { class: "eyebrow spend-points-name", children: fieldLabel(gives.field) }), _jsxs("span", { class: "spend-points-number", children: [_jsx("b", { children: value }), gives.max !== undefined && _jsxs("span", { class: "spend-points-max", children: ["/", gives.max] })] }), gained > 0 && _jsxs("span", { class: "spend-gain", children: ["+", gained] }), full && (_jsxs("span", { class: "spend-full", children: [_jsx(Icon, { name: "check" }), t("at the maximum")] }))] }), gives.max !== undefined && gives.max > 0 && (_jsxs("span", { class: "bar spend-bar", role: "meter", "aria-label": fieldLabel(gives.field), "aria-valuemin": 0, "aria-valuemax": gives.max, "aria-valuenow": gives.value, "aria-valuetext": t("{value} of {max}", { value: gives.value, max: gives.max }), children: [_jsx("span", { class: "fill spend-now", style: { "--fill": String(share(gives.value, gives.max)) } }), gives.from > 0 && _jsx("span", { class: "fill spend-before", style: { "--fill": String(share(gives.from, gives.max)) } })] }))] })] }), _jsx("ul", { class: "spend-rows", children: shown.dice.map((dice) => {
|
|
71
|
-
const out = dice.value <= 0;
|
|
72
|
-
const label = fieldLabel(dice.field);
|
|
73
|
-
return (_jsxs("li", { class: out ? "spend-row out" : "spend-row", children: [_jsx("span", { class: "spend-row-name", children: label }), dice.max <= 10
|
|
74
|
-
? (_jsx("span", { class: "pips spend-pips", role: "img", "aria-label": `${label}: ${t("{value} of {max}", { value: dice.value, max: dice.max })}`, children: Array.from({ length: dice.max }, (_, index) => (_jsx("span", { class: ["pip", index < dice.value ? "on" : "", last?.field === dice.field && index === dice.value ? "fresh" : ""].filter((name) => name !== "").join(" ") }, index))) }))
|
|
75
|
-
: _jsx("span", { class: "spend-count", children: t("{value} of {max}", { value: dice.value, max: dice.max }) }), _jsxs("button", { type: "button", class: sent?.field === dice.field && waiting ? "spend-roll sent" : "spend-roll", "aria-disabled": out || busy ? "true" : undefined, onClick: () => !out && void spendOne(dice.field), children: [_jsx(DieIcon, { sides: dice.sides }), _jsx("span", { class: "asked-check-name", children: out ? t("None left") : t("Roll") }), !out && dice.adds !== 0 && _jsx("span", { class: "asked-dice", children: signed(dice.adds) }), _jsx("span", { class: "visually-hidden", children: label })] })] }, dice.field));
|
|
76
|
-
}) })] }), _jsxs("div", { class: "spend-foot", children: [shown.rolls.length === 0
|
|
77
|
-
? _jsx("p", { class: "spend-hint", children: t("One die at a time: stop when you like.") })
|
|
78
|
-
: (_jsx("ol", { class: "spend-chips", "aria-label": t("Dice rolled"), children: shown.rolls.map((roll) => (_jsxs("li", { class: roll.id === last?.id ? "spend-chip fresh" : "spend-chip", children: [_jsxs("span", { class: "die-chip", children: [_jsx(DieIcon, { sides: shown.dice.find((dice) => dice.field === roll.field)?.sides ?? 6 }), roll.face] }), roll.adds !== 0 && _jsx("span", { class: "spend-chip-adds", children: signed(roll.adds) }), _jsxs("span", { class: "spend-chip-total", children: ["= ", roll.total] })] }, roll.id))) })), _jsx("button", { ref: done, type: "button", class: left ? "spend-done" : "spend-done last", "aria-disabled": busy ? "true" : undefined, onClick: () => void end(), children: shown.rolls.length === 0 ? t("I spend none") : t("Done") })] }), _jsx("p", { class: "visually-hidden", role: "status", children: last === undefined ? "" : landedText(shown, last) })] })] }));
|
|
79
|
-
}
|
|
80
|
-
/** "Hit dice d8: 6 +2 = 8. HP: 22 of 27. Left: 1.": a die as it landed, for a screen reader. */
|
|
81
|
-
function landedText(spend, roll) {
|
|
82
|
-
const dice = spend.dice.find((counter) => counter.field === roll.field);
|
|
83
|
-
const points = spend.gives.max === undefined ? String(spend.gives.value) : t("{value} of {max}", { value: spend.gives.value, max: spend.gives.max });
|
|
84
|
-
const rolled = `${roll.face}${roll.adds === 0 ? "" : ` ${signed(roll.adds)}`} = ${roll.total}`;
|
|
85
|
-
return `${fieldLabel(roll.field)}: ${rolled}. ${fieldLabel(spend.gives.field)}: ${points}.${dice === undefined ? "" : ` ${t("Left: {count}", { count: dice.value })}`}`;
|
|
86
|
-
}
|
|
87
|
-
/** A value's share of its maximum, from 0 to 1. */
|
|
88
|
-
function share(value, max) {
|
|
89
|
-
return Math.min(1, Math.max(0, value / max));
|
|
90
|
-
}
|
|
91
|
-
/** A number that climbs to its new value in a moment, at once for a player who asked for less motion. */
|
|
92
|
-
function useClimb(target) {
|
|
93
|
-
const [value, setValue] = useState(target);
|
|
94
|
-
const from = useRef(target);
|
|
95
|
-
useEffect(() => {
|
|
96
|
-
const start = from.current;
|
|
97
|
-
from.current = target;
|
|
98
|
-
if (start === target || window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
99
|
-
setValue(target);
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
const began = performance.now();
|
|
103
|
-
let frame = 0;
|
|
104
|
-
const step = (now) => {
|
|
105
|
-
const part = Math.min(1, (now - began) / climbTime);
|
|
106
|
-
setValue(Math.round(start + (target - start) * part));
|
|
107
|
-
if (part < 1) {
|
|
108
|
-
frame = requestAnimationFrame(step);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
frame = requestAnimationFrame(step);
|
|
112
|
-
return () => cancelAnimationFrame(frame);
|
|
113
|
-
}, [target]);
|
|
114
|
-
return value;
|
|
115
|
-
}
|
|
File without changes
|