86 lines
4.8 KiB
Python
86 lines
4.8 KiB
Python
"""Run the published Camelot import Lua and ordinary anchor cases. No game is launched."""
|
|
import argparse
|
|
import re
|
|
import subprocess
|
|
import tempfile
|
|
import xml.etree.ElementTree as ET
|
|
from pathlib import Path
|
|
|
|
from prep import compose
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
DIR = "blizzard_editmode"
|
|
MANAGER = ("RegisterSystemFrame", "GetRegisteredSystemFrame", "ImportLayoutFromDialog", "ImportLayout",
|
|
"MakeNewLayout", "SaveLayouts", "PrepareSystemsForSave", "ClearActiveChangesFlags",
|
|
"GetActiveLayoutInfo", "GetActiveLayoutSystemInfo", "UpdateSystem")
|
|
SYSTEM = ("OnSystemLoad", "SetScaleOverride", "IsInitialized", "IsInDefaultPosition", "PrepareForSave", "UpdateSystem", "ApplySystemAnchor")
|
|
|
|
|
|
def method(text, name):
|
|
return re.search('^function ' + re.escape(name) + r'\([^\n]*?\)\n.*?^end\s*$', text, re.M | re.S)[0]
|
|
|
|
|
|
def stage(addons, temp):
|
|
editmode = addons / DIR
|
|
manager = (editmode / "shared/editmodemanager.lua").read_text()
|
|
system = (editmode / "shared/editmodesystemtemplates.lua").read_text()
|
|
dialogs = (editmode / "shared/editmodedialogs.lua").read_text()
|
|
pieces = ["EditModeManagerFrameMixin={}; EditModeSystemMixin={}; EditModeBaseDialogMixin={}; EditModeImportLayoutDialogMixin={}"]
|
|
for name in ("callPrepareForSave", "clearActiveChangesFlag"):
|
|
pieces.append(re.search(r"^local function " + name + r"\([^\n]*\)\n.*?^end", manager, re.M | re.S)[0])
|
|
for text, mixin, functions in ((manager, "EditModeManagerFrameMixin", MANAGER),
|
|
(system, "EditModeSystemMixin", SYSTEM),
|
|
(dialogs, "EditModeBaseDialogMixin", ("SetLayoutInfo", "GetLayoutInfo")),
|
|
(dialogs, "EditModeImportLayoutDialogMixin", ("ProcessImportText", "OnImportTextChanged"))):
|
|
pieces.extend(method(text, mixin + ":" + name) for name in functions)
|
|
# The actual enum values come from the 70334 API descriptions.
|
|
preset = (editmode / "mainline/editmodepresetlayouts.lua").read_text()
|
|
types = set(re.findall(r'Enum\.(\w+)\.', preset)) | {"EditModeLayoutType", "EditModePresetLayouts", "InputDeviceInterfaceType"}
|
|
enum = {}
|
|
for doc in (addons / "blizzard_apidocumentationgenerated").glob("*.lua"):
|
|
for name, kind, value in re.findall(r'Name = "(\w+)", Type = "(\w+)", EnumValue = (-?\d+)', doc.read_text()):
|
|
if kind in types:
|
|
enum.setdefault(kind, {})[name] = int(value)
|
|
assert types == enum.keys(), types - enum.keys()
|
|
pieces.append("Enum={}")
|
|
for kind, fields in enum.items():
|
|
pieces.append(f'Enum.{kind}=' + '{' + ','.join(f'["{key}"]={val}' for key,val in fields.items()) + '}')
|
|
pieces.append(f'Enum.EditModePresetLayoutsMeta={{NumValues={len(enum["EditModePresetLayouts"])}}}')
|
|
(temp / "released.lua").write_text('\n'.join(pieces))
|
|
|
|
caps = ET.parse(addons / "blizzard_actionbar/camelot/mainmenubarendcaps.xml")
|
|
templates = ET.parse(editmode / "shared/editmodesystemtemplates.xml")
|
|
for child, index in (("LeftEndCap", "EndCapLeft"), ("RightEndCap", "EndCapRight")):
|
|
template = caps.find(f".//{{*}}Frame[@parentKey='{child}']").attrib["inherits"]
|
|
frame = templates.find(f".//{{*}}Frame[@name='{template}']")
|
|
field = frame.find("./{*}KeyValues/{*}KeyValue[@key='systemIndex']")
|
|
assert field.attrib["value"] == f"Enum.EditModeMainActionBarEndCapSystemIndices.{index}"
|
|
base = templates.find(f".//{{*}}Frame[@name='{frame.attrib['inherits']}']")
|
|
assert base.find("./{*}KeyValues/{*}KeyValue[@key='system']").attrib["value"] == "Enum.EditModeSystem.MainActionBarEndCap"
|
|
|
|
|
|
def verify(addons):
|
|
original = addons / DIR / "camelot/editmodeutil.lua"
|
|
with tempfile.TemporaryDirectory() as name:
|
|
temp = Path(name)
|
|
stage(addons, temp)
|
|
candidate = temp / "EditModeUtil.lua"
|
|
candidate.write_bytes(compose(original.read_bytes()))
|
|
for util, expected in ((original, False), (candidate, True)):
|
|
command = ['lua5.1', HERE / 'import.lua', temp / 'released.lua', addons / DIR, util, HERE.parents[1] / 'client_addons']
|
|
result = subprocess.run(command, capture_output=True, text=True)
|
|
if not expected:
|
|
if result.returncode == 0 or 'imported right end-cap anchor was replaced' not in result.stderr:
|
|
raise AssertionError(result.stdout + result.stderr)
|
|
print('Original lost the imported right end-cap anchor')
|
|
elif result.returncode:
|
|
raise AssertionError(result.stdout + result.stderr)
|
|
else:
|
|
print(result.stdout.strip())
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('addons', type=Path, help='decoded release interface/addons directory')
|
|
verify(parser.parse_args().addons)
|