Use shared BGS preferred colourblind player symbols

This commit is contained in:
coyotte508 2026-10-02 11:07:48 +02:00
commit 3895ef60c3
6 changed files with 94 additions and 10 deletions

View file

@ -17,7 +17,7 @@
"test:tutorial:browser": "node test/tutorial-browser.mjs && node test/tutorial-walkthrough-browser.mjs"
},
"dependencies": {
"@boardgamers/protocol": "0.8.1",
"@boardgamers/protocol": "0.9.0",
"@noble/hashes": "2.0.1",
"morphdom": "2.7.8"
},

10
pnpm-lock.yaml generated
View file

@ -9,8 +9,8 @@ importers:
.:
dependencies:
'@boardgamers/protocol':
specifier: 0.8.1
version: 0.8.1
specifier: 0.9.0
version: 0.9.0
'@noble/hashes':
specifier: 2.0.1
version: 2.0.1
@ -30,8 +30,8 @@ importers:
packages:
'@boardgamers/protocol@0.8.1':
resolution: {integrity: sha512-BZNj+wof1aR1nSybRMqmQ+yAVNR3ZZy+mczIz2KbXSLXMLL3Jv21yi50CRbJ2ipdkPiPatcSP0nJj+xJbFgIfQ==}
'@boardgamers/protocol@0.9.0':
resolution: {integrity: sha512-xDQMui0xqqRF/ERIJ7Rm79JonMA2+6zn1CrgxpM6Oy3SpFKF6i0Wo6oAyYYqMveqiWJCkC0WvHlePclVfbH/IQ==}
'@esbuild/aix-ppc64@0.25.12':
resolution: {integrity: sha512-Hhmwd6CInZ3dwpuGTF8fJG6yoWmsToE+vYgD4nytZVxcu1ulHpUQRAB1UJ8+N1Am3Mz4+xOByoQoSZf4D+CpkA==}
@ -226,7 +226,7 @@ packages:
snapshots:
'@boardgamers/protocol@0.8.1':
'@boardgamers/protocol@0.9.0':
dependencies:
zod: 4.6.5

View file

@ -0,0 +1,39 @@
import test from "node:test";
import assert from "node:assert/strict";
import { init } from "../engine/index.js";
import { build } from "esbuild";
const { outputFiles } = await build({
entryPoints: ["viewer/board.js"],
bundle: true,
write: false,
platform: "node",
format: "esm",
loader: { ".webp": "dataurl" },
});
const { boardSvg } = await import(
"data:text/javascript;base64," +
Buffer.from(outputFiles[0].text).toString("base64")
);
test("boat ownership symbols use host assignments only in colourblind mode", () => {
const state = init(3, [], {}, "symbols");
const before = structuredClone(state);
const options = { t: (x) => x, colorBlind: true };
const standard = boardSvg(state, options);
const custom = boardSvg(state, {
...options,
playerSymbols: ["star", "hexagon", "cross"],
});
assert.ok(custom.includes("★"));
assert.ok(custom.includes("⬢"));
assert.notEqual(custom, standard);
assert.equal(
boardSvg(state, { ...options, playerSymbols: ["<svg>"] }),
standard,
);
assert.equal(
boardSvg(state, { t: (x) => x, playerSymbols: ["star"] }),
boardSvg(state, { t: (x) => x }),
);
assert.deepEqual(state, before);
});

View file

