Keep latest-phase progress independent of the selected phase
The bar could change when switching phases: latestCompletionRatio was nil until the selected phase's stats were complete AND the latest list was cached, and the UI then fell back to the selected phase's own completion ratio. Right after login the latest list's items are often not cached yet, so switching phases visibly moved the bar. Always compute a latest-phase ratio inside CompareGear: stats-based when both the latest list and the equipped items are cached, otherwise slot completion against the latest list. Return latestStatsComplete so the UI can mark the estimate with "~" and keep retrying until stats load (capped at 20 attempts). The UI now uses latestCompletionRatio directly instead of falling back to the selected phase. Also refresh on PLAYER_EQUIPMENT_CHANGED so gear swaps update the bar. Tests: phase-independent ratio, slot-based fallback while the latest list is uncached, and equal ratios across selected phases once cached. 106 passing.
This commit is contained in:
1 parent
b66491c5be
commit
5fba4ac10c
4 files changed
+142
-35
No files matched your search
@@ -41,4 +41,5 @@ Amibis/
|
|||||||
- Color coding: green = BIS, yellow = upgrade available, gray = empty slot
|
- Color coding: green = BIS, yellow = upgrade available, gray = empty slot
|
||||||
- Max 17 visible rows; rows are clickable (Shift+click = chat link, Ctrl+click = dress-up)
|
- Max 17 visible rows; rows are clickable (Shift+click = chat link, Ctrl+click = dress-up)
|
||||||
- Stats panel is **per-spec**: `SPEC_STAT_PROFILES` in `Amibis.lua` defines an ordered `{ stat, weight }` list for every class/spec (casters see spell damage/hit/crit/haste, melee see strength/AP/hit/expertise/armor pen, tanks see stamina/defense/dodge/parry/block, healers see healing/spirit/mp5). The same weights rank top upgrades, score completion, and pick which two gains are shown in the upgrade line. Keep profiles to 8 rows so the panel fits the frame.
|
- Stats panel is **per-spec**: `SPEC_STAT_PROFILES` in `Amibis.lua` defines an ordered `{ stat, weight }` list for every class/spec (casters see spell damage/hit/crit/haste, melee see strength/AP/hit/expertise/armor pen, tanks see stamina/defense/dodge/parry/block, healers see healing/spirit/mp5). The same weights rank top upgrades, score completion, and pick which two gains are shown in the upgrade line. Keep profiles to 8 rows so the panel fits the frame.
|
||||||
|
- The phase-progress bar always measures the **latest** phase, independent of the selected phase: stats-based once item data is cached, slot-based (prefixed `~`) until then. It refreshes on talent and equipment changes.
|
||||||
- Stat values are read via `STAT_MAP` (WoW `GetItemStats` keys → internal stat names); TBC's per-school hit/crit/haste keys are all mapped to one internal stat.
|
- Stat values are read via `STAT_MAP` (WoW `GetItemStats` keys → internal stat names); TBC's per-school hit/crit/haste keys are all mapped to one internal stat.
|
||||||
+38
-15
@@ -502,28 +502,49 @@ function Amibis:CompareGear()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local latestPhase = ns.Data.BISLists:GetLatestPhase(class, spec)
|
local latestPhase = ns.Data.BISLists:GetLatestPhase(class, spec)
|
||||||
local latestCompletionRatio = nil
|
local latestCompletionRatio = 0
|
||||||
if latestPhase and statsComplete then
|
local latestStatsComplete = false
|
||||||
|
if latestPhase then
|
||||||
local latestList = ns.Data.BISLists:GetBISList(class, spec, latestPhase)
|
local latestList = ns.Data.BISLists:GetBISList(class, spec, latestPhase)
|
||||||
if latestList then
|
if latestList then
|
||||||
local latestStatsComplete = true
|
-- The bar always measures the latest phase, so it must not depend on
|
||||||
|
-- which phase is selected. Warm the cache for the latest list and the
|
||||||
|
-- equipped items, then use stats when available and fall back to slot
|
||||||
|
-- completion (still latest-phase based) while item data is loading.
|
||||||
|
local latestItems = {}
|
||||||
|
local latestItemsCached = true
|
||||||
for slotName, bisItem in pairs(latestList) do
|
for slotName, bisItem in pairs(latestList) do
|
||||||
|
latestItems[slotName] = { itemID = bisItem.itemID }
|
||||||
if not GetItemInfo(bisItem.itemID) then
|
if not GetItemInfo(bisItem.itemID) then
|
||||||
latestStatsComplete = false
|
latestItemsCached = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local equippedCached = true
|
||||||
|
for _, item in pairs(equipped) do
|
||||||
|
if item and item.itemID and not GetItemInfo(item.itemID) then
|
||||||
|
equippedCached = false
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if latestStatsComplete then
|
|
||||||
if latestPhase == phase then
|
if latestItemsCached and equippedCached then
|
||||||
latestCompletionRatio = self:StatRatio(equippedStats, bisStats, class, spec)
|
local latestStats = bisStats
|
||||||
else
|
if latestPhase ~= phase then
|
||||||
local latestItems = {}
|
latestStats = self:AggregateStats(latestItems)
|
||||||
for slotName, bisItem in pairs(latestList) do
|
|
||||||
latestItems[slotName] = { itemID = bisItem.itemID }
|
|
||||||
end
|
|
||||||
local latestStats = self:AggregateStats(latestItems)
|
|
||||||
latestCompletionRatio = self:StatRatio(equippedStats, latestStats, class, spec)
|
|
||||||
end
|
end
|
||||||
|
latestCompletionRatio = self:StatRatio(equippedStats, latestStats, class, spec)
|
||||||
|
latestStatsComplete = true
|
||||||
|
else
|
||||||
|
local matched, total = 0, 0
|
||||||
|
for slotName, bisItem in pairs(latestList) do
|
||||||
|
total = total + 1
|
||||||
|
local equippedItem = equipped[slotName]
|
||||||
|
if equippedItem and equippedItem.itemID == bisItem.itemID then
|
||||||
|
matched = matched + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
latestCompletionRatio = total > 0 and (matched / total) or 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -542,6 +563,7 @@ function Amibis:CompareGear()
|
|||||||
statsComplete = statsComplete,
|
statsComplete = statsComplete,
|
||||||
latestPhase = latestPhase,
|
latestPhase = latestPhase,
|
||||||
latestCompletionRatio = latestCompletionRatio,
|
latestCompletionRatio = latestCompletionRatio,
|
||||||
|
latestStatsComplete = latestStatsComplete,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -583,6 +605,7 @@ local eventFrame = CreateFrame("Frame")
|
|||||||
eventFrame:RegisterEvent("ADDON_LOADED")
|
eventFrame:RegisterEvent("ADDON_LOADED")
|
||||||
eventFrame:RegisterEvent("PLAYER_LOGIN")
|
eventFrame:RegisterEvent("PLAYER_LOGIN")
|
||||||
eventFrame:RegisterEvent("PLAYER_TALENT_UPDATE")
|
eventFrame:RegisterEvent("PLAYER_TALENT_UPDATE")
|
||||||
|
eventFrame:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
|
||||||
|
|
||||||
eventFrame:SetScript("OnEvent", function(self, event, ...)
|
eventFrame:SetScript("OnEvent", function(self, event, ...)
|
||||||
if event == "ADDON_LOADED" then
|
if event == "ADDON_LOADED" then
|
||||||
@@ -592,7 +615,7 @@ eventFrame:SetScript("OnEvent", function(self, event, ...)
|
|||||||
end
|
end
|
||||||
elseif event == "PLAYER_LOGIN" then
|
elseif event == "PLAYER_LOGIN" then
|
||||||
Amibis:InitializeUI()
|
Amibis:InitializeUI()
|
||||||
elseif event == "PLAYER_TALENT_UPDATE" then
|
elseif event == "PLAYER_TALENT_UPDATE" or event == "PLAYER_EQUIPMENT_CHANGED" then
|
||||||
if ns.UI and ns.UI.RefreshUI then
|
if ns.UI and ns.UI.RefreshUI then
|
||||||
ns.UI.RefreshUI()
|
ns.UI.RefreshUI()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -303,10 +303,12 @@ describe("latest phase progress", function()
|
|||||||
AmibisCharDB.overrideSpec = "Shadow"
|
AmibisCharDB.overrideSpec = "Shadow"
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("exposes the latest phase and nil ratio while stats load", function()
|
it("reports the latest phase and an estimate while stats load", function()
|
||||||
local data = ns.Amibis:CompareGear()
|
local data = ns.Amibis:CompareGear()
|
||||||
expect(data.latestPhase).toEqual("ZA")
|
expect(data.latestPhase).toEqual("ZA")
|
||||||
expect(data.latestCompletionRatio).toBeNil()
|
expect(data.latestStatsComplete).toBeFalsy()
|
||||||
|
expect(type(data.latestCompletionRatio)).toEqual("number")
|
||||||
|
expect(data.latestCompletionRatio).toEqual(0)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("measures progress against the latest phase, not the selected one", function()
|
it("measures progress against the latest phase, not the selected one", function()
|
||||||
@@ -349,3 +351,71 @@ describe("latest phase progress", function()
|
|||||||
expect(data.latestPhase).toEqual("ZA")
|
expect(data.latestPhase).toEqual("ZA")
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe("latest phase progress is independent of the selected phase", function()
|
||||||
|
before_each(function()
|
||||||
|
MockItems = {}
|
||||||
|
MockEquipped = {}
|
||||||
|
AmibisCharDB.overrideSpec = "Shadow"
|
||||||
|
AmibisDB.selectedPhase = "T4"
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("falls back to latest-phase slot completion when the latest list is not cached", function()
|
||||||
|
local t4 = ns.Data.BISLists:GetBISList("PRIEST", "Shadow", "T4")
|
||||||
|
local za = ns.Data.BISLists:GetBISList("PRIEST", "Shadow", "ZA")
|
||||||
|
|
||||||
|
-- Make the selected phase look fully cached, but leave the ZA list uncached.
|
||||||
|
for _, entry in pairs(t4) do
|
||||||
|
MockItems[entry.itemID] = {
|
||||||
|
name = entry.name,
|
||||||
|
stats = {
|
||||||
|
["ITEM_MOD_INTELLECT_SHORT"] = 100,
|
||||||
|
["ITEM_MOD_SPELL_DAMAGE_DONE_SHORT"] = 50,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Equip two ZA BIS pieces without caching the rest of the list.
|
||||||
|
equip("Head", za["Head"].itemID)
|
||||||
|
equip("Shoulder", za["Shoulder"].itemID)
|
||||||
|
|
||||||
|
local total = 0
|
||||||
|
for _ in pairs(za) do total = total + 1 end
|
||||||
|
|
||||||
|
local data = ns.Amibis:CompareGear()
|
||||||
|
expect(data.latestPhase).toEqual("ZA")
|
||||||
|
expect(data.latestStatsComplete).toBeFalsy()
|
||||||
|
expect(data.latestCompletionRatio).toBeCloseTo(2 / total)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("reports the same ratio for every selected phase once stats are cached", function()
|
||||||
|
for _, phase in ipairs({ "T4", "T5", "T6", "ZA" }) do
|
||||||
|
for _, entry in pairs(ns.Data.BISLists:GetBISList("PRIEST", "Shadow", phase)) do
|
||||||
|
MockItems[entry.itemID] = {
|
||||||
|
name = entry.name,
|
||||||
|
stats = {
|
||||||
|
["ITEM_MOD_INTELLECT_SHORT"] = 100,
|
||||||
|
["ITEM_MOD_SPELL_DAMAGE_DONE_SHORT"] = 50,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local t6 = ns.Data.BISLists:GetBISList("PRIEST", "Shadow", "T6")
|
||||||
|
for slot, entry in pairs(t6) do
|
||||||
|
equip(slot, entry.itemID)
|
||||||
|
end
|
||||||
|
|
||||||
|
local results = {}
|
||||||
|
for _, phase in ipairs({ "T4", "T5", "T6", "ZA" }) do
|
||||||
|
AmibisDB.selectedPhase = phase
|
||||||
|
local data = ns.Amibis:CompareGear()
|
||||||
|
expect(data.latestStatsComplete).toBeTruthy()
|
||||||
|
table.insert(results, data.latestCompletionRatio)
|
||||||
|
end
|
||||||
|
|
||||||
|
for i = 2, #results do
|
||||||
|
expect(results[i]).toBeCloseTo(results[1])
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
@@ -587,10 +587,30 @@ function ns.UI.ToggleFrame()
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
MainFrame:Show()
|
MainFrame:Show()
|
||||||
|
Amibis._statsRetryAttempts = nil
|
||||||
ns.UI.RefreshUI()
|
ns.UI.RefreshUI()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function ScheduleStatsRefresh()
|
||||||
|
if Amibis._statsRetryTimer then return end
|
||||||
|
Amibis._statsRetryAttempts = (Amibis._statsRetryAttempts or 0) + 1
|
||||||
|
if Amibis._statsRetryAttempts > 20 then return end
|
||||||
|
Amibis._statsRetryTimer = CreateFrame("Frame")
|
||||||
|
Amibis._statsRetryTimer.elapsed = 0
|
||||||
|
Amibis._statsRetryTimer:SetScript("OnUpdate", function(self, elapsed)
|
||||||
|
self.elapsed = self.elapsed + elapsed
|
||||||
|
if self.elapsed >= 1.5 then
|
||||||
|
self:Hide()
|
||||||
|
Amibis._statsRetryTimer = nil
|
||||||
|
if MainFrame and MainFrame:IsShown() then
|
||||||
|
ns.UI.RefreshUI()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
Amibis._statsRetryTimer:Show()
|
||||||
|
end
|
||||||
|
|
||||||
function ns.UI.RefreshUI()
|
function ns.UI.RefreshUI()
|
||||||
if not MainFrame or not MainFrame:IsShown() then
|
if not MainFrame or not MainFrame:IsShown() then
|
||||||
return
|
return
|
||||||
@@ -629,13 +649,14 @@ function ns.UI.RefreshUI()
|
|||||||
|
|
||||||
if PhaseBar then
|
if PhaseBar then
|
||||||
RebuildPhaseButtons(data.class, data.spec, data.phase)
|
RebuildPhaseButtons(data.class, data.spec, data.phase)
|
||||||
local ratio = data.latestCompletionRatio or Amibis:GetCompletionRatio(data)
|
local ratio = data.latestCompletionRatio or 0
|
||||||
local targetPhase = data.latestPhase or data.phase
|
local targetPhase = data.latestPhase or data.phase
|
||||||
if PhaseProgressFill then
|
if PhaseProgressFill then
|
||||||
PhaseProgressFill:SetWidth(math.max(1, PhaseBar:GetWidth() * ratio))
|
PhaseProgressFill:SetWidth(math.max(1, PhaseBar:GetWidth() * ratio))
|
||||||
end
|
end
|
||||||
if PhaseProgressText then
|
if PhaseProgressText then
|
||||||
PhaseProgressText:SetText(string.format("%d%% to %s", math.floor(ratio * 100 + 0.5), targetPhase))
|
local prefix = data.latestStatsComplete == false and "~" or ""
|
||||||
|
PhaseProgressText:SetText(string.format("%s%d%% to %s", prefix, math.floor(ratio * 100 + 0.5), targetPhase))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -727,22 +748,6 @@ function ns.UI.RefreshUI()
|
|||||||
vals.diff:SetText("")
|
vals.diff:SetText("")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not Amibis._statsRetryTimer then
|
|
||||||
Amibis._statsRetryTimer = CreateFrame("Frame")
|
|
||||||
Amibis._statsRetryTimer.elapsed = 0
|
|
||||||
Amibis._statsRetryTimer:SetScript("OnUpdate", function(self, elapsed)
|
|
||||||
self.elapsed = self.elapsed + elapsed
|
|
||||||
if self.elapsed >= 1.5 then
|
|
||||||
self:Hide()
|
|
||||||
Amibis._statsRetryTimer = nil
|
|
||||||
if MainFrame and MainFrame:IsShown() then
|
|
||||||
ns.UI.RefreshUI()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
Amibis._statsRetryTimer:Show()
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
if StatsPanelTitle then
|
if StatsPanelTitle then
|
||||||
StatsPanelTitle:SetText("Stats Comparison")
|
StatsPanelTitle:SetText("Stats Comparison")
|
||||||
@@ -801,6 +806,14 @@ function ns.UI.RefreshUI()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Keep retrying until both the selected list and the latest-phase progress
|
||||||
|
-- have item stats; otherwise the bar can be stuck on the slot estimate.
|
||||||
|
if not data.statsComplete or data.latestStatsComplete == false then
|
||||||
|
ScheduleStatsRefresh()
|
||||||
|
else
|
||||||
|
Amibis._statsRetryAttempts = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local initFrame = CreateFrame("Frame")
|
local initFrame = CreateFrame("Frame")
|
||||||
|
|||||||
Reference in new issue
Block a user