-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
256 lines (224 loc) · 9.58 KB
/
Copy pathCore.lua
File metadata and controls
256 lines (224 loc) · 9.58 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
-- EllesmereUIMoonfire / Core.lua
--
-- Shared namespace, SavedVariables, Druid gate, dependency detection, slash
-- commands, debug output and the top-level event wiring. This file owns policy
-- (enabled / dormant / class gate); MoonfireAura.lua owns the managed AuraKit
-- presentation; Nameplates.lua owns the plate lifecycle.
--
-- Lua 5.1 only. No goto, no //, no native bitwise operators, no _ENV.
local ADDON, EMF = ...
-- Cheap upvalues.
local UnitClass = UnitClass
local C_Timer = C_Timer
------------------------------------------------------------------------------
-- SavedVariables defaults. Configuration ONLY -- never GUIDs, aura state,
-- expiration times, combat state or enemy databases.
------------------------------------------------------------------------------
local DEFAULTS = {
enabled = true,
indicator = {
size = 18,
x = -4, -- immediately to the LEFT of the health bar (negative = further left)
y = 0,
},
missingColour = { r = 1, g = 0, b = 0, a = 1 }, -- the static RED "needs Moonfire" background
purpleBorder = true, -- optional managed purple border around the Moonfire icon
showDuration = true, -- Blizzard-rendered, secret-safe countdown on the icon
debug = false,
}
EMF.DEFAULTS = DEFAULTS
------------------------------------------------------------------------------
-- Verified Moonfire aura IDs (see README). These are the DEBUFF AURA ids that
-- appear on the target, which is what the engine's candidate filter matches --
-- not the cast spell id. Every entry is documented; add none without checking.
------------------------------------------------------------------------------
EMF.MOONFIRE_AURA_IDS = {
[164812] = true, -- Moonfire (Spell Power) -- Balance / Guardian / Restoration DoT
[155625] = true, -- Moonfire (Attack Power) -- Feral, via the Lunar Inspiration talent
[8921] = true, -- Moonfire base spell id: harmless fallback (never matches if the
-- target aura is one of the ids above; costs nothing to keep).
}
EMF.STYLE_KEY = "EllesmereUIMoonfire"
------------------------------------------------------------------------------
-- Output helpers.
------------------------------------------------------------------------------
local PREFIX = "|cff8a5cf6[EMF]|r "
function EMF.Print(msg)
DEFAULT_CHAT_FRAME:AddMessage(PREFIX .. tostring(msg))
end
-- Debug messages are deliberately restricted to lifecycle facts (plate added /
-- removed / presentation attached). They must NEVER report aura state, managed
-- button visibility, secret durations or any forbidden frame inspection.
function EMF.Debug(msg)
if EMF.db and EMF.db.debug then
DEFAULT_CHAT_FRAME:AddMessage(PREFIX .. "|cff888888" .. tostring(msg) .. "|r")
end
end
------------------------------------------------------------------------------
-- State.
------------------------------------------------------------------------------
EMF.isDruid = false -- set at PLAYER_LOGIN
EMF.active = false -- true only when druid + enabled + deps present
EMF.AK = nil -- cached EllesmereUI.AuraKit
EMF.NS = nil -- cached _G.EllesmereNameplates_NS
-- Merges any missing default keys into the saved table (shallow + one nested
-- level for the known sub-tables). Keeps user edits, fills gaps after upgrades.
local function ApplyDefaults(dst, src)
for k, v in pairs(src) do
if type(v) == "table" then
if type(dst[k]) ~= "table" then dst[k] = {} end
for k2, v2 in pairs(v) do
if dst[k][k2] == nil then dst[k][k2] = v2 end
end
elseif dst[k] == nil then
dst[k] = v
end
end
return dst
end
------------------------------------------------------------------------------
-- Dependency detection. AuraKit + the nameplate namespace are what we integrate
-- with; if either is missing we stay dormant instead of erroring.
------------------------------------------------------------------------------
local function DetectDeps()
EMF.AK = _G.EllesmereUI and _G.EllesmereUI.AuraKit or nil
EMF.NS = _G.EllesmereNameplates_NS or nil
if _G.EllesmereUI then EMF.Debug("EllesmereUI detected.") end
if EMF.NS then EMF.Debug("EllesmereUINameplates detected.") end
if EMF.AK then EMF.Debug("AuraKit detected.") end
return EMF.AK and EMF.NS and true or false
end
-- Recomputes whether the tracker should be running and flips the nameplate
-- module on/off accordingly. Safe to call repeatedly.
function EMF.Refresh()
local shouldRun = EMF.isDruid and EMF.db and EMF.db.enabled and DetectDeps() and true or false
if shouldRun and not EMF.active then
EMF.active = true
EMF.EnsureStyle() -- MoonfireAura.lua
EMF.EnableNameplates() -- Nameplates.lua
EMF.Debug("Tracker enabled.")
elseif (not shouldRun) and EMF.active then
EMF.active = false
EMF.DisableNameplates() -- Nameplates.lua
EMF.Debug("Tracker disabled.")
end
end
------------------------------------------------------------------------------
-- Slash commands.
------------------------------------------------------------------------------
local function ClampNumber(v, lo, hi, fallback)
v = tonumber(v)
if not v then return fallback end
if v < lo then v = lo end
if v > hi then v = hi end
return v
end
local function PrintHelp()
EMF.Print("EllesmereUI - Moonfire Tracker commands:")
EMF.Print(" /emf - show status")
EMF.Print(" /emf help - this help")
EMF.Print(" /emf enable - enable the tracker")
EMF.Print(" /emf disable - disable the tracker")
EMF.Print(" /emf debug - toggle debug messages")
EMF.Print(" /emf reset - restore default settings")
EMF.Print(" /emf size <n> - indicator size (px)")
EMF.Print(" /emf x <n> - indicator X offset")
EMF.Print(" /emf y <n> - indicator Y offset")
end
local function PrintStatus()
if not EMF.isDruid then
EMF.Print("Dormant: this character is not a Druid.")
return
end
local db = EMF.db
EMF.Print("Status: " .. (db.enabled and "|cff40ff40enabled|r" or "|cffff4040disabled|r")
.. (EMF.active and " (running)" or " (idle)"))
EMF.Print(string.format("Indicator: size=%d x=%d y=%d duration=%s border=%s debug=%s",
db.indicator.size, db.indicator.x, db.indicator.y,
tostring(db.showDuration), tostring(db.purpleBorder), tostring(db.debug)))
if not (EMF.AK and EMF.NS) then
EMF.Print("|cffffcc00Waiting for EllesmereUI / EllesmereUINameplates.|r")
end
end
local function HandleSlash(msg)
msg = msg or ""
local cmd, rest = msg:match("^%s*(%S*)%s*(.-)%s*$")
cmd = (cmd or ""):lower()
if cmd == "" then
PrintStatus()
elseif cmd == "help" then
PrintHelp()
elseif cmd == "enable" then
EMF.db.enabled = true
EMF.Refresh()
EMF.Print("Enabled.")
elseif cmd == "disable" then
EMF.db.enabled = false
EMF.Refresh()
EMF.Print("Disabled.")
elseif cmd == "debug" then
EMF.db.debug = not EMF.db.debug
EMF.Print("Debug " .. (EMF.db.debug and "ON" or "OFF") .. ".")
elseif cmd == "reset" then
wipe(EMF.db)
ApplyDefaults(EMF.db, DEFAULTS)
EMF.RestyleIndicators() -- Nameplates.lua (re-applies geometry/colour to live plates)
EMF.Print("Settings reset to defaults.")
elseif cmd == "size" then
EMF.db.indicator.size = ClampNumber(rest, 6, 64, EMF.db.indicator.size)
EMF.RestyleIndicators()
EMF.Print("Indicator size = " .. EMF.db.indicator.size)
elseif cmd == "x" then
EMF.db.indicator.x = ClampNumber(rest, -200, 200, EMF.db.indicator.x)
EMF.RestyleIndicators()
EMF.Print("Indicator x = " .. EMF.db.indicator.x)
elseif cmd == "y" then
EMF.db.indicator.y = ClampNumber(rest, -200, 200, EMF.db.indicator.y)
EMF.RestyleIndicators()
EMF.Print("Indicator y = " .. EMF.db.indicator.y)
else
EMF.Print("Unknown command '" .. cmd .. "'. Try /emf help")
end
end
SLASH_ELLESMEREMOONFIRE1 = "/emf"
SlashCmdList["ELLESMEREMOONFIRE"] = HandleSlash
------------------------------------------------------------------------------
-- Event wiring.
------------------------------------------------------------------------------
local function OnLogin()
local _, class = UnitClass("player")
EMF.isDruid = (class == "DRUID")
if not EMF.isDruid then
-- Remain dormant: never create the Moonfire nameplate system.
EMF.Debug("Not a Druid -- staying dormant.")
return
end
-- Dependencies may finish loading a hair after us; retry a couple of times.
local tries = 0
local function try()
tries = tries + 1
EMF.Refresh()
if not (EMF.AK and EMF.NS) and tries < 5 then
C_Timer.After(1, try)
end
end
try()
end
local boot = CreateFrame("Frame")
boot:RegisterEvent("ADDON_LOADED")
boot:RegisterEvent("PLAYER_LOGIN")
boot:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED")
boot:SetScript("OnEvent", function(_, event, arg1)
if event == "ADDON_LOADED" then
if arg1 == ADDON then
EllesmereUIMoonfireDB = EllesmereUIMoonfireDB or {}
EMF.db = ApplyDefaults(EllesmereUIMoonfireDB, DEFAULTS)
end
elseif event == "PLAYER_LOGIN" then
OnLogin()
elseif event == "PLAYER_SPECIALIZATION_CHANGED" then
-- Spec changes never toggle the class gate (still a Druid), but keep the
-- run-state coherent in case deps arrived late or settings changed.
if EMF.isDruid then EMF.Refresh() end
end
end)