Color player and chain names in Acquire history

This commit is contained in:
coyotte508 2026-10-22 23:02:12 +02:00
commit daca2da620
13 changed files with 270 additions and 65 deletions

View file

@ -1,12 +1,12 @@
# Acquire private beta — 22 October 2026
Private BGS registration: `acquire`, version `1`. Engine `0.0.1`, viewer `0.0.5`.
Private BGS registration: `acquire`, version `1`. Engine `0.0.1`, viewer `0.0.6`.
Source: <https://github.com/boardgamers/mergers-game>. Keep `public: false`.
## Validation
- `pnpm check`: formatting, lint, TypeScript/Svelte checks, 198 engine tests,
51 viewer/tutorial tests, and the production build. Two pre-existing lint warnings
53 viewer/tutorial tests, and the production build. Two pre-existing lint warnings
remain (an unused test import and Svelte's `bind:this` assignment).
- Protocol diagnostics: all eight required engine methods; full core/chat/replay
viewer coverage, preferences, avatars and theme handlers. Protocol `0.10.0` is the
@ -27,6 +27,9 @@ Source: <https://github.com/boardgamers/mergers-game>. Keep `public: false`.
checks prevent oversized captures; desktop panels and the full-log toggle are checked.
- Wide-screen checks cover the full-window background, outer margins, board sizing,
permanently visible chat, player colors, and preservation of chat drafts when appearance changes.
- Log names use the same player colors as the table and chat. Chain names use their chain colors;
cash retains its currency symbol with emphasized, tabular digits. Checks cover both themes,
contrast, translated word order and player names that match chain names.
- Hand markers remain visible between turns, but only legal moves are clickable. Browser checks
cover selecting and confirming from the board, spectator privacy, and hiding markers in replay.

View file

@ -1,6 +1,6 @@
{
"name": "acquire-viewer",
"version": "0.0.5",
"version": "0.0.6",
"private": true,
"description": "Browser viewer for Acquire on boardgamers.space",
"license": "AGPL-3.0-only",

View file

@ -2,7 +2,8 @@
import { untrack } from "svelte";
import { mountChat } from "@boardgamers/protocol/chat/dom";
import { PLAYER_SYMBOL_IDS, playerSymbolSvg } from "@boardgamers/protocol/player-symbols";
import { playerColor, playerInk } from "./playerAppearance";
import { playerColor } from "./playerAppearance";
import { themeInk } from "./palette";
import { useStore } from "./store.svelte";
const store = useStore();
@ -26,8 +27,8 @@
const player = message.playerIndex;
const color = playerColor(player, store.appearance?.playerColors);
name.className = "player-name";
name.style.setProperty("--player-ink-light", playerInk(color, "light"));
name.style.setProperty("--player-ink-dark", playerInk(color, "dark"));
name.style.setProperty("--name-ink-light", themeInk(color, "light"));
name.style.setProperty("--name-ink-dark", themeInk(color, "dark"));
const marker = document.createElement("span");
marker.className = "player-color";
marker.style.background = color;

View file

@ -1,6 +1,8 @@
<script lang="ts">
import type { GameState } from "acquire-engine";
import { describeEntry } from "./format";
import { describeEntryParts, type LogPart } from "./format";
import { CHAIN_STYLES, themeInk } from "./palette";
import { playerColor } from "./playerAppearance";
import { useStore } from "./store.svelte";
let { state: game }: { state: GameState } = $props();
@ -15,8 +17,12 @@
// Newest first; "turn" entries become headings that group the lines below them.
const lines = $derived(
game.log
.map((entry, index) => ({ index, turn: entry.type === "turn", text: describeEntry(game, entry, store.lang) }))
.filter((line): line is { index: number; turn: boolean; text: string } => line.text !== undefined)
.map((entry, index) => ({
index,
turn: entry.type === "turn",
parts: describeEntryParts(game, entry, store.lang),
}))
.filter((line): line is { index: number; turn: boolean; parts: LogPart[] } => line.parts !== undefined)
.reverse()
);
</script>
@ -25,7 +31,23 @@
<h2>{t("log.title")}</h2>
<ol class="log">
{#each showAll ? lines : lines.slice(0, RECENT) as line (line.index)}
<li class:turn={line.turn}>{line.text}</li>
<li class:turn={line.turn}>
{#each line.parts as part}
{#if part.kind === "player" || part.kind === "chain"}
{@const color =
part.kind === "player"
? playerColor(game.seatOwner[part.seat] ?? part.seat, store.appearance?.playerColors)
: CHAIN_STYLES[part.chain].fill}
<span
class="name"
class:player-name={part.kind === "player"}
class:chain-name={part.kind === "chain"}
style:--name-ink-light={themeInk(color, "light")}
style:--name-ink-dark={themeInk(color, "dark")}>{part.text}</span
>
{:else if part.kind === "money"}<span class="money">{part.text}</span>{:else}{part.text}{/if}
{/each}
</li>
{/each}
</ol>
{#if lines.length > RECENT}
@ -50,6 +72,14 @@
font-weight: 600;
background: var(--panel-alt);
}
.name,
.money {
font-weight: 600;
}
.money {
white-space: nowrap;
font-variant-numeric: tabular-nums;
}
.more {
margin: 8px 0 0;
padding: 6px 12px;

View file

@ -2,7 +2,8 @@
import { PLAYER_SYMBOL_IDS, playerSymbolSvg } from "@boardgamers/protocol/player-symbols";
import type { GameState } from "acquire-engine";
import { seatName } from "./format";
import { playerColor, playerInk } from "./playerAppearance";
import { playerColor } from "./playerAppearance";
import { themeInk } from "./palette";
import { useStore } from "./store.svelte";
/** `playerOnly` names the player without a seat number (fourHands results are per player). */
@ -27,8 +28,8 @@
{#if symbol}<span class="symbol" aria-hidden="true">{@html playerSymbolSvg(symbol)}</span>{/if}
<span
class="player-name"
style:--player-ink-light={playerInk(color, "light")}
style:--player-ink-dark={playerInk(color, "dark")}
style:--name-ink-light={themeInk(color, "light")}
style:--name-ink-dark={themeInk(color, "dark")}
>{playerOnly ? game.seats[seat]!.name : seatName(game, seat, store.lang)}</span
>
{#if badge}<img class="badge" src={badge.url} alt={badge.label} title={badge.label} />{/if}

View file

@ -0,0 +1,63 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { initGame, type LogEntry } from "acquire-engine";
import { describeEntry, describeEntryParts, langFor } from "./format.ts";
import { LOCALES } from "./i18n.ts";
test("styled log preserves translations, lists and cash formatting", () => {
const state = initGame(3, {}, "log-colors");
const entries: LogEntry[] = [
...state.log,
{ type: "bought", seat: 0, shares: { tower: 1, luxor: 2 }, cost: 1200 },
{ type: "merger", seat: 0, tile: 3, sizes: { tower: 5, luxor: 5 } },
{ type: "mergerPlan", survivor: "tower", defunct: ["luxor", "imperial"] },
{
type: "bonuses",
chain: "luxor",
size: 5,
payouts: [
{ seat: 0, amount: 5000 },
{ seat: 1, amount: 2500 },
],
},
{ type: "disposed", seat: 1, chain: "luxor", sold: 1, traded: 2, held: 3, proceeds: 500 },
{ type: "finalSale", seat: 2, chain: "tower", shares: 2, proceeds: 2400 },
{ type: "result", cash: [15000, 10000, 7000], ranks: [1, 2, 3] },
];
for (const locale of LOCALES) {
const lang = langFor(locale);
for (const entry of entries) {
assert.equal(
describeEntryParts(state, entry, lang)
?.map((part) => part.text)
.join(""),
describeEntry(state, entry, lang),
`${locale}: ${entry.type}`
);
}
}
});
test("player names cannot be mistaken for chain names, markup or formatting tokens", () => {
const state = initGame(3, {}, "log-colors");
for (const name of ["Tower", "<img src=x>", "\uFFF90\uFFFB"]) {
state.seats[0]!.name = name;
const parts = describeEntryParts(
state,
{ type: "bought", seat: 0, shares: { tower: 1 }, cost: 200 },
langFor("en")
)!;
assert.deepEqual(
parts.filter((part) => part.kind === "player"),
[{ kind: "player", seat: 0, text: name }]
);
assert.deepEqual(
parts.filter((part) => part.kind === "chain"),
[{ kind: "chain", chain: "tower", text: "Tower" }]
);
assert.deepEqual(
parts.filter((part) => part.kind === "money"),
[{ kind: "money", text: "$200" }]
);
}
});

View file

@ -77,11 +77,22 @@ const BANK_TILE_KEYS = {
} as const satisfies Record<string, MessageKey>;
/** One log line, or undefined for entries that another line already describes. */
export function describeEntry(state: GameState, entry: LogEntry, lang: Lang): string | undefined {
const { t, list, money } = lang;
const seat = (index: number) => seatName(state, index, lang);
export function describeEntry(
state: GameState,
entry: LogEntry,
lang: Lang,
format: {
seat?: (index: number) => string;
chain?: (id: ChainId) => string;
money?: (amount: number) => string;
} = {}
): string | undefined {
const { t, list } = lang;
const money = format.money ?? lang.money;
const seat = format.seat ?? ((index: number) => seatName(state, index, lang));
const chain = format.chain ?? chainName;
const tiles = (count: number) => t("tiles", { count });
const shares = (count: number, chain: ChainId) => t("log.shares", { count, chain: chainName(chain) });
const shares = (count: number, id: ChainId) => t("log.shares", { count, chain: chain(id) });
switch (entry.type) {
case "init":
return t("log.init", { count: entry.players });
@ -104,11 +115,11 @@ export function describeEntry(state: GameState, entry: LogEntry, lang: Lang): st
case "place":
return t(entry.auto ? "log.placedAuto" : "log.placed", { name, tile: entry.move.tile });
case "survivor":
return t(entry.auto ? "log.survivorAuto" : "log.survivor", { name, chain: chainName(entry.move.chain) });
return t(entry.auto ? "log.survivorAuto" : "log.survivor", { name, chain: chain(entry.move.chain) });
case "defunctOrder":
return t(entry.auto ? "log.orderAuto" : "log.order", {
name,
chains: list(entry.move.chains.map(chainName)),
chains: list(entry.move.chains.map(chain)),
});
default:
return undefined;
@ -119,23 +130,21 @@ export function describeEntry(state: GameState, entry: LogEntry, lang: Lang): st
case "founded":
return t(entry.bonus ? "log.founded" : "log.foundedNoShare", {
name: seat(entry.seat),
chain: chainName(entry.chain),
chain: chain(entry.chain),
tiles: tiles(entry.size),
});
case "grew":
return t("log.grew", { chain: chainName(entry.chain), tiles: tiles(entry.size) });
return t("log.grew", { chain: chain(entry.chain), tiles: tiles(entry.size) });
case "merger": {
const chains = list(
Object.entries(entry.sizes).map(([chain, size]) => `${chainName(chain as ChainId)} (${size})`)
);
const chains = list(Object.entries(entry.sizes).map(([id, size]) => `${chain(id as ChainId)} (${size})`));
return entry.byBank
? t("log.mergerBank", { tile: tileLabel(entry.tile), chains })
: t("log.merger", { name: seat(entry.seat), tile: tileLabel(entry.tile), chains });
}
case "mergerPlan":
return t("log.mergerPlan", { survivor: chainName(entry.survivor), chains: list(entry.defunct.map(chainName)) });
return t("log.mergerPlan", { survivor: chain(entry.survivor), chains: list(entry.defunct.map(chain)) });
case "bonuses": {
const params = { chain: chainName(entry.chain), size: entry.size };
const params = { chain: chain(entry.chain), size: entry.size };
const paid = entry.payouts.map(({ seat: s, amount }) => `${seat(s)} ${money(amount)}`);
let line =
paid.length > 0 ? t("log.bonuses", { ...params, payouts: list(paid) }) : t("log.bonusesNobody", params);
@ -161,11 +170,11 @@ export function describeEntry(state: GameState, entry: LogEntry, lang: Lang): st
: t("log.disposedNothing", { name: seat(entry.seat) });
}
case "merged":
return t("log.merged", { chain: chainName(entry.survivor), tiles: tiles(entry.size) });
return t("log.merged", { chain: chain(entry.survivor), tiles: tiles(entry.size) });
case "bankTile":
return t(BANK_TILE_KEYS[entry.result], { tile: tileLabel(entry.tile) });
case "bought": {
const bought = Object.entries(entry.shares).map(([chain, n]) => `${n} ${chainName(chain as ChainId)}`);
const bought = Object.entries(entry.shares).map(([id, n]) => `${n} ${chain(id as ChainId)}`);
return bought.length > 0
? t("log.bought", { name: seat(entry.seat), shares: list(bought), cost: money(entry.cost) })
: t("log.boughtNothing", { name: seat(entry.seat) });
@ -184,10 +193,42 @@ export function describeEntry(state: GameState, entry: LogEntry, lang: Lang): st
return t("log.finalSale", {
name: seat(entry.seat),
count: entry.shares,
chain: chainName(entry.chain),
chain: chain(entry.chain),
amount: money(entry.proceeds),
});
case "result":
return t("log.result", { results: list(entry.cash.map((cash, s) => `${seat(s)} ${money(cash)}`)) });
}
}
export type LogPart =
| { kind: "text" | "money"; text: string }
| { kind: "player"; seat: number; text: string }
| { kind: "chain"; chain: ChainId; text: string };
/** Preserve translated word order and lists without matching names or inserting HTML. */
export function describeEntryParts(state: GameState, entry: LogEntry, lang: Lang): LogPart[] | undefined {
const references: LogPart[] = [];
const token = (part: LogPart) => `\uFFF9${references.push(part) - 1}\uFFFB`;
const line = describeEntry(state, entry, lang, {
seat: (seat) => token({ kind: "player", seat, text: seatName(state, seat, lang) }),
chain: (chain) => token({ kind: "chain", chain, text: chainName(chain) }),
money: (amount) => token({ kind: "money", text: lang.money(amount) }),
});
if (line === undefined) {
return undefined;
}
const parts: LogPart[] = [];
let offset = 0;
for (const match of line.matchAll(/\uFFF9(\d+)\uFFFB/g)) {
if (match.index > offset) {
parts.push({ kind: "text", text: line.slice(offset, match.index) });
}
parts.push(references[Number(match[1])] ?? { kind: "text", text: match[0] });
offset = match.index + match[0].length;
}
if (offset < line.length) {
parts.push({ kind: "text", text: line.slice(offset) });
}
return parts;
}

View file

@ -1,4 +1,5 @@
import type { ChainId } from "acquire-engine";
import { contrastRatio, hexToRgb } from "./color.ts";
export interface Theme {
page: string;
@ -145,3 +146,24 @@ export const OKABE_ITO_ORIGIN: Partial<Record<ChainId, string>> = {
festival: "#009e73",
continental: "#56b4e9",
};
/** Keep colored text readable across every surface in the current theme. */
export function themeInk(color: string, mode: "light" | "dark"): string {
const theme = THEMES[mode];
const rgb = hexToRgb(color);
const ink = hexToRgb(theme.ink);
for (let step = 0; step <= 20; step++) {
const mix = step / 20;
const candidate = `#${rgb
.map((value, i) =>
Math.round((value * (1 - mix) + ink[i]! * mix) * 255)
.toString(16)
.padStart(2, "0")
)
.join("")}`;
if ([theme.page, theme.panel, theme.panelAlt].every((background) => contrastRatio(candidate, background) >= 4.5)) {
return candidate;
}
}
return theme.ink;
}

View file

@ -1,13 +1,20 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { contrastRatio } from "./color.ts";
import { THEMES } from "./palette.ts";
import { PLAYER_COLORS, playerInk } from "./playerAppearance.ts";
import { THEMES, CHAIN_STYLES, themeInk } from "./palette.ts";
import { PLAYER_COLORS } from "./playerAppearance.ts";
test("default and custom player names remain readable on every light and dark surface", () => {
test("player and chain names remain readable on every light and dark surface", () => {
for (const mode of ["light", "dark"] as const) {
for (const color of [...PLAYER_COLORS, "#000000", "#ffffff", "#ffff00", "#13b7c8"]) {
const ink = playerInk(color, mode);
for (const color of [
...PLAYER_COLORS,
...Object.values(CHAIN_STYLES).map((style) => style.fill),
"#000000",
"#ffffff",
"#ffff00",
"#13b7c8",
]) {
const ink = themeInk(color, mode);
for (const surface of ["page", "panel", "panelAlt"] as const) {
assert.ok(contrastRatio(ink, THEMES[mode][surface]) >= 4.5, `${color} on ${mode} ${surface}`);
}

View file

@ -1,29 +1,6 @@
import { contrastRatio, hexToRgb } from "./color.ts";
import { THEMES } from "./palette.ts";
export const PLAYER_COLORS = ["#4595d1", "#e68b32", "#8a5cc2", "#3aa35b", "#d14545", "#d45c9e"];
export function playerColor(player: number, colors?: string[]): string {
const preferred = colors?.[player];
return preferred && /^#[\da-f]{6}$/i.test(preferred) ? preferred : PLAYER_COLORS[player % PLAYER_COLORS.length]!;
}
export function playerInk(color: string, mode: "light" | "dark"): string {
const theme = THEMES[mode];
const rgb = hexToRgb(color);
const ink = hexToRgb(theme.ink);
for (let step = 0; step <= 20; step++) {
const mix = step / 20;
const candidate = `#${rgb
.map((value, i) =>
Math.round((value * (1 - mix) + ink[i]! * mix) * 255)
.toString(16)
.padStart(2, "0")
)
.join("")}`;
if ([theme.page, theme.panel, theme.panelAlt].every((background) => contrastRatio(candidate, background) >= 4.5)) {
return candidate;
}
}
return theme.ink;
}

View file

@ -45,7 +45,7 @@ export class ViewerStore {
analysis = $state(false);
/** The shared BGS chat, one controller per viewer launch. */
readonly chat = new ChatController();
/** BGS's shared colour-blind setting: adds a pattern to every chain tile and table marker. */
/** BGS's shared colour-blind setting: supplies default player symbols. */
colorBlind = $state(false);
/** The BGS light/dark setting; undefined until BGS sends one (prefers-color-scheme applies). */
theme = $state<"light" | "dark" | undefined>();

View file

@ -26,15 +26,18 @@ body:has(.acquire) {
padding: 12px;
}
.acquire .player-name {
color: var(--player-ink-light);
.acquire .player-name,
.acquire .chain-name {
color: var(--name-ink-light);
}
.acquire[data-theme="dark"] .player-name {
color: var(--player-ink-dark);
.acquire[data-theme="dark"] .player-name,
.acquire[data-theme="dark"] .chain-name {
color: var(--name-ink-dark);
}
@media (prefers-color-scheme: dark) {
.acquire:not([data-theme]) .player-name {
color: var(--player-ink-dark);
.acquire:not([data-theme]) .player-name,
.acquire:not([data-theme]) .chain-name {
color: var(--name-ink-dark);
}
}

View file

@ -106,9 +106,39 @@ try {
assert.ok(Math.abs(geometry.board - geometry.column) < 1);
assert.equal(await page.locator(".chat summary").isVisible(), false);
assert.equal(await page.locator(".chat-composer").isVisible(), true);
const logAppearance = await page.evaluate(() => {
const colors = Object.fromEntries(
[...document.querySelectorAll(".players .player-name")].map((name) => [
name.textContent,
getComputedStyle(name).color,
])
);
return {
playersMatch: [...document.querySelectorAll(".log .player-name")].every(
(name) => getComputedStyle(name).color === colors[name.textContent]
),
chains: [
...new Set([...document.querySelectorAll(".log .chain-name")].map((name) => getComputedStyle(name).color)),
],
money: [...document.querySelectorAll(".log .money")].map((amount) => ({
text: amount.textContent,
weight: getComputedStyle(amount).fontWeight,
numbers: getComputedStyle(amount).fontVariantNumeric,
})),
};
});
assert.equal(logAppearance.playersMatch, true, "log player colors match the player table in each theme");
assert.ok(logAppearance.chains.length >= 3, "chain names retain distinct colors in the log");
assert.ok(logAppearance.money.length > 0);
for (const amount of logAppearance.money) {
assert.match(amount.text, /^\$/);
assert.equal(amount.weight, "600");
assert.equal(amount.numbers, "tabular-nums");
}
await page.screenshot({ path: new URL(`fullscreen-${theme}.png`, output).pathname });
}
report.scenarios.push("full-window theme background, no outer gutters, wider board and permanently visible chat");
report.scenarios.push("consistent player colors, distinct chain names and emphasized cash in light/dark logs");
await open("players=4&hotseat=0&view=0&theme=dark");
const inspectHand = async (view) => {
@ -174,13 +204,40 @@ try {
await preferences({
locale: "en",
colorBlind: true,
bgs: { players: [{}, {}, {}, {}], playerColors: ["#13b7c8", "#111111", "#ffffff", "#3aa35b"] },
bgs: {
players: [{ pro: true }, { pro: true }, { pro: true }, { pro: false }],
playerColors: ["#13b7c8", "#111111", "#ffffff", "#3aa35b"],
},
});
assert.equal(
await page.locator(".chat-composer input").inputValue(),
"Unsent draft",
"appearance updates preserve chat drafts"
);
const customAppearance = await page.evaluate(() => {
const names = Object.fromEntries(
[...document.querySelectorAll(".players .player-name")].map((name) => [
name.textContent,
getComputedStyle(name).color,
])
);
return {
markers: [...document.querySelectorAll(".players .color")].map((marker) => marker.style.background),
matches: [...document.querySelectorAll(".log .player-name, .chat .player-name")].every(
(name) => getComputedStyle(name).color === names[name.textContent]
),
};
});
assert.deepEqual(
customAppearance.markers,
["rgb(19, 183, 200)", "rgb(17, 17, 17)", "rgb(255, 255, 255)", "rgb(58, 163, 91)"],
"BGS supporter colors take precedence over game defaults"
);
assert.equal(
customAppearance.matches,
true,
"custom supporter colors update consistently in the table, chat and log"
);
await page.locator(".chat-composer input").fill("");
report.scenarios.push(
"chain letters without redundant patterns; player colors/symbols in chat and live appearance updates"