Skip to content

Commit

Permalink
Added new file to framework 'packtable'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tercioo committed Aug 10, 2024
1 parent 2b7d1bb commit 1d59b56
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 3 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 = 559
local dversion = 560
local major, minor = "DetailsFramework-1.0", dversion
local DF, oldminor = LibStub:NewLibrary(major, minor)

Expand Down
1 change: 1 addition & 0 deletions Libs/DF/load.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@
<Script file="tabcontainer.lua"/>
<Script file="editor.lua"/>
<Script file="keybind.lua"/>
<Script file="packtable.lua"/>
</Ui>
104 changes: 104 additions & 0 deletions Libs/DF/packtable.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@

local detailsFramework = _G["DetailsFramework"]
if (not detailsFramework or not DetailsFrameworkCanLoad) then
return
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
---@param table table
---@return string
function detailsFramework.table.pack(table)
local tableSize = #table
local newString = "" .. tableSize .. ","
for i = 1, tableSize do
newString = newString .. table[i] .. ","
end

newString = newString:gsub(",$", "")
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
---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
function detailsFramework.table.unpack(data, startIndex)
local splittedTable

if (type(data) == "table") then
splittedTable = data
else
splittedTable = {}
for value in data:gmatch("[^,]+") do
splittedTable[#splittedTable+1] = value
end
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 result = {}

for i = startIndex, endIndex do
local value = splittedTable[i]
local asNumber = tonumber(value)
if (asNumber) then
table.insert(result, asNumber)
else
table.insert(result, value)
end
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

---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

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
4 changes: 4 additions & 0 deletions Libs/DF/panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5359,6 +5359,10 @@ detailsFramework.TimeLineFunctions = {
self.data = data
self:RefreshTimeLine()
end,

GetData = function(self)
return self.data
end,
}

--creates a regular scroll in horizontal position
Expand Down
4 changes: 2 additions & 2 deletions boot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
local addonName, Details222 = ...
local version, build, date, tvs = GetBuildInfo()

Details.build_counter = 12830
Details.alpha_build_counter = 12830 --if this is higher than the regular counter, use it instead
Details.build_counter = 12831
Details.alpha_build_counter = 12831 --if this is higher than the regular counter, use it instead
Details.dont_open_news = true
Details.game_version = version
Details.userversion = version .. " " .. Details.build_counter
Expand Down

0 comments on commit 1d59b56

Please sign in to comment.