28 lines
2.1 KiB
Python
28 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Stage only the two original AVA2 lock materials; the shared locale builder provides their client assets."""
|
|
import argparse,hashlib,importlib.util,json,shutil
|
|
from pathlib import Path
|
|
HERE=Path(__file__).resolve().parent
|
|
spec=importlib.util.spec_from_file_location('ava2_items',HERE.parent/'ava2-items/make_items.py')
|
|
m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m)
|
|
def prepare(ava,reader,out):
|
|
raw=m.server_proto(ava,'item_proto.txt');ids={50348:'属性锁定符',50349:'属性解锁符'}
|
|
source={int(c[0]):[x.decode('latin1') for x in c] for line in raw.splitlines() if len(c:=line.split(b'\t'))>=33 and c[0].isdigit() and int(c[0]) in ids}
|
|
dump=ava/'3. Source BIN/Tools/DumpProto/Release/item_proto.txt'
|
|
if not dump.is_file():dump=ava.parent/'3. Source BIN/Tools/DumpProto/Release/item_proto.txt'
|
|
for line in dump.read_bytes().splitlines():
|
|
c=line.split(b'\t')
|
|
if c[0].isdigit() and int(c[0]) in ids and int(c[0]) not in source:source[int(c[0])]=[x.decode('latin1') for x in c]
|
|
if set(source)!=set(ids):raise ValueError('AVA2 lock materials are missing')
|
|
out.mkdir(parents=True,exist_ok=True);rows=[];E=m.enums(reader)
|
|
for v,c in sorted(source.items()):
|
|
s,n,kept=m.convert(c,E,set(source))
|
|
if not kept or s[2:4]!=['ITEM_USE','USE_CHANGE_ATTRIBUTE']:raise ValueError('AVA2 lock material type changed')
|
|
s[1]=ids[v];rows.append('\t'.join(s).encode('gbk'))
|
|
(out/'items-server.tsv').write_bytes(b'\n'.join(rows)+b'\n')
|
|
shutil.copy2(HERE/'attr_lock.quest',out/'attr_lock.quest')
|
|
shutil.copy2(HERE/'install_quest.py',out/'install_quest.py')
|
|
(out/'source.json').write_text(json.dumps({'server_proto_sha256':hashlib.sha256(raw).hexdigest(),'client_proto_sha256':hashlib.sha256(dump.read_bytes()).hexdigest(),'items':ids},ensure_ascii=False,indent=2)+'\n')
|
|
if __name__=='__main__':
|
|
p=argparse.ArgumentParser(description=__doc__);p.add_argument('--ava',type=Path,required=True);p.add_argument('--reader',type=Path,required=True);p.add_argument('--output',type=Path,required=True);a=p.parse_args();prepare(a.ava,a.reader,a.output)
|