V1.0.1: Aldenfell campaign seed, content library, party overview

- Seed now resets the database and seeds the Aldenfell campaign from the
  campaign book: admin DM user, default weapons, locations, bestiary,
  pre-built encounters, and DM/shared notes
- Default weapon/spell/monster library, character profile fields,
  locations and dice mode (new migration)
- Party overview page, pagination, info tips, build preview calc
- Remove stale demo-login hint; notes preserve line breaks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-23 10:24:48 +02:00
co-authored by Claude Opus 5.5
parent 9b29dc8253
commit 94067f1268
34 changed files with 3158 additions and 391 deletions
+549 -211
View File
@@ -1,11 +1,13 @@
import { useState } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { useBuildChoose, useBuildFinalize, useBuildRoll, useCampaign, useCampaignSpells, useCampaignWeapons, useCharacter } from '../api/queries';
import { useBuildChoose, useBuildFinalize, useBuildRoll, useCampaign, useCampaignSpells, useCampaignWeapons, useCharacter, usePatchDiceMode } from '../api/queries';
import { Spinner, ErrorBanner } from '../components/Spinner';
import { ABILITY_LABELS, CLASS_LABELS, SKILL_LABELS, SPECIES_LABELS, extractErrorMessage } from '../lib/format';
import { InfoTip } from '../components/InfoTip';
import { ABILITY_LABELS, CLASS_LABELS, SKILL_LABELS, SPECIES_LABELS, extractErrorMessage, fmtMod } from '../lib/format';
import { abilityModifier, speciesBonusFor } from '../lib/speciesData';
import { CLASS_SPELLCASTING_ABILITY } from '../lib/classData';
import type { Ability, CharacterClass, Species } from '../api/types';
import { CLASS_SPELLCASTING_ABILITY, CLASS_HIT_DIE, CLASS_SAVE_PROFICIENCIES } from '../lib/classData';
import { armorClass, hpMax, passivePerception, proficiencyBonus, saveBonus, spellAttackBonus, spellSaveDC } from '../lib/previewCalc';
import type { Ability, CharacterClass, DiceMode, Species } from '../api/types';
interface SpeciesChoices {
type: 'choice' | 'wildcard';
@@ -47,15 +49,18 @@ export function CharacterBuilderPage() {
const roll = useBuildRoll(characterId);
const choose = useBuildChoose(characterId);
const finalize = useBuildFinalize(characterId);
const patchDiceMode = usePatchDiceMode(characterId);
const [formError, setFormError] = useState<string | null>(null);
const [halfElfPick, setHalfElfPick] = useState<Ability[]>([]);
const [pendingSpecies, setPendingSpecies] = useState<Species | null>(null);
const [assignments, setAssignments] = useState<Partial<Record<Ability, number>>>({});
const [skillPicks, setSkillPicks] = useState<Record<string, boolean>>({});
const [expertisePicks, setExpertisePicks] = useState<Record<string, boolean>>({});
const [equipWeapons, setEquipWeapons] = useState<string[]>([]);
const [equipSpells, setEquipSpells] = useState<string[]>([]);
const [diceModeConfirmed, setDiceModeConfirmed] = useState(false);
const [adjustingSkills, setAdjustingSkills] = useState(false);
const [skillPicks, setSkillPicks] = useState<Record<string, boolean>>({});
const [expertisePicks, setExpertisePicks] = useState<Record<string, boolean>>({});
const campaignId = character?.campaignId;
const { data: campaignData } = useCampaign(campaignId);
@@ -72,11 +77,13 @@ export function CharacterBuilderPage() {
const bs = (character.buildState || {}) as BuildState;
const stage = character.buildStage;
const diceMode = character.diceMode;
const isDM = campaignData?.campaign.role === 'DM';
async function safeRoll() {
async function safeRoll(body?: { value?: number; abilitySets?: number[][] }) {
setFormError(null);
try {
await roll.mutateAsync();
await roll.mutateAsync(body);
} catch (err) {
setFormError(extractErrorMessage(err));
}
@@ -91,218 +98,342 @@ export function CharacterBuilderPage() {
}
}
async function chooseDiceMode(mode: DiceMode) {
setFormError(null);
try {
await patchDiceMode.mutateAsync(mode);
setDiceModeConfirmed(true);
} catch (err) {
setFormError(extractErrorMessage(err));
}
}
const needsDiceModeChoice = stage === 'ROLLING_SPECIES' && !bs.speciesRoll && !diceModeConfirmed;
return (
<div>
<div className="page-header">
<div>
<h1>Rolling Up {character.name}</h1>
<p className="subtitle">Roll the dice at the table — every result is locked in server-side.</p>
<div className="build-layout">
<div>
<div className="page-header">
<div>
<h1>Rolling Up {character.name}</h1>
<p className="subtitle">Roll the dice at the table — every result is locked in server-side.</p>
</div>
</div>
<BuildProgress stage={stage} />
{formError && <ErrorBanner message={formError} />}
{needsDiceModeChoice ? (
<div className="card mt-md text-center">
<div className="card-title">Before you roll — digital or physical dice?</div>
<p>Pick how this character's dice get rolled. This can't be changed once rolling starts.</p>
<div className="flex-row flex-wrap" style={{ justifyContent: 'center' }}>
<button className="btn btn-primary btn-lg" onClick={() => chooseDiceMode('DIGITAL')} disabled={patchDiceMode.isPending}>
🎲 Digital Dice
<span className="subtitle" style={{ display: 'block', fontSize: '0.75rem' }}>The app rolls for you</span>
</button>
<button className="btn btn-lg" onClick={() => chooseDiceMode('PHYSICAL')} disabled={patchDiceMode.isPending}>
🎯 Physical Dice
<span className="subtitle" style={{ display: 'block', fontSize: '0.75rem' }}>You roll at the table, type in the result</span>
</button>
</div>
</div>
) : (
<>
{stage === 'ROLLING_SPECIES' && (
<div className="card mt-md text-center">
<div className="card-title">Step 1 — Species</div>
{!bs.speciesRoll ? (
<RollControl sides={6} diceMode={diceMode} onRoll={safeRoll} rolling={roll.isPending} label="Roll a d6 to see which species you can choose between." />
) : (
<>
<div className="roll-result animate">{bs.speciesRoll}</div>
<p className="mt-sm">
{bs.speciesChoices?.type === 'wildcard' ? 'Wildcard! Pick any species:' : 'Choose your species:'}
</p>
<div className="flex-row flex-wrap" style={{ justifyContent: 'center' }}>
{bs.speciesChoices?.options.map((s) => (
<button
key={s}
className={`btn ${pendingSpecies === s ? 'btn-primary' : ''}`}
onClick={() => {
setPendingSpecies(s as Species);
setHalfElfPick([]);
if (s !== 'HALF_ELF') safeChoose({ species: s });
}}
>
{SPECIES_LABELS[s]}
</button>
))}
</div>
{pendingSpecies === 'HALF_ELF' && (
<div className="card mt-md" style={{ textAlign: 'left' }}>
<p>Half-Elf gets a fixed +2 CHA, plus +1/+1 to two other abilities of your choice:</p>
<div className="flex-row flex-wrap">
{HALF_ELF_ELIGIBLE.map((a) => (
<label key={a} className="checkbox-row">
<input
type="checkbox"
checked={halfElfPick.includes(a)}
disabled={!halfElfPick.includes(a) && halfElfPick.length >= 2}
onChange={(e) =>
setHalfElfPick((prev) =>
e.target.checked ? [...prev, a] : prev.filter((x) => x !== a)
)
}
/>
{ABILITY_LABELS[a]}
</label>
))}
</div>
<button
className="btn btn-primary mt-sm"
disabled={halfElfPick.length !== 2}
onClick={() => safeChoose({ species: 'HALF_ELF', halfElfBonusAbilities: halfElfPick })}
>
Confirm Half-Elf
</button>
</div>
)}
</>
)}
</div>
)}
{stage === 'ROLLING_CLASS' && (
<div className="card mt-md text-center">
<div className="card-title">Step 2 — Class</div>
{!bs.classRoll || bs.classChoices?.type === 'reroll' ? (
<>
{bs.classChoices?.type === 'reroll' && (
<div className="roll-result animate mb-2">{bs.classRoll}</div>
)}
<RollControl
sides={8}
diceMode={diceMode}
onRoll={safeRoll}
rolling={roll.isPending}
label={bs.classChoices?.type === 'reroll' ? 'You rolled a 7 — reroll once!' : 'Roll a d8 to see which classes you can choose between.'}
/>
</>
) : (
<>
<div className="roll-result animate">{bs.classRoll}</div>
<p className="mt-sm">
{bs.classChoices?.type === 'wildcard' ? 'Wildcard! Pick any class:' : 'Choose your class:'}
</p>
<div className="flex-row flex-wrap" style={{ justifyContent: 'center' }}>
{bs.classChoices?.options.map((c) => (
<button key={c} className="btn" onClick={() => safeChoose({ characterClass: c })}>
{CLASS_LABELS[c]}
</button>
))}
</div>
</>
)}
</div>
)}
{stage === 'ROLLING_MOTIVATION' && (
<div className="card mt-md text-center">
<div className="card-title">Step 3 — Motivation (Flavor)</div>
{!bs.motivationRoll ? (
<RollControl sides={6} diceMode={diceMode} onRoll={safeRoll} rolling={roll.isPending} label="Roll a d6 for your character's driving motivation." />
) : (
<>
<div className="roll-result animate">{bs.motivationRoll}</div>
<p className="mt-sm" style={{ fontStyle: 'italic' }}>
"{bs.motivationText}"
</p>
<button className="btn btn-primary mt-sm" onClick={() => safeChoose({})}>
Confirm & Continue
</button>
</>
)}
</div>
)}
{stage === 'ASSIGNING_SCORES' && (
<AssignScoresStep
bs={bs}
diceMode={diceMode}
assignments={assignments}
setAssignments={setAssignments}
onRoll={safeRoll}
onSubmit={() => safeChoose({ assignments })}
rolling={roll.isPending}
/>
)}
{stage === 'ASSIGNING_PROFICIENCIES' && (
<div className="card mt-md">
<div className="card-title">
Step 5 — Skill Proficiencies <InfoTip term="SKILL_BONUS" />
</div>
<p className="subtitle">
Auto-generated from your class's skill list. Saving throw proficiencies are fixed by class and were
also set automatically.
</p>
{!adjustingSkills ? (
<>
<div className="flex-row flex-wrap">
{(bs.skillProficiencies || []).map((sp) => (
<span key={sp.skill} className="badge badge-dm">
{SKILL_LABELS[sp.skill]}
</span>
))}
</div>
<div className="flex-row mt-md">
<button className="btn btn-primary" onClick={() => safeChoose({})}>
Confirm & Continue
</button>
{isDM && (
<button
className="btn btn-ghost"
onClick={() => {
const picks: Record<string, boolean> = {};
const expertise: Record<string, boolean> = {};
for (const sp of bs.skillProficiencies || []) {
picks[sp.skill] = true;
expertise[sp.skill] = sp.expertise;
}
setSkillPicks(picks);
setExpertisePicks(expertise);
setAdjustingSkills(true);
}}
>
DM: Adjust picks
</button>
)}
</div>
</>
) : (
<>
<div className="grid grid-cols-3">
{ALL_SKILLS.map((skill) => (
<label key={skill} className="checkbox-row" style={{ flexDirection: 'column', alignItems: 'flex-start', gap: 2 }}>
<span className="flex-row">
<input
type="checkbox"
checked={Boolean(skillPicks[skill])}
onChange={(e) => setSkillPicks((p) => ({ ...p, [skill]: e.target.checked }))}
/>
{SKILL_LABELS[skill]}
</span>
{skillPicks[skill] && (
<span className="flex-row" style={{ fontSize: '0.75rem', color: 'var(--text-muted)', marginLeft: '1.5rem' }}>
<input
type="checkbox"
checked={Boolean(expertisePicks[skill])}
onChange={(e) => setExpertisePicks((p) => ({ ...p, [skill]: e.target.checked }))}
/>
expertise
</span>
)}
</label>
))}
</div>
<button
className="btn btn-primary mt-md"
onClick={() =>
safeChoose({
skillProficiencies: ALL_SKILLS.filter((s) => skillPicks[s]).map((s) => ({
skill: s,
proficient: true,
expertise: Boolean(expertisePicks[s]),
})),
})
}
>
Confirm Skills
</button>
</>
)}
</div>
)}
{stage === 'CHOOSING_EQUIPMENT' && (
<EquipmentStep
bs={bs}
campaignData={campaignData}
weapons={weapons}
spells={spells}
equipWeapons={equipWeapons}
setEquipWeapons={setEquipWeapons}
equipSpells={equipSpells}
setEquipSpells={setEquipSpells}
onSubmit={() => safeChoose({ weaponIds: equipWeapons, spellIds: equipSpells })}
onFinalize={async () => {
try {
const finalized = await finalize.mutateAsync();
navigate(`/characters/${finalized.id}`);
} catch (err) {
setFormError(extractErrorMessage(err));
}
}}
finalizing={finalize.isPending}
/>
)}
</>
)}
</div>
<BuildProgress stage={stage} />
<aside className="build-preview">
<BuildPreview bs={bs} level={character.level} armorBonus={character.armorBonus} assignments={assignments} />
</aside>
</div>
);
}
{formError && <ErrorBanner message={formError} />}
function RollControl({
sides,
diceMode,
onRoll,
rolling,
label,
}: {
sides: number;
diceMode: DiceMode;
onRoll: (body?: { value?: number }) => void;
rolling: boolean;
label: string;
}) {
const [value, setValue] = useState('');
{stage === 'ROLLING_SPECIES' && (
<div className="card mt-md text-center">
<div className="card-title">Step 1 — Species</div>
{!bs.speciesRoll ? (
<>
<p>Roll a d6 to see which species you can choose between.</p>
<button className="btn-roll" onClick={safeRoll} disabled={roll.isPending}>
🎲 Roll d6
</button>
</>
) : (
<>
<div className="roll-result animate">{bs.speciesRoll}</div>
<p className="mt-sm">
{bs.speciesChoices?.type === 'wildcard' ? 'Wildcard! Pick any species:' : 'Choose your species:'}
</p>
<div className="flex-row flex-wrap" style={{ justifyContent: 'center' }}>
{bs.speciesChoices?.options.map((s) => (
<button
key={s}
className={`btn ${pendingSpecies === s ? 'btn-primary' : ''}`}
onClick={() => {
setPendingSpecies(s as Species);
setHalfElfPick([]);
if (s !== 'HALF_ELF') safeChoose({ species: s });
}}
>
{SPECIES_LABELS[s]}
</button>
))}
</div>
{pendingSpecies === 'HALF_ELF' && (
<div className="card mt-md" style={{ textAlign: 'left' }}>
<p>Half-Elf gets a fixed +2 CHA, plus +1/+1 to two other abilities of your choice:</p>
<div className="flex-row flex-wrap">
{HALF_ELF_ELIGIBLE.map((a) => (
<label key={a} className="checkbox-row">
<input
type="checkbox"
checked={halfElfPick.includes(a)}
disabled={!halfElfPick.includes(a) && halfElfPick.length >= 2}
onChange={(e) =>
setHalfElfPick((prev) =>
e.target.checked ? [...prev, a] : prev.filter((x) => x !== a)
)
}
/>
{ABILITY_LABELS[a]}
</label>
))}
</div>
<button
className="btn btn-primary mt-sm"
disabled={halfElfPick.length !== 2}
onClick={() => safeChoose({ species: 'HALF_ELF', halfElfBonusAbilities: halfElfPick })}
>
Confirm Half-Elf
</button>
</div>
)}
</>
)}
</div>
)}
{stage === 'ROLLING_CLASS' && (
<div className="card mt-md text-center">
<div className="card-title">Step 2 — Class</div>
{!bs.classRoll || bs.classChoices?.type === 'reroll' ? (
<>
{bs.classChoices?.type === 'reroll' && (
<div className="roll-result animate mb-2">{bs.classRoll}</div>
)}
<p>{bs.classChoices?.type === 'reroll' ? 'You rolled a 7 — reroll once!' : 'Roll a d8 to see which classes you can choose between.'}</p>
<button className="btn-roll" onClick={safeRoll} disabled={roll.isPending}>
🎲 Roll d8
</button>
</>
) : (
<>
<div className="roll-result animate">{bs.classRoll}</div>
<p className="mt-sm">
{bs.classChoices?.type === 'wildcard' ? 'Wildcard! Pick any class:' : 'Choose your class:'}
</p>
<div className="flex-row flex-wrap" style={{ justifyContent: 'center' }}>
{bs.classChoices?.options.map((c) => (
<button key={c} className="btn" onClick={() => safeChoose({ characterClass: c })}>
{CLASS_LABELS[c]}
</button>
))}
</div>
</>
)}
</div>
)}
{stage === 'ROLLING_MOTIVATION' && (
<div className="card mt-md text-center">
<div className="card-title">Step 3 — Motivation (Flavor)</div>
{!bs.motivationRoll ? (
<>
<p>Roll a d6 for your character's driving motivation.</p>
<button className="btn-roll" onClick={safeRoll} disabled={roll.isPending}>
🎲 Roll d6
</button>
</>
) : (
<>
<div className="roll-result animate">{bs.motivationRoll}</div>
<p className="mt-sm" style={{ fontStyle: 'italic' }}>
"{bs.motivationText}"
</p>
<button className="btn btn-primary mt-sm" onClick={() => safeChoose({})}>
Confirm & Continue
</button>
</>
)}
</div>
)}
{stage === 'ASSIGNING_SCORES' && (
<AssignScoresStep
bs={bs}
assignments={assignments}
setAssignments={setAssignments}
onRoll={safeRoll}
onSubmit={() => safeChoose({ assignments })}
rolling={roll.isPending}
/>
)}
{stage === 'ASSIGNING_PROFICIENCIES' && (
<div className="card mt-md">
<div className="card-title">Step 5 — Skill Proficiencies</div>
<p className="subtitle">Saving throw proficiencies are fixed by class and were set automatically.</p>
<div className="grid grid-cols-3">
{ALL_SKILLS.map((skill) => (
<label key={skill} className="checkbox-row" style={{ flexDirection: 'column', alignItems: 'flex-start', gap: 2 }}>
<span className="flex-row">
<input
type="checkbox"
checked={Boolean(skillPicks[skill])}
onChange={(e) => setSkillPicks((p) => ({ ...p, [skill]: e.target.checked }))}
/>
{SKILL_LABELS[skill]}
</span>
{skillPicks[skill] && (
<span className="flex-row" style={{ fontSize: '0.75rem', color: 'var(--text-muted)', marginLeft: '1.5rem' }}>
<input
type="checkbox"
checked={Boolean(expertisePicks[skill])}
onChange={(e) => setExpertisePicks((p) => ({ ...p, [skill]: e.target.checked }))}
/>
expertise
</span>
)}
</label>
))}
</div>
if (diceMode === 'PHYSICAL') {
return (
<>
<p>{label} Roll it at the table, then type the result in below.</p>
<div className="flex-row" style={{ justifyContent: 'center' }}>
<input
type="number"
min={1}
max={sides}
placeholder={`1–${sides}`}
value={value}
onChange={(e) => setValue(e.target.value)}
style={{ width: 80 }}
/>
<button
className="btn btn-primary mt-md"
onClick={() =>
safeChoose({
skillProficiencies: ALL_SKILLS.filter((s) => skillPicks[s]).map((s) => ({
skill: s,
proficient: true,
expertise: Boolean(expertisePicks[s]),
})),
})
}
className="btn btn-primary"
disabled={rolling || !value}
onClick={() => onRoll({ value: Number(value) })}
>
Confirm Skills
Submit d{sides} Roll
</button>
</div>
)}
</>
);
}
{stage === 'CHOOSING_EQUIPMENT' && (
<EquipmentStep
bs={bs}
campaignData={campaignData}
weapons={weapons}
spells={spells}
equipWeapons={equipWeapons}
setEquipWeapons={setEquipWeapons}
equipSpells={equipSpells}
setEquipSpells={setEquipSpells}
onSubmit={() => safeChoose({ weaponIds: equipWeapons, spellIds: equipSpells })}
onFinalize={async () => {
try {
const finalized = await finalize.mutateAsync();
navigate(`/characters/${finalized.id}`);
} catch (err) {
setFormError(extractErrorMessage(err));
}
}}
finalizing={finalize.isPending}
/>
)}
</div>
return (
<>
<p>{label}</p>
<button className="btn-roll" onClick={() => onRoll()} disabled={rolling}>
🎲 Roll d{sides}
</button>
</>
);
}
@@ -322,6 +453,7 @@ function BuildProgress({ stage }: { stage: string }) {
function AssignScoresStep({
bs,
diceMode,
assignments,
setAssignments,
onRoll,
@@ -329,18 +461,22 @@ function AssignScoresStep({
rolling,
}: {
bs: BuildState;
diceMode: DiceMode;
assignments: Partial<Record<Ability, number>>;
setAssignments: (a: Partial<Record<Ability, number>>) => void;
onRoll: () => void;
onRoll: (body?: { abilitySets?: number[][] }) => void;
onSubmit: () => void;
rolling: boolean;
}) {
if (!bs.abilityRolls) {
if (diceMode === 'PHYSICAL') {
return <PhysicalAbilityRollForm onRoll={onRoll} rolling={rolling} />;
}
return (
<div className="card mt-md text-center">
<div className="card-title">Step 4 — Ability Scores</div>
<p>Roll 4d6 (drop the lowest) six times — one set per ability.</p>
<button className="btn-roll" onClick={onRoll} disabled={rolling}>
<button className="btn-roll" onClick={() => onRoll()} disabled={rolling}>
🎲 Roll Ability Scores
</button>
</div>
@@ -405,6 +541,46 @@ function AssignScoresStep({
);
}
function PhysicalAbilityRollForm({ onRoll, rolling }: { onRoll: (body?: { abilitySets?: number[][] }) => void; rolling: boolean }) {
const [sets, setSets] = useState<string[][]>(Array.from({ length: 6 }, () => ['', '', '', '']));
const allFilled = sets.every((set) => set.every((v) => v !== '' && Number(v) >= 1 && Number(v) <= 6));
function updateDie(setIdx: number, dieIdx: number, value: string) {
setSets((prev) => prev.map((set, i) => (i === setIdx ? set.map((d, j) => (j === dieIdx ? value : d)) : set)));
}
return (
<div className="card mt-md">
<div className="card-title">Step 4 — Ability Scores (Physical Dice)</div>
<p>Roll 4d6 six times at the table, then enter each set's four results below (drop-the-lowest is applied automatically).</p>
{sets.map((set, i) => (
<div key={i} className="flex-row flex-wrap mt-sm">
<span className="badge">Set {i + 1}</span>
{set.map((v, j) => (
<input
key={j}
type="number"
min={1}
max={6}
value={v}
onChange={(e) => updateDie(i, j, e.target.value)}
style={{ width: 60 }}
/>
))}
</div>
))}
<button
className="btn btn-primary mt-md"
disabled={!allFilled || rolling}
onClick={() => onRoll({ abilitySets: sets.map((set) => set.map(Number)) })}
>
Submit All Six Sets
</button>
</div>
);
}
function EquipmentStep({
bs,
campaignData,
@@ -497,3 +673,165 @@ function EquipmentStep({
</div>
);
}
// Live "what does this change" preview — recomputes the projected sheet as
// species/class/scores/skills firm up, using the same pure formulas as the
// server's calculation engine (ported in lib/previewCalc.ts). Display-only;
// the server remains authoritative at finalize.
function BuildPreview({
bs,
level,
armorBonus,
assignments,
}: {
bs: BuildState;
level: number;
armorBonus: number;
assignments: Partial<Record<Ability, number>>;
}) {
const species = bs.species ?? null;
const halfElfBonusAbilities = bs.halfElfBonusAbilities || [];
const characterClass = bs.characterClass ?? null;
const abilityFinals: Partial<Record<Ability, number>> = {};
for (const ability of ABILITIES) {
const bonus = speciesBonusFor(species, ability, halfElfBonusAbilities);
const assignedIndex = assignments[ability] ?? bs.abilityAssignments?.[ability];
const rolledTotal = assignedIndex !== undefined ? bs.abilityRolls?.[assignedIndex]?.total : undefined;
if (rolledTotal !== undefined) {
abilityFinals[ability] = rolledTotal + bonus;
} else if (species) {
abilityFinals[ability] = 10 + bonus; // baseline preview before rolling
}
}
const dexMod = abilityFinals.DEX !== undefined ? abilityModifier(abilityFinals.DEX) : null;
const conMod = abilityFinals.CON !== undefined ? abilityModifier(abilityFinals.CON) : null;
const profBonus = proficiencyBonus(level || 1);
const hitDie = characterClass ? CLASS_HIT_DIE[characterClass] : null;
const saveProfs = characterClass ? CLASS_SAVE_PROFICIENCIES[characterClass] : [];
const spellAbility = characterClass ? CLASS_SPELLCASTING_ABILITY[characterClass] : null;
const perceptionProficient = Boolean(bs.skillProficiencies?.some((s) => s.skill === 'PERCEPTION'));
const wisMod = abilityFinals.WIS !== undefined ? abilityModifier(abilityFinals.WIS) : null;
return (
<div className="card">
<div className="card-title">Live Preview</div>
{!species && !characterClass && (
<p className="subtitle" style={{ marginTop: 0 }}>Pick a species and class to see your projected stats build up here.</p>
)}
{species && (
<p style={{ marginTop: 0 }}>
<strong>{SPECIES_LABELS[species]}</strong>
{Object.entries({ STR: 0, DEX: 0, CON: 0, INT: 0, WIS: 0, CHA: 0 })
.map(([a]) => [a as Ability, speciesBonusFor(species, a as Ability, halfElfBonusAbilities)] as const)
.filter(([, bonus]) => bonus !== 0)
.map(([a, bonus]) => (
<span key={a} className="preview-highlight" style={{ marginLeft: 6 }}>
{fmtMod(bonus)} {a}
</span>
))}
</p>
)}
{characterClass && (
<p>
<strong>{CLASS_LABELS[characterClass]}</strong>
<span style={{ color: 'var(--text-muted)' }}> · d{hitDie} hit die</span>
{saveProfs && saveProfs.length > 0 && (
<span style={{ color: 'var(--text-muted)' }}> · {saveProfs.map((a) => ABILITY_LABELS[a]).join('/')} saves</span>
)}
</p>
)}
{Object.keys(abilityFinals).length > 0 && (
<div className="grid grid-cols-3 mt-sm">
{ABILITIES.map((a) =>
abilityFinals[a] !== undefined ? (
<div className="stat-block" key={a}>
<span className="stat-label">{a}</span>
<span className="stat-value">{abilityFinals[a]}</span>
<span className="stat-sub">{fmtMod(abilityModifier(abilityFinals[a]!))}</span>
</div>
) : null
)}
</div>
)}
<div className="divider" />
<div className="grid grid-cols-2">
<div>
<span className="stat-label">AC</span>
<div className="stat-value">{dexMod !== null ? armorClass(dexMod, armorBonus) : '—'}</div>
</div>
<div>
<span className="stat-label">Max HP</span>
<div className="stat-value">{hitDie && conMod !== null ? hpMax(level || 1, hitDie, conMod) : '—'}</div>
</div>
<div>
<span className="stat-label">Initiative</span>
<div className="stat-value">{dexMod !== null ? fmtMod(dexMod) : '—'}</div>
</div>
<div>
<span className="stat-label">Prof. Bonus</span>
<div className="stat-value">{fmtMod(profBonus)}</div>
</div>
</div>
{characterClass && saveProfs.length > 0 && (
<>
<div className="divider" />
<div className="card-title" style={{ fontSize: '0.85rem' }}>Saving Throws</div>
{ABILITIES.map((a) => {
const mod = abilityFinals[a] !== undefined ? abilityModifier(abilityFinals[a]!) : null;
if (mod === null) return null;
const proficient = saveProfs.includes(a);
return (
<div key={a} className="flex-between" style={{ padding: '0.15rem 0', fontSize: '0.85rem' }}>
<span>
{ABILITY_LABELS[a]} {proficient && <span className="badge">prof</span>}
</span>
<span className="mono">{fmtMod(saveBonus(mod, proficient, profBonus))}</span>
</div>
);
})}
</>
)}
{wisMod !== null && (
<>
<div className="divider" />
<div className="flex-between" style={{ fontSize: '0.85rem' }}>
<span>Passive Perception</span>
<span className="mono">{passivePerception(perceptionProficient ? profBonus + wisMod : wisMod)}</span>
</div>
</>
)}
{spellAbility && abilityFinals[spellAbility] !== undefined && (
<>
<div className="divider" />
<div className="card-title" style={{ fontSize: '0.85rem' }}>Spellcasting ({ABILITY_LABELS[spellAbility]})</div>
<p style={{ margin: 0, fontSize: '0.85rem' }}>
Save DC {spellSaveDC(profBonus, abilityModifier(abilityFinals[spellAbility]!))} · Attack{' '}
{fmtMod(spellAttackBonus(profBonus, abilityModifier(abilityFinals[spellAbility]!)))}
</p>
</>
)}
{bs.skillProficiencies && bs.skillProficiencies.length > 0 && (
<>
<div className="divider" />
<div className="card-title" style={{ fontSize: '0.85rem' }}>Skills</div>
<div className="flex-row flex-wrap gap-sm">
{bs.skillProficiencies.map((sp) => (
<span key={sp.skill} className="badge">{SKILL_LABELS[sp.skill]}</span>
))}
</div>
</>
)}
</div>
);
}