#!/usr/bin/env python3 """Export the active item-proto and recipe-derived 2000-stack coverage.""" import argparse,json,re,subprocess from pathlib import Path TYPES={'ITEM_USE','ITEM_AUTOUSE','ITEM_MATERIAL','ITEM_METIN','ITEM_RESOURCE','ITEM_BLEND','ITEM_EXTRACT'} def catalogue(proto,cube,schema): if not re.fullmatch('[A-Za-z0-9_]+',schema):raise ValueError('schema') ingredients=set() if cube.exists(): for line in cube.read_text(errors='replace').splitlines(): parts=line.split() if len(parts)>=3 and parts[0]=='item' and parts[1].isdigit():ingredients.add(int(parts[1])) query=' UNION '.join('SELECT vnum%d FROM `%s`.refine_proto WHERE vnum%d>0'%(i,schema,i) for i in range(5)) result=subprocess.run(['mysql','-N','-e',query],check=True,capture_output=True,text=True) ingredients.update(int(n) for n in result.stdout.split()) records=[] for line in proto.read_bytes().splitlines()[1:]: f=[s.decode('latin1') for s in line.split(b'\t')] if len(f)<7 or not re.fullmatch(r'\d+(?:~\d+)?',f[0]):continue span=[int(n) for n in f[0].split('~')];lo=span[0];hi=span[-1] stackable='ITEM_STACKABLE' in f[6] or 'STACKABLE' in f[6] anti='ANTI_STACK' in f[5] for vnum in range(lo,hi+1): eligible=stackable and not anti and (f[2] in TYPES or vnum in ingredients) if eligible:records.append(dict(vnum=vnum,type=f[2],old_limit=200,new_limit=2000,recipe_material=vnum in ingredients)) return dict(schema=schema,proto=str(proto),cube=str(cube),covered_items=len(records),items=records) if __name__=='__main__': p=argparse.ArgumentParser();p.add_argument('--proto',type=Path,required=True);p.add_argument('--cube',type=Path,required=True);p.add_argument('--schema',required=True);p.add_argument('--output',type=Path,required=True);a=p.parse_args() report=catalogue(a.proto,a.cube,a.schema);a.output.write_text(json.dumps(report,indent=2));print(json.dumps({'covered_items':report['covered_items'],'output':str(a.output)}))