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>
359 lines
15 KiB
TypeScript
359 lines
15 KiB
TypeScript
import { Link, useMatch } from 'react-router-dom';
|
||
import { useCampaign, useCampaignCharacters, usePatchCharacterWeapon, usePatchInventoryItem, useQuickStats } from '../api/queries';
|
||
import { useAuth } from '../auth/useAuth';
|
||
import { useLastCampaignId } from '../lib/lastCampaign';
|
||
import { closeCharacterPanel, openCharacterPanel, useCharacterPanelId } from '../lib/characterPanel';
|
||
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';
|
||
|
||
// What equipped gear is doing, one line per thing: "Chain Mail: +6 AC · −10 Speed".
|
||
export function GearInForce({ gear }: { gear: ActiveGear }) {
|
||
const sources = [...new Set([...gear.effects.map((e) => e.source), ...gear.notes.map((n) => n.source)])];
|
||
if (sources.length === 0) return null;
|
||
return (
|
||
<>
|
||
{sources.map((source) => (
|
||
<div key={source} className="detail-row">
|
||
<strong>{source}</strong>
|
||
<span>
|
||
{[...gear.effects.filter((e) => e.source === source).map(effectLabel), ...gear.notes.filter((n) => n.source === source).map((n) => n.note)].join(' · ')}
|
||
</span>
|
||
</div>
|
||
))}
|
||
</>
|
||
);
|
||
}
|
||
|
||
function Flags({ equipped, usable, level }: { equipped: boolean; usable: boolean; level: number }) {
|
||
return (
|
||
<>
|
||
{equipped && <span className="badge badge-live" style={{ marginLeft: 6 }}>equipped</span>}
|
||
{!usable && <span className="badge badge-hostile" style={{ marginLeft: 6 }}>needs level {level}</span>}
|
||
</>
|
||
);
|
||
}
|
||
|
||
// One character at a glance: the numbers for a fight, and everything they
|
||
// hold. The pack, spells and purse are there for the character's own player
|
||
// and the DM, who can also put gear on and take it off from here.
|
||
function PanelBody({ characterId, isDM }: { characterId: string; isDM: boolean }) {
|
||
const { data, isLoading, error } = useQuickStats(characterId, true);
|
||
const patchWeapon = usePatchCharacterWeapon(characterId);
|
||
const patchItem = usePatchInventoryItem(characterId);
|
||
// Why something could not be equipped: too much on already.
|
||
const [equipError, setEquipError] = useState<string | null>(null);
|
||
const equip = { onError: (err: unknown) => setEquipError(extractErrorMessage(err)), onSuccess: () => setEquipError(null) };
|
||
|
||
if (isLoading) return <Spinner label="Reading the sheet…" />;
|
||
if (error || !data) return <ErrorBanner message="Could not load this character." />;
|
||
|
||
const canEquip = !data.restricted;
|
||
const stats: [string, string | number][] = [
|
||
['AC', data.armorClass],
|
||
['Initiative', fmtMod(data.initiative)],
|
||
['Speed', data.speed],
|
||
['Prof.', fmtMod(data.proficiencyBonus)],
|
||
['Passive Perc.', data.passivePerception],
|
||
['Hit Dice', `${data.hitDice.remaining}/${data.hitDice.count} d${data.hitDice.size}`],
|
||
];
|
||
|
||
return (
|
||
<div className="mt-md">
|
||
<div className="flex-between flex-wrap">
|
||
<div>
|
||
<h3 style={{ margin: 0 }}>
|
||
<span aria-hidden="true">{speciesIcon(data.species)}</span> {data.name}
|
||
</h3>
|
||
<div className="combatant-sub">
|
||
{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}>
|
||
Full sheet
|
||
</Link>
|
||
</div>
|
||
|
||
<div className="stat-chips mt-sm">
|
||
<span className="stat-chip">
|
||
<span>HP</span>
|
||
<b>
|
||
{data.currentHp}/{data.maxHp}
|
||
{data.tempHp > 0 && ` +${data.tempHp}`}
|
||
</b>
|
||
</span>
|
||
{stats.map(([label, value]) => (
|
||
<span key={label} className="stat-chip">
|
||
<span>{label}</span>
|
||
<b>{value}</b>
|
||
</span>
|
||
))}
|
||
</div>
|
||
<div className="mt-sm">
|
||
<HpBar current={data.currentHp} max={data.maxHp} temp={data.tempHp} />
|
||
</div>
|
||
{/* Read-only here; the saves are rolled on the sheet or in the encounter. */}
|
||
<DeathSaves characterId={characterId} name={data.name} deathSaves={data.deathSaves} canAct={false} isDM={false} />
|
||
|
||
<div className="stat-chips mt-sm">
|
||
{(Object.keys(data.abilities) as (keyof typeof data.abilities)[]).map((a) => (
|
||
<span key={a} className="stat-chip">
|
||
<span>{a}</span>
|
||
<b>
|
||
{data.abilities[a].final} ({fmtMod(data.abilities[a].modifier)})
|
||
</b>
|
||
</span>
|
||
))}
|
||
</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>
|
||
<GearInForce gear={data.gear} />
|
||
<p className="combatant-sub" style={{ margin: '0.4rem 0 0' }}>Already counted in the numbers above.</p>
|
||
</div>
|
||
)}
|
||
|
||
{data.spellcasting && (
|
||
<div className="card mt-md">
|
||
<div className="card-title">Spellcasting</div>
|
||
<p style={{ margin: 0 }}>
|
||
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 && (
|
||
<SpellSlotTracker
|
||
characterId={characterId}
|
||
name={data.name}
|
||
slots={data.spellSlots}
|
||
canUse={!data.restricted}
|
||
isDM={isDM}
|
||
onError={(err) => setEquipError(extractErrorMessage(err))}
|
||
/>
|
||
)}
|
||
</div>
|
||
)}
|
||
|
||
{canEquip && (
|
||
<p className="combatant-sub mt-md" style={{ marginBottom: 0 }}>
|
||
Tick what is equipped. Only equipped weapons can be used in an encounter, and only equipped gear gives its effects.
|
||
</p>
|
||
)}
|
||
{equipError && <ErrorBanner message={equipError} />}
|
||
<div className="card mt-md">
|
||
<div className="card-title">Weapons · {data.weapons.length}</div>
|
||
{data.weapons.length === 0 && <p className="combatant-sub" style={{ margin: 0 }}>No weapons.</p>}
|
||
{data.weapons.map((w) => (
|
||
<div key={w.characterWeaponId} className="reward-row">
|
||
<div className="flex-between">
|
||
<div>
|
||
<strong>{w.name}</strong>
|
||
{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} ·{' '}
|
||
<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>
|
||
{canEquip && (
|
||
<input
|
||
type="checkbox"
|
||
aria-label={`${w.name} is equipped`}
|
||
title="Equipped"
|
||
checked={w.equipped}
|
||
disabled={!w.usable || patchWeapon.isPending}
|
||
onChange={(e) => patchWeapon.mutate({ weaponId: w.weaponId, equipped: e.target.checked }, equip)}
|
||
/>
|
||
)}
|
||
</div>
|
||
</div>
|
||
))}
|
||
</div>
|
||
|
||
{data.restricted ? (
|
||
<p className="combatant-sub mt-md">Their pack, spells and purse are their own business.</p>
|
||
) : (
|
||
<>
|
||
<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">
|
||
<div className="flex-between">
|
||
<div>
|
||
<strong>{item.name}</strong>
|
||
<span className="combatant-sub"> ×{item.quantity}</span>
|
||
<Flags equipped={item.equipped} usable={item.usable} level={item.level} />
|
||
<div className="combatant-sub">
|
||
Lv {item.level}
|
||
{item.damageDice && ` · ${item.damageDice}`}
|
||
</div>
|
||
{effectsSummary(item.effects, item.effectNote) && <div className="combatant-sub">✦ {effectsSummary(item.effects, item.effectNote)}</div>}
|
||
{item.description && <div className="combatant-sub">{item.description}</div>}
|
||
</div>
|
||
<input
|
||
type="checkbox"
|
||
aria-label={`${item.name} is equipped`}
|
||
title="Equipped"
|
||
checked={item.equipped}
|
||
disabled={!item.usable || patchItem.isPending}
|
||
onChange={(e) => patchItem.mutate({ itemId: item.itemId, equipped: e.target.checked }, equip)}
|
||
/>
|
||
</div>
|
||
</div>
|
||
))}
|
||
</details>
|
||
|
||
<div className="card mt-md">
|
||
<div className="card-title">
|
||
<span>Money</span>
|
||
{data.purse && <span className="mono">{formatPurse(data.purse)}</span>}
|
||
</div>
|
||
</div>
|
||
|
||
{data.spells.length > 0 && (
|
||
<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 && (
|
||
<>
|
||
{' · '}
|
||
<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>
|
||
))}
|
||
</details>
|
||
)}
|
||
</>
|
||
)}
|
||
|
||
</div>
|
||
);
|
||
}
|
||
|
||
// The floating character button, on every page, and the panel it opens. A
|
||
// player gets their own characters in the campaign they are in; the DM gets
|
||
// everyone's. Other pages can open the panel for a particular character with
|
||
// openCharacterPanel (lib/characterPanel.ts).
|
||
export function CharacterPanel() {
|
||
const { user } = useAuth();
|
||
const campaignId = useLastCampaignId() ?? undefined;
|
||
const { data: campaignData } = useCampaign(campaignId);
|
||
const { data: characters } = useCampaignCharacters(campaignId);
|
||
const onSheet = useMatch('/characters/:characterId');
|
||
const openId = useCharacterPanelId();
|
||
|
||
const isDM = campaignData?.campaign.role === 'DM';
|
||
const choices = (characters ?? []).filter((c) => c.buildStage === 'COMPLETE' && (isDM || c.userId === user?.id));
|
||
if (choices.length === 0 && !openId) return null;
|
||
|
||
// On a character's own sheet the button opens that character; otherwise the first of yours.
|
||
const fallback = choices.find((c) => c.id === onSheet?.params.characterId) ?? choices.find((c) => c.userId === user?.id) ?? choices[0];
|
||
const shown = openId ?? undefined;
|
||
|
||
return (
|
||
<>
|
||
{fallback && (
|
||
<button
|
||
className="fab-quickstats"
|
||
onClick={() => openCharacterPanel(fallback.id)}
|
||
title={isDM ? 'Characters: stats, skills and inventory' : 'Your character: stats, skills and inventory'}
|
||
aria-label="Open the character panel"
|
||
>
|
||
🧙
|
||
</button>
|
||
)}
|
||
{shown && (
|
||
<>
|
||
<div className="drawer-backdrop" onClick={closeCharacterPanel} />
|
||
<div className="drawer" role="dialog" aria-label="Character panel">
|
||
<div className="flex-between">
|
||
{choices.length > 1 && choices.some((c) => c.id === shown) ? (
|
||
<select aria-label="Which character" value={shown} onChange={(e) => openCharacterPanel(e.target.value)} style={{ flex: 1, minWidth: 0 }}>
|
||
{choices.map((c) => (
|
||
<option key={c.id} value={c.id}>
|
||
{c.name}
|
||
{isDM && c.userId === user?.id ? ' (yours)' : ''}
|
||
</option>
|
||
))}
|
||
</select>
|
||
) : (
|
||
<h2 style={{ margin: 0 }}>Character</h2>
|
||
)}
|
||
<button className="btn btn-ghost" onClick={closeCharacterPanel} aria-label="Close the character panel">
|
||
✕
|
||
</button>
|
||
</div>
|
||
<PanelBody key={shown} characterId={shown} isDM={isDM} />
|
||
</div>
|
||
</>
|
||
)}
|
||
</>
|
||
);
|
||
}
|