"""Print a PSD's layer tree. Run this first when onboarding a new map. python tools/psd_tree.py sources/customs/customs.psd python tools/psd_tree.py sources/customs/customs.psd --depth 3 You are looking for two things: 1. the name of the top-level group holding the map art -> `baseGroup` 2. any `shape` layers inside it -> likely `excludeLayers` candidates, because psd-tools fills stroke-only vector shapes as solid colour. Legend: [V] visible [.] hidden """ from __future__ import annotations import sys from pathlib import Path from psd_tools import PSDImage def walk(node, depth: int, limit: int) -> None: for layer in node: flag = "V" if layer.visible else "." pad = " " * depth print(f"{pad}[{flag}] {layer.kind:<11} {layer.name[:44]!r:<46} " f"blend={layer.blend_mode.name.lower():<12} bbox={layer.bbox}") if layer.is_group() and depth < limit: walk(layer, depth + 1, limit) def main() -> None: args = [a for a in sys.argv[1:] if not a.startswith("--")] if not args: raise SystemExit(__doc__) limit = 2 if "--depth" in sys.argv: limit = int(sys.argv[sys.argv.index("--depth") + 1]) path = Path(args[0]) psd = PSDImage.open(path) print(f"{path.name}: {psd.size[0]}x{psd.size[1]}, {psd.depth}-bit\n") walk(psd, 0, limit) if __name__ == "__main__": main()