diff --git a/test/turn-controls-browser.mjs b/test/turn-controls-browser.mjs index f523dcf..8f9554f 100644 --- a/test/turn-controls-browser.mjs +++ b/test/turn-controls-browser.mjs @@ -65,7 +65,19 @@ try { await page .locator(".board-wrap") .screenshot({ path: `/tmp/soup-food-before-${width}.png` }); - await foodToggle.click(); + // Hold near the edge: a press animation must not move the target out + // from under the pointer before release, cancelling the click. + await foodToggle.scrollIntoViewIfNeeded(); + const foodToggleBox = await foodToggle.boundingBox(); + await page.mouse.move(foodToggleBox.x + 8, foodToggleBox.y + 22); + await page.mouse.down(); + await page.waitForTimeout(200); + assert.deepEqual( + await foodToggle.boundingBox(), + foodToggleBox, + "The food toggle stays still while pressed", + ); + await page.mouse.up(); assert.equal(await foodToggle.getAttribute("aria-pressed"), "true"); assert.equal(await foodToggle.getAttribute("aria-label"), "Show amoebas"); assert.equal(await page.locator(".amoeba-button:visible").count(), 0); diff --git a/viewer/index.js b/viewer/index.js index 0eb0672..95cc49a 100644 --- a/viewer/index.js +++ b/viewer/index.js @@ -113,7 +113,7 @@ registerViewer( ctx.target.querySelector(".board"), size, "#eef1e5", - ".pond-tools, .board-actions", + ".pond-tools, .board-actions, .board-visibility", ); }, async onPreferences(preferences) { diff --git a/viewer/style.css b/viewer/style.css index e91589b..fcd0ef2 100644 --- a/viewer/style.css +++ b/viewer/style.css @@ -485,10 +485,36 @@ } .soup .pond-tools { position: absolute; - top: 2%; - right: 1%; + top: calc(2% + 14px); + right: calc(1% + 52px); z-index: 1; } +.soup .board-visibility { + position: absolute; + right: 1%; + top: 2%; + z-index: 2; + width: 44px; + height: 44px; + padding: 10px; + color: #6a8173; + background: transparent; + border-color: transparent; + box-shadow: none; +} +.soup .board-visibility:active { + transform: none; +} +.soup .board-visibility svg { + width: 22px; + height: 22px; +} +.soup .board-visibility:hover, +.soup .board-visibility[aria-pressed="true"] { + color: var(--ink); + background: #e0eacb; + border-color: var(--line); +} .soup-board-key { display: flex; flex-direction: column; @@ -1413,6 +1439,13 @@ } @media (max-width: 1000px) { + .soup .board-wrap { + padding-top: 28px; + } + .soup .pond-tools { + top: -24px; + right: 1%; + } .player-income .income-unit { display: none; } @@ -1630,11 +1663,6 @@ width: 3px; height: 3px; } - .soup .pond-tools { - flex-direction: column; - align-items: flex-end; - gap: 7px; - } .soup .pond-bottom { padding: 3px 5px 9px; } diff --git a/viewer/ui.js b/viewer/ui.js index 1f8f6cd..6bfb71b 100644 --- a/viewer/ui.js +++ b/viewer/ui.js @@ -248,7 +248,7 @@ export function mountGame( target.append(root); root.innerHTML = `
${amoeba("green", 0)}

primordial soup.

-
${chat ? `` : ""}
CURRENT
➜
+
${chat ? `` : ""}
CURRENT
➜
`; const $ = (q) => root.querySelector(q), @@ -465,10 +465,14 @@ export function mountGame( ``, ); } - movementButtons.push( - ``, + const visibility = $('[data-ui="food-view"]'); + visibility.setAttribute("aria-pressed", String(foodView)); + visibility.setAttribute( + "aria-label", + foodView ? "Show amoebas" : "Hide amoebas", ); - $(".board-actions").hidden = false; + visibility.title = foodView ? "Show amoebas" : "Hide amoebas"; + $(".board-actions").hidden = movementButtons.length === 0; $(".board-actions").innerHTML = movementButtons.join(""); const direction = state.environment.direction; $(".board").dataset.current = ["west", "north", "east", "south", "still"][