Add mobile touch UI and AVA2 biology system with server tools
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python3
|
||||
import importlib.util,json,re,subprocess,sys,tempfile
|
||||
from pathlib import Path
|
||||
ROOT=Path(__file__).resolve().parents[1]
|
||||
reference=Path(sys.argv[1]);template=ROOT/'tests/ava2_core_test.cpp'
|
||||
# Compare the generated 13-stage table with both upstream server and Python UI tables.
|
||||
spec=importlib.util.spec_from_file_location('import_ava2',ROOT/'import_ava2.py');module=importlib.util.module_from_spec(spec);spec.loader.exec_module(module)
|
||||
rows=module.extract(reference);catalog=json.loads((ROOT/'catalog.json').read_text())
|
||||
assert len(rows)==14 and len(catalog)==13
|
||||
for row,c in zip(rows[1:],catalog):
|
||||
assert row[:6]==[c['level'],c['material'],c['count'],c['cooldown'],c['chance'],c['stone']]
|
||||
ui=ROOT.parents[2]/'src/platform/ScriptLib/BiologScript.inc';source=ui.read_text();data=re.search(r'^CATALOG = (.*)$',source,re.M).group(1)
|
||||
import ast
|
||||
assert ast.literal_eval(data)=={c['index']:c for c in catalog}
|
||||
points=sorted({v for row in rows for v in row if isinstance(v,str)})
|
||||
raw=(reference/'cmd_general.cpp').read_bytes().decode('latin1').replace('\r','');start=raw.index('ACMD(do_bio)\n');end=raw.index('\n#endif',start)
|
||||
original=raw[start:end].replace('ACMD(do_bio)','static ACMD(reference_do_bio)')
|
||||
code=template.read_text().replace('POINT_ENUMS','enum {'+', '.join([points[0]+'=1']+points[1:]+['POINT_GOLD'])+'};').replace('REFERENCE_COMMAND',original)
|
||||
with tempfile.TemporaryDirectory(prefix='biolog-ava2-') as folder:
|
||||
folder=Path(folder);cpp=folder/'test.cpp';cpp.write_text(code)
|
||||
# Keep relative production include paths resolvable when compiling the generated source.
|
||||
cpp.write_text(cpp.read_text().replace('#include "../biolog_remote.h"','#include "'+str(ROOT/'biolog_remote.h')+'"'))
|
||||
subprocess.run(['c++','-std=c++17','-I'+str(ROOT/'tests'),str(cpp),'-o',str(folder/'test')],check=True)
|
||||
subprocess.run([str(folder/'test')],check=True)
|
||||
print('PASS: 13-stage catalog and embedded client table match extracted AVA2 server constants')
|
||||
Reference in New Issue
Block a user