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
+38
-15
@@ -502,28 +502,49 @@ function Amibis:CompareGear()
|
||||
end
|
||||
|
||||
local latestPhase = ns.Data.BISLists:GetLatestPhase(class, spec)
|
||||
local latestCompletionRatio = nil
|
||||
if latestPhase and statsComplete then
|
||||
local latestCompletionRatio = 0
|
||||
local latestStatsComplete = false
|
||||
if latestPhase then
|
||||
local latestList = ns.Data.BISLists:GetBISList(class, spec, latestPhase)
|
||||
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
|
||||
latestItems[slotName] = { itemID = bisItem.itemID }
|
||||
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
|
||||
end
|
||||
end
|
||||
if latestStatsComplete then
|
||||
if latestPhase == phase then
|
||||
latestCompletionRatio = self:StatRatio(equippedStats, bisStats, class, spec)
|
||||
else
|
||||
local 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)
|
||||
|
||||
if latestItemsCached and equippedCached then
|
||||
local latestStats = bisStats
|
||||
if latestPhase ~= phase then
|
||||
latestStats = self:AggregateStats(latestItems)
|
||||
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
|
||||
@@ -542,6 +563,7 @@ function Amibis:CompareGear()
|
||||
statsComplete = statsComplete,
|
||||
latestPhase = latestPhase,
|
||||
latestCompletionRatio = latestCompletionRatio,
|
||||
latestStatsComplete = latestStatsComplete,
|
||||
}
|
||||
end
|
||||
|
||||
@@ -583,6 +605,7 @@ local eventFrame = CreateFrame("Frame")
|
||||
eventFrame:RegisterEvent("ADDON_LOADED")
|
||||
eventFrame:RegisterEvent("PLAYER_LOGIN")
|
||||
eventFrame:RegisterEvent("PLAYER_TALENT_UPDATE")
|
||||
eventFrame:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
|
||||
|
||||
eventFrame:SetScript("OnEvent", function(self, event, ...)
|
||||
if event == "ADDON_LOADED" then
|
||||
@@ -592,7 +615,7 @@ eventFrame:SetScript("OnEvent", function(self, event, ...)
|
||||
end
|
||||
elseif event == "PLAYER_LOGIN" then
|
||||
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
|
||||
ns.UI.RefreshUI()
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user