V1.13.0: a campaign page in parts, pop-outs, and a search
- The campaign page shows one part at a time, picked from a row of buttons under its name: Overview (characters and encounters), NPCs, Locations, Weapons, Items, Spells, Monsters, Notes and Settings for the DM; Overview, Places and Notes for a player. Each button counts what is in its part. On a phone the row scrolls sideways. The part showing is in the address (?view=weapons), so the back button steps through the parts. - NPCs, weapons, items, spells and monsters are lists of short rows. Clicking a row opens a pop-out with everything about it and everything that can be changed. Adding one, by hand or from the library, is a pop-out too: a window on a wide screen, the whole screen on a phone. - "Search this campaign" looks through everything added to the campaign at once: characters, encounters, locations and notes, and for the DM also NPCs, weapons, items, spells and monsters. Each of the DM's lists has a search box of its own as well. - With three pages or more, the page number of a paged list is a menu to jump straight to any page. - The invite code, the party and archive or delete are under Settings. - A weapon's properties and range, and a spell's casting time, range and duration, are shown in its pop-out. - All packages at version 1.13.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,347 @@
|
||||
import { useState, type ReactNode } from 'react';
|
||||
import { useDeleteMonster, useDeletePoolEntry, usePatchPoolEntry, useUpdateMonster } from '../../api/queries';
|
||||
import { Modal } from '../Modal';
|
||||
import { NumberInput } from '../NumberInput';
|
||||
import { ErrorBanner } from '../Spinner';
|
||||
import { EffectsEditor } from '../EffectsEditor';
|
||||
import { WaresEditor } from '../Wares';
|
||||
import { extractErrorMessage, fmtMod, spellLevelLabel, spellRequirementLabel } from '../../lib/format';
|
||||
import { abilityLine, rateLabel, type EntryRef } from '../../lib/campaignEntries';
|
||||
import { Field, MonsterForm, ScalingSelect, SpellDamageSelect, StartLevelSelect } from './parts';
|
||||
import type { GearEffect, Item, Monster, Npc, Spell, Weapon } from '../../api/types';
|
||||
|
||||
const ATTACK_ABILITY_LABELS: Record<Weapon['attackAbility'], string> = { STR: 'STR', DEX: 'DEX', FINESSE: 'Finesse (the better of STR and DEX)' };
|
||||
|
||||
function Chip({ label, children }: { label: string; children: ReactNode }) {
|
||||
return (
|
||||
<div className="stat-chip">
|
||||
<span>{label}</span>
|
||||
<b>{children}</b>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// The foot of every pop-out: taking the thing out of the campaign.
|
||||
function RemoveButton({ name, warning, pending, onRemove }: { name: string; warning: string; pending: boolean; onRemove: () => void }) {
|
||||
return (
|
||||
<div className="modal-foot">
|
||||
<button className="btn btn-danger" disabled={pending} onClick={() => window.confirm(`Remove ${name}? ${warning}`) && onRemove()}>
|
||||
Remove from campaign
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// A weapon or an item: the two share levels, growth and effects.
|
||||
function GearDetail({ campaignId, pool, entry, onClose }: { campaignId: string; pool: 'weapons' | 'items'; entry: Weapon | Item; onClose: () => void }) {
|
||||
const patch = usePatchPoolEntry(campaignId, pool);
|
||||
const remove = useDeletePoolEntry(campaignId, pool);
|
||||
const [effects, setEffects] = useState<GearEffect[]>(entry.effects ?? []);
|
||||
const [note, setNote] = useState(entry.effectNote ?? '');
|
||||
const [effectsSaved, setEffectsSaved] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const onError = (err: unknown) => setError(extractErrorMessage(err));
|
||||
const weapon = 'damageType' in entry ? entry : null;
|
||||
|
||||
return (
|
||||
<Modal title={entry.name} subtitle={weapon ? 'Weapon' : 'Item'} onClose={onClose}>
|
||||
{error && <ErrorBanner message={error} />}
|
||||
<div className="stat-chips">
|
||||
{weapon ? (
|
||||
<>
|
||||
<Chip label="Base damage">
|
||||
{weapon.damageDice} {weapon.damageType}
|
||||
</Chip>
|
||||
<Chip label="Attacks with">{ATTACK_ABILITY_LABELS[weapon.attackAbility]}</Chip>
|
||||
{weapon.rangeNormal && (
|
||||
<Chip label="Range">
|
||||
{weapon.rangeNormal}
|
||||
{weapon.rangeLong ? `/${weapon.rangeLong}` : ''} ft
|
||||
</Chip>
|
||||
)}
|
||||
{weapon.properties.length > 0 && <Chip label="Properties">{weapon.properties.join(', ')}</Chip>}
|
||||
</>
|
||||
) : (
|
||||
entry.damageDice && <Chip label="Base dice">{entry.damageDice}</Chip>
|
||||
)}
|
||||
</div>
|
||||
{!weapon && 'description' in entry && entry.description && <p className="mt-sm" style={{ whiteSpace: 'pre-wrap' }}>{entry.description}</p>}
|
||||
|
||||
<div className="grid grid-cols-2 mt-md">
|
||||
<Field label="Level it starts at">
|
||||
{(id) => <StartLevelSelect id={id} value={entry.minLevel} onChange={(minLevel) => patch.mutate({ id: entry.id, minLevel }, { onError })} />}
|
||||
</Field>
|
||||
{entry.damageDice && (
|
||||
<Field label="Growth per level">
|
||||
{(id) => <ScalingSelect id={id} value={entry.damageScaling} onChange={(damageScaling) => patch.mutate({ id: entry.id, damageScaling }, { onError })} />}
|
||||
</Field>
|
||||
)}
|
||||
</div>
|
||||
<p className="combatant-sub mt-sm">
|
||||
A character must be at least its level to use it.
|
||||
{entry.damageDice &&
|
||||
' The dice above are what it does at the level it starts at. When you level up a character\'s copy they grow one small step per level (1d4 → 1d6 → 1d8 → 1d10 → 1d12 → 2d6 → …): two steps for Powerful gear, three for Legendary.'}
|
||||
</p>
|
||||
<label className="checkbox-row mt-md">
|
||||
<input type="checkbox" checked={entry.isStartingOption} onChange={(e) => patch.mutate({ id: entry.id, isStartingOption: e.target.checked }, { onError })} />
|
||||
Starting option: a player may pick it while building a character
|
||||
</label>
|
||||
|
||||
<div className="section-label mt-md">While equipped</div>
|
||||
<p className="combatant-sub" style={{ marginTop: 0 }}>
|
||||
These count for a character only while it is equipped and they are high enough level to use it. Armor is an item with
|
||||
+AC; a penalty is a negative number.
|
||||
</p>
|
||||
<EffectsEditor
|
||||
effects={effects}
|
||||
note={note}
|
||||
onChange={(nextEffects, nextNote) => {
|
||||
setEffects(nextEffects);
|
||||
setNote(nextNote);
|
||||
setEffectsSaved(false);
|
||||
}}
|
||||
/>
|
||||
<div className="flex-row mt-sm">
|
||||
<button
|
||||
className="btn btn-primary"
|
||||
disabled={patch.isPending}
|
||||
onClick={() => patch.mutate({ id: entry.id, effects, effectNote: note.trim() || null }, { onError, onSuccess: () => setEffectsSaved(true) })}
|
||||
>
|
||||
Save Effects
|
||||
</button>
|
||||
{effectsSaved && <span className="combatant-sub">Saved.</span>}
|
||||
</div>
|
||||
|
||||
<RemoveButton name={entry.name} warning="Any character holding it loses it." pending={remove.isPending} onRemove={() => remove.mutate(entry.id, { onError, onSuccess: onClose })} />
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function SpellDetail({ campaignId, spell, onClose }: { campaignId: string; spell: Spell; onClose: () => void }) {
|
||||
const patch = usePatchPoolEntry(campaignId, 'spells');
|
||||
const remove = useDeletePoolEntry(campaignId, 'spells');
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const onError = (err: unknown) => setError(extractErrorMessage(err));
|
||||
|
||||
return (
|
||||
<Modal title={spell.name} subtitle={[spellLevelLabel(spell.level), spell.school, spellRequirementLabel(spell.level)].filter(Boolean).join(' · ')} onClose={onClose}>
|
||||
{error && <ErrorBanner message={error} />}
|
||||
<div className="stat-chips">
|
||||
{spell.castingTime && <Chip label="Casting time">{spell.castingTime}</Chip>}
|
||||
{spell.range && <Chip label="Range">{spell.range}</Chip>}
|
||||
{spell.duration && <Chip label="Duration">{spell.duration}</Chip>}
|
||||
</div>
|
||||
<p className="mt-sm" style={{ whiteSpace: 'pre-wrap' }}>{spell.description || 'No description.'}</p>
|
||||
|
||||
<div className="grid grid-cols-2 mt-md">
|
||||
<Field label="Damage">
|
||||
{(id) => <SpellDamageSelect id={id} spellName={spell.name} value={spell.damageDice} onChange={(damageDice) => patch.mutate({ id: spell.id, damageDice }, { onError })} />}
|
||||
</Field>
|
||||
</div>
|
||||
<label className="checkbox-row mt-md">
|
||||
<input type="checkbox" checked={spell.isStartingOption} onChange={(e) => patch.mutate({ id: spell.id, isStartingOption: e.target.checked }, { onError })} />
|
||||
Starting option: a player may pick it while building a character
|
||||
</label>
|
||||
<label className="checkbox-row mt-sm">
|
||||
<input type="checkbox" checked={spell.revives} onChange={(e) => patch.mutate({ id: spell.id, revives: e.target.checked }, { onError })} />
|
||||
Revives the dead: a character who can cast it may revive a dead ally on their turn in a battle
|
||||
</label>
|
||||
|
||||
<RemoveButton name={spell.name} warning="Any character holding it loses it." pending={remove.isPending} onRemove={() => remove.mutate(spell.id, { onError, onSuccess: onClose })} />
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function MonsterDetail({ campaignId, monster, onClose }: { campaignId: string; monster: Monster; onClose: () => void }) {
|
||||
const update = useUpdateMonster(campaignId);
|
||||
const remove = useDeleteMonster(campaignId);
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const onError = (err: unknown) => setError(extractErrorMessage(err));
|
||||
|
||||
return (
|
||||
<Modal title={editing ? `Editing ${monster.name}` : monster.name} subtitle="Monster" wide onClose={onClose}>
|
||||
{error && <ErrorBanner message={error} />}
|
||||
{editing ? (
|
||||
<MonsterForm
|
||||
monster={monster}
|
||||
saving={update.isPending}
|
||||
onCancel={() => setEditing(false)}
|
||||
onSave={async (stats) => {
|
||||
setError(null);
|
||||
try {
|
||||
await update.mutateAsync({ id: monster.id, ...stats });
|
||||
setEditing(false);
|
||||
} catch (err) {
|
||||
onError(err);
|
||||
throw err;
|
||||
}
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<div className="stat-chips">
|
||||
<Chip label="CR">{monster.challengeRating || '—'}</Chip>
|
||||
<Chip label="AC">{monster.ac}</Chip>
|
||||
<Chip label="HP">{monster.maxHp}</Chip>
|
||||
<Chip label="Speed">{monster.speed}</Chip>
|
||||
<Chip label="Attack">{fmtMod(monster.attackBonus)}</Chip>
|
||||
<Chip label="Damage">{monster.damageDice || '—'}</Chip>
|
||||
</div>
|
||||
<p className="mono mt-sm" style={{ color: 'var(--text-muted)', fontSize: '0.9rem' }}>{abilityLine(monster)}</p>
|
||||
{monster.specialTrait && (
|
||||
<p>
|
||||
<strong>Trait:</strong> {monster.specialTrait}
|
||||
</p>
|
||||
)}
|
||||
{monster.notes && <p style={{ color: 'var(--text-muted)', whiteSpace: 'pre-wrap' }}>{monster.notes}</p>}
|
||||
<button className="btn" onClick={() => setEditing(true)}>
|
||||
Edit stat block
|
||||
</button>
|
||||
<RemoveButton
|
||||
name={monster.name}
|
||||
warning="Copies already in encounters stay, but lose their stat block."
|
||||
pending={remove.isPending}
|
||||
onRemove={() => remove.mutate(monster.id, { onError, onSuccess: onClose })}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
// An NPC: who they are, and what they trade — the rate they change gold and
|
||||
// cash at, and their wares. Players meet both on the encounter page, in a
|
||||
// quest the NPC is part of.
|
||||
function NpcDetail({ campaignId, npc, weapons, items, onClose }: { campaignId: string; npc: Npc; weapons: Weapon[]; items: Item[]; onClose: () => void }) {
|
||||
const patch = usePatchPoolEntry(campaignId, 'npcs');
|
||||
const remove = useDeletePoolEntry(campaignId, 'npcs');
|
||||
const [gold, setGold] = useState(npc.exchangeGold ? String(npc.exchangeGold) : '');
|
||||
const [cash, setCash] = useState(npc.exchangeCash ? String(npc.exchangeCash) : '');
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const onError = (err: unknown) => setError(extractErrorMessage(err));
|
||||
const rate = rateLabel(npc);
|
||||
const hasStats = npc.ac !== null || npc.maxHp !== null || npc.attackBonus !== null || Boolean(npc.damageDice);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={npc.name}
|
||||
subtitle={
|
||||
<span className="flex-row flex-wrap gap-sm">
|
||||
{npc.role || 'NPC'}
|
||||
<span className={`badge badge-${npc.disposition.toLowerCase()}`}>{npc.disposition}</span>
|
||||
{rate && <span className="badge">💱 {rate}</span>}
|
||||
</span>
|
||||
}
|
||||
wide
|
||||
onClose={onClose}
|
||||
>
|
||||
{error && <ErrorBanner message={error} />}
|
||||
{npc.description ? <p style={{ whiteSpace: 'pre-wrap' }}>{npc.description}</p> : <p style={{ color: 'var(--text-muted)' }}>No description for the players.</p>}
|
||||
{npc.dmNotes && <p style={{ color: 'var(--text-muted)', whiteSpace: 'pre-wrap' }}>🔒 {npc.dmNotes}</p>}
|
||||
{hasStats && (
|
||||
<div className="stat-chips">
|
||||
{npc.ac !== null && <Chip label="AC">{npc.ac}</Chip>}
|
||||
{npc.maxHp !== null && <Chip label="HP">{npc.maxHp}</Chip>}
|
||||
{npc.attackBonus !== null && <Chip label="Attack">{fmtMod(npc.attackBonus)}</Chip>}
|
||||
{npc.damageDice && <Chip label="Damage">{npc.damageDice}</Chip>}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="section-label mt-md">Changes money</div>
|
||||
<p className="combatant-sub" style={{ marginTop: 0 }}>
|
||||
Set a rate and the party can change gold into cash, or cash into gold, with {npc.name}. Silver and copper are not
|
||||
taken. Leave it empty for someone who does not change money.
|
||||
</p>
|
||||
<div className="flex-row flex-wrap gap-sm">
|
||||
<NumberInput min={1} max={1000000} aria-label="Gold side of the rate" placeholder="Gold" value={gold} onChange={(e) => setGold(e.target.value)} style={{ width: 90 }} />
|
||||
<span>gold =</span>
|
||||
<span>$</span>
|
||||
<NumberInput min={1} max={1000000} aria-label="Cash side of the rate" placeholder="Cash" value={cash} onChange={(e) => setCash(e.target.value)} style={{ width: 90 }} />
|
||||
<button
|
||||
className="btn"
|
||||
disabled={!gold || !cash || patch.isPending}
|
||||
onClick={() => patch.mutate({ id: npc.id, exchangeGold: Number(gold), exchangeCash: Number(cash) }, { onError })}
|
||||
>
|
||||
Save rate
|
||||
</button>
|
||||
{rate && (
|
||||
<button
|
||||
className="btn btn-ghost"
|
||||
disabled={patch.isPending}
|
||||
onClick={() =>
|
||||
patch.mutate(
|
||||
{ id: npc.id, exchangeGold: null, exchangeCash: null },
|
||||
{
|
||||
onError,
|
||||
onSuccess: () => {
|
||||
setGold('');
|
||||
setCash('');
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
||||
>
|
||||
Stop changing money
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="section-label mt-md">For sale</div>
|
||||
<WaresEditor campaignId={campaignId} seller={{ npcId: npc.id }} wares={npc.wares ?? []} weapons={weapons} items={items} onError={onError} />
|
||||
|
||||
<RemoveButton
|
||||
name={npc.name}
|
||||
warning="They leave every encounter they are in, and their wares go with them."
|
||||
pending={remove.isPending}
|
||||
onRemove={() => remove.mutate(npc.id, { onError, onSuccess: onClose })}
|
||||
/>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
// The pop-out for whichever weapon, item, spell, monster or NPC is open.
|
||||
// Nothing shows if it is no longer in the campaign.
|
||||
export function EntryDetail({
|
||||
campaignId,
|
||||
entry,
|
||||
weapons,
|
||||
items,
|
||||
spells,
|
||||
monsters,
|
||||
npcs,
|
||||
onClose,
|
||||
}: {
|
||||
campaignId: string;
|
||||
entry: EntryRef;
|
||||
weapons: Weapon[];
|
||||
items: Item[];
|
||||
spells: Spell[];
|
||||
monsters: Monster[];
|
||||
npcs: Npc[];
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const find = <T extends { id: string }>(list: T[]) => list.find((e) => e.id === entry.id);
|
||||
switch (entry.kind) {
|
||||
case 'weapon': {
|
||||
const weapon = find(weapons);
|
||||
return weapon ? <GearDetail key={weapon.id} campaignId={campaignId} pool="weapons" entry={weapon} onClose={onClose} /> : null;
|
||||
}
|
||||
case 'item': {
|
||||
const item = find(items);
|
||||
return item ? <GearDetail key={item.id} campaignId={campaignId} pool="items" entry={item} onClose={onClose} /> : null;
|
||||
}
|
||||
case 'spell': {
|
||||
const spell = find(spells);
|
||||
return spell ? <SpellDetail key={spell.id} campaignId={campaignId} spell={spell} onClose={onClose} /> : null;
|
||||
}
|
||||
case 'monster': {
|
||||
const monster = find(monsters);
|
||||
return monster ? <MonsterDetail key={monster.id} campaignId={campaignId} monster={monster} onClose={onClose} /> : null;
|
||||
}
|
||||
case 'npc': {
|
||||
const npc = find(npcs);
|
||||
return npc ? <NpcDetail key={npc.id} campaignId={campaignId} npc={npc} weapons={weapons} items={items} onClose={onClose} /> : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user