diff --git a/README.md b/README.md index 0330d03..4af4473 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,9 @@ tools/ tile.py base.png -> web/tiles//{z}/{x}/{y}.webp build.py orchestrator; also writes web/data/world.json preview.py stitch built tiles into one overview image - common.py config loading + the world-grid maths + place_preview.py gridded base map for positioning maps + retilt.py change world.rotate, keeping placements + common.py config loading + world placement maths server/serve.py dependency-free static server with sane cache headers web/ the site: index.html, app.js, style.css, vendored Leaflet sources/ gitignored — source PSDs @@ -62,10 +64,11 @@ web/tiles/ gitignored — generated tiles ## How the shared canvas works -The base is `sources/overall/overall.jpeg`, rotated **31°** so north is up. That -angle was measured, not guessed: Customs' detail map is north-up (its PSD -compass says so) and runs 2.6:1 east–west, so solving its 259 × 207 zone -outline for the band angle gives 31°. +The base is `sources/overall/overall.jpeg`, rotated **35°** so north is up. +(An aspect-ratio fit of the Customs zone outline suggested 31°, but the zone +polygon encloses more than the playable strip so that estimate ran low; 35° +lines the maps up better by eye. Adjust with `tools/retilt.py`, which converts +every placement through the old and new angles so geography is preserved.) World pixels are overall-map pixels × `overallScale` (64), which puts Customs at almost exactly its native 7832 px. Each map's `place` entry gives its centre @@ -84,35 +87,47 @@ all. So the overview is just the base map, and detail maps appear as you go in. ## No black gaps -The base map is the backdrop. It is 70 tiles / 0.2 MB, always resident, and +The base map is the backdrop. It is 85 tiles / 0.3 MB, always resident, and Leaflet upscales it past its native z3 — so any gap while detail tiles load shows blurry terrain rather than the page background. +## Stacking + +Placements are approximate, so map rectangles overlap where the real locations +don't. Baseline order puts the finer map on top (by `maxNativeZoom`, then +smaller footprint), and on top of that **the map whose centre you are viewing +is lifted above all others** — so an overlapping neighbour can never hide the +map you came to see. + ## Current maps -Base: `overall.jpeg` 1308 × 1296 → 1790 × 1786 rotated → world 114 496 × 114 240. +Base: `overall.jpeg` 1308 × 1296 → 1816 × 1812 rotated → world 116 160 × 115 968. | Map | PSD | Base layers | | --- | --- | --- | | Customs | 7832 × 5016 | `LOCATION` | | Customs — Dorms | 4301 × 4904 | `LOCATION` | -| Woods | 7680 × 5168 | `re3mr.com/Map&Art/Map&OverlayArt/{RawMapLayer,MapBlackout,WaterDetail}` | +| 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` | -| Streets of Tarkov | 7605 × 4841 | `Layer 1`, `Map - 3D map portion…` | +| Streets of Tarkov | 7605 × 4841 | `Map - 3D map portion…` | There is **no shared naming convention** between these PSDs — see [docs/adding-a-map.md](docs/adding-a-map.md). ## Tile resolution and sharpness -`maxZoom` is derived from the largest map: `ceil(log2(7832 / 256)) = 5`. At z5 -one source pixel is one CSS pixel, and z5 *is* the full PSD — verified by -reading the embedded terrain smart object, which is exactly 7832 × 3720 placed -1:1. There is no hidden detail to recover, so z5 is a hard ceiling. +World `maxZoom` is 9, set so the whole 116 160 px world fits the pyramid. Each +map is tiled only to its own **native level** — the deepest zoom still +downscaling its source — recorded as `maxNativeZoom` in `world.json`. The base +map is native at z3; detail maps land at z7–z9. + +Those ceilings are real: Customs' embedded terrain smart object is exactly +7832 × 3720 placed 1:1, so there is no hidden detail to recover. Past a map's +native level the browser upscales. Sharpness is therefore about **level selection**, not pyramid depth. Leaflet picks its level with `Math.round(mapZoom)`, so at zoom 2.25 it takes level 2 and @@ -126,14 +141,14 @@ pixel (higher is sharper, 1.0 is pixel-perfect): | View zoom | Before | After | | --- | --- | --- | -| 0–4 | 0.56 | **1.33** | -| 5 (1:1 source) | 0.67 | 0.67 | +| below native | 0.56 | **1.33** | +| at native | 0.67 | 0.67 | It costs ~4× the tiles in view (99 at the busiest level on a 1315 px viewport, ~17 KB each). Cached for a week and served by Caddy, that is a fair trade. -At z5 and beyond you are past the source resolution and the browser upscales — -unavoidable, and `ZOOM_HEADROOM` deliberately allows two levels of it. +Past a map's native level you are beyond its source resolution and the browser +upscales — unavoidable, and `ZOOM_HEADROOM` deliberately allows one level of it. ## Serving diff --git a/docs/adding-a-map.md b/docs/adding-a-map.md index 1d736a3..cdf641d 100644 --- a/docs/adding-a-map.md +++ b/docs/adding-a-map.md @@ -109,6 +109,21 @@ aspect ratio. Positions are deliberately approximate — the game's individual maps are not drawn to match the satellite view exactly, so aim for "clearly the right place", not pixel alignment. +Because placements are approximate, map rectangles **do** overlap where the +real locations don't. That is handled in the viewer rather than by chasing +perfect boxes: the map whose centre you are viewing is always lifted to the +top, so an overlapping neighbour can never hide it. + +### Changing the tilt + +`place` coordinates live in the rotated frame, so editing `world.rotate` by +hand would move every map. Use the helper instead — it converts all placements +through the old and new angles so geography is preserved: + +```bash +python tools/retilt.py 35 +``` + --- ## 5. Build and verify diff --git a/maps.json b/maps.json index aa57444..923dcde 100644 --- a/maps.json +++ b/maps.json @@ -6,7 +6,7 @@ "$comment_world": "The overall map is the base everything else sits on. It is rotated by `rotate` degrees (counter-clockwise) to put north at the top; 31 deg was measured from the Customs zone outline, whose detail map is north-up and 2.6:1 east-west. `overallScale` is world pixels per overall-map pixel, set so Customs lands at its native 7832 px.", "world": { "image": "sources/overall/overall.jpeg", - "rotate": 31, + "rotate": 35.0, "overallScale": 64 }, "$comment_place": "`place` is in ROTATED overall-map pixels (the north-up image, which is what tools/place_preview.py draws a grid over): cx/cy = centre, w = width. Positions are deliberately approximate -- the game's maps do not tile exactly onto the satellite view.", @@ -29,8 +29,8 @@ ], "pxPerMeter": 7.39, "place": { - "cx": 952, - "cy": 960, + "cx": 970, + "cy": 969, "w": 265 } }, @@ -43,8 +43,8 @@ ], "crop": null, "place": { - "cx": 1000, - "cy": 990, + "cx": 1020, + "cy": 996, "w": 70 } }, @@ -58,8 +58,8 @@ ], "crop": null, "place": { - "cx": 818, - "cy": 652, + "cx": 814, + "cy": 672, "w": 380 } }, @@ -72,8 +72,8 @@ ], "crop": null, "place": { - "cx": 1132, - "cy": 875, + "cx": 1143, + "cy": 872, "w": 95 } }, @@ -86,8 +86,8 @@ ], "crop": null, "place": { - "cx": 770, - "cy": 1022, + "cx": 792, + "cy": 1044, "w": 140 } }, @@ -100,8 +100,8 @@ ], "crop": null, "place": { - "cx": 735, - "cy": 1222, + "cx": 771, + "cy": 1246, "w": 380 } }, @@ -115,8 +115,8 @@ ], "crop": null, "place": { - "cx": 660, - "cy": 1175, + "cx": 693, + "cy": 1204, "w": 130 } }, @@ -129,9 +129,9 @@ ], "crop": null, "place": { - "cx": 540, - "cy": 1010, - "w": 300 + "cx": 565, + "cy": 1085, + "w": 275 } }, { @@ -143,8 +143,8 @@ ], "crop": null, "place": { - "cx": 1130, - "cy": 445, + "cx": 1111, + "cy": 443, "w": 110 } } diff --git a/tools/common.py b/tools/common.py index bc3dffd..28e28a5 100644 --- a/tools/common.py +++ b/tools/common.py @@ -45,6 +45,16 @@ def rotate_point(x: float, y: float, w: int, h: int, deg: float) -> tuple[float, return (dx * c + dy * s) + w2 / 2.0, (-dx * s + dy * c) + h2 / 2.0 +def unrotate_point(rx: float, ry: float, w: int, h: int, deg: float) -> tuple[float, float]: + """Inverse of rotate_point: rotated-frame coords back to source coords.""" + th = math.radians(deg) + c, s = math.cos(th), math.sin(th) + w2 = w * abs(c) + h * abs(s) + h2 = w * abs(s) + h * abs(c) + u, v = rx - w2 / 2.0, ry - h2 / 2.0 + return (u * c - v * s) + w / 2.0, (u * s + v * c) + h / 2.0 + + def rotated_size(w: int, h: int, deg: float) -> tuple[int, int]: th = math.radians(deg) c, s = abs(math.cos(th)), abs(math.sin(th)) diff --git a/tools/retilt.py b/tools/retilt.py new file mode 100644 index 0000000..abd7853 --- /dev/null +++ b/tools/retilt.py @@ -0,0 +1,53 @@ +"""Change world.rotate without losing every map's position. + + python tools/retilt.py 35 + +`place` coordinates live in the ROTATED frame, so changing the tilt would +otherwise move every map. This converts each `place` back through the old +rotation and forward through the new one, then writes both the new angle and +the converted coordinates to maps.json. Geography is preserved; only the tilt +changes. + +Re-run `tools/place_preview.py` afterwards to check, then +`tools/build.py --tiles-only` to retile. +""" + +from __future__ import annotations + +import json +import sys + +from common import CONFIG, load_config, rotate_point, unrotate_point + + +def main() -> None: + if len(sys.argv) != 2: + raise SystemExit(__doc__) + new_deg = float(sys.argv[1]) + + cfg = load_config() + old_deg = cfg.rotate + bw, bh = cfg.base_size() + if abs(new_deg - old_deg) < 1e-9: + print(f"rotate is already {old_deg}; nothing to do") + return + + raw = json.loads(CONFIG.read_text(encoding="utf-8")) + print(f"rotate {old_deg} -> {new_deg} (base {bw}x{bh})\n") + print(f"{'map':<18} {'old cx,cy':>14} {'new cx,cy':>14}") + for m in raw["maps"]: + p = m.get("place") + if not p: + continue + sx, sy = unrotate_point(p["cx"], p["cy"], bw, bh, old_deg) + nx, ny = rotate_point(sx, sy, bw, bh, new_deg) + print(f"{m['id']:<18} {p['cx']:>6.0f},{p['cy']:>6.0f} {nx:>6.0f},{ny:>6.0f}") + p["cx"], p["cy"] = round(nx), round(ny) + + raw["world"]["rotate"] = new_deg + CONFIG.write_text(json.dumps(raw, indent=2, ensure_ascii=False) + "\n", encoding="utf-8") + print(f"\nwrote {CONFIG.name}; now run place_preview.py and build.py --tiles-only") + + +if __name__ == "__main__": + main() diff --git a/web/app.js b/web/app.js index 75eae2d..c3c39b2 100644 --- a/web/app.js +++ b/web/app.js @@ -79,12 +79,35 @@ async function main() { const boost = DENSITY_BOOST; - for (const [i, m] of world.maps.entries()) { + /* Stacking. Placements are approximate, so map rectangles overlap even when + * the real locations don't (Reserve clips Customs, Lighthouse clips + * Shoreline). Baseline order puts the finer map on top: sort by + * maxNativeZoom, then by smaller footprint. `focus()` then lifts whichever + * map you are actually looking at above the rest, so an overlapping + * neighbour can never hide the map you came to see. */ + const detail = world.maps.filter((m) => !m.base); + const stackOrder = [...detail].sort( + (a, b) => (a.maxNativeZoom - b.maxNativeZoom) + || (b.size[0] * b.size[1] - a.size[0] * a.size[1]), + ); + const BASE_Z = 1; + const baseZ = new Map(stackOrder.map((m, i) => [m.id, 2 + i])); + const TOP_Z = 2 + stackOrder.length; + const layers = new Map(); + + const focus = (id) => { + for (const [mid, layer] of layers) { + if (mid === base.id) continue; + layer.setZIndex(mid === id ? TOP_Z : baseZ.get(mid)); + } + }; + + for (const m of world.maps) { // The base map is the backdrop: it is a handful of tiles, always loaded, // and Leaflet upscales it past its native level -- so a gap while detail // tiles load shows blurry terrain rather than the page background. const isBase = !!m.base; - new OffsetTileLayer(`tiles/${m.id}/{z}/{x}/{y}.webp`, { + const layer = new OffsetTileLayer(`tiles/${m.id}/{z}/{x}/{y}.webp`, { cell: m.cell, bounds: rectOf(m), baseTileSize: world.tileSize, @@ -98,9 +121,10 @@ async function main() { keepBuffer: isBase ? 6 : 2, updateWhenIdle: false, errorTileUrl: BLANK, - zIndex: isBase ? 1 : 2 + i, + zIndex: isBase ? BASE_Z : baseZ.get(m.id), className: isBase ? 'tile-base' : undefined, }).addTo(map); + layers.set(m.id, layer); } // --- picker ----------------------------------------------------------- @@ -128,6 +152,7 @@ async function main() { .sort((a, b) => a.size[0] * a.size[1] - b.size[0] * b.size[1])[0]; buttons.forEach((b) => b.setAttribute( 'aria-current', String(hit ? hit.id === b.dataset.id : b.dataset.id === base.id))); + focus(hit?.id); const z = Math.round(map.getZoom() * 4) / 4; history.replaceState(null, '', `#${z}/${Math.round(c.lat)}/${Math.round(c.lng)}`);