#!/usr/bin/env python3 """ regen_scroll_catalog.py — re-generate CoaExporter/Data/ScrollCatalog.lua from the AtlasLootAscension MysticEnchants.lua source of truth. Usage: python3 scripts/regen_scroll_catalog.py [--source PATH] [--out PATH] """ from __future__ import annotations import argparse import collections import re from pathlib import Path DEFAULT_SOURCE = Path('/home/sub/public-repos/AtlasLootAscension/' 'AtlasLoot_OriginalWoW/MysticEnchants.lua') DEFAULT_OUT = Path(__file__).parent.parent / \ 'CoaExporter' / 'Data' / 'ScrollCatalog.lua' def extract(source: Path): text = source.read_text() sections = re.findall( r'\["(MysticEnchants\w+)"\]\s*=\s*\{(.*?)^\s*\}\s*,', text, re.DOTALL | re.MULTILINE) out = collections.defaultdict(list) for cls, body in sections: class_name = cls.replace('MysticEnchants', '') for iid, name in re.findall( r'\{\s*itemID\s*=\s*(\d+)(?:[^}]*?)?\}\s*,\s*(?://|--)\s*(.+?)(?:\n|$)', body): out[class_name].append((int(iid), name.strip())) return out def render_lua(by_class) -> str: total = sum(len(v) for v in by_class.values()) lines = [ '-- CoaExporter / Data / ScrollCatalog.lua', '-- Auto-generated from AtlasLootAscension MysticEnchants.lua', f'-- {total} mystic scroll item IDs across {len(by_class)} classes', '-- Re-generate: scripts/regen_scroll_catalog.py', '', 'CoaExporter = _G.CoaExporter or {}', 'local AE = CoaExporter', '', 'AE.ScrollCatalog = {', ] for cls in sorted(by_class): lines.append(f' {cls} = {{') for iid, name in sorted(by_class[cls], key=lambda x: x[1]): esc = name.replace('"', '\\"') lines.append(f' {{ itemID = {iid}, name = "{esc}" }},') lines.append(' },') lines.extend([ '}', '', f'AE.ScrollCatalogTotal = {total}', 'AE._loadedScrollCatalog = true', '', ]) return '\n'.join(lines) def main(): ap = argparse.ArgumentParser() ap.add_argument('--source', type=Path, default=DEFAULT_SOURCE) ap.add_argument('--out', type=Path, default=DEFAULT_OUT) args = ap.parse_args() by_class = extract(args.source) args.out.parent.mkdir(parents=True, exist_ok=True) args.out.write_text(render_lua(by_class)) total = sum(len(v) for v in by_class.values()) print(f'wrote {args.out} ({total} scrolls, {len(by_class)} classes)') if __name__ == '__main__': main()