File src/ClearcastingFrame.lua changed (mode: 100644) (index 7c61142..b5ba4e2) |
... |
... |
local function findPictureFile(auraName) |
41 |
41 |
["Infusion of Light"] = "Interface\\Icons\\Ability_Paladin_InfusionofLight", |
["Infusion of Light"] = "Interface\\Icons\\Ability_Paladin_InfusionofLight", |
42 |
42 |
["Judgements of the Pure"] = "Interface\\Icons\\Ability_Paladin_JudgementofthePure", |
["Judgements of the Pure"] = "Interface\\Icons\\Ability_Paladin_JudgementofthePure", |
43 |
43 |
["Light's Grace"] = "Interface\\Icons\\Spell_Holy_LightsGrace", |
["Light's Grace"] = "Interface\\Icons\\Spell_Holy_LightsGrace", |
|
44 |
|
["Serendipity"] = "Interface\\Icons\\Spell_Holy_Serendipity", |
|
45 |
|
["Surge of Light"] = "Interface\\Icons\\Spell_Holy_SurgeofLight", |
|
46 |
|
["Enrage"] = "Interface\\Icons\\Spell_Shadow_UnholyFrenzy", |
44 |
47 |
} |
} |
45 |
48 |
pictureFile = pictureMap[auraName] |
pictureFile = pictureMap[auraName] |
46 |
49 |
|
|
|
... |
... |
local function getIndicatorDefaultSize() |
56 |
59 |
return 32 |
return 32 |
57 |
60 |
end |
end |
58 |
61 |
|
|
59 |
|
|
|
60 |
62 |
local function createIndicator(frameName, parentFrame, unitDesignation, auraName, auraId) |
local function createIndicator(frameName, parentFrame, unitDesignation, auraName, auraId) |
61 |
63 |
assert (frameName ~= nil) |
assert (frameName ~= nil) |
62 |
64 |
assert (parentFrame ~= nil) |
assert (parentFrame ~= nil) |
|
... |
... |
local function createIndicator(frameName, parentFrame, unitDesignation, auraName |
93 |
95 |
f.text = t |
f.text = t |
94 |
96 |
f.unitDesignation = unitDesignation |
f.unitDesignation = unitDesignation |
95 |
97 |
|
|
|
98 |
|
print('[Clearcasting]: create indicator ' .. auraName .. ' ' .. tostring(auraId) .. |
|
99 |
|
' ' .. icon ) |
|
100 |
|
|
96 |
101 |
f:Hide() |
f:Hide() |
97 |
102 |
return f |
return f |
98 |
103 |
end |
end |
|
... |
... |
local function getAuraId(spellName, spellCategory) |
160 |
165 |
end |
end |
161 |
166 |
|
|
162 |
167 |
local function reload(rootFrame) |
local function reload(rootFrame) |
|
168 |
|
print('[Clearcasting]: enter reload') |
163 |
169 |
assert (rootFrame ~= nil) |
assert (rootFrame ~= nil) |
164 |
170 |
|
|
165 |
171 |
local t = rootFrame.indicatorTable |
local t = rootFrame.indicatorTable |
|
... |
... |
local function reload(rootFrame) |
168 |
174 |
assert (#t >= 1) |
assert (#t >= 1) |
169 |
175 |
assert (#t <= 1024) |
assert (#t <= 1024) |
170 |
176 |
|
|
|
177 |
|
rootFrame.elapsedSecs = 0.0 |
|
178 |
|
|
171 |
179 |
local i = #t |
local i = #t |
172 |
180 |
while (i > 0) do |
while (i > 0) do |
173 |
181 |
local f = t[i] |
local f = t[i] |
|
... |
... |
local function reload(rootFrame) |
183 |
191 |
if not f.auraId then |
if not f.auraId then |
184 |
192 |
f.auraId = getAuraId(auraName) |
f.auraId = getAuraId(auraName) |
185 |
193 |
if not f.auraId then |
if not f.auraId then |
186 |
|
--[[print('[Clearcasting]: Spell "' .. tostring(auraName) .. '" is unavailable.')]]-- |
|
|
194 |
|
print('[Clearcasting]: spell "' .. tostring(auraName) .. '" is unavailable (188).') |
187 |
195 |
end |
end |
188 |
196 |
end |
end |
189 |
197 |
|
|
|
... |
... |
local function reload(rootFrame) |
199 |
207 |
|
|
200 |
208 |
i = i - 1 |
i = i - 1 |
201 |
209 |
end |
end |
|
210 |
|
print('[Clearcasting]: exit reload') |
|
211 |
|
end |
|
212 |
|
|
|
213 |
|
function ClearcastingReload() |
|
214 |
|
if nil == ClearcastingFrame then |
|
215 |
|
error('[Clearcasting]: could not access root frame') |
|
216 |
|
end |
|
217 |
|
reload(ClearcastingFrame) |
202 |
218 |
end |
end |
203 |
219 |
|
|
204 |
220 |
local function eventProcessor(rootFrame, eventCategory, ...) |
local function eventProcessor(rootFrame, eventCategory, ...) |
|
... |
... |
local function eventProcessor(rootFrame, eventCategory, ...) |
207 |
223 |
acceptUnitAura(rootFrame, unitDesignation) |
acceptUnitAura(rootFrame, unitDesignation) |
208 |
224 |
elseif 'SPELLS_CHANGED' == eventCategory then |
elseif 'SPELLS_CHANGED' == eventCategory then |
209 |
225 |
reload(rootFrame) |
reload(rootFrame) |
|
226 |
|
elseif 'ADDON_LOADED' == eventCategory then |
|
227 |
|
reload(rootFrame) |
|
228 |
|
elseif 'PLAYER_ENTERS_WORLD' == eventCategory then |
|
229 |
|
reload(rootFrame) |
210 |
230 |
end |
end |
211 |
231 |
end |
end |
212 |
232 |
|
|
|
... |
... |
local function getUnitAuraRemainingSecs(unitDesignation, auraId) |
221 |
241 |
if nil == stackQuantity or type(stackQuantity) ~= 'number' then |
if nil == stackQuantity or type(stackQuantity) ~= 'number' then |
222 |
242 |
stackQuantity = 0 |
stackQuantity = 0 |
223 |
243 |
end |
end |
224 |
|
stackQuantitiy = math.min(math.max(0, stackQuantity), 8) |
|
|
244 |
|
stackQuantitiy = math.min(math.max(0, stackQuantity), 99) |
225 |
245 |
return (expirationTime - GetTime()), duration, stackQuantity |
return (expirationTime - GetTime()), duration, stackQuantity |
226 |
246 |
end |
end |
227 |
247 |
|
|
|
... |
... |
local function updateEveryIndicator(rootFrame) |
232 |
252 |
local f = t[i] |
local f = t[i] |
233 |
253 |
assert (f ~= nil) |
assert (f ~= nil) |
234 |
254 |
local auraId = f.auraId |
local auraId = f.auraId |
|
255 |
|
local auraName = f.auraName |
235 |
256 |
if auraId ~= nil then |
if auraId ~= nil then |
236 |
257 |
assert (auraId >= 1) |
assert (auraId >= 1) |
237 |
258 |
local unitDesignation = f.unitDesignation |
local unitDesignation = f.unitDesignation |
|
... |
... |
local function updateEveryIndicator(rootFrame) |
258 |
279 |
end |
end |
259 |
280 |
|
|
260 |
281 |
local function updateProcessor(rootFrame, elapsedSecs) |
local function updateProcessor(rootFrame, elapsedSecs) |
261 |
|
rootFrame.elapsedSecs = rootFrame.elapsedSecs + elapsedSecs |
|
262 |
|
local cooldownDurationSecs = rootFrame.elapsedSecs |
|
263 |
|
if cooldownDurationSecs >= 0.5 then |
|
|
282 |
|
assert (rootFrame ~= nil) |
|
283 |
|
assert (elapsedSecs ~= nil) |
|
284 |
|
assert (type(elapsedSecs) == 'number') |
|
285 |
|
elapsedSecs = math.min(math.max(0, elapsedSecs), 999) |
|
286 |
|
|
|
287 |
|
local duration = rootFrame.elapsedSecs |
|
288 |
|
if duration == nil then |
|
289 |
|
duration = 0.0 |
|
290 |
|
elseif type(duration) ~= 'number' then |
|
291 |
|
duration = 0.0 |
|
292 |
|
end |
|
293 |
|
duration = math.min(math.max(0, duration + elapsedSecs), 999) |
|
294 |
|
rootFrame.elapsedSecs = duration |
|
295 |
|
if duration >= 0.08 then |
264 |
296 |
updateEveryIndicator(rootFrame) |
updateEveryIndicator(rootFrame) |
265 |
|
else |
|
266 |
297 |
rootFrame.elapsedSecs = 0.0 |
rootFrame.elapsedSecs = 0.0 |
267 |
298 |
end |
end |
268 |
299 |
end |
end |
269 |
300 |
|
|
270 |
|
local function isSpellAvailable(spellName) |
|
271 |
|
local n = GetSpellInfo(spellName) |
|
|
301 |
|
--[[-- |
|
302 |
|
Use unique aura identifier when possible. |
|
303 |
|
Otherwise use aura name. Function may fail when given spell name. |
|
304 |
|
An aura is either a spell in character spell book or talent effect. |
|
305 |
|
]] |
|
306 |
|
local function isSpellAvailable(eitherSpellIdOrName) |
|
307 |
|
local n = GetSpellInfo(eitherSpellIdOrName) |
272 |
308 |
return n ~= nil |
return n ~= nil |
273 |
309 |
end |
end |
274 |
310 |
|
|
|
... |
... |
local function initIndicator(rootFrame, auraName, column, row, auraId) |
292 |
328 |
auraId = getAuraId(auraName) |
auraId = getAuraId(auraName) |
293 |
329 |
end |
end |
294 |
330 |
if auraId ~= nil then |
if auraId ~= nil then |
295 |
|
assert (auraId >= 1) |
|
|
331 |
|
assert (auraId >= 1, '[Clearcasting]: invalid aura identifier') |
|
332 |
|
end |
|
333 |
|
|
|
334 |
|
if not isSpellAvailable(auraId) then |
|
335 |
|
error('[Clearcasting]: cannot initialise spell "' .. tostring(auraName) .. '" ' .. |
|
336 |
|
'aura identifier ' .. tostring(auraId) .. ' (line 343)') |
296 |
337 |
end |
end |
297 |
338 |
|
|
298 |
339 |
if nil == rootFrame.indicatorTable then |
if nil == rootFrame.indicatorTable then |
|
... |
... |
local function initIndicator(rootFrame, auraName, column, row, auraId) |
315 |
356 |
f:SetPoint('BOTTOMLEFT', size * column, size * row) |
f:SetPoint('BOTTOMLEFT', size * column, size * row) |
316 |
357 |
table.insert(t, f) |
table.insert(t, f) |
317 |
358 |
|
|
318 |
|
if not isSpellAvailable(auraName) then |
|
319 |
|
--[[print('[Clearcasting]: Spell "' .. tostring(auraName) .. '" is unavailable.')]]-- |
|
320 |
|
end |
|
321 |
|
|
|
322 |
359 |
assert (f ~= nil) |
assert (f ~= nil) |
323 |
360 |
assert (f:GetName() ~= nil) |
assert (f:GetName() ~= nil) |
324 |
361 |
return f |
return f |
|
... |
... |
local function initEveryIndicator(rootFrame) |
387 |
424 |
end |
end |
388 |
425 |
|
|
389 |
426 |
local function init(rootFrame) |
local function init(rootFrame) |
|
427 |
|
print('[Clearcasting]: enter init') |
390 |
428 |
local t = initEveryIndicator(rootFrame) |
local t = initEveryIndicator(rootFrame) |
391 |
429 |
assert (t ~= nil) |
assert (t ~= nil) |
392 |
430 |
assert (#t >= 1) |
assert (#t >= 1) |
|
... |
... |
local function init(rootFrame) |
400 |
438 |
|
|
401 |
439 |
rootFrame:RegisterEvent('UNIT_AURA') |
rootFrame:RegisterEvent('UNIT_AURA') |
402 |
440 |
rootFrame:RegisterEvent('SPELLS_CHANGED') |
rootFrame:RegisterEvent('SPELLS_CHANGED') |
|
441 |
|
print('[Clearcasting]: exit init') |
403 |
442 |
end |
end |
404 |
443 |
|
|
405 |
444 |
local function main() |
local function main() |