-
Notifications
You must be signed in to change notification settings - Fork 4
/
GridStatus.lua
executable file
·96 lines (84 loc) · 2.11 KB
/
GridStatus.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
Grid2.statuses = {}
Grid2.statusTypes = {}
local status = {}
function status:init(name)
LibStub("AceEvent-3.0"):Embed(self)
self.indicators = {}
self.name = name
end
function status:RegisterIndicator(indicator)
if self.indicators[indicator] then
Grid2:Print(string.format("WARNING ! Indicator %s already registered with status %s", indicator.name, self.name))
return
end
local enabled = next(self.indicators)
self.indicators[indicator] = true
if not enabled then
self.enabled = true
self:OnEnable()
end
end
function status:UnregisterIndicator(indicator)
if not self.indicators[indicator] then return end
self.indicators[indicator] = nil
local enabled = next(self.indicators)
if not enabled then
self.enabled = nil
self:OnDisable()
end
end
function status:UpdateIndicators(unit)
for parent in next, Grid2:GetUnitFrames(unit) do
for indicator in pairs(self.indicators) do
indicator:Update(parent, unit)
end
end
end
function status:HasRange()
return self.range
end
function status:IsInRange(unitid, range)
return not self.range or (range and self.range >= range)
end
function status:UpdateDB(dbx)
-- ToDo: copy if it already exists
-- ToDo: update if it changed
if (dbx) then
self.dbx = dbx
end
-- print("status:UpdateDB", self.name)
end
Grid2.statusPrototype = {
__index = status,
new = function (self, ...)
local e = setmetatable({}, self)
e:init(...)
return e
end,
}
function Grid2:RegisterStatus(status, types, baseKey, dbx)
local name = status.name
if (baseKey and baseKey ~= name) then
self.statuses[name] = nil
status.name = baseKey
else
self.statuses[name] = status
for _, type in ipairs(types) do
local t = self.statusTypes[type]
if not t then
t = {}
self.statusTypes[type] = t
end
t[#t+1] = status
end
end
status.dbx = dbx
--Old
if self.db then
-- print("Grid2:RegisterStatus bad old style db", baseKey)
self:InitializeElement("status", status)
end
end
function Grid2:IterateStatuses(type)
return next, type and self.statusTypes[type] or self.statuses
end