Use shared BGS preferred colourblind player symbols
This commit is contained in:
parent
3e73e09536
commit
b96dcf69ce
5 changed files with 42 additions and 7 deletions
|
|
@ -15,7 +15,7 @@
|
|||
"test:locales": "node scripts/check-locales.mjs viewer/localization && node --test scripts/localization.test.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.8.1",
|
||||
"@boardgamers/protocol": "0.9.0",
|
||||
"@noble/hashes": "2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
|
|
@ -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
|
||||
|
|
@ -27,8 +27,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==}
|
||||
|
|
@ -220,7 +220,7 @@ packages:
|
|||
|
||||
snapshots:
|
||||
|
||||
'@boardgamers/protocol@0.8.1':
|
||||
'@boardgamers/protocol@0.9.0':
|
||||
dependencies:
|
||||
zod: 4.6.5
|
||||
|
||||
|
|
|
|||
17
test/player-symbols.test.js
Normal file
17
test/player-symbols.test.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { PLAYER_SYMBOLS } from "@boardgamers/protocol/player-symbols";
|
||||
import { colonySymbol, setPlayerSymbols } from "../viewer/art.js";
|
||||
|
||||
test("colony markers follow host symbols, accept live updates and restore legacy defaults", () => {
|
||||
const original = colonySymbol("green");
|
||||
const second = colonySymbol("red");
|
||||
setPlayerSymbols(["star", "hexagon"]);
|
||||
assert.ok(colonySymbol("green").includes(PLAYER_SYMBOLS.star.path));
|
||||
assert.ok(colonySymbol("red").includes(PLAYER_SYMBOLS.hexagon.path));
|
||||
setPlayerSymbols(["cross", "<svg>"]);
|
||||
assert.ok(colonySymbol("green").includes(PLAYER_SYMBOLS.cross.path));
|
||||
assert.equal(colonySymbol("red"), second);
|
||||
setPlayerSymbols();
|
||||
assert.equal(colonySymbol("green"), original);
|
||||
});
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
import {
|
||||
PLAYER_SYMBOLS,
|
||||
isPlayerSymbol,
|
||||
} from "@boardgamers/protocol/player-symbols";
|
||||
import { amoebaAdaptations } from "./amoeba-traits.js";
|
||||
|
||||
const colors = {
|
||||
|
|
@ -153,8 +157,20 @@ const colonySymbols = {
|
|||
black: '<path d="M8 2h8v6h6v8h-6v6H8v-6H2V8h6Z"/>',
|
||||
burgundy: '<path d="m12 1 3 7 8 1-6 6 2 8-7-4-7 4 2-8-6-6 8-1Z"/>',
|
||||
};
|
||||
let playerSymbols = [];
|
||||
export function setPlayerSymbols(preferred = []) {
|
||||
playerSymbols = Array.isArray(preferred)
|
||||
? preferred.map((s) => (isPlayerSymbol(s) ? s : null))
|
||||
: [];
|
||||
}
|
||||
const colonyShape = (color) => {
|
||||
const symbol = playerSymbols[seatColors.indexOf(color)];
|
||||
return symbol
|
||||
? `<path d="${PLAYER_SYMBOLS[symbol].path}"/>`
|
||||
: colonySymbols[color];
|
||||
};
|
||||
export const colonySymbol = (color) =>
|
||||
`<svg class="colony-symbol" data-colony="${color}" viewBox="0 0 24 24" fill="${colors[color].light}" stroke="#24433a" stroke-width="2.5" stroke-linejoin="round" aria-hidden="true">${colonySymbols[color]}</svg>`;
|
||||
`<svg class="colony-symbol" data-colony="${color}" viewBox="0 0 24 24" fill="${colors[color].light}" stroke="#24433a" stroke-width="2.5" stroke-linejoin="round" aria-hidden="true">${colonyShape(color)}</svg>`;
|
||||
|
||||
function amoeba(color, variant = 0, feature = "") {
|
||||
const c = colors[color];
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import {
|
|||
colonyTraits,
|
||||
PHASE_ICONS,
|
||||
setPlayerColors,
|
||||
setPlayerSymbols,
|
||||
displayColorName,
|
||||
} from "./art.js";
|
||||
import { geneArt } from "./gene-art.js";
|
||||
|
|
@ -740,6 +741,7 @@ export function mountGame(
|
|||
guide: $(".tutorial-slot"),
|
||||
setPlayerAppearance(preferences) {
|
||||
appearance = preferences.bgs ?? {};
|
||||
setPlayerSymbols(appearance.playerSymbols);
|
||||
setPlayerColors(
|
||||
preferences.bgs?.playerColors ?? [],
|
||||
preferences.colorBlind !== true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue