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 ---@class breakdownspellscrollframe : df_scrollboxmixin, scrollframe
---@field Header df_headerframe ---@field Header df_headerframe
---@field RefreshMe fun(scrollFrame: breakdownspellscrollframe, data: table|nil) ---@field RefreshMe fun(scrollFrame: breakdownspellscrollframe, data: table|nil)
---@field SortKey string
---@field SortOrder string
---@class breakdowntargetscrollframe : df_scrollboxmixin, scrollframe ---@class breakdowntargetscrollframe : df_scrollboxmixin, scrollframe
---@field Header df_headerframe ---@field Header df_headerframe
@@ -536,13 +538,14 @@
---@class spelltableadv : spelltable, spelltablemixin ---@class spelltableadv : spelltable, spelltablemixin
---@field expanded boolean if is true the show the nested spells ---@field expanded boolean if is true the show the nested spells
---@field spellTables spelltable[] ---@field spellTables spelltable[]
---@field spellIds number[] ---@field nestedData bknesteddata[]
---@field petNames string[]
---@field bCanExpand boolean ---@field bCanExpand boolean
---@field expandedIndex number ---@field expandedIndex number
---@field bIsExpanded boolean ---@field bIsExpanded boolean
---@field statusBarValue number ---@field statusBarValue number
---@class bknesteddata : {spellId: number, spellTable: spelltable, petName: string, value: number}
---@class breakdowntargetframe : frame ---@class breakdowntargetframe : frame
---@field spellId number ---@field spellId number
---@field bkSpellData spelltableadv ---@field bkSpellData spelltableadv
+12
View File
@@ -1193,3 +1193,15 @@ end
function Details222.PlayerStats:GetStat(statName, value) function Details222.PlayerStats:GetStat(statName, value)
return Details.player_stats[statName] return Details.player_stats[statName]
end 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 if (index) then
---@type spelltableadv ---@type spelltableadv
local bkSpellData = breakdownSpellDataList[index] local bkSpellData = breakdownSpellDataList[index]
bkSpellData.spellIds[#bkSpellData.spellIds+1] = spellId
bkSpellData.spellTables[#bkSpellData.spellTables+1] = spellTable 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 bkSpellData.bCanExpand = true
else else
---@type spelltableadv ---@type spelltableadv
@@ -4574,12 +4577,11 @@ function atributo_damage:MontaInfoDamageDone() --I guess this fills the list of
bIsExpanded = Details222.BreakdownWindow.IsSpellExpanded(spellId), bIsExpanded = Details222.BreakdownWindow.IsSpellExpanded(spellId),
bCanExpand = false, bCanExpand = false,
spellIds = {spellId}, spellTables = {spellTable},
spellTables = {spellTable}, --sub spell tables to show if the spell is expanded nestedData = {{spellId = spellId, spellTable = spellTable, petName = "", value = 0}},
petNames = {""},
} }
detailsFramework:Mixin(bkSpellData, Details.SpellTableMixin)
detailsFramework:Mixin(bkSpellData, Details.SpellTableMixin)
breakdownSpellDataList[#breakdownSpellDataList+1] = bkSpellData breakdownSpellDataList[#breakdownSpellDataList+1] = bkSpellData
alreadyAdded[spellName] = #breakdownSpellDataList alreadyAdded[spellName] = #breakdownSpellDataList
end end
@@ -4607,9 +4609,12 @@ function atributo_damage:MontaInfoDamageDone() --I guess this fills the list of
if (index) then --PET if (index) then --PET
---@type spelltableadv ---@type spelltableadv
local bkSpellData = breakdownSpellDataList[index] local bkSpellData = breakdownSpellDataList[index]
bkSpellData.spellIds[#bkSpellData.spellIds+1] = spellId
bkSpellData.spellTables[#bkSpellData.spellTables+1] = spellTable 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 bkSpellData.bCanExpand = true
else --PET else --PET
---@type spelltableadv ---@type spelltableadv
@@ -4619,12 +4624,11 @@ function atributo_damage:MontaInfoDamageDone() --I guess this fills the list of
bIsExpanded = Details222.BreakdownWindow.IsSpellExpanded(spellId), bIsExpanded = Details222.BreakdownWindow.IsSpellExpanded(spellId),
bCanExpand = false, bCanExpand = false,
spellIds = {spellId},
spellTables = {spellTable}, 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 breakdownSpellDataList[#breakdownSpellDataList+1] = bkSpellData
alreadyAdded[spellName] = #breakdownSpellDataList alreadyAdded[spellName] = #breakdownSpellDataList
end end
@@ -4639,13 +4643,13 @@ function atributo_damage:MontaInfoDamageDone() --I guess this fills the list of
---@type spelltableadv ---@type spelltableadv
local bkSpellData = breakdownSpellDataList[i] local bkSpellData = breakdownSpellDataList[i]
Details.SpellTableMixin.SumSpellTables(bkSpellData.spellTables, bkSpellData) Details.SpellTableMixin.SumSpellTables(bkSpellData.spellTables, bkSpellData)
Details:Destroy(bkSpellData, "spellTables")
end end
breakdownSpellDataList.totalValue = actorTotal breakdownSpellDataList.totalValue = actorTotal
breakdownSpellDataList.combatTime = actorCombatTime breakdownSpellDataList.combatTime = actorCombatTime
--cleanup Details:Destroy(alreadyAdded)
table.wipe(alreadyAdded)
--send to the breakdown window --send to the breakdown window
Details222.BreakdownWindow.SendSpellData(breakdownSpellDataList, actorObject, combatObject, instance) Details222.BreakdownWindow.SendSpellData(breakdownSpellDataList, actorObject, combatObject, instance)
+16 -12
View File
@@ -1904,9 +1904,12 @@ function atributo_heal:MontaInfoHealingDone()
if (index) then if (index) then
---@type spelltableadv ---@type spelltableadv
local bkSpellData = actorSpellsSorted[index] local bkSpellData = actorSpellsSorted[index]
bkSpellData.spellIds[#bkSpellData.spellIds+1] = spellId
bkSpellData.spellTables[#bkSpellData.spellTables+1] = spellTable 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 bkSpellData.bCanExpand = true
else else
---@type spelltableadv ---@type spelltableadv
@@ -1916,9 +1919,8 @@ function atributo_heal:MontaInfoHealingDone()
bIsExpanded = Details222.BreakdownWindow.IsSpellExpanded(spellId), bIsExpanded = Details222.BreakdownWindow.IsSpellExpanded(spellId),
bCanExpand = false, bCanExpand = false,
spellIds = {spellId}, spellTables = {spellTable},
spellTables = {spellTable}, --sub spell tables to show if the spell is expanded nestedData = {{spellId = spellId, spellTable = spellTable, petName = "", value = 0}},
petNames = {""},
} }
detailsFramework:Mixin(bkSpellData, Details.SpellTableMixin) detailsFramework:Mixin(bkSpellData, Details.SpellTableMixin)
@@ -1949,9 +1951,12 @@ function atributo_heal:MontaInfoHealingDone()
if (index) then --PET if (index) then --PET
---@type spelltableadv ---@type spelltableadv
local bkSpellData = actorSpellsSorted[index] local bkSpellData = actorSpellsSorted[index]
bkSpellData.spellIds[#bkSpellData.spellIds+1] = spellId
bkSpellData.spellTables[#bkSpellData.spellTables+1] = spellTable 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 bkSpellData.bCanExpand = true
else --PET else --PET
---@type spelltableadv ---@type spelltableadv
@@ -1961,9 +1966,8 @@ function atributo_heal:MontaInfoHealingDone()
expanded = Details222.BreakdownWindow.IsSpellExpanded(spellId), expanded = Details222.BreakdownWindow.IsSpellExpanded(spellId),
bCanExpand = false, bCanExpand = false,
spellIds = {spellId},
spellTables = {spellTable}, spellTables = {spellTable},
petNames = {petName}, nestedData = {{spellId = spellId, spellTable = spellTable, petName = petName, value = 0}},
} }
detailsFramework:Mixin(bkSpellData, Details.SpellTableMixin) detailsFramework:Mixin(bkSpellData, Details.SpellTableMixin)
@@ -1979,6 +1983,7 @@ function atributo_heal:MontaInfoHealingDone()
---@type spelltableadv ---@type spelltableadv
local bkSpellData = actorSpellsSorted[i] local bkSpellData = actorSpellsSorted[i]
Details.SpellTableMixin.SumSpellTables(bkSpellData.spellTables, bkSpellData) Details.SpellTableMixin.SumSpellTables(bkSpellData.spellTables, bkSpellData)
Details:Destroy(bkSpellData, "spellTables")
end end
--table.sort(actorSpellsSorted, Details.Sort2) --table.sort(actorSpellsSorted, Details.Sort2)
@@ -1989,11 +1994,10 @@ function atributo_heal:MontaInfoHealingDone()
actorSpellsSorted.totalValue = actorTotal actorSpellsSorted.totalValue = actorTotal
actorSpellsSorted.combatTime = actorCombatTime actorSpellsSorted.combatTime = actorCombatTime
--actorSpellsSorted has the spell infomation, need to pass to the summary tab
--cleanup --cleanup
table.wipe(alreadyAdded) Details:Destroy(alreadyAdded)
--actorSpellsSorted has the spell infomation, need to pass to the summary tab
--send to the breakdown window --send to the breakdown window
Details222.BreakdownWindow.SendSpellData(actorSpellsSorted, actorObject, combatObject, instance) 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 spellTable = bkSpellData
value = bkSpellData.total value = bkSpellData.total
spellId = bkSpellData.id spellId = bkSpellData.id
petName = bkSpellData.petNames[spellTableIndex] petName = bkSpellData.nestedData[spellTableIndex].petName
else else
spellTable = bkSpellData.spellTables[spellTableIndex] spellTable = bkSpellData.nestedData[spellTableIndex].spellTable
value = spellTable.total value = spellTable.total
spellId = spellTable.id spellId = spellTable.id
petName = bkSpellData.petNames[spellTableIndex] petName = bkSpellData.nestedData[spellTableIndex].petName
spellBar.bIsExpandedSpell = true spellBar.bIsExpandedSpell = true
end end
@@ -1844,7 +1844,8 @@ local refreshFunc = function(scrollFrame, scrollData, offset, totalLines) --~ref
---@type instance ---@type instance
local instanceObject = spellsTab.GetInstance() local instanceObject = spellsTab.GetInstance()
local sortKey = scrollFrame.SortKey local keyToSort = scrollFrame.SortKey
local orderToSort = scrollFrame.SortKey
local headerTable = spellsTab.spellsHeaderData local headerTable = spellsTab.spellsHeaderData
--todo: when swapping sort orders, close already expanded spells --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] local bkSpellData = scrollData[index]
if (bkSpellData) then 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 ---@type number
local spellTablesAmount = #spellTables local spellTablesAmount = #bkSpellData.nestedData
---@type string[]
local petNames = bkSpellData.petNames --array with pet names
---@type boolean
---called mainSpellBar because it is the line that shows the sum of all spells merged (if any) ---called mainSpellBar because it is the line that shows the sum of all spells merged (if any)
---@type breakdownspellbar ---@type breakdownspellbar
@@ -1880,26 +1869,51 @@ local refreshFunc = function(scrollFrame, scrollData, offset, totalLines) --~ref
if (mainSpellBar) then if (mainSpellBar) then
lineIndex = lineIndex + 1 lineIndex = lineIndex + 1
local bIsMainLine = true 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
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 --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 if (bkSpellData.bIsExpanded and spellTablesAmount > 1) then
---@type number spellTableIndex is the same counter as bkSpellStableIndex --filling necessary information to sort the data by the selected header column
--as the nested actors or spells never get sorted, it might be required to sort the data here 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 for spellTableIndex = 1, spellTablesAmount do
---@type breakdownspellbar ---@type breakdownspellbar
local spellBar = getSpellBar(scrollFrame, lineIndex) local spellBar = getSpellBar(scrollFrame, lineIndex)
if (spellBar) then if (spellBar) then
---@type bknesteddata
local nestedBkSpellData = bkSpellData.nestedData[spellTableIndex]
lineIndex = lineIndex + 1 lineIndex = lineIndex + 1
---@type string ---@type string
local petName = petNames[spellTableIndex] local petName = nestedBkSpellData.petName
---@type string ---@type string
local nameToUse = petName ~= "" and petName or actorName local nameToUse = petName ~= "" and petName or actorName
local bIsMainLine = false 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 mainSpellBar.ExpandedChildren[#mainSpellBar.ExpandedChildren + 1] = spellBar
end end
end end
@@ -2007,12 +2021,13 @@ function spellsTab.CreateSpellScrollContainer(tabFrame) --~scroll ~create ~spell
end end
---set the data and refresh the scrollframe ---set the data and refresh the scrollframe
---@param self any ---@param self breakdownspellscrollframe
---@param data breakdownspelldatalist ---@param data breakdownspelldatalist
function scrollFrame:RefreshMe(data) --~refreshme (spells) ~refreshmes function scrollFrame:RefreshMe(data) --~refreshme (spells) ~refreshmes
--get which column is currently selected and the sort order --get which column is currently selected and the sort order
local columnIndex, order, key = scrollFrame.Header:GetSelectedColumn() local columnIndex, order, key = scrollFrame.Header:GetSelectedColumn()
scrollFrame.SortKey = key scrollFrame.SortKey = key
scrollFrame.SortOrder = order
---@type string ---@type string
local keyToSort = key local keyToSort = key