-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroupCds.lua
203 lines (154 loc) · 6.15 KB
/
groupCds.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
--[[ PLAN
TSU:
- as an added (optional) feature: gray/alpha out CDs for players who are
dead or more than 100 (?) yards away
group sort could sort by any of the following:
- remaining CD, CD
- remaining CD, custom options priority
- CD
- custom options priority
]]
-------------------------------------------------------------------------------
-- init
-- Convert the custom options to a lookup table that maps from spell ID to the
-- index for that spell ID in the user's custom options. This index can be
-- used as a proxy for priority.
local configuredSpells = {}
for index, spellEntry in ipairs(aura_env.config.spells) do
if spellEntry.enabled then
configuredSpells[spellEntry.spellId] = index
end
end
-- Register callbacks with 'LibOpenRaid'.
local libOr = LibStub:GetLibrary("LibOpenRaid-1.0")
if _G["INK_GROUPCDS_CALLBACKS_INSTALLED"] == nil then
_G["INK_GROUPCDS_CALLBACKS_INSTALLED"] = true
-- Note that we ignore the 'CooldownListWipe' event from 'LibOpenRaid',
-- since this WeakAura should unload when the player is not in a group.
local callbacks = {
["CooldownListUpdate"] = (
function(unitId, unitCooldowns, allUnitsCds)
WeakAuras.ScanEvents("INK_GROUPCDS_LIST_UPDATE", unitId)
end),
["CooldownUpdate"] = (
function(unitId, spellId, cooldownInfo, unitCooldowns, allUnitsCds)
WeakAuras.ScanEvents("INK_GROUPCDS_CD_UPDATE", unitId, spellId)
end),
}
for event, _ in pairs(callbacks) do
libOr.RegisterCallback(callbacks, event, event)
end
end
-- Define some helper functions.
local generateCloneId = function(unitId, spellId)
return GetUnitName(unitId, true) .. spellId
end
aura_env.setCooldownListForUnit = function(allstates, unitId)
-- Insert or update a state in the specified 'allstates' for each
-- configured spell that is known to the specified 'unitId'.
local unitCds = libOr.GetUnitCooldowns(unitId)
for spellId, cdInfo in pairs(unitCds) do
local configuredSpellPriority = configuredSpells[spellId]
if configuredSpellPriority ~= nil then
local cloneId = generateCloneId(unitId, spellId)
local state = allstates[cloneId]
if state == nil then
local spellInfo = C_Spell.GetSpellInfo(spellId)
state = {
["name"] = spellInfo["name"],
["icon"] = spellInfo["iconID"],
["progressType"] = "timed",
["autoHide"] = false,
["spellId"] = spellId,
}
allstates[cloneId] = state
end
state["show"] = true
state["changed"] = true
state["index"] = configuredSpellPriority
state["unit"] = unitId
local unitClass, _ = UnitClass(unitId)
state["classColor"] = C_ClassColor.GetClassColor(unitClass)
local _, _, _, charges, _, maxValue, _, duration =
libOr.GetCooldownStatusFromCooldownInfo(cdInfo)
state["stacks"] = charges
state["expirationTime"] = maxValue
state["duration"] = duration
end
end
end
aura_env.updateCooldownForUnit = function(allstates, unitId, spellId)
-- Update the state for in the specified 'allstates' for the specified
-- 'unitId' and 'spellId', if one exists, to reflect the new cooldown info.
-- Return 'true' if a state was updated. Otherwise, return 'false'.
local cloneId = generateCloneId(unitId, spellId)
local state = allstates[cloneId]
if state == nil then
return false
end
local _, _, _, charges, _, maxValue, _, duration =
libOr.GetCooldownStatusFromUnitSpellID(unitId, spellId)
state["changed"] = true
state["stacks"] = charges
state["expirationTime"] = maxValue
state["duration"] = duration
return true
end
-------------------------------------------------------------------------------
-- on show
local region = aura_env.region
if region.bar and aura_env.state.classColor then
region:Color(aura_env.state.classColor:GetRGBA())
end
-------------------------------------------------------------------------------
-- TSU: GROUP_ROSTER_UPDATE, INK_GROUPCDS_LIST_UPDATE, INK_GROUPCDS_CD_UPDATE
function(allstates, event, ...)
if (event == "OPTIONS"
or event == "STATUS"
or event == "GROUP_ROSTER_UPDATE") then
-- Hide all states in order to remove spells for units no longer in the
-- group.
for _, state in pairs(allstates) do
state["show"] = false
state["changed"] = true
end
-- Set the states for each configured spell for each group unit.
for unit in WA_IterateGroupMembers() do
aura_env.setCooldownListForUnit(allstates, unit)
end
return true
elseif event == "INK_GROUPCDS_LIST_UPDATE" then
local unit = ...
-- Hide any states associated with this unit in order to remove spells
-- that the unit no longer has.
for _, state in pairs(allstates) do
if state["unit"] == unit then
state["show"] = false
state["changed"] = true
end
end
-- Set the states for this unit.
aura_env.setCooldownListForUnit(allstates, unit)
return true
elseif event == "INK_GROUPCDS_CD_UPDATE" then
local unit, spellId = ...
return aura_env.updateCooldownForUnit(allstates, unit, spellId)
end
end
-------------------------------------------------------------------------------
-- custom variables
{
["expirationTime"] = true,
["duration"] = true,
["stacks"] = true,
["unit"] = "string",
["index"] = "number",
["spellId"] = "number",
}
-------------------------------------------------------------------------------
-- group sort: stacks, expirationTime, index
WeakAuras.ComposeSorts(
WeakAuras.SortDescending{"region", "state", "stacks"},
WeakAuras.SortAscending{"region", "state", "expirationTime"},
WeakAuras.SortAscending{"region", "state", "index"}
)