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]>
103 lines
3.5 KiB
Python
103 lines
3.5 KiB
Python
"""Orchestrator: maps.json -> tiles + web/data/world.json.
|
|
|
|
python tools/build.py # base + every map
|
|
python tools/build.py customs # just one map
|
|
python tools/build.py --tiles-only # skip the slow PSD render
|
|
python tools/build.py --force-export # re-render even if base.png exists
|
|
|
|
Exporting a 1 GB PSD takes minutes, so base.png is reused unless it is older
|
|
than the PSD or --force-export is given. The base layer (`overall`) is a plain
|
|
image and is always cheap to retile.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
|
|
import export_base
|
|
import tile
|
|
from common import BUILD, DATA, ROOT, WORLD_ID, load_config
|
|
|
|
|
|
def needs_export(m: dict, force: bool) -> bool:
|
|
base = BUILD / m["id"] / "base.png"
|
|
if force or not base.exists():
|
|
return True
|
|
psd = ROOT / m["psd"]
|
|
return psd.exists() and psd.stat().st_mtime > base.stat().st_mtime
|
|
|
|
|
|
def main(argv: list[str]) -> None:
|
|
tiles_only = "--tiles-only" in argv
|
|
force = "--force-export" in argv
|
|
ids = [a for a in argv if not a.startswith("--")]
|
|
|
|
cfg = load_config()
|
|
world_m = tile.world_entry(cfg)
|
|
|
|
if ids:
|
|
targets = [world_m] if WORLD_ID in ids else []
|
|
targets += [m for m in cfg.maps if m["id"] in ids]
|
|
known = {m["id"] for m in cfg.maps} | {WORLD_ID}
|
|
unknown = set(ids) - known
|
|
if unknown:
|
|
raise SystemExit(f"unknown map id(s): {', '.join(sorted(unknown))}")
|
|
else:
|
|
targets = [world_m] + cfg.maps
|
|
|
|
if not tiles_only:
|
|
failed = []
|
|
for m in targets:
|
|
if m["id"] == WORLD_ID:
|
|
continue
|
|
if not needs_export(m, force):
|
|
print(f"[{m['id']}] base.png up to date, skipping export")
|
|
continue
|
|
try:
|
|
export_base.export(m)
|
|
except Exception as exc: # noqa: BLE001
|
|
failed.append(m["id"])
|
|
print(f"[{m['id']}] EXPORT FAILED -- {type(exc).__name__}: {exc}\n")
|
|
if failed:
|
|
print(f"skipping tiling for failed export(s): {', '.join(failed)}\n")
|
|
targets = [m for m in targets if m["id"] not in failed]
|
|
|
|
entries = []
|
|
for m in targets:
|
|
if m["id"] != WORLD_ID and not (BUILD / m["id"] / "base.png").exists():
|
|
print(f"[{m['id']}] no base.png, skipping tiling")
|
|
continue
|
|
entries.append(tile.tile_map(cfg, m))
|
|
|
|
# Keep maps that weren't part of this run so partial builds don't drop them.
|
|
by_id = {e["id"]: e for e in entries}
|
|
world_path = DATA / "world.json"
|
|
if world_path.exists():
|
|
for e in json.loads(world_path.read_text(encoding="utf-8")).get("maps", []):
|
|
by_id.setdefault(e["id"], e)
|
|
|
|
known = {m["id"] for m in cfg.maps} | {WORLD_ID}
|
|
maps = [e for e in by_id.values() if e["id"] in known]
|
|
# Base first so it paints underneath everything else.
|
|
maps.sort(key=lambda e: (not e.get("base"), -e["size"][0]))
|
|
|
|
ww, wh = cfg.world_size()
|
|
world = {
|
|
"tileSize": cfg.tile_size,
|
|
"maxZoom": cfg.max_zoom,
|
|
"worldSize": [ww, wh],
|
|
"cellSize": cfg.cell_size,
|
|
"rotate": cfg.rotate,
|
|
"overallScale": cfg.overall_scale,
|
|
"attribution": cfg.attribution,
|
|
"maps": maps,
|
|
}
|
|
DATA.mkdir(parents=True, exist_ok=True)
|
|
world_path.write_text(json.dumps(world, indent=2, ensure_ascii=False), encoding="utf-8")
|
|
print(f"\nwrote {world_path.relative_to(ROOT)}: world {ww}x{wh}, {len(maps)} layer(s)")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main(sys.argv[1:])
|