Draw crisp vector ocean tiles with subtle accessible water motion

This commit is contained in:
coyotte508 2026-09-28 08:11:51 +02:00
commit 63a896d466
6 changed files with 105 additions and 27 deletions

View file

@ -44,6 +44,31 @@ const page = await browser.newPage({
page.on("pageerror", (e) => errors.push(e.message));
await page.goto(base + "/?new&hotseat");
await page.waitForSelector("[data-character-choice]");
// Decorative motion must never move a tile's clickable/focusable SVG bounds.
await page.emulateMedia({ reducedMotion: "no-preference" });
assert.equal(
await page.evaluate(() => {
const cells = [...document.querySelectorAll(".archipelago .map-cell")];
const bounds = () =>
cells.map((cell) => JSON.stringify(cell.getBoundingClientRect()));
const before = bounds();
const reflection = document.querySelector(".archipelago .water-shimmer");
const animation = reflection.getAnimations()[0];
animation.currentTime = 14000;
const unchanged = JSON.stringify(before) === JSON.stringify(bounds());
animation.currentTime = 0;
return unchanged;
}),
true,
);
await page.emulateMedia({ reducedMotion: "reduce" });
assert.equal(
await page
.locator(".archipelago .water-shimmer")
.evaluate((el) => getComputedStyle(el).animationName),
"none",
);
await page.emulateMedia({ reducedMotion: "no-preference" });
// Every supported locale must render translated action tooltips, not English fallbacks.
const tooltipSource = "Sail 1–3 ocean spaces, paying 1 vatu per space.";
for (const locale of [
@ -460,15 +485,17 @@ for (const width of [1440, 390]) {
assert.ok(
await page.locator(".sea-board").evaluate((board) => {
const upcoming = board.querySelector(".upcoming").getBoundingClientRect();
return [...board.querySelectorAll(".cell-surface")].every((path) => {
const cell = path.getBoundingClientRect();
return (
cell.bottom <= upcoming.top ||
cell.right <= upcoming.left ||
cell.top >= upcoming.bottom ||
cell.left >= upcoming.right
);
});
return [...board.querySelectorAll(".archipelago .cell-surface")].every(
(path) => {
const cell = path.getBoundingClientRect();
return (
cell.bottom <= upcoming.top ||
cell.right <= upcoming.left ||
cell.top >= upcoming.bottom ||
cell.left >= upcoming.right
);
},
);
}),
"Overview spaces must stay clear of the upcoming tiles",
);

View file

@ -1,4 +1,3 @@
import { assets } from "./assets.js";
import efate from "./assets/efate-board.webp";
import a1 from "./assets/tile-7-board.webp";
import a2 from "./assets/tile-9-board.webp";
@ -13,5 +12,4 @@ const islands = {
"tile-19": d1,
"tile-21": d2,
};
export const boardArt = (tile) =>
tile.type === "sea" ? assets.ocean : islands[tile.art];
export const boardArt = (tile) => islands[tile.art];

View file

@ -1,6 +1,7 @@
import { boardCells, tileState, TILES, COLORS } from "../engine/catalog.js";
import { esc, svgIcon, iconLabel } from "./art.js";
import { boardArt } from "./board-assets.js";
import { oceanDefs, oceanSurface } from "./ocean.js";
const tilt = (20 * Math.PI) / 180;
const rotate = (x, y) => ({
x: x * Math.cos(tilt) - y * Math.sin(tilt),
@ -40,10 +41,10 @@ function tilePath(x, y) {
const symbols = ["●", "◆", "▲", "■", "✦"];
function tileImage(spec, c, ghost = false, prefix = "board") {
const clip = `url(#${prefix}-cell-${c.q + 2}-${c.r})`;
const ocean = `<image href="${boardArt({ type: "sea" })}" x="${c.x - 111}" y="${c.y - 111}" width="222" height="222"/>`;
const ocean = oceanSurface(c, prefix);
const art =
spec.type === "island"
? `<image href="${boardArt(spec)}" x="${c.x - 88}" y="${c.y - 88}" width="176" height="176"/>`
? `<image href="${boardArt(spec)}" x="${c.x - 88}" y="${c.y - 88}" width="176" height="176" mask="url(#${prefix}-coast-mask)"/>`
: "";
return `<g ${ghost ? 'class="tile-ghost"' : ""} clip-path="${clip}" pointer-events="none">${ocean}${art}</g>`;
}
@ -92,7 +93,7 @@ export function boardSvg(
`<clipPath id="${prefix}-cell-${c.q + 2}-${c.r}"><path d="${tilePath(c.x, c.y)}"/></clipPath>`,
)
.join("");
let svg = `<svg class="${preview ? "tile-art" : "archipelago"}${overview ? " overview" : ""}" viewBox="${x0} ${y0} ${x1 - x0} ${y1 - y0}" role="group" aria-label="${preview ? esc(t(s.board["0,0"].type === "island" ? "island" : "sea")) : "Vanuatu"}"><defs>${defs}<filter id="${prefix}-boat-shadow" x="-25%" y="-25%" width="150%" height="150%"><feDropShadow dx="0" dy="0" stdDeviation=".9" flood-color="#fff9df" flood-opacity="1"/><feDropShadow dx="0" dy="2" stdDeviation="1.5" flood-opacity=".45"/></filter></defs>`;
let svg = `<svg class="${preview ? "tile-art" : "archipelago"}${overview ? " overview" : ""}" viewBox="${x0} ${y0} ${x1 - x0} ${y1 - y0}" role="group" aria-label="${preview ? esc(t(s.board["0,0"].type === "island" ? "island" : "sea")) : "Vanuatu"}"><defs>${defs}${oceanDefs(prefix)}<filter id="${prefix}-boat-shadow" x="-25%" y="-25%" width="150%" height="150%"><feDropShadow dx="0" dy="0" stdDeviation=".9" flood-color="#fff9df" flood-opacity="1"/><feDropShadow dx="0" dy="2" stdDeviation="1.5" flood-opacity=".45"/></filter></defs>`;
let dikes = "";
for (const c of all) {
const legal = targetSet.has(c.id),

36
viewer/ocean.js Normal file
View file

@ -0,0 +1,36 @@
// Vector water stays crisp at board zoom and in the full-size tile previews.
// All tiles sample the same pattern coordinates, so the currents join at edges.
export function oceanDefs(prefix) {
return `<linearGradient id="${prefix}-water-depth" gradientUnits="userSpaceOnUse" x1="100" y1="0" x2="1000" y2="900">
<stop stop-color="#6cdece"/><stop offset=".48" stop-color="#3fc9c3"/><stop offset="1" stop-color="#25acb4"/>
</linearGradient>
<pattern id="${prefix}-water-currents" width="240" height="200" patternUnits="userSpaceOnUse">
<g fill="none" stroke-linecap="round" stroke-linejoin="round">
<path d="M0 74C20 74 33 58 60 58S100 84 120 84 154 64 180 64 220 74 240 74M0 155C20 155 40 171 60 171S100 144 120 144 157 157 180 157 220 155 240 155" stroke="#137e9a" stroke-width="14" opacity=".035"/>
<path d="M0 68C20 68 33 52 60 52S100 78 120 78 154 58 180 58 220 68 240 68M0 149C20 149 40 165 60 165S100 138 120 138 157 151 180 151 220 149 240 149" stroke="#d9fff0" stroke-width="7" opacity=".06"/>
<g stroke="#d9fff0" stroke-width="1.2" opacity=".32">
<path d="M10 29C24 31 29 18 42 22S60 36 78 28M92 25C109 12 121 18 132 9M170 20C187 9 198 27 218 18"/>
<path d="M12 63C34 44 42 57 54 51M81 62C97 53 99 38 117 41S137 53 153 42M183 63C203 44 215 59 231 47"/>
<path d="M5 98C13 94 18 88 28 93M48 91C70 102 82 77 102 83M129 77C143 67 158 79 168 74M189 90C206 100 215 82 231 87"/>
<path d="M5 135C23 119 37 133 47 125M76 121C94 107 100 117 115 109M145 119C158 104 176 119 186 112M206 137C216 124 226 137 235 130"/>
<path d="M8 175C16 170 20 174 29 168M48 164C63 152 78 163 93 152M118 168C139 158 141 140 157 147M183 164C198 153 210 166 226 154"/>
</g>
</g>
</pattern>
<pattern id="${prefix}-water-light" width="240" height="200" patternUnits="userSpaceOnUse">
<g class="water-shimmer" pointer-events="none" fill="none" stroke="#f3fff2" stroke-width="1.5" stroke-linecap="round">
<path d="M32 40C45 34 52 44 63 36M135 99C148 94 157 103 168 95M79 179C91 168 103 181 113 172M207 69C218 60 227 67 237 61"/>
</g>
</pattern>
<radialGradient id="${prefix}-coast-fade"><stop offset=".8" stop-color="white"/><stop offset="1" stop-color="black"/></radialGradient>
<mask id="${prefix}-coast-mask" maskContentUnits="objectBoundingBox"><rect width="1" height="1" fill="url(#${prefix}-coast-fade)"/></mask>`;
}
export function oceanSurface(c, prefix) {
const bounds = `x="${c.x - 112}" y="${c.y - 112}" width="224" height="224"`;
return `<g class="ocean-surface" pointer-events="none" aria-hidden="true">
<rect ${bounds} fill="url(#${prefix}-water-depth)"/>
<rect ${bounds} fill="url(#${prefix}-water-currents)"/>
<rect ${bounds} fill="url(#${prefix}-water-light)"/>
</g>`;
}

View file

@ -301,9 +301,9 @@
content: "";
position: absolute;
inset: 0;
background-image: var(--ocean);
background-size: 850px;
opacity: 0.75;
background:
radial-gradient(ellipse at 18% 15%, #b6e7db70, transparent 65%),
linear-gradient(145deg, #80c7c5, #71b6c5);
pointer-events: none;
}
.vanuatu .map-scroll {
@ -522,7 +522,7 @@
height: 260px;
min-height: 0;
}
.vanuatu .upcoming img {
.vanuatu .upcoming .tile-art {
width: 57px;
height: 57px;
object-fit: contain;
@ -666,7 +666,7 @@
border-color: #b17734;
background: #f8e1ad;
}
.vanuatu .tile-choices img {
.vanuatu .tile-choices .tile-art {
width: 57px;
height: 57px;
object-fit: contain;
@ -1337,7 +1337,7 @@ body:has(.vanuatu) {
bottom: calc(var(--tray-height, 95px) + 11px);
right: 7px;
}
.vanuatu .upcoming img {
.vanuatu .upcoming .tile-art {
width: 37px;
height: 37px;
}
@ -1402,10 +1402,6 @@ body:has(.vanuatu) {
scroll-behavior: auto !important;
}
}
.vanuatu .sea-board:before {
opacity: 0.21;
background-size: 520px;
}
.vanuatu .archipelago {
overflow: hidden;
}
@ -1741,3 +1737,23 @@ body:has(.vanuatu) {
align-items: center;
gap: 4px;
}
/* Animate the paint inside the pattern, keeping tile geometry and hit areas fixed. */
.vanuatu .water-shimmer {
opacity: 0.2;
}
@media (prefers-reduced-motion: no-preference) {
.vanuatu .archipelago .water-shimmer {
animation: vanuatu-water-shimmer 14s ease-in-out infinite alternate;
}
}
@keyframes vanuatu-water-shimmer {
from {
opacity: 0.12;
transform: translate(-1px, 0);
}
to {
opacity: 0.3;
transform: translate(1px, 1px);
}
}

View file

@ -321,7 +321,7 @@ export function mountGame(target, options = {}) {
const m = moves.find(
(m) => m.type === "place" && m.tile === tile && m.cell === selected,
);
return `<div class="turn-tray"><div class="tray-title">${t("expand")} <small>${esc(translateText(REMAINING_TILES, lang))}: ${s.upcoming.length}</small></div><details class="expand-help"><summary>${t("help")}</summary><p>${esc(t(EXTEND_WHO))}</p><p>${esc(t(EXTEND_HOW))}</p></details><div class="tile-choices">${tileChoices.map((id) => btn(`<img src="${assets[TILES[id].art]}" alt="${TILES[id].type === "island" ? t("island") : t("sea")}">`, `data-tile="${id}" aria-pressed="${tile === id}"`)).join("")}</div>${m ? moveButton(m, true) : ""}</div>`;
return `<div class="turn-tray"><div class="tray-title">${t("expand")} <small>${esc(translateText(REMAINING_TILES, lang))}: ${s.upcoming.length}</small></div><details class="expand-help"><summary>${t("help")}</summary><p>${esc(t(EXTEND_WHO))}</p><p>${esc(t(EXTEND_HOW))}</p></details><div class="tile-choices">${tileChoices.map((id) => btn(tilePreviewSvg(id, { t, colorBlind, language: lang, prefix: "choice-" + id }), `data-tile="${id}" aria-pressed="${tile === id}"`)).join("")}</div>${m ? moveButton(m, true) : ""}</div>`;
}
if (s.phase === "rest")
return `<div class="turn-tray"><strong>${t("restChoice")}</strong>${moves
@ -411,7 +411,7 @@ export function mountGame(target, options = {}) {
.map((m) => m.cell)
: actualTargets();
const html = `<header class="game-header"><div class="brand">${btn("🏝️ Vanuatu", "data-boardgame", "wordmark")}<div class="game-credits"><span>Designed by Alain Epron</span><span>Published by Quined Games</span></div></div><div class="round-track" aria-label="${t("round")} ${s.round}/8">${Array.from({ length: 8 }, (_, i) => `<span title="${t("round")} ${i + 1}/8" class="${i + 1 === s.round ? "current" : i + 1 < s.round ? "past" : ""}">${i + 1}</span>`).join("")}</div><nav class="header-tools">${analysis || !options.chat ? "" : titled(t("chat"), `${icon("chat")}<span class="unread-badge" hidden></span>`, 'data-activity="chat"', "icon-button")}${titled(t("journal"), icon("journal"), 'data-activity="journal"', "icon-button")}${titled(t("colorBlind"), icon("colorBlind"), `data-color-blind aria-pressed="${colorBlind}"`, "icon-button")}${titled(t("help"), icon("help"), "data-help", "icon-button")}${titled(t("full"), icon("fullscreen"), "data-fullscreen", "icon-button")}</nav></header>
<div class="table">${dock()}<section class="sea-board" style="--ocean:url('${assets.ocean}')"><div class="sea-dashboard"><div class="market-info"><span class="fish-price" title="${esc(marketHelp)}">${icon("fish", marketHelp)} = ${token("coin", s.market, marketHelp)}</span><span title="${t("tourist")}">${token("tourist", s.tourists, `${"Tourists available this round"}: ${s.tourists}`)}</span>${s.waterCountdown !== null ? `<span title="${t("waterLeft")}">${token("water", s.waterCountdown, `${t("waterLeft")}: ${s.waterCountdown}`)}</span>` : ""}</div>${tradeShips()}</div><div class="map-scroll ${zoom ? "zoomed" : ""}">${boardSvg(s, { player, colorBlind, overview, language: lang, selected, targets, hoverTile: s.phase === "expand" ? tile : null, t })}</div><div class="map-tools">${titled(overview ? "Focus on placed tiles" : "Show full board", icon("overview"), `data-overview aria-pressed="${overview}"`, "icon-button")}${titled(zoom ? t("fit") : t("zoom"), icon(zoom ? "eye" : "zoom"), "data-zoom", "icon-button")}</div>${s.upcoming.length && s.phase !== "expand" ? titled(t("next"), `${s.upcoming.map((id) => `<img src="${assets[TILES[id].art]}" alt="">`).join("")}${icon("zoom", t("next"))}`, "data-upcoming", "upcoming") : ""}${trayHtml}</section></div><section class="players">${s.players.map(playerCard).join("")}</section><footer class="play-footer"><span title="${"Automatic conversion"}">${token("coin", 10)} → ${token("point", 5)}</span>${btn(t("help"), "data-help", "text-button")}</footer>`;
<div class="table">${dock()}<section class="sea-board"><div class="sea-dashboard"><div class="market-info"><span class="fish-price" title="${esc(marketHelp)}">${icon("fish", marketHelp)} = ${token("coin", s.market, marketHelp)}</span><span title="${t("tourist")}">${token("tourist", s.tourists, `${"Tourists available this round"}: ${s.tourists}`)}</span>${s.waterCountdown !== null ? `<span title="${t("waterLeft")}">${token("water", s.waterCountdown, `${t("waterLeft")}: ${s.waterCountdown}`)}</span>` : ""}</div>${tradeShips()}</div><div class="map-scroll ${zoom ? "zoomed" : ""}">${boardSvg(s, { player, colorBlind, overview, language: lang, selected, targets, hoverTile: s.phase === "expand" ? tile : null, t })}</div><div class="map-tools">${titled(overview ? "Focus on placed tiles" : "Show full board", icon("overview"), `data-overview aria-pressed="${overview}"`, "icon-button")}${titled(zoom ? t("fit") : t("zoom"), icon(zoom ? "eye" : "zoom"), "data-zoom", "icon-button")}</div>${s.upcoming.length && s.phase !== "expand" ? titled(t("next"), `${s.upcoming.map((id) => tilePreviewSvg(id, { t, colorBlind, language: lang, prefix: "upcoming-" + id })).join("")}${icon("zoom", t("next"))}`, "data-upcoming", "upcoming") : ""}${trayHtml}</section></div><section class="players">${s.players.map(playerCard).join("")}</section><footer class="play-footer"><span title="${"Automatic conversion"}">${token("coin", 10)} → ${token("point", 5)}</span>${btn(t("help"), "data-help", "text-button")}</footer>`;
// Patch in place so cached SVG tile images and focused controls survive
// preference changes and incoming state updates.
morphdom(play, `<div class="play">${html}</div>`, {