-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
171 lines (145 loc) · 5.88 KB
/
Core.lua
File metadata and controls
171 lines (145 loc) · 5.88 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
local addonName, addon = ...
addon.events = CreateFrame("Frame")
-- Saved variable; initialized in ADDON_LOADED
-- Core variables
addon.CharKey = nil
addon.ProfileType = nil -- "char" or "class"
addon.Profile = nil
function addon.Print(fmt, ...)
if addon.Profile and addon.Profile.debug then
print("|cff00cc00CDG Debug:|r " .. string.format(fmt, ...))
end
end
local cdUpdateFrame = CreateFrame("Frame")
local cdTimerAccum = 0
local function CdOnUpdate(self, elapsed)
cdTimerAccum = cdTimerAccum + elapsed
if cdTimerAccum >= 0.1 then
cdTimerAccum = 0
if addon.Profile then
addon.CheckCooldowns()
addon.CheckItemCooldowns()
end
end
end
cdUpdateFrame:SetScript("OnUpdate", CdOnUpdate)
local function OnEvent(self, event, ...)
if event == "ADDON_LOADED" then
local name = ...
if name == addonName then
CooldownGlowsDB = CooldownGlowsDB or {}
-- Simple migration from old CDglowDB if present
if CDglowDB and not next(CooldownGlowsDB) then
CooldownGlowsDB = CopyTable(CDglowDB)
end
addon.Class = select(2, UnitClass("player"))
addon.CharKey = "char:" .. UnitName("player") .. "-" .. GetRealmName()
-- Ensure class profile exists
if not CooldownGlowsDB[addon.Class] then
CooldownGlowsDB[addon.Class] = { spells = {}, items = {}, debug = false }
end
if not CooldownGlowsDB[addon.Class].items then
CooldownGlowsDB[addon.Class].items = {}
end
-- Load profile (char-specific or class fallback)
if CooldownGlowsDB[addon.CharKey] then
if not CooldownGlowsDB[addon.CharKey].items then
CooldownGlowsDB[addon.CharKey].items = {}
end
addon.Profile = CooldownGlowsDB[addon.CharKey]
addon.ProfileType = "char"
else
addon.Profile = CooldownGlowsDB[addon.Class]
addon.ProfileType = "class"
end
if addon.CreateOptionsFrames then
addon.CreateOptionsFrames()
end
self:UnregisterEvent("ADDON_LOADED")
end
elseif event == "SPELLS_CHANGED" or event == "PLAYER_TALENT_UPDATE" then
addon.UpdateTrackableSpells()
elseif event == "PLAYER_ENTERING_WORLD" then
addon.UpdateTrackableSpells()
addon.CheckCooldowns()
addon.CheckItemCooldowns()
elseif event == "PLAYER_REGEN_ENABLED" then
addon.UpdateTrackableSpells()
if addon.pendingOpenSettings then
addon.pendingOpenSettings = nil
Settings.OpenToCategory(addon.category:GetID())
end
addon.CheckCooldowns()
addon.CheckItemCooldowns()
end
end
addon.events:RegisterEvent("ADDON_LOADED")
addon.events:RegisterEvent("PLAYER_ENTERING_WORLD")
addon.events:RegisterEvent("SPELLS_CHANGED")
addon.events:RegisterEvent("PLAYER_TALENT_UPDATE")
addon.events:RegisterEvent("PLAYER_REGEN_ENABLED")
addon.events:SetScript("OnEvent", OnEvent)
-- Slash commands
SLASH_COOLDOWNGLOWS1 = "/cooldownglows"
SLASH_COOLDOWNGLOWS2 = "/cdg"
SlashCmdList["COOLDOWNGLOWS"] = function(msg)
msg = msg:lower():trim()
if msg == "test" then
print("|cff00cc00CooldownGlows Test:|r Triggering all tracked glows...")
if not addon.Profile then print(" Profile not loaded.") return end
addon.isTesting = true
local maxDur = 0
local function triggerGlows(list)
if not list then return end
for id, entry in pairs(list) do
local btn = entry.button and _G[entry.button]
if btn then
local colorKey = addon.GetEntryColor(entry)
local duration = addon.GetEntryDuration(entry)
if duration > maxDur then maxDur = duration end
addon.ApplyGlowTransition(btn, true, true, duration, colorKey)
end
end
end
triggerGlows(addon.Profile.spells)
triggerGlows(addon.Profile.items)
if maxDur > 0 then
C_Timer.After(maxDur + 0.5, function() addon.isTesting = false end)
else
addon.isTesting = false
end
print(" Test complete. Glows will fade based on individual spell/item durations.")
return
end
if msg == "cache" then
print("|cff00cc00CooldownGlows Static Map:|r")
if not addon.Profile then print(" Profile not loaded.") return end
print(" Tracked Spells:")
for id, entry in pairs(addon.Profile.spells) do
local name = C_Spell.GetSpellInfo(id) and C_Spell.GetSpellInfo(id).name or "Unknown"
local btnName = entry.button or "|cffff3333None|r"
print(string.format(" - %s (%d): %s", name, id, btnName))
end
print(" Tracked Items:")
for id, entry in pairs(addon.Profile.items) do
local name = C_Item.GetItemInfo(id) or "Unknown"
local btnName = entry.button or "|cffff3333None|r"
print(string.format(" - %s (%d): %s", name, id, btnName))
end
return
end
if msg == "" then
if InCombatLockdown() then
print("|cffccaa00CooldownGlows:|r Settings will open when you leave combat.")
addon.events:RegisterEvent("PLAYER_REGEN_ENABLED")
addon.pendingOpenSettings = true
return
end
Settings.OpenToCategory(addon.category:GetID())
return
end
print("|cffccaa00CooldownGlows Commands:|r")
print(" /cdg - Open settings")
print(" /cdg cache - View button-to-spell mappings")
print(" /cdg test - Trigger glows on all tracked buttons")
end