The canvas is no longer an abstract grid of unrelated cells. overall.jpeg is now the base, rotated 31 degrees so north is up, and every detail map is scaled and positioned onto its real location. Zoom out for all of Tarkov; zoom in and the full-resolution re3mr map takes over. The 31 degrees was measured, not guessed: Customs' detail map is north-up (its PSD compass confirms it) and runs 2.6:1 east-west, so solving its 259x207 zone outline for the band angle gives 31. rotate_point is verified sub-pixel against PIL. Adds Woods, Interchange, Reserve, Shoreline, Shoreline Resort, Lighthouse and Streets, and moves every source under sources/<id>/. baseGroup becomes baseLayers, a list of slash-paths. These PSDs share no naming convention at all -- the base is variously LOCATION, Baselayer, Day, 3DRENDER, BASEMAP+2DLAYERS or Map&Art; several need more than one top-level layer, and Woods buries its terrain three groups deep. Exports also keep alpha now, so maps composite onto the terrain instead of sitting in opaque rectangles. Placement needs sub-cell precision, but tile grids stay integral only when a map's origin is a multiple of tileSize * 2^maxZoom (131072 px). So rather than snapping a map to the grid, the tiler pads it up-and-left to the nearest cell boundary and visits only tiles holding content: exact placement, integral grid, no cost. Each map is tiled to its native level and carries a minZoom, so the overview stays cheap. Two psd-tools failures worked around: stroke effects on empty-bbox layers crash scikit-image (patched to skip), and psd_tools.composite exports a function that shadows its own submodule. Verified zoom 0-9: 10 layers, zero broken tiles. Co-Authored-By: Claude Opus 5 <[email protected]>
72 lines
2.5 KiB
Python
72 lines
2.5 KiB
Python
"""Stitch built tiles into one overview PNG -- a layout sanity check.
|
|
|
|
python tools/preview.py [zoom] # default 4
|
|
|
|
Writes build/world-preview.png showing the base map with every detail map
|
|
composited on top at its world position, so you can confirm placements before
|
|
opening a browser.
|
|
|
|
Tile (z, x, y) sits at level pixel (x * tileSize, y * tileSize) because every
|
|
map's grid shares the world origin -- padding is baked into the indices.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
|
|
from PIL import Image
|
|
|
|
from common import BUILD, DATA, ROOT, TILES
|
|
|
|
Image.MAX_IMAGE_PIXELS = None
|
|
MAX_PX = 4000
|
|
|
|
|
|
def main() -> None:
|
|
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"]
|
|
z = int(sys.argv[1]) if len(sys.argv) > 1 else 4
|
|
z = max(0, min(z, zmax))
|
|
|
|
scale = 2.0 ** (z - zmax)
|
|
width = max(1, round(world["worldSize"][0] * scale))
|
|
height = max(1, round(world["worldSize"][1] * scale))
|
|
if max(width, height) > MAX_PX:
|
|
raise SystemExit(f"zoom {z} would be {width}x{height}; try a lower zoom")
|
|
|
|
canvas = Image.new("RGBA", (width, height), (16, 18, 22, 255))
|
|
|
|
for m in world["maps"]: # base first, already ordered by build.py
|
|
# Mirror the browser: fall back to the deepest level a map actually has
|
|
# and upscale it, so the base map still shows past its native zoom.
|
|
src_z = next((zz for zz in range(z, -1, -1) if (TILES / m["id"] / str(zz)).exists()), None)
|
|
if src_z is None:
|
|
print(f" {m['id']:<18} no tiles at or below z{z}")
|
|
continue
|
|
up = 2 ** (z - src_z)
|
|
tdir = TILES / m["id"] / str(src_z)
|
|
n = 0
|
|
for col in tdir.iterdir():
|
|
for tile in col.glob("*.webp"):
|
|
x, y = int(col.name), int(tile.stem)
|
|
img = Image.open(tile).convert("RGBA")
|
|
if up != 1:
|
|
img = img.resize((ts * up, ts * up), Image.LANCZOS)
|
|
canvas.alpha_composite(img, (x * ts * up, y * ts * up))
|
|
n += 1
|
|
note = "" if up == 1 else f" (z{src_z} upscaled x{up})"
|
|
print(f" {m['id']:<18} origin {tuple(m['origin'])} size {tuple(m['size'])} {n} tiles{note}")
|
|
|
|
out = BUILD / "world-preview.png"
|
|
canvas.convert("RGB").save(out)
|
|
print(f"\nwrote {out.relative_to(ROOT)} {width}x{height} (zoom {z} of {zmax})")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|