// Build the choropleth payload from a GameState: every **sub-region id** in a // nation's territory maps to its owning nation plus that nation's stable color // (see shared.nationColor). The client merges this onto public/regions.geo.json // and calls source.setData(). The map is keyed by whatever ids sit in // `nation.territory` — sub-region ids (e.g. `FR-57`) as of v0.19 — so it needs // no change to move from country to sub-region granularity; a sub-region in no // nation's territory is simply absent (unowned, rendered grey by the map). 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 regionId of nation.territory) { map[regionId] = { color, owner: nation.name, ownerId: id }; } } return map; }