Mark dice that count against teammates' destinations during rerolls

This commit is contained in:
coyotte508 2026-09-08 18:05:12 +02:00
commit 2f3324b685
4 changed files with 92 additions and 1 deletions

View file

@ -101,6 +101,31 @@
const result = $derived(s && resolvingSeat !== undefined && revealed ? comparison(s, resolvingSeat) : null);
const diceTerrain = $derived(s?.phase === "planning" ? focusTerrain : destination);
const rule = $derived(diceTerrain?.requirement);
const diceConflicts = $derived.by(() => {
if (!s || !me || seat === undefined || s.phase !== "reroll") return {};
// Only our visible dice and the public destinations of comparison neighbors.
return Object.fromEntries(
me.dice.map((d) => [
d.id,
d.aside || d.remove || !d.face
? []
: neighbors(s, seat).flatMap((i) => {
const player = s.players[i]!;
const destination = terrain(cell(s, player.path.at(-1) ?? player.position).terrain);
return matches(face(d), destination.requirement)
? [
{
seat: i,
name: player.name,
color: CHARACTER_COLORS[player.character]!,
location: destination.name,
},
]
: [];
}),
])
);
});
const localTotal = $derived(me && diceTerrain ? total(me, diceTerrain.id) : 0);
const danger = $derived(s ? threatened(s) : []);
const nextAction = $derived(
@ -441,6 +466,7 @@
colorblind={store.colorblind}
die={d}
selected={dice.includes(d.id)}
conflicts={diceConflicts[d.id] ?? []}
relevant={s.phase !== "setup" && !d.aside && !!d.face && !!rule && matches(face(d), rule)}
disabled={(d.aside && !me.pendingInjuries) ||
store.waiting ||
@ -452,6 +478,9 @@
<strong>{localTotal}</strong><span>Matching dice total<br />{diceTerrain.name}</span>
</div>{/if}
</div>
{#if s.phase === "reroll"}<p class="dice-conflict-guide">
Player numbers mark dice that also count against that teammate’s destination.
</p>{/if}
{#if s.phase === "reroll"}<section class="reroll-actions" aria-label="Dice actions">
{#if me.ready}<p class="confirmed">✓ Your dice are kept. Waiting for the team.</p>
{:else}

View file

@ -5,6 +5,7 @@
selected = false,
colorblind = false,
relevant = false,
conflicts = [],
disabled = false,
onclick = () => {},
}: {
@ -12,10 +13,14 @@
colorblind?: boolean;
selected?: boolean;
relevant?: boolean;
conflicts?: { seat: number; name: string; color: string; location: string }[];
disabled?: boolean;
onclick?: () => void;
} = $props();
const f = $derived(face(die));
const conflictHelp = $derived(
conflicts.map((p) => `Adds ${die.face} to the total ${p.name} must beat at ${p.location}`).join(". ")
);
const layouts: Record<number, number[]> = {
1: [4],
2: [0, 8],
@ -35,8 +40,9 @@
style:--die-color={die.face ? { blue: "#82ccdb", pink: "#e16d9a", yellow: "#f2cd5d" }[f.color] : "#27433c"}
{disabled}
{onclick}
title={conflictHelp || undefined}
aria-label={die.face
? `${f.color} ${die.face}${die.aside ? ", set aside" : relevant ? `, counts +${die.face}` : ""}`
? `${f.color} ${die.face}${die.aside ? ", set aside" : relevant ? `, counts +${die.face}` : ""}${conflictHelp ? `. ${conflictHelp}` : ""}`
: "Hidden die"}
aria-pressed={selected}
>
@ -48,6 +54,9 @@
{#if die.face}<span class="pips" aria-hidden="true"
>{#each Array(9) as _, i}<i class:filled={layouts[die.face]?.includes(i)}></i>{/each}</span
>{#if colorblind}<span class="die-caption">{f.color}</span>{/if}{:else}<span aria-hidden="true">?</span>{/if}
{#if conflicts.length && die.face && !die.aside}<span class="conflict-badges" aria-hidden="true">
{#each conflicts as player}<span style:--player-color={player.color}>{player.seat + 1}</span>{/each}
</span>{/if}
</button>
<style>
@ -102,6 +111,28 @@
pointer-events: none;
}
.conflict-badges {
position: absolute;
bottom: -12px;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 3px;
pointer-events: none;
}
.conflict-badges > span {
display: grid;
place-items: center;
width: 19px;
height: 19px;
border: 1.5px solid var(--player-color);
border-radius: 50%;
background: #102c25;
color: var(--player-color);
font-size: 11px;
font-weight: 700;
box-shadow: 0 2px 4px #0005;
}
.die.aside {
opacity: 0.5;
transform: scale(0.85);

View file

@ -1616,3 +1616,9 @@ h3 {
.visible-choices button:not(.die):hover {
background: #294136;
}
.dice-conflict-guide {
margin: 0 0 12px;
font-size: 12px;
color: #aebfa3;
}

View file

@ -101,6 +101,31 @@ import path from "node:path";
if (await page.locator(".die-caption").count()) throw Error("Color labels did not turn off");
await page.keyboard.press("Escape");
if ((await page.locator(".village-marker").count()) !== 5) throw Error("Every village location needs a marker");
const conflictState = initGame(4, {}, "dice-conflicts");
conflictState.phase = "reroll";
conflictState.board.forEach((c) => {
if (!c.lava) c.terrain = 16;
});
conflictState.players.forEach((p) => {
p.path = [p.position];
p.ready = false;
p.rerolls = 1;
});
conflictState.players[0].dice.forEach((d) => (d.face = 1));
conflictState.players[0].dice[0].aside = true;
await page.evaluate((v) => window.bridge.emit("state", v), stripSecret(conflictState, 0));
const conflictMarkers = page.locator(".personal .conflict-badges > span");
const markers = await conflictMarkers.allTextContents();
if (markers.length !== 10 || markers.some((m) => !["2", "4"].includes(m)))
throw Error("Only comparison neighbors should be marked; set-aside dice must be excluded");
conflictState.players[1].dice.forEach((d) => (d.face = 6));
await page.evaluate((v) => window.bridge.emit("state", v), stripSecret(conflictState, 0));
if (JSON.stringify(await conflictMarkers.allTextContents()) !== JSON.stringify(markers))
throw Error("Conflict markers used hidden teammate rolls");
await page.screenshot({ path: "work/browser/fuji-dice-conflicts.png", fullPage: true });
conflictState.phase = "equipment";
await page.evaluate((v) => window.bridge.emit("state", v), stripSecret(conflictState, 0));
if (await conflictMarkers.count()) throw Error("Reroll conflict markers leaked into another phase");
s.phase = "reroll";
s.players[0].rerolls = 0;
await page.evaluate((v) => window.bridge.emit("state", v), stripSecret(s, 0));