"""boss.py KEY "Name" ITEM STAGE[/alt]:COUNT...: registers a boss: bosses.json (appended), its 1% item and the Rebirth boss pool (itempools.json), COUNT entries in each named stage's pool (its alt's with /alt; a pool listing weight-1 bosses four times takes 4) and one in The Void's.""" import json, re, sys V = 'resources/data/versions/rebirth/' key, name, item, stages = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4:] p = V + 'bosses.json'; s = open(p).read() if f'"key": "{key}"' not in s: s = re.sub(r'(\n \{"key": [^\n]*\})\n \]', lambda m: m.group(1) + f',\n {{"key": "{key}", "name": "{name}"}}\n ]', s, count=1) open(p, 'w').write(s) p = V + 'itempools.json'; s = open(p).read() if f'"bosses": ["{key}"]' not in s: s = s.replace(' {"key": "rebirth_boss_pool"', f' {{"key": "{key}_{item}", "bosses": ["{key}"], "items": ["{item}"], "one_in": 100}},\n {{"key": "rebirth_boss_pool"', 1) s = re.sub(r'("key": "rebirth_boss_pool", "bosses": \[[^\]]*)\]', lambda m: m.group(1) + f', "{key}"]', s, count=1) open(p, 'w').write(s) p = V + 'stages.json'; s = open(p).read() def pool_add(start, count): """Adds count entries to the first bosses list at or after start (unless it names the boss already).""" global s m = re.compile(r'"bosses": \[([^\]]*)\]').search(s, start) if f'"{key}"' in m.group(1): return s = s[:m.end() - 1] + ''.join(f', "{key}"' for _ in range(count)) + s[m.end() - 1:] for spec in stages + ['the_void:1']: stage, count = spec.rsplit(':', 1) stage, _, alt = stage.partition('/') at = s.index(f'"key": "{stage}"') if alt: at = s.index('"alt": {', at) pool_add(at, int(count)) open(p, 'w').write(s) json.load(open(V + 'stages.json')); json.load(open(V + 'itempools.json')); json.load(open(V + 'bosses.json'))