Merge desktop layout and hand-adjacent placement confirm

This commit is contained in:
Mike Isom 2026-11-04 07:01:36 -07:00
commit 72e9998165
4 changed files with 168 additions and 79 deletions

View file

@ -5,6 +5,7 @@
import Chat from "./lib/Chat.svelte";
import Hand from "./lib/Hand.svelte";
import Log from "./lib/Log.svelte";
import PlaceConfirm from "./lib/PlaceConfirm.svelte";
import Players from "./lib/Players.svelte";
import PriceTable from "./lib/PriceTable.svelte";
import Status from "./lib/Status.svelte";
@ -17,32 +18,43 @@
<main class="acquire" data-theme={store.theme} lang={store.locale} dir={store.rightToLeft ? "rtl" : "ltr"}>
{#if store.state}
{@const state = store.view!}
<!-- Each column stacks its panels independently on wider screens, so a short panel never stretches
to the board's height; phones place the panels individually (the columns are display: contents). -->
<div class="layout">
<div class="controls">
<Status {state} seats={store.seats} />
<ActionPanel {store} />
<div class="column turn-column">
<div class="controls">
<Status {state} seats={store.seats} />
<ActionPanel {store} />
</div>
{#if store.seats.length > 0 && store.replayAt === undefined}
<div class="hand">
<Hand {store} />
<div class="hand-confirm"><PlaceConfirm {store} nearHand /></div>
</div>
{/if}
<div class="market">
<ChainTable {state} seats={store.seats} />
<PriceTable {state} />
</div>
</div>
<div class="board">
<Board
{state}
selected={store.selected}
onplace={(tile) => store.send({ type: "place", tile: tileLabel(tile) })}
/>
<div class="column board-column">
<div class="board">
<Board
{state}
selected={store.selected}
onplace={(tile) => store.send({ type: "place", tile: tileLabel(tile) })}
/>
</div>
<div class="players">
<Players {state} seats={store.seats} />
</div>
</div>
{#if store.seats.length > 0 && store.replayAt === undefined}
<div class="hand"><Hand {store} /></div>
{/if}
<div class="market">
<ChainTable {state} seats={store.seats} />
<PriceTable {state} />
<div class="column talk-column">
<div class="history"><Log {state} /></div>
{#if !store.analysis}
<div class="conversation"><Chat /></div>
{/if}
</div>
<div class="players">
<Players {state} seats={store.seats} />
</div>
{#if !store.analysis}
<div class="conversation"><Chat /></div>
{/if}
<div class="history"><Log {state} /></div>
</div>
{:else}
<p>{store.lang.t("loading")}</p>
@ -50,7 +62,7 @@
</main>
<style>
/* Keep the decision and board together on narrow screens. */
/* Phones: one column that keeps the decision, board and hand together. */
.layout {
display: grid;
gap: 20px;
@ -58,7 +70,11 @@
grid-template-areas: "controls" "board" "hand" "market" "players" "conversation" "history";
align-items: start;
}
.layout > div {
.column {
display: contents;
}
.column,
.column > div {
min-width: 0;
}
.controls {
@ -87,29 +103,44 @@
.history {
grid-area: history;
}
/* Tablets and phones in landscape: the board beside the decision and hand. */
/* Tablets and phones in landscape: the board and players beside the decision, hand and chains;
history and chat below. */
@media (min-width: 700px) {
.layout {
grid-template-columns: minmax(0, 1.4fr) minmax(260px, 1fr);
grid-template-areas:
"board controls"
"board hand"
"market players"
"history conversation";
grid-template-rows: auto 1fr auto auto;
grid-template-areas: "main turn" "history conversation";
}
.board-column,
.turn-column {
display: flex;
flex-direction: column;
gap: 20px;
}
.board-column {
grid-area: main;
}
.turn-column {
grid-area: turn;
}
/* Placing a tile needs no second confirmation here: the decision is right above the hand. */
.hand-confirm {
display: none;
}
}
/* Desktop: keep the market beside the board; spread the supporting panels across a second row
instead of letting chat and history make one very tall sidebar. */
/* Desktop: three independent columns (board and players; decision, hand and chains; history and
chat), so none of them leaves an empty area beside the board. */
@media (min-width: 1200px) {
.layout {
row-gap: 16px;
grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr) minmax(320px, 1fr);
grid-template-areas:
"board controls market"
"board hand market"
"players history conversation";
grid-template-rows: auto 1fr auto;
grid-template-areas: "main turn talk";
}
.column {
display: flex;
flex-direction: column;
gap: 16px;
}
.talk-column {
grid-area: talk;
}
}
</style>

View file

@ -7,22 +7,14 @@
merger,
sharePrice,
sharePurchaseLimit,
tileLabel,
type ChainId,
type Shares,
} from "acquire-engine";
import ChainMark from "./ChainMark.svelte";
import PlaceConfirm from "./PlaceConfirm.svelte";
import StockSwap from "./StockSwap.svelte";
import { mergerPreview } from "./mergerPreview";
import {
adjustShares,
canBuy,
canDispose,
describePlacement,
disposalPresets,
nextDefunctChoices,
ofType,
} from "./decisions";
import { adjustShares, canBuy, canDispose, disposalPresets, nextDefunctChoices, ofType } from "./decisions";
import { chainName } from "./format";
import type { ViewerStore } from "./store.svelte";
@ -72,12 +64,6 @@
const price = (chain: ChainId) => sharePrice(chain, chainSize(game.board, chain));
const cost = $derived(Object.entries(shares).reduce((sum, [chain, n]) => sum + n * price(chain as ChainId), 0));
const total = $derived(Object.values(shares).reduce((sum, n) => sum + n, 0));
function placeSelected(): void {
if (store.selected !== undefined) {
store.send({ type: "place", tile: tileLabel(store.selected) });
}
}
</script>
{#if moves.length > 0 && !store.sending}
@ -115,18 +101,7 @@
{#if game.phase === "place"}
{#if store.selected !== undefined}
<p>
{t("place.effect", {
tile: tileLabel(store.selected),
effect: describePlacement(game, store.selected, lang),
})}
</p>
<button type="button" class="actionable primary" onclick={placeSelected}
>{t("place.button", { tile: tileLabel(store.selected) })}</button
>
<button type="button" class="actionable" onclick={() => (store.selected = undefined)}
>{t("place.another")}</button
>
<PlaceConfirm {store} />
{:else if legal("place")}
<p>{t("place.choose")}</p>
{/if}

View file

@ -0,0 +1,72 @@
<script lang="ts">
import { tileLabel } from "acquire-engine";
import { describePlacement } from "./decisions";
import type { ViewerStore } from "./store.svelte";
let {
store,
nearHand = false,
}: {
store: ViewerStore;
/** The copy under the rack on phones, where the decision panel is above the board, out of view. */
nearHand?: boolean;
} = $props();
const t = $derived(store.lang.t);
const tile = $derived(
store.state?.phase === "place" && store.moves.length > 0 && !store.sending ? store.selected : undefined
);
let row = $state<HTMLElement>();
// Bring the confirmation into view when it opens below a rack at the bottom of the screen.
$effect(() => {
if (nearHand && row && tile !== undefined && row.getClientRects().length > 0) {
const still = matchMedia("(prefers-reduced-motion: reduce)").matches;
row.scrollIntoView({ block: "nearest", behavior: still ? "auto" : "smooth" });
}
});
</script>
{#if tile !== undefined}
<div class="place-confirm" class:near-hand={nearHand} bind:this={row}>
<p>{t("place.effect", { tile: tileLabel(tile), effect: describePlacement(store.state!, tile, store.lang) })}</p>
<button
type="button"
class="actionable primary"
onclick={() => store.send({ type: "place", tile: tileLabel(tile) })}
>{t("place.button", { tile: tileLabel(tile) })}</button
>
<button type="button" class="actionable" onclick={() => (store.selected = undefined)}>{t("place.another")}</button>
</div>
{/if}
<style>
.place-confirm.near-hand {
margin-top: 8px;
padding: 10px 12px 12px;
background: var(--panel);
}
p {
margin: 0 0 8px;
}
button {
margin-block: 4px;
margin-inline: 0 8px;
padding: 6px 12px;
min-height: 36px;
background: var(--page);
color: var(--ink);
font: inherit;
border: none;
}
button.primary {
background: var(--accent);
color: var(--on-accent);
font-weight: 600;
}
@media (pointer: coarse) {
button {
min-height: 44px;
}
}
</style>

View file

@ -668,7 +668,7 @@ try {
await open(`players=4&moves=95&publicHoldings=1&theme=${theme}`);
const geometry = await page.evaluate(() => {
const main = document.querySelector("main");
const column = document.querySelector(".layout > .board");
const column = document.querySelector(".board-column > .board");
const frame = column.querySelector(".frame");
return {
margin: getComputedStyle(document.body).margin,
@ -1028,17 +1028,28 @@ try {
"desktop/phone undo, repeated private revisions, refresh, no undo network calls, one saved turn and one clock increment"
);
// The desktop used to stack every supporting panel in one tall sidebar. Check the rendered
// arrangement and height, not only horizontal overflow, before creating gallery images.
// The desktop used to stack every supporting panel in one tall sidebar, and later left empty
// areas beside the board. Each column now stacks its own panels; check the rendered arrangement.
await page.setViewportSize({ width: 1280, height: 900 });
await open("players=4&moves=95&publicHoldings=1");
const board = await page.locator(".layout > .board").boundingBox();
const panels = await Promise.all(
[".players", ".history", ".conversation"].map((selector) => page.locator(`.layout > ${selector}`).boundingBox())
);
for (const panel of panels) {
assert.ok(panel.y >= board.y + board.height, "supporting panels sit below the board");
assert.ok(Math.abs(panel.y - panels[0].y) < 1, "supporting panels share a desktop row");
const box = (selector) => page.locator(`.layout ${selector}`).boundingBox();
const columns = [
[".board-column > .board", ".board-column > .players"],
[".turn-column > .controls", ".turn-column > .hand", ".turn-column > .market"],
[".talk-column > .history", ".talk-column > .conversation"],
];
let previousColumn;
for (const column of columns) {
const boxes = await Promise.all(column.map(box));
for (const [index, panel] of boxes.entries()) {
assert.ok(Math.abs(panel.x - boxes[0].x) < 1, `${column[index]} stays in its column`);
if (index > 0) {
const gap = panel.y - (boxes[index - 1].y + boxes[index - 1].height);
assert.ok(gap >= 0 && gap < 40, `${column[index]} follows the panel above it without an empty area`);
}
}
assert.ok(!previousColumn || boxes[0].x > previousColumn.x + previousColumn.width, "desktop columns side by side");
previousColumn = boxes[0];
}
assert.ok((await page.locator("main").boundingBox()).height <= 900, "desktop game fits within 900px");
assert.equal(await page.locator(".log li").count(), 8);
@ -1046,7 +1057,7 @@ try {
assert.ok((await page.locator(".log li").count()) > 100, "full history remains available");
await page.locator(".history button").click();
assert.equal(await page.locator(".log li").count(), 8);
report.scenarios.push("balanced desktop panels, compact recent history and expandable full log");
report.scenarios.push("independent desktop columns, compact recent history and expandable full log");
for (const [name, params, width, height] of [
["overview", "players=4&moves=95&publicHoldings=1", 1280, 900],
@ -1057,7 +1068,7 @@ try {
for (const theme of ["light", "dark"]) {
await open(`${params}&theme=${theme}`);
const main = await page.locator("main").boundingBox();
const hand = await page.locator(".layout > .hand").boundingBox();
const hand = await page.locator(".turn-column > .hand").boundingBox();
// Desktop shows the whole compact layout. On phones frame the complete decision, board
// and hand, without appending a long column of tables, chat and history to the image.
const captureHeight = Math.ceil(width < 700 ? hand.y + hand.height + 12 : main.height);