Files

23 lines
2.6 KiB
Python

#!/usr/bin/env python3
"""Append native Zora/fireball art to the existing actor bank, preserving IDs."""
import hashlib,json
from extract_graphics import ROOT
from extract_start_room import write_json
from nes_object_graphics import descriptor,P
from validate_octorok_graphics import native_image
def prepare():
folder=ROOT/'assets/characters/octorok';p=folder/'asset.json';doc=json.loads(p.read_text());arts=[a for a in doc['artifacts'] if not a['artifact_id'].startswith('zora-')];start=max(a['index'] for a in arts)+1;specs={}
for i,frame in enumerate([0,1,2,3,8,9]):
info=descriptor(17,frame,True);specs[str(frame)]=info;im=native_image(info,True);path=folder/f'zora_{frame}.png';im.save(path);arts.append({'file':path.name,'index':start+i,'artifact_id':f'zora-{frame}','fingerprint':hashlib.sha256(path.read_bytes()).hexdigest()})
info=descriptor(85);specs['fireball']=info;path=folder/'zora_fireball.png';native_image(info,True).save(path);arts.append({'file':path.name,'index':start+6,'artifact_id':'zora-fireball','fingerprint':hashlib.sha256(path.read_bytes()).hexdigest()});doc['artifacts']=arts;write_json(p,doc)
hp=P.index(bytes.fromhex('06432531122481142242'));at=P.index(bytes.fromhex('080a1020100a80200fff1060100b0105010b'),65536,81920);times=list(P[at+6:at+12]);anim=list(P[at+12:at+18]);speeds=P.index(bytes.fromhex('70686058503c26100010263c5058606870'),65536,81920);qx=list(P[speeds:speeds+8])+[0];qy=list(P[speeds+8:speeds+17]);assert P[hp+8]&15==2
code='// Generated from native burrower timers, fireball speeds and executed descriptors.\n'
for name,values in [('z_times',times),('z_anim',anim),('z_qx',qx),('z_qy',qy)]:code+=f'declare global {name}: array<int> = ['+','.join(map(str,values))+'];\n'
code+='declare struct ZoraData() {\n fn timer(s: int) -> int { return z_times[s] else 0; }\n fn anim(s: int) -> int { return z_anim[s] else 1; }\n fn qx(s: int) -> int { return z_qx[s] else 0; }\n fn qy(s: int) -> int { return z_qy[s] else 0; }\n'
code+=f' fn glyph(frame: int) -> int {{ if frame==8 {{ return {start+4}; }} if frame==9 {{ return {start+5}; }} return {start}+frame; }}\n fn fireball() -> int {{ return {start+6}; }}\n}}\n'
(ROOT/'src/enemies/zora/data.generated.pbs').write_text(code)
write_json(ROOT/'extracted/zora/rom-data.json',{'descriptors':specs,'hp':2,'hp_table_prg':hp,'timers':times,'animation_timers':anim,'state_tables_prg':at,'qx':qx,'qy':qy,'fireball_table_prg':speeds,'actor_bank':11,'first_glyph':start,'water_tiles':[141,152],'fireball_damage':128,'magic_shield_slot':31,'room_kill_count':False,'scope':'First Zora encounter; no sound.'})
print('Zora art appended:',start,'through',start+6)
if __name__=='__main__':prepare()