diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md new file mode 100644 index 0000000..7640856 --- /dev/null +++ b/DOCUMENTATION.md @@ -0,0 +1,664 @@ +# TarkovMap — Technical Documentation + +Complete reference for how this project works. For a five-line quickstart see +[README.md](README.md); for the step-by-step runbook to add a map see +[docs/adding-a-map.md](docs/adding-a-map.md); for project status and open work +see [PLAN.md](PLAN.md). + +**Contents** + +1. [What this is](#1-what-this-is) +2. [How it fits together](#2-how-it-fits-together) +3. [Coordinate systems](#3-coordinate-systems) +4. [The tile grid, and why maps are padded](#4-the-tile-grid-and-why-maps-are-padded) +5. [The build pipeline](#5-the-build-pipeline) +6. [Configuration reference — `maps.json`](#6-configuration-reference--mapsjson) +7. [Data contract — `world.json`](#7-data-contract--worldjson) +8. [The viewer](#8-the-viewer) +9. [Serving](#9-serving) +10. [Source-art findings](#10-source-art-findings) +11. [Traps and workarounds](#11-traps-and-workarounds) +12. [Design decisions and rejected alternatives](#12-design-decisions-and-rejected-alternatives) +13. [Troubleshooting](#13-troubleshooting) +14. [Current state](#14-current-state) +15. [Licence](#15-licence) + +--- + +## 1. What this is + +A self-hosted, mobile-friendly Escape from Tarkov map viewer. + +Layered Photoshop files from [re3mr.com](https://re3mr.com) go in; a Leaflet +XYZ tile pyramid comes out. Every map is placed onto **one shared world +canvas** — the overall satellite map of Tarkov, rotated so north is up. Zoom +out for the whole region; zoom into a location and the full-resolution map for +it takes over. + +Two deliberate scope choices: + +- **Base map art only.** Markers, spawns, extracts, captions, legends and + titles are dropped during the render. Only terrain survives. +- **Approximate placement.** The game's individual maps are not drawn to match + the satellite view, so exact registration is impossible. The goal is + "clearly the right place". + +--- + +## 2. How it fits together + +``` +sources//*.psd layered source art (gitignored, 0.2-1.1 GB each) + │ + │ tools/export_base.py keep only baseLayers, drop everything else + ▼ +build//base.png flat RGBA render at full PSD canvas size + │ + │ tools/tile.py crop, scale to world size, pad, cut tiles + ▼ +web/tiles//{z}/{x}/{y}.webp + web/data/world.json + │ + │ server/run.ps1 Caddy (or serve.py) + ▼ +web/index.html + app.js Leaflet viewer +``` + +`tools/build.py` orchestrates export → tile → manifest. `maps.json` is the only +file you edit to add or change a map. + +### File inventory + +| Path | Lines | Role | +| --- | --- | --- | +| `maps.json` | — | **The only input you edit.** Every map, its layers, crop and placement | +| `tools/common.py` | 131 | Config loading, rotation maths, world placement | +| `tools/psd_tree.py` | 48 | Print a PSD's layer tree — run first when onboarding | +| `tools/export_base.py` | 168 | PSD → `build//base.png`, keeping only `baseLayers` | +| `tools/tile.py` | 153 | `base.png` → placed, padded XYZ tile pyramid | +| `tools/build.py` | 102 | Orchestrator; writes `web/data/world.json` | +| `tools/place_preview.py` | 69 | Gridded north-up base map for positioning | +| `tools/retilt.py` | 53 | Change `world.rotate` without moving any map | +| `tools/preview.py` | 71 | Stitch built tiles into one overview image | +| `web/app.js` | 179 | The whole viewer | +| `web/style.css` | 114 | Dark minimal UI | +| `server/serve.py` | 81 | Dependency-free static server (fallback) | +| `server/Caddyfile` | — | Production static server config | + +Roughly 1200 lines total, plus vendored Leaflet 1.9.4. + +### Dependencies + +``` +psd-tools[composite]>=1.18 the [composite] extra is required, see §11 +Pillow>=11 +``` + +Python 3.13 on the build machine. No ImageMagick, libvips or GDAL. Node is not +required — Leaflet is vendored, and there is no build step for the web app. + +--- + +## 3. Coordinate systems + +Four spaces, converted in this order: + +**1. PSD pixels** — the source canvas, e.g. Customs is 7832 × 5016. `crop` is +expressed here. + +**2. Overall-map pixels (unrotated)** — `overall.jpeg`, 1308 × 1296. Only used +internally; you never author in this space. + +**3. Overall-map pixels (rotated)** — the same image after +`rotate(world.rotate, expand=True)`, currently 1816 × 1812 at 35°. **This is +where `place` lives**, because it is the north-up image you actually look at. +`tools/place_preview.py` draws a 100 px grid over it so you can read +coordinates directly. + +**4. World pixels** — rotated overall-map pixels × `world.overallScale` (64). +The world is 116 160 × 115 968. Tiles, origins and Leaflet coordinates all use +this space. + +In the viewer, a Leaflet `LatLng` is `(y, x)` in world pixels at native +resolution, via a custom CRS: + +```js +const CRS = L.extend({}, L.CRS.Simple, { + transformation: new L.Transformation(1, 0, 1, 0), // y grows downward + scale: (z) => 2 ** (z - ZMAX), + zoom: (s) => Math.log(s) / Math.LN2 + ZMAX, +}); +``` + +so at `maxZoom` one world pixel is one CSS pixel, and `lat` increases +downward — matching image coordinates rather than geographic north. + +### Rotation + +`rotate_point()` in `common.py` reproduces PIL's `rotate(deg, expand=True)` +analytically, and `unrotate_point()` inverts it. Both are **verified sub-pixel +against PIL** (max error 0.7 px over test points; predicted canvas size within +1 px). + +`overallScale = 64` was chosen so Customs lands at almost exactly its native +7832 px source width. It also makes the base map's native level land on a whole +number: `maxZoom − log2(64) = 9 − 6 = 3`. + +--- + +## 4. The tile grid, and why maps are padded + +This is the core mechanism; everything else follows from it. + +Each map is tiled independently and numbered **from its own cell origin**. For +that to work, a map's tile-index offset must be a whole number of tiles at +every zoom level. That holds only when the origin is a multiple of + +``` +cellSize = tileSize · 2^maxZoom = 256 · 2^9 = 131 072 world pixels +``` + +131 072 px is larger than the entire world (116 160 px). Useless for +positioning — every map would land at (0, 0). + +**The fix is to pad, not to snap.** The tiler: + +1. computes the map's exact world rect from `place`; +2. takes `cell = floor(origin / cellSize)` — in practice always `(0, 0)`; +3. records `pad = origin − cell · cellSize`, the exact sub-cell offset; +4. renders the map into that padded position; +5. **visits only the tile indices that actually contain content.** + +Step 5 is what makes it free. The padded canvas is notionally enormous, but the +tiler computes the content's tile range directly: + +```python +tx0, tx1 = floor(px / ts), ceil((px + cw) / ts) +ty0, ty1 = floor(py / ts), ceil((py + ch) / ts) +``` + +and never iterates the empty region. Result: exact placement, an integral grid, +and no cost for the padding. + +Because every map shares the world origin, tile `(z, x, y)` of any map sits at +world-level pixel `(x · 256, y · 256)` — which is why `tools/preview.py` can +stitch all maps into one image by simply pasting at `x·ts, y·ts`. + +### Native levels + +A map is tiled only down to its **native level** — the deepest zoom at which we +are still downscaling its source: + +```python +native = maxZoom + log2(source_width / target_world_width) +native_level = min(maxZoom, floor(native + 0.25)) +``` + +The `+ 0.25` slack matters. Customs computes to 7.88; plain `floor()` would +give 7 and render its 7832 px source at 4240 px, discarding almost half the +detail. The slack tolerates up to a 1.19× upscale — invisible — to keep it. + +Past its native level the browser upscales, which looks identical to upscaling +during the build but stores nothing. Each map also carries a `minZoom` below +which it is not loaded at all, so the overview costs only the base map. + +--- + +## 5. The build pipeline + +### `export_base.py` — PSD → flat RGBA + +Renders only the layers named in `baseLayers` and hides everything else. The +visibility walk keeps a layer if it *is* a target, is an **ancestor** of one +(so the target is reachable), or is a **descendant** of one; everything else is +hidden before a single whole-document composite. + +Output is **RGBA**, deliberately: these maps are composited onto terrain, so +regions outside the map art must be transparent rather than opaque black or +white rectangles. + +A `baseLayers` entry matching nothing is a hard error — silently rendering the +wrong thing after a five-minute wait is worse than failing. `excludeLayers` +misses only warn. + +One failed map no longer aborts the batch; failures are collected and reported +at the end. + +### `tile.py` — place, pad, cut + +Crops, scales to the world size implied by `place`, pads to the cell boundary, +and writes WebP tiles (quality 82, method 4). Fully-transparent tiles are +skipped; fully-opaque tiles are written as RGB rather than RGBA. + +It refuses to tile a map larger than one cell with an actionable message. + +### `build.py` — orchestration + +Skips the PSD render when `base.png` is newer than the PSD, so iterating on +`place` or `crop` takes seconds rather than minutes. Maps not part of the +current run are preserved in `world.json`, so partial builds don't drop layers. + +### Commands + +```bash +python tools/build.py # base + every map +python tools/build.py customs # one map +python tools/build.py overall # just retile the base +python tools/build.py --tiles-only # skip the slow PSD render +python tools/build.py --force-export # re-render even if base.png is current +``` + +```bash +python tools/psd_tree.py sources/woods/woods.psd --depth 2 +python tools/place_preview.py # gridded base for positioning +python tools/retilt.py 35 # change tilt, keeping placements +python tools/preview.py 4 # stitch tiles into one overview +``` + +### Timings + +PSD render is the long pole, roughly 3 minutes per GB: + +| Map | PSD | Render | +| --- | --- | --- | +| Reserve | 299 MB | 16 s | +| Lighthouse | 486 MB | 20 s | +| Shoreline | 203 MB | 60 s | +| Customs | 1143 MB | 158 s | +| Streets | 811 MB | 225 s | +| Woods | 530 MB | 236 s | +| Shoreline Resort | 527 MB | 292 s | +| Interchange | 1064 MB | 347 s | + +Tiling the whole world takes well under a minute. Peak memory during render is +around 8 GB for the largest PSDs. + +--- + +## 6. Configuration reference — `maps.json` + +### Top level + +| Key | Value | Meaning | +| --- | --- | --- | +| `tileSize` | 256 | Tile edge in pixels | +| `maxZoom` | 9 | World zoom depth; sets `cellSize = tileSize · 2^maxZoom` | +| `attribution` | HTML | Shown in the viewer; **must** keep the re3mr credit | +| `world.image` | path | The base map | +| `world.rotate` | 35 | Degrees counter-clockwise to put north up | +| `world.overallScale` | 64 | World pixels per overall-map pixel | + +### Per map + +| Key | Required | Meaning | +| --- | --- | --- | +| `id` | yes | URL-safe; becomes `web/tiles//` | +| `name` | yes | Label in the picker | +| `psd` | yes | Path under `sources/` | +| `baseLayers` | yes | Slash-paths from the document root; everything else hidden | +| `excludeLayers` | no | Layer names to hide anywhere inside the kept set | +| `crop` | no | `[x0, y0, x1, y1]` in PSD pixels, or `null` | +| `place` | yes | `{cx, cy, w}` in **rotated** overall-map pixels | +| `pxPerMeter` | no | From the map's scale bar; recorded for future use | + +`place.w` is the map's width in overall-map pixels; height follows from the +source aspect ratio. + +**Changing `world.rotate` by hand will move every map**, because `place` lives +in the rotated frame. Use `python tools/retilt.py `, which converts each +placement back through the old angle and forward through the new one. + +--- + +## 7. Data contract — `world.json` + +Generated into `web/data/`. The viewer hard-codes nothing about any map; adding +a map is a data change. + +```json +{ + "tileSize": 256, + "maxZoom": 9, + "worldSize": [116160, 115968], + "cellSize": 131072, + "rotate": 35.0, + "overallScale": 64.0, + "attribution": "Maps by re3mr.com · CC BY-NC-SA 4.0", + "maps": [ + { + "id": "customs", + "name": "Customs", + "cell": [0, 0], + "origin": [53600, 58752], + "size": [16960, 6529], + "minZoom": 3, + "maxNativeZoom": 8, + "base": false, + "version": "120c7eae", + "pxPerMeter": 7.39 + } + ] +} +``` + +`maps` is ordered base-first, then by descending footprint. `version` is a hash +of the map's geometry, zoom range and source file stamp — see §11. + +--- + +## 8. The viewer + +`web/app.js`, 179 lines, no build step, no framework, vendored Leaflet. + +### Layers + +Every map becomes an `OffsetTileLayer` — a `L.TileLayer` subclass whose +`getTileUrl` translates world tile coordinates into the map's local grid and +appends the cache-busting version: + +```js +const perCell = (o.baseTileSize * 2 ** coords.z) / o.tileSize; +x: coords.x - o.cell[0] * perCell +y: coords.y - o.cell[1] * perCell +``` + +`perCell` is derived from `baseTileSize` rather than assuming `2^z`, so the +maths stays exact under the density boost (§8, *Sharpness*). + +### Stacking + +Placements are approximate, so map rectangles overlap where the real locations +don't — Reserve clips Customs, Lighthouse clipped Shoreline. Two rules: + +1. **Baseline order** — by `maxNativeZoom`, then smaller footprint, so the + finer map is on top. The base map is always at the bottom. +2. **Focus override** — the map whose centre you are viewing is lifted above + everything else. + +Rule 2 is what actually solves it. Chasing perfect boxes would not: whichever +neighbour overlaps you, the map you navigated to now wins. + +### No black gaps + +The base map is the backdrop: 85 tiles / 0.3 MB, always resident, and Leaflet +upscales it past its native z3. Any gap while detail tiles load shows blurry +terrain rather than the page background. + +### Sharpness + +Leaflet picks its tile level with `Math.round(mapZoom)`, so at zoom 2.25 it +takes level 2 and stretches it 1.19×. On a 150 %-scaled Windows display +(`devicePixelRatio` 1.5) that compounds to a **1.78× upscale** — visibly soft. + +`DENSITY_BOOST` halves each tile's CSS size and adds a matching `zoomOffset`, +so Leaflet downscales a denser level instead of upscaling a coarser one. +Measured at DPR 1.5, in source pixels per device pixel (higher is sharper): + +| | Before | After | +| --- | --- | --- | +| Below native level | 0.56 | **1.33** | +| At native level | 0.67 | 0.67 | + +It costs roughly 4× the tiles in view (~17 KB each), which is a fair trade on a +LAN. The boost switches itself off on a 1:1 display with integer zoom. + +### Other behaviour + +- URL hash `#zoom/y/x` for shareable positions. +- Map picker; the active map is marked. +- `window.tarkovMap` / `window.tarkovWorld` exposed for console debugging. +- Non-dismissible attribution control (licence requirement). +- Mobile: `viewport-fit=cover`, safe-area insets, 44 px touch targets, + collapsible picker, zoom buttons hidden under 640 px in favour of pinch. + +--- + +## 9. Serving + +Tiles are inert static files. `server/run.ps1` uses Caddy when +`server/caddy.exe` exists (fetch with `server/get-caddy.ps1`) and falls back to +`server/serve.py` so a fresh clone works with nothing installed. + +Measured on loopback, 480 tile requests over reused connections: + +| | `serve.py` | Caddy | +| --- | --- | --- | +| Dependencies | none (stdlib) | one 47 MB binary | +| concurrency 8 | 2 622 req/s · p95 4.0 ms | **6 987 req/s** · p95 1.9 ms | +| concurrency 32 | 462 req/s · max **1 013 ms** | **5 877 req/s** · max 21 ms | +| ETags / compression | no | yes (zstd, gzip) | + +The second row is the argument. `serve.py` is thread-per-connection behind the +GIL, so under load throughput *falls* below its 8-thread figure and tail +latency crosses a second. Caddy stays flat. + +`serve.py` also inherited `SimpleHTTPRequestHandler`'s **HTTP/1.0** default, +which closes the socket after every response — one TCP handshake per tile, ~30 +per map view. It now sets HTTP/1.1, which is most of its improvement above. + +**Neither serves HTTP/2**: browsers only negotiate h2 over TLS, and trusting a +local CA on every phone is not worth it on a LAN. The Caddy win is Go's I/O. + +Cache policy: tiles `public, max-age=604800, immutable`; app shell and +`world.json` `no-cache`. + +To reach it from a phone, allow the port once (elevated): + +```bash +netsh advfirewall firewall add rule name="TarkovMap 8080" dir=in action=allow protocol=TCP localport=8080 +``` + +--- + +## 10. Source-art findings + +### There is no naming convention + +Customs' tidy `LOCATION` / `OVERLAY` / `LEGEND` / `TITLE` structure turned out +to be a Customs thing. Every map differs: + +| Map | PSD | Base layers | +| --- | --- | --- | +| Customs | 7832 × 5016 | `LOCATION` | +| Customs — Dorms | 4301 × 4904 | `LOCATION` | +| Woods | 7680 × 5168 | `re3mr.com/Map&Art/Map&OverlayArt/{RawMapLayer,WaterDetail}` | +| Interchange | 9600 × 5400 | `3DRENDER` | +| Reserve | 5760 × 3240 | `Day copy` | +| Shoreline | 5760 × 3240 | `Baselayer` | +| Shoreline — Resort | 10694 × 6016 | `BGCOLOR PATTERN`, `BASEMAP+2DLAYERS` | +| Lighthouse | 8259 × 7560 | `Day` (a hidden `Night` also exists) | +| Streets of Tarkov | 7605 × 4841, 16-bit | `Map - 3D map portion…` | + +Several need more than one top-level layer; Woods buries its terrain three +groups deep. Always run `psd_tree.py`. + +**Watch for plates.** Interchange's `Background` and Reserve's `Color Fill 1` +are solid white; Woods' `MapBlackout` and Streets' `Layer 1` are solid black. +Including them hides the terrain beneath. + +### Detail ceilings are real + +Customs' terrain is a smart object embedding a 473 MB PSB — but its header says +**7832 × 3720, placed 1:1**. There is no hidden resolution to recover. Its +7832 px source is the hard ceiling. + +### Scale + +Customs' scale bar gives **≈ 7.39 px/metre** (cross-checked at the 5, 25, 50 +and 100 m ticks). Recorded as `pxPerMeter`; not yet used by the viewer. + +### Two maps are floor plans + +Customs — Dorms and Shoreline — Resort are interior schematics, not terrain. +They are placed at their building locations, which is geometrically right but +reads oddly over satellite imagery. + +--- + +## 11. Traps and workarounds + +Each of these cost real debugging time. They are documented so nobody pays +twice. + +### psd-tools fills stroke-only vector shapes + +A `shape` layer with a stroke and no fill renders as a **solid fill**. Customs' +`Map Borders` painted the entire playable area white — the first render was a +white blob. Worked around with `excludeLayers`. + +Side effect: Customs no longer shows its dotted play-area boundary. The +out-of-bounds grey-out still marks it. Accepted. + +### psd-tools crashes on stroke effects with empty bboxes + +A layer carrying a stroke effect but an empty bbox feeds a zero-size array into +scikit-image's rank filter: `The parameter 'image' cannot be an empty array`. +Woods hits this. `export_base.py` patches `Compositor._apply_stroke_effect` to +skip the effect rather than lose the whole render. + +### `psd_tools.composite` shadows its own submodule + +`from psd_tools.composite import composite` returns a **function**, not the +module. Use `importlib.import_module("psd_tools.composite.composite")`. + +### Layer effects need the `[composite]` extra + +Without scikit-image, psd-tools raises `ImportError` on any layer with a +stroke. Hence `psd-tools[composite]` in `requirements.txt`. + +### Immutable caching versus rebuilt tiles + +Tile paths are stable across rebuilds but their contents are not: move a map's +`place` and `tiles//6/17/33.webp` becomes different imagery at the same +URL. Served `immutable` for a week, a browser that had seen the old build +blended the two and drew **duplicated, offset terrain**. + +Every map now carries a `version` — hashed from geometry, zoom range and source +file stamp — appended to tile URLs as `?v=`. Re-tiled maps get fresh URLs; +identical rebuilds keep the same hash so nothing is re-fetched needlessly. + +### The base map's tilt could not be measured automatically + +Two attempts failed: + +- **Aspect-ratio fit** of the Customs zone outline gave 31°, but the zone + polygon encloses more than the playable strip, so the estimate ran low. +- **Polygon registration** between the overall map and the PSD's `MapBorder` + failed because the zone outline is *dashed* and will not flood-fill — the + filled region came out at 2 % coverage with elongation 1.24 against the + PSD's 3.73. + +The current **35°** is a visual judgement, not a measurement. `retilt.py` makes +it a one-number change. + +### PowerShell here-strings in Bash + +`@'...'@` is PowerShell syntax. Used in the Bash tool it silently prepends a +literal `@` to the commit message. Use a heredoc with `git commit -F -`. + +--- + +## 12. Design decisions and rejected alternatives + +| Decision | Why | Rejected | +| --- | --- | --- | +| XYZ tile pyramid + Leaflet | Standard, mobile gestures free, no client deps | `L.imageOverlay` (39 MP in one request); IIIF/DZI (extra dependency) | +| 256 px tiles | Works cleanly with the density boost (128 CSS px at 2×) | 512 px — fewer requests but coarser boost granularity | +| WebP q82 | ~4× smaller than PNG, alpha supported everywhere in scope | PNG (too large); JPEG (no alpha) | +| Pad maps onto the grid | Exact placement with an integral tile grid, zero cost | Snapping origins (131 072 px granularity — unusable); one giant baked world raster (gigapixels, rebuild everything per change) | +| Per-map pyramids | Adding a map never re-tiles the others | Single world pyramid | +| Pure-Python pipeline | No native binaries across several machines; 39 MP fits in RAM | libvips `dzsave` (faster, but a native dep) | +| Focus-based stacking | Robust to overlapping approximate placements | Chasing perfect placement boxes | +| Loose tile files | Trivially served and debuggable | PMTiles — worth revisiting past ~5 more maps | +| Caddy default, `serve.py` fallback | Fast where it matters, works from a bare clone | nginx (heavier Windows setup) | +| Base map art only | The user's explicit scope | Marker/overlay layers — cheap to revive, see below | + +**Reviving marker overlays** would be inexpensive if wanted: the PSDs keep +every marker as its own layer with a known bounding box, so positions can be +extracted programmatically rather than hand-placed. Customs alone has 28 PMC +spawns, 15 scav spawns, 5 boss and 4 sniper markers already separated. + +--- + +## 13. Troubleshooting + +**Duplicated or offset terrain.** Cached tiles from an older build. Should be +impossible now that tile URLs carry `?v=`, but a browser that cached before +that change needs one hard reload (Ctrl+Shift+R). + +**A map renders as a flat colour block.** A shape layer is filling, or you kept +a white/black plate layer. Check `build//base.png`, then fix `baseLayers` +or add to `excludeLayers`. + +**Markers or legends survived.** Wrong `baseLayers` — re-run `psd_tree.py`. + +**A map sits in the wrong place.** Run `place_preview.py`, read the grid, edit +`place`, re-run `build.py --tiles-only `. + +**Every map moved at once.** You edited `world.rotate` by hand. Restore it and +use `retilt.py`. + +**`baseLayers entry '…' matched nothing`.** A typo, or the path is nested — +`psd_tree.py --depth 3`. + +**Blurry at full zoom.** Expected past a map's native level; the source has no +more detail. Check `maxNativeZoom` in `world.json`. + +**Tiles 404 in the browser.** Usually a stale `world.json` referencing a map +whose tiles were deleted. Re-run `build.py`. + +**Phone cannot reach the LAN URL.** Firewall rule missing — see §9. + +--- + +## 14. Current state + +World 116 160 × 115 968 px, `maxZoom` 9, rotated 35°. Ten layers, **6096 tiles, +45.1 MB**. + +| Layer | Origin | World size | Zooms | Tiles | Size | +| --- | --- | --- | --- | --- | --- | +| overall (base) | 0, 0 | 116160 × 115968 | z0–3 | 85 | 0.3 MB | +| woods | 39936, 34825 | 24320 × 16365 | z2–7 | 466 | 4.2 MB | +| shoreline | 37184, 72904 | 24320 × 13680 | z2–7 | 506 | 3.1 MB | +| lighthouse | 27360, 61385 | 17600 × 16110 | z3–8 | 1580 | 16.2 MB | +| customs | 53600, 58752 | 16960 × 6529 | z3–8 | 646 | 9.3 MB | +| reserve | 46208, 64296 | 8960 × 5040 | z4–8 | 277 | 1.7 MB | +| shoreline-resort | 40192, 74716 | 8320 × 4680 | z4–9 | 924 | 2.4 MB | +| streets | 67584, 26111 | 7040 × 4481 | z4–9 | 713 | 2.8 MB | +| interchange | 70112, 54098 | 6080 × 3420 | z4–9 | 392 | 3.3 MB | +| customs-dorms | 63040, 61190 | 4480 × 5108 | z5–9 | 507 | 1.9 MB | + +Verified across zoom 0–9: zero broken tiles; every tile carries `?v=`; the +focused map is topmost in all seven tested cases. + +### Known gaps + +- **Placement accuracy varies.** Customs, Streets, Interchange and Reserve land + well. Lighthouse and Shoreline are noticeably offset. +- **Some maps keep dark surrounds** baked into their art (Streets, Lighthouse, + Shoreline's red band). The identifiable plates were stripped; the rest is + part of the source renders. +- **Nothing has been tested on a real phone.** The CSS is responsive with + proper touch targets, but this is unproven — the browser pane used during + development would not composite frames, so verification was DOM- and + network-level, never pixels. +- **Ground Zero, Factory and Labs** are on the base map but have no detail map. +- **Source PSDs have no agreed home.** They are gitignored; the team needs a + shared drive or NAS path recorded in the README. + +--- + +## 15. Licence + +Map art is by [re3mr.com](https://re3mr.com) under **CC BY-NC-SA 4.0**, +confirmed in every PSD. + +- Attribution is displayed in the viewer and **must stay there**. +- Non-commercial use only. +- Derivative map images inherit the same licence. + +Local and LAN hosting is unambiguously fine. **Get sign-off before hosting +publicly** — ShareAlike would apply to the tiles as adapted works. + +The `sources/` directory is gitignored except `overall.jpeg`, which is 1.3 MB +and is the anchor every placement is expressed against. diff --git a/PLAN.md b/PLAN.md index 25df384..8483d5c 100644 --- a/PLAN.md +++ b/PLAN.md @@ -12,7 +12,7 @@ PSDs in, XYZ tile pyramid out, every map placed on one shared pannable canvas. > maps side by side. > > **Revision 3 (2026-08-08)** — the canvas is now **geographic**. `overall.jpeg` -> is the base, rotated 31° so north is up, and every detail map is scaled and +> is the base, rotated so north is up, and every detail map is scaled and > positioned onto its real location. Seven more maps added (Woods, Interchange, > Reserve, Shoreline, Shoreline Resort, Lighthouse, Streets). The abstract grid > of unrelated cells is gone. @@ -37,7 +37,8 @@ PSDs in, XYZ tile pyramid out, every map placed on one shared pannable canvas. ## 2. Source audit — findings `[x]` -Measured 2026-08-07 from the two supplied PSDs. +Full per-map detail is in [DOCUMENTATION.md §10](DOCUMENTATION.md#10-source-art-findings). +Measured 2026-08-07 from the first two PSDs. | | Customs | Customs — Dorms | | --- | --- | --- | @@ -49,12 +50,13 @@ Measured 2026-08-07 from the two supplied PSDs. | Crop applied | `[0, 860, 7832, 3875]` → 7832 × 3015 | none (art fills canvas) | | Scale | ≈ **7.39 px/m** from the scale bar | not marked | | Render time | 158 s | 321 s | -| Tiles | 503 (8.4 MB) | 469 (1.4 MB) | +| Tiles (current world) | 646 (9.3 MB) | 507 (1.9 MB) | -**Both PSDs use the same top-level convention** — `LOCATION` next to `OVERLAY`, -`LEGEND`, `TITLE`. That is what makes "render one group, drop the rest" a -general rule rather than a Customs special case. Expect it to hold for other -re3mr maps; verify per map at step 1 of the runbook. +**This convention turned out to be Customs-only.** Revision 3 added seven more +maps and none of them matched: the base group is variously `Baselayer`, `Day`, +`3DRENDER`, `BASEMAP+2DLAYERS` or `Map&Art`, several maps need more than one +top-level layer, and Woods buries its terrain three groups deep. Always run +`psd_tree.py`. This was listed as a risk in §10 and it landed. Licence in both files: **CC BY-NC-SA 4.0**, "Made by re3mr.com". @@ -81,15 +83,20 @@ Licence in both files: **CC BY-NC-SA 4.0**, "Made by re3mr.com". | A7 | Dependency-free static server, long cache on tiles | Caddy/nginx drop-in later if wanted | | A8 | Pure-Python pipeline (psd-tools + Pillow) | No native binaries to install on three machines | | A9 | `excludeLayers` escape hatch | Needed because psd-tools fills stroke-only vector shapes | -| A10 | **Coarse underlay layer per map** at `underlayZoom` (2) | Whole world = 17 tiles / 134 KB, on screen in ~120 ms; detail tiles draw over it, so loading gaps never show black | +| A10 | **The base map is the backdrop** | 85 tiles / 0.3 MB, always resident, upscaled past its native z3 — loading gaps show blurry terrain, never black. Replaced the per-map underlay of revision 2 | +| A11 | **Focus-based stacking** | Approximate placements overlap; the map whose centre you are viewing is lifted above all others | +| A12 | **Versioned tile URLs** (`?v=`) | Tile paths are stable across rebuilds but their contents are not; without this, immutable caching blends two builds | ### The world canvas (A5) -The base is `overall.jpeg`, rotated **31°** to put north at the top. That angle -was measured rather than guessed: Customs' detail map is north-up (confirmed by -its PSD compass) and runs 2.6:1 east–west, so solving its 259 × 207 zone -outline for the band angle yields 31°. Rotation maths is verified sub-pixel -against PIL in `rotate_point`. +The base is `overall.jpeg`, rotated **35°** to put north at the top. An +aspect-ratio fit of the Customs zone outline first suggested 31°, but that +polygon encloses more than the playable strip so the estimate ran low, and +attempts to register the two polygons directly failed — the zone outline is +dashed and will not flood-fill. 35° is therefore a visual judgement. +`tools/retilt.py` makes it a one-number change, converting every placement +through the old and new angles. The rotation maths itself is verified +sub-pixel against PIL in `rotate_point`. World pixels are overall-map pixels × `overallScale` (64) — chosen so Customs lands at almost exactly its native 7832 px. Each map's `place` gives centre and @@ -119,11 +126,14 @@ tools/ tile.py base.png -> web/tiles//{z}/{x}/{y}.webp build.py orchestrator; writes web/data/world.json preview.py stitch built tiles into one overview image - common.py config loading + world-grid maths + place_preview.py gridded north-up base map for positioning + retilt.py change world.rotate, keeping placements + common.py config loading + world placement maths server/serve.py static server, LAN-reachable, cache headers web/ index.html, app.js, style.css, vendored Leaflet 1.9.4 +DOCUMENTATION.md full technical reference docs/adding-a-map.md -sources/ build/ web/tiles/ gitignored +sources/ build/ web/tiles/ gitignored (except sources/overall/) ``` --- @@ -135,7 +145,10 @@ sources/ build/ web/tiles/ gitignored | psd-tools fills stroke-only vector `shape` layers as solid colour | Customs rendered white over the whole playable area until `Map Borders` was excluded | Worked around via `excludeLayers`; documented as a check in the runbook | | Excluding `Map Borders` also removes the playable-area boundary outline | Customs no longer shows the dotted play-area edge; the out-of-bounds grey-out still marks it | Accepted. Revisit only if the boundary is missed | | ~~No retina / DPR tiles~~ | ~~Soft on high-DPI screens~~ | **Fixed** — `DENSITY_BOOST` requests one level deeper; 0.56 → 1.33 source px per device px at DPR 1.5 | -| z5 is a hard detail ceiling | Upscaling past zoom 5 is browser-side and blurry | Inherent. The embedded terrain smart object is 7832 × 3720 placed 1:1, so there is no further source detail to extract | +| Each map has a hard detail ceiling | Upscaling past a map's native level is browser-side and blurry | Inherent. Customs' embedded terrain smart object is 7832 × 3720 placed 1:1 — no further source detail exists | +| The 35° tilt is a visual judgement, not a measurement | Alignment may still be slightly off | Both automated approaches failed (see DOCUMENTATION.md §11). `retilt.py` makes it a one-number change | +| Placement accuracy varies | Lighthouse and Shoreline are noticeably offset | Focus-based stacking stops overlaps hiding maps; nudge `place` when it matters | +| Some maps keep dark surrounds baked into their art | Streets, Lighthouse, Shoreline show dark edges | Identifiable plates stripped; the rest is part of the source renders | | `flyToBounds` depends on `requestAnimationFrame` | Picker doesn't move the view in a non-compositing tab | Cosmetic; not seen in a real browser | | Dorms has no scale bar | No px/m for that map | Fine — `pxPerMeter` is optional | @@ -264,4 +277,4 @@ Stages 7 and 8 are fully independent — run them in parallel. --- -*Last updated: 2026-08-07 · Phase 1 complete and verified; Phase 2 next.* +*Last updated: 2026-08-08 · Revision 3 complete and verified; Phase 2 (real-device testing, third-party onboarding) next.* diff --git a/README.md b/README.md index 866ab54..a9a9a9f 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,14 @@ Open the printed URL. The LAN address works from a phone on the same network. Source PSDs are not in the repo (see `.gitignore`) — get them from the shared drive and put them under `sources/`. +## Documentation + +| | | +| --- | --- | +| **[DOCUMENTATION.md](DOCUMENTATION.md)** | Full technical reference — architecture, coordinate systems, config, traps, troubleshooting | +| **[docs/adding-a-map.md](docs/adding-a-map.md)** | Step-by-step runbook for adding a map | +| **[PLAN.md](PLAN.md)** | Project status and remaining work | + ## Adding a map See **[docs/adding-a-map.md](docs/adding-a-map.md)**. Short version: run