-
Notifications
You must be signed in to change notification settings - Fork 17
/
GridSetup.lua
81 lines (75 loc) · 2.27 KB
/
GridSetup.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
--[[
Created by Grid2 original authors, modified by Michael
--]]
local Grid2 = Grid2
local pairs = pairs
local tonumber = tonumber
function Grid2:SetupShutdown()
-- remove indicators
for _, indicator in Grid2:IterateIndicators() do
Grid2:UnregisterIndicator(indicator)
end
-- remove statuses
for _, status in Grid2:IterateStatuses() do
Grid2:UnregisterStatus(status)
end
end
function Grid2:SetupIndicators(setup)
local loaded = {}
-- Parent indicators are loaded before child indicators
local function SetupIndicator(baseKey, dbx)
if loaded[baseKey] then return true end
local anchorTo = dbx.anchorTo
if (not anchorTo) or SetupIndicator(anchorTo, setup[anchorTo]) then
local setupFunc = self.setupFunc[dbx.type]
if (setupFunc) then
setupFunc(baseKey, dbx)
loaded[baseKey] = true
return true
else
Grid2:Debug("SetupIndicators setupFunc not found for indicator: ", dbx.type)
end
else
Grid2:Debug("SetupIndicators child indicator not loaded due to failed dependencies: ", baseKey, dbx.type)
end
end
-- add new indicator types
for baseKey, dbx in pairs(setup) do
SetupIndicator(baseKey, dbx)
end
end
function Grid2:SetupStatuses(setup)
-- add new statuses
for baseKey, dbx in pairs(setup) do
local setupFunc = self.setupFunc[dbx.type]
if setupFunc then
setupFunc(baseKey, dbx)
else
Grid2:Debug("SetupStatuses setupFunc not found for status: ", dbx.type)
end
end
end
function Grid2:SetupStatusMap(setup)
for baseKey, map in pairs(setup) do
local indicator = self.indicators[baseKey]
if indicator then
for statusKey, priority in pairs(map) do
local status = self.statuses[statusKey]
if tonumber(priority) and status then
indicator:RegisterStatus(status, priority)
else
Grid2:Debug("Grid2:SetupStatusMap failed mapping:", statusKey, "status:", status, "priority:", priority, "indicator:", baseKey)
end
end
else
Grid2:Debug("Grid2:SetupStatusMap Could not find mapped indicator baseKey:", baseKey)
end
end
end
function Grid2:Setup()
local db = Grid2.db.profile
Grid2:SetupStatusPrototype()
Grid2:SetupIndicators(db.indicators)
Grid2:SetupStatuses(db.statuses)
Grid2:SetupStatusMap(db.statusMap)
end