Files
GaCy-GO/tools/export_ffgo_penalties.py
2026-10-28 18:54:43 +07:00

32 lines
1.3 KiB
Python

"""Export labelled reference penalty rules; never imports a saved run."""
import argparse
import hashlib
import json
from pathlib import Path
p = argparse.ArgumentParser(description=__doc__)
p.add_argument('--excel', type=Path, required=True)
p.add_argument('--catalog', type=Path, required=True)
p.add_argument('--binary-sha256', required=True)
p.add_argument('--output', type=Path, required=True)
a = p.parse_args()
if len(bytes.fromhex(a.binary_sha256)) != 32:
raise ValueError('Expected SHA256')
raw = a.excel.read_bytes()
c = json.loads(a.catalog.read_bytes())
fields = ('ID', 'ThresholdPosition', 'ThresholdFailPlayerHPPenalty',
'ThresholdPassBasicPlayerHPPenalty', 'ProgressPenaltyCoefficient')
rows = [{k: int(r.get(k, 0)) for k in fields}
for r in json.loads(raw)['grid_fight_penalty_rule']]
a.output.write_text(json.dumps({
'format_version': 1,
'target_client_version': c['client_version'],
'target_assembly_sha256': c['provenance']['game_assembly_sha256'],
'source_kind': 'reference-implementation; captured current rules take precedence',
'reference_executable_sha256': a.binary_sha256,
'excel_dump_sha256': hashlib.sha256(raw).hexdigest(),
'source_table': 'grid_fight_penalty_rule',
'penalty_rules': rows,
}, indent=2) + '\n', encoding='utf8')
print(f'Exported {len(rows)} reference penalties')