File src/ChorusAuraFrameTemplate.lua changed (mode: 100644) (index ee57294..faf5d72) |
1 |
1 |
local Chorus = Chorus |
local Chorus = Chorus |
2 |
2 |
|
|
|
3 |
|
local auraButtonEventProcessor = Chorus.auraButtonEventProcessor |
|
4 |
|
|
3 |
5 |
local UnitAura = Chorus.test.UnitAura or UnitAura |
local UnitAura = Chorus.test.UnitAura or UnitAura |
4 |
6 |
local UnitExists = Chorus.test.UnitExists or UnitExists |
local UnitExists = Chorus.test.UnitExists or UnitExists |
5 |
7 |
local UnitIsConnected = Chorus.test.UnitIsConnected or UnitIsConnected |
local UnitIsConnected = Chorus.test.UnitIsConnected or UnitIsConnected |
|
... |
... |
local auraWeightMap = { |
67 |
69 |
Chorus.auraWeightMap = auraWeightMap |
Chorus.auraWeightMap = auraWeightMap |
68 |
70 |
|
|
69 |
71 |
local function getAuraWeight(unitDesignation, auraIndex, filter) |
local function getAuraWeight(unitDesignation, auraIndex, filter) |
70 |
|
local name, _, _, _, category, durationSec, owner = UnitAura(unitDesignation, auraIndex, filter) |
|
|
72 |
|
local name, _, _, _, _, durationSec, owner = UnitAura(unitDesignation, auraIndex, filter) |
71 |
73 |
if not name then |
if not name then |
72 |
74 |
return 0 |
return 0 |
73 |
75 |
end |
end |
74 |
76 |
|
|
75 |
|
--[[ TODO Make sure getAuraWeight implementation does not depend on locale. ]]-- |
|
76 |
|
local categoryPrio = 1 |
|
77 |
|
if 'Magic' == category then |
|
78 |
|
categoryPrio = 5 |
|
79 |
|
elseif 'Poison' == category then |
|
80 |
|
categoryPrio = 4 |
|
81 |
|
elseif 'Disease' == category then |
|
82 |
|
categoryPrio = 3 |
|
83 |
|
elseif 'Curse' == category then |
|
84 |
|
categoryPrio = 2 |
|
85 |
|
end |
|
86 |
|
categoryPrio = math.min(math.max(1, math.floor(math.abs(categoryPrio))), 9) |
|
87 |
|
|
|
88 |
77 |
local specialPrio = auraWeightMap[name] or 0 |
local specialPrio = auraWeightMap[name] or 0 |
89 |
78 |
specialPrio = math.min(math.max(1, math.floor(math.abs(specialPrio))), 9) |
specialPrio = math.min(math.max(1, math.floor(math.abs(specialPrio))), 9) |
90 |
79 |
|
|
|
... |
... |
local function getAuraWeight(unitDesignation, auraIndex, filter) |
100 |
89 |
|
|
101 |
90 |
local weight = 100000 * ownerPrio + |
local weight = 100000 * ownerPrio + |
102 |
91 |
10000 * specialPrio + |
10000 * specialPrio + |
103 |
|
durationIsLimited * (7201 - math.min(durationSec, 7200)) + |
|
104 |
|
categoryPrio |
|
|
92 |
|
durationIsLimited * (7201 - math.min(durationSec, 7200)) |
105 |
93 |
return math.abs(math.floor(weight)) |
return math.abs(math.floor(weight)) |
106 |
94 |
end |
end |
107 |
95 |
|
|
|
... |
... |
end |
129 |
117 |
local function auraFrameEventProcessor(self, eventCategory, ...) |
local function auraFrameEventProcessor(self, eventCategory, ...) |
130 |
118 |
assert(self ~= nil) |
assert(self ~= nil) |
131 |
119 |
|
|
|
120 |
|
--[[ Optimization hack ]]-- |
|
121 |
|
--[[ Make it use table value if it lags again. ]]-- |
132 |
122 |
local unitDesignation = SecureButton_GetUnit(self) or 'none' |
local unitDesignation = SecureButton_GetUnit(self) or 'none' |
133 |
123 |
assert(unitDesignation ~= nil) |
assert(unitDesignation ~= nil) |
134 |
124 |
assert('string' == type(unitDesignation)) |
assert('string' == type(unitDesignation)) |
|
... |
... |
local function auraFrameEventProcessor(self, eventCategory, ...) |
150 |
140 |
end |
end |
151 |
141 |
end |
end |
152 |
142 |
|
|
|
143 |
|
--[[ Make it use table value if it lags again. ]]-- |
153 |
144 |
local filter = SecureButton_GetAttribute(self, 'filter') |
local filter = SecureButton_GetAttribute(self, 'filter') |
154 |
145 |
assert(filter ~= nil) |
assert(filter ~= nil) |
155 |
146 |
assert('string' == type(filter)) |
assert('string' == type(filter)) |
|
... |
... |
local function auraFrameEventProcessor(self, eventCategory, ...) |
178 |
169 |
assert(k >= 0) |
assert(k >= 0) |
179 |
170 |
b.index = k |
b.index = k |
180 |
171 |
|
|
181 |
|
local func = b:GetScript('OnEvent') |
|
182 |
|
if func then |
|
183 |
|
func(b, eventCategory, ...) |
|
184 |
|
end |
|
|
172 |
|
auraButtonEventProcessor(b, eventCategory, ...) |
185 |
173 |
end |
end |
186 |
174 |
|
|
187 |
175 |
while (i < #t) do |
while (i < #t) do |
|
... |
... |
local function auraFrameEventProcessor(self, eventCategory, ...) |
190 |
178 |
assert(b ~= nil) |
assert(b ~= nil) |
191 |
179 |
b.index = 0 |
b.index = 0 |
192 |
180 |
|
|
193 |
|
local func = b:GetScript('OnEvent') |
|
194 |
|
if func then |
|
195 |
|
func(b, eventCategory, ...) |
|
196 |
|
end |
|
|
181 |
|
auraButtonEventProcessor(b, eventCategory, ...) |
197 |
182 |
end |
end |
198 |
183 |
end |
end |
199 |
184 |
|
|
|
... |
... |
function Chorus.auraFrameMain(self) |
244 |
229 |
self:RegisterEvent('PLAYER_TARGET_CHANGED') |
self:RegisterEvent('PLAYER_TARGET_CHANGED') |
245 |
230 |
self:RegisterEvent('UNIT_AURA') |
self:RegisterEvent('UNIT_AURA') |
246 |
231 |
|
|
|
232 |
|
--[[ Disable redundant aura updates. ]]-- |
|
233 |
|
local t = {self:GetChildren()} |
|
234 |
|
local i = 0 |
|
235 |
|
while (i < #t) do |
|
236 |
|
i = i + 1 |
|
237 |
|
local b = t[i] |
|
238 |
|
if b then |
|
239 |
|
b:UnregisterEvent('UNIT_AURA') |
|
240 |
|
end |
|
241 |
|
end |
|
242 |
|
|
|
243 |
|
--[[ Optimization hack. This function call is expensive. Probably. ]]-- |
|
244 |
|
self.unit = SecureButton_GetUnit(self) |
|
245 |
|
self.filter = SecureButton_GetAttribute(self, 'filter') |
|
246 |
|
|
247 |
247 |
self:SetScript('OnEvent', auraFrameEventProcessor) |
self:SetScript('OnEvent', auraFrameEventProcessor) |
248 |
248 |
end |
end |