Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions spec/System/TestCompareTab_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,61 @@ describe("CompareTab", function()
assert.are.equals(build.calcsTab.mainOutput.GemQuality, entry.calcsTab.mainOutput.GemQuality)
assert.are.equals(build.calcsTab.mainOutput.CombinedDPS, entry.calcsTab.mainOutput.CombinedDPS)
end)
it("recalculates the power report when either build changes", function()
newBuild()
build.skillsTab:PasteSocketGroup("Fireball 20/0 1\nControlled Destruction 20/0 1\n")
runCallback("OnFrame")
local entry = new("CompareEntry"):CompareEntry(build:SaveDB("code"), "Compare")
-- Config differences rebuild the primary's config mod list, which must not flag a rebuild
entry.configTab.input.conditionEnemyRareOrUnique = true
entry.configTab:BuildModList()
entry:Rebuild()
local primaryGemList = build.skillsTab.socketGroupList[1].gemList
local supportGem = table.remove(primaryGemList)
build.buildFlag = true
runCallback("OnFrame")

local compareTab = build.compareTab
compareTab.compareEntries = { entry }
compareTab.activeCompareIndex = 1
for _, powerStat in ipairs(data.powerStatList) do
if powerStat.stat == "CombinedDPS" then
compareTab.comparePowerStat = powerStat
end
end
local function runReport()
runCallback("OnFrame")
compareTab:RunComparePowerReport(entry)
while compareTab.comparePowerCoroutine do
compareTab:RunComparePowerReport(entry)
end
local supportResults = 0
for _, result in ipairs(compareTab.comparePowerResults) do
if result.category == "Support gem" then
supportResults = supportResults + 1
end
end
return supportResults
end

assert.are.equals(1, runReport())
-- Finished report must not restart itself
local results = compareTab.comparePowerResults
runCallback("OnFrame")
compareTab:RunComparePowerReport(entry)
assert.are.equal(results, compareTab.comparePowerResults)

-- Primary gains the support gem: nothing left to compare
table.insert(primaryGemList, supportGem)
build.buildFlag = true
assert.are.equals(0, runReport())

-- Compared build loses it too
table.remove(entry.skillsTab.socketGroupList[1].gemList)
table.remove(primaryGemList)
build.buildFlag = true
entry.buildFlag = true
entry:Rebuild()
assert.are.equals(0, runReport())
end)
end)
24 changes: 14 additions & 10 deletions src/Classes/CompareTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ function CompareTabClass:CompareTab(primaryBuild)
self.comparePowerProgress = 0 -- 0-100
self.comparePowerDirty = false -- flag to restart calculation
self.comparePowerCompareId = nil -- track which compare entry was calculated
self.comparePowerPrimaryRevision = nil -- primary build outputRevision the report was calculated for
self.comparePowerCompareRevision = nil -- compare entry outputRevision the report was calculated for

-- Pre-load static module data
self.configOptions = require("Modules.ConfigOptions")
Expand Down Expand Up @@ -2754,7 +2756,7 @@ function CompareTabClass:ComparePowerBuilder(compareEntry, powerStat, categories
-- copy item
local itemCopy = new("Item"):Item(cmpJewel:BuildRaw())
table.insert(cmpJewels, itemCopy)
self.primaryBuild.itemsTab:AddItem(itemCopy, false)
self.primaryBuild.itemsTab:AddItem(itemCopy, true)

-- equip copied
self.primaryBuild.itemsTab.slots[abyssSlotName]:SetSelItemId(itemCopy.id)
Expand All @@ -2774,7 +2776,7 @@ function CompareTabClass:ComparePowerBuilder(compareEntry, powerStat, categories
self.primaryBuild.itemsTab.slots[k]:SetSelItemId(v)
end
for _, item in ipairs(cmpJewels) do
self.primaryBuild.itemsTab:DeleteItem(item)
self.primaryBuild.itemsTab:DeleteItem(item, true)
end
end

Expand Down Expand Up @@ -2914,7 +2916,6 @@ function CompareTabClass:ComparePowerBuilder(compareEntry, powerStat, categories
if sig ~= "" and not pSignatures[sig] then
-- Temporarily add this socket group to primary build and recalculate
t_insert(pGroups, cGroup)
self.primaryBuild.buildFlag = true

-- Get a fresh calculator with the added group (pcall to guarantee cleanup)
local ok, gemCalcFunc, gemCalcBase = pcall(function()
Expand All @@ -2923,7 +2924,6 @@ function CompareTabClass:ComparePowerBuilder(compareEntry, powerStat, categories

-- Always remove the temporarily added group
t_remove(pGroups)
self.primaryBuild.buildFlag = true

if not ok then
-- gemCalcFunc contains the error message on failure; skip this group
Expand Down Expand Up @@ -2998,15 +2998,13 @@ function CompareTabClass:ComparePowerBuilder(compareEntry, powerStat, categories

-- Temporarily add to primary build's main socket group
t_insert(pMainGroup.gemList, tempGem)
self.primaryBuild.buildFlag = true

local ok, sgCalcFunc, sgCalcBase = pcall(function()
return self.calcs.getMiscCalculator(self.primaryBuild)
end)

-- Always remove the temporarily added gem
t_remove(pMainGroup.gemList)
self.primaryBuild.buildFlag = true

if not ok then
ConPrintf("Compare power (support gem): %s", tostring(sgCalcFunc))
Expand Down Expand Up @@ -3062,21 +3060,23 @@ function CompareTabClass:ComparePowerBuilder(compareEntry, powerStat, categories
if pNorm ~= cNorm then
-- Save original value
local savedVal = pInput[varData.var]
local buildFlag = self.primaryBuild.buildFlag

-- Apply compare build's config value
pInput[varData.var] = cVal

-- Rebuild and calculate (pcall to guarantee restore on error)
local ok, cfgCalcFunc, cfgCalcBase = pcall(function()
self.primaryBuild.configTab:BuildModList()
self.primaryBuild.buildFlag = true
return self.calcs.getMiscCalculator(self.primaryBuild)
end)

-- Always restore original value
pInput[varData.var] = savedVal
self.primaryBuild.configTab:BuildModList()
self.primaryBuild.buildFlag = true
-- Some config applies (e.g. enemyIsBoss placeholders) flag the build for a rebuild,
-- which would restart this report
self.primaryBuild.buildFlag = buildFlag

if not ok then
-- cfgCalcFunc contains the error message on failure; skip this config
Expand Down Expand Up @@ -3127,9 +3127,13 @@ end

-- Drive the compare power report coroutine
function CompareTabClass:RunComparePowerReport(compareEntry)
-- Invalidate if compare entry changed
if self.comparePowerCompareId ~= compareEntry then
-- Invalidate if the compare entry changed or either build was recalculated
if self.comparePowerCompareId ~= compareEntry
or self.comparePowerPrimaryRevision ~= self.primaryBuild.outputRevision
or self.comparePowerCompareRevision ~= compareEntry.outputRevision then
self.comparePowerCompareId = compareEntry
self.comparePowerPrimaryRevision = self.primaryBuild.outputRevision
self.comparePowerCompareRevision = compareEntry.outputRevision
self.comparePowerDirty = true
end

Expand Down
Loading