82 lines
3.6 KiB
Python
82 lines
3.6 KiB
Python
"""Exercise Camelot realm choice using locally decoded release UI (build 70334).
|
|
|
|
GW_TEST_CAMELOT_REALM_UI may point at a decoded interface/addons directory.
|
|
Otherwise use the project's release store, listfile and casc-tool if installed.
|
|
"""
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import xml.etree.ElementTree as ET
|
|
|
|
TESTS = Path(__file__).resolve().parent
|
|
PROJECT = TESTS.parents[1]
|
|
sys.path.insert(0, str(TESTS.parent / "ops"))
|
|
from source_realm_ui import refresh_release_district_adapter
|
|
NAV = "blizzard_characterselectnavbar"
|
|
GLUE = "blizzard_gluexml"
|
|
# IDs from the enUS 70334 release. Keep the native UI sources external.
|
|
FILE_IDS = (5613496, 6796721, 6796715, 7373118, 6796719, 8263017,
|
|
5614220, 8280381, 5612385, 8199120, 5612621, 5614237)
|
|
|
|
|
|
def required_frame(path, attribute, value):
|
|
matches = ET.parse(path).findall(f".//{{*}}Frame[@{attribute}='{value}']")
|
|
if len(matches) != 1:
|
|
raise ValueError(f"{path}: expected exactly one frame with {attribute}={value}")
|
|
return matches[0]
|
|
|
|
|
|
def run(library, lua):
|
|
toc = (library / NAV / (NAV + ".toc")).read_text(encoding="utf-8-sig")
|
|
entries = [" ".join(line.lower().split()) for line in toc.splitlines()]
|
|
for file in ("characterselectnavbar.lua", "characterselectnavtemplates.xml"):
|
|
assert f"[game]\\{file} [allowloadgametype camelot]" in entries, file
|
|
|
|
nav = required_frame(library / GLUE / "mainline/characterselect.xml", "parentKey", "NavBar")
|
|
child = required_frame(library / NAV / "camelot/characterselectnavtemplates.xml",
|
|
"name", nav.attrib["inherits"])
|
|
base = required_frame(library / NAV / "characterselectnavbar.xml", "name", child.attrib["inherits"])
|
|
assert base.attrib["mixin"] == "CharacterSelectNavBarMixin"
|
|
settings = {}
|
|
for frame in (base, child, nav):
|
|
for item in frame.findall("{*}KeyValues/{*}KeyValue"):
|
|
if item.attrib["type"] == "boolean":
|
|
settings[item.attrib["key"]] = item.attrib["value"]
|
|
source = library / GLUE / "mainline/superdistrict.lua"
|
|
with tempfile.TemporaryDirectory(prefix="camelot-district-") as directory:
|
|
candidate = Path(directory) / "SuperDistrict.lua"
|
|
candidate.write_bytes(refresh_release_district_adapter(source.read_bytes()))
|
|
subprocess.run([lua, TESTS / "source_realm_district_test.lua", candidate,
|
|
TESTS / "camelot_change_realm_test.lua", library,
|
|
settings["realmsButtonAvailable"], settings["superDistrictsButtonAvailable"]], check=True)
|
|
|
|
|
|
def main():
|
|
lua = sys.argv[1]
|
|
supplied = os.environ.get("GW_TEST_CAMELOT_REALM_UI")
|
|
if supplied:
|
|
run(Path(supplied), lua)
|
|
return 0
|
|
|
|
store = PROJECT / "release-20261127/OctoWoW"
|
|
tool = PROJECT / "tools/casc-tool/build/casc-tool"
|
|
names = PROJECT / "listfiles/community-listfile.csv"
|
|
if not (store.is_dir() and tool.is_file() and names.is_file()):
|
|
print("Build 70334 release assets unavailable. Set GW_TEST_CAMELOT_REALM_UI to the decoded interface/addons.")
|
|
return 77
|
|
with tempfile.TemporaryDirectory(prefix="camelot-realm-") as directory:
|
|
work = Path(directory)
|
|
ids = work / "ids.txt"
|
|
ids.write_text("".join(f"{value}\n" for value in FILE_IDS))
|
|
output = work / "release"
|
|
subprocess.run([tool, "extract-batch", "--from-list", ids, output, "--storage", store,
|
|
"--listfile", names, "--locale", "enus", "--strict-encrypted"], check=True)
|
|
run(output / "interface/addons", lua)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|