Skip to content

Commit

Permalink
Framework update
Browse files Browse the repository at this point in the history
  • Loading branch information
Tercioo committed Aug 25, 2023
1 parent 4ae7c24 commit 5cef044
Show file tree
Hide file tree
Showing 10 changed files with 571 additions and 159 deletions.
36 changes: 34 additions & 2 deletions Libs/DF/definitions.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@

---@class df_table_functions
---@field find fun(tbl:table, value:any) : number? find the index of a value in a array
---@field addunique fun(tbl:table, value:any) : boolean add a value to an array if it doesn't exist yet
---@field reverse fun(tbl:table) reverse the order of an array
---@field append fun(tbl1:table, tbl2:table) append the array of table2 to table1
---@field duplicate fun(tblReceiving:table, tblGiving:table) copy the values from table2 to table1 overwriting existing values, ignores __index and __newindex, keys pointing to a UIObject are preserved
---@field copy fun(tblReceiving:table, tblGiving:table) copy the values from table2 to table1 overwriting existing values, ignores __index and __newindex, threat UIObjects as regular tables
---@field deploy fun(tblReceiving:table, tblGiving:table) copy keys/values that does exist on tblGiving but not in tblReceiving
---@field copytocompress fun(tblReceiving:table, tblGiving:table) copy the values from table2 to table1 overwriting existing values, ignores __index, functions and tables with a 'GetObjectType' key
---@field removeduplicate fun(tbl1:table, tbl2:table) remove the keys from table1 which also exists in table2 with the same value
---@field dump fun(tbl:table) : string dump a table to a string

---@class detailsframework
---@field OptionsFunctions df_optionsmixin
---@field RoundedCornerPanelMixin df_roundedcornermixin
---@field GetDefaultBackdropColor fun(self:table) : red, green, blue, alpha return a standard backdrop color
---@field Schedules df_schedule
---@field Math df_math
---@field table df_table_functions
---@field Dispatch fun(self:table, callback:function, ...) : any dispatch a function call using xpcall
---@field GetDefaultBackdropColor fun(self:table) : red, green, blue, alpha return the standard backdrop color used by blizzard on their own frames
---@field Msg fun(self:table, message:string, ...) show a message in the chat frame
---@field MsgWarning fun(self:table, message:string, ...) show a warning message in the chat frame
---@field CreateCloseButton fun(self:table, parent:frame, frameName:string?) : df_closebutton
Expand All @@ -14,4 +30,20 @@
---@field Mixin fun(self:table, target:table, ...) : table
---@field SetButtonTexture fun(self:table, button:button|df_button, texture:atlasname|texturepath|textureid)
---@field CreateFadeAnimation fun(self:table, UIObject:uiobject, fadeInTime:number?, fadeOutTime:number?, fadeInAlpha:number?, fadeOutAlpha:number?)
---@field UnitGroupRolesAssigned fun(self:table, unitId: unit, specId: specializationid) : string
---@field SetFontSize fun(self:table, fontstring:fontstring, size:number)
---@field SetFontColor fun(self:table, fontstring:fontstring, red:any, green:number?, blue:number?, alpha:number?)
---@field SetFontFace fun(self:table, fontstring:fontstring, font:string)
---@field SetFontShadow fun(self:table, fontstring:fontstring, red:any, green:number?, blue:number?, alpha:number?, offsetX:number?, offsetY:number?)
---@field SetFontOutline fun(self:table, fontstring:fontstring, outline:fontflags)
---@field RemoveRealmName fun(self:table, name:string) : string, number remove the realm name from the player name, must be in the format of "name-realm"
---@field RemoveOwnerName fun(self:table, name:string) : string, number removes the owner name from a name string, the owner name must be between < and >
---@field CleanUpName fun(self:table, name:string) : string removes the realm name and owner name from a name string
---@field IntegerToTimer fun(self:table, time:number) : string convert a number to a timer string, e.g. 150 -> 2:30
---@field GroupIterator fun(self:table, callback:function, ...) iterate over the group, calling the callback function for each group member
---@field CommaValue fun(self:table, value:number) : string convert a number to a string with commas, e.g. 1000000 -> 1,000,000
---@field SplitTextInLines fun(self:table, text:string) : string[] split a text into lines
---@field UnitGroupRolesAssigned fun(unitId: unit, bUseSupport:boolean, specId: specializationid) : string there's no self here
---@field
---@field
---@field
---@field
104 changes: 89 additions & 15 deletions Libs/DF/fw.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


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

Expand Down Expand Up @@ -233,8 +233,8 @@ end

---return the role of the unit, this is safe to use for all versions of wow
---@param unitId string
---@param specId number
---@param bUseSupport boolean
---@param specId number
---@return string
function DF.UnitGroupRolesAssigned(unitId, bUseSupport, specId)
if (not DF.IsTimewalkWoW()) then --Was function exist check. TBC has function, returns NONE. -Flamanis 5/16/2022
Expand Down Expand Up @@ -525,7 +525,7 @@ function DF.table.reverse(t)
return new
end

---copy the values from table2 to table1, ignore the metatable and UIObjects
---copy the values from table2 to table1 overwriting existing values, ignores __index and __newindex, keys pointing to a UIObject are preserved
---@param t1 table
---@param t2 table
---@return table
Expand All @@ -549,7 +549,7 @@ function DF.table.duplicate(t1, t2)
return t1
end

