236 lines
12 KiB
JavaScript
236 lines
12 KiB
JavaScript
import {
|
|
PLAYER_SYMBOLS,
|
|
isPlayerSymbol,
|
|
} from "@boardgamers/protocol/player-symbols";
|
|
import { amoebaAdaptations } from "./amoeba-traits.js";
|
|
|
|
const colors = {
|
|
black: {
|
|
body: "#7f8589",
|
|
shade: "#505960",
|
|
light: "#c7cdd0",
|
|
stroke: "#303b43",
|
|
cheek: "#70777e",
|
|
},
|
|
burgundy: {
|
|
body: "#b479aa",
|
|
shade: "#855076",
|
|
light: "#ebc5e0",
|
|
stroke: "#683b5b",
|
|
cheek: "#ac6797",
|
|
},
|
|
green: {
|
|
body: "#b7d967",
|
|
shade: "#8cb74a",
|
|
light: "#e5ef9e",
|
|
stroke: "#52753c",
|
|
cheek: "#96bc50",
|
|
},
|
|
red: {
|
|
body: "#e99b8a",
|
|
shade: "#ce7969",
|
|
light: "#ffcab2",
|
|
stroke: "#a06151",
|
|
cheek: "#d6776e",
|
|
},
|
|
blue: {
|
|
body: "#8eb8d5",
|
|
shade: "#6398bc",
|
|
light: "#c5e0e7",
|
|
stroke: "#4a7c96",
|
|
cheek: "#7ca8c9",
|
|
},
|
|
yellow: {
|
|
body: "#eed17c",
|
|
shade: "#d4b14e",
|
|
light: "#fff0b4",
|
|
stroke: "#aa8c45",
|
|
cheek: "#dfb965",
|
|
},
|
|
};
|
|
const originalColors = structuredClone(colors);
|
|
const seatColors = ["green", "red", "blue", "yellow", "black", "burgundy"];
|
|
let colourLabels = [];
|
|
const mix = (hex, target, amount) =>
|
|
"#" +
|
|
[1, 3, 5]
|
|
.map((i) =>
|
|
Math.round(
|
|
parseInt(hex.slice(i, i + 2), 16) * (1 - amount) + target * amount,
|
|
)
|
|
.toString(16)
|
|
.padStart(2, "0"),
|
|
)
|
|
.join("");
|
|
export function setPlayerColors(preferred = [], enabled = true) {
|
|
colourLabels = [];
|
|
seatColors.forEach((key, i) => {
|
|
const hex = enabled && Array.isArray(preferred) ? preferred[i] : undefined;
|
|
if (typeof hex !== "string" || !/^#[a-f0-9]{6}$/i.test(hex)) {
|
|
colors[key] = { ...originalColors[key] };
|
|
return;
|
|
}
|
|
const original = Object.entries(originalColors).find(
|
|
([, v]) => v.body.toLowerCase() === hex.toLowerCase(),
|
|
);
|
|
colors[key] = original
|
|
? { ...original[1] }
|
|
: {
|
|
body: hex,
|
|
shade: mix(hex, 0, 0.15),
|
|
light: mix(hex, 255, 0.5),
|
|
stroke: mix(hex, 0, 0.4),
|
|
cheek: mix(hex, 0, 0.1),
|
|
};
|
|
const names = {
|
|
"#da4a47": "Red",
|
|
"#e68b32": "Orange",
|
|
"#e8c844": "Yellow",
|
|
"#42a06a": "Green",
|
|
"#4595d1": "Blue",
|
|
"#9868c5": "Purple",
|
|
"#da73aa": "Pink",
|
|
"#e8e7de": "White",
|
|
"#414955": "Black",
|
|
};
|
|
colourLabels[i] = original
|
|
? original[0]
|
|
: (names[hex.toLowerCase()] ?? "Player " + (i + 1));
|
|
});
|
|
}
|
|
export function displayColorName(index, fallback) {
|
|
return colourLabels[index] || fallback;
|
|
}
|
|
const iconPaths = {
|
|
"colony-symbols":
|
|
'<circle cx="6" cy="7" r="4"/><path d="m17 3 5 9H12Z"/><rect x="3" y="15" width="8" height="7" rx="1"/><path d="m18 15 4 4-4 4-4-4Z"/>',
|
|
help: '<circle cx="12" cy="12" r="9"/><path d="M9.5 9a2.5 2.5 0 0 1 5 0c0 2-2.5 2-2.5 4m0 3v.1"/>',
|
|
heart:
|
|
'<path d="M12 20S3 15 3 8.5A4.5 4.5 0 0 1 12 7a4.5 4.5 0 0 1 9 1.5C21 15 12 20 12 20Z"/>',
|
|
injury:
|
|
'<g transform="rotate(-40 12 12)"><rect x="2" y="7" width="20" height="10" rx="3.5" fill="#f3cca0"/><rect x="9" y="8" width="6" height="8" rx="1" fill="#fff3dc" stroke-width="1.3"/><g fill="currentColor" stroke="none"><circle cx="5.5" cy="10" r=".8"/><circle cx="5.5" cy="14" r=".8"/><circle cx="18.5" cy="10" r=".8"/><circle cx="18.5" cy="14" r=".8"/></g></g>',
|
|
bio: '<path d="M9 2h6m-5 0v7L5 18q-1 3 3 3h8q4 0 3-3l-5-9V2M8 14h8"/><circle cx="11" cy="17" r="1"/>',
|
|
grid: '<rect x="3" y="3" width="18" height="18" rx="3"/><path d="M3 9h18M3 15h18M9 3v18M15 3v18"/>',
|
|
expand: '<path d="M8 3H3v5m13-5h5v5M3 16v5h5m13-5v5h-5"/>',
|
|
"sound-off": '<path d="M11 4 6 8H3v8h3l5 4Zm5 5 6 6m-6 0 6-6"/>',
|
|
sound: '<path d="M11 4 6 8H3v8h3l5 4Zm4 4q4 4 0 8m3-11q7 7 0 14"/>',
|
|
history: '<path d="M3 10a9 9 0 1 1 1 7M3 4v6h6m3-4v6l4 2"/>',
|
|
chat: '<path d="M5 4h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H9l-6 3V6a2 2 0 0 1 2-2Z"/><path d="M7 9h10M7 13h6"/>',
|
|
spark: '<path d="m12 2 3 7 7 3-7 3-3 7-3-7-7-3 7-3Z"/>',
|
|
wave: '<path d="M2 8q3-5 7 0t7 0 6 0M2 15q3-5 7 0t7 0 6 0"/>',
|
|
arrow: '<path d="M4 12h16m-6-6 6 6-6 6"/>',
|
|
sun: '<circle cx="12" cy="12" r="4"/><path d="M12 1v2m0 18v2M1 12h2m18 0h2M4 4l2 2m12 12 2 2M4 20l2-2M18 6l2-2"/>',
|
|
ozone:
|
|
'<circle cx="12" cy="7" r="3"/><path d="M12 1v1M5.5 2.5l1 1M2 7h2m16 0h2m-4.5-4.5-1 1M7 11l-1 1m11-1 1 1M2 16q2.5-2 5 0t5 0 5 0 5 0M2 21q2.5-2 5 0t5 0 5 0 5 0"/>',
|
|
"environment-card":
|
|
'<path d="M15 3V2H3v16h2"/><rect x="7" y="6" width="14" height="16" rx="2"/><path d="M10 14h8m-3-3 3 3-3 3"/>',
|
|
divide:
|
|
'<path d="M11 5C4-2-3 14 5 19c4 3 5-3 7-3s3 6 7 3c8-5 1-21-6-14Z"/><circle cx="7" cy="11" r="2"/><circle cx="17" cy="11" r="2"/>',
|
|
shield:
|
|
'<path d="m12 2 9 4v7q-2 6-9 9-7-3-9-9V6Z"/><path d="m8 12 3 3 5-6"/>',
|
|
food: '<rect x="3" y="5" width="7" height="7" rx="2"/><rect x="13" y="12" width="7" height="7" rx="2"/>',
|
|
numbers: '<path d="M5 9h15M4 15h15M11 3 7 21M18 3l-4 18"/>',
|
|
eye: '<path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/>',
|
|
swap: '<path d="M3 7h17m-4-4 4 4-4 4M21 17H4m4-4-4 4 4 4"/>',
|
|
link: '<path d="m10 8 3-3a4 4 0 0 1 6 6l-3 3m-2 2-3 3a4 4 0 0 1-6-6l3-3m1 5 6-6"/>',
|
|
tentacle:
|
|
'<path d="M3 20c10 0 3-17 12-17a5 5 0 0 1 0 10c-4 0-4-5-1-5M7 20c8 0 6-4 13-4"/>',
|
|
attack: '<path d="m13 2-9 12h7l-1 8 10-13h-8Z"/>',
|
|
gene: '<path d="M7 3c0 8 10 10 10 18M17 3c0 8-10 10-10 18M7.5 5h9M9 9h6m-6 6h6m-7.5 4h9"/>',
|
|
undo: '<path d="M4 11a8 8 0 1 1 2 9M4 4v7h7"/>',
|
|
};
|
|
const icon = (name) =>
|
|
`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${iconPaths[name] || iconPaths.spark}</svg>`;
|
|
export const PHASE_ICONS = [
|
|
"wave",
|
|
"ozone",
|
|
"gene",
|
|
"divide",
|
|
"heart",
|
|
"spark",
|
|
];
|
|
|
|
let artId = 0;
|
|
const colonySymbols = {
|
|
green: '<circle cx="12" cy="12" r="9"/>',
|
|
red: '<path d="m12 2 10 19H2Z"/>',
|
|
blue: '<rect x="3" y="3" width="18" height="18" rx="1"/>',
|
|
yellow: '<path d="m12 1 11 11-11 11L1 12Z"/>',
|
|
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">${colonyShape(color)}</svg>`;
|
|
|
|
function amoeba(color, variant = 0, feature = "") {
|
|
const c = colors[color];
|
|
const traits = new Set(Array.isArray(feature) ? feature : [feature]);
|
|
const id = `amoeba-${++artId}`;
|
|
const body =
|
|
variant % 3 === 0
|
|
? "M23 57C9 57 7 43 18 39C8 25 20 16 31 24C35 9 48 9 53 20C64 7 79 16 75 30C95 27 97 43 84 49C100 59 91 73 76 69C72 88 54 83 48 76C37 89 22 79 24 69C9 75 5 62 23 57Z"
|
|
: variant % 3 === 1
|
|
? "M18 47C5 34 16 22 29 27C24 10 42 6 49 20C56 5 73 14 70 25C88 16 98 30 84 40C103 49 94 63 81 63C90 80 72 87 61 73C58 90 38 89 34 73C19 84 7 74 18 61C5 63 5 48 18 47Z"
|
|
: "M19 55C5 48 11 30 25 33C12 17 34 8 40 24C44 5 64 8 66 25C81 11 97 30 83 42C104 43 98 63 82 62C89 80 65 89 59 74C47 93 27 86 31 70C11 82 4 61 19 55Z";
|
|
const adaptations = amoebaAdaptations(c, traits, body);
|
|
return `<svg viewBox="0 0 100 100" overflow="visible" aria-hidden="true"><defs><radialGradient id="${id}" cx="40%" cy="24%" r="75%"><stop stop-color="${c.light}"/><stop offset=".48" stop-color="${c.body}"/><stop offset="1" stop-color="${c.shade}"/></radialGradient></defs>
|
|
${adaptations.behind}
|
|
${traits.has("movement") ? `<path d="M23 65Q-12 45 2 35Q17 40 23 53M77 60Q105 35 99 25Q84 31 77 43" fill="${c.body}" stroke="${c.stroke}" stroke-width="2"/>` : ""}
|
|
${traits.has("spines") ? `<path d="M25 29 17 8 39 23M64 21 80 6 77 31M82 54 99 71 76 69M37 72 31 94 52 76M19 52 0 64 23 67" fill="${c.shade}" stroke="${c.stroke}" stroke-width="2" stroke-linejoin="round"/>` : ""}
|
|
${traits.has("tentacle") ? `<g fill="none" stroke-linecap="round"><path d="M28 64C13 79 2 72 5 56s14-8 9-4M77 61c20 2 23 18 13 19s-10-7-5-7" stroke="${c.stroke}" stroke-width="8"/><path d="M28 64C13 79 2 72 5 56s14-8 9-4M77 61c20 2 23 18 13 19s-10-7-5-7" stroke="${c.body}" stroke-width="4.5"/></g>` : ""}
|
|
<path d="${body}" fill="url(#${id})" stroke="${c.stroke}" stroke-width="2" stroke-linejoin="round"/>
|
|
${adaptations.skin}
|
|
<path d="M26 32q1-6 7-7M55 24q5-3 9 0" stroke="#fff" stroke-opacity=".65" stroke-width="4" fill="none" stroke-linecap="round"/>
|
|
<ellipse cx="36" cy="64" rx="7" ry="5" fill="${c.cheek}" opacity=".6"/><ellipse cx="71" cy="60" rx="6" ry="4" fill="${c.cheek}" opacity=".55"/>
|
|
<circle cx="29" cy="46" r="3" fill="${c.light}"/><circle cx="74" cy="38" r="2" fill="${c.shade}" opacity=".45"/><circle cx="47" cy="70" r="2" fill="${c.shade}" opacity=".7"/>
|
|
${traits.has("armor") ? '<path d="M25 31C25 2 76-2 80 29l-18-4-7 7-8-6Z" fill="#c9d5cc" stroke="#647d71" stroke-width="2"/><path d="M53 9v13m-19 2 8-9" stroke="#f6fcf5" stroke-width="3.5" stroke-linecap="round"/>' : ""}
|
|
<g class="eyes"><ellipse cx="43" cy="41" rx="12" ry="14" fill="#fffef1" stroke="${c.stroke}" stroke-width="1.7"/><ellipse cx="65" cy="40" rx="12" ry="14.5" fill="#fffef1" stroke="${c.stroke}" stroke-width="1.7"/>
|
|
<ellipse cx="${45 + (variant % 2)}" cy="44" rx="4.3" ry="6.2" fill="#24433a"/><ellipse cx="${65 + (variant % 2)}" cy="43" rx="4.3" ry="6.2" fill="#24433a"/><circle cx="44" cy="41" r="1.8" fill="white"/><circle cx="64" cy="40" r="1.8" fill="white"/></g>
|
|
${traits.has("glasses") ? '<g fill="none" stroke="#425d48" stroke-width="2.7"><rect x="30" y="27" width="26" height="28" rx="9"/><rect x="54" y="26" width="26" height="28" rx="9"/><path d="m30 36-9-3m59 2 6-4"/></g>' : ""}
|
|
${adaptations.mouth || `<path d="M47 61q7 8 14-1" stroke="${c.stroke}" stroke-width="2" stroke-linecap="round" fill="none"/>`}
|
|
${traits.has("food") ? '<path d="M65 70q9-13 11-2q-1 12-11 2" fill="#ffd4a2" stroke="#86613c" stroke-width="1.5"/><rect x="68" y="68" width="9" height="8" rx="2" fill="#ed9785" stroke="#a46c54"/>' : ""}
|
|
${traits.has("shield") || traits.has("armor") ? '<path d="m75 55 18 7v12q-5 10-18 15-12-5-15-15V62Z" fill="#dbe8e0" stroke="#4d7767" stroke-width="2"/><path d="m68 71 5 5 11-11" fill="none" stroke="#6b995b" stroke-width="3"/>' : ""}
|
|
${adaptations.front}
|
|
<g class="amoeba-symbol" transform="translate(9 62)"><rect x="-2" y="-2" width="29" height="29" rx="6" fill="#fffef1" stroke="#24433a" stroke-width="1.5"/>${colonySymbol(color).replace('viewBox="0 0 24 24"', 'width="25" height="25" viewBox="0 0 24 24"')}</g>
|
|
</svg>`;
|
|
}
|
|
|
|
export function colonyTraits(genes) {
|
|
const ids = new Set(genes.map((gene) => gene.id));
|
|
const traits = [];
|
|
if (ids.has("movement2")) traits.push("movement2");
|
|
else if (ids.has("movement1")) traits.push("movement");
|
|
if (ids.has("struggle") || ids.has("aggression")) traits.push("bite");
|
|
if (ids.has("aggression")) traits.push("spines", "fierce");
|
|
if (ids.has("tentacle")) traits.push("tentacle");
|
|
if (ids.has("armor")) traits.push("armor");
|
|
if (ids.has("intelligence") || ids.has("phd")) traits.push("glasses");
|
|
if (ids.has("phd")) traits.push("phd");
|
|
if (ids.has("hard-crust")) traits.push("crust");
|
|
if (ids.has("camouflage2")) traits.push("camouflage2");
|
|
else if (ids.has("camouflage1")) traits.push("camouflage");
|
|
if (ids.has("environmental")) traits.push("sensing2");
|
|
else if (ids.has("migration")) traits.push("sensing");
|
|
if (ids.has("healing2")) traits.push("healing2");
|
|
else if (ids.has("healing1")) traits.push("healing");
|
|
if (ids.has("suction2")) traits.push("suction2");
|
|
else if (ids.has("suction1")) traits.push("suction");
|
|
if (ids.has("toxic")) traits.push("toxic");
|
|
if (ids.has("threat")) traits.push("frill");
|
|
if (ids.has("glutton")) traits.push("hungry");
|
|
return traits;
|
|
}
|
|
|
|
export { colors, icon, amoeba };
|