Repository navigation
Expand file tree
/
Copy pathSlash.lua
More file actions
628 lines (553 loc) · 20.3 KB
/
Copy pathSlash.lua
File metadata and controls
628 lines (553 loc) · 20.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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
----------------------------------------------------
-- CooldownCursor Slash Commands
----------------------------------------------------
local addonName, addonTable = ...
local CooldownCursor = addonTable.Frame
SLASH_COOLDOWNCURSOR1 = "/cdcursor"
SLASH_COOLDOWNCURSOR2 = "/cdc"
local PREFIX = "|cff00ff00CooldownCursor|r"
----------------------------------------------------
-- Helper functions
----------------------------------------------------
local function Print(...)
print(PREFIX, ...)
end
local function Trim(s)
return (s or ""):match("^%s*(.-)%s*$")
end
local function ToBool(s)
s = (Trim(s)):lower()
if s == "on" or s == "1" or s == "true" or s == "yes" then return true end
if s == "off" or s == "0" or s == "false" or s == "no" then return false end
return nil
end
local function ToNum(s)
return tonumber(Trim(s))
end
local function ToggleBool(t)
return not t
end
----------------------------------------------------
-- Help Menu
----------------------------------------------------
local function Usage(line)
Print("usage:", line)
end
local function Help()
print([[
|cff00ff00CooldownCursor Commands|r:
/cdcursor icon - Configure icon settings (submenu)
/cdcursor text - Configure spellname text settings (submenu)
/cdcursor number - Configure cooldown number settings (submenu)
/cdcursor scale - Set scale of icon and texts
/cdcursor animation - Toggle icon animation on/off
/cdcursor fadeout - Set icon fade-out duration in seconds
/cdcursor strata - Set icon frame strata
/cdcursor hideafter - Set icon hide-after duration in seconds
/cdcursor show <0||1||2> - 0=always, 1=in-combat, 2=out-of-combat
/cdcursor mount - Toggle hide while mounted
/cdcursor preview - Toggle preview mode
/cdcursor help - Show this help message
/cdcursor reset - Reset all settings to default
/cdcursor status - Show current settings
/cdcursor debug - Toggle debug mode (subcommands: state|icons|rules|spell|pool|events|log|cache|filter)
]])
end
----------------------------------------------------
--- Command Handlers
----------------------------------------------------
local handlers = {}
-- Adding a new command
-- handlers.newcmd = function(...) ... end
handlers.help = function()
Help()
end
handlers.anchors = function()
Print("Valid anchors:")
local anchors = CooldownCursor:GetValidAnchorPositions()
for _, pos in ipairs(anchors) do
print(" -", pos)
end
end
handlers.animation = function()
local toggle = ToggleBool(CooldownCursor:GetDBValue("animation"))
CooldownCursor:SetDBBoolean("animation", toggle)
Print("animation set to:", toggle and "on" or "off")
end
handlers.fadeout = function(arg1)
local n = ToNum(arg1)
if not n then return Usage("/cdcursor fadeout <seconds>") end
CooldownCursor:SetFadeOutDuration(n)
Print("icon fade-out duration set to:", n)
end
handlers.fonts = function()
Print("Available fonts:")
local allFonts = CooldownCursor:GetAllFonts()
for _, path in ipairs(allFonts) do
print(" -", path)
end
end
handlers.hideafter = function(arg1)
local n = ToNum(arg1)
if not n then return Usage("/cdcursor hideafter <seconds>") end
CooldownCursor:SetHideAfter(n)
Print("icon hide after set to:", n)
end
handlers.icon = function(arg1, arg2)
if not arg1 or arg1 == "" then
Usage("/cdcursor icon <anchor||size||alpha||swipe||toggle>")
print("options:")
print(" anchor - Set icon anchor position")
print(" size - Set icon size")
print(" alpha - Set icon alpha (0-100)")
print(" swipe - Set icon swipe on/off")
print(" toggle - Toggle icon display")
return
end
if arg1 == "alpha" then
local n = ToNum(arg2)
if not n then return Usage("/cdcursor icon alpha <number>") end
CooldownCursor:SetDBNumber("iconAlpha", n)
Print("icon alpha set to:", n)
elseif arg1 == "anchor" then
local pos = string.upper(arg2)
local validAnchor = CooldownCursor:GetValidAnchorPosition(pos)
if not validAnchor then
Print("invalid anchor position:", pos)
Print("/cdcursor icon anchor <anchor>")
handlers.anchors()
return
end
CooldownCursor:SetDBString("anchor", pos)
Print("anchor set to:", pos)
elseif arg1 == "size" then
local n = ToNum(arg2)
if not n then return Usage("/cdcursor icon size <number>") end
CooldownCursor:SetDBNumber("iconSize", n)
Print("icon size set to:", n)
elseif arg1 == "swipe" then
local toggle = ToggleBool(CooldownCursor:GetDBValue("showCooldownSwipe"))
CooldownCursor:SetDBBoolean("showCooldownSwipe", toggle)
Print("swipe set to:", toggle and "on" or "off")
elseif arg1 == "toggle" then
local toggle = ToggleBool(CooldownCursor:GetDBValue("iconHide"))
CooldownCursor:SetDBBoolean("iconHide", toggle)
Print("icon is now", toggle and "hidden" or "shown")
else
Usage("/cdcursor icon <alpha||anchor||size||swipe||toggle>")
end
end
-- Deprecated in Midnight
handlers.max = function(arg1)
local n = ToNum(arg1)
if not n then return Usage("/cdcursor max <seconds>") end
CooldownCursor:SetDBNumber("maxDuration", n)
Print("cooldown max duration:", n)
end
-- Deprecated in Midnight
handlers.min = function(arg1)
local n = ToNum(arg1)
if not n then return Usage("/cdcursor min <seconds>") end
CooldownCursor:SetDBNumber("minDuration", n)
Print("cooldown min duration:", n)
end
handlers.mount = function()
local toggle = ToggleBool(CooldownCursor:GetDBValue("hideWhileMounted"))
CooldownCursor:SetDBBoolean("hideWhileMounted", toggle)
Print("hide while mounted is now", toggle and "enabled" or "disabled")
end
handlers.number = function(arg1, arg2)
if not arg1 or arg1 == "" then
Usage("/cdcursor number <alpha||anchor||color||font||ftype||size||toggle>")
print("options:")
print(" alpha - Set cooldown text alpha (0-100)")
print(" anchor - Set cooldown text anchor position")
print(" color - Set cooldown text color (use hex code, e.g. ff0000)")
print(" font - Set cooldown text font")
print(" ftype - Set cooldown text font type (outline, thickoutline, monochrome, none)")
print(" size - Set cooldown text size")
print(" toggle - Toggle cooldown name display")
return
end
if arg1 == "alpha" then
local n = ToNum(arg2)
if not n then return Usage("/cdcursor number alpha <number>") end
CooldownCursor:SetDBNumber("cooldownTextAlpha", n)
Print("cooldown number alpha set to:", n)
elseif arg1 == "anchor" then
local pos = string.upper(arg2)
local validAnchor = CooldownCursor:GetValidCooldownTextAnchorPosition(pos)
if not validAnchor then
Print("invalid anchor position:", pos)
Print("/cdcursor number anchor <anchor>")
handlers.anchors()
return
end
CooldownCursor:SetDBString("cooldownTextAnchor", pos)
Print("cooldown number anchor set to:", pos)
elseif arg1 == "color" then
CooldownCursor:SetDBString("cooldownTextColor", arg2)
Print("cooldown number color set to:", arg2)
elseif arg1 == "font" then
local font = arg2
if not font or font == "" then
Print("no font provided", font)
Print("to see available fonts run:")
Print("/cdcursor fonts")
return
end
local validFont = CooldownCursor:GetAllFonts()
if not tContains(validFont, font) then
Print("invalid font", font)
Print("to see available fonts run:")
Print("/cdcursor fonts")
return
end
CooldownCursor:SetFontPath("cooldownTextFont", font)
Print("cooldown number font set to:", font)
elseif arg1 == "ftype" then
local ftype = string.upper(arg2)
if not CooldownCursor:GetValidFontType(ftype) then
Print("invalid font type:", ftype)
Print(
"/cdcursor number ftype <outline||thickoutline||monochrome||monochromeoutline||monochromethickoutline||none>")
return
end
CooldownCursor:SetDBString("cooldownTextFontType", ftype)
Print("cooldown number font type set to:", ftype)
elseif arg1 == "size" then
local n = ToNum(arg2)
if not n then return Usage("/cdcursor number size <number>") end
CooldownCursor:SetDBNumber("cooldownTextSize", n)
Print("cooldown number size set to:", n)
elseif arg1 == "toggle" then
local toggle = ToggleBool(CooldownCursor:GetDBValue("hideCooldownNumbers"))
CooldownCursor:SetDBBoolean("hideCooldownNumbers", toggle)
Print("cooldown numbers now", toggle and "hidden" or "shown")
else
Usage("/cdcursor number <alpha||anchor||color||font||ftype||size||toggle>")
end
end
handlers.preview = function()
CooldownCursor:Preview()
local mode = ToggleBool(CooldownCursor:GetPreviewMouseMode())
CooldownCursor:SetPreviewMouseMode(mode)
Print("toggled preview.")
end
handlers.reset = function()
CooldownCursor:ResetSettings()
Print("settings reset to default.")
end
handlers.scale = function(arg1)
local n = ToNum(arg1)
if not n then return Usage("/cdcursor scale <0.5 - 5>") end
if n < 0.5 or n > 5 then
Print("scale must be greater than or equal to 0.5 and less than or equal to 5")
return
end
CooldownCursor:SetDBNumber("scale", n)
Print("scale set to:", n)
end
handlers.show = function(arg1)
local n = ToNum(arg1)
if n ~= 0 and n ~= 1 and n ~= 2 then
return Usage("/cdcursor show <0||1||2> (0=always, 1=in-combat, 2=out-of-combat)")
end
CooldownCursor:SetDBNumber("showWhen", n)
local label = (n == 0 and "always") or (n == 1 and "in-combat") or "out-of-combat"
Print("show mode set to:", label)
end
handlers.strata = function(arg1)
local strata = string.upper(arg1)
if not CooldownCursor:GetValidFrameStrata(strata) then
Print("invalid frame strata:", strata)
Print("/cdcursor strata <strata>")
Print("valid stratas are: background, low, medium, high, dialog, tooltip")
return
end
CooldownCursor:SetDBString("frameStrata", strata)
Print("icon frame strata set to:", strata)
end
handlers.text = function(arg1, arg2)
if not arg1 or arg1 == "" then
Usage("/cdcursor text <alpha||anchor||color||font||ftype||size||toggle>")
print("options:")
print(" alpha - Set spell text alpha (0-100)")
print(" anchor - Set spell text anchor position (TOP or BOTTOM)")
print(" color - Set spell text color (use hex code, e.g. ff0000)")
print(" font - Set spell text font")
print(" ftype - Set spell text font type (outline, thickoutline, monochrome, none)")
print(" size - Set spell text size")
print(" toggle - Toggle spell name display")
return
end
if arg1 == "alpha" then
local n = ToNum(arg2)
if not n then return Usage("/cdcursor text alpha <number>") end
CooldownCursor:SetDBNumber("spellTextAlpha", n)
Print("spell text alpha set to:", n)
elseif arg1 == "anchor" then
local pos = string.upper(arg2)
local validAnchor = CooldownCursor:GetValidSpellTextAnchorPosition(pos)
if not validAnchor then
Print("invalid anchor position:", pos)
Print("/cdcursor text anchor <top||bottom>")
return
end
CooldownCursor:SetDBString("spellTextAnchor", pos)
Print("spell text anchor set to:", pos)
elseif arg1 == "color" then
CooldownCursor:SetDBString("spellTextColor", arg2)
Print("spell text color set to:", arg2)
elseif arg1 == "font" then
local font = arg2
if not font or font == "" then
Print("no font provided", font)
Print("to see available fonts run:")
Print("/cdcursor fonts")
return
end
local validFont = CooldownCursor:GetAllFonts()
if not tContains(validFont, font) then
Print("invalid font", font)
Print("to see available fonts run:")
Print("/cdcursor fonts")
return
end
CooldownCursor:SetFontPath("spellTextFont", arg2)
Print("spell text font set to:", arg2)
elseif arg1 == "ftype" then
local ftype = string.upper(arg2)
if not CooldownCursor:GetValidFontType(ftype) then
Print("invalid font type:", ftype)
Print("/cdcursor text ftype <outline||thickoutline||monochrome||monochromeoutline||monochromethickoutline||none>")
return
end
CooldownCursor:SetDBString("spellTextFontType", ftype)
Print("spell text font type set to:", ftype)
elseif arg1 == "size" then
local n = ToNum(arg2)
if not n then return Usage("/cdcursor text size <number>") end
CooldownCursor:SetDBNumber("spellTextSize", n)
Print("spell text size set to:", n)
elseif arg1 == "toggle" then
local toggle = ToggleBool(CooldownCursor:GetDBValue("showSpellNames"))
CooldownCursor:SetDBBoolean("showSpellNames", toggle)
Print("spell names now", toggle and "on" or "off")
else
Usage("/cdcursor text <alpha||anchor||color||font||ftype||size||toggle>")
end
end
-- Expose a method on CooldownCursor for exporting settings
function CooldownCursor:ExportSettings()
Print("======================================")
Print("CooldownCursor Settings Export")
Print("======================================")
-- Skip internal keys (those starting with _) and complex objects
local skipKeys = {
spellRules = true,
releaseNotes = true,
}
-- Collect and sort all setting keys
local sortedKeys = {}
for key, _ in pairs(CooldownCursorDB) do
-- Skip internal keys (starting with _) and skipped keys
if not key:match("^_") and not skipKeys[key] then
table.insert(sortedKeys, key)
end
end
table.sort(sortedKeys)
-- Function to format value for display
local function FormatValue(value)
local valueType = type(value)
if valueType == "boolean" then
return value and "true" or "false"
elseif valueType == "number" then
return tostring(value)
elseif valueType == "string" then
return value
elseif valueType == "table" then
return "[table]"
else
return tostring(value)
end
end
-- Print all settings
for _, key in ipairs(sortedKeys) do
local value = CooldownCursorDB[key]
Print(" " .. key .. ":", FormatValue(value))
end
-- Handle spell rules separately
if CooldownCursorDB.spellRules and CooldownCursorDB.spellRules.rules then
Print("")
Print("Spell Rules:")
local ruleCount = 0
local sortedRules = {}
for spellID, rule in pairs(CooldownCursorDB.spellRules.rules) do
if type(spellID) == "number" then
ruleCount = ruleCount + 1
table.insert(sortedRules, {spellID = spellID, rule = rule})
end
end
-- Sort by spell ID
table.sort(sortedRules, function(a, b) return a.spellID < b.spellID end)
for _, entry in ipairs(sortedRules) do
local spellID = entry.spellID
local rule = entry.rule
local info = C_Spell.GetSpellInfo(spellID)
local spellName = info and info.name or ("Unknown Spell " .. spellID)
local enabled = rule.enabled ~= false and "enabled" or "disabled"
local priority = rule.priority or 0
local iconSize = rule.iconSize or "default"
Print(string.format(" [%d] %s - %s (priority: %s, size: %s)",
spellID, spellName, enabled, tostring(priority), tostring(iconSize)))
end
Print(string.format(" Total: %d spell rule(s)", ruleCount))
-- Print spell rules settings
if CooldownCursorDB.spellRules.settings then
Print("")
Print("Spell Rules Settings:")
Print(" disableRules:", FormatValue(CooldownCursorDB.spellRules.settings.disableRules))
end
end
Print("======================================")
end
-- Generate a compact serialized string of all settings for sharing
function CooldownCursor:SerializeSettings()
local parts = {}
-- Skip internal keys (those starting with _) and complex objects
local skipKeys = {
spellRules = true,
releaseNotes = true,
}
-- Collect and sort all setting keys
local sortedKeys = {}
for key, _ in pairs(CooldownCursorDB) do
if not key:match("^_") and not skipKeys[key] then
table.insert(sortedKeys, key)
end
end
table.sort(sortedKeys)
-- Function to escape special characters in strings
local function EscapeString(str)
return str:gsub("([\\;|])", "\\%1")
end
-- Serialize each setting
for _, key in ipairs(sortedKeys) do
local value = CooldownCursorDB[key]
local valueType = type(value)
local serializedValue
if valueType == "boolean" then
serializedValue = value and "1" or "0"
elseif valueType == "number" then
serializedValue = tostring(value)
elseif valueType == "string" then
serializedValue = EscapeString(value)
else
serializedValue = nil -- Skip tables and other types
end
if serializedValue then
table.insert(parts, key .. "=" .. serializedValue)
end
end
-- Add spell rules
if CooldownCursorDB.spellRules and CooldownCursorDB.spellRules.rules then
local rules = {}
for spellID, rule in pairs(CooldownCursorDB.spellRules.rules) do
if type(spellID) == "number" then
local enabled = rule.enabled ~= false and "1" or "0"
local priority = rule.priority or 0
local iconSize = rule.iconSize or ""
local useGlobal = rule.useGlobalIconSize ~= false and "1" or "0"
table.insert(rules, string.format("%d:%s:%s:%s:%s",
spellID, enabled, priority, iconSize, useGlobal))
end
end
if #rules > 0 then
table.insert(parts, "spellRules=" .. table.concat(rules, "|"))
end
-- Add spell rules settings
if CooldownCursorDB.spellRules.settings then
local disableRules = CooldownCursorDB.spellRules.settings.disableRules and "1" or "0"
table.insert(parts, "spellRulesDisabled=" .. disableRules)
end
end
return table.concat(parts, ";")
end
handlers.debug = function(arg1, arg2)
if not arg1 or arg1 == "" then
CooldownCursor:Toggle()
return
end
if arg1 == "state" then
CooldownCursor:DumpState()
elseif arg1 == "icons" then
CooldownCursor:DumpIcons()
elseif arg1 == "rules" then
CooldownCursor:DumpRules()
elseif arg1 == "spell" then
CooldownCursor:DumpSpell(arg2)
elseif arg1 == "pool" then
CooldownCursor:DumpPool()
elseif arg1 == "events" then
CooldownCursor:ToggleEvents()
elseif arg1 == "log" then
CooldownCursor:DumpLog()
elseif arg1 == "cache" then
CooldownCursor:DumpCache()
elseif arg1 == "filter" then
CooldownCursor:ToggleFilter(arg2)
else
Print("debug subcommands: state | icons | rules | spell <id> | pool | events | log | cache | filter")
end
end
handlers.status = function()
CooldownCursor:ExportSettings()
end
handlers.version = function()
Print("v" .. (CooldownCursor:GetVersion() or " unknown"))
end
----------------------------------------------------
--- Command Alias Handlers
----------------------------------------------------
-- Adding a new command alias
-- handlers.alias = function()
-- handlers.cmd(args)
-- end
handlers.h = function()
handlers.help()
end
handlers.i = function(arg1, arg2)
handlers.icon(arg1, arg2)
end
handlers.n = function(arg1, arg2)
handlers.number(arg1, arg2)
end
handlers.p = function()
handlers.preview()
end
handlers.s = function()
handlers.status()
end
handlers.t = function(arg1, arg2)
handlers.text(arg1, arg2)
end
----------------------------------------------------
--Main
----------------------------------------------------
SlashCmdList["COOLDOWNCURSOR"] = function(msg)
msg = Trim(msg)
if msg == "" then return Help() end
local cmd, rest = msg:match("^(%S+)%s*(.-)$")
cmd = (cmd or ""):lower()
local arg1, arg2 = rest:match("^(%S+)%s*(.-)$")
arg1 = Trim(arg1) or ""
arg2 = Trim(arg2) or ""
arg1 = arg1:lower()
local fn = handlers[cmd]
if not fn then
Help()
return
end
fn(arg1, arg2)
end