From 27eda0a2afc982401316fbc5f788b871adc24283 Mon Sep 17 00:00:00 2001 From: Jacob Coffee Date: Wed, 11 Nov 2026 12:18:57 -0600 Subject: [PATCH 1/4] feat: item tooltips show guild crafters even when they're offline --- .luacheckrc | 4 + SideQuest/UI/Tooltip.lua | 18 ++++ tests/test_tooltip_offline_crafters.lua | 107 ++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 tests/test_tooltip_offline_crafters.lua diff --git a/.luacheckrc b/.luacheckrc index b10f64a..e4214be 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -127,6 +127,10 @@ files["tests/test_auctions.lua"] = { globals = { "WowStub", "SideQuestDB", "TooltipDataProcessor", "Enum", "UIParent" }, } +files["tests/test_tooltip_offline_crafters.lua"] = { + globals = { "WowStub", "SideQuestDB", "TooltipDataProcessor", "Enum", "UIParent" }, +} + files["tests/test_minimap.lua"] = { globals = { "WowStub", "SideQuestDB" }, } diff --git a/SideQuest/UI/Tooltip.lua b/SideQuest/UI/Tooltip.lua index 1057f17..c592d54 100755 --- a/SideQuest/UI/Tooltip.lua +++ b/SideQuest/UI/Tooltip.lua @@ -103,6 +103,24 @@ local function onItemTooltip(tooltip, data) table.insert(crafters, hit) end end + -- Offline/imported crafters (contract SQI1 on-demand "crafters" + + -- "recipe_names", additive): a guildie who is offline or doesn't + -- run the addon still shows up here. The import carries recipe + -- ids, not item ids, so this matches by recipe name exactly the + -- same way the live WhoCrafts hits above were filtered. + local onDemand = SideQuestDB.onDemand + for _, row in ipairs((onDemand and onDemand.crafters) or {}) do + if not seen[row.character] then + for _, recipeId in ipairs(row.recipes or {}) do + local name = onDemand.recipe_names[tostring(recipeId)] + if name == itemName then + seen[row.character] = true + table.insert(crafters, { character = row.character }) + break + end + end + end + end if #crafters > 0 then table.insert(lines, "Crafted by " .. joinCapped(crafters, function(c) return shortName(c.character) end)) end diff --git a/tests/test_tooltip_offline_crafters.lua b/tests/test_tooltip_offline_crafters.lua new file mode 100644 index 0000000..91ad6a3 --- /dev/null +++ b/tests/test_tooltip_offline_crafters.lua @@ -0,0 +1,107 @@ +-- tests/test_tooltip_offline_crafters.lua +-- The item tooltip's "Crafted by" line folds in the site's SQI1 on-demand +-- "crafters" + "recipe_names" import (additive), so a guildie who is offline +-- or doesn't run the addon still shows up, deduplicated against live +-- WhoCrafts hits and matched by exact recipe name the same way. + +return function(h) + local test, assertTrue, resetAddon = h.test, h.assertTrue, h.resetAddon + + local function setupPlayer() + WowStub.realm = "Whitemane" + WowStub.SetUnit("player", { name = "Demo1", realm = "Whitemane", class = "PRIEST", guid = "Player-1-OFFL0001" }) + end + + local function tooltipLines(tooltip) + local out = {} + for _, line in ipairs(tooltip.lines) do + table.insert(out, line) + end + return out + end + + test("tooltip crafted-by: an offline/imported crafter with no addon shows up alongside a live one", function() + resetAddon() + setupPlayer() + WowStub.inCombat = false + WowStub.items = { [30001] = { name = "Runed Adamantite Rod" } } + + -- A live crafter the directory already knows about. + local profData = { professions = { { name = "Enchanting", skill = 300, max_skill = 300, recipes = { 7421 } } } } + SideQuestDB.directory["Live-Whitemane"] = { + prof = { v = SideQuest.Directory.Hash(profData), at = WowStub.time, d = profData }, + seen_at = WowStub.time, + } + -- WhoCrafts matches on recipe/profession name; its recipe name comes from C_Spell.GetSpellName. + WowStub.spellNames = { [7421] = "Runed Adamantite Rod" } + + -- An offline guildie who never ran the addon, known only from the site's SQI1 import. + SideQuestDB.onDemand.recipe_names = { ["7422"] = "Runed Adamantite Rod" } + SideQuestDB.onDemand.crafters = { + { character = "Offline-Whitemane", member_id = 5, profession = "Enchanting", skill = 285, + recipes = { 7422 } }, + } + + local callback = TooltipDataProcessor.callbacks[Enum.TooltipDataType.Item][1] + local tooltip = CreateFrame("GameTooltip", nil, UIParent) + callback(tooltip, { id = 30001 }) + + local line + for _, l in ipairs(tooltipLines(tooltip)) do + if l:find("^Crafted by") then + line = l + end + end + assertTrue(line ~= nil, "a Crafted by line appears") + assertTrue(line:find("Live") ~= nil, "the live crafter is listed") + assertTrue(line:find("Offline") ~= nil, "the offline/imported crafter is listed too") + end) + + test("tooltip crafted-by: the same character known both live and offline is listed once", function() + resetAddon() + setupPlayer() + WowStub.inCombat = false + WowStub.items = { [30002] = { name = "Glowing Brightwood Staff" } } + WowStub.spellNames = { [7777] = "Glowing Brightwood Staff" } + + local profData = { professions = { { name = "Enchanting", skill = 300, max_skill = 300, recipes = { 7777 } } } } + SideQuestDB.directory["Both-Whitemane"] = { + prof = { v = SideQuest.Directory.Hash(profData), at = WowStub.time, d = profData }, + seen_at = WowStub.time, + } + SideQuestDB.onDemand.recipe_names = { ["7777"] = "Glowing Brightwood Staff" } + SideQuestDB.onDemand.crafters = { + { character = "Both-Whitemane", member_id = 9, profession = "Enchanting", skill = 300, recipes = { 7777 } }, + } + + local callback = TooltipDataProcessor.callbacks[Enum.TooltipDataType.Item][1] + local tooltip = CreateFrame("GameTooltip", nil, UIParent) + callback(tooltip, { id = 30002 }) + + local count = 0 + for _, l in ipairs(tooltipLines(tooltip)) do + if l:find("^Crafted by") then + count = count + 1 + end + end + h.assertEq(count, 1, "exactly one Crafted by line, not one per source") + end) + + test("tooltip crafted-by: an on-demand recipe for a different item never matches", function() + resetAddon() + setupPlayer() + WowStub.inCombat = false + WowStub.items = { [30003] = { name = "Formula: Enchant Weapon - Fiery Weapon" } } + SideQuestDB.onDemand.recipe_names = { ["8001"] = "Enchant Weapon - Fiery Weapon" } -- the taught recipe, not the formula item + SideQuestDB.onDemand.crafters = { + { character = "Nobody-Whitemane", member_id = 1, profession = "Enchanting", skill = 200, recipes = { 8001 } }, + } + + local callback = TooltipDataProcessor.callbacks[Enum.TooltipDataType.Item][1] + local tooltip = CreateFrame("GameTooltip", nil, UIParent) + callback(tooltip, { id = 30003 }) + for _, l in ipairs(tooltipLines(tooltip)) do + assertTrue(not l:find("^Crafted by"), "a same-prefix recipe name is not an exact match") + end + end) +end From 01b5b1f354bd9767c55a474dd9cae48f3634377a Mon Sep 17 00:00:00 2001 From: Jacob Coffee Date: Wed, 11 Nov 2026 12:19:38 -0600 Subject: [PATCH 2/4] feat: item tooltips show how many guildies want an item on their wishlist --- .luacheckrc | 4 ++ README.md | 10 +++-- SideQuest/Market.lua | 3 +- SideQuest/Sync.lua | 2 +- SideQuest/UI/Tooltip.lua | 6 +++ tests/test_tooltip_wanted.lua | 80 +++++++++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 tests/test_tooltip_wanted.lua diff --git a/.luacheckrc b/.luacheckrc index e4214be..99d6f4d 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -131,6 +131,10 @@ files["tests/test_tooltip_offline_crafters.lua"] = { globals = { "WowStub", "SideQuestDB", "TooltipDataProcessor", "Enum", "UIParent" }, } +files["tests/test_tooltip_wanted.lua"] = { + globals = { "WowStub", "SideQuestDB", "TooltipDataProcessor", "Enum", "UIParent" }, +} + files["tests/test_minimap.lua"] = { globals = { "WowStub", "SideQuestDB" }, } diff --git a/README.md b/README.md index e3c8372..05eaa14 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,9 @@ The full rules and prices are on the [Ledger page](https://sidequest-guild.com/l | News | Guild announcements and recent activity. | Click someone on the Guild tab to see their level, spec, item level, professions, Onyxia attunement, tracked -reputations and cooldowns. Hover any item to see which guildmates craft, sell, buy or hold it, and the guild's -lowest auction-house price if a sync has priced it. +reputations and cooldowns; item level comes from the site's last sync when they haven't logged in with the addon +running. Hover any item to see which guildmates craft, sell, buy or hold it, how many have it on their wishlist, and +the guild's lowest auction-house price if a sync has priced it. Your event sign-ups reach the website the next time an officer syncs. You don't need to do anything else. @@ -67,8 +68,9 @@ were there. SideQuest keeps a record of your character and shares it with the guild automatically: your professions and skill, your level, class, spec and item level, your craft cooldowns, your Onyxia attunement and the few reputations the guild tracks, what you sell and want to buy, and the crafting materials in your bags and bank (never gold or gear). That's -how the Crafters and Market tabs work for guildmates who are offline, and officers' syncs carry it to the website, -where only signed-in guild members see it. +how the Crafters and Market tabs work for guildmates who are offline but have run the addon recently; a site sync +fills in the rest -- crafters, item level and wishlist counts -- for guildies who are offline or have never installed +it, and officers' syncs carry it to the website, where only signed-in guild members see it. Turn any part off on the You tab, or with `/sq share on|off`. `/sq dir` shows what you share and how many guildmates the addon has heard from. Open each profession window once so the guild knows your diff --git a/SideQuest/Market.lua b/SideQuest/Market.lua index 426b96f..2e9f42c 100755 --- a/SideQuest/Market.lua +++ b/SideQuest/Market.lua @@ -60,7 +60,8 @@ end --- The guild's lowest auction-house price for itemId from the last game -- import ("Game import" contract: SideQuestDB.prices), or nil when none is --- known. { p = unit_price copper, q = quantity, at = unix timestamp }. +-- known. { p = unit_price copper, q = quantity, at = unix timestamp, +-- w = distinct wishers (contract SQI1 `wanted`, additive; 0 on an old import) }. function Market.AuctionPrice(itemId) return SideQuestDB and SideQuestDB.prices and SideQuestDB.prices[itemId] end diff --git a/SideQuest/Sync.lua b/SideQuest/Sync.lua index 0292d7f..aa14cca 100755 --- a/SideQuest/Sync.lua +++ b/SideQuest/Sync.lua @@ -53,7 +53,7 @@ function Sync.ApplyImport(payload) if payload.prices ~= nil then local prices = {} for _, entry in ipairs(payload.prices) do - prices[entry.item_id] = { p = entry.unit_price, q = entry.quantity, at = entry.at } + prices[entry.item_id] = { p = entry.unit_price, q = entry.quantity, at = entry.at, w = entry.wanted or 0 } end SideQuestDB.prices = prices end diff --git a/SideQuest/UI/Tooltip.lua b/SideQuest/UI/Tooltip.lua index c592d54..e4a6e28 100755 --- a/SideQuest/UI/Tooltip.lua +++ b/SideQuest/UI/Tooltip.lua @@ -88,6 +88,12 @@ local function onItemTooltip(tooltip, data) if priceEntry then table.insert(lines, "Auction house: " .. moneyText(priceEntry.p) .. " (" .. (priceEntry.q or 0) .. " listed, " .. ago(priceEntry.at) .. ")") + -- Game import "prices" `wanted` (contract SQI1, additive): distinct + -- guild members with this item on their wishlist; absent/0 on an + -- old import or an unwished item, so this line just doesn't appear. + if (priceEntry.w or 0) > 0 then + table.insert(lines, "Wanted by " .. priceEntry.w .. (priceEntry.w == 1 and " guildie" or " guildies")) + end end -- Crafters: WhoCrafts matches by recipe name substring, so this only diff --git a/tests/test_tooltip_wanted.lua b/tests/test_tooltip_wanted.lua new file mode 100644 index 0000000..fdc5527 --- /dev/null +++ b/tests/test_tooltip_wanted.lua @@ -0,0 +1,80 @@ +-- tests/test_tooltip_wanted.lua +-- GameImportPrice.wanted (SQI1, additive): the number of distinct guild +-- members with an item on their wishlist. Sync.ApplyImport stores it +-- alongside the price as `w`, defaulting to 0 when the import omits it, and +-- the item tooltip shows a "Wanted by N guildies" line under the Auction +-- house line when it's above zero. + +return function(h) + local test, assertEq, assertTrue, resetAddon = h.test, h.assertEq, h.assertTrue, h.resetAddon + + local function setupPlayer() + WowStub.realm = "Whitemane" + WowStub.SetUnit("player", { name = "Demo1", realm = "Whitemane", class = "PRIEST", guid = "Player-1-WANT0001" }) + end + + local function sawLine(tooltip, text) + for _, line in ipairs(tooltip.lines) do + if line == text then + return true + end + end + return false + end + + test("import: GameImportPrice.wanted is stored as w, defaulting to 0 when the import omits it", function() + resetAddon() + setupPlayer() + local base = { v = 1, generated_at = WowStub.time, rules = nil, standings = {}, killed_encounters = {}, events = {} } + + local withWanted = {} + for k, v in pairs(base) do withWanted[k] = v end + withWanted.prices = { + { item_id = 111, unit_price = 100, quantity = 1, at = WowStub.time, wanted = 4 }, + { item_id = 222, unit_price = 200, quantity = 1, at = WowStub.time }, -- old-shaped entry, no wanted + } + SideQuest.Sync.ApplyImport(withWanted) + assertEq(SideQuestDB.prices[111].w, 4, "wanted carried through as w") + assertEq(SideQuestDB.prices[222].w, 0, "a price entry without wanted defaults to 0") + end) + + test("tooltip wanted line: shown under the Auction house line, singular for one, plural otherwise, absent at zero", function() + resetAddon() + setupPlayer() + WowStub.inCombat = false + + SideQuestDB.prices[14048] = { p = 12000, q = 35, at = WowStub.time - 3600, w = 1 } + local callback = TooltipDataProcessor.callbacks[Enum.TooltipDataType.Item][1] + local tooltip = CreateFrame("GameTooltip", nil, UIParent) + callback(tooltip, { id = 14048 }) + assertTrue(sawLine(tooltip, "Wanted by 1 guildie"), "singular wording for exactly one wisher") + + SideQuestDB.prices[14049] = { p = 500, q = 2, at = WowStub.time, w = 3 } + local tooltip2 = CreateFrame("GameTooltip", nil, UIParent) + callback(tooltip2, { id = 14049 }) + assertTrue(sawLine(tooltip2, "Wanted by 3 guildies"), "plural wording for more than one wisher") + + SideQuestDB.prices[14050] = { p = 100, q = 1, at = WowStub.time, w = 0 } + local tooltip3 = CreateFrame("GameTooltip", nil, UIParent) + callback(tooltip3, { id = 14050 }) + for _, l in ipairs(tooltip3.lines) do + assertTrue(not l:find("^Wanted by"), "no wanted line when nobody wants it") + end + end) + + test("tooltip wanted line: an import from before the `wanted` field existed shows no wanted line", function() + resetAddon() + setupPlayer() + WowStub.inCombat = false + + -- An old import stores prices without `w` at all (Sync.ApplyImport before this field existed). + SideQuestDB.prices[14048] = { p = 12000, q = 35, at = WowStub.time - 3600 } + local callback = TooltipDataProcessor.callbacks[Enum.TooltipDataType.Item][1] + local tooltip = CreateFrame("GameTooltip", nil, UIParent) + callback(tooltip, { id = 14048 }) + assertTrue(sawLine(tooltip, "Auction house: 1g 20s (35 listed, 1h ago)"), "the price line still shows") + for _, l in ipairs(tooltip.lines) do + assertTrue(not l:find("^Wanted by"), "no wanted line when the field was never imported") + end + end) +end From 003463c0b3564d69bd34913f2c0b416c37f1bfe9 Mon Sep 17 00:00:00 2001 From: Jacob Coffee Date: Wed, 11 Nov 2026 12:20:07 -0600 Subject: [PATCH 3/4] feat: Crafters > Professions lists guild members from the site even when they're offline --- .luacheckrc | 4 ++ README.md | 2 +- SideQuest/UI/Main.lua | 16 ++++++ tests/test_crafters_professions_offline.lua | 60 +++++++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/test_crafters_professions_offline.lua diff --git a/.luacheckrc b/.luacheckrc index 99d6f4d..e42dee3 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -135,6 +135,10 @@ files["tests/test_tooltip_wanted.lua"] = { globals = { "WowStub", "SideQuestDB", "TooltipDataProcessor", "Enum", "UIParent" }, } +files["tests/test_crafters_professions_offline.lua"] = { + globals = { "WowStub", "SideQuestDB" }, +} + files["tests/test_minimap.lua"] = { globals = { "WowStub", "SideQuestDB" }, } diff --git a/README.md b/README.md index 05eaa14..b76ba82 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ The full rules and prices are on the [Ledger page](https://sidequest-guild.com/l |---|---| | You | Your PR and where it ranks, your last four weeks of points, your next event with Going, Maybe and Can't buttons, and who's online. | | Guild | The roster, with alts under their main. Search it, filter by class, rank or online, and whisper or invite from it. Whisper opens a small SideQuest box: replies come back in chat as usual. Online guildmates show in green, offline in grey. | -| Crafters | Search a recipe or profession to see who can make it, online people first; every member with a profession and their skill; and who has Transmute, Mooncloth and other craft cooldowns ready. | +| Crafters | Search a recipe or profession to see who can make it, online people first; every member with a profession and their skill, including guildies who are offline or don't run the addon, from the site's last sync; and who has Transmute, Mooncloth and other craft cooldowns ready (addon-tracked members only). | | Market | What guildmates sell and want to buy, open requests for materials, and who holds an item, with the guild's lowest auction-house price next to each listing when one's known. Mine lists and edits your own. | | Events | Upcoming events, how many have signed up for each role, and your own answer, then the last 30 days' past events with how many went. | | Ledger | Everyone's EP, GP and PR, then your own points history and loot. | diff --git a/SideQuest/UI/Main.lua b/SideQuest/UI/Main.lua index 30aa38b..0c94fc5 100755 --- a/SideQuest/UI/Main.lua +++ b/SideQuest/UI/Main.lua @@ -2425,6 +2425,22 @@ function UI.RefreshCraftersProfessions() end local members = SideQuest.Directory.ByProfession(chamber.profession) or {} + -- Offline/imported crafters (contract SQI1 on-demand "crafters", + -- additive): a character+profession the live directory already has + -- wins (fresher skill, recipe counts, online state); the import only + -- fills in characters/professions the directory hasn't seen at all. + -- Cooldowns stay live-only -- the import carries none. + local seenKey = {} + for _, m in ipairs(members) do + seenKey[m.character .. "\0" .. (m.profession or "")] = true + end + for _, row in ipairs((SideQuestDB.onDemand and SideQuestDB.onDemand.crafters) or {}) do + local key = row.character .. "\0" .. (row.profession or "") + if not seenKey[key] and (chamber.profession == nil or row.profession == chamber.profession) then + seenKey[key] = true + table.insert(members, { character = row.character, profession = row.profession, skill = row.skill, online = false }) + end + end table.sort(members, function(a, b) local aOnline, bOnline = a.online and true or false, b.online and true or false if aOnline ~= bOnline then return aOnline end diff --git a/tests/test_crafters_professions_offline.lua b/tests/test_crafters_professions_offline.lua new file mode 100644 index 0000000..812ad55 --- /dev/null +++ b/tests/test_crafters_professions_offline.lua @@ -0,0 +1,60 @@ +-- tests/test_crafters_professions_offline.lua +-- The Crafters tab's Professions view folds the site's SQI1 on-demand +-- "crafters" import (additive) into Directory.ByProfession's live results, +-- so a guildie who is offline or doesn't run the addon still shows up, +-- marked offline the same way the Search sub-tab marks it, and never +-- duplicating a character+profession the live directory already has. + +return function(h) + local test, assertEq, assertTrue, resetAddon = h.test, h.assertEq, h.assertTrue, h.resetAddon + + local function setupPlayer() + WowStub.realm = "Whitemane" + WowStub.SetUnit("player", { name = "Demo1", realm = "Whitemane", class = "PRIEST", guid = "Player-1-CPRO0001" }) + end + + test("crafters Professions view: an on-demand crafter appears marked offline, deduped against a live match", function() + resetAddon() + setupPlayer() + WowStub.inCombat = false + + local profData = { professions = { { name = "Blacksmithing", skill = 300, max_skill = 300 } } } + SideQuestDB.directory["Live-Whitemane"] = { + prof = { v = SideQuest.Directory.Hash(profData), at = WowStub.time, d = profData }, + seen_at = WowStub.time, + } + SideQuestDB.roster = { taken_at = WowStub.time, members = { + { character = "Live-Whitemane", online = true, rank = "Member" }, + } } + + SideQuestDB.onDemand.crafters = { + -- Same character+profession the directory already has: must not duplicate. + { character = "Live-Whitemane", member_id = 1, profession = "Blacksmithing", skill = 299, recipes = {} }, + -- A guildie the live directory has never heard from. + { character = "Offline-Whitemane", member_id = 2, profession = "Blacksmithing", skill = 280, recipes = {} }, + } + + SideQuest.UI.main = nil + SideQuest.UI.Show() + SideQuest.UI.ShowTab("Crafters") + local chamber = SideQuest.UI.panels.Crafters.professionsChamber + chamber.profession = nil + SideQuest.UI.RefreshCraftersProfessions() + + local liveCount, offlineRow = 0, nil + for i = 1, #chamber.rows do + local row = chamber.rows[i] + if row:IsShown() then + local name = row.nameRow.nameFS:GetText() + if name and name:find("Live") then + liveCount = liveCount + 1 + elseif name and name:find("Offline") then + offlineRow = row + end + end + end + assertEq(liveCount, 1, "the live character appears exactly once, not duplicated by the import") + assertTrue(offlineRow ~= nil, "the offline/imported crafter appears too") + assertTrue(offlineRow.lastSeenText:GetText() ~= "Online", "the imported crafter is marked offline, not online") + end) +end From e31e27b479199f981f1cf5fb50c1878d4b03f561 Mon Sep 17 00:00:00 2001 From: Jacob Coffee Date: Wed, 11 Nov 2026 12:20:14 -0600 Subject: [PATCH 4/4] feat: Guild tab shows item level from the site import when a member hasn't logged in --- .luacheckrc | 4 ++ SideQuest/UI/Main.lua | 19 +++++- tests/test_guild_item_level_import.lua | 86 ++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 tests/test_guild_item_level_import.lua diff --git a/.luacheckrc b/.luacheckrc index e42dee3..f0508b3 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -139,6 +139,10 @@ files["tests/test_crafters_professions_offline.lua"] = { globals = { "WowStub", "SideQuestDB" }, } +files["tests/test_guild_item_level_import.lua"] = { + globals = { "WowStub", "SideQuestDB" }, +} + files["tests/test_minimap.lua"] = { globals = { "WowStub", "SideQuestDB" }, } diff --git a/SideQuest/UI/Main.lua b/SideQuest/UI/Main.lua index 0c94fc5..caeddd6 100755 --- a/SideQuest/UI/Main.lua +++ b/SideQuest/UI/Main.lua @@ -1637,6 +1637,22 @@ local function buildGuildDetail(content) return block end +--- A character's equipped item level from the last site import ("Game +-- import" contract GameImportCharacter.item_level, additive): nil when +-- the import has no entry for them, or when an import predating the +-- field is all the addon has. Only consulted when the live directory +-- hasn't scanned this character's gear yet. +local function importItemLevel(character) + for _, member in ipairs((SideQuestDB.guild and SideQuestDB.guild.members) or {}) do + for _, char in ipairs(member.characters or {}) do + if char.name == character then + return char.item_level + end + end + end + return nil +end + --- Fills `block` with `character`'s directory record and returns the -- height it used, so the caller can offset rows below it. function UI.PaintGuildDetail(block, character) @@ -1650,7 +1666,8 @@ function UI.PaintGuildDetail(block, character) local metaParts = {} if charData and charData.level then table.insert(metaParts, "Level " .. charData.level) end if charData and charData.spec then table.insert(metaParts, charData.spec) end - if charData and charData.item_level then table.insert(metaParts, "ilvl " .. string.format("%.1f", charData.item_level)) end + local ilvl = (charData and charData.item_level) or importItemLevel(character) + if ilvl then table.insert(metaParts, "ilvl " .. string.format("%.1f", ilvl)) end block.metaText:SetText(table.concat(metaParts, " -- ")) local freshness = recordFreshness(entry) setStateText(block.freshnessText, freshness and ("Record " .. ago(freshness)) or "No directory record yet", not freshness) diff --git a/tests/test_guild_item_level_import.lua b/tests/test_guild_item_level_import.lua new file mode 100644 index 0000000..e845d94 --- /dev/null +++ b/tests/test_guild_item_level_import.lua @@ -0,0 +1,86 @@ +-- tests/test_guild_item_level_import.lua +-- GameImportCharacter.item_level (SQI1, additive): the Guild tab's member +-- detail falls back to it when the live directory hasn't scanned that +-- character's gear. A live scan always wins over the import, and an import +-- from before the field existed leaves the detail panel working exactly as +-- before (no ilvl shown, no error). + +return function(h) + local test, assertTrue, resetAddon = h.test, h.assertTrue, h.resetAddon + + local function setupPlayer() + WowStub.realm = "Whitemane" + WowStub.SetUnit("player", { name = "Demo1", realm = "Whitemane", class = "PRIEST", guid = "Player-1-GILV0001" }) + end + + local function openGuildDetail(character) + SideQuest.UI.main = nil + SideQuest.UI.Show() + SideQuest.UI.ShowTab("Guild") + local chamber = SideQuest.UI.panels.Guild.chamber + chamber.selectedCharacter = character + SideQuest.UI.RefreshGuild() + return chamber.detailBlock + end + + test("guild detail: item_level comes from the import when the live directory has none", function() + resetAddon() + setupPlayer() + WowStub.inCombat = false + SideQuestDB.roster = { taken_at = WowStub.time, members = { + { character = "Imported-Whitemane", online = true, rank = "Member" }, + } } + SideQuestDB.guild.members = { + { member_id = 1, name = "Imported", main = "Imported-Whitemane", class = "WARRIOR", rank = "Member", + raid_status = nil, guild_ep = 0, attendance_rate = 0, events_attended = 0, badges = {}, + characters = { { name = "Imported-Whitemane", class = "WARRIOR", level = 60, is_main = true, + item_level = 650 } } }, + } + + local block = openGuildDetail("Imported-Whitemane") + assertTrue(block.metaText:GetText():find("ilvl 650") ~= nil, "shows the import's item level") + end) + + test("guild detail: a live directory scan's item_level wins over the import", function() + resetAddon() + setupPlayer() + WowStub.inCombat = false + local charData = { level = 60, item_level = 700.0 } + SideQuestDB.directory["Fresher-Whitemane"] = { + char = { v = SideQuest.Directory.Hash(charData), at = WowStub.time, d = charData }, + seen_at = WowStub.time, + } + SideQuestDB.roster = { taken_at = WowStub.time, members = { + { character = "Fresher-Whitemane", online = true, rank = "Member" }, + } } + SideQuestDB.guild.members = { + { member_id = 2, name = "Fresher", main = "Fresher-Whitemane", class = "WARRIOR", rank = "Member", + raid_status = nil, guild_ep = 0, attendance_rate = 0, events_attended = 0, badges = {}, + characters = { { name = "Fresher-Whitemane", class = "WARRIOR", level = 60, is_main = true, + item_level = 500 } } }, -- stale import value + } + + local block = openGuildDetail("Fresher-Whitemane") + assertTrue(block.metaText:GetText():find("ilvl 700") ~= nil, "shows the fresher live scan, not the stale import") + end) + + test("guild detail: an import from before item_level existed shows no ilvl, without erroring", function() + resetAddon() + setupPlayer() + WowStub.inCombat = false + SideQuestDB.roster = { taken_at = WowStub.time, members = { + { character = "Old-Whitemane", online = true, rank = "Member" }, + } } + SideQuestDB.guild.members = { + -- Old-shaped GameImportCharacter: no item_level key at all. + { member_id = 3, name = "Old", main = "Old-Whitemane", class = "WARRIOR", rank = "Member", + raid_status = nil, guild_ep = 0, attendance_rate = 0, events_attended = 0, badges = {}, + characters = { { name = "Old-Whitemane", class = "WARRIOR", level = 60, is_main = true } } }, + } + + local ok, block = pcall(openGuildDetail, "Old-Whitemane") + assertTrue(ok, "painting the detail panel for an old-shaped import doesn't error") + assertTrue(block:IsShown(), "the detail block actually painted (sanity check)") + assertTrue(not block.metaText:GetText():find("ilvl"), "no ilvl shown when neither source has one") + end) +end