Preview planning dice conflicts and clarify choice controls
This commit is contained in:
parent
e6bcd883e9
commit
421efefe72
6 changed files with 185 additions and 17 deletions
|
|
@ -171,7 +171,7 @@
|
|||
const diceTerrain = $derived(s?.phase === "planning" ? focusTerrain : destination);
|
||||
const rule = $derived(diceTerrain?.requirement);
|
||||
const diceConflicts = $derived.by(() => {
|
||||
if (!s || !me || seat === undefined || !["reroll", "equipment"].includes(s.phase)) return {};
|
||||
if (!s || !me || seat === undefined || !["planning", "reroll", "equipment"].includes(s.phase)) return {};
|
||||
// Only our visible dice and the public destinations of comparison neighbors.
|
||||
return Object.fromEntries(
|
||||
me.dice.map((d) => [
|
||||
|
|
@ -180,6 +180,7 @@
|
|||
? []
|
||||
: neighbors(s, seat).flatMap((i) => {
|
||||
const player = s.players[i]!;
|
||||
if (s.phase === "planning" && player.path.length <= 1 && !player.ready) return [];
|
||||
const destination = terrain(cell(s, player.path.at(-1) ?? player.position).terrain);
|
||||
return matches(face(d), destination.requirement)
|
||||
? [
|
||||
|
|
@ -188,6 +189,7 @@
|
|||
name: player.name,
|
||||
color: CHARACTER_COLORS[player.character]!,
|
||||
location: destination.name,
|
||||
provisional: s.phase === "planning" && !player.ready,
|
||||
},
|
||||
]
|
||||
: [];
|
||||
|
|
@ -436,7 +438,17 @@
|
|||
? "Preparation"
|
||||
: s.phase}</span
|
||||
>
|
||||
<span class="difficulty-label" title={`Difficulty level ${s.difficulty} of 4`}>Level {s.difficulty}</span>
|
||||
<button
|
||||
type="button"
|
||||
class="difficulty-label"
|
||||
use:equipmentPopover
|
||||
aria-label={`Difficulty level ${s.difficulty}: stamina costs`}
|
||||
>Level {s.difficulty} <span aria-hidden="true">ⓘ</span></button
|
||||
>
|
||||
<span class="equipment-preview difficulty-preview" popover="auto">
|
||||
<strong>Difficulty level {s.difficulty} of 4</strong>
|
||||
<StaminaGuide difficulty={s.difficulty} expanded />
|
||||
</span>
|
||||
</div>
|
||||
{#if store.chat.enabled}<button class="text-button" onclick={openChat}
|
||||
>Chat{store.chat.unread ? ` · ${store.chat.unread}` : ""}</button
|
||||
|
|
@ -683,6 +695,7 @@
|
|||
{seat}
|
||||
{reserved}
|
||||
previewTotals={s.phase === "planning" && !!me && !me.ready && !s.pending && !tool}
|
||||
previewImpacts={s.phase === "planning" && !!me && !s.pending && !tool}
|
||||
selectedLocations={tool ? tilePicks : []}
|
||||
selectionReasons={binocularReasons}
|
||||
selected={s.phase === "setup" ? "" : tool ? (tilePicks.at(-1) ?? "") : (currentRoute.at(-1) ?? "")}
|
||||
|
|
@ -726,13 +739,14 @@
|
|||
<strong>{localTotal}</strong><span>Matching dice total<br />{diceTerrain.name}</span>
|
||||
</div>{/if}
|
||||
</div>
|
||||
{#if ["reroll", "equipment"].includes(s.phase)}<p class="dice-conflict-guide">
|
||||
{#if ["planning", "reroll", "equipment"].includes(s.phase)}<p class="dice-conflict-guide">
|
||||
Player numbers mark dice that also count against that teammate’s destination.
|
||||
{#if s.phase === "planning"}Dashed markers are provisional; solid markers are confirmed.{/if}
|
||||
</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>
|
||||
<button
|
||||
class="text-button"
|
||||
class="revise-choice"
|
||||
onclick={() => store.dispatch({ action: "unready" })}
|
||||
disabled={store.waiting || !canReopenChoice(s, seat!)}>Change my dice choices</button
|
||||
>
|
||||
|
|
@ -1018,7 +1032,7 @@
|
|||
disabled={store.waiting || !!reserved[currentRoute.at(-1)!]}
|
||||
onclick={confirmTravel}>Ready to travel <span>→</span></button
|
||||
>{:else}<p class="confirmed">✓ Your route is set. Waiting for the team.</p>
|
||||
<button class="text-button" onclick={() => store.dispatch({ action: "plan", path: me.path })}
|
||||
<button class="revise-choice" onclick={() => store.dispatch({ action: "plan", path: me.path })}
|
||||
>Change my route</button
|
||||
>{/if}
|
||||
{:else if s.phase === "reroll"}
|
||||
|
|
@ -1033,7 +1047,7 @@
|
|||
disabled={store.waiting}>Ready to reveal <span>→</span></button
|
||||
>{:else}<p class="confirmed">✓ Ready. Waiting for the team.</p>
|
||||
<button
|
||||
class="text-button"
|
||||
class="revise-choice"
|
||||
onclick={() => store.dispatch({ action: "unready" })}
|
||||
disabled={store.waiting || !canReopenChoice(s, seat!)}>Change my choice</button
|
||||
>{/if}
|
||||
|
|
|
|||
|
|
@ -13,13 +13,18 @@
|
|||
colorblind?: boolean;
|
||||
selected?: boolean;
|
||||
relevant?: boolean;
|
||||
conflicts?: { seat: number; name: string; color: string; location: string }[];
|
||||
conflicts?: { seat: number; name: string; color: string; location: string; provisional?: boolean }[];
|
||||
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(". ")
|
||||
conflicts
|
||||
.map(
|
||||
(p) =>
|
||||
`Adds ${die.face} to the total ${p.name} must beat at ${p.location}${p.provisional ? " (provisional destination)" : ""}`
|
||||
)
|
||||
.join(". ")
|
||||
);
|
||||
const layouts: Record<number, number[]> = {
|
||||
1: [4],
|
||||
|
|
@ -55,7 +60,9 @@
|
|||
>{#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}
|
||||
{#each conflicts as player}<span class:provisional={player.provisional} style:--player-color={player.color}
|
||||
>{player.seat + 1}</span
|
||||
>{/each}
|
||||
</span>{/if}
|
||||
</button>
|
||||
|
||||
|
|
@ -133,6 +140,9 @@
|
|||
font-weight: 700;
|
||||
box-shadow: 0 2px 4px #0005;
|
||||
}
|
||||
.conflict-badges > span.provisional {
|
||||
border-style: dashed;
|
||||
}
|
||||
.die.aside {
|
||||
opacity: 0.5;
|
||||
transform: scale(0.85);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
import {
|
||||
terrain,
|
||||
total,
|
||||
neighbors,
|
||||
cell,
|
||||
distance,
|
||||
threatened,
|
||||
|
|
@ -24,6 +25,7 @@
|
|||
selectionReasons,
|
||||
reachable = [],
|
||||
previewTotals = false,
|
||||
previewImpacts = false,
|
||||
onclick,
|
||||
oninspect,
|
||||
}: {
|
||||
|
|
@ -37,9 +39,18 @@
|
|||
selectionReasons?: Record<string, string>;
|
||||
reachable?: string[];
|
||||
previewTotals?: boolean;
|
||||
previewImpacts?: boolean;
|
||||
onclick: (id: string) => void;
|
||||
oninspect: (id: string) => void;
|
||||
} = $props();
|
||||
const impactPlayers = $derived(
|
||||
previewImpacts && seat !== undefined
|
||||
? neighbors(state, seat).filter((i) => {
|
||||
const p = state.players[i]!;
|
||||
return p.path.length > 1 || p.ready;
|
||||
})
|
||||
: []
|
||||
);
|
||||
const opposite = $derived(state.players.length === 4 && seat !== undefined ? (seat + 2) % 4 : -1);
|
||||
const danger = $derived(threatened(state));
|
||||
const mapWidth = $derived(116 + Math.max(...state.board.map((c) => c.x)) * 100);
|
||||
|
|
@ -109,6 +120,7 @@
|
|||
class:burnt={a.lava || b.lava}
|
||||
/>{/each}
|
||||
{#each state.board as c (c.id)}
|
||||
{@const peers = impactPlayers.filter((i) => state.players[i]!.path.at(-1) === c.id)}
|
||||
{@const data = terrain(c.terrain)}
|
||||
<g
|
||||
class="location"
|
||||
|
|
@ -207,7 +219,25 @@
|
|||
rx="4"
|
||||
fill="#112820e6"
|
||||
/><RequirementSymbols requirement={data.requirement} x={x(c.id)} y={y(c.id) + 25} {colorblind} />{/if}
|
||||
{#if previewTotals && seat !== undefined && reachable.includes(c.id) && !reserved[c.id] && !c.lava}
|
||||
|
||||
{#if seat !== undefined && peers.length && !c.lava}
|
||||
{#each peers as playerIndex, index}
|
||||
{@const player = state.players[playerIndex]!}
|
||||
{@const value = total(state.players[seat]!, c.terrain)}
|
||||
{@const cx = x(c.id) + (index - (peers.length - 1) / 2) * 43}
|
||||
<g
|
||||
class="dice-preview impact-preview"
|
||||
class:provisional={!player.ready}
|
||||
data-location={c.id}
|
||||
data-player={playerIndex}
|
||||
style:--impact-color={CHARACTER_COLORS[player.character]}
|
||||
aria-label={`Your dice total against ${player.name}: ${value}. ${player.ready ? "Confirmed" : "Provisional"} destination.`}
|
||||
>
|
||||
<rect x={cx - 20} y={y(c.id) - 13} width="40" height="26" rx="6" />
|
||||
<text x={cx} y={y(c.id) + 6}>{value}</text>
|
||||
</g>
|
||||
{/each}
|
||||
{:else if previewTotals && seat !== undefined && reachable.includes(c.id) && !reserved[c.id] && !c.lava}
|
||||
{@const value = total(state.players[seat]!, c.terrain) + state.players[seat]!.bonus}
|
||||
<g class="dice-preview" data-location={c.id} aria-label={`Your current dice total: ${value}`}>
|
||||
<title>Your current matching dice total, including bonuses. Rerolls may change it.</title>
|
||||
|
|
@ -333,6 +363,16 @@
|
|||
font-weight: 700;
|
||||
text-anchor: middle;
|
||||
}
|
||||
.impact-preview rect {
|
||||
stroke: var(--impact-color);
|
||||
stroke-width: 2;
|
||||
}
|
||||
.impact-preview text {
|
||||
fill: var(--impact-color);
|
||||
}
|
||||
.impact-preview.provisional rect {
|
||||
stroke-dasharray: 4 3;
|
||||
}
|
||||
@media (max-width: 650px), (pointer: coarse) {
|
||||
.dice-preview {
|
||||
display: block;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
<script lang="ts">
|
||||
let { difficulty, margin, aid = false }: { difficulty: number; margin?: number; aid?: boolean } = $props();
|
||||
let {
|
||||
difficulty,
|
||||
margin,
|
||||
aid = false,
|
||||
expanded = false,
|
||||
}: { difficulty: number; margin?: number; aid?: boolean; expanded?: boolean } = $props();
|
||||
const maximum = $derived(difficulty + 2);
|
||||
const current = $derived(
|
||||
margin === undefined ? undefined : margin <= 0 ? 0 : Math.min(maximum, Math.ceil(margin / 2))
|
||||
);
|
||||
</script>
|
||||
|
||||
<details class="stamina-guide">
|
||||
<details class="stamina-guide" open={expanded}>
|
||||
<summary>ⓘ Stamina cost</summary>
|
||||
<p>Lead = your total − the highest neighbouring total.</p>
|
||||
<table>
|
||||
|
|
|
|||
|
|
@ -222,11 +222,7 @@ h3 {
|
|||
min-width: 0;
|
||||
}
|
||||
.journey {
|
||||
position: sticky;
|
||||
top: 12px;
|
||||
max-height: calc(100dvh - 24px);
|
||||
overflow-y: auto;
|
||||
scrollbar-width: thin;
|
||||
position: static;
|
||||
border-left: 1px solid #c9d4b620;
|
||||
padding-left: 28px;
|
||||
min-width: 0;
|
||||
|
|
@ -1810,3 +1806,47 @@ button.equipment-chip {
|
|||
padding-left: 9px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
button.difficulty-label {
|
||||
background: transparent;
|
||||
border: 0;
|
||||
border-left: 1px solid #597367;
|
||||
padding: 0 0 0 9px;
|
||||
font: inherit;
|
||||
cursor: help;
|
||||
}
|
||||
button.difficulty-label:hover,
|
||||
button.difficulty-label:focus-visible {
|
||||
color: #f1d584;
|
||||
}
|
||||
.difficulty-preview {
|
||||
text-transform: none;
|
||||
letter-spacing: normal;
|
||||
}
|
||||
|
||||
.revise-choice {
|
||||
display: block;
|
||||
width: 100%;
|
||||
margin: 10px 0;
|
||||
padding: 12px 16px;
|
||||
border: 1px solid #d9c581;
|
||||
border-radius: 5px;
|
||||
background: #d9c58118;
|
||||
color: #f1dba0;
|
||||
font: inherit;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
text-align: center;
|
||||
}
|
||||
.revise-choice:hover:not(:disabled) {
|
||||
background: #d9c58130;
|
||||
}
|
||||
.revise-choice:focus-visible {
|
||||
outline: 2px solid #f1dba0;
|
||||
outline-offset: 3px;
|
||||
}
|
||||
.revise-choice:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: default;
|
||||
}
|
||||
|
|
|
|||
59
tests/planning-impacts-smoke.mjs
Normal file
59
tests/planning-impacts-smoke.mjs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import { chromium } from "playwright";
|
||||
import { initGame, stripSecret, total, paths, terrain } from "../packages/engine/dist/index.js";
|
||||
import assert from "node:assert/strict";
|
||||
const root = process.cwd();
|
||||
const browser = await chromium.launch({ headless: true, executablePath: process.env.FUJI_CHROMIUM_EXECUTABLE });
|
||||
for (const ready of [false, true]) {
|
||||
const s = initGame(4, { skillAssignment: "fixed" }, "impacts");
|
||||
s.phase = "planning";
|
||||
s.players.forEach((p) => {
|
||||
p.setupDone = true;
|
||||
p.ready = false;
|
||||
p.dice.forEach((d) => (d.face = 3));
|
||||
});
|
||||
s.players[0].bonus = 3;
|
||||
const reach = paths(s, 0);
|
||||
const far = s.board.find((c) => !c.lava && terrain(c.terrain).kind === "land" && !reach[c.id]);
|
||||
const near = s.board.find((c) => c.id !== s.players[0].position && reach[c.id]);
|
||||
for (const [i, c] of [
|
||||
[1, far],
|
||||
[2, near],
|
||||
[3, near],
|
||||
]) {
|
||||
s.players[i].path = [s.players[i].position, c.id];
|
||||
s.players[i].ready = ready;
|
||||
}
|
||||
const p = await browser.newPage({ viewport: { width: 390, height: 840 } });
|
||||
const errors = [];
|
||||
p.on("pageerror", (e) => errors.push(e.message));
|
||||
await p.setContent('<div id="app"></div>');
|
||||
await p.addStyleTag({ path: root + "/packages/viewer/dist/fuji-viewer.css" });
|
||||
await p.addScriptTag({ path: root + "/packages/viewer/dist/fuji-viewer.iife.js" });
|
||||
await p.evaluate(
|
||||
(s) => {
|
||||
window.e = fuji.launch("#app");
|
||||
e.emit("player", { index: 0 });
|
||||
e.emit("state", s);
|
||||
},
|
||||
stripSecret(s, 0)
|
||||
);
|
||||
await p.locator(".impact-preview").first().waitFor();
|
||||
assert.equal(await p.locator(".impact-preview").count(), 2);
|
||||
assert.equal(await p.locator('.impact-preview[data-player="2"]').count(), 0);
|
||||
assert.equal(
|
||||
await p.locator('.impact-preview[data-player="1"] text').textContent(),
|
||||
String(total(s.players[0], far.terrain))
|
||||
);
|
||||
assert.equal(await p.locator(".impact-preview.provisional").count(), ready ? 0 : 2);
|
||||
assert.equal(await p.locator('.impact-preview[data-player="3"]').count(), 1);
|
||||
assert.equal(await p.locator(`.dice-preview:not(.impact-preview)[data-location="${near.id}"]`).count(), 0);
|
||||
const markers = await p.locator(".conflict-badges > span").count();
|
||||
assert(markers > 0);
|
||||
assert.equal(await p.locator(".conflict-badges > span.provisional").count(), ready ? 0 : markers);
|
||||
assert.deepEqual(errors, []);
|
||||
await p.close();
|
||||
}
|
||||
await browser.close();
|
||||
console.log(
|
||||
"Planning previews: unreachable/reachable destinations, neighbour filtering, own dice totals, provisional/confirmed borders passed."
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue