-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
347 lines (322 loc) · 12.3 KB
/
Copy pathCore.lua
File metadata and controls
347 lines (322 loc) · 12.3 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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
-- ════════════════════════════════════════════════════════════════
-- Part 1: Core Module
-- (Addon bootstrap, SavedVariables defaults, module registration,
-- DB migration, and addon lifecycle)
-- ════════════════════════════════════════════════════════════════
local addonName, addon = ...
addon.modules = {}
-- ── SavedVariables defaults ──────────────────────────────────
local defaultDB = {
modules = {
["SharedActionBars"] = false,
["DeathAlert"] = false,
["PotionAlert"] = false,
["LustAlert"] = false,
["StealthIndicator"] = false,
["TimeSpiralAlert"] = false,
["OCETag"] = false,
["GroupJoinedReminder"] = false,
["ItemUpgradeReminder"] = false,
["CVarBrowser"] = true,
["ActionBarToggle"] = false,
["BlizzardFrames"] = false,
["DataTexts"] = false,
["MountActions"] = false,
["ConsumableMacros"] = false,
},
-- ── Global settings ─────────────────────────────────────
global = {
slugRendering = false,
},
-- ── Death Alert defaults ────────────────────────────────
deathAlert = {
fontSize = 24,
fontFamily = STANDARD_TEXT_FONT,
posX = 0,
posY = 200,
playSound = false,
soundName = "None",
muteInRaid = false,
},
-- ── Potion Alert defaults ───────────────────────────────
potionAlert = {
fontSize = 16,
fontFamily = STANDARD_TEXT_FONT,
onlyCombat = false,
showInDungeons = false,
showInRaids = false,
showInOpenWorld = false,
posX = 0,
posY = -70,
playSound = false,
soundName = "None",
},
-- ── Lust Alert defaults ─────────────────────────────────
lustAlert = {
fontSize = 16,
fontFamily = STANDARD_TEXT_FONT,
onlyCombat = false,
showInDungeons = false,
showInRaids = false,
showInOpenWorld = false,
posX = 0,
posY = -100,
playSound = false,
soundName = "None",
onlyIfHasLust = false,
},
-- ── Stealth Indicator defaults ──────────────────────────
stealthIndicator = {
fontSize = 14,
fontFamily = STANDARD_TEXT_FONT,
posX = 0,
posY = 25,
},
-- ── Item Upgrade Reminder defaults ──────────────────────
itemUpgradeReminder = {
showOnScreen = false,
fontSize = 16,
fontFamily = STANDARD_TEXT_FONT,
posX = 250,
posY = 150,
},
-- ── Action Bar Toggle defaults ──────────────────────────
actionBarToggle = {
keybind = "",
bars = {
Bar1 = true,
Bar2 = true,
Bar3 = true,
Bar4 = true,
Bar5 = true,
Bar6 = true,
Bar7 = true,
Bar8 = true,
},
includePetBar = false,
includeStanceBar = false,
hidden = false,
},
-- ── Blizzard Frames defaults ────────────────────────────
blizzardFrames = {
hideMicroMenu = true,
hideBagsBar = true,
moverEnabled = false,
moverFrames = {},
moverPositions = {},
},
-- ── CVar Browser defaults ───────────────────────────────
cvarBrowser = {
modifiedCVars = {},
},
-- ── Data Texts defaults ──────────────────────────────
dataTexts = {
leftText = "Guild",
leftTooltip = "Default",
leftClick = "Default",
rightText = "Friends",
rightTooltip = "Default",
rightClick = "Default",
fontSize = 12,
fontFamily = STANDARD_TEXT_FONT,
matchMinimap = true,
panelWidth = 232,
panelHeight = 24,
anchorFrom = "TOP",
anchorTo = "BOTTOM",
anchorX = 0,
anchorY = -2,
tooltipAnchorFrom = "TOPLEFT",
tooltipAnchorTo = "BOTTOMLEFT",
tooltipAnchorX = 0,
tooltipAnchorY = -2,
timeFormat = "12H",
providerSettings = {},
showClickHints = true,
goldData = {},
},
-- ── Mount Actions defaults ──────────────────────────────
mountActions = {
repairKeybind = "",
ahKeybind = "",
dracthyrVisage = false,
},
-- ── Consumable Macros defaults ─────────────────────────
consumableMacros = {
healthMacroEnabled = false,
healthUseRecuperate = false,
drinkMacroEnabled = false,
preferMageFood = true,
allowRecuperate = true,
useManaPotionInCombat = false,
minManaFoodValue = 50,
},
-- ── Time Spiral Alert defaults ──────────────────────────
timeSpiralAlert = {
fontSize = 13,
fontFamily = STANDARD_TEXT_FONT,
posX = 0,
posY = 70,
playSound = false,
soundName = "None",
onlyCombat = false,
showInDungeons = false,
showInRaids = false,
showInOpenWorld = false,
enabledClasses = {
DEATHKNIGHT = true,
DEMONHUNTER = true,
DRUID = true,
EVOKER = true,
HUNTER = true,
MAGE = true,
MONK = true,
PALADIN = true,
PRIEST = true,
ROGUE = true,
SHAMAN = true,
WARLOCK = true,
WARRIOR = true,
},
},
}
-- ── Helper: DeepCopy ─────────────────────────────────────────
-- Deep-copy a table recursively (needed so SavedVariables don't alias defaultDB)
local function DeepCopy(orig)
local copy
if type(orig) == "table" then
copy = {}
for k, v in next, orig, nil do
copy[DeepCopy(k)] = DeepCopy(v)
end
setmetatable(copy, DeepCopy(getmetatable(orig)))
else
copy = orig
end
return copy
end
-- ── Module Registration ──────────────────────────────────────
function addon:RegisterModule(name, moduleTable)
self.modules[name] = moduleTable
end
-- ── Module State Queries ─────────────────────────────────────
function addon:IsModuleEnabled(name)
if not self.db then return false end
return self.db.modules[name]
end
-- ── Module State Management ──────────────────────────────────
function addon:SetModuleEnabled(name, enabled)
if not self.db then return end
self.db.modules[name] = enabled
local module = self.modules[name]
if module then
if enabled and module.OnEnable then
module:OnEnable()
elseif not enabled and module.OnDisable then
module:OnDisable()
end
end
end
-- ── Global Test Mode Management ──────────────────────────────
function addon:SetGlobalTestMode(enabled)
for name, module in pairs(self.modules) do
if self:IsModuleEnabled(name) and module.SetTestMode then
module:SetTestMode(enabled)
end
end
end
function addon:IsAnyTestModeActive()
for name, module in pairs(self.modules) do
if self:IsModuleEnabled(name) and module.IsTestMode and module:IsTestMode() then
return true
end
end
return false
end
-- ── Font Resolution ──────────────────────────────────────────
-- Resolves a font family name to a file path via LibSharedMedia, falling back to STANDARD_TEXT_FONT.
-- If a global font override is set (TFQoLDB.global.fontFamily), it takes precedence over `family`.
function addon:ResolveFont(family)
local fontPath = STANDARD_TEXT_FONT
local effective = self.db and self.db.global and self.db.global.fontFamily or family
if effective then
local LSM = LibStub and LibStub("LibSharedMedia-3.0", true)
if LSM then
fontPath = LSM:Fetch("font", effective) or fontPath
elseif effective:find("\\\\") or effective:find("/") or effective:find("%.") then
fontPath = effective
end
end
return fontPath
end
function addon:GetLSMFonts()
local LSM = LibStub and LibStub("LibSharedMedia-3.0", true)
if LSM then return LSM:List("font") end
return { STANDARD_TEXT_FONT }
end
-- ── ADDON_LOADED Event ───────────────────────────────────────
local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", function(self, event, ...)
if event == "ADDON_LOADED" then
local loadedAddon = ...
if loadedAddon == addonName then
self:UnregisterEvent("ADDON_LOADED")
-- Initialize DB
if not TFQoLDB then
TFQoLDB = DeepCopy(defaultDB)
else
-- Migration: ensure any new modules added to defaultDB are enabled by default
for name, enabled in pairs(defaultDB.modules) do
if TFQoLDB.modules[name] == nil then
TFQoLDB.modules[name] = enabled
end
end
-- Remove stale modules no longer in defaultDB
for name, _ in pairs(TFQoLDB.modules) do
if defaultDB.modules[name] == nil then
TFQoLDB.modules[name] = nil
end
end
-- Ensure all sub-tables exist and fill in any missing fields within them
for key, defaultValue in pairs(defaultDB) do
if key ~= "modules" then
if not TFQoLDB[key] then
TFQoLDB[key] = DeepCopy(defaultValue)
elseif type(defaultValue) == "table" then
for field, fieldDefault in pairs(defaultValue) do
if TFQoLDB[key][field] == nil then
TFQoLDB[key][field] = fieldDefault
end
end
-- Remove stale fields from sub-tables
for field, _ in pairs(TFQoLDB[key]) do
if defaultValue[field] == nil then
TFQoLDB[key][field] = nil
end
end
end
end
end
-- Remove stale top-level keys no longer in defaultDB
for key, _ in pairs(TFQoLDB) do
if defaultDB[key] == nil then
TFQoLDB[key] = nil
end
end
end
addon.db = TFQoLDB
-- Initialize modules
for name, module in pairs(addon.modules) do
if module.OnInitialize then
module:OnInitialize()
end
if addon:IsModuleEnabled(name) then
if module.OnEnable then
module:OnEnable()
end
end
end
end
end
end)