-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathoglow.lua
120 lines (92 loc) · 2.48 KB
/
oglow.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
local _, ns = ...
local oGlow = ns.oGlow
local _VERSION = GetAddOnMetadata('oGlow', 'version')
local argcheck = oGlow.argcheck
local print = function(...) print("|cff33ff99oGlow:|r ", ...) end
local error = function(...) print("|cffff0000Error:|r "..string.format(...)) end
local pipesTable = ns.pipesTable
local filtersTable = ns.filtersTable
local displaysTable = ns.displaysTable
local numFilters = 0
local optionCallbacks = {}
local activeFilters = ns.activeFilters
local upgradePath = {
[0] = function(db)
db.FilterSettings = {}
db.Colors = {}
db.version = 1
end
}
local upgradeDB = function(db)
local version = db.version
if(upgradePath[version]) then
repeat
upgradePath[version](db)
version = version + 1
until not upgradePath[version]
end
end
local ADDON_LOADED = function(self, event, addon)
if(addon == 'oGlow') then
if(not oGlowDB) then
oGlowDB = {
version = 1,
EnabledPipes = {},
EnabledFilters = {},
FilterSettings = {},
Colors = {},
}
for pipe in next, pipesTable do
self:EnablePipe(pipe)
for filter in next, filtersTable do
self:RegisterFilterOnPipe(pipe, filter)
end
end
else
upgradeDB(oGlowDB)
for name, color in next, oGlowDB.Colors do
oGlow:RegisterColor(name, unpack(color))
end
for pipe in next, oGlowDB.EnabledPipes do
self:EnablePipe(pipe)
for filter, enabledPipes in next, oGlowDB.EnabledFilters do
if(enabledPipes[pipe]) then
self:RegisterFilterOnPipe(pipe, filter)
break
end
end
end
end
self:CallOptionCallbacks()
end
end
--[[ General API ]]
function oGlow:CallFilters(pipe, frame, ...)
argcheck(pipe, 2, 'string')
if(not pipesTable[pipe]) then return nil, 'Pipe does not exist.' end
local ref = activeFilters[pipe]
if(ref) then
for display, filters in next, ref do
-- TODO: Move this check out of the loop.
if(not displaysTable[display]) then return nil, 'Display does not exist.' end
for i=1,#filters do
local func = filters[i][2]
-- drop out of the loop if we actually do something nifty on a frame.
if(displaysTable[display](frame, func(...))) then break end
end
end
end
end
function oGlow:RegisterOptionCallback(func)
argcheck(func, 2, 'function')
table.insert(optionCallbacks, func)
end
function oGlow:CallOptionCallbacks()
for _, func in next, optionCallbacks do
func(oGlowDB)
end
end
oGlow:RegisterEvent('ADDON_LOADED', ADDON_LOADED)
oGlow.argcheck = argcheck
oGlow.version = _VERSION
_G.oGlow = oGlow