"""Orchestrator: maps.json -> tiles + web/data/world.json. python tools/build.py # export (if needed) + tile everything 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. """ from __future__ import annotations import json import sys import export_base import tile from common import BUILD, DATA, ROOT, 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() targets = [m for m in cfg.maps if m["id"] in ids] if ids else cfg.maps if ids and len(targets) != len(ids): raise SystemExit(f"unknown map id in {ids}") if not tiles_only: for m in targets: if needs_export(m, force): export_base.export(m) else: print(f"[{m['id']}] base.png up to date, skipping export " f"(--force-export to redo)") entries = [tile.tile_map(cfg, m) for m in targets] # The world manifest always describes every configured map, not just the # ones rebuilt this run, so partial builds don't drop maps from the site. 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} maps = sorted((e for e in by_id.values() if e["id"] in known), key=lambda e: (e["cell"][1], e["cell"][0])) world = { "tileSize": cfg.tile_size, "maxZoom": cfg.max_zoom, "cellSize": cfg.cell_size, "gridCols": cfg.grid_cols, "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)} with {len(maps)} map(s)") if __name__ == "__main__": main(sys.argv[1:])