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
@@ -587,10 +587,30 @@ function ns.UI.ToggleFrame()
|
||||
end
|
||||
else
|
||||
MainFrame:Show()
|
||||
Amibis._statsRetryAttempts = nil
|
||||
ns.UI.RefreshUI()
|
||||
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()
|
||||
if not MainFrame or not MainFrame:IsShown() then
|
||||
return
|
||||
@@ -629,13 +649,14 @@ function ns.UI.RefreshUI()
|
||||
|
||||
if PhaseBar then
|
||||
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
|
||||
if PhaseProgressFill then
|
||||
PhaseProgressFill:SetWidth(math.max(1, PhaseBar:GetWidth() * ratio))
|
||||
end
|
||||
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
|
||||
|
||||
@@ -727,22 +748,6 @@ function ns.UI.RefreshUI()
|
||||
vals.diff:SetText("")
|
||||
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
|
||||
if StatsPanelTitle then
|
||||
StatsPanelTitle:SetText("Stats Comparison")
|
||||
@@ -801,6 +806,14 @@ function ns.UI.RefreshUI()
|
||||
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
|
||||
|
||||
local initFrame = CreateFrame("Frame")
|
||||
|
||||
Reference in new issue
Block a user