Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0141G6xqLeNRYEtviLWSB5Up
543 lines
15 KiB
Svelte
543 lines
15 KiB
Svelte
<script lang="ts">
|
|
import Chronicle from './Chronicle.svelte';
|
|
import HandPicker from './HandPicker.svelte';
|
|
import Ledger from './Ledger.svelte';
|
|
import MobileBar from './MobileBar.svelte';
|
|
import Roster from './Roster.svelte';
|
|
import SpellSheet from './SpellSheet.svelte';
|
|
import TableTalk from './TableTalk.svelte';
|
|
import TurnSummary from './TurnSummary.svelte';
|
|
import WizardStatus from './WizardStatus.svelte';
|
|
import { castKey, listText, tokensText, type Duel } from '$lib/game/duel.svelte';
|
|
import { seatColor } from '$lib/game/colors';
|
|
import { GESTURE_SHORT, glyph } from '$lib/game/glyphs';
|
|
import { MAGIC_GESTURES, type Gesture } from '$lib/game/spells';
|
|
|
|
let { duel }: { duel: Duel } = $props();
|
|
|
|
const foeMonsters = $derived(duel.state.monsters.filter((m) => m.owner !== duel.me));
|
|
const outcome = $derived(duel.state.over);
|
|
const won = $derived(outcome?.winner === duel.me);
|
|
/** With three or more opponents the rail shows a one-line roster instead of a status card each. */
|
|
const crowded = $derived(duel.others.length >= 3);
|
|
/** The seal button's label for the current state. */
|
|
const sealLabel = $derived(
|
|
duel.moved ? 'Waiting' : duel.sending ? 'Sending' : duel.surrendering ? 'Surrender' : duel.timeStopped ? 'Act in the stopped moment' : 'Seal the turn'
|
|
);
|
|
|
|
/** Letters typed anywhere on the board fill the hands, left then right; Enter seals the turn. */
|
|
const KEYS: Record<string, Gesture> = { f: 'F', p: 'P', s: 'S', w: 'W', d: 'D', c: 'C', k: '>', '>': '>', '-': '-', '.': '-', ' ': '-' };
|
|
function onKey(e: KeyboardEvent) {
|
|
if (e.metaKey || e.ctrlKey || e.altKey) return;
|
|
const el = e.target as HTMLElement | null;
|
|
if (el && (el.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(el.tagName))) return;
|
|
if (outcome || duel.out || duel.moved || duel.spectating) return;
|
|
if (e.key === 'Enter') {
|
|
if (duel.ready) {
|
|
e.preventDefault();
|
|
duel.reveal();
|
|
}
|
|
return;
|
|
}
|
|
if (e.key === 'Backspace') {
|
|
e.preventDefault();
|
|
duel.untype();
|
|
return;
|
|
}
|
|
const g = KEYS[e.key.toLowerCase()];
|
|
if (g && duel.typeGesture(g)) e.preventDefault();
|
|
}
|
|
</script>
|
|
|
|
<svelte:window onkeydown={onKey} />
|
|
|
|
<main class="board">
|
|
<section class="play">
|
|
<Ledger {duel} />
|
|
<TurnSummary {duel} />
|
|
|
|
{#if outcome}
|
|
<div class="verdict" id="verdict" class:won>
|
|
<h2>{duel.spectating ? (outcome.winner === null ? 'A draw.' : `${duel.state.wizards[outcome.winner].name} wins.`) : won ? 'You win.' : outcome.winner === null ? 'A draw.' : 'You lose.'}</h2>
|
|
<p>{outcome.reason}</p>
|
|
{#if duel.remote}
|
|
<a class="reveal again" href="/">Back to the hall</a>
|
|
{:else}
|
|
<button type="button" class="reveal" onclick={() => duel.newGame()}>Duel again</button>
|
|
{/if}
|
|
</div>
|
|
{:else}
|
|
{#if duel.spectating}
|
|
<section class="move out" aria-labelledby="move-heading">
|
|
<h2 id="move-heading">You watch from the Peanut Gallery</h2>
|
|
<p class="threats muted">{duel.awaitingText ? `${duel.awaitingText} ${duel.awaiting.length === 1 ? 'is' : 'are'} still writing turn ${duel.turnNumber}.` : `Turn ${duel.turnNumber} is being written.`} The gallery sees only what every wizard at the table can see.</p>
|
|
</section>
|
|
{:else if duel.out}
|
|
<section class="move out" aria-labelledby="move-heading">
|
|
<h2 id="move-heading">{duel.you.alive ? 'You have yielded' : 'You have fallen'}</h2>
|
|
<p class="threats muted">The duel goes on without you. Watch the ledger fill; {listText(duel.others.filter((id) => duel.state.wizards[id].alive && !duel.state.wizards[id].surrendered).map((id) => duel.state.wizards[id].name))} still stand.</p>
|
|
</section>
|
|
{:else}
|
|
<section class="move" aria-labelledby="move-heading">
|
|
{#if duel.timeStopped}
|
|
<h2 id="move-heading">Time stands still. Take your extra turn.</h2>
|
|
<p class="threats"><span class="muted">{duel.foe.name} cannot move, see this, or resist anything you do. Last turn's enchantments do not bind you.</span></p>
|
|
{:else}
|
|
<h2 id="move-heading">Your gestures for turn {duel.turnNumber}{#if duel.hasted}, twice over{/if}</h2>
|
|
{/if}
|
|
|
|
{#if duel.threats.length && !duel.timeStopped}
|
|
<div class="threats">
|
|
{#if duel.threatsNow.length}
|
|
<p>Their hands could finish this turn:</p>
|
|
<ul>
|
|
{#each duel.threatsNow as t (duel.threatKey(t))}
|
|
{@const active = duel.isHighlighted(t)}
|
|
<li>
|
|
<button type="button" class="threat soon" class:active aria-pressed={active} onclick={() => duel.toggleHighlight(t)}>
|
|
<span class="thand">{#if duel.others.length > 1}<span class="dot" style="background: {seatColor(duel.state, t.who)}"></span>{`${duel.state.wizards[t.who].name}, `}{/if}{t.hand}</span>
|
|
<span class="tseq">{tokensText(t.done)} → <strong>{tokensText(t.remaining)}</strong></span>
|
|
<span class="tname">{t.spell.name}</span>
|
|
</button>
|
|
</li>
|
|
{/each}
|
|
</ul>
|
|
{/if}
|
|
{#if duel.threatsNext.length}
|
|
<details class="next" open={!duel.compact}>
|
|
<summary class="muted">Two gestures away ({duel.threatsNext.length})</summary>
|
|
<ul>
|
|
{#each duel.threatsNext as t (duel.threatKey(t))}
|
|
{@const active = duel.isHighlighted(t)}
|
|
<li>
|
|
<button type="button" class="threat" class:active aria-pressed={active} onclick={() => duel.toggleHighlight(t)}>
|
|
<span class="thand">{#if duel.others.length > 1}<span class="dot" style="background: {seatColor(duel.state, t.who)}"></span>{`${duel.state.wizards[t.who].name}, `}{/if}{t.hand}</span>
|
|
<span class="tseq">{tokensText(t.done)} → {tokensText(t.remaining)}</span>
|
|
<span class="tname">{t.spell.name}</span>
|
|
</button>
|
|
</li>
|
|
{/each}
|
|
</ul>
|
|
</details>
|
|
{/if}
|
|
</div>
|
|
{:else if !duel.timeStopped}
|
|
<p class="threats muted">Nothing hostile is one gesture away.</p>
|
|
{/if}
|
|
|
|
<div class="hands">
|
|
<HandPicker {duel} hand="left" />
|
|
<HandPicker {duel} hand="right" />
|
|
</div>
|
|
<div class="prefs">
|
|
<label class="pref">
|
|
<input type="checkbox" checked={duel.showPlans} onchange={(e) => duel.setShowPlans(e.currentTarget.checked)} />
|
|
Show spells under way beneath each hand
|
|
</label>
|
|
<label class="pref">
|
|
<input type="checkbox" checked={duel.showLessons} onchange={(e) => duel.setShowLessons(e.currentTarget.checked)} />
|
|
Explain rules as they come up
|
|
</label>
|
|
</div>
|
|
{#if duel.hasted}
|
|
<p class="haste-note">You are hastened, so a second pair of gestures follows the first, and both take effect together.</p>
|
|
<div class="hands">
|
|
<HandPicker {duel} hand="left" set="haste" />
|
|
<HandPicker {duel} hand="right" set="haste" />
|
|
</div>
|
|
{/if}
|
|
|
|
<div class="orders">
|
|
{#if duel.stabbing}
|
|
<label class="field">
|
|
<span>Stab</span>
|
|
<select bind:value={duel.stabTarget} onchange={() => duel.focusOn(duel.stabTarget)}>
|
|
{#each duel.others as id (id)}
|
|
<option value={id}>{crowded ? duel.targetLabel(id) : duel.state.wizards[id].name}</option>
|
|
{/each}
|
|
{#each foeMonsters as m (m.id)}
|
|
<option value={m.id}>{m.name}</option>
|
|
{/each}
|
|
</select>
|
|
</label>
|
|
{/if}
|
|
{#each duel.yourMonsters as m (m.id)}
|
|
<label class="field">
|
|
<span>{m.name} attacks</span>
|
|
<select bind:value={duel.monsterOrders[m.id]} onchange={() => duel.focusOn(duel.monsterOrders[m.id])}>
|
|
{#each duel.others as id (id)}
|
|
<option value={id}>{crowded ? duel.targetLabel(id) : duel.state.wizards[id].name}</option>
|
|
{/each}
|
|
{#each foeMonsters as fm (fm.id)}
|
|
<option value={fm.id}>{fm.name}</option>
|
|
{/each}
|
|
</select>
|
|
</label>
|
|
{/each}
|
|
{#if duel.bankedSpell}
|
|
<label class="field">
|
|
<span>Release the banked {duel.bankedSpell.name.toLowerCase()}</span>
|
|
<select bind:value={duel.release}>
|
|
<option value="">not yet</option>
|
|
{#each duel.targetsFor(duel.bankedSpell) as t (t.id)}
|
|
<option value={t.id}>at {t.label}</option>
|
|
{/each}
|
|
</select>
|
|
</label>
|
|
{/if}
|
|
{#if duel.bankCandidates.length > 1}
|
|
<label class="field">
|
|
<span>Bank</span>
|
|
<select bind:value={duel.bankPick}>
|
|
{#each duel.bankCandidates as p (castKey(p.set, p.hand))}
|
|
<option value={castKey(p.set, p.hand)}>{p.completion.spell.name} ({p.hand}{p.set === 'haste' ? ', second pair' : ''})</option>
|
|
{/each}
|
|
</select>
|
|
</label>
|
|
{/if}
|
|
{#if duel.permanentCandidates.length > 1}
|
|
<label class="field">
|
|
<span>Make permanent</span>
|
|
<select bind:value={duel.permanentPick}>
|
|
{#each duel.permanentCandidates as p (castKey(p.set, p.hand))}
|
|
<option value={castKey(p.set, p.hand)}>{p.completion.spell.name} ({p.hand}{p.set === 'haste' ? ', second pair' : ''})</option>
|
|
{/each}
|
|
</select>
|
|
</label>
|
|
{/if}
|
|
{#each duel.charmedFoes as id (id)}
|
|
<label class="field">
|
|
<span>{duel.state.wizards[id].name}'s charmed {duel.state.wizards[id].constraints.charmed?.hand} hand makes</span>
|
|
<select bind:value={duel.charmGestures[id]}>
|
|
{#each MAGIC_GESTURES as g (g)}
|
|
<option value={g}>{glyph(g)} {GESTURE_SHORT[g]}</option>
|
|
{/each}
|
|
</select>
|
|
</label>
|
|
{/each}
|
|
</div>
|
|
|
|
{#if duel.remote?.error}
|
|
<p class="warning">{duel.remote.error}</p>
|
|
{/if}
|
|
<div class="commit">
|
|
<div class="pair" aria-label="This turn's gestures">
|
|
{#each duel.activeSets as set (set)}
|
|
<span class="hand-pair">
|
|
<span class="which">left</span> <span class="letter" class:empty={duel.chosenGesture(set, 'left') === null}>{duel.drawn(set, 'left')}</span>
|
|
<span class="which">right</span> <span class="letter" class:empty={duel.chosenGesture(set, 'right') === null}>{duel.drawn(set, 'right')}</span>
|
|
</span>
|
|
{/each}
|
|
</div>
|
|
<div class="notes">
|
|
{#if duel.moved}
|
|
<p class="waiting">Your hands are still. Waiting for {duel.awaitingText}.</p>
|
|
{:else if duel.intentText}
|
|
<p class="intent">{duel.intentText}</p>
|
|
{/if}
|
|
{#if duel.surrendering}
|
|
<p class="warning">Both palms at once is surrender. You will lose the duel.</p>
|
|
{:else if duel.loneClap && !duel.moved}
|
|
<p class="warning">A clap needs both hands, and one hand clapping does nothing. Clap with both, or rest the other hand.</p>
|
|
{/if}
|
|
{#if duel.conflict}
|
|
<p class="warning">Those two spells share a gesture, and a gesture can finish only one spell. Let one of them pass.</p>
|
|
{/if}
|
|
{#if !duel.moved}
|
|
<p class="keys muted">Or type: F P S W D C, K to stab, a dash to rest; Backspace undoes, Enter seals.</p>
|
|
{/if}
|
|
</div>
|
|
<button type="button" class="reveal" disabled={!duel.ready} onclick={() => duel.reveal()}>{sealLabel}</button>
|
|
</div>
|
|
</section>
|
|
{/if}
|
|
{/if}
|
|
</section>
|
|
|
|
<aside class="rail">
|
|
{#if !duel.spectating}
|
|
<WizardStatus turnsPlayed={duel.state.turn} wizard={duel.you} monsters={duel.yourMonsters} you />
|
|
{/if}
|
|
{#if crowded}
|
|
<Roster {duel} />
|
|
{:else}
|
|
{#each duel.others as id (id)}
|
|
<WizardStatus turnsPlayed={duel.state.turn} wizard={duel.state.wizards[id]} monsters={duel.state.monsters.filter((m) => m.owner === id)} />
|
|
{/each}
|
|
{/if}
|
|
<TableTalk {duel} />
|
|
<SpellSheet {duel} />
|
|
<Chronicle log={duel.state.log} />
|
|
</aside>
|
|
</main>
|
|
|
|
<MobileBar {duel} />
|
|
|
|
<style>
|
|
details.next summary {
|
|
cursor: pointer;
|
|
list-style: none;
|
|
}
|
|
|
|
details.next summary::before {
|
|
content: '\25B8 ';
|
|
color: var(--bone-faint);
|
|
}
|
|
|
|
details.next[open] summary::before {
|
|
content: '\25BE ';
|
|
}
|
|
|
|
.board {
|
|
display: grid;
|
|
grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
|
|
gap: 0 clamp(1.5rem, 4vw, 3.5rem);
|
|
padding: 0 var(--gutter);
|
|
max-width: 1280px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.play {
|
|
min-width: 0;
|
|
}
|
|
|
|
.rail {
|
|
min-width: 0;
|
|
}
|
|
|
|
.dot {
|
|
display: inline-block;
|
|
width: 0.5rem;
|
|
height: 0.5rem;
|
|
border-radius: 50%;
|
|
margin-right: 0.3rem;
|
|
vertical-align: baseline;
|
|
}
|
|
|
|
.intent {
|
|
margin: 0.6rem 0 0.2rem;
|
|
font-style: italic;
|
|
color: var(--bone);
|
|
}
|
|
|
|
.move {
|
|
padding: 0.6rem 0 1.5rem;
|
|
}
|
|
|
|
.move h2 {
|
|
font-size: 1.3rem;
|
|
margin-bottom: 0.3rem;
|
|
}
|
|
|
|
.threats {
|
|
font-size: 0.9rem;
|
|
margin-bottom: 0.7rem;
|
|
}
|
|
|
|
.threats ul {
|
|
list-style: none;
|
|
margin: 0.15rem 0 0.4rem;
|
|
padding: 0;
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 0.3rem 0.5rem;
|
|
}
|
|
|
|
.threat {
|
|
background: var(--slate);
|
|
border: 1px solid transparent;
|
|
border-radius: 3px;
|
|
padding: 0.15rem 0.5rem;
|
|
display: inline-flex;
|
|
gap: 0.5rem;
|
|
align-items: baseline;
|
|
color: var(--bone-dim);
|
|
}
|
|
|
|
.threat.soon {
|
|
color: var(--bone);
|
|
}
|
|
|
|
.threat:hover,
|
|
.threat.active {
|
|
border-color: var(--frost);
|
|
}
|
|
|
|
.threat.active {
|
|
background: rgba(140, 200, 224, 0.12);
|
|
}
|
|
|
|
.thand {
|
|
font-style: italic;
|
|
font-size: 0.8rem;
|
|
}
|
|
|
|
.tseq {
|
|
letter-spacing: 0.04em;
|
|
}
|
|
|
|
.tseq strong {
|
|
font-weight: 600;
|
|
color: var(--ember);
|
|
}
|
|
|
|
.prefs {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 0.3rem 1.5rem;
|
|
margin-top: 0.7rem;
|
|
}
|
|
|
|
.pref {
|
|
display: flex;
|
|
gap: 0.4rem;
|
|
align-items: center;
|
|
font-size: 0.85rem;
|
|
color: var(--bone-dim);
|
|
}
|
|
|
|
.hands {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 1.25rem 2rem;
|
|
}
|
|
|
|
.orders {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 0.5rem 1.5rem;
|
|
margin-top: 0.9rem;
|
|
}
|
|
|
|
.warning {
|
|
color: var(--blood);
|
|
margin-top: 0.8rem;
|
|
}
|
|
|
|
.haste-note {
|
|
color: var(--frost);
|
|
font-size: 0.95rem;
|
|
margin: 1rem 0 0.6rem;
|
|
}
|
|
|
|
/* Box the hand pickers so they read apart from the ledger table above. */
|
|
.hands {
|
|
background: var(--slate);
|
|
border: 1px solid var(--rule-strong);
|
|
border-radius: 6px;
|
|
padding: 0.7rem 0.9rem 0.9rem;
|
|
}
|
|
|
|
/* Sticky at the foot so the chosen pair and the seal button stay in view while the pickers scroll. */
|
|
.commit {
|
|
position: sticky;
|
|
bottom: 0;
|
|
z-index: 4;
|
|
display: grid;
|
|
grid-template-columns: auto minmax(0, 1fr) auto;
|
|
align-items: center;
|
|
gap: 0.4rem 1rem;
|
|
margin-top: 0.9rem;
|
|
padding: 0.6rem 0.2rem;
|
|
background: var(--slate-deep);
|
|
border-top: 1px solid var(--rule-strong);
|
|
}
|
|
|
|
.pair {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.1rem;
|
|
}
|
|
|
|
.hand-pair {
|
|
display: flex;
|
|
align-items: baseline;
|
|
gap: 0.35rem;
|
|
}
|
|
|
|
.which {
|
|
font-size: 0.75rem;
|
|
font-style: italic;
|
|
color: var(--bone-faint);
|
|
}
|
|
|
|
.pair .letter {
|
|
font-size: 1.5rem;
|
|
min-width: 1ch;
|
|
}
|
|
|
|
.pair .letter.empty {
|
|
color: var(--bone-faint);
|
|
}
|
|
|
|
.notes p {
|
|
margin: 0;
|
|
}
|
|
|
|
.notes p + p {
|
|
margin-top: 0.2rem;
|
|
}
|
|
|
|
.keys {
|
|
font-size: 0.8rem;
|
|
}
|
|
|
|
.verdict {
|
|
padding: 1.5rem 0;
|
|
}
|
|
|
|
.verdict h2 {
|
|
font-size: 2rem;
|
|
font-style: italic;
|
|
color: var(--blood);
|
|
}
|
|
|
|
.verdict.won h2 {
|
|
color: var(--ember);
|
|
}
|
|
|
|
.verdict p {
|
|
margin: 0.3rem 0 0.8rem;
|
|
color: var(--bone-dim);
|
|
}
|
|
|
|
/* Must match COMPACT_QUERY in duel.svelte.ts. */
|
|
@media (max-width: 860px) {
|
|
.board {
|
|
grid-template-columns: minmax(0, 1fr);
|
|
}
|
|
|
|
/* Narrow screens: MobileBar carries the pair and the button instead. */
|
|
.commit {
|
|
position: static;
|
|
grid-template-columns: minmax(0, 1fr);
|
|
border-top: 0;
|
|
}
|
|
|
|
.commit .pair,
|
|
.commit .reveal,
|
|
.keys {
|
|
display: none;
|
|
}
|
|
|
|
.rail {
|
|
order: 2;
|
|
border-top: 1px solid var(--rule-strong);
|
|
margin-top: 1rem;
|
|
}
|
|
|
|
.hands {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
}
|
|
|
|
.waiting {
|
|
color: var(--frost);
|
|
}
|
|
|
|
.reveal.again {
|
|
display: inline-block;
|
|
text-decoration: none;
|
|
}
|
|
</style>
|