"""PSD -> flat base-map PNG. Renders exactly one top-level group (`baseGroup` in maps.json, "LOCATION" for every re3mr map so far) and discards everything else, so no markers, legend, title or captions survive into the tiles. Individual layers inside that group can be suppressed via `excludeLayers`. That exists because psd-tools renders stroke-only vector shapes as solid fills -- Customs' "Map Borders" group paints the whole playable area white if it is left in. Run psd_tree.py and eyeball the output when onboarding a new map. python tools/export_base.py # every map python tools/export_base.py customs # one map Output: build//base.png (full PSD canvas, uncropped -- tile.py crops) """ from __future__ import annotations import sys import time from PIL import Image from psd_tools import PSDImage from common import BUILD, ROOT, find_map, load_config Image.MAX_IMAGE_PIXELS = None def hide(group, names: list[str], map_id: str) -> None: """Hide every descendant layer whose name matches one in `names`.""" remaining = set(names) def walk(node): for layer in node: if layer.name in remaining: layer.visible = False print(f"[{map_id}] excluding {layer.name!r}") elif layer.is_group(): walk(layer) walk(group) # A name that matches nothing is almost always a typo, and it fails # silently into a bad render, so say so loudly. found = set() def collect(node): for layer in node: found.add(layer.name) if layer.is_group(): collect(layer) collect(group) for missing in remaining - found: print(f"[{map_id}] WARNING: excludeLayers entry {missing!r} matched nothing") def export(m: dict) -> None: psd_path = ROOT / m["psd"] if not psd_path.exists(): raise SystemExit(f"missing source PSD: {psd_path}") out = BUILD / m["id"] / "base.png" out.parent.mkdir(parents=True, exist_ok=True) print(f"[{m['id']}] opening {psd_path.name} ({psd_path.stat().st_size / 1e6:.0f} MB)") t0 = time.time() psd = PSDImage.open(psd_path) wanted = m.get("baseGroup", "LOCATION") group = next((l for l in psd if l.name == wanted), None) if group is None: names = ", ".join(repr(l.name) for l in psd) raise SystemExit(f"[{m['id']}] no top-level layer named {wanted!r}. Found: {names}") dropped = [l.name for l in psd if l.name != wanted and l.visible] print(f"[{m['id']}] canvas {psd.size[0]}x{psd.size[1]}, rendering {wanted!r}") print(f"[{m['id']}] dropping: {', '.join(repr(n) for n in dropped) or '(nothing)'}") if m.get("excludeLayers"): hide(group, m["excludeLayers"], m["id"]) # viewport pins the result to the full canvas so every map's export shares # the PSD's own coordinate system -- crops in maps.json stay meaningful. img = group.composite(viewport=psd.viewbox, force=True) img = img.convert("RGB") img.save(out, "PNG", optimize=False, compress_level=1) print(f"[{m['id']}] wrote {out.relative_to(ROOT)} " f"{img.size[0]}x{img.size[1]} in {time.time() - t0:.0f}s\n") def main(argv: list[str]) -> None: cfg = load_config() targets = [find_map(cfg, i) for i in argv] if argv else cfg.maps for m in targets: export(m) if __name__ == "__main__": main(sys.argv[1:])