Repository navigation
Expand file tree
/
Copy pathSimpleMeters_Util.lua
More file actions
85 lines (67 loc) · 1.98 KB
/
Copy pathSimpleMeters_Util.lua
File metadata and controls
85 lines (67 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
-- SimpleMeters v0.5
-- Build date: 2026-07-18
local addon = _G.SimpleMeters
if not addon then
return
end
local floor = math.floor
local format = string.format
local function FormatOneDecimal(value, suffix)
local roundedTenth = floor((value * 10) + 0.5)
local whole = floor(roundedTenth / 10)
local tenth = roundedTenth - (whole * 10)
if tenth == 0 then
return whole .. suffix
end
return whole .. "." .. tenth .. suffix
end
function addon:AbbrevNumber(value)
value = tonumber(value) or 0
local negative = value < 0
if negative then
value = -value
end
local text
if value >= 1000000000 then
text = FormatOneDecimal(value / 1000000000, "b")
elseif value >= 1000000 then
text = FormatOneDecimal(value / 1000000, "m")
elseif value >= 1000 then
text = FormatOneDecimal(value / 1000, "k")
else
text = tostring(floor(value + 0.5))
end
if negative then
return "-" .. text
end
return text
end
function addon:GetClassColorTable(classFile)
if not classFile then
return nil
end
local custom = _G.CUSTOM_CLASS_COLORS
if custom and custom[classFile] then
return custom[classFile]
end
if RAID_CLASS_COLORS then
return RAID_CLASS_COLORS[classFile]
end
return nil
end
function addon:GetClassColorRGB(classFile)
local color = self:GetClassColorTable(classFile)
if color then
return color.r or color[1] or 1, color.g or color[2] or 1, color.b or color[3] or 1
end
return 0.82, 0.82, 0.82
end
function addon:GetClassColorHex(classFile, fallbackHex)
local r, g, b = self:GetClassColorRGB(classFile)
return format("%02x%02x%02x", floor((r * 255) + 0.5), floor((g * 255) + 0.5), floor((b * 255) + 0.5))
end
function addon:ColorizeNameByClass(name, classFile)
name = name or (UNKNOWNOBJECT or "Unknown")
local hex = self:GetClassColorHex(classFile, "d1d1d1")
return "|cff" .. hex .. name .. "|r"
end