Skip to content

Commit

Permalink
Fixed an issue with the end of m+ panel
Browse files Browse the repository at this point in the history
  • Loading branch information
Tercioo committed Aug 11, 2024
1 parent 1d59b56 commit 15111dc
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Libs/DF/fw.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


local dversion = 560
local dversion = 561
local major, minor = "DetailsFramework-1.0", dversion
local DF, oldminor = LibStub:NewLibrary(major, minor)

Expand Down
8 changes: 8 additions & 0 deletions Libs/DF/math.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ DF.Math = {}
---@field RandomFraction fun(minValue: number, maxValue: number) : number
---@field GetNinePoints fun(object: uiobject) : df_ninepoints
---@field GetClosestPoint fun(ninePoints: df_ninepoints, coordinate: df_coordinate) : anchorid
---@field GetVectorLength fun(vectorX: number, vectorY: number, vectorZ: number?) : number return the magnitude of a vector

---@class df_coordinate : table
---@field x number
Expand Down Expand Up @@ -122,6 +123,13 @@ function DF.Math.GetNinePoints(object)
return ninePoints
end

function DF.Math.GetVectorLength(vectorX, vectorY, vectorZ)
if (not vectorZ) then
return (vectorX * vectorX + vectorY * vectorY) ^ 0.5
end
return (vectorX * vectorX + vectorY * vectorY + vectorZ * vectorZ) ^ 0.5
end

---return a random fraction between two values, example: RandomFraction(.2, .3) returns a number between .2 and .3, 0.25, 0.28, 0.21, etc
function DF.Math.RandomFraction(minValue, maxValue)
minValue = minValue or 0
Expand Down
107 changes: 70 additions & 37 deletions Libs/DF/packtable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ end
---@cast detailsFramework detailsframework

---pack a table into a string separating values with commas
---the first index tells the table length, expected table: {1, 2, 3, 4, 5, 6, 7, 8, 9, ...}
---can pack strings and numbers, returned string: "9,1,2,3,4,5,6,7,8,9", where the first number is the total size of table
---example: table: {1, 2, 3, 4, 5, 6, 7, 8, 9}
---returned string: "9,1,2,3,4,5,6,7,8,9", where the first number is the total size of table
---@param table table
---@return string
function detailsFramework.table.pack(table)
Expand All @@ -22,8 +22,53 @@ function detailsFramework.table.pack(table)
return newString
end

---unpack a string and an array of data into a indexed table, sarting from the startIndex also returns the next index to start reading
---pack subtables into a string separating values with commas, the first index tells the table length of the first packed table, the index t[currentIndex+length+1] tells the length of the next table.
---can pack strings and numbers, example:
---passed table: { {1, 2, 3}, {4, 5, 6}, {7, 8, 9}, ... }
---returned string: "3,1,2,3,3,4,5,6,3,7,8,9" > 3 indicating the total size of the first subtable followed by the sub table data, then 3 indicating the total size of the second subtable and so on
function detailsFramework.table.packsub(table)
local newString = ""
for i = 1, #table do
newString = newString .. detailsFramework.table.pack(table[i]) .. ","
end

newString = newString:gsub(",$", "")
return newString
end

