From 58473a481cb5210608c2078f1a663b647babf819 Mon Sep 17 00:00:00 2001 From: Martin Konstantin Herrmann Date: Mon, 9 Nov 2026 17:41:48 +0100 Subject: [PATCH] Render atlases and fix sample icons in UI proof - Fix sample aura icons: Spell_Shadow_CurseOfTounges, INV_Misc_Herb_Felblossom - scripts/atlas_catalog.py generates tests/proof/atlases.lua from Wago atlas exports for the pinned Forever build (manifest in data/forever-atlases) - wowproof: BLP2 decoder, wago CASC file source, atlas table source; atlases drawn from their cropped sub-rect with later SetTexCoord mapped into it - Mock SetAtlas drops earlier texture coordinates like the client - CI verifies the atlas table; docs updated --- .github/workflows/tests.yml | 2 + AGENTS.md | 3 +- DEVELOPMENT.md | 21 +- UnitFrames/Units/Definitions.lua | 4 +- data/forever-atlases/manifest.json | 24 ++ scripts/atlas_catalog.py | 221 ++++++++++++++++++ scripts/update-blizzard-source.sh | 1 + tests/mock/wow.lua | 4 +- tests/proof/atlases.lua | 65 ++++++ tests/proof/setup.lua | 13 +- .../spec/auras/aura_category_filters_spec.lua | 2 +- tests/spec/contract/atlas_catalog_spec.lua | 5 + wowproof/README.md | 29 ++- wowproof/adapters/mock_state.lua | 5 +- wowproof/blp.lua | 151 ++++++++++++ wowproof/init.lua | 34 +++ wowproof/paint.lua | 46 +++- wowproof/raster.lua | 46 ++++ wowproof/sources/atlas_table.lua | 8 + wowproof/sources/wago_casc.lua | 32 +++ wowproof/sources/wow_ui_textures.lua | 25 +- wowproof/spec/blp_spec.lua | 56 +++++ wowproof/spec/package_spec.lua | 7 + wowproof/spec/paint_spec.lua | 22 ++ wowproof/spec/sources_spec.lua | 22 ++ 25 files changed, 799 insertions(+), 49 deletions(-) create mode 100644 data/forever-atlases/manifest.json create mode 100644 scripts/atlas_catalog.py create mode 100644 tests/proof/atlases.lua create mode 100644 tests/spec/contract/atlas_catalog_spec.lua create mode 100644 wowproof/blp.lua create mode 100644 wowproof/sources/atlas_table.lua create mode 100644 wowproof/sources/wago_casc.lua create mode 100644 wowproof/spec/blp_spec.lua diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 35e8b3c..6eb60af 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,6 +35,8 @@ jobs: persist-credentials: false - name: Verify the generated spell catalogue against pinned exports run: python3 -B scripts/spell_catalog.py --fetch --check + - name: Verify the generated proof atlas table against pinned exports + run: python3 -B scripts/atlas_catalog.py --fetch --check - name: Run all tests and addon syntax checks run: bash scripts/run-tests.sh --times -j - name: Cache Blizzard interface art for UI proof diff --git a/AGENTS.md b/AGENTS.md index 05a4984..a73cf3f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -12,6 +12,7 @@ - `UnitFrames/Core/`: namespace/bootstrap, schema, AceDB configuration, theme, media, colours and text formats. Core Lua files receive `local _, ns = ...`; the public `UnitFrames` handle exposes that namespace to companion addons. - `UnitFrames/Tracking/`: data-only DoT damage estimates (tracking ported from DoesItDie, MIT). `DotSpells` reads generated numeric metadata, never descriptions. `ns.DotTracker` runs only while `Acquire`d on the exact catalogue client build, checks player-known spell IDs, keys active DoTs by generated family and learns ticks per rank. It matches `UNIT_COMBAT` on target/focus, fires `DotsChanged(key)` and fills reused lists through `Breakdown`. In combat `UNIT_COMBAT` amounts are secret: those hits match on school and rhythm alone (never drop them, or every DoT looks resisted) and are tallied per spell; on `PLAYER_REGEN_ENABLED` the `C_DamageMeter` per-spell totals, minus the generated `directPoints` upfront hit, become weighted average ticks. Fights with unseen ticks, several combo-point sizes or a dominant upfront hit are not learned. Learned tick sizes and weights live in AceDB `global`. +- `tests/proof/atlases.lua` is generated by `python3 -B scripts/atlas_catalog.py` from Wago atlas exports for the same pinned Forever build (manifest in `data/forever-atlases/`). Regenerate it after adding a `SetAtlas` call, so UI proof draws the atlas. - `Tracking/DotCatalog.lua` is generated by `python3 -B scripts/spell_catalog.py` from checksum-verified Wago exports cached under ignored `examples/forever-spells//`. Only the manifest (`data/forever-spells/manifest.json`), generated Lua and small native-record fixtures are tracked. It must match the exact Forever UI-source build/commit in both workflows and the TOC interface. `scripts/update-blizzard-source.sh` refreshes both sources; `--fetch --check` populates a fresh cache and validates regeneration in CI. Ordinary tests use `--check-pin` and the small fixtures offline. The ignored `catalog.json` audits periodic candidates and exclusions; CI uploads it as an artifact. Channels are excluded. Runtime only accepts player-known spells. Combo builders, finishers, rank families and projectile flags are generated. Agony's uneven shape remains an explicit family-ID exception in `DotSpells`; baseline damage is unmodified client data until ticks are learned. - Pending DoT damage: `Components/PendingDamage.lua` is owned by Bar (`spec.pendingDamage`, health rows) like Overheal; the `pendingDamage` frame driver binds `UF_PendingDamage` (Elements.lua), and the health `PostUpdate` (`ufHealthHooks`) gives it the secret scale and current health. - `UnitFrames/Components/`: reusable visual building blocks. Keep them independent of oUF bindings; their configuration and data APIs also serve previews. `UnitFrame` exposes rows and optional parts through `GetRow(key)`/`GetPart(key)` and the `Rows()`/`Parts()` iterators; add a part to `UnitFrame.PARTS` rather than adding per-part getters. Ready-check state lives in the `ReadyCheck` presenter (`GetReadyCheck()`), which also owns its settings schema. @@ -102,7 +103,7 @@ luajit tests/run.lua workbench -t "preview" Every change that can affect what a frame, preview or Workbench panel looks like ships with UI proof rendered by `wowproof`: in the pull request and, when working in Beluga, in the chat and on the task. 1. Pick the scenarios in `tests/proof/units.lua` and `tests/proof/workbench.lua` that show the change. When none does (a new setting, state or layout), add one: a name plus a `build` that configures through `Config:SetUnitValue` and feeds sample values. Prefer one scenario per state the change touches (like `player-idle` beside `player`) over one busy frame. -2. Render and look at them with `bash scripts/proof.sh ` before claiming the change works. Dashed placeholders mean missing art, an atlas or a portrait model, not a bug; mention them if they hide the change. +2. Render and look at them with `bash scripts/proof.sh ` before claiming the change works. Dashed placeholders mean missing art, an atlas the generated table lacks or a portrait model, not a bug; mention them if they hide the change. 3. When opening or updating the pull request, run `bash scripts/proof-publish.sh --out .beluga/scratch/proof `. It renders the scenarios, commits the PNGs to the orphan `ui-proof` branch under `/` (it never touches the working tree or the current branch) and prints a `### UI proof` Markdown section with images pinned to that commit. Paste that section into the PR body (`gh pr create --body-file` or `gh pr edit --body-file`). Re-run it after visual changes in review; old links keep showing the earlier images. `--dry-run` skips the push. 4. In Beluga, show the same PNGs in the answer as Markdown images with their absolute paths under `.beluga/scratch/proof/`, and attach each one to the worktree's task with `task_attach_proof` (kind `image`). 5. Proof shows mocked rendering only. Still list what needs in-game verification (see Verification above): combat, secret values, taint, Edit Mode and live unit changes. diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 7385c10..a68e72c 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -264,9 +264,28 @@ commit that art. `UF_PROOF_ART` picks another cache folder, and `UF_PROOF_ART_FETCH=0` stays offline. Set `GH_TOKEN` or `GITHUB_TOKEN` if GitHub's API rate limit bites. +Atlases (`SetAtlas`) come from `tests/proof/atlases.lua`, which +`scripts/atlas_catalog.py` generates from Wago's `UiTextureAtlas`, +`UiTextureAtlasMember` and `UiTextureAtlasElement` exports for the pinned +Forever build. It keeps only the atlases the addon and oUF elements name: dashed +string literals in files that mention atlases, plus `"prefix-" .. value` +concatenations. Where an atlas has several members, it takes the 1x one and +prefers Forever's `-c60` variant. The sheets are downloaded by file ID from +Wago for the same build into `.proof-art/casc-/`. Don't edit the +generated table: + +```sh +python3 -B scripts/atlas_catalog.py --update # fetch exports for the pinned build and regenerate +python3 -B scripts/atlas_catalog.py # regenerate from the cached exports +python3 -B scripts/atlas_catalog.py --fetch --check # what CI runs +``` + +Regenerate after adding a `SetAtlas` call. A name the table lacks draws as a +placeholder. + Still drawn as dashed placeholders: - art the mirror lacks, listed in `.proof-art/missing-.txt` -- atlases (`SetAtlas`), which need Blizzard's atlas table +- atlases the generated table lacks - portrait models ### Pull request checks diff --git a/UnitFrames/Units/Definitions.lua b/UnitFrames/Units/Definitions.lua index bb6541f..3a643d4 100644 --- a/UnitFrames/Units/Definitions.lua +++ b/UnitFrames/Units/Definitions.lua @@ -345,14 +345,14 @@ Units.SAMPLE = { { icon = [[Interface\Icons\Spell_Nature_Rejuvenation]], duration = 12, remaining = 5, sourceUnit = "party1", isRaidInCombat = true }, { icon = [[Interface\Icons\Spell_Nature_ResistNature]], duration = 20, remaining = 14, sourceUnit = "party1" }, { icon = [[Interface\Icons\Spell_Holy_PowerWordShield]], duration = 30, remaining = 21, sourceUnit = "player" }, - { icon = [[Interface\Icons\Spell_Nature_LifeBloom]], duration = 15, remaining = 9, applications = 3, sourceUnit = "player", isRaidInCombat = true }, + { icon = [[Interface\Icons\INV_Misc_Herb_Felblossom]], duration = 15, remaining = 9, applications = 3, sourceUnit = "player", isRaidInCombat = true }, { icon = [[Interface\Icons\Spell_Nature_Regeneration]], duration = 0, sourceUnit = "player", isRaid = true }, { icon = [[Interface\Icons\Spell_Holy_DivineIntervention]], duration = 8, remaining = 5, sourceUnit = "player", isBigDefensive = true, isImportant = true }, { icon = [[Interface\Icons\Spell_Holy_SealOfProtection]], duration = 10, remaining = 4, sourceUnit = "party1", isExternalDefensive = true }, }, debuffs = { { icon = [[Interface\Icons\Spell_Frost_FrostBolt02]], duration = 15, remaining = 7, dispelName = "Magic", sourceUnit = "player", isRaid = true }, - { icon = [[Interface\Icons\Spell_Shadow_CurseOfTongues]], duration = 24, remaining = 18, dispelName = "Curse", sourceUnit = "party1", isRaid = true }, + { icon = [[Interface\Icons\Spell_Shadow_CurseOfTounges]], duration = 24, remaining = 18, dispelName = "Curse", sourceUnit = "party1", isRaid = true }, { icon = [[Interface\Icons\Spell_Shadow_AbominationExplosion]], duration = 20, remaining = 13, dispelName = "Disease", applications = 2, sourceUnit = "party1", isRaid = true }, { icon = [[Interface\Icons\Spell_Nature_CorrosiveBreath]], duration = 12, remaining = 6, dispelName = "Poison", applications = 4, sourceUnit = "player", isRaid = true }, { icon = [[Interface\Icons\Ability_Gouge]], duration = 15, remaining = 11, sourceUnit = "party1", isCrowdControl = true }, diff --git a/data/forever-atlases/manifest.json b/data/forever-atlases/manifest.json new file mode 100644 index 0000000..fd16367 --- /dev/null +++ b/data/forever-atlases/manifest.json @@ -0,0 +1,24 @@ +{ + "build": "1.60.1.70862", + "format": 1, + "tables": { + "UiTextureAtlas": { + "filename": "UiTextureAtlas.1.60.1.70862.csv", + "rows": 2826, + "sha256": "a53e784e29c3a42d4a991e843fa1908d15f1fc381c66ac4ecfc508c3b7d19041", + "url": "https://wago.tools/db2/UiTextureAtlas/csv?build=1.60.1.70862&locale=enUS" + }, + "UiTextureAtlasElement": { + "filename": "UiTextureAtlasElement.1.60.1.70862.csv", + "rows": 20817, + "sha256": "d5b5244ceefcde365bbdcf925104ddf848ce35554bc182b7d9e06071abc7d262", + "url": "https://wago.tools/db2/UiTextureAtlasElement/csv?build=1.60.1.70862&locale=enUS" + }, + "UiTextureAtlasMember": { + "filename": "UiTextureAtlasMember.1.60.1.70862.csv", + "rows": 20685, + "sha256": "000fe3517bb7600aeee97b4465e9c721accd6914dde6ba079ebe00a6e2562d6b", + "url": "https://wago.tools/db2/UiTextureAtlasMember/csv?build=1.60.1.70862&locale=enUS" + } + } +} diff --git a/scripts/atlas_catalog.py b/scripts/atlas_catalog.py new file mode 100644 index 0000000..acc6de8 --- /dev/null +++ b/scripts/atlas_catalog.py @@ -0,0 +1,221 @@ +import argparse +import csv +import gzip +import io +import json +from pathlib import Path +import re +import subprocess +import sys +import tempfile +from collections import defaultdict + +from spell_catalog import canonical, digest, pinned_source, validate_download + + +ROOT = Path(__file__).resolve().parents[1] +DATA = ROOT / "data/forever-atlases" +CACHE = ROOT / "examples/forever-atlases" +OUTPUT = ROOT / "tests/proof/atlases.lua" +SOURCE_GLOBS = ("UnitFrames*/**/*.lua", "UnitFrames/Libs/oUF/elements/*.lua") +TABLES = { + "UiTextureAtlas": {"ID", "FileDataID", "AtlasWidth", "AtlasHeight"}, + "UiTextureAtlasMember": {"ID", "CommittedName", "UiTextureAtlasID", "Width", "Height", "CommittedLeft", "CommittedRight", "CommittedTop", "CommittedBottom", "UiTextureAtlasElementID", "CommittedFlags"}, + "UiTextureAtlasElement": {"ID", "Name"}, +} +TILES_VERTICALLY, TILES_HORIZONTALLY = 2, 4 +LITERAL = re.compile(r"""(["'])([^"'\s\\]*-[^"'\s\\]*)\1""") +CONCATENATION = re.compile(r"""(["'])([^"'\s\\]+-)\1\s*\.\.\s*[\w.:\[\]()]+(?:\s*\.\.\s*(["'])([^"'\s\\]*)\3)?""") + + +def table_url(name, build): + return f"https://wago.tools/db2/{name}/csv?build={build}&locale=enUS" + + +def parse_table(name, raw): + reader = csv.DictReader(io.StringIO(raw.decode("utf-8-sig"))) + missing = TABLES[name] - set(reader.fieldnames or []) + if missing: + raise ValueError(f"{name}: missing columns {sorted(missing)}") + rows = list(reader) + ids = [int(row["ID"]) for row in rows] + if not rows or len(ids) != len(set(ids)): + raise ValueError(f"{name}: empty table or duplicate IDs") + return rows + + +def download(pin): + tables, records, compressed = {}, {}, {} + for name in TABLES: + url = table_url(name, pin["build"]) + with tempfile.TemporaryDirectory() as directory: + headers = Path(directory) / "headers" + raw = subprocess.check_output(["curl", "--fail", "--silent", "--show-error", "--location", "--max-time", "90", "--dump-header", str(headers), url]) + validate_download(name, pin["build"], headers.read_text()) + tables[name] = parse_table(name, raw) + compressed[name] = gzip.compress(raw, mtime=0) + records[name] = {"url": url, "filename": f"{name}.{pin['build']}.csv", "sha256": digest(raw), "rows": len(tables[name])} + print(f"Fetched {name}: {len(tables[name])} records", file=sys.stderr) + return tables, {"build": pin["build"], "format": 1, "tables": records}, compressed + + +def read_manifest(pin): + manifest = json.loads((DATA / "manifest.json").read_text()) + if manifest.get("format") != 1 or manifest.get("build") != pin["build"]: + raise ValueError("atlas snapshot does not match the pinned Forever build; run --update") + if set(manifest["tables"]) != set(TABLES): + raise ValueError("atlas snapshot table set changed; run --update") + for name in TABLES: + record = manifest["tables"][name] + if record["url"] != table_url(name, pin["build"]) or record.get("filename") != f"{name}.{pin['build']}.csv": + raise ValueError(f"{name}: source does not match the pinned build") + if not re.fullmatch(r"[0-9a-f]{64}", record["sha256"]) or record["rows"] <= 0: + raise ValueError(f"{name}: invalid checksum or row count") + return manifest + + +def read_snapshot(pin): + manifest = read_manifest(pin) + tables = {} + for name in TABLES: + record = manifest["tables"][name] + raw = gzip.decompress((CACHE / pin["build"] / f"{name}.csv.gz").read_bytes()) + if digest(raw) != record["sha256"]: + raise ValueError(f"{name}: checksum mismatch") + tables[name] = parse_table(name, raw) + if len(tables[name]) != record["rows"]: + raise ValueError(f"{name}: row count mismatch") + return tables, manifest + + +def write_cache(pin, compressed): + directory = CACHE / pin["build"] + directory.mkdir(parents=True, exist_ok=True) + for name, content in compressed.items(): + (directory / f"{name}.csv.gz").write_bytes(content) + + +def source_files(root=ROOT): + if not (root / "UnitFrames/Libs/oUF/elements").is_dir(): + raise ValueError("oUF is missing; run scripts/setup-test-libs.sh first") + files = set() + for pattern in SOURCE_GLOBS: + for path in root.glob(pattern): + relative = path.relative_to(root).as_posix() + if "/Libs/" not in relative or relative.startswith("UnitFrames/Libs/oUF/elements/"): + files.add(path) + return sorted(files) + + +def atlas_uses(root=ROOT): + literals, patterns = set(), set() + for path in source_files(root): + text = path.read_text(encoding="utf-8") + if not re.search("atlas", text, re.I): + continue + literals.update(match[2].lower() for match in LITERAL.finditer(text)) + for match in CONCATENATION.finditer(text): + patterns.add(re.escape(match[2].lower()) + r"[a-z]+" + re.escape((match[4] or "").lower())) + return literals, re.compile("|".join(sorted(patterns))) if patterns else None + + +def preferred_member(members): + def rank(member): + name = member["CommittedName"].lower() + return (name.endswith("-2x"), not name.endswith("-c60"), int(member["ID"])) + return min(members, key=rank) + + +def compile_atlases(tables, root=ROOT): + atlases = {row["ID"]: row for row in tables["UiTextureAtlas"]} + members = defaultdict(list) + for row in tables["UiTextureAtlasMember"]: + members[row["UiTextureAtlasElementID"]].append(row) + literals, pattern = atlas_uses(root) + selected = {} + for element in tables["UiTextureAtlasElement"]: + name = element["Name"] + lower = name.lower() + if not members[element["ID"]] or (lower not in literals and not (pattern and pattern.fullmatch(lower))): + continue + member = preferred_member(members[element["ID"]]) + atlas = atlases[member["UiTextureAtlasID"]] + width, height = int(atlas["AtlasWidth"]), int(atlas["AtlasHeight"]) + flags = int(member["CommittedFlags"]) + selected[name] = { + "file": int(atlas["FileDataID"]), + "width": int(member["Width"]), + "height": int(member["Height"]), + "left": int(member["CommittedLeft"]) / width, + "right": int(member["CommittedRight"]) / width, + "top": int(member["CommittedTop"]) / height, + "bottom": int(member["CommittedBottom"]) / height, + "tilesH": bool(flags & TILES_HORIZONTALLY), + "tilesV": bool(flags & TILES_VERTICALLY), + } + if not selected: + raise ValueError("no atlas used by the addon was found in the client tables") + return selected + + +def lua_atlases(atlases, build): + lines = ["return {", f'\tbuild = "{build}",', "\tatlases = {"] + for name in sorted(atlases, key=str.lower): + info = atlases[name] + fields = [f'file = {info["file"]}', f'width = {info["width"]}', f'height = {info["height"]}'] + fields += [f"{key} = {info[key]:.12g}" for key in ("left", "right", "top", "bottom")] + fields += [f'{key} = {"true" if info[key] else "false"}' for key in ("tilesH", "tilesV")] + lines.append(f'\t\t["{name}"] = {{ ' + ", ".join(fields) + " },") + return "\n".join(lines + ["\t},", "}", ""]) + + +def main(): + global CACHE + parser = argparse.ArgumentParser() + parser.add_argument("--update", action="store_true") + parser.add_argument("--check", action="store_true") + parser.add_argument("--fetch", action="store_true") + parser.add_argument("--check-pin", action="store_true") + parser.add_argument("--cache", type=Path, default=CACHE) + args = parser.parse_args() + CACHE = args.cache.resolve() + if args.update and (args.check or args.fetch or args.check_pin): + parser.error("--update cannot be combined with validation or --fetch") + if args.check_pin and (args.check or args.fetch): + parser.error("--check-pin cannot be combined with --check or --fetch") + pin = pinned_source() + if args.update: + tables, manifest, compressed = download(pin) + else: + manifest = read_manifest(pin) + if args.check_pin: + if f'build = "{pin["build"]}"' not in OUTPUT.read_text(): + raise ValueError("generated atlas table build does not match the source pin") + print(f'Forever {pin["build"]}: atlas table pin verified') + return + if args.fetch: + tables, fetched, compressed = download(pin) + if fetched != manifest: + raise ValueError("downloaded tables do not match the committed checksums; review with --update") + write_cache(pin, compressed) + else: + tables, manifest = read_snapshot(pin) + atlases = compile_atlases(tables) + output = lua_atlases(atlases, pin["build"]) + if args.check: + if not OUTPUT.exists() or OUTPUT.read_text() != output: + raise ValueError(f"stale generated artifact: {OUTPUT.relative_to(ROOT)}") + else: + if args.update: + DATA.mkdir(parents=True, exist_ok=True) + write_cache(pin, compressed) + (DATA / "manifest.json").write_text(canonical(manifest)) + OUTPUT.write_text(output) + print(f'Forever {pin["build"]}: {len(atlases)} atlases') + + +if __name__ == "__main__": + try: + main() + except (ValueError, OSError, subprocess.CalledProcessError) as error: + sys.exit(str(error)) diff --git a/scripts/update-blizzard-source.sh b/scripts/update-blizzard-source.sh index 111db6e..92d0752 100644 --- a/scripts/update-blizzard-source.sh +++ b/scripts/update-blizzard-source.sh @@ -34,4 +34,5 @@ for workflow in tests release; do done (cd "$repo_dir" && luajit scripts/api-snapshot.lua "$source_dir") python3 -B "$repo_dir/scripts/spell_catalog.py" --update --source "$source_dir" +python3 -B "$repo_dir/scripts/atlas_catalog.py" --update echo "Pinned wow-ui-source $commit (Forever $version)" diff --git a/tests/mock/wow.lua b/tests/mock/wow.lua index 13408e3..799a7e0 100644 --- a/tests/mock/wow.lua +++ b/tests/mock/wow.lua @@ -547,11 +547,13 @@ end function Methods:GetTexture() return self.__state.texture end function Methods:SetVertexColor(r, g, b, a) self.__state.vertexColor = { r, g, b, a } end function Methods:SetColorTexture(r, g, b, a) self.__state.colorTexture = { r, g, b, a } end --- Like the client, the texture then reports the atlas's file. +-- Like the client, the texture then reports the atlas's file and drops +-- earlier texture coordinates: the atlas brings its own sub-rectangle. function Methods:SetAtlas(atlas, useAtlasSize) Record(self, "SetAtlas", atlas, useAtlasSize) self.__state.atlas = atlas self.__state.texture = "atlas:" .. tostring(atlas) + self.__state.texCoords = nil end -- FontString diff --git a/tests/proof/atlases.lua b/tests/proof/atlases.lua new file mode 100644 index 0000000..d6783b3 --- /dev/null +++ b/tests/proof/atlases.lua @@ -0,0 +1,65 @@ +return { + build = "1.60.1.70862", + atlases = { + ["classicon-deathknight"] = { file = 1662186, width = 128, height = 128, left = 0.00048828125, right = 0.06298828125, top = 0.0009765625, bottom = 0.1259765625, tilesH = false, tilesV = false }, + ["classicon-demonhunter"] = { file = 1662186, width = 128, height = 128, left = 0.00048828125, right = 0.06298828125, top = 0.1279296875, bottom = 0.2529296875, tilesH = false, tilesV = false }, + ["classicon-druid"] = { file = 1662186, width = 128, height = 128, left = 0.00048828125, right = 0.06298828125, top = 0.2548828125, bottom = 0.3798828125, tilesH = false, tilesV = false }, + ["classicon-evoker"] = { file = 1662186, width = 128, height = 128, left = 0.00048828125, right = 0.06298828125, top = 0.3818359375, bottom = 0.5068359375, tilesH = false, tilesV = false }, + ["classicon-hunter"] = { file = 1662186, width = 128, height = 128, left = 0.00048828125, right = 0.06298828125, top = 0.5087890625, bottom = 0.6337890625, tilesH = false, tilesV = false }, + ["classicon-mage"] = { file = 1662186, width = 128, height = 128, left = 0.00048828125, right = 0.06298828125, top = 0.6357421875, bottom = 0.7607421875, tilesH = false, tilesV = false }, + ["classicon-monk"] = { file = 1662186, width = 128, height = 128, left = 0.00048828125, right = 0.06298828125, top = 0.7626953125, bottom = 0.8876953125, tilesH = false, tilesV = false }, + ["classicon-paladin"] = { file = 1662186, width = 128, height = 128, left = 0.06396484375, right = 0.12646484375, top = 0.0009765625, bottom = 0.1259765625, tilesH = false, tilesV = false }, + ["classicon-priest"] = { file = 1662186, width = 128, height = 128, left = 0.06396484375, right = 0.12646484375, top = 0.1279296875, bottom = 0.2529296875, tilesH = false, tilesV = false }, + ["classicon-rogue"] = { file = 1662186, width = 128, height = 128, left = 0.06396484375, right = 0.12646484375, top = 0.2548828125, bottom = 0.3798828125, tilesH = false, tilesV = false }, + ["classicon-shaman"] = { file = 1662186, width = 128, height = 128, left = 0.06396484375, right = 0.12646484375, top = 0.3818359375, bottom = 0.5068359375, tilesH = false, tilesV = false }, + ["classicon-warlock"] = { file = 1662186, width = 128, height = 128, left = 0.06396484375, right = 0.12646484375, top = 0.5087890625, bottom = 0.6337890625, tilesH = false, tilesV = false }, + ["classicon-warrior"] = { file = 1662186, width = 128, height = 128, left = 0.06396484375, right = 0.12646484375, top = 0.6357421875, bottom = 0.7607421875, tilesH = false, tilesV = false }, + ["honorsystem-portrait-alliance"] = { file = 1250929, width = 50, height = 52, left = 0.0009765625, right = 0.0498046875, top = 0.763671875, bottom = 0.865234375, tilesH = false, tilesV = false }, + ["honorsystem-portrait-horde"] = { file = 1250929, width = 50, height = 52, left = 0.0009765625, right = 0.0498046875, top = 0.869140625, bottom = 0.970703125, tilesH = false, tilesV = false }, + ["honorsystem-portrait-neutral"] = { file = 1250929, width = 50, height = 52, left = 0.0517578125, right = 0.1005859375, top = 0.763671875, bottom = 0.865234375, tilesH = false, tilesV = false }, + ["nameplates-icon-bounty-alliance"] = { file = 1300837, width = 21, height = 20, left = 0.13671875, right = 0.21875, top = 0.88671875, bottom = 0.96484375, tilesH = false, tilesV = false }, + ["nameplates-icon-bounty-horde"] = { file = 1300837, width = 21, height = 20, left = 0.24609375, right = 0.328125, top = 0.4375, bottom = 0.515625, tilesH = false, tilesV = false }, + ["nameplates-icon-cart-alliance"] = { file = 1300837, width = 32, height = 32, left = 0.00390625, right = 0.12890625, top = 0.4375, bottom = 0.5625, tilesH = false, tilesV = false }, + ["nameplates-icon-cart-horde"] = { file = 1300837, width = 32, height = 32, left = 0.00390625, right = 0.12890625, top = 0.5703125, bottom = 0.6953125, tilesH = false, tilesV = false }, + ["nameplates-icon-elite-gold"] = { file = 1300837, width = 80, height = 80, left = 0.00390625, right = 0.31640625, top = 0.00390625, bottom = 0.31640625, tilesH = false, tilesV = false }, + ["nameplates-icon-elite-silver"] = { file = 1300837, width = 80, height = 80, left = 0.32421875, right = 0.63671875, top = 0.00390625, bottom = 0.31640625, tilesH = false, tilesV = false }, + ["nameplates-icon-flag-alliance"] = { file = 1300837, width = 18, height = 18, left = 0.24609375, right = 0.31640625, top = 0.5234375, bottom = 0.59375, tilesH = false, tilesV = false }, + ["nameplates-icon-flag-horde"] = { file = 1300837, width = 18, height = 18, left = 0.24609375, right = 0.31640625, top = 0.6015625, bottom = 0.671875, tilesH = false, tilesV = false }, + ["nameplates-icon-flag-neutral"] = { file = 1300837, width = 18, height = 18, left = 0.24609375, right = 0.31640625, top = 0.6796875, bottom = 0.75, tilesH = false, tilesV = false }, + ["nameplates-icon-orb-blue"] = { file = 1300837, width = 26, height = 26, left = 0.00390625, right = 0.10546875, top = 0.703125, bottom = 0.8046875, tilesH = false, tilesV = false }, + ["nameplates-icon-orb-green"] = { file = 1300837, width = 26, height = 26, left = 0.00390625, right = 0.10546875, top = 0.8125, bottom = 0.9140625, tilesH = false, tilesV = false }, + ["nameplates-icon-orb-orange"] = { file = 1300837, width = 26, height = 26, left = 0.13671875, right = 0.23828125, top = 0.4375, bottom = 0.5390625, tilesH = false, tilesV = false }, + ["nameplates-icon-orb-purple"] = { file = 1300837, width = 26, height = 26, left = 0.13671875, right = 0.23828125, top = 0.546875, bottom = 0.6484375, tilesH = false, tilesV = false }, + ["RaidFrame-AgroFrame"] = { file = 7526019, width = 70, height = 34, left = 0.00390625, right = 0.27734375, top = 0.0078125, bottom = 0.2734375, tilesH = false, tilesV = false }, + ["RaidFrame-Icon-MainAssist"] = { file = 7526019, width = 21, height = 21, left = 0.8125, right = 0.89453125, top = 0.2890625, bottom = 0.453125, tilesH = false, tilesV = false }, + ["RaidFrame-Icon-MainTank"] = { file = 7526019, width = 21, height = 21, left = 0.90234375, right = 0.984375, top = 0.2890625, bottom = 0.453125, tilesH = false, tilesV = false }, + ["RaidFrame-Icon-Phasing"] = { file = 7526019, width = 44, height = 44, left = 0.18359375, right = 0.35546875, top = 0.2890625, bottom = 0.6328125, tilesH = false, tilesV = false }, + ["RaidFrame-Icon-Rez"] = { file = 7526019, width = 44, height = 44, left = 0.18359375, right = 0.35546875, top = 0.6484375, bottom = 0.9921875, tilesH = false, tilesV = false }, + ["RaidFrame-Icon-SummonAccepted"] = { file = 7526019, width = 44, height = 44, left = 0.36328125, right = 0.53515625, top = 0.2890625, bottom = 0.6328125, tilesH = false, tilesV = false }, + ["RaidFrame-Icon-SummonDeclined"] = { file = 7526019, width = 44, height = 44, left = 0.36328125, right = 0.53515625, top = 0.6484375, bottom = 0.9921875, tilesH = false, tilesV = false }, + ["RaidFrame-Icon-SummonPending"] = { file = 7526019, width = 44, height = 44, left = 0.54296875, right = 0.71484375, top = 0.2890625, bottom = 0.6328125, tilesH = false, tilesV = false }, + ["RaidFrame-Shield-Overshield"] = { file = 7526019, width = 16, height = 32, left = 0.91796875, right = 0.98046875, top = 0.0078125, bottom = 0.2578125, tilesH = false, tilesV = false }, + ["UI-HUD-ActionBar-Proc-Loop-Flipbook"] = { file = 5199404, width = 333, height = 400, left = 0.41259765625, right = 0.5751953125, top = 0.0009765625, bottom = 0.3916015625, tilesH = false, tilesV = false }, + ["UI-HUD-ActionBar-Proc-Start-Flipbook"] = { file = 5199404, width = 842, height = 1010, left = 0.00048828125, right = 0.41162109375, top = 0.0009765625, bottom = 0.9873046875, tilesH = false, tilesV = false }, + ["UI-HUD-UnitFrame-Player-CombatIcon"] = { file = 4631591, width = 16, height = 16, left = 0.9833984375, right = 0.9990234375, top = 0.259765625, bottom = 0.291015625, tilesH = false, tilesV = false }, + ["UI-HUD-UnitFrame-Player-Group-GuideIcon"] = { file = 4631591, width = 16, height = 16, left = 0.1904296875, right = 0.2060546875, top = 0.95703125, bottom = 0.98828125, tilesH = false, tilesV = false }, + ["UI-HUD-UnitFrame-Player-Group-LeaderIcon"] = { file = 4631591, width = 16, height = 16, left = 0.2080078125, right = 0.2236328125, top = 0.95703125, bottom = 0.98828125, tilesH = false, tilesV = false }, + ["UI-HUD-UnitFrame-Player-PVP-AllianceIcon"] = { file = 4631591, width = 28, height = 41, left = 0.2353515625, right = 0.2626953125, top = 0.51171875, bottom = 0.591796875, tilesH = false, tilesV = false }, + ["UI-HUD-UnitFrame-Player-PVP-FFAIcon"] = { file = 8036204, width = 28, height = 44, left = 0.1201171875, right = 0.1474609375, top = 0.427734375, bottom = 0.513671875, tilesH = false, tilesV = false }, + ["UI-HUD-UnitFrame-Player-PVP-HordeIcon"] = { file = 4631591, width = 44, height = 44, left = 0.1904296875, right = 0.2333984375, top = 0.51171875, bottom = 0.59765625, tilesH = false, tilesV = false }, + ["UI-HUD-UnitFrame-Player-Rest-Flipbook"] = { file = 4659635, width = 360, height = 420, left = 0.001953125, right = 0.705078125, top = 0.001953125, bottom = 0.822265625, tilesH = false, tilesV = false }, + ["UI-HUD-UnitFrame-SmallCircle"] = { file = 8036204, width = 39, height = 39, left = 0.9560546875, right = 0.994140625, top = 0.169921875, bottom = 0.24609375, tilesH = false, tilesV = false }, + ["UI-HUD-UnitFrame-SmallCircle-Alliance"] = { file = 8036204, width = 24, height = 27, left = 0.1201171875, right = 0.1435546875, top = 0.626953125, bottom = 0.6796875, tilesH = false, tilesV = false }, + ["UI-HUD-UnitFrame-SmallCircle-Horde"] = { file = 8036204, width = 24, height = 27, left = 0.1201171875, right = 0.1435546875, top = 0.7265625, bottom = 0.779296875, tilesH = false, tilesV = false }, + ["UI-HUD-UnitFrame-Target-PortraitOn-Boss-Rare-Star"] = { file = 4703659, width = 26, height = 26, left = 0.32421875, right = 0.42578125, top = 0.578125, bottom = 0.6796875, tilesH = false, tilesV = false }, + ["UI-LFG-DeclineMark-Raid"] = { file = 5171843, width = 64, height = 64, left = 0.95068359375, right = 0.98193359375, top = 0.12646484375, bottom = 0.15771484375, tilesH = false, tilesV = false }, + ["UI-LFG-PendingMark-Raid"] = { file = 5171843, width = 64, height = 64, left = 0.95068359375, right = 0.98193359375, top = 0.15869140625, bottom = 0.18994140625, tilesH = false, tilesV = false }, + ["UI-LFG-ReadyMark-Raid"] = { file = 5171843, width = 64, height = 64, left = 0.95068359375, right = 0.98193359375, top = 0.19091796875, bottom = 0.22216796875, tilesH = false, tilesV = false }, + ["UI-LFG-RoleIcon-DPS-Micro-Raid"] = { file = 5171843, width = 12, height = 12, left = 0.9873046875, right = 0.9931640625, top = 0.0341796875, bottom = 0.0400390625, tilesH = false, tilesV = false }, + ["UI-LFG-RoleIcon-Healer-Micro-Raid"] = { file = 5171843, width = 12, height = 12, left = 0.98486328125, right = 0.99072265625, top = 0.04345703125, bottom = 0.04931640625, tilesH = false, tilesV = false }, + ["UI-LFG-RoleIcon-Tank-Micro-Raid"] = { file = 5171843, width = 12, height = 12, left = 0.98486328125, right = 0.99072265625, top = 0.05029296875, bottom = 0.05615234375, tilesH = false, tilesV = false }, + ["UI-PetHappiness"] = { file = 8472668, width = 128, height = 128, left = 0.001953125, right = 0.251953125, top = 0.00390625, bottom = 0.50390625, tilesH = false, tilesV = false }, + ["UI-PetMad"] = { file = 8472668, width = 128, height = 128, left = 0.255859375, right = 0.505859375, top = 0.00390625, bottom = 0.50390625, tilesH = false, tilesV = false }, + ["UI-PetNeutral"] = { file = 8472668, width = 128, height = 128, left = 0.509765625, right = 0.759765625, top = 0.00390625, bottom = 0.50390625, tilesH = false, tilesV = false }, + }, +} diff --git a/tests/proof/setup.lua b/tests/proof/setup.lua index 4f4faea..26a8e01 100644 --- a/tests/proof/setup.lua +++ b/tests/proof/setup.lua @@ -5,6 +5,8 @@ local Proof = require("wowproof") local MockState = require("wowproof.adapters.mock_state") local Raster = require("wowproof.raster") local BlizzardArt = require("wowproof.sources.wow_ui_textures") +local ClientFiles = require("wowproof.sources.wago_casc") +local AtlasTable = require("wowproof.sources.atlas_table") local Mock = Helpers.Mock @@ -14,15 +16,19 @@ local FONT_DIR = "UnitFrames_Media/Fonts" local FONT_FAMILY = "Roboto Condensed" local FONT_WEIGHTS = { Light = 300, Regular = 400, Medium = 500, Bold = 700 } local ART_REF = "d23deaf8f44a7d280dc974a5c9d5321c013db59b" +local ATLASES = dofile("tests/proof/atlases.lua") +local ART_DIR = os.getenv("UF_PROOF_ART") or ".proof-art" +local ART_FETCH = os.getenv("UF_PROOF_ART_FETCH") ~= "0" local Setup = {} local blizzardArt = BlizzardArt({ ref = ART_REF, - dir = os.getenv("UF_PROOF_ART") or ".proof-art", - fetch = os.getenv("UF_PROOF_ART_FETCH") ~= "0", + dir = ART_DIR, + fetch = ART_FETCH, token = os.getenv("GITHUB_TOKEN") or os.getenv("GH_TOKEN"), }) +local clientFiles = ClientFiles({ build = ATLASES.build, dir = ART_DIR, fetch = ART_FETCH }) local function AddonFile(path) if type(path) ~= "string" or path:lower():sub(1, #ADDON_PREFIX) ~= ADDON_PREFIX then return nil end @@ -40,7 +46,7 @@ function Setup.AddonTexture(path) end function Setup.Texture(path) - return Setup.AddonTexture(path) or blizzardArt(path) + return Setup.AddonTexture(path) or blizzardArt(path) or clientFiles(path) end function Setup.Font(path) @@ -90,6 +96,7 @@ function Setup.Proof(options) settle = Setup.SettleBackdrops, assets = { textures = Setup.Texture, + atlases = AtlasTable(ATLASES.atlases), fonts = { dirs = { FONT_DIR }, family = Setup.Font, default = FONT_FAMILY, defaultWeight = 500 }, }, }) diff --git a/tests/spec/auras/aura_category_filters_spec.lua b/tests/spec/auras/aura_category_filters_spec.lua index 9ad9775..efa9b50 100644 --- a/tests/spec/auras/aura_category_filters_spec.lua +++ b/tests/spec/auras/aura_category_filters_spec.lua @@ -57,7 +57,7 @@ describe("Category aura filters", function() end return out end - assert.same({ "Spell_Holy_Renew", "Spell_Nature_LifeBloom" }, Icons("buffs", "HELPFUL|PLAYER|RAID_IN_COMBAT")) + assert.same({ "Spell_Holy_Renew", "INV_Misc_Herb_Felblossom" }, Icons("buffs", "HELPFUL|PLAYER|RAID_IN_COMBAT")) assert.same({ "Spell_Holy_DivineIntervention" }, Icons("buffs", "HELPFUL|BIG_DEFENSIVE")) assert.same({ "Spell_Holy_SealOfProtection" }, Icons("buffs", "HELPFUL|EXTERNAL_DEFENSIVE")) assert.same({ "Spell_Holy_DivineIntervention" }, Icons("buffs", "HELPFUL|IMPORTANT")) diff --git a/tests/spec/contract/atlas_catalog_spec.lua b/tests/spec/contract/atlas_catalog_spec.lua new file mode 100644 index 0000000..c4d5112 --- /dev/null +++ b/tests/spec/contract/atlas_catalog_spec.lua @@ -0,0 +1,5 @@ +describe("Generated Forever atlas table #proof", function() + it("matches the pinned build without requiring the raw atlas tables", function() + assert.equals(0, os.execute("python3 -B scripts/atlas_catalog.py --check-pin")) + end) +end) diff --git a/wowproof/README.md b/wowproof/README.md index c65991a..c64166b 100644 --- a/wowproof/README.md +++ b/wowproof/README.md @@ -57,7 +57,7 @@ the adapter's job. | `Size(r)`, `Scale(r)` | width, height; own scale | | `Shown(r)`, `Alpha(r)`, `IgnoresParentAlpha(r)` | own shown state; own alpha; boolean | | `Strata(r)`, `Level(r)`, `Layer(r)` | strata or nil (inherited); frame level; draw layer and sublevel | -| `Texture(r)` | `{ color, vertexColor, file, atlas, gradient = { orientation, from, to }, blend, slice }` | +| `Texture(r)` | `{ color, vertexColor, file, atlas, gradient = { orientation, from, to }, blend, slice, texCoords }` (`atlas` only while the texture shows it; `texCoords` set after `SetAtlas` are file coordinates, as in the client) | | `Bar(r)` | nil, or for status bars `{ min, max, value, orientation, reverse, color }` | | `Text(r)` | nil, or for font strings `{ text, font, size, flags, color, justifyH, justifyV }` | | `FillOf(r)` *(optional)* | the status bar whose fill texture `r` is; the fill then gets its rect from the bar value | @@ -78,7 +78,8 @@ the adapter's job. - Blizzard's white textures, drawn as solid colour - resolved image files, tinted by vertex colour, including nine-slice and texture coordinates (crops, mirrors, rotations and tiling beyond 0–1, such as backdrop edges) - - anything else as a dashed placeholder titled with its path + - atlases, cropped to their sub-rectangle; later texture coordinates map into it + - anything else as a dashed placeholder titled with its path or atlas name - **Status bars and text:** status bar fills by value, and font strings with justification, outline and `|c` colour codes. Rendering is deterministic: the same scene gives the same SVG. @@ -102,8 +103,28 @@ assets.textures = function(path) return ownTexture(path) or art(path) end ``` Files the commit lacks are remembered in `missing-.txt` and never -requested again. Atlases (`SetAtlas`) still draw as placeholders: they need -Blizzard's atlas table. +requested again. + +The mirror stops at 10.0, so newer art (most atlas sheets) comes from +`wowproof.sources.wago_casc`. It resolves client file IDs to PNGs through +[wago.tools](https://wago.tools)' CASC download, pinned to one client build. +`wowproof.blp` decodes the BLP2 files (uncompressed, palette and DXT1/3/5), +and ImageMagick writes the PNG. It caches under `/casc-/`. + +`assets.atlases` maps an atlas name to `{ file, width, height, left, right, +top, bottom, tilesH, tilesV }`, the fields of `C_Texture.GetAtlasInfo`, with +`file` resolved through `assets.textures`. `wowproof.sources.atlas_table` +wraps a plain table and looks names up case-insensitively, like the client. +Ship a pinned subset of the atlas table with the host so renders stay +deterministic and work offline. + +```lua +local files = require("wowproof.sources.wago_casc")({ build = "1.60.1.70862", dir = ".proof-art" }) +assets.textures = function(path) return ownTexture(path) or art(path) or files(path) end +assets.atlases = require("wowproof.sources.atlas_table")(pinnedAtlases) +``` + +Tiling atlases draw once, not repeated, and flipbooks show their whole sheet. ## Tests diff --git a/wowproof/adapters/mock_state.lua b/wowproof/adapters/mock_state.lua index 49d7a33..f9413ca 100644 --- a/wowproof/adapters/mock_state.lua +++ b/wowproof/adapters/mock_state.lua @@ -145,12 +145,13 @@ return function(options) local barState = bar and State(bar) or {} local file = state.texture or barState.texture if file ~= nil and type(file) ~= "string" then file = tostring(file) end - if file and file:sub(1, 6) == "atlas:" then file = nil end + local atlas + if file and file:sub(1, 6) == "atlas:" then atlas, file = state.atlas or file:sub(7), nil end return { color = Color(state.colorTexture), vertexColor = Color(barState.color) or Color(state.vertexColor), file = file, - atlas = state.atlas, + atlas = atlas, gradient = gradient, blend = state.blendMode, slice = state.sliceMargins, diff --git a/wowproof/blp.lua b/wowproof/blp.lua new file mode 100644 index 0000000..2160a4f --- /dev/null +++ b/wowproof/blp.lua @@ -0,0 +1,151 @@ +local ffi = require("ffi") +local bit = require("bit") + +local band, bor, rshift, lshift = bit.band, bit.bor, bit.rshift, bit.lshift + +local Blp = {} + +local HEADER_SIZE = 1172 +local PALETTE_OFFSET = 148 +local COMPRESSION_PALETTE, COMPRESSION_DXT, COMPRESSION_RAW = 1, 2, 3 +local DXT1, DXT3, DXT5 = 0, 1, 7 + +local function UInt16(bytes, offset) + return bor(bytes[offset], lshift(bytes[offset + 1], 8)) +end + +local function UInt32(bytes, offset) + return bytes[offset] + bytes[offset + 1] * 256 + bytes[offset + 2] * 65536 + bytes[offset + 3] * 16777216 +end + +local function Expand565(color) + local r, g, b = band(rshift(color, 11), 31), band(rshift(color, 5), 63), band(color, 31) + return math.floor(r * 255 / 31 + 0.5), math.floor(g * 255 / 63 + 0.5), math.floor(b * 255 / 31 + 0.5) +end + +local function Mix(a, b, weightA, weightB, total) + return math.floor((a * weightA + b * weightB) / total + 0.5) +end + +local function ColorPalette(bytes, offset, fourColor) + local c0, c1 = UInt16(bytes, offset), UInt16(bytes, offset + 2) + local r0, g0, b0 = Expand565(c0) + local r1, g1, b1 = Expand565(c1) + local palette = { { r0, g0, b0, 255 }, { r1, g1, b1, 255 } } + if fourColor or c0 > c1 then + palette[3] = { Mix(r0, r1, 2, 1, 3), Mix(g0, g1, 2, 1, 3), Mix(b0, b1, 2, 1, 3), 255 } + palette[4] = { Mix(r0, r1, 1, 2, 3), Mix(g0, g1, 1, 2, 3), Mix(b0, b1, 1, 2, 3), 255 } + else + palette[3] = { Mix(r0, r1, 1, 1, 2), Mix(g0, g1, 1, 1, 2), Mix(b0, b1, 1, 1, 2), 255 } + palette[4] = { 0, 0, 0, 0 } + end + return palette +end + +local function Dxt3Alpha(bytes, offset) + local alphas = {} + for index = 0, 15 do + local byte = bytes[offset + rshift(index, 1)] + alphas[index] = band(rshift(byte, band(index, 1) * 4), 15) * 17 + end + return alphas +end + +local function Dxt5Alpha(bytes, offset) + local a0, a1 = bytes[offset], bytes[offset + 1] + local levels = { [0] = a0, a1 } + if a0 > a1 then + for step = 2, 7 do levels[step] = Mix(a0, a1, 8 - step, step - 1, 7) end + else + for step = 2, 5 do levels[step] = Mix(a0, a1, 6 - step, step - 1, 5) end + levels[6], levels[7] = 0, 255 + end + local alphas = {} + for half = 0, 1 do + local base = offset + 2 + half * 3 + local bits = bytes[base] + bytes[base + 1] * 256 + bytes[base + 2] * 65536 + for index = 0, 7 do alphas[half * 8 + index] = levels[band(rshift(bits, index * 3), 7)] end + end + return alphas +end + +local function DecodeDxt(bytes, offset, width, height, alphaType, out) + local blockSize = alphaType == DXT1 and 8 or 16 + local blocksWide, blocksHigh = math.ceil(width / 4), math.ceil(height / 4) + for blockY = 0, blocksHigh - 1 do + for blockX = 0, blocksWide - 1 do + local block = offset + (blockY * blocksWide + blockX) * blockSize + local alphas + if alphaType == DXT3 then alphas = Dxt3Alpha(bytes, block) elseif alphaType == DXT5 then alphas = Dxt5Alpha(bytes, block) end + local colorOffset = alphaType == DXT1 and block or block + 8 + local palette = ColorPalette(bytes, colorOffset, alphaType ~= DXT1) + local indices = UInt32(bytes, colorOffset + 4) + for index = 0, 15 do + local x, y = blockX * 4 + index % 4, blockY * 4 + math.floor(index / 4) + if x < width and y < height then + local color = palette[band(rshift(indices, index * 2), 3) + 1] + local target = (y * width + x) * 4 + out[target], out[target + 1], out[target + 2] = color[1], color[2], color[3] + out[target + 3] = alphas and alphas[index] or color[4] + end + end + end + end +end + +local function PaletteAlpha(bytes, offset, index, depth) + if depth == 8 then return bytes[offset + index] end + if depth == 4 then return band(rshift(bytes[offset + rshift(index, 1)], band(index, 1) * 4), 15) * 17 end + if depth == 1 then return band(rshift(bytes[offset + rshift(index, 3)], band(index, 7)), 1) * 255 end + return 255 +end + +local function DecodePalette(bytes, offset, pixels, alphaDepth, out) + for index = 0, pixels - 1 do + local entry = PALETTE_OFFSET + bytes[offset + index] * 4 + local target = index * 4 + out[target], out[target + 1], out[target + 2] = bytes[entry + 2], bytes[entry + 1], bytes[entry] + out[target + 3] = PaletteAlpha(bytes, offset + pixels, index, alphaDepth) + end +end + +local function DecodeRaw(bytes, offset, pixels, out) + for index = 0, pixels - 1 do + local source, target = offset + index * 4, index * 4 + out[target], out[target + 1], out[target + 2], out[target + 3] = + bytes[source + 2], bytes[source + 1], bytes[source], bytes[source + 3] + end +end + +local function ExpectedSize(compression, alphaDepth, alphaType, width, height) + local pixels = width * height + if compression == COMPRESSION_RAW then return pixels * 4 end + if compression == COMPRESSION_PALETTE then return pixels + math.ceil(pixels * alphaDepth / 8) end + if compression == COMPRESSION_DXT and (alphaType == DXT1 or alphaType == DXT3 or alphaType == DXT5) then + return math.ceil(width / 4) * math.ceil(height / 4) * (alphaType == DXT1 and 8 or 16) + end + return nil +end + +function Blp.Decode(data) + if type(data) ~= "string" or #data < HEADER_SIZE or data:sub(1, 4) ~= "BLP2" then return nil, "not a BLP2 file" end + local bytes = ffi.cast("const uint8_t*", data) + local compression, alphaDepth, alphaType = bytes[8], bytes[9], bytes[10] + local width, height = UInt32(bytes, 12), UInt32(bytes, 16) + local offset, size = UInt32(bytes, 20), UInt32(bytes, 84) + local expected = ExpectedSize(compression, alphaDepth, alphaType, width, height) + if not expected then return nil, string.format("unsupported BLP2 encoding %d/%d", compression, alphaType) end + if width == 0 or height == 0 or size < expected or offset + expected > #data then return nil, "truncated BLP2 file" end + local pixels = width * height + local out = ffi.new("uint8_t[?]", pixels * 4) + if compression == COMPRESSION_RAW then + DecodeRaw(bytes, offset, pixels, out) + elseif compression == COMPRESSION_PALETTE then + DecodePalette(bytes, offset, pixels, alphaDepth, out) + else + DecodeDxt(bytes, offset, width, height, alphaType, out) + end + return width, height, ffi.string(out, pixels * 4) +end + +return Blp diff --git a/wowproof/init.lua b/wowproof/init.lua index 19483de..ce4bffb 100644 --- a/wowproof/init.lua +++ b/wowproof/init.lua @@ -24,6 +24,7 @@ function Proof.New(options) settle = options.settle, entries = {}, images = {}, + atlases = {}, }, Proof) end @@ -45,6 +46,38 @@ function Proof:Image(file) return cached.uri, cached.width, cached.height end +local function Pixel(value, size) + return math.floor(value * size + 0.5) +end + +local function LoadAtlas(self, name) + local resolve, textures = self.assets.atlases, self.assets.textures + local info = resolve and textures and resolve(name) + local file = info and textures(info.file) + local png = file and Raster.ToPng(file, self.cacheDir) + if not png then return false end + local width, height = Raster.PngSize(png) + if not width then return false end + local left, top = Pixel(info.left, width), Pixel(info.top, height) + local rect = { left = left, top = top, width = Pixel(info.right, width) - left, height = Pixel(info.bottom, height) - top } + if rect.width <= 0 or rect.height <= 0 then return false end + local crop = Raster.Crop(png, rect, self.cacheDir) + local uri = crop and Raster.DataUri(crop) + if not uri then return false end + return { uri = uri, width = rect.width, height = rect.height, + rect = { left = info.left, right = info.right, top = info.top, bottom = info.bottom } } +end + +function Proof:Atlas(name) + local cached = self.atlases[name] + if cached == nil then + cached = LoadAtlas(self, name) or false + self.atlases[name] = cached + end + if not cached then return nil end + return cached.uri, cached.width, cached.height, cached.rect +end + function Proof:Font(file) local fonts = self.assets.fonts if not fonts then return nil end @@ -71,6 +104,7 @@ function Proof:Render(region, options) debug = options.debug, background = options.background, image = function(file) return self:Image(file) end, + atlas = function(name) return self:Atlas(name) end, font = function(file) return self:Font(file) end, }) end diff --git a/wowproof/paint.lua b/wowproof/paint.lua index 5a92018..975b0d9 100644 --- a/wowproof/paint.lua +++ b/wowproof/paint.lua @@ -176,21 +176,46 @@ local GRADIENT = '' .. '' .. '' -function Context:ImageDef(file) - local cached = self.images[file] +function Context:ImageDef(key, load) + local cached = self.images[key] if cached ~= nil then return cached or nil end - local href, width, height = self.image(file) + local href, width, height, rect = load() if not href then - self.images[file] = false + self.images[key] = false return nil end local id = self:Define(string.format('', Number(width or 1), Number(height or 1), href)) - local image = { id = id, width = width, height = height } - self.images[file] = image + local image = { id = id, width = width, height = height, rect = rect } + self.images[key] = image return image end +local function AtlasCoords(coords, rect) + if not coords or #coords < 4 then return nil end + local width, height = rect.right - rect.left, rect.bottom - rect.top + local function U(value) return (value - rect.left) / width end + local function V(value) return (value - rect.top) / height end + if #coords >= 8 then + local mapped = {} + for index = 1, 8, 2 do mapped[index], mapped[index + 1] = U(coords[index]), V(coords[index + 1]) end + return mapped + end + return { U(coords[1]), U(coords[2]), V(coords[3]), V(coords[4]) } +end +Paint.AtlasCoords = AtlasCoords + +function Context:TextureImage(texture) + if texture.atlas then + local atlas = texture.atlas + local image = self:ImageDef("atlas:" .. atlas, function() return self.atlas(atlas) end) + if image then return image, AtlasCoords(texture.texCoords, image.rect) end + end + local file = texture.file + if not file then return nil end + return self:ImageDef(file, function() return self.image(file) end), texture.texCoords +end + function Context:DrawImagePiece(image, target, source) if target.width <= 0 or target.height <= 0 or source.width <= 0 or source.height <= 0 then return end self:Emit(string.format('', @@ -304,7 +329,7 @@ function Context:DrawTexture(region, rect, alpha) self:Emit(string.format('', RectAttributes(rect), Fill(Multiply(solid, texture.vertexColor), alpha), blend)) return end - local image = texture.file and self:ImageDef(texture.file) + local image, coords = self:TextureImage(texture) if image then local filter = "" local tint = texture.vertexColor @@ -317,10 +342,10 @@ function Context:DrawTexture(region, rect, alpha) self:Emit(string.format('', Number(Clamp(alpha)), filter, blend)) if texture.slice and image.width then self:DrawNineSlice(image, texture.slice, rect) - elseif NeedsAffine(texture.texCoords) and image.width then - self:DrawImageAffine(image, rect, texture.texCoords) + elseif NeedsAffine(coords) and image.width then + self:DrawImageAffine(image, rect, coords) else - self:DrawImagePiece(image, rect, SourceRect(texture.texCoords, image.width or 1, image.height or 1)) + self:DrawImagePiece(image, rect, SourceRect(coords, image.width or 1, image.height or 1)) end self:Emit("") return @@ -411,6 +436,7 @@ function Paint.Render(options) layout = layout, root = root, image = options.image or function() return nil end, + atlas = options.atlas or function() return nil end, font = options.font or function() return nil end, defs = {}, body = {}, diff --git a/wowproof/raster.lua b/wowproof/raster.lua index c769ec2..c80e72c 100644 --- a/wowproof/raster.lua +++ b/wowproof/raster.lua @@ -81,6 +81,52 @@ function Raster.ToPng(file, cacheDir) return target end +function Raster.RawToPng(rgba, width, height, target) + local tool = Raster.ImageTool() + if not tool then return nil end + local raw = target .. ".rgba" + Raster.Write(raw, rgba) + local ok = Run(string.format("%s -size %dx%d -depth 8 %s %s >/dev/null 2>&1", + tool, width, height, Quote("rgba:" .. raw), Quote(target))) + os.remove(raw) + return ok and target or nil +end + +function Raster.Crop(png, rect, cacheDir) + local tool = Raster.ImageTool() + if not tool or not Raster.Exists(png) then return nil end + Raster.MakeDir(cacheDir) + local geometry = string.format("%dx%d+%d+%d", rect.width, rect.height, rect.left, rect.top) + local target = cacheDir .. "/" .. CacheName(png .. "@" .. geometry) + if Raster.Exists(target) then return target end + if not Run(string.format("%s %s -crop %s +repage %s >/dev/null 2>&1", tool, Quote(png), geometry, Quote(target))) then + return nil + end + return target +end + +local function NonEmpty(file) + local handle = io.open(file, "rb") + if not handle then return false end + local size = handle:seek("end") + handle:close() + return size > 0 +end + +function Raster.Download(url, target, headers) + Raster.MakeDir(target:match("^(.*)/[^/]+$") or ".") + local partial = target .. ".part" + local curl = io.popen("curl -fsSL --retry 2 --max-time 60 -H @- -o " .. Quote(partial) .. " " .. Quote(url) .. " 2>/dev/null", "w") + curl:write(table.concat(headers or { "User-Agent: wowproof" }, "\n"), "\n") + curl:close() + if not NonEmpty(partial) then + os.remove(partial) + return false + end + os.rename(partial, target) + return true +end + local function UInt32(data, offset) local a, b, c, d = data:byte(offset, offset + 3) return ((a * 256 + b) * 256 + c) * 256 + d diff --git a/wowproof/sources/atlas_table.lua b/wowproof/sources/atlas_table.lua new file mode 100644 index 0000000..38678ec --- /dev/null +++ b/wowproof/sources/atlas_table.lua @@ -0,0 +1,8 @@ +return function(atlases) + local byName = {} + for name, info in pairs(atlases or {}) do byName[name:lower()] = info end + return function(name) + if type(name) ~= "string" then return nil end + return byName[name:lower()] + end +end diff --git a/wowproof/sources/wago_casc.lua b/wowproof/sources/wago_casc.lua new file mode 100644 index 0000000..619ea55 --- /dev/null +++ b/wowproof/sources/wago_casc.lua @@ -0,0 +1,32 @@ +local Raster = require("wowproof.raster") +local Blp = require("wowproof.blp") + +local DEFAULT_URL = "https://wago.tools/api/casc/%d?version=%s" + +local function FileId(file) + if type(file) == "number" then return file % 1 == 0 and file > 0 and file or nil end + if type(file) == "string" and file:match("^%d+$") then return tonumber(file) end + return nil +end + +return function(options) + options = options or {} + local build = options.build or error("wowproof: pin the CASC source to a client build (build)", 2) + local dir = (options.dir or ".proof-art") .. "/casc-" .. build + local fetch = options.fetch ~= false + local url = options.url or DEFAULT_URL + + return function(file) + local id = FileId(file) + if not id then return nil end + local cached = string.format("%s/%d.png", dir, id) + if Raster.Exists(cached) then return cached end + if not fetch or not Raster.Has("curl") then return nil end + local blp = string.format("%s/%d.blp", dir, id) + if not Raster.Download(string.format(url, id, build), blp) then return nil end + local width, height, rgba = Blp.Decode(Raster.Read(blp)) + os.remove(blp) + if not width then return nil end + return Raster.RawToPng(rgba, width, height, cached) + end +end diff --git a/wowproof/sources/wow_ui_textures.lua b/wowproof/sources/wow_ui_textures.lua index df23ff0..1cf8e24 100644 --- a/wowproof/sources/wow_ui_textures.lua +++ b/wowproof/sources/wow_ui_textures.lua @@ -6,18 +6,6 @@ local function UrlEncode(text) return (text:gsub("[^%w%-_%.~/]", function(char) return string.format("%%%02X", char:byte()) end)) end -local function DirName(path) - return path:match("^(.*)/[^/]+$") or "." -end - -local function NonEmpty(file) - local handle = io.open(file, "rb") - if not handle then return false end - local size = handle:seek("end") - handle:close() - return size > 0 -end - return function(options) options = options or {} local repository = options.repository or DEFAULT_REPOSITORY @@ -31,21 +19,10 @@ return function(options) local trees, missing = {}, nil local function Download(url, target, api) - Raster.MakeDir(DirName(target)) - local partial = target .. ".part" local headers = { "User-Agent: wowproof" } if api then headers[#headers + 1] = "Accept: application/vnd.github+json" end if api and token and token ~= "" then headers[#headers + 1] = "Authorization: Bearer " .. token end - local curl = io.popen("curl -fsSL --retry 2 --max-time 60 -H @- -o " .. Raster.Quote(partial) .. " " - .. Raster.Quote(url) .. " 2>/dev/null", "w") - curl:write(table.concat(headers, "\n"), "\n") - curl:close() - if not NonEmpty(partial) then - os.remove(partial) - return false - end - os.rename(partial, target) - return true + return Raster.Download(url, target, headers) end local function Tree(sha) diff --git a/wowproof/spec/blp_spec.lua b/wowproof/spec/blp_spec.lua new file mode 100644 index 0000000..713ade2 --- /dev/null +++ b/wowproof/spec/blp_spec.lua @@ -0,0 +1,56 @@ +local Blp = require("wowproof.blp") + +local function UInt32(value) + return string.char(value % 256, math.floor(value / 256) % 256, math.floor(value / 65536) % 256, math.floor(value / 16777216)) +end + +local function File(compression, alphaDepth, alphaType, width, height, body, palette) + return "BLP2" .. UInt32(1) .. string.char(compression, alphaDepth, alphaType, 0) .. UInt32(width) .. UInt32(height) + .. UInt32(1172) .. string.rep(UInt32(0), 15) .. UInt32(#body) .. string.rep(UInt32(0), 15) + .. (palette or "") .. string.rep("\0", 1024 - #(palette or "")) .. body +end + +local function Bytes(text) + return { text:byte(1, -1) } +end + +local RED_BLUE = "\0\248\31\0" + +describe("wowproof BLP2 decoder", function() + it("swizzles uncompressed BGRA to RGBA", function() + local width, height, rgba = Blp.Decode(File(3, 8, 8, 2, 1, "\3\2\1\4\7\6\5\8")) + assert.equals(2, width) + assert.equals(1, height) + assert.same({ 1, 2, 3, 4, 5, 6, 7, 8 }, Bytes(rgba)) + end) + + it("looks palette pixels up with 8-bit and 1-bit alpha", function() + local palette = "\30\20\10\0\60\50\40\0" + local _, _, rgba = Blp.Decode(File(1, 8, 0, 2, 1, "\0\1\128\255", palette)) + assert.same({ 10, 20, 30, 128, 40, 50, 60, 255 }, Bytes(rgba)) + _, _, rgba = Blp.Decode(File(1, 1, 0, 2, 1, "\0\1\2", palette)) + assert.same({ 10, 20, 30, 0, 40, 50, 60, 255 }, Bytes(rgba)) + _, _, rgba = Blp.Decode(File(1, 0, 0, 1, 1, "\1", palette)) + assert.same({ 40, 50, 60, 255 }, Bytes(rgba)) + end) + + it("decodes DXT1 blocks, clipped to the image, with the transparent three-colour mode", function() + local _, _, rgba = Blp.Decode(File(2, 0, 0, 2, 2, RED_BLUE .. UInt32(4))) + assert.same({ 255, 0, 0, 255, 0, 0, 255, 255, 255, 0, 0, 255, 255, 0, 0, 255 }, Bytes(rgba)) + _, _, rgba = Blp.Decode(File(2, 1, 0, 1, 1, "\31\0\0\248" .. UInt32(3))) + assert.same({ 0, 0, 0, 0 }, Bytes(rgba)) + end) + + it("decodes DXT3 and DXT5 alpha", function() + local _, _, rgba = Blp.Decode(File(2, 8, 1, 1, 1, "\8" .. string.rep("\0", 7) .. RED_BLUE .. UInt32(0))) + assert.same({ 255, 0, 0, 136 }, Bytes(rgba)) + _, _, rgba = Blp.Decode(File(2, 8, 7, 2, 1, "\255\0\1\0\0\0\0\0" .. RED_BLUE .. UInt32(0))) + assert.same({ 255, 0, 0, 0, 255, 0, 0, 255 }, Bytes(rgba)) + end) + + it("rejects other files and encodings", function() + assert.is_nil(Blp.Decode("PNG")) + assert.is_nil(Blp.Decode(File(2, 8, 5, 1, 1, string.rep("\0", 16)))) + assert.is_nil(Blp.Decode(File(3, 8, 8, 2, 2, "\0\0\0\0"))) + end) +end) diff --git a/wowproof/spec/package_spec.lua b/wowproof/spec/package_spec.lua index b01c3d7..3f11f5e 100644 --- a/wowproof/spec/package_spec.lua +++ b/wowproof/spec/package_spec.lua @@ -75,6 +75,13 @@ describe("wowproof package", function() assert.is_true(adapter.ClipsChildren(bar)) assert.is_false(adapter.ClipsChildren(root)) assert.same({ min = 0, max = 10, value = 4, reverse = false, color = { 1, 0, 0, 1 } }, adapter.Bar(bar)) + local icon = Object("Texture", root, { atlas = "Some-Atlas", texture = "atlas:Some-Atlas" }) + registry[#registry + 1] = icon + assert.equals("Some-Atlas", adapter.Texture(icon).atlas) + assert.is_nil(adapter.Texture(icon).file) + icon.__state.texture = "Interface\\Other" + assert.is_nil(adapter.Texture(icon).atlas) + assert.equals("Interface\\Other", adapter.Texture(icon).file) local info = adapter.Text(text) assert.equals("40%", info.text) assert.equals(11, info.size) diff --git a/wowproof/spec/paint_spec.lua b/wowproof/spec/paint_spec.lua index d15ef97..90472c0 100644 --- a/wowproof/spec/paint_spec.lua +++ b/wowproof/spec/paint_spec.lua @@ -126,6 +126,28 @@ describe("wowproof paint", function() assert.same({ left = 0, top = 0, width = 32, height = 16 }, Paint.SourceRect(nil, 32, 16)) end) + it("draws atlases from their own sub-rectangle and maps later texture coordinates into it", function() + local rect = { left = 0.5, right = 0.75, top = 0.25, bottom = 0.5 } + local function Atlas(name) + if name == "Known-Atlas" then return "data:image/png;base64,AT", 16, 8, rect end + end + scene.Node("Texture", frame, { points = { { all = true } }, texture = { atlas = "Known-Atlas" } }) + scene.Node("Texture", frame, { + points = { { all = true } }, texture = { atlas = "Known-Atlas", texCoords = { 0.625, 0.75, 0.25, 0.5 } }, + }) + scene.Node("Texture", frame, { points = { { all = true } }, texture = { atlas = "Missing-Atlas" } }) + local svg = Render(nil, { atlas = Atlas }) + local _, images = svg:gsub("base64,AT", "") + assert.equals(1, images) + assert.is_true(Has(svg, '')) + assert.is_true(Has(svg, 'viewBox="0 0 16 8"')) + assert.is_true(Has(svg, 'viewBox="8 0 8 8"')) + assert.is_true(Has(svg, "Missing-Atlas")) + assert.same({ 1, 0, 0, 1 }, Paint.AtlasCoords({ 0.75, 0.5, 0.25, 0.5 }, rect)) + assert.same({ 0, 1, 1, 1, 0, 0, 1, 0 }, Paint.AtlasCoords({ 0.5, 0.5, 0.75, 0.5, 0.5, 0.25, 0.75, 0.25 }, rect)) + assert.is_nil(Paint.AtlasCoords(nil, rect)) + end) + it("maps rotated and tiled texture coordinates through a pattern transform", function() local coords = { 0, 2, 1, 2, 0, 0, 1, 0 } assert.is_true(Paint.NeedsAffine(coords)) diff --git a/wowproof/spec/sources_spec.lua b/wowproof/spec/sources_spec.lua index c973465..9aab545 100644 --- a/wowproof/spec/sources_spec.lua +++ b/wowproof/spec/sources_spec.lua @@ -1,5 +1,7 @@ local Raster = require("wowproof.raster") local WowUiTextures = require("wowproof.sources.wow_ui_textures") +local WagoCasc = require("wowproof.sources.wago_casc") +local AtlasTable = require("wowproof.sources.atlas_table") local REF = "abc123" @@ -42,4 +44,24 @@ describe("wowproof wow-ui-textures source", function() local missing = Raster.Read(dir .. "/missing-" .. REF .. ".txt") assert.equals("ICONS\\SPELL_NATURE_LIFEBLOOM\nNOWHERE\\THING\n", missing) end) + + it("resolves client file IDs from the pinned build's cache only", function() + assert.has_error(function() WagoCasc({ dir = dir }) end) + Write(dir .. "/casc-1.2.3.4/7526019.png", "png") + local resolve = WagoCasc({ build = "1.2.3.4", dir = dir, fetch = false }) + assert.equals(dir .. "/casc-1.2.3.4/7526019.png", resolve(7526019)) + assert.equals(dir .. "/casc-1.2.3.4/7526019.png", resolve("7526019")) + assert.is_nil(resolve(1234)) + assert.is_nil(resolve(1.5)) + assert.is_nil(resolve("Interface\\Icons\\Spell_Holy_Renew")) + end) + + it("looks atlases up by name, case-insensitively like the client", function() + local info = { file = 7526019 } + local resolve = AtlasTable({ ["RaidFrame-Icon-Rez"] = info }) + assert.equals(info, resolve("raidframe-icon-rez")) + assert.equals(info, resolve("RAIDFRAME-ICON-REZ")) + assert.is_nil(resolve("Missing")) + assert.is_nil(resolve(nil)) + end) end)