// Build the choropleth payload from a GameState: every region key (see // public/region-keys.json) maps to its owning nation plus that nation's stable // color (see shared.nationColor). The client merges this onto the sub-national // regions.geo.json (resolving each feature by its own region key) and calls // source.setData(). Format-agnostic: it maps whatever keys sit in territory. // // A key ABSENT from the returned map is unowned (no nation's territory holds // it) — this covers both regions a preset never assigned and regions released // to no man's land mid-game (v0.22, #16 P3). The map deliberately does NOT // distinguish the two: the visible no-man's-land grey vs the faint // preset-unassigned look is decided by the client from `GameState.unowned` // (see shared/protocol.ts's regionFillStyle). import { nationColor, type RegionMap } from '../shared/protocol'; import type { GameState } from '../shared/types'; export function buildRegionMap(state: GameState): RegionMap { const map: RegionMap = {}; for (const [id, nation] of Object.entries(state.nations)) { const color = nationColor(id); for (const key of nation.territory) { map[key] = { color, owner: nation.name, ownerId: id }; } } return map; }