@ -204,6 +204,41 @@ try {
}, state);
assert.equal(await page.locator(".event-beg").count(), 0);
assert.equal(await fish.textContent(), "2");
await page.evaluate(async () => {
host.emit("preferences", {
locale: "fr",
sound: false,
colorBlind: true,
bgs: {
players: [],
playerColors: [],
playerSymbols: ["star", "hexagon", "cross"],
},
});
await settle();
});
assert.equal(
await page.locator(".boat.own .color-symbol").textContent(),
"★",
);
await page.evaluate(async () => {
host.emit("preferences", {
locale: "fr",
sound: false,
colorBlind: true,
bgs: {
players: [],
playerColors: [],
playerSymbols: ["diamond", "hexagon", "cross"],
},
});
await settle();
});
assert.equal(
await page.locator(".boat.own .color-symbol").textContent(),
"◆",
"symbol-only updates invalidate the board cache",
);
assert.deepEqual(errors, []);
console.log(
`${width}px: duplicate updates, sound, marker-only changes, selection reset, resources and retained journal rows passed`,

View file

@ -1,3 +1,4 @@
import { playerSymbolGlyph } from "@boardgamers/protocol/player-symbols";
import { boardCells, tileState, TILES, COLORS } from "../engine/catalog.js";
import { esc, svgIcon, iconLabel } from "./art.js";
import { boardArt } from "./board-assets.js";
@ -38,7 +39,7 @@ function tilePath(x, y) {
}
return path + "Z";
}
const symbols = ["●", "◆", "▲", "■", "✦"];
const defaultSymbols = ["●", "◆", "▲", "■", "✦"];
function tileImage(spec, c, ghost = false, prefix = "board") {
const clip = `url(#${prefix}-cell-${c.q + 2}-${c.r})`;
const ocean = oceanSurface(c, prefix);
@ -73,6 +74,7 @@ export function boardSvg(
hoverTile,
player,
colorBlind = false,
playerSymbols = [],
overview = false,
preview = false,
prefix = "board",
@ -80,6 +82,9 @@ export function boardSvg(
t,
} = {},
) {
const symbols = defaultSymbols.map((fallback, i) =>
playerSymbolGlyph(playerSymbols[i], fallback),
);
const label = (name) => iconLabel(name, language);
const targetSet = new Set(targets);
const all = boardCells(s)

View file

@ -1,3 +1,4 @@
import { playerSymbolGlyph } from "@boardgamers/protocol/player-symbols";
import { blockingHtml, blockingText } from "./blocking.js";
import {
playerColorState,
@ -55,7 +56,7 @@ const actionHelp = {
"Bring a tourist to an adjacent island and earn 1 vatu for every hut there, of any colour.",
rest: "Choose a rest token. Its bonus is resolved at the end of the round.",
};
const symbols = ["●", "◆", "▲", "■", "✦"];
const defaultSymbols = ["●", "◆", "▲", "■", "✦"];
export function mountGame(target, options = {}) {
const root = document.createElement("div");
root.className = "vanuatu";
@ -67,6 +68,8 @@ export function mountGame(target, options = {}) {
feedback = root.querySelector(".feedback");
let avatars = [];
let appearance = {};
const symbol = (i) =>
playerSymbolGlyph(appearance.playerSymbols?.[i], defaultSymbols[i]);
const playerBadge = (i) => {
const badge = appearance.players?.[i]?.pro && appearance.supporterBadge;
return badge
@ -256,7 +259,7 @@ export function mountGame(target, options = {}) {
}
function playerCard(p, i) {
const c = CHARACTERS[p.character];
return `<section class="player-card ${i === s.actor && !s.finished ? "active" : ""} ${i === player ? "own" : ""}" style="--player:${p.color};--player-ink:${playerColorInk(p.color)};--player-text:${playerColorText(p.color)}"><div class="player-name">${btn(`${avatars[i] ? `<img class="player-avatar" src="${esc(avatars[i])}" alt="">` : ""}<span>${colorBlind ? symbols[i] + " " : ""}${esc(p.name)}</span>${playerBadge(i)}`, `data-bgs-player="${i}" title="${esc(p.name)}"`, "profile")} ${s.first === i ? btn(icon("first", translateText(FIRST_HELP, lang)), `data-first-help aria-label="${t("first")}"`, "icon-button") : ""}<strong class="score">${token("point", p.score)}</strong></div><div class="player-supplies">${token("coin", p.money)}<span class="hand" title="${t("fishStock")}">${p.fish.length ? p.fish.map((n) => token("fish", n)).join("") : token("fish", 0)}</span><span class="hand" title="${t("treasure")}">${p.treasures.length ? p.treasures.map((n) => token("explore", n)).join("") : token("explore", 0)}</span>${token("build", p.hutsLeft)}</div>${c ? `<button type="button" class="character-owned ${p.used ? "used" : ""}" data-character="${p.character}" title="${charName(p.character)}"><img src="${assets["character-" + c.art]}" alt=""><span>${charName(p.character)}</span>${p.used ? icon("check") : icon(c.action ?? "point")}</button>` : ""}${i === player ? `<div class="free-actions">${legal().some((m) => m.type === "treasure") ? btn(`${icon("explore")} → ${icon("coin")}`, `data-free="treasure" title="${t("treasure")}"`) : ""}${legal().some((m) => m.type === "beg") ? btn(`${icon("point")} → ${icon("coin")}`, `data-free="beg" title="${t("beg")}"`) : ""}</div>` : ""}</section>`;
return `<section class="player-card ${i === s.actor && !s.finished ? "active" : ""} ${i === player ? "own" : ""}" style="--player:${p.color};--player-ink:${playerColorInk(p.color)};--player-text:${playerColorText(p.color)}"><div class="player-name">${btn(`${avatars[i] ? `<img class="player-avatar" src="${esc(avatars[i])}" alt="">` : ""}<span>${colorBlind ? symbol(i) + " " : ""}${esc(p.name)}</span>${playerBadge(i)}`, `data-bgs-player="${i}" title="${esc(p.name)}"`, "profile")} ${s.first === i ? btn(icon("first", translateText(FIRST_HELP, lang)), `data-first-help aria-label="${t("first")}"`, "icon-button") : ""}<strong class="score">${token("point", p.score)}</strong></div><div class="player-supplies">${token("coin", p.money)}<span class="hand" title="${t("fishStock")}">${p.fish.length ? p.fish.map((n) => token("fish", n)).join("") : token("fish", 0)}</span><span class="hand" title="${t("treasure")}">${p.treasures.length ? p.treasures.map((n) => token("explore", n)).join("") : token("explore", 0)}</span>${token("build", p.hutsLeft)}</div>${c ? `<button type="button" class="character-owned ${p.used ? "used" : ""}" data-character="${p.character}" title="${charName(p.character)}"><img src="${assets["character-" + c.art]}" alt=""><span>${charName(p.character)}</span>${p.used ? icon("check") : icon(c.action ?? "point")}</button>` : ""}${i === player ? `<div class="free-actions">${legal().some((m) => m.type === "treasure") ? btn(`${icon("explore")} → ${icon("coin")}`, `data-free="treasure" title="${t("treasure")}"`) : ""}${legal().some((m) => m.type === "beg") ? btn(`${icon("point")} → ${icon("coin")}`, `data-free="beg" title="${t("beg")}"`) : ""}</div>` : ""}</section>`;
}
function dock() {
const planning = ["plan", "neutral"].includes(s.phase) && working().length;
@ -319,7 +322,7 @@ export function mountGame(target, options = {}) {
const stacks = s.players
.map((p, i) =>
p.markers[a]
? `<span class="marker-stack ${s.majorities?.[i]?.includes(a) ? "majority" : ""}" style="--player:${p.color};--player-ink:${playerColorInk(p.color)};--player-text:${playerColorText(p.color)}" title="${esc(p.name)}: ${p.markers[a]}">${colorBlind ? symbols[i] : ""}${p.markers[a]}</span>`
? `<span class="marker-stack ${s.majorities?.[i]?.includes(a) ? "majority" : ""}" style="--player:${p.color};--player-ink:${playerColorInk(p.color)};--player-text:${playerColorText(p.color)}" title="${esc(p.name)}: ${p.markers[a]}">${colorBlind ? symbol(i) : ""}${p.markers[a]}</span>`
: "",
)
.join("");
@ -447,6 +450,7 @@ export function mountGame(target, options = {}) {
s.players.map(({ boat, name, color }) => [boat, name, color]),
player,
colorBlind,
appearance.playerSymbols,
lang,
selected,
targets,
@ -457,6 +461,7 @@ export function mountGame(target, options = {}) {
boardHtml = boardSvg(s, {
player,
colorBlind,
playerSymbols: appearance.playerSymbols,
language: lang,
selected,
targets,