Add shared color-blind mode with player and region markers
This commit is contained in:
parent
421546a136
commit
9c3d99b680
24 changed files with 124 additions and 4 deletions
|
|
@ -55,3 +55,9 @@ The ordinary viewer bundle exposes both `powergrid.launch` and `powergrid.launch
|
|||
Lessons live in `src/tutorial/lessons.ts`. Keep their IDs stable and increase a chapter's version when changing its setup or accepted actions would invalidate saved progress. Test normal board clicks, refresh, rewind and completion on desktop and mobile before release.
|
||||
|
||||
See the [desktop and mobile screenshots](docs/tutorials/README.md) for examples of the tutorial UI.
|
||||
|
||||
## Shared accessibility preference
|
||||
|
||||
The viewer accepts BGS's `colorBlind` boolean preference (default `false`). The eye button in the status bar changes it through `update:preference`, so BGS saves the setting across games. It also works locally in tutorials.
|
||||
|
||||
When enabled, houses on the map, turn-order track and city-count track carry their owner's seat number. Player panels use the same number, regardless of turn order or selected color. Map regions have distinct letter badges, with a fixed mapping that survives region selection. Resources already use different shapes.
|
||||
|
|
|
|||
|
|
@ -316,6 +316,26 @@ try {
|
|||
/unread/,
|
||||
'opening chat clears restored unread'
|
||||
);
|
||||
await page.evaluate(() => {
|
||||
window.preferenceUpdates = [];
|
||||
host.on('update:preference', (value) => preferenceUpdates.push(value));
|
||||
host.emit('preferences', { sound: false, colorBlind: true });
|
||||
});
|
||||
await page.waitForFunction(
|
||||
() => document.querySelector('.color-blind-toggle')?.getAttribute('aria-pressed') === 'true'
|
||||
);
|
||||
const owners = await page.locator('.house-owner text').allTextContents();
|
||||
assert.deepEqual([...new Set(owners.map((t) => t.trim()))].sort(), ['1', '2', '3']);
|
||||
assert.match(await page.locator('.player-board [data-bgs-player="1"]').textContent(), /2 · Ada Lovelace/);
|
||||
const regions = await page.locator('.region-labels text').allTextContents();
|
||||
assert.equal(regions.length, state.map.cities.length);
|
||||
assert.equal(new Set(regions).size, new Set(state.map.cities.map((city) => city.region)).size);
|
||||
await page.locator('#scene').screenshot({ path: `/tmp/powergrid-color-blind-${width}.png` });
|
||||
await page.getByRole('button', { name: 'Color-blind mode', exact: true }).click();
|
||||
await page.waitForFunction(() => !document.querySelector('.house-owner'));
|
||||
assert.equal(await page.locator('.region-labels').count(), 0);
|
||||
assert.doesNotMatch(await page.locator('.player-board [data-bgs-player="1"]').textContent(), /2 ·/);
|
||||
assert.deepEqual(await page.evaluate(() => preferenceUpdates), [{ name: 'colorBlind', value: false }]);
|
||||
await checkHostPresentation(page, 'host', `/tmp/powergrid-board-thumbnail-${width}.png`);
|
||||
assert.deepEqual(errors, []);
|
||||
await page.close();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,19 @@
|
|||
<div :class="['game', { fitToScreen: preferences.fitToScreen && !stacked, stacked: stacked }]">
|
||||
<div class="planner-header" :class="{ planning: hasPlanPanel }">
|
||||
<div class="statusBar">
|
||||
<button
|
||||
class="color-blind-toggle"
|
||||
aria-label="Color-blind mode"
|
||||
title="Color-blind mode"
|
||||
:aria-pressed="preferences.colorBlind ? 'true' : 'false'"
|
||||
@click="toggleColorBlind()"
|
||||
>
|
||||
<svg width="24" height="24" viewBox="0 0 30 30" aria-hidden="true">
|
||||
<path d="M4 15Q15 2 26 15Q15 28 4 15Z" fill="none" stroke="currentColor" stroke-width="1.7" />
|
||||
<circle cx="15" cy="15" r="4.5" fill="none" stroke="currentColor" stroke-width="1.7" />
|
||||
<path d="M15 10.5V19.5A4.5 4.5 0 0 1 15 10.5" fill="currentColor" />
|
||||
</svg>
|
||||
</button>
|
||||
<span class="status-message">{{ getStatusMessage() }}</span>
|
||||
<button
|
||||
v-if="!tutorialMove && !paused && canPlanRound && !roundPlan"
|
||||
|
|
@ -2263,6 +2276,11 @@ export default class Game extends Vue {
|
|||
return false;
|
||||
}
|
||||
|
||||
toggleColorBlind() {
|
||||
this.preferences.colorBlind = !this.preferences.colorBlind;
|
||||
this.emitter.emit('update:preference', { name: 'colorBlind', value: this.preferences.colorBlind });
|
||||
}
|
||||
|
||||
toggleSound() {
|
||||
const newSound = !this.preferences.sound;
|
||||
|
||||
|
|
@ -2840,6 +2858,28 @@ ul {
|
|||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.color-blind-toggle {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
padding: 0;
|
||||
border: 1px solid #93a786;
|
||||
border-radius: 5px;
|
||||
background: #253221;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
}
|
||||
.color-blind-toggle[aria-pressed='true'] {
|
||||
background: #eaf4cf;
|
||||
color: #203a45;
|
||||
}
|
||||
.color-blind-toggle:focus-visible {
|
||||
outline: 2px solid white;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.status-message {
|
||||
flex: 1;
|
||||
padding: 7px 0;
|
||||
|
|
|
|||
|
|
@ -196,6 +196,7 @@ export default class PlayerBoard extends Vue {
|
|||
name += '• ';
|
||||
}
|
||||
|
||||
if (this.preferences.colorBlind && this.owner !== undefined) name += `${this.owner + 1} · `;
|
||||
name += this.player.name;
|
||||
|
||||
if (this.ended) {
|
||||
|
|
|
|||
|
|
@ -387,6 +387,24 @@
|
|||
/>
|
||||
</template>
|
||||
|
||||
<g v-if="preferences.colorBlind" class="region-labels" pointer-events="none">
|
||||
<g
|
||||
v-for="city in cities"
|
||||
:key="city.name + '_regionLabel'"
|
||||
:transform="`translate(${city.x}, ${
|
||||
city.y - (city.connectionCost == null ? 24 : 32)
|
||||
}) rotate(${-mapRotation})`"
|
||||
>
|
||||
<rect x="-7" y="-7" width="14" height="14" rx="3" fill="#fffbe9" stroke="#17251d" />
|
||||
<text
|
||||
text-anchor="middle"
|
||||
dominant-baseline="central"
|
||||
style="font: bold 12px sans-serif; fill: #17251d"
|
||||
>{{ regionLabel(city.region) }}</text
|
||||
>
|
||||
</g>
|
||||
</g>
|
||||
|
||||
<!-- City tap targets, drawn LAST so they sit above the houses already built
|
||||
there. Houses are painted after the city's own circle, and SVG hit-testing
|
||||
takes the topmost element — so once a city held houses the active player
|
||||
|
|
@ -519,6 +537,10 @@ export default class Map extends Vue {
|
|||
|
||||
houses: Piece[] = [];
|
||||
|
||||
regionLabel(region: string) {
|
||||
return ({ blue: 'A', brown: 'B', cyan: 'C', green: 'D', orange: 'E', pink: 'F', purple: 'G', red: 'H', yellow: 'I', manhattan: 'J' } as Record<string, string>)[region] || '?';
|
||||
}
|
||||
|
||||
createPieces(gameState: GameState) {
|
||||
this.houses = [];
|
||||
gameState.players.forEach((player, pi) => {
|
||||
|
|
|
|||
|
|
@ -22,12 +22,23 @@
|
|||
stroke-width="12"
|
||||
stroke-miterlimit="10"
|
||||
/>
|
||||
<g v-if="preferences.colorBlind && owner !== undefined" class="house-owner" pointer-events="none">
|
||||
<circle cx="200" cy="285" r="143" fill="#fffbe9" stroke="#17251d" stroke-width="18" />
|
||||
<text
|
||||
x="200"
|
||||
y="288"
|
||||
text-anchor="middle"
|
||||
dominant-baseline="central"
|
||||
style="font: bold 255px sans-serif; fill: #17251d"
|
||||
>{{ owner + 1 }}</text
|
||||
>
|
||||
</g>
|
||||
<title>{{ houseTitle }}</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { PieceType } from './../../types/ui-data';
|
||||
import { Component, InjectReactive, Mixins, Prop } from 'vue-property-decorator';
|
||||
import { PieceType, Preferences } from './../../types/ui-data';
|
||||
import { Component, Inject, InjectReactive, Mixins, Prop } from 'vue-property-decorator';
|
||||
import Piece from './Piece.vue';
|
||||
|
||||
@Component({
|
||||
|
|
@ -36,6 +47,8 @@ import Piece from './Piece.vue';
|
|||
}
|
||||
})
|
||||
export default class House extends Mixins(Piece) {
|
||||
@Inject() readonly preferences!: Preferences;
|
||||
|
||||
@InjectReactive()
|
||||
readonly player!: number;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import { mountLocalization } from './localization';
|
||||
import { installPlayerCards, createBoardThumbnail } from './host-presentation';
|
||||
import { createViewer } from '@boardgamers/protocol/viewer';
|
||||
import { EventEmitter } from 'events';
|
||||
import type { GameState, Move } from 'powergrid-engine';
|
||||
|
|
@ -7,6 +5,8 @@ import type { PremoveCommand } from 'powergrid-engine/src/premoves';
|
|||
import Vue from 'vue';
|
||||
import Game from './components/Game.vue';
|
||||
import { mountGameChat } from './game-chat';
|
||||
import { createBoardThumbnail, installPlayerCards } from './host-presentation';
|
||||
import { mountLocalization } from './localization';
|
||||
import { installActionSounds } from './sounds';
|
||||
import type { Preferences } from './types/ui-data';
|
||||
import { shouldAdoptLogState } from './util/turn-buffer';
|
||||
|
|
@ -39,6 +39,7 @@ function launch(selector: string) {
|
|||
// toggles, platform preference pushes) would only paint on the next re-render.
|
||||
preferences: Vue.observable({
|
||||
sound: true,
|
||||
colorBlind: false,
|
||||
disableHelp: false,
|
||||
adjustPlayerOrder: false,
|
||||
undoWholeTurn: true,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"Color-blind mode": "Farveblind-tilstand",
|
||||
"\" not found for variant \"": "\" ikke fundet for variant \"",
|
||||
"#scene g.button": "#scene g.knap",
|
||||
"'s House": "'s Hus",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"Color-blind mode": "Modus für Farbenblindheit",
|
||||
"\" not found for variant \"": "„ nicht gefunden für Variante „",
|
||||
"#scene g.button": "#szene g.knopf",
|
||||
"'s House": "s Haus",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"Color-blind mode": "Λειτουργία για αχρωματοψία",
|
||||
"\" not found for variant \"": "\" δεν βρέθηκε για την παραλλαγή \"",
|
||||
"#scene g.button": "#scene g.button",
|
||||
"'s House": "του Οίκου",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"Color-blind mode": "Color-blind mode",
|
||||
"\" not found for variant \"": "\" not found for variant \"",
|
||||
"#scene g.button": "#scene g.button",
|
||||
"'s House": "'s House",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"Color-blind mode": "Mode daltonien",
|
||||
"\" not found for variant \"": "\" introuvable pour la variante \"",
|
||||
"#scene g.button": "#scene g.button",
|
||||
"'s House": "Maison de ",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"Color-blind mode": "रंग-अंधता मोड",
|
||||
"\" not found for variant \"": "\" वैरिएंट के लिए नहीं मिला \"",
|
||||
"#scene g.button": "#दृश्य g.button",
|
||||
"'s House": "का घर",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"Color-blind mode": "Modalità daltonici",
|
||||
"\" not found for variant \"": "\" non trovato per la variante \"",
|
||||
"#scene g.button": "#scena g.button",
|
||||
"'s House": "Casa di",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"Color-blind mode": "색각 이상 모드",
|
||||
"\" not found for variant \"": "\" 변형에 대해 찾을 수 없음 \"",
|
||||
"#scene g.button": "#scene g.button",
|
||||
"'s House": "의 집",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"Color-blind mode": "Modus voor kleurenblindheid",
|
||||
"\" not found for variant \"": "\" niet gevonden voor variant \"",
|
||||
"#scene g.button": "#scene g.button",
|
||||
"'s House": "'s Huis",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"Color-blind mode": "Tryb dla daltonistów",
|
||||
"\" not found for variant \"": "\" nie znaleziono dla wariantu \"",
|
||||
"#scene g.button": "#scena g.przycisk",
|
||||
"'s House": "Dom",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"Color-blind mode": "Modo daltônico",
|
||||
"\" not found for variant \"": "\" não encontrado para a variante \"",
|
||||
"#scene g.button": "#cena g.botão",
|
||||
"'s House": "Casa de ",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"Color-blind mode": "Mod pentru daltoniști",
|
||||
"\" not found for variant \"": "\" nu a fost găsit pentru varianta \"",
|
||||
"#scene g.button": "#scena g.buton",
|
||||
"'s House": "Casa lui",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"Color-blind mode": "Режим для дальтоников",
|
||||
"\" not found for variant \"": "\" не найдено для варианта \"",
|
||||
"#scene g.button": "#scene g.button",
|
||||
"'s House": "а Дом",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"Color-blind mode": "Chế độ mù màu",
|
||||
"\" not found for variant \"": "\" không tìm thấy cho biến thể \"",
|
||||
"#scene g.button": "#scene g.button",
|
||||
"'s House": "Nhà của",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"Color-blind mode": "色盲模式",
|
||||
"\" not found for variant \"": "」未找到,用於變體「",
|
||||
"#scene g.button": "#scene g.button",
|
||||
"'s House": "的房屋",
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ export const mountTutorial: TutorialMount = async (target, { chapter, onProgress
|
|||
emitter,
|
||||
preferences: Vue.observable({
|
||||
sound: false,
|
||||
colorBlind: false,
|
||||
disableHelp: false,
|
||||
adjustPlayerOrder: false,
|
||||
undoWholeTurn: true,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ export interface UIData {
|
|||
export type Preferences = {
|
||||
analysis?: boolean;
|
||||
sound: boolean;
|
||||
colorBlind: boolean;
|
||||
disableHelp: boolean;
|
||||
adjustPlayerOrder: boolean;
|
||||
undoWholeTurn: boolean;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue