Base-map tile pipeline and shared-canvas Leaflet viewer

Extracts only the base map art from re3mr PSDs (the top-level LOCATION
group), tiles it to WebP, and renders every map on one shared world canvas.

Pipeline: psd_tree -> export_base -> tile -> build -> preview, driven
entirely by maps.json. Adding a map is a config change.

Maps are placed on an 8192px grid (tileSize * 2^maxZoom) so a cell's tile
index shift is exactly cell * 2^z at every zoom. Each map keeps its own
locally numbered pyramid and the browser translates on the fly, so adding
a map never re-tiles the others.

excludeLayers works around psd-tools rendering stroke-only vector shapes
as solid fills, which otherwise buries Customs under a white fill.

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
Claude committed 2026-08-07 23:22:21 -07:00
commit 5afde00ab7
25 files changed
+2015

No files matched your search

+151
View File
@@ -0,0 +1,151 @@
# Adding a map
The whole job is: point the config at a PSD, name the group that holds the map
art, pick a grid cell, build. Everything else is automatic.
Budget ~10 minutes plus render time (roughly 3 minutes per GB of PSD).
---
## 0. Once per machine
```bash
python -m pip install -r tools/requirements.txt
```
Put the PSD under `sources/<area>/`. That directory is gitignored — source art
lives on the shared drive, never in the repo.
---
## 1. Look at the layer tree
```bash
python tools/psd_tree.py sources/customs/customs.psd
```
You are answering two questions.
**Which top-level group holds the map art?** On every re3mr map so far it is
`LOCATION`, sitting next to `OVERLAY`/`OVERLAYS`, `LEGEND` and `TITLE`. Only the
group you name gets rendered, so markers, legends, captions and titles are
dropped by construction — you never have to hide them one by one.
**Are there `shape` layers inside it?** Note their names. psd-tools renders a
stroke-only vector shape as a *solid fill*, which can bury the entire map under
one flat colour. These go in `excludeLayers` at step 3.
---
## 2. Add it to `maps.json`
```json
{
"id": "factory",
"name": "Factory",
"psd": "sources/factory/factory.psd",
"baseGroup": "LOCATION",
"excludeLayers": [],
"crop": null,
"cell": [2, 0]
}
```
| Field | Meaning |
| --- | --- |
| `id` | URL-safe; becomes `web/tiles/<id>/` |
| `baseGroup` | the group from step 1 |
| `excludeLayers` | layer names to hide anywhere inside `baseGroup` |
| `crop` | `[x0, y0, x1, y1]` in PSD pixels, or `null` for the full canvas |
| `cell` | `[col, row]` on the world grid — omit it and the next free cell is used |
| `pxPerMeter` | optional, from the map's scale bar; recorded for later use |
A map must fit inside one grid cell: **8192 × 8192 px** at the default
`maxZoom: 5`. The build fails with a clear message if it doesn't; raising
`maxZoom` by one doubles the cell.
---
## 3. Render the base layer and check it
```bash
python tools/export_base.py factory
```
Open `build/factory/base.png` and actually look at it. You are checking for:
- **large flat areas of solid colour** — a shape layer is filling. Add its name
to `excludeLayers` and re-run. (Customs needs `"Map Borders"` for exactly
this reason; without it the whole playable area renders white.)
- **leftover markers or text** — you named the wrong group, or the art has
markers nested inside the base group.
- **how much dead canvas surrounds the art** — that sets your `crop`.
Re-run after any `maps.json` change; `export_base.py` always re-renders.
---
## 4. Set the crop
Read the pixel bounds of the real map art off `base.png` and put them in
`crop`. Customs uses `[0, 860, 7832, 3875]` — the PSD reserves the top ~860 px
for the title bar and everything below y=3875 for the legend, and tiling that
empty space just makes the map awkward to pan.
If the art fills the canvas, leave `crop: null`.
---
## 5. Build and verify
```bash
python tools/build.py factory # export if stale, then tile, then manifest
python tools/preview.py 3 # stitch every map into one overview
```
`build/world-preview.png` shows all maps at their world positions. Confirm the
new one landed in the cell you intended and doesn't collide with a neighbour.
Then:
```bash
python server/serve.py
```
and open the printed URL.
---
## Useful variations
```bash
python tools/build.py # every map
python tools/build.py --tiles-only # re-tile after a crop change, skip the slow render
python tools/build.py --force-export # re-render even if base.png looks current
```
`build.py` skips the PSD render when `base.png` is newer than the PSD, so
iterating on `crop` is fast — that loop is seconds, not minutes.
Rebuilding one map never touches another map's tiles, and `world.json` keeps
entries for maps that weren't part of this run.
---
## Why the grid works
Every map is tiled independently, numbered from its own top-left corner. The
world places a map in grid cell `(gx, gy)` at world pixel
`(gx · cellSize, gy · cellSize)`, where
```
cellSize = tileSize · 2^maxZoom = 256 · 32 = 8192
```
At that cell size the tile-index shift for a cell is exactly `gx · 2^z` at
every zoom level — always a whole number. So the browser can translate world
tile coordinates into a map's local ones with integer arithmetic and no
resampling (`getTileUrl` in `web/app.js`).
That is what lets you add a map without re-tiling any other map, and what keeps
unrelated maps sharing one continuous canvas.