-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathshards.lua
55 lines (49 loc) · 1.6 KB
/
shards.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
local myname, ns = ...
local core = LibStub("AceAddon-3.0"):GetAddon("SilverDragon")
local module = core:NewModule("Shards", "AceConsole-3.0", "AceEvent-3.0")
local Debug = core.Debug
function module:OnEnable()
self:RegisterEvent("PLAYER_TARGET_CHANGED")
self:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
self:RegisterEvent("NAME_PLATE_UNIT_ADDED")
if C_EventUtils.IsEventValid("VIGNETTE_MINIMAP_UPDATED") then
-- this needs to run in Classic, which doesn't have these
self:RegisterEvent("VIGNETTE_MINIMAP_UPDATED")
self:RegisterEvent("VIGNETTES_UPDATED")
end
-- todo: combat log as well?
-- Can't know it until we see an event
self.currentShard = "unknown"
end
function module:PLAYER_TARGET_CHANGED()
self:TrackCurrentShard(UnitGUID("target"))
end
function module:UPDATE_MOUSEOVER_UNIT()
self:TrackCurrentShard(UnitGUID("mouseover"))
end
function module:NAME_PLATE_UNIT_ADDED(event, unit)
self:TrackCurrentShard(UnitGUID(unit))
end
function module:VIGNETTE_MINIMAP_UPDATED(event, guid)
self:TrackCurrentShard(guid)
end
function module:VIGNETTES_UPDATED()
local vignetteids = C_VignetteInfo.GetVignettes()
for i=1, #vignetteids do
self:TrackCurrentShard(vignetteids[i])
end
end
function module:TrackCurrentShard(guid)
if not guid then return end
local shard = core:GUIDShard(guid)
if shard and self.currentShard ~= shard then
local lastShard = self.currentShard
self.currentShard = shard
Debug("ShardChanged", self.currentShard, lastShard, guid)
core.events:Fire("ShardChanged", self.currentShard, lastShard, guid)
return true
end
end
function module:GetCurrentShard()
return self.currentShard
end