Files
TarkovMaps/tools/preview.py
T
Claude 5afde00ab7 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]>
2026-08-07 23:22:21 -07:00

64 lines
1.9 KiB
Python

"""Stitch built tiles into one overview PNG -- a layout sanity check.
python tools/preview.py [zoom] # default 3
Writes build/world-preview.png showing every map at its world position, so you
can confirm a newly added map landed in the grid cell you meant before opening
a browser.
"""
from __future__ import annotations
import json
import sys
from PIL import Image
from common import BUILD, DATA, ROOT, TILES
Image.MAX_IMAGE_PIXELS = None
def main() -> None:
z = int(sys.argv[1]) if len(sys.argv) > 1 else 3
world_path = DATA / "world.json"
if not world_path.exists():
raise SystemExit("web/data/world.json missing -- run tools/build.py first")
world = json.loads(world_path.read_text(encoding="utf-8"))
ts, zmax = world["tileSize"], world["maxZoom"]
if not 0 <= z <= zmax:
raise SystemExit(f"zoom must be 0..{zmax}")
scale = 2.0 ** (z - zmax)
def at(v: float) -> int:
return round(v * scale)
width = max(at(m["origin"][0] + m["size"][0]) for m in world["maps"])
height = max(at(m["origin"][1] + m["size"][1]) for m in world["maps"])
canvas = Image.new("RGB", (width, height), (20, 22, 26))
for m in world["maps"]:
gx, gy = m["cell"]
ox, oy = at(m["origin"][0]), at(m["origin"][1])
tdir = TILES / m["id"] / str(z)
if not tdir.exists():
print(f" {m['id']}: no tiles at z{z}, skipped")
continue
n = 0
for col in tdir.iterdir():
for tile in col.glob("*.webp"):
lx, ly = int(col.name), int(tile.stem)
canvas.paste(Image.open(tile).convert("RGB"),
(ox + lx * ts, oy + ly * ts))
n += 1
print(f" {m['id']:<16} cell {gx},{gy} world {ox},{oy} {n} tiles")
out = BUILD / "world-preview.png"
canvas.save(out)
print(f"\nwrote {out.relative_to(ROOT)} {width}x{height} (zoom {z})")
if __name__ == "__main__":
main()