Skip to content

Commit 71fefa8

Browse files
authored
Sort the Calculations Tab breakdown lists by value (#7211)
* Sort the CalcBreakdownControl list by value. There is already a sort by type, but this is not used for a lot of breakdowns. Applying a sort by value should make it easier to read the breakdown without disrupting the sort by type. * Sort the CalcBreakdownControl taking in consideration boolean values. Some breakdowns can contain a mix of `number` and `boolean`. e.g. the skill buffs breakdown if you have a golem active will have a `Condition: have golem` with value of `true`. The values in this kind of breakdown are pretty sparse and sorting them in a coherent way is not easy, so for the sake of this PR we can just keep skip(return false) when comparing number and boolean. * Use a copy of the modList in CalcBreakdownControl If we try to sort on the original modlist, we'll actually change the order of the values in memory and next time we sort again, some of the mods can move position. Using a copy of the table--which will be discarded after use--will prevent this. * Sort generic breakdown and slots Breakdowns can also accept direct breakdown tables and slots values. These also need to be sorted by value.
1 parent 56a4d66 commit 71fefa8

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/Classes/CalcBreakdownControl.lua

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,19 @@ function CalcBreakdownClass:AddBreakdownSection(sectionData)
148148
end
149149

150150
if breakdown.rowList and #breakdown.rowList > 0 then
151+
-- sort by the first column (the value)
152+
local rowList = copyTable(breakdown.rowList, true)
153+
local colKey = breakdown.colList[1].key
154+
table.sort(rowList, function(a, b)
155+
return a[colKey] > b[colKey]
156+
end)
157+
151158
-- Generic table
152159
local section = {
153160
type = "TABLE",
154161
label = breakdown.label,
155162
footer = breakdown.footer,
156-
rowList = breakdown.rowList,
163+
rowList = rowList,
157164
colList = breakdown.colList,
158165
}
159166
t_insert(self.sectionList, section)
@@ -225,6 +232,10 @@ function CalcBreakdownClass:AddBreakdownSection(sectionData)
225232
rowList = breakdown.slots
226233
end
227234

235+
table.sort(rowList, function(a, b)
236+
return a['base'] > b['base']
237+
end)
238+
228239
local section = {
229240
type = "TABLE",
230241
rowList = rowList,
@@ -260,8 +271,8 @@ function CalcBreakdownClass:AddModSection(sectionData, modList)
260271
cfg.actor = sectionData.actor
261272
local rowList
262273
local modStore = (sectionData.enemy and actor.enemy.modDB) or (sectionData.cfg and actor.mainSkill.skillModList) or actor.modDB
263-
if modList then
264-
rowList = modList
274+
if modList then
275+
rowList = copyTable(modList)
265276
else
266277
if type(sectionData.modName) == "table" then
267278
rowList = modStore:Tabulate(sectionData.modType, cfg, unpack(sectionData.modName))
@@ -289,6 +300,17 @@ function CalcBreakdownClass:AddModSection(sectionData, modList)
289300
}
290301
t_insert(self.sectionList, section)
291302

303+
table.sort(rowList, function(a, b)
304+
-- Sort Modifiers by descending value
305+
if type(a.value) == 'number' and type(b.value) == 'number' then
306+
return b.value < a.value
307+
end
308+
if type(a.value) == 'boolean' and type(b.value) == 'boolean' then
309+
return a.value and not b.value
310+
end
311+
return false
312+
end)
313+
292314
if not modList and not sectionData.modType then
293315
-- Sort modifiers by type
294316
for i, row in ipairs(rowList) do
@@ -726,4 +748,4 @@ function CalcBreakdownClass:OnKeyUp(key)
726748
self.controls.scrollBar:Scroll(-1)
727749
end
728750
return self
729-
end
751+
end

0 commit comments

Comments
 (0)