#!/usr/bin/env python3 """Write OpenMapClassic's `Data/OverlayLand.lua` from the baked `MapOverlayLand` masks. `cargo run -p benilla-app --example bake_zone_land` writes one 256x256 alpha mask per map, the union of that map's own `WorldMapOverlay` art -- the shape of the ground it paints. Lua cannot ask whether a texture file exists (a missing one draws as a white quad, or, as a *mask*, is silently dropped and the whole rectangle shows), so the addon needs a table of which ids were baked. That is all this writes. Run it after the baker, any time the mask set changes: python3 scripts/overlay-land-index.py `--dir` points at another mask folder, `--out` at another destination. """ import argparse import re import sys from pathlib import Path ADDON = Path(__file__).resolve().parent.parent / "benilla-config/AddOns/OpenMapClassic" HEAD = """-------------------------------------------------------------------------------- -- Which maps have a generated land mask (Media/Textures/MapOverlayLand/.tga). -- -- GENERATED -- do not edit. `cargo run -p benilla-app --example bake_zone_land` writes the masks, -- `scripts/overlay-land-index.py` writes this list. -- -- Each mask is the union of that map's own `WorldMapOverlay` alpha: the pieces the game reveals -- as you explore, cut to the shape of the ground, so the union is the map's land and nothing -- else. `Map/Stitch.lua` cuts the unexplored darkening to it, and falls back to it for the art of -- any map the hand-made `MapZoneSoft` set has no file for -- this realm has 175 `WorldMapArea` -- rows against that set's 40. -- -- A file list, not a file test, because Lua has no way to ask whether a texture exists: a mask -- whose art is missing is dropped by the engine and the whole rectangle draws, which is the -- "massive squares" this set exists to remove. -------------------------------------------------------------------------------- local _, ns = ... ns.MapOverlayLand = { """ def main() -> int: ap = argparse.ArgumentParser() ap.add_argument("--dir", default=str(ADDON / "Media/Textures/MapOverlayLand")) ap.add_argument("--out", default=str(ADDON / "Data/OverlayLand.lua")) args = ap.parse_args() folder = Path(args.dir) if not folder.is_dir(): print(f"overlay-land-index: no mask folder at {folder}", file=sys.stderr) return 1 ids = sorted( int(m.group(1)) for p in folder.iterdir() if (m := re.fullmatch(r"(\d+)\.tga", p.name, re.IGNORECASE)) ) if not ids: print(f"overlay-land-index: {folder} holds no .tga masks", file=sys.stderr) return 1 body = [] for i in range(0, len(ids), 8): body.append("\t" + " ".join(f"[{n}] = true," for n in ids[i : i + 8])) text = HEAD + "\n".join(body) + "\n}\n" Path(args.out).write_text(text, encoding="utf-8") print(f"overlay-land-index: {len(ids)} masks -> {args.out}") return 0 if __name__ == "__main__": raise SystemExit(main())