-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVortexMeter_Utilities.lua
96 lines (80 loc) · 2.78 KB
/
VortexMeter_Utilities.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
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
86
87
88
89
90
91
92
93
94
95
96
---------------------------------------------------------------------------------------
-- Vortex Meter
--- Maintained by Vim <Codex>
--- Original addon : Rift Meter by Vince (http://www.curse.com/addons/rift/rift-meter)
local VortexMeter = Apollo.GetAddon("VortexMeter")
table.empty = function(t) for k in pairs(t) do t[k] = nil end end
math.round = function(val) return math.floor(val + .5) end
function VortexMeter.formatSeconds(seconds)
return ("%02d:%02d"):format(seconds / 60, seconds % 60)
end
function VortexMeter.numberShortFormat(num)
if math.round(num) > 1000000 then return ("%.1fm"):format(math.round(num) / 1000000)
elseif math.round(num) > 1000 then return ("%.1fk"):format(math.round(num) / 1000)
else return tostring(math.round(num)) end
end
function VortexMeter.numberFormat(num)
local str = tostring(math.round(num))
if VortexMeter.settings.showShortNumber then
return VortexMeter.numberShortFormat(num)
else
local formatted = str:reverse():gsub("(%d%d%d)","%1,"):reverse()
return str:len() % 3 == 0 and formatted:sub(2) or formatted
end
end
function VortexMeter.BuildFormat(absolute, perSecond, percent)
local args = {}
local format = ""
if VortexMeter.settings.showAbsolute then
table.insert(args, absolute)
format = format .. "%s" .. (VortexMeter.settings.showPercent and " (" or ", ") .. "%s"
else
format = format .. "%s"
end
table.insert(args, VortexMeter.numberFormat(perSecond))
if VortexMeter.settings.showPercent then
table.insert(args, percent)
format = format .. (VortexMeter.settings.showAbsolute and ", " or " ") .. (not VortexMeter.settings.showAbsolute and "(" or "") .. "%.1f%%)"
end
return format:format(unpack(args))
end
function VortexMeter.colorize(text, fromHex, toHex)
local colored = {}
local len = text:len() - 1
local from = {
r = bit.rshift(fromHex, 16),
g = bit.band(bit.rshift(fromHex, 8), 0xff),
b = bit.band(fromHex, 0xff)
}
local to = {
r = bit.rshift(toHex, 16),
g = bit.band(bit.rshift(toHex, 8), 0xff),
b = bit.band(toHex, 0xff)
}
local step = {
r = (to.r - from.r) / len,
g = (to.g - from.g) / len,
b = (to.b - from.b) / len
}
for char in text:gmatch(".") do
table.insert(colored, ("<P TextColor=\"ff%02x%02x%02x\">%s</P>"):format(from.r, from.g, from.b, char))
from.r = from.r + step.r
from.g = from.g + step.g
from.b = from.b + step.b
end
return table.concat(colored)
end
function VortexMeter.deepcopy(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[VortexMeter.deepcopy(orig_key)] = VortexMeter.deepcopy(orig_value)
end
setmetatable(copy, VortexMeter.deepcopy(getmetatable(orig)))
else -- number, string, boolean, etc
copy = orig
end
return copy
end