V1.1.0: gear levels, encounter overhaul, guided builder, trading, docs
Characters - Builder: pick-then-Next on every step with live preview, Back button, plain-language help throughout, and "Suggest for me" for ability scores - Motivation is picked from a list; new steps for special abilities, background and appearance, all composed from fixed lists and DM-only to edit afterwards - Copy a character to another campaign - Characters can give gold, weapons, items and spells to each other - Money tracker: gold only changes through a logged ledger - Fixes: level/XP/location are DM-only, HP stays within 0..max, physical dice ability rolls, every die is rolled once Gear - DM-managed item pool; weapons, items and spells are handed out by the DM - Starting-option flag per pool entry - Gear levels 1-9 per held copy with a damage ladder, growth rate and starting level; spells gated by spell level with a fixed damage value - Spell library carries default damage; damage is picked from a list Encounters - Battle and NPC quest modes, turn tracking, scene description, DM notes - NPCs, richer combatant cards, conditions from a list - Rewards (gold, weapons, items) lined up and awarded, with gold splitting - Character HP is shared between the sheet and the encounter - Monster stat blocks and NPC secrets are never sent to players Other - Dice roller on every page - Docs for characters, weapons, spells, items, encounters, monsters and NPCs, with full lists generated from the data (npm run docs:lists) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,20 +1,30 @@
|
||||
import { useState, type FormEvent } from 'react';
|
||||
import { Link, useParams } from 'react-router-dom';
|
||||
import { Link, useNavigate, useParams } from 'react-router-dom';
|
||||
import {
|
||||
useCharacter,
|
||||
usePatchCharacter,
|
||||
useCampaignWeapons,
|
||||
useAssignWeapon,
|
||||
usePatchCharacterWeapon,
|
||||
useAddInventoryItem,
|
||||
useRemoveCharacterWeapon,
|
||||
useCampaignItems,
|
||||
useAssignItem,
|
||||
usePatchInventoryItem,
|
||||
useDeleteInventoryItem,
|
||||
useRemoveInventoryItem,
|
||||
useCampaignSpells,
|
||||
useAssignSpell,
|
||||
usePatchCharacterSpell,
|
||||
useRemoveCharacterSpell,
|
||||
useGoldLedger,
|
||||
useAdjustGold,
|
||||
useCampaignCharacters,
|
||||
useGive,
|
||||
type Gift,
|
||||
useCharacterNotes,
|
||||
useCreateNote,
|
||||
useCampaign,
|
||||
useCampaigns,
|
||||
useCopyCharacter,
|
||||
useCampaignLocations,
|
||||
} from '../api/queries';
|
||||
import { useAuth } from '../auth/AuthContext';
|
||||
@@ -23,11 +33,173 @@ import { Spinner, ErrorBanner } from '../components/Spinner';
|
||||
import { QuickStatsFab } from '../components/QuickStatsDrawer';
|
||||
import { InfoTip } from '../components/InfoTip';
|
||||
import { usePagination, Pagination } from '../components/Paginated';
|
||||
import { ABILITY_LABELS, CLASS_LABELS, SKILL_LABELS, SPECIES_LABELS, fmtMod, hpBarClass, extractErrorMessage } from '../lib/format';
|
||||
import { ABILITY_LABELS, CLASS_LABELS, SKILL_LABELS, SPECIES_LABELS, fmtMod, hpBarClass, extractErrorMessage, spellLevelLabel } from '../lib/format';
|
||||
import { speciesIcon } from '../lib/speciesIcons';
|
||||
import { hpMax as previewHpMax } from '../lib/previewCalc';
|
||||
import { hpMax as previewHpMax, scaledDamageDice, MAX_GEAR_LEVEL } from '../lib/previewCalc';
|
||||
import { CLASS_HIT_DIE } from '../lib/classData';
|
||||
import type { Ability } from '../api/types';
|
||||
import type { Ability, CharacterDetail } from '../api/types';
|
||||
|
||||
// The DM's level picker for one held weapon or item, from the level the gear
|
||||
// starts at up to the maximum. Each option shows what the dice become at that
|
||||
// level, so the step up is visible before choosing.
|
||||
function GearLevelSelect({
|
||||
name,
|
||||
level,
|
||||
entry,
|
||||
onChange,
|
||||
}: {
|
||||
name: string;
|
||||
level: number;
|
||||
entry: { damageDice: string | null; damageScaling: number; minLevel: number };
|
||||
onChange: (level: number) => void;
|
||||
}) {
|
||||
const levels = Array.from({ length: MAX_GEAR_LEVEL - entry.minLevel + 1 }, (_, i) => entry.minLevel + i);
|
||||
return (
|
||||
<select aria-label={`${name} level`} value={level} onChange={(e) => onChange(Number(e.target.value))}>
|
||||
{levels.map((l) => (
|
||||
<option key={l} value={l}>
|
||||
Lv {l}
|
||||
{entry.damageDice ? ` · ${scaledDamageDice(entry.damageDice, l, entry.damageScaling, entry.minLevel)}` : ''}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
);
|
||||
}
|
||||
|
||||
function RequiresLevel({ level }: { level: number }) {
|
||||
return (
|
||||
<span className="badge" style={{ marginLeft: 6 }} title="Held, but can't be used until the character reaches this level">
|
||||
Requires level {level}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
// Lets the owner (or DM) hand something this character holds to another
|
||||
// character in the campaign. Giving moves it: the giver no longer has it.
|
||||
function GiveCard({ character, onError }: { character: CharacterDetail; onError: (err: unknown) => void }) {
|
||||
const { data: characters } = useCampaignCharacters(character.campaignId);
|
||||
const give = useGive(character.id);
|
||||
const [what, setWhat] = useState('');
|
||||
const [amount, setAmount] = useState('1');
|
||||
const [toCharacterId, setToCharacterId] = useState('');
|
||||
const [done, setDone] = useState<string | null>(null);
|
||||
|
||||
const others = characters?.filter((c) => c.id !== character.id && c.buildStage === 'COMPLETE') ?? [];
|
||||
if (others.length === 0) return null;
|
||||
|
||||
// "kind:id" identifies the thing picked; gold has no id.
|
||||
const [kind, id] = what.split(':');
|
||||
const heldWeapon = character.weapons.find((w) => w.weaponId === id);
|
||||
const heldItem = character.inventoryItems.find((i) => i.itemId === id);
|
||||
const max = kind === 'gold' ? character.gold : kind === 'weapon' ? (heldWeapon?.quantity ?? 0) : kind === 'item' ? (heldItem?.quantity ?? 0) : 1;
|
||||
const count = Math.floor(Number(amount));
|
||||
const countOk = kind === 'spell' || (count >= 1 && count <= max);
|
||||
const nothingToGive = character.gold === 0 && character.weapons.length + character.inventoryItems.length + character.spells.length === 0;
|
||||
|
||||
function handleGive() {
|
||||
const gift: Gift | null =
|
||||
kind === 'gold'
|
||||
? { kind, amount: count }
|
||||
: kind === 'weapon' || kind === 'item'
|
||||
? { kind, id, quantity: count }
|
||||
: kind === 'spell'
|
||||
? { kind, id }
|
||||
: null;
|
||||
if (!gift || !toCharacterId) return;
|
||||
setDone(null);
|
||||
give.mutate(
|
||||
{ ...gift, toCharacterId },
|
||||
{
|
||||
onError,
|
||||
onSuccess: () => {
|
||||
setDone(`Given to ${others.find((c) => c.id === toCharacterId)?.name}.`);
|
||||
setWhat('');
|
||||
setAmount('1');
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="card mt-md">
|
||||
<div className="card-title">Give to Another Character</div>
|
||||
<p className="subtitle" style={{ marginTop: 0 }}>
|
||||
Hand gold, a weapon, an item or a spell to someone else in the party. Giving moves it — {character.name} no longer has
|
||||
it afterwards.
|
||||
</p>
|
||||
{nothingToGive ? (
|
||||
<p style={{ color: 'var(--text-muted)', margin: 0 }}>{character.name} has nothing to give yet.</p>
|
||||
) : (
|
||||
<div className="flex-row flex-wrap">
|
||||
<select
|
||||
aria-label="What to give"
|
||||
value={what}
|
||||
onChange={(e) => {
|
||||
setWhat(e.target.value);
|
||||
setAmount('1');
|
||||
setDone(null);
|
||||
}}
|
||||
style={{ flex: 2, minWidth: 160 }}
|
||||
>
|
||||
<option value="">What to give…</option>
|
||||
{character.gold > 0 && <option value="gold:">Gold ({character.gold} gp)</option>}
|
||||
{character.weapons.length > 0 && (
|
||||
<optgroup label="Weapons">
|
||||
{character.weapons.map((w) => (
|
||||
<option key={w.weaponId} value={`weapon:${w.weaponId}`}>
|
||||
{w.weapon.name} (Lv {w.level}, x{w.quantity})
|
||||
</option>
|
||||
))}
|
||||
</optgroup>
|
||||
)}
|
||||
{character.inventoryItems.length > 0 && (
|
||||
<optgroup label="Items">
|
||||
{character.inventoryItems.map((i) => (
|
||||
<option key={i.itemId} value={`item:${i.itemId}`}>
|
||||
{i.item.name} (Lv {i.level}, x{i.quantity})
|
||||
</option>
|
||||
))}
|
||||
</optgroup>
|
||||
)}
|
||||
{character.spells.length > 0 && (
|
||||
<optgroup label="Spells">
|
||||
{character.spells.map((s) => (
|
||||
<option key={s.spellId} value={`spell:${s.spellId}`}>
|
||||
{s.spell.name} ({spellLevelLabel(s.spell.level)})
|
||||
</option>
|
||||
))}
|
||||
</optgroup>
|
||||
)}
|
||||
</select>
|
||||
{what && kind !== 'spell' && (
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
max={max}
|
||||
aria-label={kind === 'gold' ? 'How much gold' : 'How many'}
|
||||
title={kind === 'gold' ? 'How much gold' : `How many (up to ${max})`}
|
||||
value={amount}
|
||||
onChange={(e) => setAmount(e.target.value)}
|
||||
style={{ width: 90 }}
|
||||
/>
|
||||
)}
|
||||
<select aria-label="Who to give it to" value={toCharacterId} onChange={(e) => setToCharacterId(e.target.value)} style={{ flex: 1, minWidth: 130 }}>
|
||||
<option value="">To whom…</option>
|
||||
{others.map((c) => (
|
||||
<option key={c.id} value={c.id}>
|
||||
{c.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<button className="btn" onClick={handleGive} disabled={!what || !toCharacterId || !countOk || give.isPending}>
|
||||
Give
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{done && <p className="subtitle">✓ {done}</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function CharacterSheetPage() {
|
||||
const { characterId = '' } = useParams();
|
||||
@@ -39,29 +211,41 @@ export function CharacterSheetPage() {
|
||||
const { data: campaignData } = useCampaign(character?.campaignId);
|
||||
const { data: campaignWeapons } = useCampaignWeapons(character?.campaignId);
|
||||
const { data: campaignSpells } = useCampaignSpells(character?.campaignId);
|
||||
const { data: campaignItems } = useCampaignItems(character?.campaignId);
|
||||
const { data: goldLedger } = useGoldLedger(characterId);
|
||||
const { data: locations } = useCampaignLocations(character?.campaignId);
|
||||
const { data: notes } = useCharacterNotes(characterId);
|
||||
|
||||
const assignWeapon = useAssignWeapon(characterId);
|
||||
const patchWeapon = usePatchCharacterWeapon(characterId);
|
||||
const addItem = useAddInventoryItem(characterId);
|
||||
const removeWeapon = useRemoveCharacterWeapon(characterId);
|
||||
const assignItem = useAssignItem(characterId);
|
||||
const patchItem = usePatchInventoryItem(characterId);
|
||||
const deleteItem = useDeleteInventoryItem(characterId);
|
||||
const removeItem = useRemoveInventoryItem(characterId);
|
||||
const assignSpell = useAssignSpell(characterId);
|
||||
const patchSpell = usePatchCharacterSpell(characterId);
|
||||
const removeSpell = useRemoveCharacterSpell(characterId);
|
||||
const adjustGold = useAdjustGold(characterId);
|
||||
const createNote = useCreateNote();
|
||||
const { data: campaigns } = useCampaigns();
|
||||
const copyCharacter = useCopyCharacter(characterId);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [hpDelta, setHpDelta] = useState('');
|
||||
const [newItemName, setNewItemName] = useState('');
|
||||
const [pickedItemId, setPickedItemId] = useState('');
|
||||
const [goldAmount, setGoldAmount] = useState('');
|
||||
const [goldReason, setGoldReason] = useState('');
|
||||
const [noteBody, setNoteBody] = useState('');
|
||||
const [pickedWeaponId, setPickedWeaponId] = useState('');
|
||||
const [pickedSpellId, setPickedSpellId] = useState('');
|
||||
const [copyTargetId, setCopyTargetId] = useState('');
|
||||
const [formError, setFormError] = useState<string | null>(null);
|
||||
|
||||
const weaponsPage = usePagination(character?.weapons, 8);
|
||||
const spellsPage = usePagination(character?.spells, 8);
|
||||
const itemsPage = usePagination(character?.inventoryItems, 8);
|
||||
const notesPage = usePagination(notes, 6);
|
||||
const ledgerPage = usePagination(goldLedger, 6);
|
||||
|
||||
if (isLoading) return <Spinner label="Unfurling the character sheet…" />;
|
||||
if (error || !character) return <ErrorBanner message="Could not load this character." />;
|
||||
@@ -99,11 +283,27 @@ export function CharacterSheetPage() {
|
||||
patchCharacter.mutate({ currentHp: newMax });
|
||||
}
|
||||
|
||||
async function handleAddItem(e: FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!newItemName.trim()) return;
|
||||
await addItem.mutateAsync({ name: newItemName });
|
||||
setNewItemName('');
|
||||
async function handleAssignItem() {
|
||||
if (!pickedItemId) return;
|
||||
try {
|
||||
await assignItem.mutateAsync({ itemId: pickedItemId });
|
||||
setPickedItemId('');
|
||||
} catch (err) {
|
||||
setFormError(extractErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
async function handleGold(sign: 1 | -1) {
|
||||
const amount = Math.floor(Number(goldAmount));
|
||||
if (!(amount > 0)) return;
|
||||
setFormError(null);
|
||||
try {
|
||||
await adjustGold.mutateAsync({ amount: sign * amount, reason: goldReason.trim() || undefined });
|
||||
setGoldAmount('');
|
||||
setGoldReason('');
|
||||
} catch (err) {
|
||||
setFormError(extractErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
async function handleAddNote(e: FormEvent) {
|
||||
@@ -133,6 +333,19 @@ export function CharacterSheetPage() {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCopy() {
|
||||
if (!copyTargetId) return;
|
||||
try {
|
||||
const copy = await copyCharacter.mutateAsync(copyTargetId);
|
||||
setCopyTargetId('');
|
||||
navigate(`/campaigns/${copy.campaignId}`);
|
||||
} catch (err) {
|
||||
setFormError(extractErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
const otherCampaigns = campaigns?.filter((c) => c.id !== character.campaignId) ?? [];
|
||||
|
||||
const assignedWeaponIds = new Set(character.weapons.map((w) => w.weaponId));
|
||||
const assignedSpellIds = new Set(character.spells.map((s) => s.spellId));
|
||||
|
||||
@@ -349,26 +562,44 @@ export function CharacterSheetPage() {
|
||||
<div>
|
||||
<strong>{cw.weapon.name}</strong>
|
||||
<span style={{ color: 'var(--text-muted)', marginLeft: 6 }}>
|
||||
{cw.weapon.damageDice} {cw.weapon.damageType} · x{cw.quantity}
|
||||
Lv {cw.level} · {cw.scaledDamageDice} {cw.weapon.damageType} · x{cw.quantity}
|
||||
</span>
|
||||
{!cw.usable && <RequiresLevel level={cw.level} />}
|
||||
</div>
|
||||
{canEdit && (
|
||||
<label className="flex-row gap-sm">
|
||||
Equipped
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={cw.equipped}
|
||||
onChange={(e) => patchWeapon.mutate({ weaponId: cw.weaponId, equipped: e.target.checked })}
|
||||
/>
|
||||
</label>
|
||||
<div className="flex-row gap-sm">
|
||||
<label className="flex-row gap-sm">
|
||||
Equipped
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={cw.equipped}
|
||||
disabled={!cw.usable}
|
||||
onChange={(e) => patchWeapon.mutate({ weaponId: cw.weaponId, equipped: e.target.checked })}
|
||||
/>
|
||||
</label>
|
||||
{isDM && (
|
||||
<>
|
||||
<GearLevelSelect
|
||||
name={cw.weapon.name}
|
||||
level={cw.level}
|
||||
entry={cw.weapon}
|
||||
onChange={(level) => patchWeapon.mutate({ weaponId: cw.weaponId, level })}
|
||||
/>
|
||||
<button className="btn btn-ghost" aria-label={`Take away ${cw.weapon.name}`} onClick={() => removeWeapon.mutate(cw.weaponId)}>
|
||||
✕
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
{character.weapons.length === 0 && <p style={{ color: 'var(--text-muted)' }}>No weapons. The DM hands these out.</p>}
|
||||
<Pagination page={weaponsPage.page} pageCount={weaponsPage.pageCount} onPrev={weaponsPage.prevPage} onNext={weaponsPage.nextPage} />
|
||||
{canEdit && (
|
||||
{isDM && (
|
||||
<div className="flex-row mt-sm flex-wrap">
|
||||
<select value={pickedWeaponId} onChange={(e) => setPickedWeaponId(e.target.value)} style={{ flex: 1, minWidth: 160 }}>
|
||||
<option value="">Add a weapon from the campaign pool…</option>
|
||||
<option value="">Give a weapon from the campaign pool…</option>
|
||||
{campaignWeapons
|
||||
?.filter((w) => !assignedWeaponIds.has(w.id))
|
||||
.map((w) => (
|
||||
@@ -378,7 +609,7 @@ export function CharacterSheetPage() {
|
||||
))}
|
||||
</select>
|
||||
<button className="btn" onClick={handleAssignWeapon} disabled={!pickedWeaponId}>
|
||||
Add
|
||||
Give
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
@@ -391,35 +622,49 @@ export function CharacterSheetPage() {
|
||||
<div key={cs.id} className="flex-between" style={{ padding: '0.4rem 0', borderBottom: '1px solid var(--border-soft)' }}>
|
||||
<div>
|
||||
<strong>{cs.spell.name}</strong>
|
||||
<span style={{ color: 'var(--text-muted)', marginLeft: 6 }}>Lv {cs.spell.level}</span>
|
||||
<span style={{ color: 'var(--text-muted)', marginLeft: 6 }}>
|
||||
{spellLevelLabel(cs.spell.level)}
|
||||
{cs.spell.damageDice && ` · ${cs.spell.damageDice} 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>}
|
||||
</div>
|
||||
{canEdit && (
|
||||
<label className="flex-row gap-sm">
|
||||
Prepared
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={cs.prepared}
|
||||
onChange={(e) => patchSpell.mutate({ spellId: cs.spellId, prepared: e.target.checked })}
|
||||
/>
|
||||
</label>
|
||||
<div className="flex-row gap-sm">
|
||||
<label className="flex-row gap-sm">
|
||||
Prepared
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={cs.prepared}
|
||||
disabled={!cs.usable}
|
||||
onChange={(e) => patchSpell.mutate({ spellId: cs.spellId, prepared: e.target.checked })}
|
||||
/>
|
||||
</label>
|
||||
{isDM && (
|
||||
<button className="btn btn-ghost" aria-label={`Take away ${cs.spell.name}`} onClick={() => removeSpell.mutate(cs.spellId)}>
|
||||
✕
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
{character.spells.length === 0 && <p style={{ color: 'var(--text-muted)' }}>No spells known. The DM grants these.</p>}
|
||||
<Pagination page={spellsPage.page} pageCount={spellsPage.pageCount} onPrev={spellsPage.prevPage} onNext={spellsPage.nextPage} />
|
||||
{canEdit && (
|
||||
{isDM && (
|
||||
<div className="flex-row mt-sm flex-wrap">
|
||||
<select value={pickedSpellId} onChange={(e) => setPickedSpellId(e.target.value)} style={{ flex: 1, minWidth: 160 }}>
|
||||
<option value="">Add a spell from the campaign list…</option>
|
||||
<option value="">Grant a spell from the campaign list…</option>
|
||||
{campaignSpells
|
||||
.filter((s) => !assignedSpellIds.has(s.id))
|
||||
.map((s) => (
|
||||
<option key={s.id} value={s.id}>
|
||||
{s.name} (Lv {s.level})
|
||||
{s.name} ({spellLevelLabel(s.level)})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<button className="btn" onClick={handleAssignSpell} disabled={!pickedSpellId}>
|
||||
Add
|
||||
Grant
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
@@ -428,11 +673,18 @@ export function CharacterSheetPage() {
|
||||
|
||||
<div className="card mt-md">
|
||||
<div className="card-title">Inventory</div>
|
||||
{itemsPage.pageItems.map((item) => (
|
||||
<div key={item.id} className="flex-between" style={{ padding: '0.4rem 0', borderBottom: '1px solid var(--border-soft)' }}>
|
||||
{itemsPage.pageItems.map((held) => (
|
||||
<div key={held.id} className="flex-between" style={{ padding: '0.4rem 0', borderBottom: '1px solid var(--border-soft)' }}>
|
||||
<div>
|
||||
<strong>{item.name}</strong>
|
||||
<span style={{ color: 'var(--text-muted)', marginLeft: 6 }}>x{item.quantity}</span>
|
||||
<strong>{held.item.name}</strong>
|
||||
<span style={{ color: 'var(--text-muted)', marginLeft: 6 }}>
|
||||
Lv {held.level}
|
||||
{held.scaledDamageDice && ` · ${held.scaledDamageDice}`} · x{held.quantity}
|
||||
</span>
|
||||
{!held.usable && <RequiresLevel level={held.level} />}
|
||||
{held.item.description && (
|
||||
<div style={{ color: 'var(--text-muted)', fontSize: '0.85rem' }}>{held.item.description}</div>
|
||||
)}
|
||||
</div>
|
||||
{canEdit && (
|
||||
<div className="flex-row gap-sm">
|
||||
@@ -440,67 +692,178 @@ export function CharacterSheetPage() {
|
||||
Equipped
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={item.equipped}
|
||||
onChange={(e) => patchItem.mutate({ itemId: item.id, equipped: e.target.checked })}
|
||||
checked={held.equipped}
|
||||
disabled={!held.usable}
|
||||
onChange={(e) => patchItem.mutate({ itemId: held.itemId, equipped: e.target.checked })}
|
||||
/>
|
||||
</label>
|
||||
<button className="btn btn-ghost" onClick={() => deleteItem.mutate(item.id)}>
|
||||
✕
|
||||
</button>
|
||||
{isDM && (
|
||||
<>
|
||||
<GearLevelSelect
|
||||
name={held.item.name}
|
||||
level={held.level}
|
||||
entry={held.item}
|
||||
onChange={(level) => patchItem.mutate({ itemId: held.itemId, level })}
|
||||
/>
|
||||
<button
|
||||
className="btn btn-ghost"
|
||||
aria-label={`One fewer ${held.item.name}`}
|
||||
disabled={held.quantity <= 1}
|
||||
onClick={() => patchItem.mutate({ itemId: held.itemId, quantity: held.quantity - 1 })}
|
||||
>
|
||||
−
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-ghost"
|
||||
aria-label={`One more ${held.item.name}`}
|
||||
onClick={() => patchItem.mutate({ itemId: held.itemId, quantity: held.quantity + 1 })}
|
||||
>
|
||||
+
|
||||
</button>
|
||||
<button className="btn btn-ghost" aria-label={`Take away ${held.item.name}`} onClick={() => removeItem.mutate(held.itemId)}>
|
||||
✕
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
{character.inventoryItems.length === 0 && <p style={{ color: 'var(--text-muted)' }}>Nothing carried. The DM hands out items.</p>}
|
||||
<Pagination page={itemsPage.page} pageCount={itemsPage.pageCount} onPrev={itemsPage.prevPage} onNext={itemsPage.nextPage} />
|
||||
{canEdit && (
|
||||
<form onSubmit={handleAddItem} className="flex-row mt-sm flex-wrap">
|
||||
<input
|
||||
placeholder="New item name"
|
||||
value={newItemName}
|
||||
onChange={(e) => setNewItemName(e.target.value)}
|
||||
style={{ flex: 1, minWidth: 160 }}
|
||||
/>
|
||||
<button type="submit" className="btn">
|
||||
Add Item
|
||||
{isDM && (
|
||||
<div className="flex-row mt-sm flex-wrap">
|
||||
<select value={pickedItemId} onChange={(e) => setPickedItemId(e.target.value)} style={{ flex: 1, minWidth: 160 }}>
|
||||
<option value="">Give an item from the campaign pool…</option>
|
||||
{campaignItems?.map((item) => (
|
||||
<option key={item.id} value={item.id}>
|
||||
{item.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<button className="btn" onClick={handleAssignItem} disabled={!pickedItemId}>
|
||||
Give
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
)}
|
||||
{isDM && campaignItems?.length === 0 && (
|
||||
<p className="subtitle">The item pool is empty — add items on the campaign page first.</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{canEdit && (
|
||||
<div className="card mt-md">
|
||||
<div className="card-title">
|
||||
<span>Money</span>
|
||||
<span className="mono">{character.gold} gp</span>
|
||||
</div>
|
||||
{canEdit && (
|
||||
<div className="flex-row flex-wrap">
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
placeholder="Amount"
|
||||
aria-label="Gold amount"
|
||||
value={goldAmount}
|
||||
onChange={(e) => setGoldAmount(e.target.value)}
|
||||
style={{ width: 100 }}
|
||||
/>
|
||||
<input
|
||||
placeholder="What for? (optional)"
|
||||
aria-label="Reason"
|
||||
maxLength={200}
|
||||
value={goldReason}
|
||||
onChange={(e) => setGoldReason(e.target.value)}
|
||||
style={{ flex: 1, minWidth: 160 }}
|
||||
/>
|
||||
<button className="btn" onClick={() => handleGold(1)} disabled={!goldAmount || adjustGold.isPending}>
|
||||
+ Gain
|
||||
</button>
|
||||
<button className="btn btn-danger" onClick={() => handleGold(-1)} disabled={!goldAmount || adjustGold.isPending}>
|
||||
− Spend
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<div className="mt-sm">
|
||||
{goldLedger?.length === 0 && <p style={{ color: 'var(--text-muted)' }}>No transactions yet.</p>}
|
||||
{ledgerPage.pageItems.map((t) => (
|
||||
<div key={t.id} className="flex-between" style={{ padding: '0.4rem 0', borderBottom: '1px solid var(--border-soft)' }}>
|
||||
<div>
|
||||
<strong className="mono">{t.amount > 0 ? `+${t.amount}` : `−${Math.abs(t.amount)}`}</strong>
|
||||
<span style={{ marginLeft: 8 }}>{t.reason || (t.amount > 0 ? 'Gained' : 'Spent')}</span>
|
||||
<div style={{ fontSize: '0.75rem', color: 'var(--text-dim)' }}>
|
||||
{t.createdBy ? `${t.createdBy.displayName} · ` : ''}
|
||||
{new Date(t.createdAt).toLocaleString()}
|
||||
</div>
|
||||
</div>
|
||||
<span className="mono" style={{ color: 'var(--text-muted)' }}>{t.balanceAfter} gp</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<Pagination page={ledgerPage.page} pageCount={ledgerPage.pageCount} onPrev={ledgerPage.prevPage} onNext={ledgerPage.nextPage} />
|
||||
</div>
|
||||
|
||||
{/* Composed by the character builder from the player's picks. Players
|
||||
read them; only the DM can rewrite them (new abilities on level-up,
|
||||
a scar earned in play). */}
|
||||
{(
|
||||
[
|
||||
['specialAbilities', 'Special Abilities', 'One per line, e.g. “Reckless Attack — gained at level 2.”', 6],
|
||||
['background', 'Background', 'Where this character came from, what drives them…', 5],
|
||||
['appearance', 'Appearance', 'Height, build, notable features, typical outfit…', 5],
|
||||
] as const
|
||||
).map(([field, title, placeholder, rows]) => (
|
||||
<div className="card mt-md" key={field}>
|
||||
<div className="card-title">
|
||||
<span>{title}</span>
|
||||
{isDM && <span className="badge">DM can edit</span>}
|
||||
</div>
|
||||
{isDM ? (
|
||||
<textarea
|
||||
key={`${field}:${character[field] ?? ''}`}
|
||||
className="textarea-block"
|
||||
rows={rows}
|
||||
defaultValue={character[field] ?? ''}
|
||||
placeholder={placeholder}
|
||||
aria-label={title}
|
||||
onBlur={(e) => {
|
||||
const value = e.target.value.trim() || null;
|
||||
if (value !== (character[field] ?? null)) patchCharacter.mutate({ [field]: value });
|
||||
}}
|
||||
/>
|
||||
) : character[field] ? (
|
||||
<p className="composed-text">{character[field]}</p>
|
||||
) : (
|
||||
<p className="subtitle" style={{ margin: 0 }}>
|
||||
Nothing here yet. Your DM can fill this in.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
|
||||
{canEdit && <GiveCard character={character} onError={(err) => setFormError(extractErrorMessage(err))} />}
|
||||
|
||||
{canEdit && otherCampaigns.length > 0 && (
|
||||
<div className="card mt-md">
|
||||
<div className="card-title">Special Abilities</div>
|
||||
<textarea
|
||||
rows={3}
|
||||
defaultValue={character.specialAbilities || ''}
|
||||
placeholder="Darkvision, Second Wind, Sneak Attack, etc."
|
||||
onBlur={(e) => patchCharacter.mutate({ specialAbilities: e.target.value })}
|
||||
/>
|
||||
<div className="card-title">Copy to Another Campaign</div>
|
||||
<p className="subtitle" style={{ marginTop: 0 }}>
|
||||
Makes an independent copy at full HP with the same stats, gear and spells. This character stays here unchanged.
|
||||
</p>
|
||||
<div className="flex-row flex-wrap">
|
||||
<select value={copyTargetId} onChange={(e) => setCopyTargetId(e.target.value)} style={{ flex: 1, minWidth: 160 }}>
|
||||
<option value="">Choose a campaign…</option>
|
||||
{otherCampaigns.map((c) => (
|
||||
<option key={c.id} value={c.id}>
|
||||
{c.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<button className="btn" onClick={handleCopy} disabled={!copyTargetId || copyCharacter.isPending}>
|
||||
{copyCharacter.isPending ? 'Copying…' : 'Copy Character'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="card mt-md">
|
||||
<div className="card-title">Background</div>
|
||||
<textarea
|
||||
rows={4}
|
||||
defaultValue={character.background || ''}
|
||||
placeholder={canEdit ? "Where this character came from, what drives them…" : 'No background written yet.'}
|
||||
readOnly={!canEdit}
|
||||
onBlur={(e) => canEdit && patchCharacter.mutate({ background: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="card mt-md">
|
||||
<div className="card-title">Appearance</div>
|
||||
<textarea
|
||||
rows={3}
|
||||
defaultValue={character.appearance || ''}
|
||||
placeholder={canEdit ? 'Height, build, notable features, typical outfit…' : 'No appearance written yet.'}
|
||||
readOnly={!canEdit}
|
||||
onBlur={(e) => canEdit && patchCharacter.mutate({ appearance: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{isOwner && (
|
||||
<div className="card mt-md">
|
||||
<div className="card-title">Private Notes</div>
|
||||
|
||||
Reference in New Issue
Block a user