Files
WoW-Hybrid-gateway/tests/source_spell_conversion_test.py

44 lines
2.9 KiB
Python

#!/usr/bin/env python3
import hashlib,json,os,shutil,struct,sys,tempfile
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1];sys.path[:0]=[str(ROOT/'ops'),str(ROOT/'ops/addon_source_authority')]
from octo_spell_presentation import presentation_rows
from convert_spells import PAIRS,source_pair,decoded
from turtle_data import DBC
from verify import verify
def digest(path):
with path.open('rb') as f:return hashlib.file_digest(f,'sha256').hexdigest()
def load(path):return json.loads(path.read_text())
# Source's signed base points plus base dice, not the raw unsigned DBC cell.
r=[0]*173;r[0]=59509;r[1]=2;r[6]=192;r[18]=1;r[30]=21;r[36]=1;r[61]=6;r[67]=1;r[76]=-6;r[82]=1;r[91]=198;r[120]=1;r[25]=101
values=presentation_rows(r,lambda x:'Reduced Critical Damage 5' if x else '',134400,{'SpellMisc':4000000,'SpellEffect':4000000,'SpellAuraOptions':4000000})
assert values['SpellEffect'][0]['EffectBasePointsF']==-5.0
assert values['SpellEffect'][0]['EffectAura']==198 and values['SpellMisc'][0]['SchoolMask']==4
assert not values['SpellAuraOptions'] and values['SpellName'][0]['ID']==59509
if os.environ.get('GW_SOURCE_SPELL_CONVERSION_ROOT'):
root=Path(os.environ['GW_SOURCE_SPELL_CONVERSION_ROOT']);manifest=load(root/'spell-manifest.json');source=Path(manifest['source']['file'])
assert digest(source)==manifest['source']['sha256'];dbc=DBC(source,173)
for i,ref in PAIRS.items():source_pair(dbc,i,ref)
original=dbc.by_id[59509];changed=list(original);changed[109]=123;dbc.by_id[59509]=changed
try:source_pair(dbc,59509,59507)
except ValueError:pass
else:raise AssertionError('Unreviewed trigger difference accepted')
dbc.by_id[59509]=original
for table,expected in manifest['tables'].items():
assert digest(root/'spell-db2'/(table+'.db2'))==expected
before=decoded(root/'spell-baseline'/(table+'.jsonl'));after=decoded(root/'native-spells'/(table+'.jsonl'))
assert all(after.get(i)==r for i,r in before.items())
new=[r for i,r in after.items() if i not in before];assert len(new)==7
if table=='SpellName':assert {r['ID']:r['Name_lang'] for r in new}=={i:dbc.string(dbc.by_id[i][120]) for i in PAIRS}
if table=='SpellEffect':
for row in new:
r=dbc.by_id[row['SpellID']];signed=lambda x:x-(1<<32) if x>=1<<31 else x
assert row['EffectBasePointsF']=={'f32_bits':struct.unpack('<I',struct.pack('<f',signed(r[76])+signed(r[67])))[0]}
assert row['EffectAura']==r[91] and row['EffectTriggerSpell']==r[109] and row['ImplicitTarget']==[r[82],r[85]]
assert len(load(root/'reviewed-dangling-slots.json'))==7
verify(root,root/'native-baseline',Path(os.environ['GW_ADDON_SOURCE_AUTHORITY_READER']),Path('/mnt/Games/@project/tools/WoWDBDefs/definitions'))
from content_candidate_rehearsal import rehearse
rehearse(root)
print('PASS Source presentation conversion, approved slot omissions, complete DB2 deltas, physical forward/inverse rehearsal')