V1.21.0: a DM's toolkit: the battle at a glance, subclasses, character state, rolls, XP
Seven steps in one commit, 1.15.0 to 1.21.0. They change the same files and were not saved apart, so they go in together. - The battle at a glance (1.15). A strip across the top of an encounter lists everyone in turn order and stays in view; a click goes to that card. On a wide screen the stat block of whoever is on turn stays beside the cards, and Pin keeps anyone else's there. Saving throws, every skill and passive Perception, Investigation and Insight are on encounter cards and in the character panel, which "Sheet" on a card and a button on the party overview open. For the DM, N is Next Turn and S opens the sheet of whoever is on turn. The party overview shows passive scores and spell save DC. - Subclasses (1.16). Three per class, picked in the level-up checklist at level 2 (cleric, druid, wizard) or 3, shown beside the class everywhere, and changed by the DM from the sheet: the old one's lines come out of Special Abilities and the new one's go in. Characters already at that level keep the path they were on. - Character state (1.17). Inspiration, exhaustion and conditions on the sheet and in the panel, and counters for what a class does a set number of times (Rage, Ki, Channel Divinity...), which the player spends and a rest gives back. A long rest takes a level of exhaustion off. A character's conditions are their own now: they stay from one encounter to the next. - Faster battles (1.18). Up to 20 of a monster added at once, numbered. One button rolls initiative for the monsters and NPCs. A condition can be given a number of rounds and then comes off by itself. Hovering over a condition shows its rule, and damaging someone who is Concentrating shows the save to call for. - Rolls from the sheet (1.19). A number with a dotted underline rolls when clicked, with its bonus: skills, saves, ability checks, attacks, damage, spell dice, and a monster's attack, damage and abilities. The dice roller has advantage and disadvantage. "Call for a roll" rolls one check or save for the whole party. Rolls stay in the browser. - XP and difficulty (1.20). An encounter shows the DM how hard it is, Trivial to Deadly, from the monsters' challenge ratings against the characters in it, and what it is worth in XP; one button shares that out, once. The sheet and the party overview show XP and when a level is due. Levelling up stays the DM's decision. - Subclasses are optional per campaign (1.21). With "Characters choose a subclass" unticked in the campaign's Settings nobody is asked, each class follows its first subclass, and none is named. - Conditions, exhaustion, counters and subclass features are reminders for the table: none of them changes a number on the sheet. - The docs cover all of it, with generated tables of what each subclass adds. - New migrations: a character's subclass; inspiration, exhaustion, conditions and spent counters on a character; the rounds left on a combatant's conditions; the XP awarded for an encounter; the campaign's subclass setting. - All packages at version 1.21.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -216,6 +216,39 @@ export function useSpellSlots(characterId: string) {
|
||||
});
|
||||
}
|
||||
|
||||
// The class counters. Spending is for the character's own player and the DM,
|
||||
// one use at a time or `amount` from a pool; setting how many are spent, and
|
||||
// giving them all back, are the DM's alone.
|
||||
export type ResourceAction = { action: 'use'; key: string; amount?: number } | { action: 'set'; key: string; used: number } | { action: 'restore' };
|
||||
|
||||
export function useResources(characterId: string) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (data: ResourceAction) =>
|
||||
(await apiClient.post<{ character: CharacterDetail }>(`/characters/${characterId}/resources`, data)).data.character,
|
||||
onSuccess: (character) => {
|
||||
invalidateCharacter(qc, characterId);
|
||||
qc.invalidateQueries({ queryKey: ['encounter'] }); // a character combatant shows its counters
|
||||
qc.invalidateQueries({ queryKey: ['campaign', character.campaignId, 'characters'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Inspiration, exhaustion and conditions. The DM sets all three; the
|
||||
// character's own player may spend inspiration (set it to false).
|
||||
export function useCharacterState(characterId: string) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (data: { inspiration?: boolean; exhaustion?: number; conditions?: string[] }) =>
|
||||
(await apiClient.patch<{ character: CharacterDetail }>(`/characters/${characterId}`, data)).data.character,
|
||||
onSuccess: (character) => {
|
||||
invalidateCharacter(qc, characterId);
|
||||
qc.invalidateQueries({ queryKey: ['encounter'] }); // a character combatant shows all of it
|
||||
qc.invalidateQueries({ queryKey: ['campaign', character.campaignId, 'characters'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// What a character's next level brings. DM only.
|
||||
export function useLevelUpPlan(characterId: string, enabled: boolean) {
|
||||
return useQuery({
|
||||
@@ -230,7 +263,7 @@ export function useLevelUpPlan(characterId: string, enabled: boolean) {
|
||||
export function useLevelUp(characterId: string) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (data: { boon?: string; weaponId?: string | null; spellIds?: string[] }) =>
|
||||
mutationFn: async (data: { subclass?: string; boon?: string; weaponId?: string | null; spellIds?: string[] }) =>
|
||||
(await apiClient.post<{ character: CharacterDetail }>(`/characters/${characterId}/level-up`, data)).data.character,
|
||||
onSuccess: (character) => {
|
||||
invalidateCharacter(qc, characterId);
|
||||
@@ -807,7 +840,7 @@ function keepEncounter(qc: QueryClient, encounterId: string, data: unknown) {
|
||||
export function useAddParticipant(encounterId: string) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (data: { characterId?: string; monsterId?: string; npcId?: string; displayName?: string; initiativeRoll?: number }) =>
|
||||
mutationFn: async (data: { characterId?: string; monsterId?: string; npcId?: string; displayName?: string; initiativeRoll?: number; count?: number }) =>
|
||||
(await apiClient.post(`/encounters/${encounterId}/participants`, data)).data,
|
||||
onSuccess: (data) => keepEncounter(qc, encounterId, data),
|
||||
});
|
||||
@@ -831,6 +864,15 @@ export function useRemoveParticipant(encounterId: string) {
|
||||
});
|
||||
}
|
||||
|
||||
// Rolls a d20 for every monster and NPC that has no initiative roll yet. DM only.
|
||||
export function useRollInitiative(encounterId: string) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async () => (await apiClient.post<{ rolled: number }>(`/encounters/${encounterId}/roll-initiative`)).data,
|
||||
onSuccess: (data) => keepEncounter(qc, encounterId, data),
|
||||
});
|
||||
}
|
||||
|
||||
export function useAdvanceRound(encounterId: string) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
@@ -921,6 +963,21 @@ export function useDeleteReward(encounterId: string) {
|
||||
|
||||
// Awarding is what actually changes the character: a gold ledger entry, or
|
||||
// the weapon/item added to what they hold.
|
||||
// Hands out the encounter's XP, shared evenly between the characters in it:
|
||||
// what its monsters are worth, or the amount given. Once only. DM only.
|
||||
export function useAwardXp(encounterId: string) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (xp?: number) =>
|
||||
(await apiClient.post<{ xp: number; share: number; awardedTo: string[] }>(`/encounters/${encounterId}/award-xp`, xp ? { xp } : {})).data,
|
||||
onSuccess: (data) => {
|
||||
keepEncounter(qc, encounterId, data);
|
||||
qc.invalidateQueries({ queryKey: ['character'] });
|
||||
qc.invalidateQueries({ queryKey: ['campaign'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useAwardReward(encounterId: string) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
|
||||
@@ -95,6 +95,8 @@ export interface Campaign {
|
||||
showMonsterHp: boolean; // off: players get a health bar for monsters and NPCs, no numbers
|
||||
// Added to each target's AC for every target beyond the first in an area attack; 0 is off.
|
||||
areaAttackAcPenalty: number;
|
||||
// Off: nobody chooses a subclass; each class follows its first one, unnamed.
|
||||
subclassesEnabled: boolean;
|
||||
// How many weapons and items a character can have equipped together, and
|
||||
// how many of those can be weapons. Only equipped gear is used in a fight.
|
||||
maxEquipped: number;
|
||||
@@ -152,7 +154,46 @@ export interface HitDice {
|
||||
remaining: number;
|
||||
}
|
||||
|
||||
export interface CharacterSummary {
|
||||
// A class counter (Rage, Ki, Channel Divinity...): how many uses there are,
|
||||
// how many are spent, and the rest that gives them back.
|
||||
export interface ClassResource {
|
||||
key: string;
|
||||
name: string;
|
||||
max: number;
|
||||
used: number;
|
||||
remaining: number;
|
||||
restoresOn: 'SHORT' | 'LONG';
|
||||
}
|
||||
|
||||
// How a character is doing beyond hit points. Reminders for the table: none
|
||||
// of it changes a number on the sheet.
|
||||
export interface CharacterCondition {
|
||||
inspiration: boolean;
|
||||
exhaustion: number; // 0 to 6
|
||||
conditions: string[];
|
||||
}
|
||||
|
||||
// Where a character's XP puts them: what the next level takes (null at level
|
||||
// 20), and whether they have it. Levelling is still the DM's to do.
|
||||
export interface XpProgress {
|
||||
nextLevelAt: number | null;
|
||||
levelUpDue: boolean;
|
||||
}
|
||||
|
||||
// How hard an encounter is for the characters in it (DM only). `xp` is what
|
||||
// its monsters are worth; `adjustedXp` is that multiplied for their number,
|
||||
// and is what the rating is judged on.
|
||||
export interface EncounterDifficulty {
|
||||
xp: number;
|
||||
adjustedXp: number;
|
||||
multiplier: number;
|
||||
rating: 'TRIVIAL' | 'EASY' | 'MEDIUM' | 'HARD' | 'DEADLY' | null; // null with no party, or nothing rated to fight
|
||||
thresholds: { easy: number; medium: number; hard: number; deadly: number } | null; // the party's; null with no party
|
||||
monsters: number; // how many have a challenge rating
|
||||
unrated: number; // and how many do not, left out of the rest
|
||||
}
|
||||
|
||||
export interface CharacterSummary extends CharacterCondition {
|
||||
id: string;
|
||||
campaignId: string;
|
||||
userId: string | null;
|
||||
@@ -160,8 +201,10 @@ export interface CharacterSummary {
|
||||
name: string;
|
||||
species: Species | null;
|
||||
characterClass: CharacterClass | null;
|
||||
subclassName: string | null;
|
||||
level: number;
|
||||
xp: number;
|
||||
xpProgress: XpProgress;
|
||||
buildStage: BuildStage;
|
||||
currentHp: number;
|
||||
tempHp: number;
|
||||
@@ -173,9 +216,15 @@ export interface CharacterSummary {
|
||||
cash: number | null;
|
||||
maxHp: number | null;
|
||||
armorClass: number | null;
|
||||
// Passive scores and the spell save DC; null until built (the DC also for a non-caster).
|
||||
passives: { perception: number; investigation: number; insight: number } | null;
|
||||
spellSaveDC: number | null;
|
||||
// What the character rolls with; null until built.
|
||||
checks: { abilities: Record<Ability, AbilityDetail>; saves: SaveBonuses; skills: SkillBonuses } | null;
|
||||
// What is left before the next rest; both null until the character is built.
|
||||
spellSlots: SpellSlots | null; // also null for a character with no spell slots
|
||||
hitDice: (HitDice & { conModifier: number }) | null; // each die heals its roll plus this
|
||||
resources: ClassResource[]; // the class counters; empty until built
|
||||
currentLocationId: string | null;
|
||||
currentLocationName: string | null;
|
||||
}
|
||||
@@ -209,6 +258,9 @@ export interface ActiveGear {
|
||||
notes: { source: string; note: string }[];
|
||||
}
|
||||
|
||||
export type SaveBonuses = Record<Ability, { proficient: boolean; bonus: number }>;
|
||||
export type SkillBonuses = Record<string, { ability: Ability; proficient: boolean; expertise: boolean; bonus: number }>;
|
||||
|
||||
export interface CharacterSheet {
|
||||
abilities: Record<Ability, AbilityDetail>;
|
||||
proficiencyBonus: number;
|
||||
@@ -217,11 +269,14 @@ export interface CharacterSheet {
|
||||
speed: number;
|
||||
hp: { max: number };
|
||||
hitDice: HitDice;
|
||||
saves: Record<Ability, { proficient: boolean; bonus: number }>;
|
||||
skills: Record<string, { ability: Ability; proficient: boolean; expertise: boolean; bonus: number }>;
|
||||
saves: SaveBonuses;
|
||||
skills: SkillBonuses;
|
||||
passivePerception: number;
|
||||
passiveInvestigation: number;
|
||||
passiveInsight: number;
|
||||
spellcasting: { ability: Ability; saveDC: number; attackBonus: number } | null;
|
||||
spellSlots: SpellSlots | null; // null for a character with no spell slots
|
||||
resources: ClassResource[]; // the class counters, with how many of each are left
|
||||
gear: ActiveGear;
|
||||
}
|
||||
|
||||
@@ -253,6 +308,8 @@ export interface CharacterWeapon {
|
||||
equipped: boolean;
|
||||
level: number;
|
||||
scaledDamageDice: string; // the dice at this copy's level
|
||||
attackBonus: number; // what this character adds to the d20 with it
|
||||
damageBonus: number; // and to its dice
|
||||
usable: boolean; // false while the character is below this copy's level
|
||||
weapon: Weapon;
|
||||
}
|
||||
@@ -329,7 +386,7 @@ export interface SaveProficiency {
|
||||
proficient: boolean;
|
||||
}
|
||||
|
||||
export interface CharacterDetail {
|
||||
export interface CharacterDetail extends CharacterCondition {
|
||||
id: string;
|
||||
campaignId: string;
|
||||
userId: string | null;
|
||||
@@ -337,8 +394,15 @@ export interface CharacterDetail {
|
||||
name: string;
|
||||
species: Species | null;
|
||||
characterClass: CharacterClass | null;
|
||||
// The path within the class: its key and name, null until one is chosen;
|
||||
// what there is to choose from, and the level the class chooses at.
|
||||
subclass: string | null;
|
||||
subclassName: string | null;
|
||||
subclassLevel: number | null;
|
||||
subclassOptions: { key: string; name: string; summary: string }[];
|
||||
level: number;
|
||||
xp: number;
|
||||
xpProgress: XpProgress;
|
||||
motivation: string | null;
|
||||
halfElfBonusAbility1: Ability | null;
|
||||
halfElfBonusAbility2: Ability | null;
|
||||
@@ -488,6 +552,7 @@ export interface CharacterCombatInfo {
|
||||
level: number;
|
||||
species: Species | null;
|
||||
characterClass: CharacterClass | null;
|
||||
subclassName: string | null;
|
||||
armorClass: number;
|
||||
tempHp: number;
|
||||
deathSaves: DeathSaves;
|
||||
@@ -495,9 +560,16 @@ export interface CharacterCombatInfo {
|
||||
speed: number;
|
||||
initiativeBonus: number;
|
||||
passivePerception: number;
|
||||
passiveInvestigation: number;
|
||||
passiveInsight: number;
|
||||
proficiencyBonus: number;
|
||||
abilities: Record<Ability, AbilityDetail>;
|
||||
saves: Record<Ability, { proficient: boolean; bonus: number }>;
|
||||
saves: SaveBonuses;
|
||||
skills: SkillBonuses;
|
||||
spellSlots: SpellSlots | null;
|
||||
resources: ClassResource[];
|
||||
inspiration: boolean;
|
||||
exhaustion: number;
|
||||
specialAbilities: string | null;
|
||||
gear: ActiveGear;
|
||||
weapons: CombatWeapon[]; // the equipped ones: a weapon has to be in hand to be used
|
||||
@@ -523,6 +595,8 @@ export interface EncounterParticipant {
|
||||
maxHp: number | null;
|
||||
hpPercent?: number | null;
|
||||
conditions: string[];
|
||||
// Rounds left on the conditions that wear off by themselves.
|
||||
conditionRounds: Record<string, number>;
|
||||
isMonster: boolean;
|
||||
kind: 'CHARACTER' | 'MONSTER' | 'NPC';
|
||||
// Out of the fight (a dead character, or a monster or NPC at 0 HP) and so
|
||||
@@ -554,6 +628,8 @@ export interface Encounter {
|
||||
location?: Pick<Location, 'id' | 'name' | 'description'> | null;
|
||||
archivedAt: string | null; // archived encounters only reach the DM's list
|
||||
sortOrder: number; // place in the campaign's own order, lowest first
|
||||
xpAwarded?: number | null; // the XP handed out for it, in all; null until awarded
|
||||
difficulty?: EncounterDifficulty; // DM only
|
||||
createdAt: string;
|
||||
participants?: EncounterParticipant[]; // a player's list leaves out the fallen
|
||||
// The dead characters in the scene. Players do not get their cards, only
|
||||
@@ -681,12 +757,13 @@ export interface QuickStatsSpell {
|
||||
// A character at a glance, with everything it holds. The pack, the spell
|
||||
// list and the purse are only sent to the owning player and the DM
|
||||
// (`restricted` is true for anyone else).
|
||||
export interface QuickStats {
|
||||
export interface QuickStats extends CharacterCondition {
|
||||
id: string;
|
||||
name: string;
|
||||
level: number;
|
||||
species: Species | null;
|
||||
characterClass: CharacterClass | null;
|
||||
subclassName: string | null;
|
||||
currentHp: number;
|
||||
maxHp: number;
|
||||
tempHp: number;
|
||||
@@ -698,8 +775,13 @@ export interface QuickStats {
|
||||
spellcasting: { ability: Ability; saveDC: number; attackBonus: number } | null;
|
||||
spellSlots: SpellSlots | null;
|
||||
hitDice: HitDice;
|
||||
resources: ClassResource[];
|
||||
passivePerception: number;
|
||||
passiveInvestigation: number;
|
||||
passiveInsight: number;
|
||||
abilities: Record<Ability, AbilityDetail>;
|
||||
saves: SaveBonuses;
|
||||
skills: SkillBonuses;
|
||||
specialAbilities: string | null;
|
||||
gear: ActiveGear;
|
||||
weapons: QuickStatsWeapon[];
|
||||
@@ -724,6 +806,12 @@ export interface LevelUpPlan {
|
||||
fromLevel: number;
|
||||
toLevel: number;
|
||||
maxHp: { from: number; to: number };
|
||||
// Set when a subclass has to be picked on the way to this level: the level
|
||||
// the class chooses at, and each option with everything it would write.
|
||||
subclass: { level: number; options: { key: string; name: string; summary: string; features: { name: string; text: string }[] }[] } | null;
|
||||
// In a campaign without subclasses: the one taken without asking at this
|
||||
// level, its features already among `features`. Null otherwise.
|
||||
subclassTaken: string | null;
|
||||
// What the class gains. An upgrade rewrites the line that has its name.
|
||||
features: { name: string; text: string; upgrade: boolean }[];
|
||||
boon: BoonOption[] | null; // null at a level that grants no Boon
|
||||
|
||||
@@ -3,13 +3,17 @@ import { useCampaign, useCampaignCharacters, usePatchCharacterWeapon, usePatchIn
|
||||
import { useAuth } from '../auth/useAuth';
|
||||
import { useLastCampaignId } from '../lib/lastCampaign';
|
||||
import { closeCharacterPanel, openCharacterPanel, useCharacterPanelId } from '../lib/characterPanel';
|
||||
import { CLASS_LABELS, SPECIES_LABELS, fmtMod, formatPurse, spellLevelLabel } from '../lib/format';
|
||||
import { SPECIES_LABELS, classLabel, fmtMod, formatPurse, spellLevelLabel } from '../lib/format';
|
||||
import { effectLabel, effectsSummary } from '../lib/gear';
|
||||
import { speciesIcon } from '../lib/speciesIcons';
|
||||
import { Spinner, ErrorBanner } from './Spinner';
|
||||
import { HpBar } from './HpBar';
|
||||
import { DeathSaves } from './DeathSaves';
|
||||
import { SpellSlotTracker } from './SpellSlots';
|
||||
import { SheetNumbers } from './SheetNumbers';
|
||||
import { CharacterState } from './CharacterState';
|
||||
import { Rollable } from './Rollable';
|
||||
import { withBonus } from '../lib/diceRoller';
|
||||
import { useState } from 'react';
|
||||
import { extractErrorMessage } from '../lib/format';
|
||||
import type { ActiveGear } from '../api/types';
|
||||
@@ -73,7 +77,7 @@ function PanelBody({ characterId, isDM }: { characterId: string; isDM: boolean }
|
||||
<span aria-hidden="true">{speciesIcon(data.species)}</span> {data.name}
|
||||
</h3>
|
||||
<div className="combatant-sub">
|
||||
{data.species && SPECIES_LABELS[data.species]} {data.characterClass && CLASS_LABELS[data.characterClass]} · Level {data.level}
|
||||
{data.species && SPECIES_LABELS[data.species]} {classLabel(data.characterClass, data.subclassName)} · Level {data.level}
|
||||
</div>
|
||||
</div>
|
||||
<Link to={`/characters/${data.id}`} className="btn" onClick={closeCharacterPanel}>
|
||||
@@ -113,6 +117,37 @@ function PanelBody({ characterId, isDM }: { characterId: string; isDM: boolean }
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-sm">
|
||||
<CharacterState
|
||||
characterId={characterId}
|
||||
name={data.name}
|
||||
inspiration={data.inspiration}
|
||||
exhaustion={data.exhaustion}
|
||||
conditions={data.conditions}
|
||||
resources={data.resources}
|
||||
canUse={!data.restricted}
|
||||
isDM={isDM}
|
||||
onError={(err) => setEquipError(extractErrorMessage(err))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<details className="card mt-md" open>
|
||||
<summary className="card-title">Saves and skills</summary>
|
||||
<SheetNumbers
|
||||
who={data.name}
|
||||
saves={data.saves}
|
||||
skills={data.skills}
|
||||
passives={{ perception: data.passivePerception, investigation: data.passiveInvestigation, insight: data.passiveInsight }}
|
||||
/>
|
||||
</details>
|
||||
|
||||
{data.specialAbilities && (
|
||||
<details className="card mt-md" open>
|
||||
<summary className="card-title">Special Abilities</summary>
|
||||
<p style={{ margin: 0, whiteSpace: 'pre-wrap' }}>{data.specialAbilities}</p>
|
||||
</details>
|
||||
)}
|
||||
|
||||
{(data.gear.effects.length > 0 || data.gear.notes.length > 0) && (
|
||||
<div className="card mt-md">
|
||||
<div className="card-title">From equipped gear</div>
|
||||
@@ -125,7 +160,10 @@ function PanelBody({ characterId, isDM }: { characterId: string; isDM: boolean }
|
||||
<div className="card mt-md">
|
||||
<div className="card-title">Spellcasting</div>
|
||||
<p style={{ margin: 0 }}>
|
||||
Save DC {data.spellcasting.saveDC} · Attack {fmtMod(data.spellcasting.attackBonus)}
|
||||
Save DC {data.spellcasting.saveDC} ·{' '}
|
||||
<Rollable label={`${data.name}: spell attack`} modifier={data.spellcasting.attackBonus}>
|
||||
Attack {fmtMod(data.spellcasting.attackBonus)}
|
||||
</Rollable>
|
||||
</p>
|
||||
{/* The character's own player and the DM spend slots here; the DM can also give them back. */}
|
||||
{data.spellSlots && (
|
||||
@@ -158,7 +196,15 @@ function PanelBody({ characterId, isDM }: { characterId: string; isDM: boolean }
|
||||
{w.quantity > 1 && <span className="combatant-sub"> ×{w.quantity}</span>}
|
||||
<Flags equipped={w.equipped} usable={w.usable} level={w.level} />
|
||||
<div className="combatant-sub">
|
||||
Lv {w.level} · attack {fmtMod(w.attackBonus)} · {w.damageDice} {fmtMod(w.damageBonus)} {w.damageType}
|
||||
Lv {w.level} ·{' '}
|
||||
<Rollable label={`${data.name}: ${w.name} attack`} modifier={w.attackBonus}>
|
||||
attack {fmtMod(w.attackBonus)}
|
||||
</Rollable>{' '}
|
||||
·{' '}
|
||||
<Rollable label={`${data.name}: ${w.name} damage`} dice={withBonus(w.damageDice, w.damageBonus)}>
|
||||
{w.damageDice} {fmtMod(w.damageBonus)}
|
||||
</Rollable>{' '}
|
||||
{w.damageType}
|
||||
</div>
|
||||
{effectsSummary(w.effects, w.effectNote) && <div className="combatant-sub">✦ {effectsSummary(w.effects, w.effectNote)}</div>}
|
||||
</div>
|
||||
@@ -181,8 +227,8 @@ function PanelBody({ characterId, isDM }: { characterId: string; isDM: boolean }
|
||||
<p className="combatant-sub mt-md">Their pack, spells and purse are their own business.</p>
|
||||
) : (
|
||||
<>
|
||||
<div className="card mt-md">
|
||||
<div className="card-title">Inventory · {data.inventory.length}</div>
|
||||
<details className="card mt-md" open>
|
||||
<summary className="card-title">Inventory · {data.inventory.length}</summary>
|
||||
{data.inventory.length === 0 && <p className="combatant-sub" style={{ margin: 0 }}>Nothing carried.</p>}
|
||||
{data.inventory.map((item) => (
|
||||
<div key={item.inventoryItemId} className="reward-row">
|
||||
@@ -209,7 +255,7 @@ function PanelBody({ characterId, isDM }: { characterId: string; isDM: boolean }
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<div className="card mt-md">
|
||||
<div className="card-title">
|
||||
@@ -219,32 +265,33 @@ function PanelBody({ characterId, isDM }: { characterId: string; isDM: boolean }
|
||||
</div>
|
||||
|
||||
{data.spells.length > 0 && (
|
||||
<div className="card mt-md">
|
||||
<div className="card-title">Spells · {data.spells.length}</div>
|
||||
<details className="card mt-md" open>
|
||||
<summary className="card-title">Spells · {data.spells.length}</summary>
|
||||
{data.spells.map((s) => (
|
||||
<div key={s.characterSpellId} className="reward-row">
|
||||
<strong>{s.name}</strong>
|
||||
<span className="combatant-sub">
|
||||
{' '}
|
||||
{spellLevelLabel(s.level)}
|
||||
{s.damageDice && ` · ${s.damageDice}`}
|
||||
{s.damageDice && (
|
||||
<>
|
||||
{' · '}
|
||||
<Rollable label={`${data.name}: ${s.name}`} dice={s.damageDice}>
|
||||
{s.damageDice}
|
||||
</Rollable>
|
||||
</>
|
||||
)}
|
||||
</span>
|
||||
{s.prepared && <span className="badge badge-live" style={{ marginLeft: 6 }}>prepared</span>}
|
||||
{!s.usable && <span className="badge badge-hostile" style={{ marginLeft: 6 }}>needs level {s.level}</span>}
|
||||
{s.description && <div className="combatant-sub">{s.description}</div>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</details>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{data.specialAbilities && (
|
||||
<div className="card mt-md">
|
||||
<div className="card-title">Special Abilities</div>
|
||||
<p style={{ margin: 0, whiteSpace: 'pre-wrap' }}>{data.specialAbilities}</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -275,7 +322,7 @@ export function CharacterPanel() {
|
||||
<button
|
||||
className="fab-quickstats"
|
||||
onClick={() => openCharacterPanel(fallback.id)}
|
||||
title={isDM ? 'Characters: stats and inventory' : 'Your character: stats and inventory'}
|
||||
title={isDM ? 'Characters: stats, skills and inventory' : 'Your character: stats, skills and inventory'}
|
||||
aria-label="Open the character panel"
|
||||
>
|
||||
🧙
|
||||
|
||||
@@ -0,0 +1,257 @@
|
||||
import { useState } from 'react';
|
||||
import { useCharacterState, useResources } from '../api/queries';
|
||||
import { CONDITIONS, MAX_EXHAUSTION, conditionRule, exhaustionRule } from '../lib/conditions';
|
||||
import { NumberInput } from './NumberInput';
|
||||
import type { ClassResource } from '../api/types';
|
||||
|
||||
// A counter with more uses than this is a pool (Lay on Hands, a high-level
|
||||
// monk's Ki): it gets a number to spend in place of a row of pips.
|
||||
const MOST_PIPS = 10;
|
||||
|
||||
// One condition, with its rule a hover away. `onRemove` adds the ✕.
|
||||
export function ConditionChip({ name, note, onRemove }: { name: string; note?: string; onRemove?: () => void }) {
|
||||
return (
|
||||
<span className="condition-chip" title={conditionRule(name) || undefined}>
|
||||
{name}
|
||||
{note && <span className="condition-note">{note}</span>}
|
||||
{onRemove && (
|
||||
<button aria-label={`Remove ${name}`} onClick={onRemove}>
|
||||
✕
|
||||
</button>
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
// The "+ Condition" menu: every condition not already in force.
|
||||
export function ConditionPicker({ who, current, onAdd }: { who: string; current: string[]; onAdd: (condition: string) => void }) {
|
||||
return (
|
||||
<select aria-label={`Add a condition to ${who}`} value="" onChange={(e) => e.target.value && onAdd(e.target.value)} style={{ width: 'auto' }}>
|
||||
<option value="">+ Condition</option>
|
||||
{CONDITIONS.filter((c) => !current.includes(c)).map((c) => (
|
||||
<option key={c} value={c} title={conditionRule(c)}>
|
||||
{c}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
);
|
||||
}
|
||||
|
||||
// Inspiration and exhaustion as badges, for places that only show them.
|
||||
export function StateBadges({ inspiration, exhaustion }: { inspiration: boolean; exhaustion: number }) {
|
||||
return (
|
||||
<>
|
||||
{inspiration && (
|
||||
<span className="badge badge-live" title="Inspiration: spend it for advantage on one attack, check or save">
|
||||
✨ Inspired
|
||||
</span>
|
||||
)}
|
||||
{exhaustion > 0 && (
|
||||
<span className="badge badge-hostile" title={exhaustionRule(exhaustion)}>
|
||||
Exhaustion {exhaustion}
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// The class counters (Rage, Ki, Channel Divinity...): pips that are filled
|
||||
// while a use is left, and "Use" to spend one. `canUse` is the character's own
|
||||
// player or the DM. Getting a use back is the DM's alone: for them each pip
|
||||
// sets how many are left, and "All back" refills the lot.
|
||||
export function ResourceTracker({
|
||||
characterId,
|
||||
name,
|
||||
resources,
|
||||
canUse,
|
||||
isDM,
|
||||
onError,
|
||||
}: {
|
||||
characterId: string;
|
||||
name: string;
|
||||
resources: ClassResource[];
|
||||
canUse: boolean;
|
||||
isDM: boolean;
|
||||
onError?: (err: unknown) => void;
|
||||
}) {
|
||||
const mutation = useResources(characterId);
|
||||
const send = (action: Parameters<typeof mutation.mutate>[0]) => mutation.mutate(action, { onError });
|
||||
// What is typed into a pool's box, by counter.
|
||||
const [amounts, setAmounts] = useState<Record<string, string>>({});
|
||||
|
||||
if (resources.length === 0) return null;
|
||||
return (
|
||||
<div className="resource-tracker">
|
||||
{isDM && resources.some((r) => r.used > 0) && (
|
||||
<div className="flex-between">
|
||||
<span />
|
||||
<button className="btn btn-ghost" onClick={() => send({ action: 'restore' })} disabled={mutation.isPending} title={`Give ${name} every use back`}>
|
||||
All back
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{resources.map((r) => {
|
||||
const rest = r.restoresOn === 'SHORT' ? 'short or long rest' : 'long rest';
|
||||
const isPool = r.max > MOST_PIPS;
|
||||
const amount = Math.max(1, Math.floor(Number(amounts[r.key])) || 1);
|
||||
return (
|
||||
<div key={r.key} className="slot-row">
|
||||
<span className="resource-name" title={`Back on a ${rest}`}>
|
||||
{r.name}
|
||||
<span className="resource-rest">{r.restoresOn === 'SHORT' ? 'short rest' : 'long rest'}</span>
|
||||
</span>
|
||||
{isPool ? (
|
||||
<span className="slot-pips" />
|
||||
) : (
|
||||
<span className="slot-pips" role="group" aria-label={`${r.remaining} of ${r.max} ${r.name} left`}>
|
||||
{Array.from({ length: r.max }, (_, i) => i + 1).map((n) => {
|
||||
const className = `slot-pip${n <= r.remaining ? ' is-filled' : ''}`;
|
||||
const left = n === r.remaining ? n - 1 : n;
|
||||
return isDM ? (
|
||||
<button
|
||||
key={n}
|
||||
type="button"
|
||||
className={className}
|
||||
aria-label={`Set ${r.name} left to ${left}`}
|
||||
disabled={mutation.isPending}
|
||||
onClick={() => send({ action: 'set', key: r.key, used: r.max - left })}
|
||||
/>
|
||||
) : (
|
||||
<span key={n} className={className} />
|
||||
);
|
||||
})}
|
||||
</span>
|
||||
)}
|
||||
<span className="mono slot-count">
|
||||
{r.remaining}/{r.max}
|
||||
</span>
|
||||
{canUse && isPool && (
|
||||
<NumberInput
|
||||
min={1}
|
||||
max={r.max}
|
||||
placeholder="1"
|
||||
aria-label={`How much ${r.name} to spend`}
|
||||
value={amounts[r.key] ?? ''}
|
||||
onChange={(e) => setAmounts({ ...amounts, [r.key]: e.target.value })}
|
||||
style={{ width: 60 }}
|
||||
/>
|
||||
)}
|
||||
{canUse && (
|
||||
<button
|
||||
className="btn"
|
||||
onClick={() => send({ action: 'use', key: r.key, amount: isPool ? amount : 1 })}
|
||||
disabled={r.remaining === 0 || mutation.isPending}
|
||||
title={r.remaining === 0 ? `None left. Back on a ${rest}` : `Spend ${isPool ? amount : 'one'}. Back on a ${rest}`}
|
||||
aria-label={`Use ${r.name}`}
|
||||
>
|
||||
Use
|
||||
</button>
|
||||
)}
|
||||
{isDM && isPool && (
|
||||
<button
|
||||
className="btn btn-ghost"
|
||||
onClick={() => send({ action: 'set', key: r.key, used: Math.max(0, r.used - amount) })}
|
||||
disabled={r.used === 0 || mutation.isPending}
|
||||
title={`Give ${amount} back`}
|
||||
aria-label={`Give ${r.name} back`}
|
||||
>
|
||||
+ Back
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{canUse && !isDM && <p className="combatant-sub" style={{ margin: '0.3rem 0 0' }}>Once used, a rest or the DM gives it back.</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// How a character is doing beyond hit points: inspiration, exhaustion,
|
||||
// conditions and class counters. The DM gives and takes away all of it. The
|
||||
// character's own player spends inspiration and counters. Everyone else reads.
|
||||
// With `conditions` left out that row is not drawn (an encounter card has its
|
||||
// own).
|
||||
export function CharacterState({
|
||||
characterId,
|
||||
name,
|
||||
inspiration,
|
||||
exhaustion,
|
||||
conditions,
|
||||
resources,
|
||||
canUse,
|
||||
isDM,
|
||||
onError,
|
||||
}: {
|
||||
characterId: string;
|
||||
name: string;
|
||||
inspiration: boolean;
|
||||
exhaustion: number;
|
||||
conditions?: string[];
|
||||
resources: ClassResource[];
|
||||
canUse: boolean;
|
||||
isDM: boolean;
|
||||
onError?: (err: unknown) => void;
|
||||
}) {
|
||||
const state = useCharacterState(characterId);
|
||||
const set = (data: Parameters<typeof state.mutate>[0]) => state.mutate(data, { onError });
|
||||
|
||||
return (
|
||||
<div className="character-state">
|
||||
<div className="flex-row flex-wrap gap-sm">
|
||||
{isDM ? (
|
||||
<button
|
||||
className={`btn btn-target${inspiration ? ' is-lit' : ''}`}
|
||||
aria-pressed={inspiration}
|
||||
disabled={state.isPending}
|
||||
title={inspiration ? `Take ${name}'s inspiration away` : `Give ${name} inspiration: advantage on one attack, check or save of their choice`}
|
||||
onClick={() => set({ inspiration: !inspiration })}
|
||||
>
|
||||
✨ {inspiration ? 'Inspired' : 'Give inspiration'}
|
||||
</button>
|
||||
) : inspiration ? (
|
||||
<>
|
||||
<StateBadges inspiration exhaustion={0} />
|
||||
{canUse && (
|
||||
<button className="btn btn-target" disabled={state.isPending} title="Spend it for advantage on one attack, check or save" onClick={() => set({ inspiration: false })}>
|
||||
Spend
|
||||
</button>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<span className="combatant-sub">No inspiration</span>
|
||||
)}
|
||||
{isDM ? (
|
||||
<label className="flex-row gap-sm" title={exhaustionRule(exhaustion)}>
|
||||
Exhaustion
|
||||
<select
|
||||
value={exhaustion}
|
||||
disabled={state.isPending}
|
||||
onChange={(e) => set({ exhaustion: Number(e.target.value) })}
|
||||
style={{ width: 'auto' }}
|
||||
>
|
||||
{Array.from({ length: MAX_EXHAUSTION + 1 }, (_, level) => (
|
||||
<option key={level} value={level}>
|
||||
{level === 0 ? 'None' : `Level ${level}`}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
) : (
|
||||
<StateBadges inspiration={false} exhaustion={exhaustion} />
|
||||
)}
|
||||
</div>
|
||||
{exhaustion > 0 && <p className="combatant-sub" style={{ margin: '0.3rem 0 0', whiteSpace: 'pre-wrap' }}>{exhaustionRule(exhaustion)}</p>}
|
||||
|
||||
{conditions && (conditions.length > 0 || isDM) && (
|
||||
<div className="flex-row flex-wrap gap-sm mt-sm">
|
||||
{conditions.map((c) => (
|
||||
<ConditionChip key={c} name={c} onRemove={isDM ? () => set({ conditions: conditions.filter((x) => x !== c) }) : undefined} />
|
||||
))}
|
||||
{isDM && <ConditionPicker who={name} current={conditions} onAdd={(c) => set({ conditions: [...conditions, c] })} />}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ResourceTracker characterId={characterId} name={name} resources={resources} canUse={canUse} isDM={isDM} onError={onError} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,43 +1,88 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { fmtMod } from '../lib/format';
|
||||
import { onRollRequest, parseDice, rollD20, rollDie, type RollMode, type RollRequest } from '../lib/diceRoller';
|
||||
|
||||
const DICE = [4, 6, 8, 10, 12, 20, 100];
|
||||
const MAX_DICE = 20;
|
||||
const HISTORY_LENGTH = 8;
|
||||
|
||||
const MODES: { mode: RollMode; label: string; title: string }[] = [
|
||||
{ mode: 'DISADVANTAGE', label: 'Disadv.', title: 'Disadvantage: roll two d20s and keep the lower' },
|
||||
{ mode: 'NORMAL', label: 'Normal', title: 'One d20' },
|
||||
{ mode: 'ADVANTAGE', label: 'Adv.', title: 'Advantage: roll two d20s and keep the higher' },
|
||||
];
|
||||
|
||||
interface Roll {
|
||||
id: number;
|
||||
sides: number;
|
||||
label?: string; // what it was for, when it was asked for from a sheet
|
||||
notation: string; // "1d20+3", "1d8+1d6+2"
|
||||
dice: number[]; // every die rolled, in order
|
||||
modifier: number;
|
||||
dice: number[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
// One fair roll of an n-sided die. Uses the browser's cryptographic random
|
||||
// source, discarding values that would make some faces slightly likelier.
|
||||
function rollDie(sides: number): number {
|
||||
const limit = Math.floor(0x100000000 / sides) * sides;
|
||||
const buffer = new Uint32Array(1);
|
||||
do {
|
||||
crypto.getRandomValues(buffer);
|
||||
} while (buffer[0] >= limit);
|
||||
return (buffer[0] % sides) + 1;
|
||||
// The d20 that counted, for a roll of a single d20 (a natural 20 or 1 means something).
|
||||
natural: number | null;
|
||||
mode: RollMode; // how a single d20 was rolled
|
||||
}
|
||||
|
||||
function notation(count: number, sides: number, modifier: number): string {
|
||||
return `${count}d${sides}${modifier ? fmtMod(modifier) : ''}`;
|
||||
}
|
||||
|
||||
// A table-side dice roller, reachable from every page. These rolls are for
|
||||
// the player's own use at the table: they are not sent to the server and do
|
||||
// not feed the character builder, whose dice stay locked in server-side.
|
||||
// A d20 plus a bonus, with advantage or disadvantage as chosen.
|
||||
function d20Roll(modifier: number, mode: RollMode, label?: string): Omit<Roll, 'id'> {
|
||||
const { kept, dice } = rollD20(mode);
|
||||
return { label, notation: notation(1, 20, modifier), dice, modifier, total: kept + modifier, natural: kept, mode };
|
||||
}
|
||||
|
||||
// What a request from a sheet comes to; null for dice that cannot be read.
|
||||
function answer(request: RollRequest, mode: RollMode): Omit<Roll, 'id'> | null {
|
||||
if (request.kind === 'check') return d20Roll(request.modifier, mode, request.label);
|
||||
const parsed = parseDice(request.expression);
|
||||
if (!parsed) return null;
|
||||
const dice: number[] = [];
|
||||
let total = parsed.flat;
|
||||
for (const term of parsed.dice) {
|
||||
for (let i = 0; i < term.count; i++) {
|
||||
const die = rollDie(term.sides);
|
||||
dice.push(die);
|
||||
total += term.sign * die;
|
||||
}
|
||||
}
|
||||
return { label: request.label, notation: request.expression.replace(/\s+/g, ''), dice, modifier: parsed.flat, total, natural: null, mode: 'NORMAL' };
|
||||
}
|
||||
|
||||
// A table-side dice roller, reachable from every page. It rolls what is set
|
||||
// up here, and whatever is clicked on a sheet or an encounter card (a skill,
|
||||
// a save, an attack, damage: lib/diceRoller.ts), with the bonus already in.
|
||||
// These rolls are for the table: they are not sent to the server and do not
|
||||
// feed the character builder, whose dice stay locked in server-side.
|
||||
export function DiceRoller() {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [sides, setSides] = useState(20);
|
||||
const [count, setCount] = useState(1);
|
||||
const [modifier, setModifier] = useState(0);
|
||||
const [mode, setMode] = useState<RollMode>('NORMAL');
|
||||
const [history, setHistory] = useState<Roll[]>([]);
|
||||
|
||||
const push = (roll: Omit<Roll, 'id'>) => setHistory((prev) => [{ ...roll, id: (prev[0]?.id ?? 0) + 1 }, ...prev].slice(0, HISTORY_LENGTH));
|
||||
|
||||
// A roll asked for from elsewhere on the page: rolled, and shown. It is
|
||||
// rolled the way the roller is set at that moment.
|
||||
const currentMode = useRef(mode);
|
||||
useEffect(() => {
|
||||
currentMode.current = mode;
|
||||
});
|
||||
useEffect(
|
||||
() =>
|
||||
onRollRequest((request) => {
|
||||
const roll = answer(request, currentMode.current);
|
||||
if (!roll) return;
|
||||
push(roll);
|
||||
setOpen(true);
|
||||
}),
|
||||
[]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && setOpen(false);
|
||||
@@ -46,15 +91,16 @@ export function DiceRoller() {
|
||||
}, [open]);
|
||||
|
||||
const latest = history[0];
|
||||
const singleD20 = sides === 20 && count === 1;
|
||||
|
||||
function roll() {
|
||||
if (singleD20) return push(d20Roll(modifier, mode));
|
||||
const dice = Array.from({ length: count }, () => rollDie(sides));
|
||||
const total = dice.reduce((sum, d) => sum + d, 0) + modifier;
|
||||
setHistory((prev) => [{ id: (prev[0]?.id ?? 0) + 1, sides, modifier, dice, total }, ...prev].slice(0, HISTORY_LENGTH));
|
||||
push({ notation: notation(count, sides, modifier), dice, modifier, total: dice.reduce((sum, d) => sum + d, 0) + modifier, natural: null, mode: 'NORMAL' });
|
||||
}
|
||||
|
||||
// The natural 20 and natural 1 only mean something on a single d20.
|
||||
const natural = latest && latest.sides === 20 && latest.dice.length === 1 ? latest.dice[0] : null;
|
||||
const natural = latest?.natural ?? null;
|
||||
const modeNote = (r: Roll) => (r.mode === 'ADVANTAGE' ? 'advantage' : r.mode === 'DISADVANTAGE' ? 'disadvantage' : '');
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -113,29 +159,44 @@ export function DiceRoller() {
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{/* For any single d20: one rolled here, and every check, save and attack clicked on a sheet. */}
|
||||
<div className="dice-choices mt-sm" role="group" aria-label="How a d20 is rolled">
|
||||
{MODES.map((m) => (
|
||||
<button key={m.mode} className={`die-btn${m.mode === mode ? ' is-selected' : ''}`} aria-pressed={m.mode === mode} title={m.title} onClick={() => setMode(m.mode)}>
|
||||
{m.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<button className="btn btn-primary btn-block btn-lg mt-sm" onClick={roll}>
|
||||
🎲 Roll {notation(count, sides, modifier)}
|
||||
{singleD20 && mode !== 'NORMAL' && ` (${modeNote({ mode } as Roll)})`}
|
||||
</button>
|
||||
|
||||
<div className="dice-result" aria-live="polite">
|
||||
{latest ? (
|
||||
<>
|
||||
{latest.label && <div className="dice-label roll-label">{latest.label}</div>}
|
||||
{/* Keyed on the roll so the pop animation replays every time, even on a repeat result. */}
|
||||
<div key={latest.id} className={`roll-result animate${natural === 20 ? ' is-crit' : natural === 1 ? ' is-fumble' : ''}`}>
|
||||
{latest.total}
|
||||
</div>
|
||||
{natural === 20 && <div className="dice-callout">Natural 20!</div>}
|
||||
{natural === 1 && <div className="dice-callout is-fumble">Natural 1</div>}
|
||||
{(latest.dice.length > 1 || latest.modifier !== 0) && (
|
||||
{(latest.dice.length > 1 || latest.modifier !== 0 || latest.label) && (
|
||||
<div className="dice-breakdown mono">
|
||||
{latest.dice.join(' + ')}
|
||||
{latest.natural != null && latest.dice.length > 1
|
||||
? `${latest.dice.join(' / ')} → ${latest.natural} (${modeNote(latest)})`
|
||||
: latest.natural != null
|
||||
? latest.natural
|
||||
: `${latest.notation}: ${latest.dice.join(', ')}`}
|
||||
{latest.modifier !== 0 && ` ${latest.modifier > 0 ? '+' : '−'} ${Math.abs(latest.modifier)}`} = {latest.total}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<p className="subtitle" style={{ margin: 0 }}>
|
||||
Pick a die and roll.
|
||||
Pick a die and roll, or click a skill, save or attack on a sheet.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
@@ -151,7 +212,8 @@ export function DiceRoller() {
|
||||
{history.slice(1).map((r) => (
|
||||
<div key={r.id} className="flex-between dice-history-row">
|
||||
<span>
|
||||
{notation(r.dice.length, r.sides, r.modifier)}
|
||||
{r.label ? `${r.label} · ` : ''}
|
||||
{r.notation}
|
||||
{r.dice.length > 1 && <span className="dice-history-dice"> ({r.dice.join(', ')})</span>}
|
||||
</span>
|
||||
<strong className="mono">{r.total}</strong>
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
import { useState } from 'react';
|
||||
import { Modal } from './Modal';
|
||||
import { NumberInput } from './NumberInput';
|
||||
import { ABILITY_LABELS, SKILL_LABELS, fmtMod } from '../lib/format';
|
||||
import { rollD20, type RollMode } from '../lib/diceRoller';
|
||||
import type { Ability, AbilityDetail, SaveBonuses, SkillBonuses } from '../api/types';
|
||||
|
||||
const ABILITIES: Ability[] = ['STR', 'DEX', 'CON', 'INT', 'WIS', 'CHA'];
|
||||
|
||||
// What the modal needs to know about each character who might roll.
|
||||
export interface Checker {
|
||||
id: string;
|
||||
name: string;
|
||||
abilities: Record<Ability, AbilityDetail>;
|
||||
saves: SaveBonuses;
|
||||
skills: SkillBonuses;
|
||||
}
|
||||
|
||||
interface Result {
|
||||
id: string;
|
||||
name: string;
|
||||
dice: number[];
|
||||
kept: number;
|
||||
bonus: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
// A check is "SKILL:STEALTH", "SAVE:DEX" or "ABILITY:STR".
|
||||
function describe(check: string): string {
|
||||
const [kind, key] = check.split(':');
|
||||
if (kind === 'SKILL') return SKILL_LABELS[key];
|
||||
return `${ABILITY_LABELS[key]} ${kind === 'SAVE' ? 'save' : 'check'}`;
|
||||
}
|
||||
|
||||
function bonusFor(c: Checker, check: string): number {
|
||||
const [kind, key] = check.split(':');
|
||||
if (kind === 'SKILL') return c.skills[key].bonus;
|
||||
if (kind === 'SAVE') return c.saves[key as Ability].bonus;
|
||||
return c.abilities[key as Ability].modifier;
|
||||
}
|
||||
|
||||
// The DM calling for a roll from several characters at once: everyone makes
|
||||
// a Stealth check, or a Dexterity save against a fireball. Pick the roll and
|
||||
// who makes it; each gets their own d20 with their own bonus, and with a DC
|
||||
// the list says who made it. Rolled in the browser, like every table roll.
|
||||
export function GroupCheckModal({ characters, onClose }: { characters: Checker[]; onClose: () => void }) {
|
||||
const [check, setCheck] = useState('SKILL:PERCEPTION');
|
||||
const [dc, setDc] = useState('');
|
||||
const [mode, setMode] = useState<RollMode>('NORMAL');
|
||||
const [left, setLeft] = useState<Set<string>>(new Set()); // who sits this one out
|
||||
const [results, setResults] = useState<{ check: string; dc: number | null; rows: Result[] } | null>(null);
|
||||
|
||||
const rolling = characters.filter((c) => !left.has(c.id));
|
||||
const target = dc === '' ? null : Number(dc);
|
||||
|
||||
function roll() {
|
||||
setResults({
|
||||
check,
|
||||
dc: target,
|
||||
rows: rolling.map((c) => {
|
||||
const { kept, dice } = rollD20(mode);
|
||||
const bonus = bonusFor(c, check);
|
||||
return { id: c.id, name: c.name, dice, kept, bonus, total: kept + bonus };
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
const passed = results && results.dc != null ? results.rows.filter((r) => r.total >= results.dc!).length : 0;
|
||||
|
||||
return (
|
||||
<Modal title="Call for a roll" subtitle="One d20 each, with each character's own bonus" onClose={onClose}>
|
||||
<div className="flex-row flex-wrap gap-sm">
|
||||
<select aria-label="What to roll" value={check} onChange={(e) => setCheck(e.target.value)} style={{ flex: 1, minWidth: 180 }}>
|
||||
<optgroup label="Skills">
|
||||
{Object.keys(SKILL_LABELS).map((skill) => (
|
||||
<option key={skill} value={`SKILL:${skill}`}>
|
||||
{SKILL_LABELS[skill]}
|
||||
</option>
|
||||
))}
|
||||
</optgroup>
|
||||
<optgroup label="Saving throws">
|
||||
{ABILITIES.map((a) => (
|
||||
<option key={a} value={`SAVE:${a}`}>
|
||||
{ABILITY_LABELS[a]} save
|
||||
</option>
|
||||
))}
|
||||
</optgroup>
|
||||
<optgroup label="Ability checks">
|
||||
{ABILITIES.map((a) => (
|
||||
<option key={a} value={`ABILITY:${a}`}>
|
||||
{ABILITY_LABELS[a]} check
|
||||
</option>
|
||||
))}
|
||||
</optgroup>
|
||||
</select>
|
||||
<NumberInput
|
||||
min={1}
|
||||
max={40}
|
||||
placeholder="DC"
|
||||
title="The number to reach. Leave empty to just see the totals."
|
||||
aria-label="Difficulty class"
|
||||
value={dc}
|
||||
onChange={(e) => setDc(e.target.value)}
|
||||
style={{ width: 70 }}
|
||||
/>
|
||||
<select aria-label="How the d20s are rolled" value={mode} onChange={(e) => setMode(e.target.value as RollMode)} style={{ width: 'auto' }}>
|
||||
<option value="NORMAL">Normal</option>
|
||||
<option value="ADVANTAGE">Advantage</option>
|
||||
<option value="DISADVANTAGE">Disadvantage</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="level-spells mt-sm">
|
||||
{characters.map((c) => (
|
||||
<label key={c.id} className="checkbox-row level-choice">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={!left.has(c.id)}
|
||||
onChange={(e) => {
|
||||
const next = new Set(left);
|
||||
if (e.target.checked) next.delete(c.id);
|
||||
else next.add(c.id);
|
||||
setLeft(next);
|
||||
}}
|
||||
/>
|
||||
<span>
|
||||
{c.name} <span className="combatant-sub mono">{fmtMod(bonusFor(c, check))}</span>
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<button className="btn btn-primary btn-block mt-sm" onClick={roll} disabled={rolling.length === 0}>
|
||||
🎲 Roll {describe(check)} for {rolling.length}
|
||||
</button>
|
||||
|
||||
{results && (
|
||||
<div className="mt-md" aria-live="polite">
|
||||
<div className="section-label">
|
||||
{describe(results.check)}
|
||||
{results.dc != null && ` · DC ${results.dc} · ${passed} of ${results.rows.length} made it`}
|
||||
</div>
|
||||
{results.rows.map((r) => {
|
||||
const made = results.dc == null ? null : r.total >= results.dc;
|
||||
return (
|
||||
<div key={r.id} className="detail-row">
|
||||
<span>
|
||||
{r.name}{' '}
|
||||
<span className="combatant-sub mono">
|
||||
{r.dice.length > 1 ? `${r.dice.join(' / ')} → ${r.kept}` : r.kept} {r.bonus >= 0 ? '+' : '−'} {Math.abs(r.bonus)}
|
||||
{r.kept === 20 && ' · natural 20'}
|
||||
{r.kept === 1 && ' · natural 1'}
|
||||
</span>
|
||||
</span>
|
||||
<span>
|
||||
<strong className="mono">{r.total}</strong>
|
||||
{made != null && (
|
||||
<span className={`badge ${made ? 'badge-live' : 'badge-hostile'}`} style={{ marginLeft: 6 }}>
|
||||
{made ? 'made it' : 'failed'}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{results.dc != null && (
|
||||
<p className="combatant-sub" style={{ margin: '0.4rem 0 0' }}>
|
||||
A group check succeeds when at least half make it{passed * 2 >= results.rows.length ? ': this one does.' : ': this one does not.'}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -25,12 +25,13 @@ function allowance(spells: NonNullable<LevelUpPlan['spells']>): string {
|
||||
}
|
||||
|
||||
// The levelling-up checklist for one character, one level at a time: the
|
||||
// level, HP, the class's new special abilities (and a Boon where the level
|
||||
// grants one), new spells and fresh slots, and the free weapon upgrade. The
|
||||
// level, HP, the class's new special abilities (with a subclass or a Boon
|
||||
// where the level calls for one), new spells and fresh slots, and the free weapon upgrade. The
|
||||
// site does every step; the DM makes the choices and says yes.
|
||||
export function LevelUpModal({ character, campaignSpells, onClose }: { character: CharacterDetail; campaignSpells: Spell[]; onClose: () => void }) {
|
||||
const { data: plan, isLoading, error: planError } = useLevelUpPlan(character.id, true);
|
||||
const levelUp = useLevelUp(character.id);
|
||||
const [subclass, setSubclass] = useState('');
|
||||
const [boon, setBoon] = useState('');
|
||||
// undefined until picked: the equipped weapon is offered first.
|
||||
const [weaponChoice, setWeaponChoice] = useState<string | undefined>(undefined);
|
||||
@@ -51,6 +52,8 @@ export function LevelUpModal({ character, campaignSpells, onClose }: { character
|
||||
? campaignSpells.filter((s) => !known.has(s.id) && s.level <= plan.spells!.maxSpellLevel).sort((a, b) => a.level - b.level || a.name.localeCompare(b.name))
|
||||
: [];
|
||||
const pickedBoon = plan.boon?.find((b) => b.key === boon);
|
||||
const pickedSubclass = plan.subclass?.options.find((option) => option.key === subclass);
|
||||
const owed = plan.subclass && !subclass ? 'Choose a subclass first' : plan.boon && !boon ? 'Choose a Boon first' : null;
|
||||
|
||||
function toggleSpell(id: string) {
|
||||
setSpellIds((current) => {
|
||||
@@ -63,7 +66,7 @@ export function LevelUpModal({ character, campaignSpells, onClose }: { character
|
||||
async function handleLevelUp() {
|
||||
setError(null);
|
||||
try {
|
||||
await levelUp.mutateAsync({ boon: plan!.boon ? boon : undefined, weaponId: weaponId || null, spellIds: [...spellIds] });
|
||||
await levelUp.mutateAsync({ subclass: plan!.subclass ? subclass : undefined, boon: plan!.boon ? boon : undefined, weaponId: weaponId || null, spellIds: [...spellIds] });
|
||||
onClose();
|
||||
} catch (err) {
|
||||
setError(extractErrorMessage(err));
|
||||
@@ -87,7 +90,35 @@ export function LevelUpModal({ character, campaignSpells, onClose }: { character
|
||||
</Step>
|
||||
|
||||
<Step n={3} title="Special abilities">
|
||||
{plan.features.length === 0 && !plan.boon && (
|
||||
{plan.subclass && (
|
||||
<div role="radiogroup" aria-label="Subclass" style={{ marginBottom: '0.6rem' }}>
|
||||
<p style={{ margin: '0 0 0.3rem' }}>
|
||||
<strong>Subclass</strong>{' '}
|
||||
<span className="combatant-sub">
|
||||
{plan.subclass.level === plan.toLevel
|
||||
? `chosen at level ${plan.subclass.level}. Choose one:`
|
||||
: `owed since level ${plan.subclass.level}; everything it has given so far is written now. Choose one:`}
|
||||
</span>
|
||||
</p>
|
||||
{plan.subclass.options.map((option) => (
|
||||
<label key={option.key} className="checkbox-row level-choice">
|
||||
<input type="radio" name="subclass" value={option.key} checked={subclass === option.key} onChange={() => setSubclass(option.key)} />
|
||||
<span>
|
||||
<strong>{option.name}</strong>
|
||||
<span className="combatant-sub" style={{ display: 'block' }}>{option.summary}</span>
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
{pickedSubclass?.features.map((feature) => (
|
||||
<div key={feature.name + feature.text} className="reward-row">
|
||||
<strong>{feature.name}</strong>
|
||||
<span className="badge" style={{ marginLeft: 6 }}>{pickedSubclass.name}</span>
|
||||
<div className="combatant-sub">{feature.text}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{plan.features.length === 0 && !plan.boon && !plan.subclass && (
|
||||
<p className="combatant-sub">
|
||||
{plan.beyondTables ? 'The class tables stop at level 10. Add anything new to the special abilities by hand.' : 'No new feature at this level.'}
|
||||
</p>
|
||||
@@ -118,7 +149,7 @@ export function LevelUpModal({ character, campaignSpells, onClose }: { character
|
||||
{pickedBoon?.key === 'HARDY' && <p className="combatant-sub">The Temp HP is given now, and again after every long rest taken with the Rest button.</p>}
|
||||
</div>
|
||||
)}
|
||||
{(plan.features.length > 0 || plan.boon) && (
|
||||
{(plan.features.length > 0 || plan.boon || plan.subclass) && (
|
||||
<p className="combatant-sub">Written into Special Abilities for you. Where a line says "choose", edit it there once the player has.</p>
|
||||
)}
|
||||
</Step>
|
||||
@@ -179,8 +210,8 @@ export function LevelUpModal({ character, campaignSpells, onClose }: { character
|
||||
</Step>
|
||||
|
||||
<div className="modal-foot">
|
||||
<button className="btn btn-primary" onClick={handleLevelUp} disabled={levelUp.isPending || Boolean(plan.boon && !boon)}>
|
||||
{levelUp.isPending ? 'Levelling…' : plan.boon && !boon ? 'Choose a Boon first' : `Level up to ${plan.toLevel}`}
|
||||
<button className="btn btn-primary" onClick={handleLevelUp} disabled={levelUp.isPending || Boolean(owed)}>
|
||||
{levelUp.isPending ? 'Levelling…' : (owed ?? `Level up to ${plan.toLevel}`)}
|
||||
</button>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { leadingDice, rollCheck, rollDice } from '../lib/diceRoller';
|
||||
|
||||
// A number that rolls when clicked: a d20 plus `modifier` (a check, a save,
|
||||
// an attack), or the dice in `dice` (damage). The roll opens in the dice
|
||||
// roller under `label`. Of dice written with more after them ("2d8+3 fire")
|
||||
// the dice are rolled; text that does not start with dice (a DM may type
|
||||
// anything) is shown as it is.
|
||||
export function Rollable({
|
||||
label,
|
||||
modifier,
|
||||
dice,
|
||||
className = '',
|
||||
children,
|
||||
}: {
|
||||
label: string;
|
||||
modifier?: number;
|
||||
dice?: string;
|
||||
className?: string;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const readable = dice === undefined ? null : leadingDice(dice);
|
||||
if (dice !== undefined && !readable) return <span className={className}>{children}</span>;
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className={`rollable ${className}`}
|
||||
title={readable ? `Roll ${readable}: ${label}` : `Roll a d20 for ${label}`}
|
||||
onClick={() => (readable ? rollDice(label, readable) : rollCheck(label, modifier ?? 0))}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { ABILITY_LABELS, SKILL_LABELS, fmtMod } from '../lib/format';
|
||||
import type { Ability, SaveBonuses, SkillBonuses } from '../api/types';
|
||||
import { Rollable } from './Rollable';
|
||||
|
||||
const ABILITIES: Ability[] = ['STR', 'DEX', 'CON', 'INT', 'WIS', 'CHA'];
|
||||
|
||||
// Saving throws, skills and passive scores in one compact block: what the DM
|
||||
// asks for mid-fight. Proficient lines are marked ● and expertise ◆. Used by
|
||||
// the character panel and the encounter screen, so they always agree. A click
|
||||
// on a line rolls it in the dice roller, under `who`'s name.
|
||||
export function SheetNumbers({
|
||||
who,
|
||||
saves,
|
||||
skills,
|
||||
passives,
|
||||
}: {
|
||||
who: string;
|
||||
saves: SaveBonuses;
|
||||
skills: SkillBonuses;
|
||||
passives: { perception: number; investigation: number; insight: number };
|
||||
}) {
|
||||
return (
|
||||
<div className="sheet-numbers">
|
||||
<div className="section-label">Saving throws</div>
|
||||
<div className="number-grid is-saves">
|
||||
{ABILITIES.map((a) => (
|
||||
<Rollable key={a} label={`${who}: ${ABILITY_LABELS[a]} save`} modifier={saves[a].bonus} className={`number-row${saves[a].proficient ? ' is-proficient' : ''}`}>
|
||||
<span>
|
||||
<span className="prof-mark" aria-hidden="true">{saves[a].proficient ? '●' : '○'}</span> {a}
|
||||
</span>
|
||||
<b className="mono">{fmtMod(saves[a].bonus)}</b>
|
||||
</Rollable>
|
||||
))}
|
||||
</div>
|
||||
<div className="section-label">Skills</div>
|
||||
<div className="number-grid">
|
||||
{Object.entries(skills).map(([skill, detail]) => (
|
||||
<Rollable key={skill} label={`${who}: ${SKILL_LABELS[skill]}`} modifier={detail.bonus} className={`number-row${detail.proficient ? ' is-proficient' : ''}`}>
|
||||
<span>
|
||||
<span className="prof-mark" aria-hidden="true">{detail.expertise ? '◆' : detail.proficient ? '●' : '○'}</span> {SKILL_LABELS[skill]}{' '}
|
||||
<span className="number-ability">{detail.ability}</span>
|
||||
</span>
|
||||
<b className="mono">{fmtMod(detail.bonus)}</b>
|
||||
</Rollable>
|
||||
))}
|
||||
</div>
|
||||
<div className="stat-chips mt-sm">
|
||||
<span className="stat-chip">
|
||||
<span>Passive Perception</span>
|
||||
<b>{passives.perception}</b>
|
||||
</span>
|
||||
<span className="stat-chip">
|
||||
<span>Passive Investigation</span>
|
||||
<b>{passives.investigation}</b>
|
||||
</span>
|
||||
<span className="stat-chip">
|
||||
<span>Passive Insight</span>
|
||||
<b>{passives.insight}</b>
|
||||
</span>
|
||||
</div>
|
||||
<p className="combatant-sub" style={{ margin: '0.4rem 0 0' }}>● proficient · ◆ expertise · click a line to roll it</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
// Single-key shortcuts for a page: { n: () => …, s: () => … }. A key does
|
||||
// nothing while the cursor is in a field, while a modifier is held, or when
|
||||
// its entry is undefined (so a page can switch one off by leaving it out).
|
||||
export function useHotkeys(keys: Record<string, (() => void) | undefined>) {
|
||||
const latest = useRef(keys);
|
||||
useEffect(() => {
|
||||
latest.current = keys;
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.ctrlKey || e.metaKey || e.altKey || e.repeat) return;
|
||||
const target = e.target as HTMLElement | null;
|
||||
if (target && (target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName))) return;
|
||||
const action = latest.current[e.key.toLowerCase()];
|
||||
if (!action) return;
|
||||
e.preventDefault();
|
||||
action();
|
||||
};
|
||||
window.addEventListener('keydown', onKey);
|
||||
return () => window.removeEventListener('keydown', onKey);
|
||||
}, []);
|
||||
}
|
||||
@@ -2062,3 +2062,264 @@ button.slot-pip:disabled {
|
||||
background: rgba(95, 138, 79, 0.14);
|
||||
color: var(--success-strong);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
The battle at a glance: the turn strip, the spotlight, saves and skills
|
||||
--------------------------------------------------------------------------- */
|
||||
|
||||
/* Everyone in the scene on one line that stays under the top bar. */
|
||||
.turn-strip {
|
||||
position: sticky;
|
||||
top: 3.6rem;
|
||||
z-index: 25;
|
||||
display: flex;
|
||||
gap: 0.4rem;
|
||||
overflow-x: auto;
|
||||
margin: 0 -0.25rem 1rem;
|
||||
padding: 0.5rem 0.25rem;
|
||||
background: var(--bg);
|
||||
border-bottom: 1px solid var(--border-soft);
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
.turn-chip {
|
||||
flex: 0 0 auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.1rem;
|
||||
min-width: 5.5rem;
|
||||
max-width: 10rem;
|
||||
padding: 0.3rem 0.6rem;
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--bg-inset);
|
||||
color: var(--text-muted);
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
.turn-chip:hover {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
.turn-chip-name {
|
||||
font-family: var(--font-display);
|
||||
font-size: 0.78rem;
|
||||
letter-spacing: 0.03em;
|
||||
color: var(--text);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.turn-chip-sub {
|
||||
font-size: 0.72rem;
|
||||
color: var(--text-dim);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.turn-chip .hp-bar-track {
|
||||
margin: 0;
|
||||
}
|
||||
.turn-chip.is-mine {
|
||||
border-color: var(--arcane-strong);
|
||||
}
|
||||
.turn-chip.is-targeted {
|
||||
border-color: var(--danger-strong);
|
||||
background: var(--danger-soft);
|
||||
}
|
||||
.turn-chip.is-active {
|
||||
border-color: var(--accent-strong);
|
||||
background: var(--accent-soft);
|
||||
box-shadow: 0 0 0 1px var(--accent-strong);
|
||||
}
|
||||
.turn-chip.is-active .turn-chip-name {
|
||||
color: var(--accent-strong);
|
||||
}
|
||||
.turn-chip.has-acted {
|
||||
opacity: 0.55;
|
||||
}
|
||||
/* The attack bar sits under the strip, not behind it. */
|
||||
.attack-bar {
|
||||
top: 7.6rem;
|
||||
}
|
||||
|
||||
/* On a wide screen the side column stays in view, scrolling on its own. */
|
||||
@media (min-width: 960px) {
|
||||
.encounter-side {
|
||||
position: sticky;
|
||||
top: 7.6rem;
|
||||
max-height: calc(100vh - 8.4rem);
|
||||
overflow-y: auto;
|
||||
scrollbar-width: thin;
|
||||
padding-right: 2px;
|
||||
}
|
||||
}
|
||||
.spotlight {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
.link-button {
|
||||
background: none;
|
||||
border: 0;
|
||||
padding: 0;
|
||||
font: inherit;
|
||||
color: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
.link-button:hover {
|
||||
color: var(--accent-strong);
|
||||
}
|
||||
|
||||
.sheet-numbers .section-label {
|
||||
margin: 0.6rem 0 0.25rem;
|
||||
}
|
||||
.number-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
|
||||
column-gap: 1rem;
|
||||
}
|
||||
.number-grid.is-saves {
|
||||
grid-template-columns: repeat(auto-fill, minmax(5rem, 1fr));
|
||||
}
|
||||
.number-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: baseline;
|
||||
gap: 0.4rem;
|
||||
padding: 0.12rem 0;
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-muted);
|
||||
border-bottom: 1px dotted var(--border-soft);
|
||||
}
|
||||
.number-row.is-proficient {
|
||||
color: var(--text);
|
||||
}
|
||||
.number-row.is-proficient b {
|
||||
color: var(--accent-strong);
|
||||
}
|
||||
.prof-mark {
|
||||
color: var(--accent);
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
.number-ability {
|
||||
font-size: 0.62rem;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--text-dim);
|
||||
}
|
||||
|
||||
/* A card that folds away: the title is the switch. */
|
||||
summary.card-title {
|
||||
cursor: pointer;
|
||||
list-style: none;
|
||||
}
|
||||
summary.card-title::-webkit-details-marker {
|
||||
display: none;
|
||||
}
|
||||
summary.card-title::after {
|
||||
content: '▾';
|
||||
color: var(--text-dim);
|
||||
margin-left: auto;
|
||||
}
|
||||
details:not([open]) > summary.card-title {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
details:not([open]) > summary.card-title::after {
|
||||
content: '▸';
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.turn-strip {
|
||||
top: 2.9rem;
|
||||
}
|
||||
.attack-bar {
|
||||
top: 6.6rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* In one column the card on turn is already at the top of the list. */
|
||||
@media (max-width: 959px) {
|
||||
.spotlight,
|
||||
.btn-pin {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
Character state: inspiration, exhaustion, conditions, class counters
|
||||
--------------------------------------------------------------------------- */
|
||||
.btn-target.is-lit {
|
||||
border-color: var(--accent-strong);
|
||||
color: var(--accent-strong);
|
||||
background: var(--accent-soft);
|
||||
}
|
||||
.condition-chip[title] {
|
||||
cursor: help;
|
||||
}
|
||||
.condition-note {
|
||||
opacity: 0.8;
|
||||
font-size: 0.72rem;
|
||||
}
|
||||
.resource-tracker {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
.resource-name {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 7.5rem;
|
||||
max-width: 11rem;
|
||||
line-height: 1.15;
|
||||
}
|
||||
.resource-rest {
|
||||
font-size: 0.62rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--text-dim);
|
||||
}
|
||||
|
||||
.notice-card {
|
||||
border-color: var(--arcane-strong);
|
||||
background: rgba(92, 127, 176, 0.12);
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
Numbers that roll when clicked
|
||||
--------------------------------------------------------------------------- */
|
||||
.rollable {
|
||||
background: none;
|
||||
border: 0;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
font: inherit;
|
||||
color: inherit;
|
||||
text-align: inherit;
|
||||
cursor: pointer;
|
||||
text-decoration: underline dotted var(--border);
|
||||
text-underline-offset: 3px;
|
||||
}
|
||||
.rollable:hover,
|
||||
.rollable:focus-visible {
|
||||
color: var(--accent-strong);
|
||||
text-decoration-color: var(--accent);
|
||||
}
|
||||
/* A whole row or chip that rolls keeps its own shape. */
|
||||
.rollable.number-row {
|
||||
width: 100%;
|
||||
text-decoration: none;
|
||||
border-bottom: 1px dotted var(--border-soft);
|
||||
}
|
||||
.rollable.number-row:hover {
|
||||
background: var(--accent-soft);
|
||||
}
|
||||
.rollable:has(> .stat-chip) {
|
||||
text-decoration: none;
|
||||
display: inline-flex;
|
||||
}
|
||||
.rollable:hover > .stat-chip {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
.rollable.stat-sub {
|
||||
display: block;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
.roll-label {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// The conditions a combatant can be under, each with its rule in a sentence
|
||||
// or two. They are reminders for the table: the site changes no number for
|
||||
// them. "Concentrating" is not a condition in the rules, but it is tracked the
|
||||
// same way.
|
||||
export const CONDITION_RULES: Record<string, string> = {
|
||||
Blinded: 'Cannot see: fails any check that needs sight. Attacks against them have advantage; their own attacks have disadvantage.',
|
||||
Charmed: 'Cannot attack the charmer or target them with anything harmful. The charmer has advantage on social checks with them.',
|
||||
Deafened: 'Cannot hear: fails any check that needs hearing.',
|
||||
Frightened: 'Disadvantage on ability checks and attacks while the source of the fear is in sight, and cannot willingly move closer to it.',
|
||||
Grappled: 'Speed is 0. Ends if the grappler is incapacitated or the two are forced apart.',
|
||||
Incapacitated: 'Cannot take actions or reactions.',
|
||||
Invisible: 'Cannot be seen without magic or a special sense. Attacks against them have disadvantage; their own attacks have advantage.',
|
||||
Paralyzed: 'Incapacitated; cannot move or speak. Fails Strength and Dexterity saves. Attacks against them have advantage, and a hit from within 5 ft is a critical hit.',
|
||||
Petrified: 'Turned to stone: incapacitated, cannot move or speak, unaware. Attacks against them have advantage; fails Strength and Dexterity saves; resists all damage; immune to poison and disease.',
|
||||
Poisoned: 'Disadvantage on attack rolls and ability checks.',
|
||||
Prone: 'Can only crawl, and standing up costs half their speed. Disadvantage on their attacks. Attacks from within 5 ft have advantage against them; from further away, disadvantage.',
|
||||
Restrained: 'Speed is 0. Attacks against them have advantage; their own have disadvantage. Disadvantage on Dexterity saves.',
|
||||
Stunned: 'Incapacitated; cannot move and can barely speak. Fails Strength and Dexterity saves. Attacks against them have advantage.',
|
||||
Unconscious: 'Incapacitated; cannot move or speak, unaware, drops what they hold and falls prone. Fails Strength and Dexterity saves. Attacks against them have advantage, and a hit from within 5 ft is a critical hit.',
|
||||
Concentrating: 'Holding a spell. Taking damage calls for a Constitution save, DC 10 or half the damage if that is higher; a failure ends the spell. So does casting another concentration spell, or being incapacitated.',
|
||||
};
|
||||
|
||||
export const CONDITIONS = Object.keys(CONDITION_RULES);
|
||||
|
||||
// What a condition does; empty for one the DM typed in by another name.
|
||||
export function conditionRule(name: string): string {
|
||||
return CONDITION_RULES[name] ?? '';
|
||||
}
|
||||
|
||||
// Exhaustion has six levels, each adding to the ones before it.
|
||||
export const EXHAUSTION_LEVELS = [
|
||||
'Disadvantage on ability checks.',
|
||||
'Speed halved.',
|
||||
'Disadvantage on attack rolls and saving throws.',
|
||||
'Hit point maximum halved.',
|
||||
'Speed reduced to 0.',
|
||||
'Death.',
|
||||
];
|
||||
export const MAX_EXHAUSTION = EXHAUSTION_LEVELS.length;
|
||||
|
||||
// Everything a level of exhaustion means, one effect per line.
|
||||
export function exhaustionRule(level: number): string {
|
||||
if (level <= 0) return 'Not exhausted.';
|
||||
return EXHAUSTION_LEVELS.slice(0, level)
|
||||
.map((effect, i) => `${i + 1}: ${effect}`)
|
||||
.join('\n');
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
// Rolls asked for from elsewhere on the page: a skill on a sheet, an attack
|
||||
// on an encounter card. Kept outside React, like the character panel's
|
||||
// (lib/characterPanel.ts), so anything can ask without being wired to the
|
||||
// layout. The dice roller picks each request up, rolls it and shows it. The
|
||||
// rolls themselves never leave the browser.
|
||||
|
||||
// A d20 with a bonus (a check, a save, an attack), or a dice expression (damage).
|
||||
export type RollRequest = { id: number; label: string } & ({ kind: 'check'; modifier: number } | { kind: 'dice'; expression: string });
|
||||
|
||||
let nextId = 1;
|
||||
const listeners = new Set<(request: RollRequest) => void>();
|
||||
|
||||
function ask(request: RollRequest) {
|
||||
listeners.forEach((listener) => listener(request));
|
||||
}
|
||||
|
||||
// The dice roller listens here; returns the way to stop listening.
|
||||
export function onRollRequest(listener: (request: RollRequest) => void): () => void {
|
||||
listeners.add(listener);
|
||||
return () => {
|
||||
listeners.delete(listener);
|
||||
};
|
||||
}
|
||||
|
||||
// Rolls a d20 and adds `modifier`, under a label such as "Aria: Stealth".
|
||||
export function rollCheck(label: string, modifier: number) {
|
||||
ask({ id: nextId++, label, kind: 'check', modifier });
|
||||
}
|
||||
|
||||
// Rolls a dice expression such as "1d8+3", under a label such as "Aria: Longsword damage".
|
||||
export function rollDice(label: string, expression: string) {
|
||||
ask({ id: nextId++, label, kind: 'dice', expression });
|
||||
}
|
||||
|
||||
// One fair roll of an n-sided die. Uses the browser's cryptographic random
|
||||
// source, discarding values that would make some faces slightly likelier.
|
||||
export function rollDie(sides: number): number {
|
||||
const limit = Math.floor(0x100000000 / sides) * sides;
|
||||
const buffer = new Uint32Array(1);
|
||||
do {
|
||||
crypto.getRandomValues(buffer);
|
||||
} while (buffer[0] >= limit);
|
||||
return (buffer[0] % sides) + 1;
|
||||
}
|
||||
|
||||
export interface ParsedDice {
|
||||
dice: { count: number; sides: number; sign: 1 | -1 }[];
|
||||
flat: number;
|
||||
}
|
||||
|
||||
// Reads the dice expressions the app writes: "1d8", "2d6", "1d6+1d8",
|
||||
// "2d4+2", "1d8 - 1". Null for anything else (free text is allowed where a
|
||||
// DM types dice), and for something too big to be a real roll.
|
||||
export function parseDice(expression: string): ParsedDice | null {
|
||||
const terms = expression
|
||||
.replace(/\s+/g, '')
|
||||
.replace(/[−–]/g, '-')
|
||||
.toLowerCase()
|
||||
.replace(/-/g, '+-')
|
||||
.split('+')
|
||||
.filter(Boolean);
|
||||
if (terms.length === 0) return null;
|
||||
const parsed: ParsedDice = { dice: [], flat: 0 };
|
||||
for (const term of terms) {
|
||||
const die = /^(-?)(\d*)d(\d+)$/.exec(term);
|
||||
if (die) {
|
||||
const count = Number(die[2]) || 1;
|
||||
const sides = Number(die[3]);
|
||||
if (count > 100 || sides < 2 || sides > 1000) return null;
|
||||
parsed.dice.push({ count, sides, sign: die[1] ? -1 : 1 });
|
||||
} else if (/^-?\d+$/.test(term)) {
|
||||
parsed.flat += Number(term);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return parsed.dice.length > 0 ? parsed : null;
|
||||
}
|
||||
|
||||
// The dice at the start of a line of text that says more: "2d8+3" from
|
||||
// "2d8+3 fire". Null when it does not start with dice.
|
||||
export function leadingDice(text: string): string | null {
|
||||
const match = /^\s*((?:\d*d\d+|\d+)(?:\s*[+\-−–]\s*(?:\d*d\d+|\d+))*)/i.exec(text);
|
||||
return match && parseDice(match[1]) ? match[1].replace(/\s+/g, '') : null;
|
||||
}
|
||||
|
||||
// A dice expression from its parts: "1d8" and +3 make "1d8+3".
|
||||
export function withBonus(dice: string, bonus: number): string {
|
||||
return bonus === 0 ? dice : `${dice}${bonus > 0 ? '+' : '-'}${Math.abs(bonus)}`;
|
||||
}
|
||||
|
||||
export type RollMode = 'NORMAL' | 'ADVANTAGE' | 'DISADVANTAGE';
|
||||
|
||||
// A d20 as the mode has it: one die, or two with the higher or lower kept.
|
||||
export function rollD20(mode: RollMode): { kept: number; dice: number[] } {
|
||||
if (mode === 'NORMAL') {
|
||||
const die = rollDie(20);
|
||||
return { kept: die, dice: [die] };
|
||||
}
|
||||
const dice = [rollDie(20), rollDie(20)];
|
||||
return { kept: mode === 'ADVANTAGE' ? Math.max(...dice) : Math.min(...dice), dice };
|
||||
}
|
||||
@@ -58,6 +58,18 @@ export const ABILITY_LABELS: Record<string, string> = {
|
||||
CHA: 'Charisma',
|
||||
};
|
||||
|
||||
// "37 / 300 XP": what a character has and what the next level takes.
|
||||
export function xpLabel(xp: number, progress: { nextLevelAt: number | null }): string {
|
||||
return progress.nextLevelAt == null ? `${xp.toLocaleString()} XP` : `${xp.toLocaleString()} / ${progress.nextLevelAt.toLocaleString()} XP`;
|
||||
}
|
||||
|
||||
// "Fighter" or, with a subclass chosen, "Fighter (Champion)".
|
||||
export function classLabel(characterClass: string | null, subclassName?: string | null): string {
|
||||
if (!characterClass) return '';
|
||||
const label = CLASS_LABELS[characterClass] ?? characterClass;
|
||||
return subclassName ? `${label} (${subclassName})` : label;
|
||||
}
|
||||
|
||||
export function fmtMod(mod: number): string {
|
||||
return mod >= 0 ? `+${mod}` : `${mod}`;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ function CharacterRow({ character, isDM, onDelete }: { character: CharacterSumma
|
||||
</div>
|
||||
<p style={{ margin: 0, color: 'var(--text-muted)', fontSize: '0.9rem' }}>
|
||||
{character.species ? `${character.species} ` : ''}
|
||||
{character.characterClass || (inProgress ? 'Not yet built' : '')} · Level {character.level}
|
||||
{character.characterClass || (inProgress ? 'Not yet built' : '')}{character.subclassName && ` (${character.subclassName})`} · Level {character.level}
|
||||
{character.currentLocationName && ` · 📍 ${character.currentLocationName}`}
|
||||
</p>
|
||||
</div>
|
||||
@@ -788,6 +788,7 @@ export function CampaignHomePage() {
|
||||
startingSpellCount: Number(fd.get('startingSpellCount')),
|
||||
skipMotivationRoll: fd.get('skipMotivationRoll') === 'on',
|
||||
showMonsterHp: fd.get('showMonsterHp') === 'on',
|
||||
subclassesEnabled: fd.get('subclassesEnabled') === 'on',
|
||||
areaAttackAcPenalty: Number(fd.get('areaAttackAcPenalty')),
|
||||
maxEquipped: Number(fd.get('maxEquipped')),
|
||||
maxEquippedWeapons: Number(fd.get('maxEquippedWeapons')),
|
||||
@@ -816,6 +817,10 @@ export function CampaignHomePage() {
|
||||
<input type="checkbox" name="showMonsterHp" defaultChecked={campaign.showMonsterHp} />
|
||||
Players see the exact hit points of monsters and NPCs in encounters (untick for a health bar only)
|
||||
</label>
|
||||
<label className="checkbox-row mt-sm">
|
||||
<input type="checkbox" name="subclassesEnabled" defaultChecked={campaign.subclassesEnabled} />
|
||||
Characters choose a subclass (untick and every class follows one path, with nothing to choose)
|
||||
</label>
|
||||
<label className="flex-row flex-wrap gap-sm mt-sm">
|
||||
Area attack AC penalty
|
||||
<NumberInput
|
||||
|
||||
@@ -37,6 +37,9 @@ import { useRememberCampaign } from '../lib/lastCampaign';
|
||||
import { HpBar } from '../components/HpBar';
|
||||
import { DeathSaves } from '../components/DeathSaves';
|
||||
import { SpellSlotTracker } from '../components/SpellSlots';
|
||||
import { CharacterState } from '../components/CharacterState';
|
||||
import { Rollable } from '../components/Rollable';
|
||||
import { withBonus } from '../lib/diceRoller';
|
||||
import { LevelUpModal } from '../components/LevelUpModal';
|
||||
import { GearInForce } from '../components/CharacterPanel';
|
||||
import { effectsSummary } from '../lib/gear';
|
||||
@@ -45,7 +48,8 @@ import { Pagination } from '../components/Paginated';
|
||||
import { usePagination } from '../hooks/usePagination';
|
||||
import {
|
||||
ABILITY_LABELS,
|
||||
CLASS_LABELS,
|
||||
classLabel,
|
||||
xpLabel,
|
||||
COINS,
|
||||
COIN_FIELD,
|
||||
COIN_LABELS,
|
||||
@@ -424,8 +428,13 @@ export function CharacterSheetPage() {
|
||||
<span aria-hidden="true">{speciesIcon(character.species)}</span> {character.name}
|
||||
</h1>
|
||||
<p className="subtitle">
|
||||
{character.species && SPECIES_LABELS[character.species]} {character.characterClass && CLASS_LABELS[character.characterClass]} · Level{' '}
|
||||
{character.level}
|
||||
{character.species && SPECIES_LABELS[character.species]} {classLabel(character.characterClass, character.subclassName)} · Level{' '}
|
||||
{character.level} · {xpLabel(character.xp, character.xpProgress)}
|
||||
{character.xpProgress.levelUpDue && (
|
||||
<span className="badge badge-live" style={{ marginLeft: 6 }} title="They have the XP for the next level. Levelling up is the DM's to do.">
|
||||
⬆ Level up due
|
||||
</span>
|
||||
)}
|
||||
{character.motivation && ` · "${character.motivation}"`}
|
||||
{character.currentLocation && ` · 📍 ${character.currentLocation.name}`}
|
||||
</p>
|
||||
@@ -554,6 +563,39 @@ export function CharacterSheetPage() {
|
||||
onBlur={(e) => Number(e.target.value) !== character.level && patchCharacter.mutate({ level: Number(e.target.value) })}
|
||||
/>
|
||||
</label>
|
||||
{character.subclassLevel != null && character.level >= character.subclassLevel && (
|
||||
<label
|
||||
className="flex-row gap-sm"
|
||||
title="The path within the class. Changing it takes the old subclass's lines out of Special Abilities and writes the new one's, up to this level."
|
||||
>
|
||||
Subclass
|
||||
<select
|
||||
value={character.subclass ?? ''}
|
||||
disabled={patchCharacter.isPending}
|
||||
onChange={(e) => patchCharacter.mutate({ subclass: e.target.value || null }, { onError: (err) => setFormError(extractErrorMessage(err)) })}
|
||||
style={{ width: 'auto' }}
|
||||
>
|
||||
<option value="">Not chosen</option>
|
||||
{character.subclassOptions.map((option) => (
|
||||
<option key={option.key} value={option.key} title={option.summary}>
|
||||
{option.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
<label className="flex-row gap-sm" title="Experience points. An encounter's XP is added here when you award it. Enough for the next level marks the level as due; it does not level the character up.">
|
||||
XP
|
||||
<NumberInput
|
||||
key={`xp:${character.xp}`}
|
||||
min={0}
|
||||
max={10000000}
|
||||
keepValue
|
||||
defaultValue={character.xp}
|
||||
style={{ width: 90 }}
|
||||
onBlur={(e) => Number(e.target.value) !== character.xp && patchCharacter.mutate({ xp: Math.max(0, Math.floor(Number(e.target.value)) || 0) })}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
className="btn btn-primary"
|
||||
onClick={() => setLevellingUp(true)}
|
||||
@@ -612,6 +654,21 @@ export function CharacterSheetPage() {
|
||||
|
||||
<JumpNav />
|
||||
|
||||
<div data-jump="Condition" className="card mt-md">
|
||||
<div className="card-title">Condition and counters</div>
|
||||
<CharacterState
|
||||
characterId={characterId}
|
||||
name={character.name}
|
||||
inspiration={character.inspiration}
|
||||
exhaustion={character.exhaustion}
|
||||
conditions={character.conditions}
|
||||
resources={sheet.resources}
|
||||
canUse={canEdit}
|
||||
isDM={isDM}
|
||||
onError={(err) => setFormError(extractErrorMessage(err))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div data-jump="Abilities" className="card mt-md">
|
||||
<div className="card-title">Ability Scores</div>
|
||||
<div className="grid grid-cols-3">
|
||||
@@ -621,7 +678,9 @@ export function CharacterSheetPage() {
|
||||
{ABILITY_LABELS[ability]} <InfoTip term="ABILITY_MODIFIER" />
|
||||
</span>
|
||||
<span className="stat-value">{sheet.abilities[ability].final}</span>
|
||||
<span className="stat-sub">{fmtMod(sheet.abilities[ability].modifier)}</span>
|
||||
<Rollable label={`${character.name}: ${ABILITY_LABELS[ability]} check`} modifier={sheet.abilities[ability].modifier} className="stat-sub">
|
||||
{fmtMod(sheet.abilities[ability].modifier)}
|
||||
</Rollable>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -637,7 +696,9 @@ export function CharacterSheetPage() {
|
||||
<span>
|
||||
{ABILITY_LABELS[ability]} {sheet.saves[ability].proficient && <span className="badge">prof</span>}
|
||||
</span>
|
||||
<span className="mono">{fmtMod(sheet.saves[ability].bonus)}</span>
|
||||
<Rollable label={`${character.name}: ${ABILITY_LABELS[ability]} save`} modifier={sheet.saves[ability].bonus} className="mono">
|
||||
{fmtMod(sheet.saves[ability].bonus)}
|
||||
</Rollable>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -656,7 +717,9 @@ export function CharacterSheetPage() {
|
||||
<span className="badge">prof</span>
|
||||
) : null}
|
||||
</span>
|
||||
<span className="mono">{fmtMod(detail.bonus)}</span>
|
||||
<Rollable label={`${character.name}: ${SKILL_LABELS[skill]}`} modifier={detail.bonus} className="mono">
|
||||
{fmtMod(detail.bonus)}
|
||||
</Rollable>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -670,7 +733,10 @@ export function CharacterSheetPage() {
|
||||
</div>
|
||||
<p style={{ margin: 0 }}>
|
||||
Save DC <strong>{sheet.spellcasting.saveDC}</strong> · Attack Bonus{' '}
|
||||
<strong>{fmtMod(sheet.spellcasting.attackBonus)}</strong> <InfoTip term="SPELL_ATTACK_BONUS" />
|
||||
<Rollable label={`${character.name}: spell attack`} modifier={sheet.spellcasting.attackBonus}>
|
||||
<strong>{fmtMod(sheet.spellcasting.attackBonus)}</strong>
|
||||
</Rollable>{' '}
|
||||
<InfoTip term="SPELL_ATTACK_BONUS" />
|
||||
</p>
|
||||
{sheet.spellSlots ? (
|
||||
<SpellSlotTracker
|
||||
@@ -696,7 +762,15 @@ export function CharacterSheetPage() {
|
||||
<div>
|
||||
<strong>{cw.weapon.name}</strong>
|
||||
<span style={{ color: 'var(--text-muted)', marginLeft: 6 }}>
|
||||
Lv {cw.level} · {cw.scaledDamageDice} {cw.weapon.damageType} · x{cw.quantity}
|
||||
Lv {cw.level} ·{' '}
|
||||
<Rollable label={`${character.name}: ${cw.weapon.name} attack`} modifier={cw.attackBonus}>
|
||||
{fmtMod(cw.attackBonus)} to hit
|
||||
</Rollable>{' '}
|
||||
·{' '}
|
||||
<Rollable label={`${character.name}: ${cw.weapon.name} damage`} dice={withBonus(cw.scaledDamageDice, cw.damageBonus)}>
|
||||
{cw.scaledDamageDice} {fmtMod(cw.damageBonus)}
|
||||
</Rollable>{' '}
|
||||
{cw.weapon.damageType} · x{cw.quantity}
|
||||
</span>
|
||||
{!cw.usable && <RequiresLevel level={cw.level} />}
|
||||
{effectsSummary(cw.weapon.effects, cw.weapon.effectNote) && (
|
||||
@@ -761,7 +835,15 @@ export function CharacterSheetPage() {
|
||||
<strong>{cs.spell.name}</strong>
|
||||
<span style={{ color: 'var(--text-muted)', marginLeft: 6 }}>
|
||||
{spellLevelLabel(cs.spell.level)}
|
||||
{cs.spell.damageDice && ` · ${cs.spell.damageDice} damage`}
|
||||
{cs.spell.damageDice && (
|
||||
<>
|
||||
{' · '}
|
||||
<Rollable label={`${character.name}: ${cs.spell.name}`} dice={cs.spell.damageDice}>
|
||||
{cs.spell.damageDice}
|
||||
</Rollable>{' '}
|
||||
damage
|
||||
</>
|
||||
)}
|
||||
</span>
|
||||
{!cs.usable && <RequiresLevel level={cs.spell.level} />}
|
||||
{cs.spell.description && <div style={{ color: 'var(--text-muted)', fontSize: '0.9rem' }}>{cs.spell.description}</div>}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,11 +7,14 @@ import { Spinner, ErrorBanner } from '../components/Spinner';
|
||||
import { Pagination } from '../components/Paginated';
|
||||
import { usePagination } from '../hooks/usePagination';
|
||||
import { InfoTip } from '../components/InfoTip';
|
||||
import { CLASS_LABELS, SPECIES_LABELS, formatPurse, slotsSummary } from '../lib/format';
|
||||
import { SPECIES_LABELS, classLabel, formatPurse, slotsSummary, xpLabel } from '../lib/format';
|
||||
import { RestModal } from '../components/RestModal';
|
||||
import { HpBar } from '../components/HpBar';
|
||||
import { LifeBadge } from '../components/DeathSaves';
|
||||
import { ConditionChip, StateBadges } from '../components/CharacterState';
|
||||
import { speciesIcon } from '../lib/speciesIcons';
|
||||
import { openCharacterPanel } from '../lib/characterPanel';
|
||||
import { GroupCheckModal } from '../components/GroupCheckModal';
|
||||
|
||||
// A DM's one-screen view of every character's stats at a glance; a player
|
||||
// sees the same table, scoped to their own character(s) plus a read-only
|
||||
@@ -26,11 +29,14 @@ export function PartyOverviewPage() {
|
||||
const { data: characters, isLoading: charsLoading, error: charsError } = useCampaignCharacters(campaignId);
|
||||
const { pageItems, page, pageCount, prevPage, nextPage, setPage } = usePagination(characters, 12);
|
||||
const [resting, setResting] = useState(false);
|
||||
const [checking, setChecking] = useState(false);
|
||||
|
||||
if (campaignLoading || charsLoading) return <Spinner label="Gathering the party…" />;
|
||||
if (campaignError || charsError || !data) return <ErrorBanner message="Could not load the party overview." />;
|
||||
|
||||
const isDM = data.campaign.role === 'DM';
|
||||
// Everyone alive and built, for a roll the DM calls for from the whole party.
|
||||
const checkers = (characters ?? []).flatMap((c) => (c.checks && c.deathSaves.state !== 'DEAD' ? [{ id: c.id, name: c.name, ...c.checks }] : []));
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -40,6 +46,11 @@ export function PartyOverviewPage() {
|
||||
<p className="subtitle">{isDM ? 'Every character in this campaign, at a glance.' : 'Your party.'}</p>
|
||||
</div>
|
||||
<div className="flex-row">
|
||||
{isDM && checkers.length > 0 && (
|
||||
<button className="btn" onClick={() => setChecking(true)} title="Call for a check or a save from the party, and roll it for all of them at once">
|
||||
🎲 Call for a roll…
|
||||
</button>
|
||||
)}
|
||||
{isDM && characters?.some((c) => c.buildStage === 'COMPLETE') && (
|
||||
<button className="btn" onClick={() => setResting(true)} title="A short or long rest for any of the party: Hit Dice, HP and spell slots">
|
||||
🛏 Rest…
|
||||
@@ -68,6 +79,8 @@ export function PartyOverviewPage() {
|
||||
<th>
|
||||
AC <InfoTip term="AC" />
|
||||
</th>
|
||||
<th title="Passive Perception, Investigation and Insight: 10 + the skill's bonus, used without a roll">Passive P / Inv / Ins</th>
|
||||
<th title="What a target rolls against to resist this character's spells">Spell DC</th>
|
||||
<th>
|
||||
Hit Dice <InfoTip term="HIT_DICE_LEFT" />
|
||||
</th>
|
||||
@@ -89,10 +102,38 @@ export function PartyOverviewPage() {
|
||||
<span aria-hidden="true">{speciesIcon(c.species)}</span> {c.name}
|
||||
</Link>
|
||||
{isMine && <span className="badge badge-mine" style={{ marginLeft: 6 }}>★ Yours</span>}
|
||||
{!inProgress && (c.inspiration || c.exhaustion > 0 || c.conditions.length > 0) && (
|
||||
<span className="flex-row flex-wrap gap-sm" style={{ display: 'inline-flex', marginLeft: 6 }}>
|
||||
<StateBadges inspiration={c.inspiration} exhaustion={c.exhaustion} />
|
||||
{c.conditions.map((condition) => (
|
||||
<ConditionChip key={condition} name={condition} />
|
||||
))}
|
||||
</span>
|
||||
)}
|
||||
{!inProgress && (
|
||||
<button
|
||||
className="btn btn-target"
|
||||
style={{ marginLeft: 6 }}
|
||||
title={`${c.name} at a glance, without leaving this page: saves, skills, attacks and special abilities`}
|
||||
onClick={() => openCharacterPanel(c.id)}
|
||||
>
|
||||
📋
|
||||
</button>
|
||||
)}
|
||||
</td>
|
||||
<td data-label="Species">{c.species ? SPECIES_LABELS[c.species] : '—'}</td>
|
||||
<td data-label="Class">{c.characterClass ? CLASS_LABELS[c.characterClass] : inProgress ? 'Building…' : '—'}</td>
|
||||
<td data-label="Level">{c.level}</td>
|
||||
<td data-label="Class">{c.characterClass ? classLabel(c.characterClass, c.subclassName) : inProgress ? 'Building…' : '—'}</td>
|
||||
<td data-label="Level">
|
||||
{c.level}
|
||||
{!inProgress && (
|
||||
<div className="combatant-sub mono" style={{ whiteSpace: 'nowrap' }}>
|
||||
{xpLabel(c.xp, c.xpProgress)}
|
||||
{c.xpProgress.levelUpDue && (
|
||||
<span title="They have the XP for the next level"> ⬆</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
<td data-label="HP">
|
||||
{c.maxHp != null ? (
|
||||
<div style={{ minWidth: 90 }}>
|
||||
@@ -108,6 +149,10 @@ export function PartyOverviewPage() {
|
||||
)}
|
||||
</td>
|
||||
<td data-label="AC">{c.armorClass ?? '—'}</td>
|
||||
<td data-label="Passive P / Inv / Ins" className="mono">
|
||||
{c.passives ? `${c.passives.perception} / ${c.passives.investigation} / ${c.passives.insight}` : '—'}
|
||||
</td>
|
||||
<td data-label="Spell DC" className="mono">{c.spellSaveDC ?? '—'}</td>
|
||||
<td data-label="Hit Dice" className="mono">{c.hitDice ? `${c.hitDice.remaining}/${c.hitDice.count} d${c.hitDice.size}` : '—'}</td>
|
||||
<td data-label="Spell slots" className="mono">{slotsSummary(c.spellSlots) || '—'}</td>
|
||||
<td data-label="Coins" className="mono">{c.gold == null ? '—' : formatPurse(c)}</td>
|
||||
@@ -120,6 +165,7 @@ export function PartyOverviewPage() {
|
||||
</div>
|
||||
)}
|
||||
<Pagination page={page} pageCount={pageCount} onPrev={prevPage} onNext={nextPage} onJump={setPage} />
|
||||
{isDM && checking && <GroupCheckModal characters={checkers} onClose={() => setChecking(false)} />}
|
||||
{isDM && resting && <RestModal campaignId={campaignId} characters={characters ?? []} onClose={() => setResting(false)} />}
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user