Spells and Pets nested now are ordered correctly

This commit is contained in:
Tercio Jose
2023-05-07 00:18:39 -03:00
parent ab7073ce3e
commit 01ee2a4ebc
5 changed files with 88 additions and 50 deletions
+5 -2
View File
@@ -482,6 +482,8 @@
---@class breakdownspellscrollframe : df_scrollboxmixin, scrollframe
---@field Header df_headerframe
---@field RefreshMe fun(scrollFrame: breakdownspellscrollframe, data: table|nil)
---@field SortKey string
---@field SortOrder string
---@class breakdowntargetscrollframe : df_scrollboxmixin, scrollframe
---@field Header df_headerframe
@@ -536,13 +538,14 @@
---@class spelltableadv : spelltable, spelltablemixin
---@field expanded boolean if is true the show the nested spells
---@field spellTables spelltable[]
---@field spellIds number[]
---@field petNames string[]
---@field nestedData bknesteddata[]
---@field bCanExpand boolean
---@field expandedIndex number
---@field bIsExpanded boolean
---@field statusBarValue number
---@class bknesteddata : {spellId: number, spellTable: spelltable, petName: string, value: number}
---@class breakdowntargetframe : frame
---@field spellId number
---@field bkSpellData spelltableadv
+12
View File
@@ -1192,4 +1192,16 @@ end
---@return any
function Details222.PlayerStats:GetStat(statName, value)
return Details.player_stats[statName]
end
---destroy a table and remove it from the object, if the key isn't passed, the object itself is destroyed
---@param object any
---@param key string|nil
function Details:Destroy(object, key)
if (key) then
table.wipe(object[key])
object[key] = nil
else
table.wipe(object)
end
end
+17 -13
View File
@@ -4562,9 +4562,12 @@ function atributo_damage:MontaInfoDamageDone() --I guess this fills the list of
if (index) then
---@type spelltableadv
local bkSpellData = breakdownSpellDataList[index]
bkSpellData.spellIds[#bkSpellData.spellIds+1] = spellId
bkSpellData.spellTables[#bkSpellData.spellTables+1] = spellTable
bkSpellData.petNames[#bkSpellData.petNames+1] = ""
---@type bknesteddata
local nestedData = {spellId = spellId, spellTable = spellTable, petName = "", value = 0}
bkSpellData.nestedData[#bkSpellData.nestedData+1] = nestedData
bkSpellData.bCanExpand = true
else
---@type spelltableadv
@@ -4574,12 +4577,11 @@ function atributo_damage:MontaInfoDamageDone() --I guess this fills the list of
bIsExpanded = Details222.BreakdownWindow.IsSpellExpanded(spellId),
bCanExpand = false,
spellIds = {spellId},
spellTables = {spellTable}, --sub spell tables to show if the spell is expanded
petNames = {""},
spellTables = {spellTable},
nestedData = {{spellId = spellId, spellTable = spellTable, petName = "", value = 0}},
}
detailsFramework:Mixin(bkSpellData, Details.SpellTableMixin)
detailsFramework:Mixin(bkSpellData, Details.SpellTableMixin)
breakdownSpellDataList[#breakdownSpellDataList+1] = bkSpellData
alreadyAdded[spellName] = #breakdownSpellDataList
end
@@ -4607,9 +4609,12 @@ function atributo_damage:MontaInfoDamageDone() --I guess this fills the list of
if (index) then --PET
---@type spelltableadv
local bkSpellData = breakdownSpellDataList[index]
bkSpellData.spellIds[#bkSpellData.spellIds+1] = spellId
bkSpellData.spellTables[#bkSpellData.spellTables+1] = spellTable
bkSpellData.petNames[#bkSpellData.petNames+1] = petName
---@type bknesteddata
local nestedData = {spellId = spellId, spellTable = spellTable, petName = petName, value = 0}
bkSpellData.nestedData[#bkSpellData.nestedData+1] = nestedData
bkSpellData.bCanExpand = true
else --PET
---@type spelltableadv
@@ -4619,12 +4624,11 @@ function atributo_damage:MontaInfoDamageDone() --I guess this fills the list of
bIsExpanded = Details222.BreakdownWindow.IsSpellExpanded(spellId),
bCanExpand = false,
spellIds = {spellId},
spellTables = {spellTable},
petNames = {petName},
nestedData = {{spellId = spellId, spellTable = spellTable, petName = petName, value = 0}},
}
detailsFramework:Mixin(bkSpellData, Details.SpellTableMixin)
detailsFramework:Mixin(bkSpellData, Details.SpellTableMixin)
breakdownSpellDataList[#breakdownSpellDataList+1] = bkSpellData
alreadyAdded[spellName] = #breakdownSpellDataList
end
@@ -4639,13 +4643,13 @@ function atributo_damage:MontaInfoDamageDone() --I guess this fills the list of
---@type spelltableadv
local bkSpellData = breakdownSpellDataList[i]
Details.SpellTableMixin.SumSpellTables(bkSpellData.spellTables, bkSpellData)
Details:Destroy(bkSpellData, "spellTables")
end
breakdownSpellDataList.totalValue = actorTotal
breakdownSpellDataList.combatTime = actorCombatTime
--cleanup
table.wipe(alreadyAdded)
Details:Destroy(alreadyAdded)
--send to the breakdown window
Details222.BreakdownWindow.SendSpellData(breakdownSpellDataList, actorObject, combatObject, instance)
+16 -12
View File
@@ -1904,9 +1904,12 @@ function atributo_heal:MontaInfoHealingDone()
if (index) then
---@type spelltableadv
local bkSpellData = actorSpellsSorted[index]
bkSpellData.spellIds[#bkSpellData.spellIds+1] = spellId
bkSpellData.spellTables[#bkSpellData.spellTables+1] = spellTable
bkSpellData.petNames[#bkSpellData.petNames+1] = ""
---@type bknesteddata
local nestedData = {spellId = spellId, spellTable = spellTable, petName = "", value = 0}
bkSpellData.nestedData[#bkSpellData.nestedData+1] = nestedData
bkSpellData.bCanExpand = true
else
---@type spelltableadv
@@ -1916,9 +1919,8 @@ function atributo_heal:MontaInfoHealingDone()
bIsExpanded = Details222.BreakdownWindow.IsSpellExpanded(spellId),
bCanExpand = false,
spellIds = {spellId},
spellTables = {spellTable}, --sub spell tables to show if the spell is expanded
petNames = {""},
spellTables = {spellTable},
nestedData = {{spellId = spellId, spellTable = spellTable, petName = "", value = 0}},
}
detailsFramework:Mixin(bkSpellData, Details.SpellTableMixin)
@@ -1949,9 +1951,12 @@ function atributo_heal:MontaInfoHealingDone()
if (index) then --PET
---@type spelltableadv
local bkSpellData = actorSpellsSorted[index]
bkSpellData.spellIds[#bkSpellData.spellIds+1] = spellId
bkSpellData.spellTables[#bkSpellData.spellTables+1] = spellTable
bkSpellData.petNames[#bkSpellData.petNames+1] = petName
---@type bknesteddata
local nestedData = {spellId = spellId, spellTable = spellTable, petName = petName, value = 0}
bkSpellData.nestedData[#bkSpellData.nestedData+1] = nestedData
bkSpellData.bCanExpand = true
else --PET
---@type spelltableadv
@@ -1961,9 +1966,8 @@ function atributo_heal:MontaInfoHealingDone()
expanded = Details222.BreakdownWindow.IsSpellExpanded(spellId),
bCanExpand = false,
spellIds = {spellId},
spellTables = {spellTable},
petNames = {petName},
nestedData = {{spellId = spellId, spellTable = spellTable, petName = petName, value = 0}},
}
detailsFramework:Mixin(bkSpellData, Details.SpellTableMixin)
@@ -1979,6 +1983,7 @@ function atributo_heal:MontaInfoHealingDone()
---@type spelltableadv
local bkSpellData = actorSpellsSorted[i]
Details.SpellTableMixin.SumSpellTables(bkSpellData.spellTables, bkSpellData)
Details:Destroy(bkSpellData, "spellTables")
end
--table.sort(actorSpellsSorted, Details.Sort2)
@@ -1989,11 +1994,10 @@ function atributo_heal:MontaInfoHealingDone()
actorSpellsSorted.totalValue = actorTotal
actorSpellsSorted.combatTime = actorCombatTime
--actorSpellsSorted has the spell infomation, need to pass to the summary tab
--cleanup
table.wipe(alreadyAdded)
Details:Destroy(alreadyAdded)
--actorSpellsSorted has the spell infomation, need to pass to the summary tab
--send to the breakdown window
Details222.BreakdownWindow.SendSpellData(actorSpellsSorted, actorObject, combatObject, instance)
+38 -23
View File
@@ -1613,12 +1613,12 @@ local updateSpellBar = function(spellBar, index, actorName, combatObject, scroll
spellTable = bkSpellData
value = bkSpellData.total
spellId = bkSpellData.id
petName = bkSpellData.petNames[spellTableIndex]
petName = bkSpellData.nestedData[spellTableIndex].petName
else
spellTable = bkSpellData.spellTables[spellTableIndex]
spellTable = bkSpellData.nestedData[spellTableIndex].spellTable
value = spellTable.total
spellId = spellTable.id
petName = bkSpellData.petNames[spellTableIndex]
petName = bkSpellData.nestedData[spellTableIndex].petName
spellBar.bIsExpandedSpell = true
end
@@ -1844,7 +1844,8 @@ local refreshFunc = function(scrollFrame, scrollData, offset, totalLines) --~ref
---@type instance
local instanceObject = spellsTab.GetInstance()
local sortKey = scrollFrame.SortKey
local keyToSort = scrollFrame.SortKey
local orderToSort = scrollFrame.SortKey
local headerTable = spellsTab.spellsHeaderData
--todo: when swapping sort orders, close already expanded spells
@@ -1857,20 +1858,8 @@ local refreshFunc = function(scrollFrame, scrollData, offset, totalLines) --~ref
local bkSpellData = scrollData[index]
if (bkSpellData) then
--before getting a line, check if the data for the line is a expanded line and if the spell is expanded
local expandedIndex = bkSpellData.expandedIndex
local spellId = bkSpellData.id
local value = math.floor(bkSpellData.total)
---@type number[]
local spellIds = bkSpellData.spellIds --array with spellIds
---@type spelltable[]
local spellTables = bkSpellData.spellTables --array with spellTables
---@type number
local spellTablesAmount = #spellTables
---@type string[]
local petNames = bkSpellData.petNames --array with pet names
---@type boolean
local spellTablesAmount = #bkSpellData.nestedData
---called mainSpellBar because it is the line that shows the sum of all spells merged (if any)
---@type breakdownspellbar
@@ -1880,26 +1869,51 @@ local refreshFunc = function(scrollFrame, scrollData, offset, totalLines) --~ref
if (mainSpellBar) then
lineIndex = lineIndex + 1
local bIsMainLine = true
updateSpellBar(mainSpellBar, index, actorName, combatObject, scrollFrame, headerTable, bkSpellData, 1, totalValue, topValue, bIsMainLine, sortKey, spellTablesAmount)
updateSpellBar(mainSpellBar, index, actorName, combatObject, scrollFrame, headerTable, bkSpellData, 1, totalValue, topValue, bIsMainLine, keyToSort, spellTablesAmount)
end
end
--then it adds the lines for each spell merged, but it cannot use the bkSpellData, it needs the spellTable, it's kinda using bkSpellData, need to debug
if (bkSpellData.bIsExpanded and spellTablesAmount > 1) then
---@type number spellTableIndex is the same counter as bkSpellStableIndex
--as the nested actors or spells never get sorted, it might be required to sort the data here
--filling necessary information to sort the data by the selected header column
for spellTableIndex = 1, spellTablesAmount do
---@type bknesteddata
local nestedBkSpellData = bkSpellData.nestedData[spellTableIndex]
---@type spelltable
local spellTable = nestedBkSpellData.spellTable
nestedBkSpellData.value = spellTable[keyToSort] or getValueForHeaderSortKey(combatObject, spellTable, keyToSort)
end
--sort the nested data
if (orderToSort == "DESC") then
table.sort(bkSpellData.nestedData,
function(t1, t2)
return t1.value < t2.value
end)
else
table.sort(bkSpellData.nestedData,
function(t1, t2)
return t1.value > t2.value
end)
end
for spellTableIndex = 1, spellTablesAmount do
---@type breakdownspellbar
local spellBar = getSpellBar(scrollFrame, lineIndex)
if (spellBar) then
---@type bknesteddata
local nestedBkSpellData = bkSpellData.nestedData[spellTableIndex]
lineIndex = lineIndex + 1
---@type string
local petName = petNames[spellTableIndex]
local petName = nestedBkSpellData.petName
---@type string
local nameToUse = petName ~= "" and petName or actorName
local bIsMainLine = false
updateSpellBar(spellBar, index, nameToUse, combatObject, scrollFrame, headerTable, bkSpellData, spellTableIndex, totalValue, topValue, bIsMainLine, sortKey, spellTablesAmount)
bkSpellData[keyToSort] = nestedBkSpellData.value
updateSpellBar(spellBar, index, nameToUse, combatObject, scrollFrame, headerTable, bkSpellData, spellTableIndex, totalValue, topValue, bIsMainLine, keyToSort, spellTablesAmount)
mainSpellBar.ExpandedChildren[#mainSpellBar.ExpandedChildren + 1] = spellBar
end
end
@@ -2007,12 +2021,13 @@ function spellsTab.CreateSpellScrollContainer(tabFrame) --~scroll ~create ~spell
end
---set the data and refresh the scrollframe
---@param self any
---@param self breakdownspellscrollframe
---@param data breakdownspelldatalist
function scrollFrame:RefreshMe(data) --~refreshme (spells) ~refreshmes
--get which column is currently selected and the sort order
local columnIndex, order, key = scrollFrame.Header:GetSelectedColumn()
scrollFrame.SortKey = key
scrollFrame.SortOrder = order
---@type string
local keyToSort = key