---merge multiple tables into a single one and pack it into a string separating values with commas where the first index tells the table length
---can pack strings and numbers, example:
---passed table: { {1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
---result string: "9,1,2,3,4,5,6,7,8,9" > 9 indicating the total size of the subtables following by the indexes of the subtables
---@param table table
---@return string
function detailsFramework.table.packsubmerge(table)
local totalSize = 0
local subTablesAmount = #table

for i = 1, subTablesAmount do
totalSize = totalSize + #table[i]
end

--set the first index to be the total size of the subtables
local newString = "" .. totalSize .. ","

for i = 1, subTablesAmount do
local subTable = table[i]
for subIndex = 1, #subTable do
newString = newString .. subTable[subIndex] .. ","
end
end

newString = newString:gsub(",$", "")
return newString
end

---unpack a string and an array of data into a indexed table, starting from the startIndex also returns the next index to start reading
---expected data: "3,1,2,3,4,5,6,7,8" or {3,1,2,3,4,5,6,7,8}, with the example the returned table is: {1, 2, 3} and the next index to read is 5
---@param data string|table
---@param startIndex number?
---@return table, number
function detailsFramework.table.unpack(data, startIndex)
local splittedTable

Expand All @@ -37,15 +82,13 @@ function detailsFramework.table.unpack(data, startIndex)
end

local currentIndex = startIndex or 1

local currentTableSize = tonumber(splittedTable[currentIndex])
if (not currentTableSize) then
error("Details! Framework: table.unpack: invalid table size.")
end

startIndex = (startIndex and startIndex + 1) or 2
local endIndex = currentTableSize + 1

local endIndex = currentIndex + currentTableSize
local result = {}

for i = startIndex, endIndex do
Expand All @@ -58,47 +101,37 @@ function detailsFramework.table.unpack(data, startIndex)
end
end

local nextIndex = endIndex + 1
if (not splittedTable[nextIndex]) then
return result, 0
end

return result, endIndex + 1 --return the position of the last index plus 1 to account for the table size index
end


---pack subtables into a string separating values with commas
---the first index tells the table length of the first packed table, the index t[currentIndex+length+1] tells the length of the next table.
---expected table: { {1, 2, 3}, {4, 5, 6}, {7, 8, 9}, ... }
---can pack strings and numbers, returned string: "3,1,2,3,3,4,5,6,3,7,8,9"
function detailsFramework.table.packsub(table)
local newString = ""
for i = 1, #table do
newString = newString .. detailsFramework.table.pack(table[i]) .. ","
end

newString = newString:gsub(",$", "")
return newString
end
function detailsFramework.table.unpacksub(data, startIndex)
startIndex = startIndex or 1

---merge multiple tables into a single one and pack it into a string separating values with commas
---the first index tells the table length, expected table: { {1, 2, 3}, {4, 5, 6}, {7, 8, 9}, ... }
---can pack strings and numbers, returned string: "9,1,2,3,4,5,6,7,8,9", where the first number is the total size of table
---@param table table
---@return string
function detailsFramework.table.packsubmerge(table)
local totalSize = 0
local subTablesAmount = #table
local splittedTable = {}
local bIsRunning = true
local result = {}

for i = 1, subTablesAmount do
totalSize = totalSize + #table[i]
for value in data:gmatch("[^,]+") do
splittedTable[#splittedTable+1] = value
end

--set the first index to be the total size of the subtables
local newString = "" .. totalSize .. ","
while (bIsRunning) do
local unpackTable, nextIndex = detailsFramework.table.unpack(splittedTable, startIndex)
table.insert(result, unpackTable)

for i = 1, subTablesAmount do
local subTable = table[i]
for subIndex = 1, #subTable do
newString = newString .. subTable[subIndex] .. ","
if (nextIndex == 0) then
bIsRunning = false
break
else
startIndex = nextIndex
end
end

newString = newString:gsub(",$", "")
return newString
return result
end
56 changes: 56 additions & 0 deletions Libs/DF/packtable.tests.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

--this file isn't loaded, the tests need to be copied, loaded and run.

function PackTest()
local table = {1, 2, 3, 4, 5}
local packed = DetailsFramework.table.pack(table)
print("Testing table.pack, table: {1, 2, 3, 4, 5}")
local expected = "\"5,1,2,3,4,5\""
print("Expected: string ", expected)
print("Result: " .. type(packed) .. " \"" .. packed .. "\"")
end

function PackSubTest()
local table = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }
local packed = DetailsFramework.table.packsub(table)
print("Testing table.packsub, table: { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }")
local expected = "\"3,1,2,3,3,4,5,6,3,7,8,9\""
print("Expected: string ", expected)
print("Result: " .. type(packed) .. " \"" .. packed .. "\"")
end

function PackSubMergeTest()
local table = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }
local packed = DetailsFramework.table.packsubmerge(table)
print("Testing table.packsubmerge, table: { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }")
local expected = "\"9,1,2,3,4,5,6,7,8,9\""
print("Expected: string ", expected)
print("Result: " .. type(packed) .. " \"" .. packed .. "\"")
end

function UnpackTest()
local packed = "5,1,2,3,4,5"
local table, nextIndex = DetailsFramework.table.unpack(packed)
print("Testing table.unpack, data: \"5,1,2,3,4,5\"")
local expected = "table {1, 2, 3, 4, 5}, 0"
print("Expected:", expected)
print("Result: " .. type(table) .. " {" .. table[1] .. ", " .. table[2] .. ", " .. table[3] .. ", " .. table[4] .. ", " .. table[5] .. "},", nextIndex)
end

function UnpackSecondTest()
local packed = "5,1,2,3,4,5,2,5,4,3,1,2,3"
local table, nextIndex = DetailsFramework.table.unpack(packed, 7)
print("Testing table.unpack with Idx 7, data: \"5,1,2,3,4,5,2,5,4,3,1,2,3\"")
local expected = "table {5, 4}, 10"
print("Expected:", expected)
print("Result: " .. type(table) .. " {" .. table[1] .. ", " .. table[2] .. "},", nextIndex)
end

function UnpackSubTest()
local packed = "3,1,2,3,3,4,5,6,3,7,8,9"
local tables = DetailsFramework.table.unpacksub(packed)
print("Testing table.unpacksub, data: \"3,1,2,3,3,4,5,6,3,7,8,9\"")
local expected = "table {table {1, 2, 3}, table {4, 5, 6}, table {7, 8, 9}}"
print("Expected:", expected)
print("Result: " .. type(tables) .. " {" .. type(tables[1]) .. " {" .. tables[1][1] .. ", " .. tables[1][2] .. ", " .. tables[1][3] .. "}, " .. type(tables[2]) .. " {" .. tables[2][1] .. ", " .. tables[2][2] .. ", " .. tables[2][3] .. "}, " .. type(tables[3]) .. " {" .. tables[3][1] .. ", " .. tables[3][2] .. ", " .. tables[3][3] .. "}}")
end
3 changes: 3 additions & 0 deletions frames/window_mythicplus/window_end_of_run.lua
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ function lootFrame.UpdateUnitLoot(playerBanner)

local timeNow = GetTime()
local lootCache = lootFrame.LootCache[unitName]
if (not lootCache) then
return
end

---@type details_loot_cache[]
local lootCandidates = {}
Expand Down

0 comments on commit 15111dc

Please sign in to comment.