/** * What colour a body is drawn in. * * Every body says `mate`: on the viewer's side or not. That is enough for a * game of two sides, and a game that sends nothing more looks exactly as it * always has. A game of three sides, or everybody for themselves, also sends * `side` — any string naming the body's side — and each side that is not the * viewer's gets its own colour from a small fixed palette. * * A side keeps the colour it was first given for as long as the page is * open, so it does not change hue between frames, or when another side walks * out of sight. The first side seen gets the enemy red a two-side game * already wears. More sides than the palette has wrap round to its start. * * Mates keep the mate colour, you keep yours and the dead keep their grey, * whatever side they are on: those are drawn by the callers, not here. */ /** Today's enemy, and what any body without a `side` wears. */ export const ENEMY = { skin: "#d8483f", dot: "#e35d5b", mark: "rgba(235,150,120,0.9)" }; /** * The palette, in the order sides are handed it. Each is `skin` in the first * person, `dot` on the map and `mark` for a last-seen outline. None is blue * (mates), grey (the dead) or white (you). */ export const PALETTE = [ ENEMY, { skin: "#e08a2c", dot: "#f0a040", mark: "rgba(240,175,100,0.9)" }, { skin: "#9b5fd6", dot: "#b07ae8", mark: "rgba(190,150,235,0.9)" }, { skin: "#4fae4a", dot: "#62c45c", mark: "rgba(140,210,130,0.9)" }, { skin: "#d655a8", dot: "#e86fbb", mark: "rgba(235,150,205,0.9)" }, { skin: "#c9b52e", dot: "#ddc944", mark: "rgba(225,210,120,0.9)" }, ]; /** A fresh book of which side has which colour. */ export const makeSides = () => new Map(); /** The one book the renderers share, so the map and the scene agree. */ const shared = makeSides(); /** * The colours for a body that is not on the viewer's side: by its `side` * when it carries one, today's enemy colours when it does not. */ export function enemyColours(body, book = shared) { const side = body.side; if (typeof side !== "string") return ENEMY; let at = book.get(side); if (at === undefined) { at = book.size % PALETTE.length; book.set(side, at); } return PALETTE[at]; }