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
@@ -303,10 +303,12 @@ describe("latest phase progress", function()
|
||||
AmibisCharDB.overrideSpec = "Shadow"
|
||||
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()
|
||||
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)
|
||||
|
||||
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")
|
||||
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)
|
||||
Reference in new issue
Block a user