diff --git a/package.json b/package.json index 35a361f..43f17dd 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6a4034b..66f93c1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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 diff --git a/test/player-symbols.test.js b/test/player-symbols.test.js new file mode 100644 index 0000000..c59f26a --- /dev/null +++ b/test/player-symbols.test.js @@ -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: [""] }), + standard, + ); + assert.equal( + boardSvg(state, { t: (x) => x, playerSymbols: ["star"] }), + boardSvg(state, { t: (x) => x }), + ); + assert.deepEqual(state, before); +}); diff --git a/test/redraw-browser.mjs b/test/redraw-browser.mjs index 7525ecf..af78429 100644 --- a/test/redraw-browser.mjs +++ b/test/redraw-browser.mjs @@ -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`, diff --git a/viewer/board.js b/viewer/board.js index fb53dec..f547526 100644 --- a/viewer/board.js +++ b/viewer/board.js @@ -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) diff --git a/viewer/ui.js b/viewer/ui.js index 46e8345..a718de4 100644 --- a/viewer/ui.js +++ b/viewer/ui.js @@ -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 `
${btn(`${avatars[i] ? `` : ""}${colorBlind ? symbols[i] + " " : ""}${esc(p.name)}${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") : ""}${token("point", p.score)}
${token("coin", p.money)}${p.fish.length ? p.fish.map((n) => token("fish", n)).join("") : token("fish", 0)}${p.treasures.length ? p.treasures.map((n) => token("explore", n)).join("") : token("explore", 0)}${token("build", p.hutsLeft)}
${c ? `` : ""}${i === player ? `
${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")}"`) : ""}
` : ""}`; + return `
${btn(`${avatars[i] ? `` : ""}${colorBlind ? symbol(i) + " " : ""}${esc(p.name)}${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") : ""}${token("point", p.score)}
${token("coin", p.money)}${p.fish.length ? p.fish.map((n) => token("fish", n)).join("") : token("fish", 0)}${p.treasures.length ? p.treasures.map((n) => token("explore", n)).join("") : token("explore", 0)}${token("build", p.hutsLeft)}
${c ? `` : ""}${i === player ? `
${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")}"`) : ""}
` : ""}
`; } 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] - ? `${colorBlind ? symbols[i] : ""}${p.markers[a]}` + ? `${colorBlind ? symbol(i) : ""}${p.markers[a]}` : "", ) .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,