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]>
77 lines
2.5 KiB
Python
77 lines
2.5 KiB
Python
"""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:])
|