-
Notifications
You must be signed in to change notification settings - Fork 8
/
colors.lua
50 lines (38 loc) · 1.07 KB
/
colors.lua
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
local _, ns = ...
local oGlow = ns.oGlow
local argcheck = oGlow.argcheck
local colorTable = setmetatable(
{},
-- We mainly want to handle item quality coloring, so this acts as a fallback.
-- The bonus of doing this is that we don't really have to make any updates to
-- the add-on if any new item colors are added. It also caches unlike the old
-- version.
{__index = function(self, val)
argcheck(val, 2, 'number')
local r, g, b = GetItemQualityColor(val)
rawset(self, val, {r, g, b})
return self[val]
end}
)
function oGlow:RegisterColor(name, r, g, b)
argcheck(name, 2, 'string', 'number')
argcheck(r, 3, 'number')
argcheck(g, 4, 'number')
argcheck(b, 5, 'number')
local color = rawget(colorTable, name)
if(color) then
color[1], color[2], color[3] = r, g, b
else
color = {r, g, b}
rawset(colorTable, name, color)
end
oGlowDB.Colors[name] = color
return true
end
function oGlow:ResetColor(name)
argcheck(name, 2, 'string', 'number')
oGlowDB.Colors[name] = nil
colorTable[name] = nil
return unpack(colorTable[name])
end
ns.colorTable = colorTable