---copy from the table 't2' to table 't1' ignoring the metatable and overwriting values, does copy UIObjects
---copy the values from table2 to table1 overwriting existing values, ignores __index and __newindex, threat UIObjects as regular tables
---@param t1 table
---@param t2 table
---@return table
Expand Down Expand Up @@ -640,12 +640,83 @@ function DF.table.deploy(t1, t2)
return t1
end

local function tableToString(t, resultString, deep, seenTables)
resultString = resultString or ""
deep = deep or 0
seenTables = seenTables or {}

if seenTables[t] then
resultString = resultString .. "--CIRCULAR REFERENCE\n"
return resultString
end

local space = string.rep(" ", deep)

seenTables[t] = true

for key, value in pairs(t) do
local valueType = type(value)

if (type(key) == "function") then
key = "#function#"
elseif (type(key) == "table") then
key = "#table#"
end

if (type(key) ~= "string" and type(key) ~= "number") then
key = "unknown?"
end

if (valueType == "table") then
local sUIObjectType = value.GetObjectType and value:GetObjectType()
if (sUIObjectType) then
if (type(key) == "number") then
resultString = resultString .. space .. "[" .. key .. "] = |cFFa9ffa9 " .. sUIObjectType .. " {|r\n"
else
resultString = resultString .. space .. "[\"" .. key .. "\"] = |cFFa9ffa9 " .. sUIObjectType .. " {|r\n"
end
else
if (type(key) == "number") then
resultString = resultString .. space .. "[" .. key .. "] = |cFFa9ffa9 {|r\n"
else
resultString = resultString .. space .. "[\"" .. key .. "\"] = |cFFa9ffa9 {|r\n"
end
end
resultString = resultString .. tableToString(value, nil, deep + 1, seenTables)
resultString = resultString .. space .. "|cFFa9ffa9},|r\n"

elseif (valueType == "string") then
resultString = resultString .. space .. "[\"" .. key .. "\"] = \"|cFFfff1c1" .. value .. "|r\",\n"

elseif (valueType == "number") then
resultString = resultString .. space .. "[\"" .. key .. "\"] = |cFFffc1f4" .. value .. "|r,\n"

elseif (valueType == "function") then
resultString = resultString .. space .. "[\"" .. key .. "\"] = function()end,\n"

elseif (valueType == "boolean") then
resultString = resultString .. space .. "[\"" .. key .. "\"] = |cFF99d0ff" .. (value and "true" or "false") .. "|r,\n"
end
end

return resultString
end

local function tableToStringSafe(t)
local seenTables = {}
return tableToString(t, nil, 0, seenTables)
end


---get the contends of table 't' and return it as a string
---@param t table
---@param resultString string
---@param deep integer
---@return string
function DF.table.dump(t, resultString, deep)

if true then return tableToStringSafe(t) end

resultString = resultString or ""
deep = deep or 0
local space = ""
Expand Down Expand Up @@ -967,7 +1038,7 @@ end
---@param self table
---@param fontString fontstring
---@param degrees number
function DF:SetFontRotation(fontString, degrees)
function DF:SetFontRotation(fontString, degrees) --deprecated, use fontString:SetRotation(degrees)
if (type(degrees) == "number") then
if (not fontString.__rotationAnimation) then
fontString.__rotationAnimation = DF:CreateAnimationHub(fontString)
Expand Down Expand Up @@ -3927,7 +3998,7 @@ function DF:CreateGlowOverlay (parent, antsColor, glowColor)
glowFrame.SetColor = glow_overlay_setcolor

glowFrame:SetColor(antsColor, glowColor)

glowFrame:Hide()

parent.overlay = glowFrame
Expand All @@ -3950,7 +4021,7 @@ function DF:CreateGlowOverlay (parent, antsColor, glowColor)
--glowFrame.ProcStartFlipbook:SetSize(frameWidth * scale, frameHeight * scale)
glowFrame.ProcStartFlipbook:SetPoint("TOPLEFT", glowFrame, "TOPLEFT", -frameWidth * scale, frameHeight * scale)
glowFrame.ProcStartFlipbook:SetPoint("BOTTOMRIGHT", glowFrame, "BOTTOMRIGHT", frameWidth * scale, -frameHeight * scale)
end
end
glowFrame:EnableMouse(false)
return glowFrame
end
Expand Down Expand Up @@ -4557,19 +4628,22 @@ end
---@return any
function DF:Dispatch(func, ...)
if (type(func) ~= "function") then
return dispatch_error (_, "DF:Dispatch expect a function as parameter 1.")
return dispatch_error(_, "DetailsFramework:Dispatch(func) expect a function as parameter 1.")
end
return select(2, xpcall(func, geterrorhandler(), ...))

local dispatchResult = {xpcall(func, geterrorhandler(), ...)}
local okay = dispatchResult[1]
--[=[
local dispatchResult = {xpcall(func, geterrorhandler(), ...)}
local okay = dispatchResult[1]
if (not okay) then
return false
end
if (not okay) then
return false
end
tremove(dispatchResult, 1)
tremove(dispatchResult, 1)
return unpack(dispatchResult)
return unpack(dispatchResult)
--]=]
end

--[=[
Expand Down
Loading

0 comments on commit 5cef044

Please sign in to comment.