Files
GaCy-GO/tools/export_cw_spotlights.py
T

41 lines
2.2 KiB
Python

"""Export native Spotlight handbook rows, retaining fixed-point strings."""
import argparse
import hashlib
import json
from pathlib import Path
def main():
p = argparse.ArgumentParser(description=__doc__)
p.add_argument('--capture', type=Path, required=True)
p.add_argument('--catalog', type=Path, required=True)
p.add_argument('--output', type=Path, required=True)
a = p.parse_args()
raw = a.capture.read_bytes()
lines = raw.decode('utf-8-sig').splitlines()
if '[GAC_CW_SPOT_ROWS] END' not in lines or any('[GAC_CW_SPOT_ROWS] ERROR' in line for line in lines):
raise ValueError('Spotlight capture did not complete')
rows = [json.loads(line.split(' ROW ', 1)[1]) for line in lines if '[GAC_CW_SPOT_ROWS] ROW ' in line]
count = [int(line.rsplit(' ', 1)[1]) for line in lines if line.startswith('[GAC_CW_SPOT_ROWS] BEGIN ')]
if count != [len(rows)] or len({r['ID'] for r in rows}) != len(rows):
raise ValueError('missing or duplicate Spotlight rows')
for row in rows:
if not row['ID'] or not isinstance(row['IsCarry'], bool) or not isinstance(row['IsOCEffective'], bool):
raise ValueError('invalid Spotlight identity/flags')
if any(type(v) is not int or v <= 0 for v in row['SuitableAvatarList']):
raise ValueError('invalid Spotlight role IDs')
if any(not isinstance(v, str) for v in row['EffectParamList']):
raise ValueError('fixed-point values must remain strings')
c = json.loads(a.catalog.read_text(encoding='utf-8-sig'))
result = dict(format_version=1, target_client_version=c['client_version'],
target_assembly_sha256=c['provenance']['game_assembly_sha256'],
source_capture_sha256=hashlib.sha256(raw).hexdigest(),
scope='Initialized handbook configurations only; this capture does not establish selection weights, reroll costs, grants, or effect execution.',
entries=sorted(rows, key=lambda r: r['ID']))
a.output.write_text(json.dumps(result, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
print(f'Exported {len(rows)} current Spotlight configurations')
if __name__ == '__main__':
main()