-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
executable file
·170 lines (138 loc) · 4.63 KB
/
Copy pathCore.lua
File metadata and controls
executable file
·170 lines (138 loc) · 4.63 KB
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
-- Next Target Highlighter Addon
---@diagnostic disable: undefined-global, param-type-mismatch
local addonName, addon = ...
addon.frame = addon.frame or CreateFrame("Frame")
addon.highlights = addon.highlights or {}
addon.pendingUpdate = addon.pendingUpdate or false
local sanitizeCommand = addon.SanitizeCommand
function addon:UpdateHighlight()
local inInstance, instanceType = IsInInstance()
if inInstance then
if #self.highlights > 0 then
self:ClearHighlights()
end
return
end
self:ClearHighlights()
if not NextTargetDB.enabled then
if NextTargetDB.debugMode then
self:UpdateDebugFrame({})
end
return
end
local results = self:CollectHighlights()
if NextTargetDB.debugMode then
self:UpdateDebugFrame(results)
end
end
function addon:RequestUpdate()
if self.pendingUpdate then
return
end
if not C_Timer or not C_Timer.After then
self:UpdateHighlight()
return
end
self.pendingUpdate = true
C_Timer.After(0.05, function()
addon.pendingUpdate = false
addon:UpdateHighlight()
end)
end
local eventHandlers = {}
local function handleQuestDataChanged(self)
if self.ResetCaches then
self:ResetCaches()
end
self:RequestUpdate()
end
eventHandlers.ADDON_LOADED = function(self, loadedAddon)
if loadedAddon ~= addonName then
return
end
self:InitializeDB()
self.frame:UnregisterEvent("ADDON_LOADED")
if NextTargetDB.debugMode then
self:ShowDebugFrame()
end
print("|cFF00FF00[next]|r loaded. Type |cFFFFFF00/next help|r for options.")
self:RequestUpdate()
end
eventHandlers.PLAYER_TARGET_CHANGED = function(self)
self:RequestUpdate()
end
eventHandlers.NAME_PLATE_UNIT_ADDED = function(self)
self:RequestUpdate()
end
eventHandlers.NAME_PLATE_UNIT_REMOVED = function(self)
self:RequestUpdate()
end
eventHandlers.PLAYER_ENTERING_WORLD = function(self)
self:RequestUpdate()
end
eventHandlers.QUEST_LOG_UPDATE = handleQuestDataChanged
eventHandlers.QUEST_ACCEPTED = handleQuestDataChanged
eventHandlers.QUEST_REMOVED = handleQuestDataChanged
eventHandlers.QUEST_TURNED_IN = handleQuestDataChanged
eventHandlers.QUEST_WATCH_LIST_CHANGED = handleQuestDataChanged
eventHandlers.TASK_PROGRESS_UPDATE = handleQuestDataChanged
eventHandlers.QUESTLINE_UPDATE = handleQuestDataChanged
addon.frame:SetScript("OnEvent", function(_, event, ...)
local handler = eventHandlers[event]
if handler then
handler(addon, ...)
end
end)
addon.frame:RegisterEvent("ADDON_LOADED")
addon.frame:RegisterEvent("PLAYER_TARGET_CHANGED")
addon.frame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
addon.frame:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
addon.frame:RegisterEvent("PLAYER_ENTERING_WORLD")
addon.frame:RegisterEvent("QUEST_LOG_UPDATE")
addon.frame:RegisterEvent("QUEST_ACCEPTED")
addon.frame:RegisterEvent("QUEST_REMOVED")
addon.frame:RegisterEvent("QUEST_TURNED_IN")
addon.frame:RegisterEvent("QUEST_WATCH_LIST_CHANGED")
addon.frame:RegisterEvent("TASK_PROGRESS_UPDATE")
addon.frame:RegisterEvent("QUESTLINE_UPDATE")
SLASH_NEXT1 = "/next"
SlashCmdList.NEXT = function(msg)
-- Wrap in pcall to prevent errors from breaking slash command system
local success, err = pcall(function()
msg = sanitizeCommand(msg or "")
msg = msg:lower()
if msg == "" then
addon:OpenSettings()
print("|cFF00FF00[next]|r commands:")
print(" |cFFFFFF00/next config|r - open settings")
print(" |cFFFFFF00/next toggle|r - enable or disable the addon")
return
end
if msg == "config" or msg == "options" or msg == "settings" then
addon:OpenSettings()
return
end
if msg == "toggle" then
NextTargetDB.enabled = not NextTargetDB.enabled
print(string.format("|cFF00FF00[next]|r addon %s", NextTargetDB.enabled and "enabled" or "disabled"))
addon:RequestUpdate()
return
end
if msg == "debug" then
NextTargetDB.debugMode = not NextTargetDB.debugMode
if NextTargetDB.debugMode then
addon:ShowDebugFrame()
else
addon:HideDebugFrame()
end
addon:RequestUpdate()
return
end
print("|cFF00FF00[next]|r commands:")
print(" |cFFFFFF00/next config|r - open settings")
print(" |cFFFFFF00/next toggle|r - enable or disable the addon")
end)
if not success then
print("|cFFFF0000[next]|r Error processing command: " .. tostring(err))
end
end