Files

283 lines
14 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# TarkovMap — Project Plan
Self-hosted, mobile-friendly Escape from Tarkov map viewer on Leaflet. Layered
PSDs in, XYZ tile pyramid out, every map placed on one shared pannable canvas.
**Status legend:** `[ ]` not started · `[~]` in progress · `[x]` done · `[!]` blocked
**Every stage lists `Owner`, `Depends on`, and `Done when`. Don't tick `[x]` until `Done when` is objectively true.**
> **Revision 2 (2026-08-07)** — scope narrowed to **base map art only**; marker,
> spawn and label overlays are cut. Architecture changed from "one pyramid per
> map plus a switcher" to a **single shared world canvas** holding unrelated
> maps side by side.
>
> **Revision 3 (2026-08-08)** — the canvas is now **geographic**. `overall.jpeg`
> 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.
---
## 1. Goals / Non-goals
### Goals
- Extract **only the base map** from each PSD. No markers, spawns, extracts, captions, legends or titles.
- All maps — including ones with no geographic relationship, like Customs and its Dorms floor plans — live on **one big canvas** you pan across.
- Adding a map is a **config change**, never a code change, and never re-tiles existing maps.
- Fast on a phone over LAN.
- A flow a teammate can follow from a document without asking questions.
### Non-goals
- Marker / spawn / extract overlays *(cut in revision 2 — see §8 backlog)*.
- Public internet hosting (licence constrains this — §3).
- Accounts, editing UI, quest tracking, live player position.
---
## 2. Source audit — findings `[x]`
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 |
| --- | --- | --- |
| PSD canvas | 7832 × 5016 | 4301 × 4904 |
| PSD size | 1.09 GB, 295 layers | 198 MB |
| Base group | `LOCATION` | `LOCATION` |
| Siblings dropped | `LEGEND`, `OVERLAYS`, `TITLE SECTION` | `OVERLAY`, `LEGEND`, `TITLE`, `Credits` |
| Extra exclusion | `Map Borders` (see §6) | none |
| 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 (current world) | 646 (9.3 MB) | 507 (1.9 MB) |
**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".
---
## 3. Constraints
- **CC BY-NC-SA 4.0.** Attribution stays visible in the viewer; non-commercial only; derived map images inherit the licence. LAN use is fine. **Sign-off required before public hosting.**
- **Source art uses Git LFS.** Multi-gigabyte PSDs and archives are LFS objects;
generated `build/` and `web/tiles/` output remains gitignored.
- Tooling on the build machine: Python 3.13, Pillow 12, psd-tools 1.18 + scikit-image, Node 22. No ImageMagick / libvips / GDAL needed.
---
## 4. Architecture — as built
| # | Decision | Notes |
| --- | --- | --- |
| A1 | Leaflet + custom `CRS.Simple`, XYZ pyramid | LatLng is `(y, x)` in world pixels at native resolution |
| A2 | **256 px tiles**, world zoom 0–9 | Base map is native at z3; detail maps at z7–z9 |
| A3 | **WebP q82**, transparent padding on edge tiles | 9.8 MB for both maps combined |
| A4 | Chrome cropped away, not rebuilt | Scope is base art only, so there is no legend to rebuild |
| A5 | **Geographic world canvas** on the rotated overall map | See below — the core of revision 3 |
| A6 | `maps.json` in, `web/data/world.json` out | The app hard-codes nothing about any map |
| 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 | **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 **45°** 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. 45° is therefore the current visual starting point.
`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
width in **rotated** overall-map pixels; `tools/place_preview.py` draws a
gridded preview to author against.
Tile grids must stay integral: a map's tile-index offset has to be a whole
number of tiles at every zoom, which only holds when its origin is a multiple
of `tileSize · 2^maxZoom` = 131 072 px — hopeless for positioning. So rather
than moving a map onto the grid, the tiler **pads** it up-and-left to the
nearest cell boundary and visits only tiles containing content. Exact
placement, integral grid, zero padding cost.
Each map is tiled only to its **native level** (deepest zoom still downscaling
the source) and carries a `minZoom` below which it does not load, so the
overview is just the base map and detail fades in as you zoom.
---
## 5. Repository layout
```
maps.json the only file you edit to add or change a map
tools/
psd_tree.py inspect a PSD's layer tree
export_base.py PSD -> build/<id>/base.png (base group only)
tile.py base.png -> web/tiles/<id>/{z}/{x}/{y}.webp
build.py orchestrator; writes web/data/world.json
preview.py stitch built tiles into one overview image
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/ source artwork tracked through Git LFS
build/ web/tiles/ reproducible output, gitignored
```
---
## 6. Known issues
| Issue | Impact | Status |
| --- | --- | --- |
| 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 |
| 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 45° tilt is a visual judgement, not a measurement | Alignment may still be slightly off | The interactive center-anchor editor now supports manual tuning; `retilt.py` changes the global angle |
| 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 |
---
## 7. Stages
### Phase 1 — pipeline and viewer ✅ **complete**
#### Stage 0 — Repo foundations `[x]`
- [x] `git init`, Git LFS for sources, `.gitignore` covering build output and tiles
- [x] Directory skeleton, `tools/requirements.txt`
- [x] `README.md` with quickstart
- [x] Sources moved to `sources/customs/`
- [x] Large source artwork stored as Git LFS objects
- [x] Master PSDs live in the repository through Git LFS
#### Stage 1 — Source audit `[x]`
- [x] Dimensions, layer trees, blend modes, masks for both PSDs
- [x] Identified the shared `LOCATION` convention
- [x] Derived 7.39 px/m for Customs
- [x] Confirmed CC BY-NC-SA 4.0
#### Stage 2 — Contracts `[x]`
- [x] `maps.json` schema — the single input contract
- [x] `web/data/world.json` — the single output contract the app reads
- [x] Tile URL scheme `tiles/{id}/{z}/{x}/{y}.webp`, XYZ, y-down
- [x] Coordinate spec: LatLng = `(y, x)` in world pixels; grid maths in `common.py`
- [x] `docs/adding-a-map.md` written as the runbook
#### Stage 3 — Extraction `[x]`
- [x] `psd_tree.py` for onboarding inspection
- [x] `export_base.py` renders one named group, drops all siblings
- [x] `excludeLayers` escape hatch for the shape-fill bug
- [x] Warns loudly when an `excludeLayers` entry matches nothing
- [x] Both maps verified by eye — no markers, labels, legends or titles survive
#### Stage 4 — Tiler `[x]`
- [x] Crop, Lanczos pyramid, 256 px WebP tiles, z0–z5
- [x] Edge tiles padded to square with alpha; fully-empty tiles skipped
- [x] Rejects a map too large for its grid cell with an actionable message
- [x] `build.py` orchestrates and emits `world.json`; skips the slow render when `base.png` is current
- [x] Partial builds keep other maps in `world.json`
#### Stage 5 — Viewer `[x]`
- [x] Vendored Leaflet 1.9.4 (no CDN — must work offline on LAN)
- [x] Custom CRS, world grid, per-map `OffsetTileLayer` with `bounds`
- [x] Map picker, URL hash state, non-dismissible attribution
- [x] Minimal dark UI, `maxNativeZoom` over-zoom, transparent `errorTileUrl`
- [x] Verified in-browser: 972 tiles, **zero 404s, zero broken tiles**, correct cross-map offsets
#### Stage 6 — Serving `[~]`
- [x] `server/serve.py` — dependency-free, binds `0.0.0.0`, prints the LAN URL
- [x] `image/webp` MIME, tiles cached 7 days, app shell uncached
- [x] Fixed `serve.py` defaulting to **HTTP/1.0** (a TCP handshake per tile); now HTTP/1.1 keep-alive
- [x] Benchmarked and added **Caddy** as the default engine — `serve.py` collapses to 462 req/s at concurrency 32 while Caddy holds 5,877
- [x] `run.ps1` picks Caddy when present, falls back to `serve.py`; `get-caddy.ps1` fetches the binary
- [x] Verified through Caddy: `immutable` + ETag on tiles, `no-cache` + zstd on the shell, bare 404 for missing tiles
- [ ] Windows Firewall rule for the port
- [ ] Confirm from a phone on the LAN and record the URL in the README
---
### Phase 2 — verification and hardening ← **next**
#### Stage 7 — Mobile pass
`Owner:` __ · `Depends on:` 6
- [x] Viewport meta with `viewport-fit=cover`, safe-area insets, 44 px touch targets
- [x] Collapsible picker; zoom buttons hidden under 640 px in favour of pinch
- [ ] **Test on a real iOS Safari and a real Android Chrome over LAN** — nothing here is proven until this happens
- [ ] Check pinch, double-tap and inertial pan don't fight page scroll
- [x] Retina decided: `DENSITY_BOOST` requests one pyramid level deeper instead of shipping `@2x` tiles — no extra build output, fixes fractional-zoom softness too
- [ ] First-paint budget on LAN (target ~2 s)
#### Stage 8 — Third map by someone else
`Owner:` __ · `Depends on:` 2
The real test of the runbook is a person who has not seen the pipeline.
- [ ] Pick a third map (Factory is the fastest loop; Woods/Streets stress size)
- [ ] A teammate adds it using **only** `docs/adding-a-map.md`
- [ ] Every question they have to ask is a documentation bug — fix the doc
- [ ] Confirm the `LOCATION` convention holds; if it doesn't, note the variant
- [ ] Confirm no map needs more than one grid cell
#### Stage 9 — Grid ergonomics
`Owner:` __ · `Depends on:` 8
- [ ] Decide grid layout policy as map count grows (`gridCols` is currently 4)
- [ ] Consider labelling each map on the canvas at low zoom, so the overview is readable
- [ ] Consider per-map `maxBounds` snapping so panning between maps feels deliberate
---
### Phase 3 — backlog (only if wanted)
- [ ] Measure tool using `pxPerMeter` (Customs has it; Dorms doesn't)
- [ ] PWA / offline tile caching for phones that leave the LAN
- [ ] PMTiles single-file archives instead of loose tiles — revisit around 5+ maps
- [ ] Marker/overlay layers — **cut in revision 2.** The PSDs make this cheap to revive: every marker is its own layer with a known bbox, so positions can be extracted programmatically rather than hand-placed
- [ ] Restore the Customs playable-area boundary, if its absence turns out to matter
---
## 8. Parallelisation
Phase 1 is done, so the tracks are narrower now:
| Track | Stages | Skills |
| --- | --- | --- |
| **Mobile / frontend** | 7 | JS, Leaflet, touch CSS, real devices |
| **Content** | 8 | Photoshop-adjacent; mostly following the runbook |
| **Ops** | 6 tail | Windows networking, firewall |
Stages 7 and 8 are fully independent — run them in parallel.
---
## 9. Open questions
1. Where do master PSDs live so every contributor can reach them? *(blocks Stage 0's last item)*
2. Which maps next, and in what order?
3. Is public hosting ever intended? Changes the licence conversation entirely.
4. Does the missing Customs play-area boundary matter enough to restore?
---
*Last updated: 2026-08-08 · Revision 3 complete and verified; Phase 2 (real-device testing, third-party onboarding) next.*