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]>
70 lines
2.3 KiB
Python
70 lines
2.3 KiB
Python
"""Render the rotated base map with a grid and every map's `place` box.
|
|
|
|
python tools/place_preview.py
|
|
|
|
Writes build/place-preview.png. This is the tool for positioning maps: read
|
|
coordinates straight off the grid, edit `place` in maps.json, re-run. No
|
|
tiling needed, so the loop is a couple of seconds.
|
|
|
|
Coordinates shown are ROTATED overall-map pixels, which is exactly what
|
|
`place.cx/cy/w` expect.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from PIL import Image, ImageDraw
|
|
|
|
from common import BUILD, ROOT, load_config
|
|
|
|
Image.MAX_IMAGE_PIXELS = None
|
|
GRID = 100
|
|
|
|
|
|
def main() -> None:
|
|
cfg = load_config()
|
|
im = Image.open(cfg.base_image_path()).convert("RGB")
|
|
cfg.set_base_size(im.size)
|
|
if cfg.rotate:
|
|
im = im.rotate(cfg.rotate, expand=True, resample=Image.BICUBIC)
|
|
im = Image.eval(im, lambda v: min(255, int(v * 2.1))) # the art is very dark
|
|
w, h = im.size
|
|
d = ImageDraw.Draw(im)
|
|
|
|
for x in range(0, w, GRID):
|
|
d.line([x, 0, x, h], fill=(0, 90, 90))
|
|
d.text((x + 2, 2), str(x), fill=(0, 220, 220))
|
|
for y in range(0, h, GRID):
|
|
d.line([0, y, w, y], fill=(0, 90, 90))
|
|
d.text((2, y + 2), str(y), fill=(0, 220, 220))
|
|
|
|
for m in cfg.maps:
|
|
p = m.get("place")
|
|
if not p:
|
|
continue
|
|
src = BUILD / m["id"] / "base.png"
|
|
aspect = 0.6
|
|
if src.exists():
|
|
with Image.open(src) as s:
|
|
cw, ch = (m["crop"][2] - m["crop"][0], m["crop"][3] - m["crop"][1]) \
|
|
if m.get("crop") else s.size
|
|
aspect = ch / cw
|
|
hw = p["w"] / 2.0
|
|
hh = hw * aspect
|
|
box = [p["cx"] - hw, p["cy"] - hh, p["cx"] + hw, p["cy"] + hh]
|
|
d.rectangle(box, outline=(255, 70, 70), width=3)
|
|
d.text((box[0] + 4, box[1] + 4), m["id"], fill=(255, 255, 0))
|
|
d.line([p["cx"] - 6, p["cy"], p["cx"] + 6, p["cy"]], fill=(255, 0, 0), width=2)
|
|
d.line([p["cx"], p["cy"] - 6, p["cx"], p["cy"] + 6], fill=(255, 0, 0), width=2)
|
|
|
|
d.text((10, h - 20), f"rotate={cfg.rotate}deg north up | rotated base {w}x{h}",
|
|
fill=(0, 255, 255))
|
|
out = BUILD / "place-preview.png"
|
|
out.parent.mkdir(parents=True, exist_ok=True)
|
|
im.save(out)
|
|
print(f"wrote {out.relative_to(ROOT)} {w}x{h}")
|
|
print("place boxes use these rotated coordinates; edit maps.json and re-run")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|