From eae461a73a269ca6b586e756318cfa09d8513f42 Mon Sep 17 00:00:00 2001 From: Martin Konstantin Herrmann Date: Mon, 9 Nov 2026 18:18:19 +0100 Subject: [PATCH 1/2] Render 3D portraits in UI proof wowproof draws model frames through assets.models (cover-cropped, model alpha, desaturation) with a model placeholder fallback; mock_state reports the model's unit, zoom, alpha and desaturation. The proof host stands in Blizzard race portraits. Adds player-dead, focus-portrait and pet-portrait scenarios. --- AGENTS.md | 2 +- DEVELOPMENT.md | 11 +++++- tests/proof/setup.lua | 23 +++++++++++++ tests/proof/units.lua | 9 +++++ wowproof/README.md | 15 ++++++++ wowproof/adapters/mock_state.lua | 24 +++++++++++++ wowproof/init.lua | 1 + wowproof/paint.lua | 59 +++++++++++++++++++++++++++++--- wowproof/scene.lua | 8 ++++- wowproof/spec/package_spec.lua | 22 ++++++++++++ wowproof/spec/paint_spec.lua | 36 +++++++++++++++++++ 11 files changed, 203 insertions(+), 7 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index a73cf3f..4de146b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -103,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 the generated table lacks 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 or an atlas the generated table lacks, not a bug. 3D portraits show a static race portrait as a stand-in; 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 a68e72c..dfe7e92 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -283,10 +283,19 @@ 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. +3D portraits (`PlayerModel`) can't be rendered headlessly, so +`Setup.Model` stands in Blizzard's static race portrait +(`Interface\CharacterFrame\TemporaryPortrait-Male-`) for the unit the +model shows, or the pet/monster portrait for non-players, from the same +mirror. It keeps the model's alpha, model alpha and dead/ghost desaturation. +Previews always show the player's own model (the portrait driver's sample is +`"player"`), so every sample portrait is the mocked Human. `player-dead`, +`focus-portrait` and `pet-portrait` cover the portraits that are off by +default. + Still drawn as dashed placeholders: - art the mirror lacks, listed in `.proof-art/missing-.txt` - atlases the generated table lacks -- portrait models ### Pull request checks diff --git a/tests/proof/setup.lua b/tests/proof/setup.lua index 26a8e01..738e329 100644 --- a/tests/proof/setup.lua +++ b/tests/proof/setup.lua @@ -19,6 +19,10 @@ 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 PORTRAIT_ART = "Interface\\CharacterFrame\\TemporaryPortrait-" +local PORTRAIT_SEX = "Male" +local PORTRAIT_CROP = { 0.14, 0.86, 0.14, 0.86 } +local CREATURE_PORTRAITS = { Beast = "Pet", Mechanical = "Vehicle-Mechanical" } local Setup = {} @@ -49,6 +53,24 @@ function Setup.Texture(path) return Setup.AddonTexture(path) or blizzardArt(path) or clientFiles(path) end +local function Plain(value) + if Mock.IsSecret(value) then return value.secretValue end + return value +end + +function Setup.Model(info) + local unit = info.unit + if not unit then return nil end + local art + if Plain(UnitIsPlayer(unit)) then + local _, race = UnitRace(unit) + art = PORTRAIT_SEX .. "-" .. Plain(race) + else + art = CREATURE_PORTRAITS[Plain(UnitCreatureType(unit))] or "Monster" + end + return { file = PORTRAIT_ART .. art, texCoords = PORTRAIT_CROP } +end + function Setup.Font(path) local file = AddonFile(path) local style = file and file:match("^" .. FONT_DIR .. "/RobotoCondensed%-(%a+)%.ttf$") @@ -97,6 +119,7 @@ function Setup.Proof(options) assets = { textures = Setup.Texture, atlases = AtlasTable(ATLASES.atlases), + models = Setup.Model, fonts = { dirs = { FONT_DIR }, family = Setup.Font, default = FONT_FAMILY, defaultWeight = 500 }, }, }) diff --git a/tests/proof/units.lua b/tests/proof/units.lua index a633575..be965c0 100644 --- a/tests/proof/units.lua +++ b/tests/proof/units.lua @@ -28,6 +28,12 @@ local function NoBorder(ns) ns.Config:SetUnitValue("player", "border.enabled", false) end +local function Enable(unit, keys) + return function(ns) + for _, key in ipairs(keys) do ns.Config:SetUnitValue(unit, key .. ".enabled", true) end + end +end + local function ThickAuraBorder(ns) ns.Config:SetUnitValue("target", "auras.border", { enabled = true, border = "Blizzard Tooltip", size = 10, padding = 2 }) end @@ -45,6 +51,7 @@ return { { name = "player-idle", build = UnitFrame("player", { showCast = false }) }, { name = "player-tooltip-border", build = UnitFrame("player", { showCast = false }, TooltipBorder) }, { name = "player-no-border", build = UnitFrame("player", { showCast = false }, NoBorder) }, + { name = "player-dead", build = UnitFrame("player", { status = "dead", showCast = false }) }, { name = "player-overheal", build = UnitFrame("player", { health = 22000, heal = 7000, showCast = false }, EnableOverheal) }, { name = "target", build = UnitFrame("target") }, { name = "target-35pct", build = UnitFrame("target", { health = 8400, showCast = false }) }, @@ -52,6 +59,8 @@ return { { name = "target-aura-wide", build = UnitFrame("target", { showCast = false }, WideAuras) }, { name = "targettarget", build = UnitFrame("targettarget") }, { name = "focus", build = UnitFrame("focus") }, + { name = "focus-portrait", build = UnitFrame("focus", { showCast = false }, Enable("focus", { "portrait" })) }, { name = "focustarget", build = UnitFrame("focustarget") }, { name = "pet", build = UnitFrame("pet") }, + { name = "pet-portrait", build = UnitFrame("pet", nil, Enable("pet", { "health", "power", "portrait" })) }, } diff --git a/wowproof/README.md b/wowproof/README.md index c64166b..32eb388 100644 --- a/wowproof/README.md +++ b/wowproof/README.md @@ -62,6 +62,7 @@ the adapter's job. | `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 | | `ClipsChildren(r)` *(optional)* | whether the frame clips its children | +| `Model(r)` *(optional)* | nil, or for model frames (`Scene.MODEL_TYPES`) `{ unit, file, displayId, creatureId, zoom, modelAlpha, desaturation }`; all sources nil once cleared | `wowproof.scene` validates adapters and lists the strata and draw-layer order. `wowproof.adapters.mock_state` covers mocks that keep widget state in @@ -80,6 +81,11 @@ the adapter's job. texture coordinates (crops, mirrors, rotations and tiling beyond 0–1, such as backdrop edges) - 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 +- **Models:** `PlayerModel` and the other model frames through `assets.models(info)`, which gets + the adapter's `Model(r)` and returns a texture path (resolved through `assets.textures`) or + `{ file, texCoords }`. The image covers the frame (centre-cropped to its aspect) at the frame's + alpha times the model alpha, desaturated by the model's desaturation. Without art it's a dashed + placeholder titled `model: `; a cleared model draws nothing. - **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. @@ -126,6 +132,15 @@ assets.atlases = require("wowproof.sources.atlas_table")(pinnedAtlases) Tiling atlases draw once, not repeated, and flipbooks show their whole sheet. +Models can't be rendered without the client, so a host maps them to stand-in +art, for example a race portrait for player units: + +```lua +assets.models = function(info) + if info.unit then return { file = "Interface\\CharacterFrame\\TemporaryPortrait-Male-Human", texCoords = { 0.14, 0.86, 0.14, 0.86 } } end +end +``` + ## Tests `spec/` holds busted-style specs (`describe`/`it`/`assert.*`) that need diff --git a/wowproof/adapters/mock_state.lua b/wowproof/adapters/mock_state.lua index f9413ca..bf0ca71 100644 --- a/wowproof/adapters/mock_state.lua +++ b/wowproof/adapters/mock_state.lua @@ -1,3 +1,5 @@ +local Scene = require("wowproof.scene") + return function(options) options = options or {} local isSecret = options.isSecret or function() return false end @@ -174,6 +176,28 @@ return function(options) } end + local MODEL_SOURCES = { SetUnit = "unit", SetModel = "file", SetDisplayInfo = "displayId", SetCreature = "creatureId" } + + function adapter.Model(region) + if not Scene.IsModel(adapter, region) then return nil end + local state = State(region) + local info = { zoom = 0, desaturation = 0 } + for _, call in ipairs(rawget(region, "__calls") or {}) do + local name = call[1] + if name == "ClearModel" or MODEL_SOURCES[name] then + info.unit, info.file, info.displayId, info.creatureId = nil, nil, nil, nil + if MODEL_SOURCES[name] then info[MODEL_SOURCES[name]] = Plain(call[2]) end + elseif name == "SetPortraitZoom" then + info.zoom = Plain(call[2]) + elseif name == "SetDesaturation" then + info.desaturation = Plain(call[2]) + end + end + local modelAlpha = Plain(state.modelAlpha) + info.modelAlpha = modelAlpha == nil and 1 or modelAlpha + return info + end + local function FontObject(value) if type(value) == "string" then value = globals[value] end if type(value) == "table" and rawget(value, "__state") then return value end diff --git a/wowproof/init.lua b/wowproof/init.lua index ce4bffb..a27bfde 100644 --- a/wowproof/init.lua +++ b/wowproof/init.lua @@ -106,6 +106,7 @@ function Proof:Render(region, options) image = function(file) return self:Image(file) end, atlas = function(name) return self:Atlas(name) end, font = function(file) return self:Font(file) end, + model = function(info) return self.assets.models and self.assets.models(info) end, }) end diff --git a/wowproof/paint.lua b/wowproof/paint.lua index 975b0d9..6243d5b 100644 --- a/wowproof/paint.lua +++ b/wowproof/paint.lua @@ -354,11 +354,59 @@ function Context:DrawTexture(region, rect, alpha) self:Emit(string.format('', RectAttributes(rect), Fill(texture.vertexColor, alpha), blend)) return end - if texture.file or texture.atlas then - self:Emit(string.format('%s', - RectAttributes(rect), Fill(PLACEHOLDER_COLOR, alpha), Rgb(PLACEHOLDER_COLOR), - Escape(texture.file or texture.atlas))) + if texture.file or texture.atlas then self:DrawPlaceholder(rect, alpha, texture.file or texture.atlas) end +end + +function Context:DrawPlaceholder(rect, alpha, title) + self:Emit(string.format('%s', + RectAttributes(rect), Fill(PLACEHOLDER_COLOR, alpha), Rgb(PLACEHOLDER_COLOR), Escape(title))) +end + +local function CoverRect(source, target) + if source.width <= 0 or source.height <= 0 or target.width <= 0 or target.height <= 0 then return source end + local aspect = target.width / target.height + if source.width / source.height > aspect then + local width = source.height * aspect + return { left = source.left + (source.width - width) / 2, top = source.top, width = width, height = source.height } + end + local height = source.width / aspect + return { left = source.left, top = source.top + (source.height - height) / 2, width = source.width, height = height } +end +Paint.CoverRect = CoverRect + +local function ModelSubject(info) + return info.unit or info.file or (info.displayId and "display " .. info.displayId) + or (info.creatureId and "creature " .. info.creatureId) +end +Paint.ModelSubject = ModelSubject + +function Context:DrawModel(region, rect, alpha) + local info = self.adapter.Model and self.adapter.Model(region) + if not info then + self:DrawPlaceholder(rect, alpha, "model: " .. self.adapter.Type(region)) + return + end + local subject = ModelSubject(info) + alpha = alpha * Clamp(info.modelAlpha or 1) + if not subject or alpha <= 0 then return end + local art = self.model(info) + if type(art) == "string" then art = { file = art } end + local image = art and art.file and self:ImageDef(art.file, function() return self.image(art.file) end) + if not image or not image.width then + self:DrawPlaceholder(rect, alpha, "model: " .. subject) + return + end + local filter = "" + local desaturation = Clamp(info.desaturation or 0) + if desaturation > 0 then + local id = self:Define(string.format( + '', + Number(1 - desaturation))) + filter = string.format(' filter="url(#%s)"', id) end + self:Emit(string.format('', Number(alpha), filter)) + self:DrawImagePiece(image, rect, CoverRect(SourceRect(art.texCoords, image.width, image.height), rect)) + self:Emit("") end function Context:DrawBar(region, alpha) @@ -438,6 +486,7 @@ function Paint.Render(options) image = options.image or function() return nil end, atlas = options.atlas or function() return nil end, font = options.font or function() return nil end, + model = options.model or function() return nil end, defs = {}, body = {}, images = {}, @@ -472,6 +521,8 @@ function Paint.Render(options) context:DrawTexture(entry.region, entry.rect, entry.alpha) elseif kind == "FontString" then context:DrawText(entry.region, entry.rect, entry.alpha) + elseif Scene.IsModel(adapter, entry.region) then + context:DrawModel(entry.region, entry.rect, entry.alpha) elseif not adapter.FillOf and not Scene.IsRegion(adapter, entry.region) then context:DrawBar(entry.region, entry.alpha) end diff --git a/wowproof/scene.lua b/wowproof/scene.lua index 3c40a6f..28e8d43 100644 --- a/wowproof/scene.lua +++ b/wowproof/scene.lua @@ -7,7 +7,7 @@ Scene.REQUIRED = { "Texture", "Bar", "Text", } -Scene.OPTIONAL = { "FillOf", "ClipsChildren" } +Scene.OPTIONAL = { "FillOf", "ClipsChildren", "Model" } Scene.SOLID_FILES = { ["interface\\buttons\\white8x8"] = true, @@ -21,6 +21,12 @@ end Scene.REGION_TYPES ={ Texture = true, FontString = true, Line = true, MaskTexture = true } +Scene.MODEL_TYPES = { Model = true, PlayerModel = true, DressUpModel = true, CinematicModel = true, TabardModel = true } + +function Scene.IsModel(adapter, region) + return Scene.MODEL_TYPES[adapter.Type(region)] == true +end + Scene.STRATA = { "WORLD", "BACKGROUND", "LOW", "MEDIUM", "HIGH", "DIALOG", "FULLSCREEN", "FULLSCREEN_DIALOG", "TOOLTIP", } diff --git a/wowproof/spec/package_spec.lua b/wowproof/spec/package_spec.lua index 3f11f5e..8d88f84 100644 --- a/wowproof/spec/package_spec.lua +++ b/wowproof/spec/package_spec.lua @@ -88,4 +88,26 @@ describe("wowproof package", function() assert.equals("RIGHT", info.justifyH) assert.equals(4, adapter.Order(text)) end) + + it("replays model calls through the mock_state adapter", function() + local secret = {} + local function Secret(value) return setmetatable({ value = value }, secret) end + local model = { __type = "PlayerModel", __state = { kids = {} }, __calls = {} } + local adapter = MockState({ + isSecret = function(value) return getmetatable(value) == secret end, + reveal = function(value) return value.value end, + }) + assert.same({ zoom = 0, desaturation = 0, modelAlpha = 1 }, adapter.Model(model)) + model.__calls = { + { "SetModel", "Interface\\Buttons\\TalkToMeQuestionMark.m2" }, { "SetPortraitZoom", 0 }, + { "ClearModel" }, { "SetUnit", "target" }, { "SetPortraitZoom", 1 }, { "SetDesaturation", Secret(0.5) }, + } + model.__state.modelAlpha = Secret(0.4) + assert.same({ unit = "target", zoom = 1, desaturation = 0.5, modelAlpha = 0.4 }, adapter.Model(model)) + model.__calls[#model.__calls + 1] = { "SetDisplayInfo", 1234 } + assert.same({ displayId = 1234, zoom = 1, desaturation = 0.5, modelAlpha = 0.4 }, adapter.Model(model)) + model.__calls[#model.__calls + 1] = { "ClearModel" } + assert.is_nil(adapter.Model(model).displayId) + assert.is_nil(adapter.Model({ __type = "Frame", __state = {}, __calls = {} })) + end) end) diff --git a/wowproof/spec/paint_spec.lua b/wowproof/spec/paint_spec.lua index 90472c0..c72618c 100644 --- a/wowproof/spec/paint_spec.lua +++ b/wowproof/spec/paint_spec.lua @@ -213,6 +213,42 @@ describe("wowproof paint", function() assert.is_true(Has(svg, '')) + assert.is_true(Has(svg, '')) + assert.is_true(Has(svg, 'viewBox="0 4.8 32 6.4"')) + assert.same({ left = 0, top = 12, width = 32, height = 8 }, + Paint.CoverRect({ left = 0, top = 0, width = 32, height = 32 }, { left = 0, top = 0, width = 100, height = 25 })) + end) + + it("draws models without art as placeholders titled with their unit, and cleared models as nothing", function() + scene.adapter.Model = function(node) return node.model end + local model = scene.Node("PlayerModel", frame, { points = { { all = true } }, model = { unit = "focus" } }) + local svg = Render(nil, { image = Image, model = function() return "Interface\\Missing" end }) + assert.is_true(Has(svg, "model: focus")) + assert.is_true(Has(Render(), "model: focus")) + model.model = { displayId = 42 } + assert.is_true(Has(Render(), "model: display 42")) + model.model = { modelAlpha = 1 } + assert.is_false(Has(Render(), "")) + model.model = { unit = "focus", modelAlpha = 0 } + assert.is_false(Has(Render(), "<title>")) + scene.adapter.Model = nil + assert.is_true(Has(Render(), "<title>model: PlayerModel")) + end) + it("renders the same scene to the same SVG", function() scene.Node("StatusBar", frame, { points = { { all = true } }, bar = { min = 0, max = 3, value = 1 } }) scene.Node("FontString", frame, { points = { { point = "CENTER" } }, text = { text = "1/3" } }) From eba30492dff3d99efaf127b7ee062d8e127c81cc Mon Sep 17 00:00:00 2001 From: Martin Konstantin Herrmann Date: Mon, 9 Nov 2026 18:31:07 +0100 Subject: [PATCH 2/2] Prefer Classic preset portrait captures in UI proof Proof renders Forever's Classic (SD) preset by default and takes in-game portrait captures from a private folder (UF_PROOF_PORTRAITS, NAS over ssh) through the new wowproof remote_dir source, falling back to the HD TemporaryPortrait art. Model hooks can return a local { path }. --- DEVELOPMENT.md | 18 +++++++++---- tests/proof/setup.lua | 13 +++++++++ wowproof/README.md | 14 +++++++--- wowproof/init.lua | 21 +++++++++++---- wowproof/paint.lua | 8 +++++- wowproof/raster.lua | 1 + wowproof/sources/remote_dir.lua | 48 +++++++++++++++++++++++++++++++++ wowproof/spec/paint_spec.lua | 12 +++++++++ wowproof/spec/sources_spec.lua | 17 ++++++++++++ 9 files changed, 138 insertions(+), 14 deletions(-) create mode 100644 wowproof/sources/remote_dir.lua diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index dfe7e92..706c455 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -283,11 +283,19 @@ 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. -3D portraits (`PlayerModel`) can't be rendered headlessly, so -`Setup.Model` stands in Blizzard's static race portrait -(`Interface\CharacterFrame\TemporaryPortrait-Male-`) for the unit the -model shows, or the pet/monster portrait for non-players, from the same -mirror. It keeps the model's alpha, model alpha and dead/ghost desaturation. +3D portraits (`PlayerModel`) can't be rendered headlessly, so `Setup.Model` +stands in a picture for the unit the model shows, keeping the model's alpha, +model alpha and dead/ghost desaturation. Proof renders Forever's **Classic** +experience preset (original "SD" character models) by default; +`UF_PROOF_PRESET=enhanced` renders the HD one. For each preset it first looks +for an in-game capture of the default portrait, +`/-.png` (`Pet`/`Monster` for non-players), in the private +folder `UF_PROOF_PORTRAITS` (default `nas:/volume1/Game/unit-frames/proof-portraits`, +fetched over `ssh` into `.proof-art/portraits/`; also a local folder or an +HTTPS URL; skipped when `CI` is set or `UF_PROOF_ART_FETCH=0`). Captures are +Blizzard art: keep them in that folder, never in the repo. Without a capture +it falls back to Blizzard's static HD portrait +(`Interface\CharacterFrame\TemporaryPortrait-Male-`) from the mirror. Previews always show the player's own model (the portrait driver's sample is `"player"`), so every sample portrait is the mocked Human. `player-dead`, `focus-portrait` and `pet-portrait` cover the portraits that are off by diff --git a/tests/proof/setup.lua b/tests/proof/setup.lua index 738e329..fe54053 100644 --- a/tests/proof/setup.lua +++ b/tests/proof/setup.lua @@ -7,6 +7,7 @@ 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 RemoteDir = require("wowproof.sources.remote_dir") local Mock = Helpers.Mock @@ -19,6 +20,9 @@ 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 PRESETS = { classic = true, enhanced = true } +local PRESET = os.getenv("UF_PROOF_PRESET") or "classic" +local PORTRAIT_REMOTE = os.getenv("UF_PROOF_PORTRAITS") or "nas:/volume1/Game/unit-frames/proof-portraits" local PORTRAIT_ART = "Interface\\CharacterFrame\\TemporaryPortrait-" local PORTRAIT_SEX = "Male" local PORTRAIT_CROP = { 0.14, 0.86, 0.14, 0.86 } @@ -33,6 +37,13 @@ local blizzardArt = BlizzardArt({ token = os.getenv("GITHUB_TOKEN") or os.getenv("GH_TOKEN"), }) local clientFiles = ClientFiles({ build = ATLASES.build, dir = ART_DIR, fetch = ART_FETCH }) +local portraitCaptures = RemoteDir({ + remote = PORTRAIT_REMOTE, + dir = ART_DIR .. "/portraits", + fetch = ART_FETCH and os.getenv("CI") == nil, +}) + +if not PRESETS[PRESET] then error("UF_PROOF_PRESET must be classic or enhanced, not " .. PRESET) end local function AddonFile(path) if type(path) ~= "string" or path:lower():sub(1, #ADDON_PREFIX) ~= ADDON_PREFIX then return nil end @@ -68,6 +79,8 @@ function Setup.Model(info) else art = CREATURE_PORTRAITS[Plain(UnitCreatureType(unit))] or "Monster" end + local capture = portraitCaptures(PRESET .. "/" .. art .. ".png") + if capture then return { path = capture } end return { file = PORTRAIT_ART .. art, texCoords = PORTRAIT_CROP } end diff --git a/wowproof/README.md b/wowproof/README.md index 32eb388..b138ddd 100644 --- a/wowproof/README.md +++ b/wowproof/README.md @@ -82,8 +82,8 @@ the adapter's job. - 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 - **Models:** `PlayerModel` and the other model frames through `assets.models(info)`, which gets - the adapter's `Model(r)` and returns a texture path (resolved through `assets.textures`) or - `{ file, texCoords }`. The image covers the frame (centre-cropped to its aspect) at the frame's + the adapter's `Model(r)` and returns a texture path (resolved through `assets.textures`), + `{ file, texCoords }`, or `{ path, texCoords }` for a local image used as is. The image covers the frame (centre-cropped to its aspect) at the frame's alpha times the model alpha, desaturated by the model's desaturation. Without art it's a dashed placeholder titled `model: `; a cleared model draws nothing. - **Status bars and text:** status bar fills by value, and font strings with justification, outline and `|c` colour codes. @@ -133,7 +133,15 @@ assets.atlases = require("wowproof.sources.atlas_table")(pinnedAtlases) Tiling atlases draw once, not repeated, and flipbooks show their whole sheet. Models can't be rendered without the client, so a host maps them to stand-in -art, for example a race portrait for player units: +art. `wowproof.sources.remote_dir` copies named files once from a private +folder (`host:/dir` over `ssh`, an `https://` URL, or a local folder) into a +cache, for example in-game captures that must not live in the repository: + +```lua +local captures = require("wowproof.sources.remote_dir")({ remote = "nas:/srv/captures", dir = ".proof-art/captures" }) +``` + +A race portrait for player units, from the mirror: ```lua assets.models = function(info) diff --git a/wowproof/init.lua b/wowproof/init.lua index a27bfde..eacd11b 100644 --- a/wowproof/init.lua +++ b/wowproof/init.lua @@ -28,11 +28,10 @@ function Proof.New(options) }, Proof) end -function Proof:Image(file) - local cached = self.images[file] +local function LoadImage(self, key, locate) + local cached = self.images[key] if cached == nil then - local resolve = self.assets.textures - local localFile = resolve and resolve(file) + local localFile = locate() local png = localFile and Raster.ToPng(localFile, self.cacheDir) local uri = png and Raster.DataUri(png) cached = false @@ -40,12 +39,23 @@ function Proof:Image(file) local width, height = Raster.PngSize(png) cached = { uri = uri, width = width, height = height } end - self.images[file] = cached + self.images[key] = cached end if not cached then return nil end return cached.uri, cached.width, cached.height end +function Proof:Image(file) + return LoadImage(self, file, function() + local resolve = self.assets.textures + return resolve and resolve(file) + end) +end + +function Proof:File(path) + return LoadImage(self, "path:" .. path, function() return path end) +end + local function Pixel(value, size) return math.floor(value * size + 0.5) end @@ -104,6 +114,7 @@ function Proof:Render(region, options) debug = options.debug, background = options.background, image = function(file) return self:Image(file) end, + file = function(path) return self:File(path) end, atlas = function(name) return self:Atlas(name) end, font = function(file) return self:Font(file) end, model = function(info) return self.assets.models and self.assets.models(info) end, diff --git a/wowproof/paint.lua b/wowproof/paint.lua index 6243d5b..a4e3b4d 100644 --- a/wowproof/paint.lua +++ b/wowproof/paint.lua @@ -391,7 +391,12 @@ function Context:DrawModel(region, rect, alpha) if not subject or alpha <= 0 then return end local art = self.model(info) if type(art) == "string" then art = { file = art } end - local image = art and art.file and self:ImageDef(art.file, function() return self.image(art.file) end) + local image + if art and art.path then + image = self:ImageDef("path:" .. art.path, function() return self.file(art.path) end) + elseif art and art.file then + image = self:ImageDef(art.file, function() return self.image(art.file) end) + end if not image or not image.width then self:DrawPlaceholder(rect, alpha, "model: " .. subject) return @@ -487,6 +492,7 @@ function Paint.Render(options) atlas = options.atlas or function() return nil end, font = options.font or function() return nil end, model = options.model or function() return nil end, + file = options.file or function() return nil end, defs = {}, body = {}, images = {}, diff --git a/wowproof/raster.lua b/wowproof/raster.lua index c80e72c..54df107 100644 --- a/wowproof/raster.lua +++ b/wowproof/raster.lua @@ -112,6 +112,7 @@ local function NonEmpty(file) handle:close() return size > 0 end +Raster.NonEmpty = NonEmpty function Raster.Download(url, target, headers) Raster.MakeDir(target:match("^(.*)/[^/]+$") or ".") diff --git a/wowproof/sources/remote_dir.lua b/wowproof/sources/remote_dir.lua new file mode 100644 index 0000000..47b95a2 --- /dev/null +++ b/wowproof/sources/remote_dir.lua @@ -0,0 +1,48 @@ +local Raster = require("wowproof.raster") + +local function IsUrl(remote) + return remote:match("^https?://") ~= nil +end + +local function CopyCommand(remote, name, partial) + local host, dir = remote:match("^([%w%._@%-]+):(.+)$") + if host then + if not Raster.Has("ssh") then return nil end + return "ssh -o BatchMode=yes -o ConnectTimeout=5 " .. Raster.Quote(host) .. " " + .. Raster.Quote("cat " .. Raster.Quote(dir .. "/" .. name)) .. " > " .. Raster.Quote(partial) .. " 2>/dev/null" + end + return "cp " .. Raster.Quote(remote .. "/" .. name) .. " " .. Raster.Quote(partial) .. " 2>/dev/null" +end + +local function Copy(remote, name, target) + if IsUrl(remote) then + return Raster.Has("curl") and Raster.Download(remote .. "/" .. name, target) + end + Raster.MakeDir(target:match("^(.*)/[^/]+$") or ".") + local partial = target .. ".part" + local command = CopyCommand(remote, name, partial) + if not command or not Raster.Run(command) or not Raster.NonEmpty(partial) then + os.remove(partial) + return false + end + os.rename(partial, target) + return true +end + +return function(options) + options = options or {} + local remote = options.remote + local dir = options.dir or error("wowproof: give the remote folder a cache dir (dir)", 2) + local fetch = options.fetch ~= false and remote ~= nil and remote ~= "" + local tried = {} + + return function(name) + if type(name) ~= "string" or name:find("%.%.") or name:sub(1, 1) == "/" then return nil end + local cached = dir .. "/" .. name + if Raster.Exists(cached) then return cached end + if not fetch or tried[name] then return nil end + tried[name] = true + if not Copy((remote:gsub("/$", "")), name, cached) then return nil end + return cached + end +end diff --git a/wowproof/spec/paint_spec.lua b/wowproof/spec/paint_spec.lua index c72618c..7660037 100644 --- a/wowproof/spec/paint_spec.lua +++ b/wowproof/spec/paint_spec.lua @@ -233,6 +233,18 @@ describe("wowproof paint", function() Paint.CoverRect({ left = 0, top = 0, width = 32, height = 32 }, { left = 0, top = 0, width = 100, height = 25 })) end) + it("draws model art from a local file as is", function() + scene.adapter.Model = function(node) return node.model end + scene.Node("PlayerModel", frame, { points = { { all = true } }, model = { unit = "player" } }) + local function File(path) + if path == "captures/Male-Human.png" then return "data:image/png;base64,CA", 20, 20 end + end + local svg = Render(nil, { image = Image, file = File, model = function() return { path = "captures/Male-Human.png" } end }) + assert.is_true(Has(svg, 'href="data:image/png;base64,CA"')) + svg = Render(nil, { image = Image, model = function() return { path = "captures/Missing.png" } end }) + assert.is_true(Has(svg, "model: player")) + end) + it("draws models without art as placeholders titled with their unit, and cleared models as nothing", function() scene.adapter.Model = function(node) return node.model end local model = scene.Node("PlayerModel", frame, { points = { { all = true } }, model = { unit = "focus" } }) diff --git a/wowproof/spec/sources_spec.lua b/wowproof/spec/sources_spec.lua index 9aab545..fae0074 100644 --- a/wowproof/spec/sources_spec.lua +++ b/wowproof/spec/sources_spec.lua @@ -2,6 +2,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 RemoteDir = require("wowproof.sources.remote_dir") local REF = "abc123" @@ -56,6 +57,22 @@ describe("wowproof wow-ui-textures source", function() assert.is_nil(resolve("Interface\\Icons\\Spell_Holy_Renew")) end) + it("copies files from a remote folder into its cache once, and stays inside it", function() + Write(dir .. "/remote/classic/Male-Human.png", "png") + local cache = dir .. "/cache" + local resolve = RemoteDir({ remote = dir .. "/remote/", dir = cache }) + assert.equals(cache .. "/classic/Male-Human.png", resolve("classic/Male-Human.png")) + assert.equals("png", Raster.Read(cache .. "/classic/Male-Human.png")) + assert.is_nil(resolve("classic/Female-Orc.png")) + Write(dir .. "/remote/classic/Female-Orc.png", "png") + assert.is_nil(resolve("classic/Female-Orc.png")) + assert.is_nil(resolve("../remote/classic/Female-Orc.png")) + assert.is_nil(resolve("/etc/hostname")) + assert.equals(cache .. "/classic/Male-Human.png", RemoteDir({ dir = cache })("classic/Male-Human.png")) + assert.is_nil(RemoteDir({ dir = cache, remote = dir .. "/remote", fetch = false })("classic/Female-Orc.png")) + assert.has_error(function() RemoteDir({ remote = dir }) end) + end) + it("looks atlases up by name, case-insensitively like the client", function() local info = { file = 7526019 } local resolve = AtlasTable({ ["RaidFrame-Icon-Rez"] = info })