diff --git a/docs/releases/action-labels-2.3.23.json b/docs/releases/action-labels-2.3.23.json new file mode 100644 index 0000000..937e81d --- /dev/null +++ b/docs/releases/action-labels-2.3.23.json @@ -0,0 +1,52 @@ +{ + "game": "powergrid", + "gameVersion": 13, + "publishedAt": "2026-11-02T21:04:06.134Z", + "viewer": { + "version": "2.3.23", + "url": "https://s3.fr-par.scw.cloud/bgs-assets/games/powergrid/13/viewer/split-fdd1a2db7176e23c0b50/powergrid-viewer.umd.min.js", + "stylesheets": [ + "https://s3.fr-par.scw.cloud/bgs-assets/games/powergrid/13/viewer/split-fdd1a2db7176e23c0b50/powergrid-viewer.css" + ], + "scriptBytes": 1226805, + "sha256": "ddd2b31175fc8d71617bd289323590424355f9537eaad31043e3c10016f791fb", + "bundle": "split-fdd1a2db7176e23c0b50", + "files": 42 + }, + "addedPreferences": ["textActions"], + "preferences": [ + { + "label": "Enable sound when players move", + "type": "checkbox", + "name": "sound", + "items": null, + "default": false + }, + { + "name": "showUnselectedRegions", + "label": "Show unselected regions", + "type": "checkbox", + "default": true + }, + { + "label": "Adjust player order", + "type": "checkbox", + "name": "adjustPlayerOrder", + "items": null, + "default": false + }, + { + "name": "colorBlind", + "label": "Color-blind mode", + "type": "checkbox", + "default": false + }, + { + "name": "textActions", + "label": "Show action labels", + "type": "checkbox", + "default": false + } + ], + "verified": true +} diff --git a/docs/viewer-publishing.md b/docs/viewer-publishing.md index 8b576b2..054e83d 100644 --- a/docs/viewer-publishing.md +++ b/docs/viewer-publishing.md @@ -46,3 +46,19 @@ It uses the public deck count and remains stable during resource purchases and u After packaging, run `node viewer/scripts/action-controls-smoke.mjs` to check normal/only-pass states, hover/focus styling against the board-option buttons, resource/building/powering transitions, and plant borders. + +## Viewer 2.3.23: action labels + +The Aa toggle switches the phase and Undo buttons between pictograms and full, +translated text. Both modes reserve identical bounds, and disabled pictograms +fade like disabled text. The utility buttons share a light surface and an active +marker; the duplicate board sound button is removed (sound remains in the sidebar). + +This release adds +`{ "name": "textActions", "label": "Show action labels", "type": "checkbox", "default": false }` +to the BGS version 13 preferences, preserving every other preference. BGS only +persists declared preference names, so this addition must accompany the release. + +After packaging, `node viewer/scripts/action-labels-smoke.mjs` checks the two +presentations, keyboard toggling, translated text fitting in all 17 languages, +mobile/desktop geometry, saved-move undo and text-mode local undo. diff --git a/viewer/package.json b/viewer/package.json index cb0cb25..d6d3839 100644 --- a/viewer/package.json +++ b/viewer/package.json @@ -1,6 +1,6 @@ { "name": "powergrid-viewer", - "version": "2.3.22", + "version": "2.3.23", "repository": { "type": "git", "url": "git+https://github.com/boardgamers/powergrid.git", diff --git a/viewer/scripts/action-controls-smoke.mjs b/viewer/scripts/action-controls-smoke.mjs index 9171d2d..21c1516 100644 --- a/viewer/scripts/action-controls-smoke.mjs +++ b/viewer/scripts/action-controls-smoke.mjs @@ -91,6 +91,38 @@ try { await page.close(); console.log(`${mode}: hover matches board options; focus and market cues passed`); } + { + const page = await browser.newPage(); + await page.goto(`http://127.0.0.1:${server.address().port}/?mode=public&text=1`); + const pass = page.locator('[data-board-control="pass"]'); + const undo = page.locator('[data-board-control="undo"]'); + await pass.locator('[data-action-label]').waitFor(); + assert.equal(await pass.getAttribute('aria-disabled'), 'true'); + assert.equal(await undo.getAttribute('aria-disabled'), 'true'); + const fadedText = await pass.locator('[data-action-label]').evaluate((e) => getComputedStyle(e).fill); + assert.equal(fadedText, 'rgb(192, 192, 192)'); + await page.locator('[data-board-control="text-actions"]').click(); + await pass.locator('[data-phase-icon]').waitFor(); + const checkDisabled = async () => { + for (const selector of ['[data-phase-icon]', '[data-action-icon]', '.button-divider']) { + assert.equal(await pass.locator(selector).evaluate((e) => getComputedStyle(e).stroke), fadedText); + } + assert.equal( + await pass.locator('.phase-background').evaluate((e) => getComputedStyle(e).fill), + 'rgb(220, 220, 220)' + ); + assert.equal(await pass.locator('.button-outline').evaluate((e) => getComputedStyle(e).strokeWidth), '1px'); + assert.equal( + await undo.locator('[data-action-icon]').evaluate((e) => getComputedStyle(e).filter), + 'invert(0.75)' + ); + }; + await checkDisabled(); + await pass.hover(); + await checkDisabled(); + await page.close(); + console.log('Disabled controls: pictograms and divider match faded text, including on hover'); + } const page = await browser.newPage(); await page.goto(`http://127.0.0.1:${server.address().port}/?mode=resources`); const phaseButton = page.locator('[data-board-control="pass"]'); diff --git a/viewer/scripts/action-labels-smoke.mjs b/viewer/scripts/action-labels-smoke.mjs new file mode 100644 index 0000000..2e088a6 --- /dev/null +++ b/viewer/scripts/action-labels-smoke.mjs @@ -0,0 +1,162 @@ +// Run after packaging: node viewer/scripts/action-labels-smoke.mjs +import assert from 'node:assert/strict'; +import { readFile } from 'node:fs/promises'; +import { chromium } from 'playwright'; +import { auctionPreviewServer } from './auction-preview.mjs'; + +const server = auctionPreviewServer(); +await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve)); +const origin = `http://127.0.0.1:${server.address().port}`; +const locales = [ + 'en', + 'de', + 'fr', + 'pl', + 'ro', + 'el', + 'hi', + 'ru', + 'da', + 'pt-BR', + 'ko', + 'zh-TW', + 'zh-CN', + 'vi', + 'it', + 'nl', + 'fa', +]; +const browser = await chromium.launch({ executablePath: process.env.CHROMIUM_EXECUTABLE }); +const errors = []; +async function fits(page) { + await page.waitForFunction(() => + [...document.querySelectorAll('[data-action-label]')].every((label) => { + const border = label.parentElement.querySelector('.turn-action-border'); + const b = label.getBBox(); + return ( + b.x >= 7 && + b.x + b.width <= Number(border.getAttribute('width')) - 7 && + b.y >= 1 && + b.y + b.height <= Number(border.getAttribute('height')) - 1 + ); + }) + ); + const sizes = await page + .locator('[data-action-label]') + .evaluateAll((labels) => labels.map((label) => Number(label.getAttribute('font-size')))); + assert( + sizes.every((size) => size >= 10), + `complete labels remain readable: ${sizes}` + ); +} +try { + for (const width of [390, 1400]) { + const page = await browser.newPage({ viewport: { width, height: 900 } }); + page.on('pageerror', (error) => errors.push(error.message)); + await page.goto(`${origin}/?mode=your-turn`); + const toggle = page.locator('[data-board-control="text-actions"]'); + await toggle.waitFor(); + await page.evaluate(() => { + window.beforeTextMode = JSON.stringify(document.querySelector('.game').__vue__.G); + window.textModeMoves = []; + window.host.on('move', (move) => window.textModeMoves.push(move)); + }); + const geometry = await page.locator('[data-board-control="pass"]').boundingBox(); + await toggle.focus(); + await page.keyboard.press('Enter'); + await page.waitForFunction(() => document.querySelector('[data-action-label]')); + assert.equal(await toggle.getAttribute('aria-pressed'), 'true'); + assert.equal(await page.locator('[data-phase-icon]').count(), 0); + assert.equal( + await page.locator('[data-board-control="pass"] [data-action-label]').textContent(), + 'Skip auction' + ); + await fits(page); + // All language changes happen through the host, including back to English. + for (const locale of [...locales, 'en']) { + const catalog = JSON.parse(await readFile(new URL(`../src/localization/${locale}.json`, import.meta.url))); + await page.evaluate((locale) => window.host.emit('preferences', { locale }), locale); + await page.waitForFunction( + (expected) => + document.querySelector('[data-board-control="pass"] [data-action-label]').textContent === expected, + catalog['Skip auction'] + ); + await page.waitForFunction( + (expected) => + document.querySelector('[data-board-control="undo"] [data-action-label]').textContent === expected, + catalog['Undo last move'] + ); + await fits(page); + } + // The enabled map toggle uses the same light surface treatment and dark pictogram. + const map = page.locator('[data-board-control="unselected-regions"]'); + await map.hover(); + assert.equal( + await map.locator('.option-background').evaluate((e) => getComputedStyle(e).fill), + 'rgb(192, 192, 192)' + ); + assert.equal( + await map + .locator(':scope > g') + .first() + .evaluate((e) => getComputedStyle(e).stroke), + 'rgb(0, 0, 0)' + ); + await toggle.focus(); + await page.keyboard.press('Space'); + await page.waitForFunction(() => !document.querySelector('[data-action-label]')); + assert.equal(await toggle.getAttribute('aria-pressed'), 'false'); + const after = await page.locator('[data-board-control="pass"]').boundingBox(); + for (const key of ['x', 'y', 'width', 'height']) + assert(Math.abs(geometry[key] - after[key]) < 1, `stable ${key}`); + assert( + await page.evaluate( + () => window.beforeTextMode === JSON.stringify(document.querySelector('.game').__vue__.G) + ) + ); + assert.deepEqual(await page.evaluate(() => window.textModeMoves), []); + // Host pushes also select presentation, independent of clicking the toolbar. + await page.evaluate(() => window.host.emit('preferences', { textActions: true })); + await page.locator('[data-action-label]').first().waitFor(); + await page.evaluate(() => window.host.emit('undo:available', true)); + await page.locator('[data-board-control="undo-move"] [data-action-label]').waitFor(); + assert.equal( + await page.locator('[data-board-control="undo-move"] [data-action-label]').textContent(), + 'Undo my move' + ); + await fits(page); + await page.close(); + console.log( + `${width}px: Text/Icons, keyboard, host preference, saved-move undo, map hover and all 17 languages passed` + ); + } + for (const [mode, move, label] of [ + ['resources', 'BuyResource', 'Finish buying'], + ['building', 'Build', 'Finish building'], + ['powering', 'UsePowerPlant', 'Finish powering'], + ]) { + const page = await browser.newPage(); + page.on('pageerror', (error) => errors.push(error.message)); + await page.goto(`${origin}/?mode=${mode}&text=1`); + const actionLabel = page.locator('[data-board-control="pass"] [data-action-label]'); + await actionLabel.waitFor(); + assert.equal(await actionLabel.textContent(), label); + const echo = page.waitForResponse((r) => r.url().includes('/move?')); + await page.evaluate((move) => { + const game = document.querySelector('.game').__vue__; + game.sendMove({ name: move, data: game.G.players[0].availableMoves[move][0] }); + }, move); + await echo; + await page.locator('[data-board-control="undo"].enabled').waitFor(); + await page.locator('[data-board-control="undo"]').click(); + await page.locator('[data-board-control="undo"][aria-disabled="true"]').waitFor(); + assert.equal(await actionLabel.textContent(), label); + await fits(page); + await page.close(); + console.log(`${mode}: full action wording and working text-mode Undo passed`); + } + assert.deepEqual(errors, []); +} finally { + await browser.close(); + await new Promise((resolve) => server.close(resolve)); +} diff --git a/viewer/scripts/auction-preview.mjs b/viewer/scripts/auction-preview.mjs index eb647e9..7720d03 100644 --- a/viewer/scripts/auction-preview.mjs +++ b/viewer/scripts/auction-preview.mjs @@ -63,10 +63,11 @@ document.querySelector('#mode').value=mode; if(mode==='only-pass')document.querySelector('.hint').textContent='You have 1. No plant is affordable, so passing is the only legal action.'; if(mode==='building')document.querySelector('.hint').textContent='Build a city to change skip to confirm. Undo all builds to restore skip.'; if(mode==='powering')document.querySelector('.hint').textContent='Activate your oil plant to change skip to confirm. Hover its border to see the white highlight.'; -document.querySelector('#mode').onchange=e=>location.search='?mode='+e.target.value; +document.querySelector('#mode').onchange=e=>{query.set('mode',e.target.value);location.search='?'+query;}; async function send(path,body){const response=await fetch(path+'?mode='+mode,{method:body?'POST':'GET',headers:{'Content-Type':'application/json'},body:body?JSON.stringify(body):undefined});const data=await response.json();document.querySelector('#error').textContent=data.error||'';if(data.error)return;host.emit('settings',data.settings);host.emit('state',data.state);const button=document.querySelector('#opponent');button.textContent=data.next;button.disabled=!data.opponent;} host.on('fetchState',()=>send('/state'));host.on('move',move=>send('/move',{move}));host.on('update:setting',setting=>send('/setting',setting)); -host.emit('player',{index:0});host.emit('preferences',{sound:false,fitToScreen:true,locale:query.get('locale')||'en'});host.emit('chat:state',{canSend:false,mentions:[]}); +host.on('update:preference',({name,value})=>{if(name==='textActions'){query.set('text',value?'1':'0');history.replaceState(null,'','?'+query);}}); +host.emit('player',{index:0});host.emit('preferences',{sound:false,textActions:query.get('text')==='1',locale:query.get('locale')||'en'});host.emit('chat:state',{canSend:false,mentions:[]}); document.querySelector('#opponent').onclick=()=>send('/opponent',{});document.querySelector('#reset').onclick=()=>send('/reset',{});send('/state'); `; export function auctionPreviewServer() { diff --git a/viewer/src/components/Game.vue b/viewer/src/components/Game.vue index 9180bc1..003bc7e 100644 --- a/viewer/src/components/Game.vue +++ b/viewer/src/components/Game.vue @@ -485,6 +485,9 @@ :enabled="canUsePhaseButton" :highlightButton="highlightPhaseButton" :text="phaseButtonText" + :showText="!!preferences.textActions" + :width="168" + :height="32" :icon="phaseButtonIcon" :action="phaseButtonAction" @click="usePhaseButton" @@ -498,6 +501,9 @@ transform="translate(15, 56)" control="undo-move" text="Undo my move" + :showText="!!preferences.textActions" + :width="168" + :height="32" :enabled="true" :highlightButton="true" @click="undoMove()" @@ -510,10 +516,25 @@ :highlightButton="changingBid || canUndo()" :icon="changingBid ? 'cancel' : 'undo'" :text="changingBid ? 'Cancel bid edit' : 'Undo last move'" + :showText="!!preferences.textActions" + :width="168" + :height="32" @click="useUndoButton()" /> + - - + + + + diff --git a/viewer/src/components/buttons/BoardOption.vue b/viewer/src/components/buttons/BoardOption.vue index e759096..2a9f1e6 100644 --- a/viewer/src/components/buttons/BoardOption.vue +++ b/viewer/src/components/buttons/BoardOption.vue @@ -5,14 +5,20 @@ :data-board-control="control" role="button" :aria-label="label" - :aria-pressed="active ? 'true' : 'false'" + :aria-pressed="toggle ? (active ? 'true' : 'false') : undefined" tabindex="0" @click="$emit('click')" @keydown.enter.prevent="$emit('click')" @keydown.space.prevent="$emit('click')" > - -