forked from frankdekker/PerfectRaid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerfectRaid_Utils.lua
More file actions
70 lines (54 loc) · 1.95 KB
/
PerfectRaid_Utils.lua
File metadata and controls
70 lines (54 loc) · 1.95 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
local DongleUtils = {}
PerfectRaid.utils = DongleUtils
function DongleUtils.RGBToHex(r, g, b)
return string.format("%02x%02x%02x", r, g, b)
end
function DongleUtils.RGBPercToHex(r, g, b)
return string.format("%02x%02x%02x", r*255, g*255, b*255)
end
function DongleUtils.HexToRGB(hex)
local rhex, ghex, bhex = string.sub(hex, 1, 2), string.sub(hex, 3, 4), string.sub(hex, 5, 6)
return tonumber(rhex, 16), tonumber(ghex, 16), tonumber(bhex, 16)
end
function DongleUtils.HexToRGBPerc(hex)
local rhex, ghex, bhex = string.sub(hex, 1, 2), string.sub(hex, 3, 4), string.sub(hex, 5, 6)
return tonumber(rhex, 16)/255, tonumber(ghex, 16)/255, tonumber(bhex, 16)/255
end
function DongleUtils.ColorGradient(perc, ...)
local num = select("#", ...)
local hexes = type(select(1, ...)) == "string"
if perc >= 1 then
if hexes then return select(num, ...)
else return select(num-2, ...), select(num-1, ...), select(num, ...) end
end
if perc <= 0 then
if hexes then return select(1, ...)
else return select(1, ...), select(2, ...), (select(3, ...)) end
end
if not hexes then num = num / 3 end
local segment, relperc = math.modf(perc*(num-1))
local r1, g1, b1, r2, g2, b2
if hexes then
r1, g1, b1 = DongleUtils.HexToRGBPerc(select(segment+1, ...))
r2, g2, b2 = DongleUtils.HexToRGBPerc(select(segment+2, ...))
else
r1, g1, b1 = select((segment*3)+1, ...), select((segment*3)+2, ...), select((segment*3)+3, ...)
r2, g2, b2 = select((segment*3)+4, ...), select((segment*3)+5, ...), select((segment*3)+6, ...)
end
if hexes then
return DongleUtils.RGBToHex(r1 + (r2-r1)*relperc,
g1 + (g2-g1)*relperc,
b1 + (b2-b1)*relperc)
else
return r1 + (r2-r1)*relperc,
g1 + (g2-g1)*relperc,
b1 + (b2-b1)*relperc
end
end
function DongleUtils.GetHPSeverity(perc, class)
if not class then return DongleUtils.ColorGradient(perc, 1,0,0, 1,1,0, 0,1,0)
else
local c = RAID_CLASS_COLORS[class]
return DongleUtils.ColorGradient(perc, 1,0,0, 1,1,0, c.r,c.g,c.b)
end
end