rook/val Public Public: anyone can read this; nobody can change it.
forked from benjivers/val
workbenchthis machine
Files b42aa0d0f5a2520c6a2bd99fd90ea66615e6c986
| 1 | /** |
| 2 | * What colour a body is drawn in. |
| 3 | * |
| 4 | * Every body says `mate`: on the viewer's side or not. That is enough for a |
| 5 | * game of two sides, and a game that sends nothing more looks exactly as it |
| 6 | * always has. A game of three sides, or everybody for themselves, also sends |
| 7 | * `side` — any string naming the body's side — and each side that is not the |
| 8 | * viewer's gets its own colour from a small fixed palette. |
| 9 | * |
| 10 | * A side keeps the colour it was first given for as long as the page is |
| 11 | * open, so it does not change hue between frames, or when another side walks |
| 12 | * out of sight. The first side seen gets the enemy red a two-side game |
| 13 | * already wears. More sides than the palette has wrap round to its start. |
| 14 | * |
| 15 | * Mates keep the mate colour, you keep yours and the dead keep their grey, |
| 16 | * whatever side they are on: those are drawn by the callers, not here. |
| 17 | */ |
| 18 | |
| 19 | /** Today's enemy, and what any body without a `side` wears. */ |
| 20 | export const ENEMY = { skin: "#d8483f", dot: "#e35d5b", mark: "rgba(235,150,120,0.9)" }; |
| 21 | |
| 22 | /** |
| 23 | * The palette, in the order sides are handed it. Each is `skin` in the first |
| 24 | * person, `dot` on the map and `mark` for a last-seen outline. None is blue |
| 25 | * (mates), grey (the dead) or white (you). |
| 26 | */ |
| 27 | export const PALETTE = [ |
| 28 | ENEMY, |
| 29 | { skin: "#e08a2c", dot: "#f0a040", mark: "rgba(240,175,100,0.9)" }, |
| 30 | { skin: "#9b5fd6", dot: "#b07ae8", mark: "rgba(190,150,235,0.9)" }, |
| 31 | { skin: "#4fae4a", dot: "#62c45c", mark: "rgba(140,210,130,0.9)" }, |
| 32 | { skin: "#d655a8", dot: "#e86fbb", mark: "rgba(235,150,205,0.9)" }, |
| 33 | { skin: "#c9b52e", dot: "#ddc944", mark: "rgba(225,210,120,0.9)" }, |
| 34 | ]; |
| 35 | |
| 36 | /** A fresh book of which side has which colour. */ |
| 37 | export const makeSides = () => new Map(); |
| 38 | |
| 39 | /** The one book the renderers share, so the map and the scene agree. */ |
| 40 | const shared = makeSides(); |
| 41 | |
| 42 | /** |
| 43 | * The colours for a body that is not on the viewer's side: by its `side` |
| 44 | * when it carries one, today's enemy colours when it does not. |
| 45 | */ |
| 46 | export function enemyColours(body, book = shared) { |
| 47 | const side = body.side; |
| 48 | if (typeof side !== "string") return ENEMY; |
| 49 | let at = book.get(side); |
| 50 | if (at === undefined) { |
| 51 | at = book.size % PALETTE.length; |
| 52 | book.set(side, at); |
| 53 | } |
| 54 | return PALETTE[at]; |
| 55 | } |