From 8b766c23d283865bbd893b4824860453554cb6d9 Mon Sep 17 00:00:00 2001 From: Sumsebrum Date: Wed, 17 Aug 2022 14:24:09 +0200 Subject: [PATCH] Util - color array - rgb to hexcolor - dump table --- Util.lua | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Util.lua b/Util.lua index cc80e47..3599d39 100644 --- a/Util.lua +++ b/Util.lua @@ -2,7 +2,8 @@ local pairs, ipairs = pairs, ipairs local select = select local type = type local floor = math.floor -local str_find, str_gsub, str_sub, tinsert = string.find, string.gsub, string.sub, table.insert +local str_find, str_gsub, str_sub, str_format = string.find, string.gsub, string.sub, string.format +local tinsert = table.insert local Gladdy = LibStub("Gladdy") local L = Gladdy.L local AuraUtil = AuraUtil @@ -228,4 +229,33 @@ function Gladdy:GetExceptionSpellName(spellID) end end return select(1, GetSpellInfo(spellID)) +end + +local function toHex(color) + if not color or not color.r or not color.g or not color.b then + return "000000" + end + return str_format("%.2x%.2x%.2x", floor(color.r * 255), floor(color.g * 255), floor(color.b * 255)) +end +function Gladdy:SetTextColor(text, color) + return "|cff" .. toHex(color) .. text or "" .. "|r" +end + +function Gladdy:ColorAsArray(color) + return {color.r, color.g, color.b, color.a} +end + +function Gladdy:Dump(table, space) + if type(table) ~= "table" then + return + end + if not space then + space = "" + end + for k,v in pairs(table) do + Gladdy:Print(space .. k .. " - ", v) + if type(v) == "table" then + Gladdy:Dump(v, space .. " ") + end + end end \ No newline at end of file