Disable treasure buttons when they cannot apply
Pick Up Treasure is disabled unless an uncarried treasure sits on your square (and your actions haven't ended); Drop Treasure unless you are actually carrying one. The warp-step button reuses the same derived state. Buttons stay visible for stable layout — they just stop inviting impossible clicks. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
8c85c13e15
commit
3e1fe059fa
@@ -351,6 +351,20 @@
|
||||
function drop() { net.command({ type: "dropTreasure" }); }
|
||||
function pass() { net.command({ type: "pass" }); }
|
||||
|
||||
const me = $derived(view?.players.find((p) => p.id === view?.you) ?? null);
|
||||
const carryingTreasure = $derived(me?.carriedTreasureId != null);
|
||||
const treasureHere = $derived(
|
||||
view != null && me != null &&
|
||||
view.treasures.some((t) => t.position && t.position.x === me.position.x &&
|
||||
t.position.y === me.position.y && !t.carriedBy),
|
||||
);
|
||||
const onWarpToken = $derived(
|
||||
view != null && me != null &&
|
||||
view.dimWarps.some((w) =>
|
||||
(w.a.x === me.position.x && w.a.y === me.position.y) ||
|
||||
(w.b.x === me.position.x && w.b.y === me.position.y)),
|
||||
);
|
||||
|
||||
let chronicleEl = $state<HTMLElement | null>(null);
|
||||
$effect(() => {
|
||||
void net.log.length;
|
||||
@@ -556,16 +570,13 @@
|
||||
{/if}
|
||||
|
||||
<div class="actions">
|
||||
{#if isYourTurn && view.dimWarps.some((w) => {
|
||||
const me = view.players.find((p) => p.id === view.you)!;
|
||||
return (w.a.x === me.position.x && w.a.y === me.position.y) ||
|
||||
(w.b.x === me.position.x && w.b.y === me.position.y);
|
||||
})}
|
||||
{#if isYourTurn && onWarpToken}
|
||||
<button class="stamp" onclick={() => net.command({ type: "warpStep" })}>Step through the warp</button>
|
||||
{/if}
|
||||
{#if isYourTurn}
|
||||
<button class="stamp" onclick={pickUp}>Pick up treasure</button>
|
||||
<button class="stamp" onclick={drop}>Drop treasure</button>
|
||||
<button class="stamp" disabled={!treasureHere || carryingTreasure || view.turn.actionsEnded}
|
||||
onclick={pickUp}>Pick up treasure</button>
|
||||
<button class="stamp" disabled={!carryingTreasure} onclick={drop}>Drop treasure</button>
|
||||
<label class="inline draw-pick">
|
||||
draw
|
||||
<select bind:value={drawCount}>
|
||||
|
||||
Reference in New Issue
Block a user