-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathglyphs.lua
49 lines (41 loc) · 1.49 KB
/
glyphs.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
---@class AddonEnv
local _addon = select(2, ...);
---Glyph slot -> active spellID
---@type table<integer, integer|nil>
local activeGlyphs = {}
---Update specific slot
---@param slot integer
local function UpdateGlyphSlot(slot)
_addon.util.PrintDebug("Updating glyph "..slot);
local _, _, glyphSpellID = GetGlyphSocketInfo(slot);
local oldGlyphId = activeGlyphs[slot];
if oldGlyphId then
-- No change.
if oldGlyphId == glyphSpellID then return end
-- Remove old effects in slot.
local name = GetSpellInfo(oldGlyphId);
local oldGlyph = _addon.classGlyphs[oldGlyphId];
for k, effect in ipairs(oldGlyph) do
_addon:RemoveAuraEffect(name.."-"..k, effect, effect.value, oldGlyphId, true);
end
activeGlyphs[slot] = nil;
end
local glyphData = _addon.classGlyphs[glyphSpellID];
if glyphData then
-- Apply new glyph effect.
local name = GetSpellInfo(glyphSpellID);
for k, effect in ipairs(glyphData) do
_addon:ApplyAuraEffect(name.."-"..k, effect, effect.value, glyphSpellID, true);
end
activeGlyphs[slot] = glyphSpellID;
end
_addon:TriggerUpdate();
end
_addon.events.Register("GLYPH_ADDED", UpdateGlyphSlot);
_addon.events.Register("GLYPH_REMOVED", UpdateGlyphSlot);
_addon.events.Register("GLYPH_UPDATED", UpdateGlyphSlot);
_addon.events.Register("PLAYER_ENTERING_WORLD", function ()
for i=1, GetNumGlyphSockets() do
UpdateGlyphSlot(i);
end
end);