Skip to content
Merged
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
49 changes: 49 additions & 0 deletions spec/System/TestBuildDisplayStats_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
describe("Build display stats", function()
local originalCompactValues

before_each(function()
originalCompactValues = main.useCompactValues
newBuild()
end)

after_each(function()
main.useCompactValues = originalCompactValues
end)

local function getSidebarStat(label)
for _, stat in ipairs(build.controls.statBox.list) do
if stat[1] and stat[1]:find(label .. ":", 1, true) then
return stat[2]
end
end
end

it("formats compact values once and preserves normal formatting below the threshold", function()
main.useCompactValues = true

assert.are.equals("^712.3K", build:FormatStat({ fmt = ".1f", compactValue = true }, 12345))
assert.are.equals("^7123", build:FormatStat({ fmt = ".1f", compactValue = true }, 123))
end)

it("shows guard suffixes for EHP and max hit values", function()
build.skillsTab:PasteSocketGroup("Steelskin 20/0 1")
runCallback("OnFrame")

assert.is_true(build.calcsTab.mainOutput.GuardSkillActive)
assert.matches("%(Guard%)$", getSidebarStat("Effective Hit Pool"))
assert.matches("%(Guard%)$", getSidebarStat("Phys Max Hit"))
assert.matches("%(Guard%)$", getSidebarStat("Elemental Max Hit"))
assert.matches("%(Guard%)$", getSidebarStat("Chaos Max Hit"))
end)

it("shows immunity instead of guard for an immune max hit", function()
build.skillsTab:PasteSocketGroup("Steelskin 20/0 1")
build.configTab.input.customMods = "Chaos Inoculation"
build.configTab:BuildModList()
runCallback("OnFrame")

assert.are.equals(math.huge, build.calcsTab.mainOutput.ChaosMaximumHitTaken)
assert.matches("%(Immune%)$", getSidebarStat("Chaos Resistance"))
assert.matches("%(Immune%)$", getSidebarStat("Chaos Max Hit"))
end)
end)
44 changes: 37 additions & 7 deletions src/Modules/Build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local t_insert = table.insert
local t_sort = table.sort
local m_min = math.min
local m_max = math.max
local m_huge = math.huge
local m_floor = math.floor
local m_abs = math.abs
local s_format = string.format
Expand Down Expand Up @@ -1195,6 +1196,9 @@ function buildMode:OnFrame(inputEvents)
if main.thousandsSeparator ~= self.lastShowThousandsSeparator then
self:RefreshStatList()
end
if main.useCompactValues ~= self.lastUseCompactValues then
self:RefreshStatList()
end
if main.decimalSeparator ~= self.lastShowDecimalSeparator then
self:RefreshStatList()
end
Expand All @@ -1204,7 +1208,6 @@ function buildMode:OnFrame(inputEvents)

-- Update contents of main skill dropdowns
self:RefreshSkillSelectControls(self.controls, self.mainSocketGroup, "")

-- Draw contents of current tab
local sideBarWidth = 312
local tabViewPort = {
Expand Down Expand Up @@ -1587,10 +1590,23 @@ function buildMode:FormatStat(statData, statVal, overCapStatVal, colorOverride)
color = colorCodes.NEGATIVE
end

local valStr = s_format("%"..statData.fmt, val)
local number, suffix = valStr:match("^([%+%-]?%d+%.%d+)(%D*)$")
if number then
valStr = number:gsub("0+$", ""):gsub("%.$", "") .. suffix
local valStr
if statData.compactValue and main.useCompactValues and val ~= m_huge and val ~= -m_huge then
local absVal = m_abs(val)
if absVal >= 1000000000 then
valStr = s_format("%.1fB", val / 1000000000)
elseif absVal >= 1000000 then
valStr = s_format("%.1fM", val / 1000000)
elseif absVal >= 10000 then
valStr = s_format("%.1fK", val / 1000)
end
end
if not valStr then
valStr = s_format("%"..statData.fmt, val)
local number, suffix = valStr:match("^([%+%-]?%d+%.%d+)(%D*)$")
if number then
valStr = number:gsub("0+$", ""):gsub("%.$", "") .. suffix
end
end
valStr = color .. formatNumSep(valStr)

Expand All @@ -1601,6 +1617,7 @@ function buildMode:FormatStat(statData, statVal, overCapStatVal, colorOverride)
self.lastShowThousandsSeparator = main.thousandsSeparator
self.lastShowDecimalSeparator = main.decimalSeparator
self.lastShowTitlebarName = main.showTitlebarName
self.lastUseCompactValues = main.useCompactValues
return valStr
end

Expand All @@ -1621,6 +1638,9 @@ function buildMode:AddDisplayStatList(statList, actor)
end
if statVal and ((statData.condFunc and statData.condFunc(statVal,actor.output)) or (not statData.condFunc and statVal ~= 0)) then
local overCapStatVal = actor.output[statData.overCapStat] or nil
if overCapStatVal and statData.overCapStatCondFunc and not statData.overCapStatCondFunc(statVal, actor.output) then
overCapStatVal = nil
end
if statData.stat == "SkillDPS" then
labelColor = colorCodes.CUSTOM
table.sort(actor.output.SkillDPS, function(a,b) return (a.dps * a.count) > (b.dps * b.count) end)
Expand All @@ -1636,7 +1656,7 @@ function buildMode:AddDisplayStatList(statList, actor)
t_insert(statBoxList, {
height = 16,
lhsString,
self:FormatStat({fmt = "1.f"}, skillData.dps * skillData.count, overCapStatVal),
self:FormatStat({ fmt = ".1f", compactValue = statData.compactValue }, skillData.dps * skillData.count, overCapStatVal),
})
if skillData.skillPart then
t_insert(statBoxList, {
Expand All @@ -1659,10 +1679,20 @@ function buildMode:AddDisplayStatList(statList, actor)
if actor.output[statData.stat.."Warning"] or (statData.warnFunc and statData.warnFunc(statVal, actor.output) and statData.warnColor) then
colorOverride = colorCodes.NEGATIVE
end
local formattedStat = self:FormatStat(statData, statVal, overCapStatVal, colorOverride)
if statData.suffix and (not statData.suffixCondFunc or statData.suffixCondFunc(statVal, actor.output)) then
local suffix = statData.suffix
if type(suffix) == "function" then
suffix = suffix(statVal, actor.output)
end
if suffix then
formattedStat = formattedStat .. "^x808080 (" .. suffix .. ")"
end
end
t_insert(statBoxList, {
height = 16,
labelColor..statData.label..":",
self:FormatStat(statData, statVal, overCapStatVal, colorOverride),
formattedStat,
})
end
end
Expand Down
Loading
Loading