-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
2162 lines (1926 loc) · 87.7 KB
/
Copy pathCore.lua
File metadata and controls
2162 lines (1926 loc) · 87.7 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
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local addonName, Addon = ...
_G.NSRTCountdownCompanion = Addon
local abs = math.abs
local floor = math.floor
local max = math.max
local min = math.min
local pairs = pairs
local tonumber = tonumber
local tostring = tostring
local type = type
local function CanonicalNumber(value, fallback)
local number = tonumber(value)
if number == nil then number = tonumber(fallback) or 0 end
local text = ("%.3f"):format(number):gsub("0+$", ""):gsub("%.$", "")
return text ~= "" and text or "0"
end
local function TrimText(value)
value = tostring(value or "")
if strtrim then return strtrim(value) end
return value:match("^%s*(.-)%s*$") or value
end
local defaults = {
schemaVersion = 13,
soundChannel = "Master",
theme = "arcane",
useDefaultWhenNSRTCountdownMissing = false,
defaultCountdown = 5,
assignments = {},
abilityRenames = {},
encounterAssignments = {},
noteAssignments = {},
knownSpells = {},
manualSpells = {},
}
Addon.activeCountdowns = {}
Addon.initialized = false
Addon.debugEnabled = false
Addon.loadedNoteCache = { personal = "", shared = "" }
local function ApplyDefaults(target, source)
for key, value in pairs(source) do
if type(value) == "table" then
if type(target[key]) ~= "table" then
target[key] = {}
end
ApplyDefaults(target[key], value)
elseif target[key] == nil then
target[key] = value
end
end
end
function Addon:Print(message)
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FFFFNSRT CC:|r " .. tostring(message))
end
function Addon:Debug(message)
if self.debugEnabled == true then
self:Print("|cFFAAAAAA[debug]|r " .. tostring(message))
end
end
function Addon:GetCurrentSpecID()
local specIndex = GetSpecialization and GetSpecialization()
if not specIndex then return nil end
return select(1, GetSpecializationInfo(specIndex))
end
function Addon:GetCurrentClass()
return select(2, UnitClass("player"))
end
function Addon:GetSpellData(spellID)
spellID = tonumber(spellID)
if not spellID then return nil end
local info = C_Spell and C_Spell.GetSpellInfo and C_Spell.GetSpellInfo(spellID)
if info then
return {
id = spellID,
name = info.name or ("Spell " .. spellID),
icon = info.iconID or 134400,
}
end
local name, _, icon = GetSpellInfo and GetSpellInfo(spellID)
if name then
return { id = spellID, name = name, icon = icon or 134400 }
end
end
-- NSRT normally resolves a missing countdown tag from its Spell/Text Countdown
-- settings while processing a reminder. Some callback and test paths expose the
-- reminder before that resolved value is copied onto info, so mirror NSRT's
-- inheritance rule here instead of incorrectly treating the countdown as absent.
function Addon:GetReminderCountdown(info)
if type(info) ~= "table" then return nil, "invalid reminder" end
-- false or zero means the countdown is deliberately disabled. Only nil means
-- the note omitted the tag and should inherit NSRT's current setting.
if info.countdown ~= nil then
local explicit = tonumber(info.countdown)
explicit = explicit and floor(explicit + 0.5)
if explicit and explicit > 0 then
return explicit, "reminder countdown"
end
return nil, "countdown disabled"
end
local settings = _G.NSRT and _G.NSRT.ReminderSettings
local settingName = info.spellID and "SpellCountdown" or "TextCountdown"
local inherited = settings and tonumber(settings[settingName])
inherited = inherited and floor(inherited + 0.5)
if inherited and inherited > 0 then
return inherited, "NSRT " .. settingName
end
return nil, "NSRT " .. settingName .. " disabled"
end
function Addon:GetPlayerTagContext()
local specID = self:GetCurrentSpecID()
local playerName = UnitName and UnitName("player") or ""
local nickname = playerName
if _G.NSAPI and type(_G.NSAPI.GetName) == "function" then
local ok, value = pcall(_G.NSAPI.GetName, _G.NSAPI, "player", "GlobalNickNames")
if ok and value and value ~= "" then nickname = value end
end
local role = UnitGroupRolesAssigned and UnitGroupRolesAssigned("player") or "NONE"
local classID = select(3, UnitClass("player"))
local subgroup = 1
if _G.NSRT and type(_G.NSRT.GetSubGroup) == "function" then
local ok, value = pcall(_G.NSRT.GetSubGroup, _G.NSRT, "player")
if ok and tonumber(value) then subgroup = tonumber(value) end
end
local melee = false
if _G.NSRT and type(_G.NSRT.meleetable) == "table" and specID then
melee = _G.NSRT.meleetable[specID] and true or false
elseif self.MELEE_SPECS and specID then
melee = self.MELEE_SPECS[specID] and true or false
end
if tostring(role):lower() == "tank" then melee = true end
return {
name = tostring(playerName or ""):lower(),
nickname = tostring(nickname or ""):lower(),
role = tostring(role or ""):lower(),
classID = classID and tostring(classID) or nil,
specID = specID and tostring(specID) or nil,
subgroup = "group" .. tostring(subgroup or 1),
position = melee and "melee" or "ranged",
}
end
-- Mirrors NSRT's own TagMatchesPlayer function so the Current Note page shows
-- exactly the reminders NSRT considers personal to this character.
function Addon:TagMatchesPlayer(tagText)
if type(tagText) ~= "string" or tagText == "" then return false end
local context = self:GetPlayerTagContext()
local lowered = tagText:lower()
local tags = {}
for token in lowered:gmatch("(%S+)") do
tags[TrimText(token)] = true
end
local ignoreEveryone = _G.NSRT and _G.NSRT.ReminderSettings
and _G.NSRT.ReminderSettings.IgnoreEveryone
return (lowered == "everyone" and not ignoreEveryone)
or (context.name ~= "" and tags[context.name])
or (context.nickname ~= "" and tags[context.nickname])
or (context.role ~= "" and tags[context.role])
or (context.specID and tags[context.specID])
or (context.classID and tags[context.classID])
or (context.subgroup and tags[context.subgroup])
or (context.position and tags[context.position])
or false
end
function Addon:GetNSRTProfileKey()
local characterName, realm = UnitFullName and UnitFullName("player")
if not realm and GetNormalizedRealmName then realm = GetNormalizedRealmName() end
if characterName and realm then return characterName .. "-" .. realm end
end
local function AddUniqueNoteSource(result, seen, key, name, value)
if type(value) ~= "string" then return end
local text = TrimText(value)
if text == "" or seen[text] then return end
seen[text] = true
result[#result + 1] = { key = key, name = name, text = text }
end
-- NSRT keeps the active runtime strings on its private namespace, while the
-- public NSRT table contains the persistent copies and selected note names.
-- The reminder-changed callback supplies the private strings when they change;
-- the saved variables and MRT note are used to populate the page on login.
function Addon:GetLoadedNoteSources()
local result, seen = {}, {}
local nsrt = _G.NSRT
local cache = self.loadedNoteCache or {}
AddUniqueNoteSource(result, seen, "shared-callback", "NSRT shared note", cache.shared)
AddUniqueNoteSource(result, seen, "personal-callback", "NSRT personal note", cache.personal)
if nsrt then
local activeSharedName = type(nsrt.ActiveReminder) == "string" and nsrt.ActiveReminder or nil
local activeShared = activeSharedName and type(nsrt.Reminders) == "table" and nsrt.Reminders[activeSharedName] or nil
AddUniqueNoteSource(result, seen, "shared-active", activeSharedName and ("Shared note: " .. activeSharedName) or "NSRT shared note", activeShared)
AddUniqueNoteSource(result, seen, "shared-stored", "NSRT shared note", nsrt.StoredSharedReminder)
local profileKey = self:GetNSRTProfileKey()
local personalName = profileKey and type(nsrt.StoredPersonalReminder) == "table" and nsrt.StoredPersonalReminder[profileKey] or nil
local personalText = personalName and type(nsrt.PersonalReminders) == "table" and nsrt.PersonalReminders[personalName] or nil
AddUniqueNoteSource(result, seen, "personal-active", personalName and ("Personal note: " .. personalName) or "NSRT personal note", personalText)
-- Compatibility fallbacks for older or modified NSRT builds that expose
-- the active strings directly on the saved-variable table.
AddUniqueNoteSource(result, seen, "shared-runtime", "NSRT shared note", nsrt.Reminder)
AddUniqueNoteSource(result, seen, "personal-runtime", "NSRT personal note", nsrt.PersonalReminder)
local settings = nsrt.ReminderSettings or {}
local timelineUsesMRT = _G.LiquidRemindersSaved
and _G.LiquidRemindersSaved.settings
and _G.LiquidRemindersSaved.settings.timeline
and _G.LiquidRemindersSaved.settings.timeline.mrtNote
if settings.MRTNote or timelineUsesMRT then
local mrtNote = _G.VMRT and _G.VMRT.Note
AddUniqueNoteSource(result, seen, "mrt-shared", "MRT shared note", mrtNote and mrtNote.Text1)
AddUniqueNoteSource(result, seen, "mrt-personal", "MRT personal note", mrtNote and mrtNote.SelfText)
end
end
return result
end
local NOTE_SYMBOLS = { star=1, circle=2, diamond=3, triangle=4, moon=5, square=6, cross=7, skull=8 }
function Addon:NormalizeNoteReminderText(value)
local text = TrimText(value)
if text == "" then return "" end
text = text:gsub("||c(%x%x%x%x%x%x%x%x)", "|c%1")
:gsub("||r", "|r")
:gsub("||T", "|T")
:gsub("||t", "|t")
text = text:gsub("{(%a*%d*)}", function(token)
local id = NOTE_SYMBOLS[token] or (token:match("^rt(%d)$") and tonumber(token:match("^rt(%d)$")))
if id then return "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_" .. id .. ":0|t" end
end)
return text
end
function Addon:BuildNoteReminderKey(encID, phase, timeValue, spellID, text)
encID = tonumber(encID)
if not encID then return nil end
local normalizedText = self:NormalizeNoteReminderText(text)
local numericSpellID = tonumber(spellID)
local identity
if normalizedText ~= "" then
identity = "text:" .. normalizedText
if numericSpellID then identity = identity .. "|spell:" .. tostring(numericSpellID) end
elseif numericSpellID then
identity = "spell:" .. tostring(numericSpellID)
else
return nil
end
return table.concat({
tostring(encID),
CanonicalNumber(phase, 1),
CanonicalNumber(timeValue, 0),
identity,
}, "|")
end
function Addon:GetNoteLineCountdown(spellID, explicitCountdown, timeValue)
local countdown
local source
if explicitCountdown ~= nil then
countdown = tonumber(explicitCountdown)
source = "note"
else
local settings = _G.NSRT and _G.NSRT.ReminderSettings
local settingName = tonumber(spellID) and "SpellCountdown" or "TextCountdown"
countdown = settings and tonumber(settings[settingName])
source = "NSRT " .. settingName
end
countdown = countdown and floor(countdown + 0.5)
if not countdown or countdown < 1 then return nil, source .. " disabled" end
local reminderTime = tonumber(timeValue)
if reminderTime and countdown > reminderTime then countdown = floor(reminderTime + 0.5) end
if countdown < 1 then return nil, source .. " disabled" end
return countdown, source
end
function Addon:GetCurrentNoteReminders()
local result = {}
local seen = {}
for _, source in ipairs(self:GetLoadedNoteSources()) do
local encID
local encounterLabel
local lineNumber = 0
local text = source.text
if text:sub(-1) ~= "\n" then text = text .. "\n" end
for line in text:gmatch("([^\n]*)\n") do
lineNumber = lineNumber + 1
local headerID = line:match("EncounterID:(%d+)")
if headerID then
local nextEncID = tonumber(headerID)
local nextLabel = TrimText(line:match("Name:([^;]+)"))
if nextLabel ~= "" then
encounterLabel = nextLabel
elseif nextEncID ~= encID or not encounterLabel or encounterLabel == "" then
encounterLabel = self:GetEncounterName(nextEncID)
end
encID = nextEncID
else
local timeValue = line:match("time:(%d*%.?%d+)")
local tag = line:match("tag:([^;]+)")
local spellID = tonumber(line:match("spellid:(%d+)"))
local reminderText = line:match("text:([^;]+)")
if encID and timeValue and tag and (spellID or reminderText) and self:TagMatchesPlayer(tag) then
local phase = tonumber(line:match("ph:(%d*%.?%d+)")) or 1
local runtimeKey = self:BuildNoteReminderKey(encID, phase, timeValue, spellID, reminderText)
if runtimeKey and not seen[runtimeKey] then
seen[runtimeKey] = true
local spell = spellID and self:GetSpellData(spellID)
local label = TrimText(reminderText)
if label == "" then label = spell and spell.name or ("Spell " .. tostring(spellID)) end
local explicit = line:match("countdown:(%d+)")
local countdown, countdownSource = self:GetNoteLineCountdown(spellID, explicit, timeValue)
result[#result + 1] = {
key = runtimeKey,
encID = encID,
encounterName = encounterLabel or self:GetEncounterName(encID),
source = source.name,
sourceKey = source.key,
lineNumber = lineNumber,
phase = phase,
time = tonumber(timeValue),
tag = TrimText(tag),
spellID = spellID,
text = reminderText,
normalizedText = self:NormalizeNoteReminderText(reminderText),
label = label,
icon = spell and spell.icon or self:GetEncounterIcon(encID),
countdown = countdown,
countdownSource = countdownSource,
rawLine = line,
}
end
end
end
end
end
table.sort(result, function(a, b)
if a.encID ~= b.encID then return a.encID < b.encID end
if a.phase ~= b.phase then return a.phase < b.phase end
if a.time ~= b.time then return a.time < b.time end
return a.label < b.label
end)
return result
end
function Addon:GetNoteAssignment(noteKey)
if noteKey == nil then return nil end
return self.db.noteAssignments and self.db.noteAssignments[tostring(noteKey)]
end
local function CopyNoteReminderMetadata(target, reminder)
target.encID = tonumber(reminder.encID)
target.phase = tonumber(reminder.phase) or 1
target.time = tonumber(reminder.time)
target.spellID = tonumber(reminder.spellID)
target.text = reminder.text
target.normalizedText = reminder.normalizedText or Addon:NormalizeNoteReminderText(reminder.text)
target.label = reminder.label
target.tag = reminder.tag
target.encounterName = reminder.encounterName
target.source = reminder.source
end
local function GetStoredNoteTTSMode(assignment)
if type(assignment) ~= "table" then return "default" end
if assignment.ttsMode == "mute" or assignment.ttsMode == "custom" then
return assignment.ttsMode
end
if assignment.muteTTS == true then return "mute" end
if TrimText(assignment.customTTS) ~= "" then return "custom" end
return "default"
end
function Addon:GetNoteTTSMode(noteKey)
return GetStoredNoteTTSMode(self:GetNoteAssignment(noteKey))
end
function Addon:SetNoteOverrides(reminder, voiceReference, ttsMode, customTTS)
if type(reminder) ~= "table" or not reminder.key then return false end
-- Backwards compatibility for the 0.5.4 boolean mute argument.
if type(ttsMode) == "boolean" then ttsMode = ttsMode and "mute" or "default" end
if ttsMode ~= "mute" and ttsMode ~= "custom" then ttsMode = "default" end
customTTS = TrimText(customTTS)
if ttsMode == "custom" and customTTS == "" then return false end
local assignment = self:GetNoteAssignment(reminder.key)
if type(assignment) ~= "table" then assignment = {} end
CopyNoteReminderMetadata(assignment, reminder)
if voiceReference ~= nil then
local provider, rawID = self:DecodeVoiceReference(voiceReference)
if not provider or not rawID then return false end
assignment.voice = rawID
assignment.provider = provider
else
assignment.voice = nil
assignment.provider = nil
end
assignment.muteTTS = nil
assignment.ttsMode = ttsMode ~= "default" and ttsMode or nil
assignment.customTTS = ttsMode == "custom" and customTTS or nil
self.db.noteAssignments = self.db.noteAssignments or {}
if not assignment.voice and not assignment.ttsMode then
self.db.noteAssignments[tostring(reminder.key)] = nil
else
self.db.noteAssignments[tostring(reminder.key)] = assignment
end
return true
end
function Addon:SetNoteTTSMuted(reminder, muted)
if type(reminder) ~= "table" or not reminder.key then return false end
local assignment = self:GetNoteAssignment(reminder.key)
local voiceReference = assignment and assignment.voice and self:GetVoiceKey(assignment) or nil
return self:SetNoteOverrides(reminder, voiceReference, muted == true and "mute" or "default", nil)
end
function Addon:IsNoteTTSMuted(noteKey)
return self:GetNoteTTSMode(noteKey) == "mute"
end
function Addon:SetNoteAssignment(reminder, voiceReference)
local existing = type(reminder) == "table" and reminder.key and self:GetNoteAssignment(reminder.key)
return self:SetNoteOverrides(
reminder,
voiceReference,
GetStoredNoteTTSMode(existing),
existing and existing.customTTS
)
end
function Addon:RemoveNoteAssignment(noteKey)
if self.db.noteAssignments then self.db.noteAssignments[tostring(noteKey)] = nil end
end
local function GetNoteOverrideSignature(assignment)
if type(assignment) ~= "table" then return "" end
local voiceKey = assignment.voice and Addon:GetVoiceKey(assignment) or ""
local mode = GetStoredNoteTTSMode(assignment)
local custom = mode == "custom" and TrimText(assignment.customTTS) or ""
return tostring(mode) .. "|" .. custom .. "|" .. tostring(voiceKey or "")
end
function Addon:GetNoteAssignmentForInfo(info)
if type(info) ~= "table" or info.IsAlert or info.IsAssignment then return nil end
local key = self:BuildNoteReminderKey(info.encID, info.phase, info.time, info.spellID, info.text)
if key then
local assignment = self:GetNoteAssignment(key)
if assignment then return assignment, key, "current note reminder" end
end
-- NSRT may generate spell-name text for a line that contained only spellid,
-- and it expands raid-icon tokens before the callback. Match the stored line
-- metadata as a compatibility fallback, but only when the resulting voice is
-- unambiguous.
local encID = tonumber(info.encID)
local phase = tonumber(info.phase) or 1
local timeValue = tonumber(info.time)
local spellID = tonumber(info.spellID)
local normalizedText = self:NormalizeNoteReminderText(info.text)
local match, matchKey
for storedKey, candidate in pairs(self.db.noteAssignments or {}) do
if type(candidate) == "table"
and tonumber(candidate.encID) == encID
and math.abs((tonumber(candidate.phase) or 1) - phase) < 0.001
and timeValue and tonumber(candidate.time) and math.abs(tonumber(candidate.time) - timeValue) < 0.001
and tonumber(candidate.spellID) == spellID then
local candidateText = candidate.normalizedText or self:NormalizeNoteReminderText(candidate.text)
local textCompatible = spellID ~= nil or candidateText == normalizedText
if textCompatible then
if match and GetNoteOverrideSignature(match) ~= GetNoteOverrideSignature(candidate) then return nil end
match, matchKey = candidate, storedKey
end
end
end
if match then return match, matchKey, "current note reminder metadata" end
end
function Addon:RememberSpell(spellID, specID)
spellID = tonumber(spellID)
specID = tonumber(specID)
if not spellID or not specID or not self:GetSpellData(spellID) then return false end
local specKey = tostring(specID)
self.db.knownSpells[specKey] = self.db.knownSpells[specKey] or {}
self.db.knownSpells[specKey][tostring(spellID)] = true
return true
end
function Addon:AddCustomSpell(spellID, specID)
spellID = tonumber(spellID)
specID = tonumber(specID)
if not spellID or not specID or not self:GetSpellData(spellID) then return false end
local specKey = tostring(specID)
self.db.manualSpells[specKey] = self.db.manualSpells[specKey] or {}
self.db.manualSpells[specKey][tostring(spellID)] = true
return true
end
-- Retained for saved-variable and external compatibility with earlier builds.
Addon.AddManualSpell = Addon.AddCustomSpell
function Addon:IsCustomSpell(spellID, specID)
local specTable = self.db.manualSpells[tostring(specID)]
return specTable and specTable[tostring(spellID)] and true or false
end
function Addon:ParseNoteForSpells(noteText, specID)
if type(noteText) ~= "string" or noteText == "" or not specID then return end
for spellID in noteText:gmatch("spellid:(%d+)") do
self:RememberSpell(spellID, specID)
end
end
function Addon:IsPassiveSpell(spellID)
if C_Spell and C_Spell.IsSpellPassive then
return C_Spell.IsSpellPassive(spellID)
end
if IsPassiveSpell then
return IsPassiveSpell(spellID)
end
return false
end
function Addon:IsSpellBookItemPassive(slotIndex, bank, itemInfo, spellID)
if type(itemInfo) == "table" and itemInfo.isPassive ~= nil then
return itemInfo.isPassive and true or false
end
if C_SpellBook and C_SpellBook.IsSpellBookItemPassive then
local ok, passive = pcall(C_SpellBook.IsSpellBookItemPassive, slotIndex, bank)
if ok then return passive and true or false end
end
return self:IsPassiveSpell(spellID)
end
function Addon:ScanCurrentSpellbook()
if not self.db then return end
local specID = self:GetCurrentSpecID()
if not specID then return end
local className = select(1, UnitClass("player"))
local specIndex = GetSpecialization and GetSpecialization()
local specName = specIndex and select(2, GetSpecializationInfo(specIndex))
-- Rebuild the active spec cache from only the class and active-specialisation
-- spellbook lines. The General tab contains racials, guild perks, toys and
-- other assorted clutter that is useless for NSRT player ability reminders.
local specKey = tostring(specID)
self.db.knownSpells[specKey] = {}
local added = 0
local seen = {}
local function AddSpell(spellID, slotIndex, bank, itemInfo)
spellID = tonumber(spellID)
if not spellID or seen[spellID] then return end
if type(itemInfo) == "table" and itemInfo.isOffSpec then return end
if C_SpellBook and C_SpellBook.IsAutoAttackSpellBookItem then
local ok, isAutoAttack = pcall(C_SpellBook.IsAutoAttackSpellBookItem, slotIndex, bank)
if ok and isAutoAttack then return end
end
if C_SpellBook and C_SpellBook.IsRangedAutoAttackSpellBookItem then
local ok, isRangedAutoAttack = pcall(C_SpellBook.IsRangedAutoAttackSpellBookItem, slotIndex, bank)
if ok and isRangedAutoAttack then return end
end
if self:IsSpellBookItemPassive(slotIndex, bank, itemInfo, spellID) then return end
seen[spellID] = true
if self:RememberSpell(spellID, specID) then
added = added + 1
end
end
if C_SpellBook and C_SpellBook.GetNumSpellBookSkillLines and C_SpellBook.GetSpellBookSkillLineInfo then
local bank = Enum and Enum.SpellBookSpellBank and Enum.SpellBookSpellBank.Player
local lineCount = C_SpellBook.GetNumSpellBookSkillLines()
for lineIndex = 1, lineCount do
local lineInfo = C_SpellBook.GetSpellBookSkillLineInfo(lineIndex)
if type(lineInfo) == "table" then
local lineSpecID = tonumber(lineInfo.specID)
local offSpecID = tonumber(lineInfo.offSpecID)
local isClassLine = className and lineInfo.name == className
local isActiveSpecLine = (lineSpecID and lineSpecID == specID)
or (not lineSpecID and specName and lineInfo.name == specName)
local isCurrentLine = not lineInfo.isGuild
and not lineInfo.shouldHide
and (not offSpecID or offSpecID == 0)
and (isClassLine or isActiveSpecLine)
if isCurrentLine then
local offset = tonumber(lineInfo.itemIndexOffset) or 0
local count = tonumber(lineInfo.numSpellBookItems) or 0
for slotIndex = offset + 1, offset + count do
local itemInfo = C_SpellBook.GetSpellBookItemInfo and C_SpellBook.GetSpellBookItemInfo(slotIndex, bank)
if type(itemInfo) == "table" then
-- Blizzard documents spellID as nil for non-spell entries,
-- making this safer than guessing enum values for flyouts.
if itemInfo.spellID then
AddSpell(itemInfo.spellID, slotIndex, bank, itemInfo)
end
elseif GetSpellBookItemInfo then
local itemType, actionID, spellID = GetSpellBookItemInfo(slotIndex, BOOKTYPE_SPELL)
if itemType == "SPELL" then
AddSpell(spellID or actionID, slotIndex, bank)
end
end
end
end
end
end
elseif GetNumSpellTabs and GetSpellTabInfo and GetSpellBookItemInfo then
for tabIndex = 1, GetNumSpellTabs() do
local tabName, _, offset, count, isGuild, tabSpecID = GetSpellTabInfo(tabIndex)
local isClassLine = className and tabName == className
local isActiveSpecLine = tonumber(tabSpecID) == specID or (specName and tabName == specName)
if not isGuild and (isClassLine or isActiveSpecLine) then
for slotIndex = offset + 1, offset + count do
local itemType, actionID, spellID = GetSpellBookItemInfo(slotIndex, BOOKTYPE_SPELL)
if itemType == "SPELL" then AddSpell(spellID or actionID, slotIndex) end
end
end
end
end
self:Debug(("Spellbook scan for %s [%s] found %d active class/spec abilities."):format(
tostring(specName or "Unknown spec"), tostring(specID), added))
if self.RefreshOptions then self:RefreshOptions() end
return added
end
function Addon:GetKnownAbilities(specID)
specID = tonumber(specID)
if not specID then return {} end
local ids = {}
local specKey = tostring(specID)
local customSpells = self.db.manualSpells[specKey] or {}
for spellKey in pairs(self.db.knownSpells[specKey] or {}) do
if not customSpells[spellKey] then ids[tonumber(spellKey)] = true end
end
for spellKey in pairs(self.db.assignments[specKey] or {}) do
if not customSpells[spellKey] then ids[tonumber(spellKey)] = true end
end
local abilities = {}
for spellID in pairs(ids) do
local spell = self:GetSpellData(spellID)
if spell then abilities[#abilities + 1] = spell end
end
table.sort(abilities, function(a, b)
if a.name == b.name then return a.id < b.id end
return a.name < b.name
end)
return abilities
end
local VOICE_KEY_SEPARATOR = "\031"
Addon.VOICE_PROVIDER_BIGWIGS = "BIGWIGS"
Addon.VOICE_PROVIDER_DBM = "DBM"
Addon.VOICE_PROVIDER_MUTE = "MUTE"
Addon.VOICE_MUTE_ID = "COUNTDOWN"
function Addon:NormalizeVoiceProvider(provider)
provider = tostring(provider or ""):upper()
if provider == self.VOICE_PROVIDER_MUTE then return self.VOICE_PROVIDER_MUTE end
if provider == self.VOICE_PROVIDER_DBM then return self.VOICE_PROVIDER_DBM end
return self.VOICE_PROVIDER_BIGWIGS
end
function Addon:MakeVoiceKey(provider, voiceID)
if voiceID == nil then return nil end
return self:NormalizeVoiceProvider(provider) .. VOICE_KEY_SEPARATOR .. tostring(voiceID)
end
function Addon:DecodeVoiceReference(voice, providerHint)
if type(voice) == "table" then
if voice.muted == true then
return self.VOICE_PROVIDER_MUTE, self.VOICE_MUTE_ID
end
providerHint = voice.provider or providerHint
voice = voice.voice
end
if voice == nil then return nil, nil end
local value = tostring(voice)
if value == "MUTE" or value == "MUTE_COUNTDOWN" then
return self.VOICE_PROVIDER_MUTE, self.VOICE_MUTE_ID
end
local separatorAt = value:find(VOICE_KEY_SEPARATOR, 1, true)
if separatorAt then
local provider = value:sub(1, separatorAt - 1)
local rawID = value:sub(separatorAt + 1)
return self:NormalizeVoiceProvider(provider), rawID
end
if value:sub(1, 9) == "BIGWIGS:" then
return self.VOICE_PROVIDER_BIGWIGS, value:sub(10)
elseif value:sub(1, 4) == "DBM:" then
return self.VOICE_PROVIDER_DBM, value:sub(5)
end
-- Assignments created before DBM support contain only a BigWigs voice ID.
return self:NormalizeVoiceProvider(providerHint), value
end
function Addon:GetVoiceKey(voice, providerHint)
local provider, rawID = self:DecodeVoiceReference(voice, providerHint)
if not provider or not rawID then return nil end
return self:MakeVoiceKey(provider, rawID)
end
function Addon:IsMuteVoice(voice, providerHint)
local provider, rawID = self:DecodeVoiceReference(voice, providerHint)
return provider == self.VOICE_PROVIDER_MUTE and rawID == self.VOICE_MUTE_ID
end
function Addon:GetBigWigsVoiceDefinitions()
local voices = {}
if not BigWigsAPI or type(BigWigsAPI.GetCountdownList) ~= "function" then return voices end
local ok, voiceMap = pcall(BigWigsAPI.GetCountdownList, BigWigsAPI)
if not ok or type(voiceMap) ~= "table" then return voices end
for rawID, name in pairs(voiceMap) do
local voiceID = tostring(rawID)
voices[#voices + 1] = {
id = self:MakeVoiceKey(self.VOICE_PROVIDER_BIGWIGS, voiceID),
rawID = voiceID,
provider = self.VOICE_PROVIDER_BIGWIGS,
providerName = "BigWigs",
voiceName = tostring(name or voiceID),
name = "BigWigs: " .. tostring(name or voiceID),
}
end
return voices
end
function Addon:GetDBMVoiceDefinitions()
local voices = {}
if not DBM or type(DBM.GetCountSounds) ~= "function" then return voices end
local ok, countSounds = pcall(DBM.GetCountSounds, DBM)
if not ok or type(countSounds) ~= "table" then return voices end
local seen = {}
for _, count in pairs(countSounds) do
if type(count) == "table" and count.value and count.path then
local rawID = tostring(count.value)
if not seen[rawID] then
seen[rawID] = true
local maximum = tonumber(count.max) or 5
maximum = min(max(floor(maximum + 0.5), 1), 10)
voices[#voices + 1] = {
id = self:MakeVoiceKey(self.VOICE_PROVIDER_DBM, rawID),
rawID = rawID,
provider = self.VOICE_PROVIDER_DBM,
providerName = "DBM",
voiceName = tostring(count.text or rawID),
name = "DBM: " .. tostring(count.text or rawID),
path = tostring(count.path),
max = maximum,
}
end
end
end
return voices
end
function Addon:GetVoiceList()
local voices = {}
local function Append(source)
for _, voice in ipairs(source) do voices[#voices + 1] = voice end
end
Append(self:GetBigWigsVoiceDefinitions())
Append(self:GetDBMVoiceDefinitions())
table.sort(voices, function(a, b)
if a.provider ~= b.provider then
return a.provider == self.VOICE_PROVIDER_BIGWIGS
end
if a.voiceName == b.voiceName then return a.rawID < b.rawID end
return a.voiceName < b.voiceName
end)
table.insert(voices, 1, {
id = self:MakeVoiceKey(self.VOICE_PROVIDER_MUTE, self.VOICE_MUTE_ID),
rawID = self.VOICE_MUTE_ID,
provider = self.VOICE_PROVIDER_MUTE,
providerName = "Companion",
voiceName = "Mute countdown",
name = "Mute countdown",
muted = true,
})
return voices
end
function Addon:GetVoiceDefinition(voice, providerHint)
local key = self:GetVoiceKey(voice, providerHint)
if not key then return nil end
for _, definition in ipairs(self:GetVoiceList()) do
if definition.id == key then return definition end
end
end
function Addon:GetVoiceMap()
local map = {}
for _, voice in ipairs(self:GetVoiceList()) do
map[voice.id] = voice.name
end
return map
end
function Addon:GetVoiceName(voice, providerHint)
local definition = self:GetVoiceDefinition(voice, providerHint)
if definition then return definition.name end
local provider, rawID = self:DecodeVoiceReference(voice, providerHint)
if not rawID then return "Unknown voice" end
local providerName = provider == self.VOICE_PROVIDER_DBM and "DBM" or "BigWigs"
return providerName .. ": " .. rawID
end
function Addon:GetVoiceProviderCounts()
local counts = { BIGWIGS = 0, DBM = 0, total = 0 }
for _, voice in ipairs(self:GetVoiceList()) do
if voice.provider ~= self.VOICE_PROVIDER_MUTE then
counts[voice.provider] = (counts[voice.provider] or 0) + 1
counts.total = counts.total + 1
end
end
return counts
end
function Addon:GetVoiceSound(voice, number, providerHint)
number = tonumber(number)
if not number then return nil end
local provider, rawID = self:DecodeVoiceReference(voice, providerHint)
if provider == self.VOICE_PROVIDER_MUTE then return nil end
if provider == self.VOICE_PROVIDER_DBM then
local definition = self:GetVoiceDefinition(voice, providerHint)
if not definition or number > (definition.max or 0) then return nil end
local path = definition.path
if path:sub(-1) ~= "\\" and path:sub(-1) ~= "/" then path = path .. "\\" end
return path .. number .. ".ogg"
end
if not BigWigsAPI or type(BigWigsAPI.GetCountdownSound) ~= "function" then return nil end
local sound = BigWigsAPI:GetCountdownSound(rawID, number)
if not sound then
local numericID = tonumber(rawID)
if numericID then sound = BigWigsAPI:GetCountdownSound(numericID, number) end
end
return sound
end
function Addon:GetMaximumVoiceNumber(voice, providerHint)
local provider = self:DecodeVoiceReference(voice, providerHint)
if provider == self.VOICE_PROVIDER_MUTE then return 10 end
if provider == self.VOICE_PROVIDER_DBM then
local definition = self:GetVoiceDefinition(voice, providerHint)
return definition and definition.max or 0
end
for number = 10, 1, -1 do
if self:GetVoiceSound(voice, number, providerHint) then return number end
end
return 0
end
function Addon:GetAssignment(specID, spellID)
local specTable = self.db.assignments[tostring(specID)]
return specTable and specTable[tostring(spellID)]
end
-- Prefer the current spec, but allow a shared class ability to use an assignment
-- made under another spec. This matters for abilities such as Divine Toll that
-- appear in more than one Paladin spellbook.
function Addon:GetAssignmentForReminder(specID, spellID)
specID = tonumber(specID)
spellID = tonumber(spellID)
if not spellID then return nil end
local exact = specID and self:GetAssignment(specID, spellID)
if exact then
return exact, specID, "exact spec"
end
local currentClass = self:GetCurrentClass()
local classMatches = {}
local allMatches = {}
local spellKey = tostring(spellID)
for specKey, spellTable in pairs(self.db.assignments) do
local assignment = spellTable[spellKey]
if assignment then
local assignedSpecID = tonumber(specKey)
local spec = self.SPEC_DATA[assignedSpecID]
local assignedClass = assignment.class or (spec and spec.class)
local match = { assignment = assignment, specID = assignedSpecID }
allMatches[#allMatches + 1] = match
if currentClass and assignedClass == currentClass then
classMatches[#classMatches + 1] = match
end
end
end
local function PickCompatible(matches, reason)
if #matches == 0 then return nil end
local first = matches[1]
for index = 2, #matches do
if self:GetVoiceKey(matches[index].assignment) ~= self:GetVoiceKey(first.assignment) then
return nil
end
end
return first.assignment, first.specID, reason
end
local assignment, assignedSpecID, reason = PickCompatible(classMatches, "shared class ability")
if assignment then return assignment, assignedSpecID, reason end
return PickCompatible(allMatches, "unique spell assignment")
end
function Addon:SetAssignment(classFile, specID, spellID, voiceReference)
specID = tonumber(specID)
spellID = tonumber(spellID)
local provider, rawID = self:DecodeVoiceReference(voiceReference)
if not specID or not spellID or not provider or not rawID then return false end
local specKey = tostring(specID)
self.db.assignments[specKey] = self.db.assignments[specKey] or {}
self.db.assignments[specKey][tostring(spellID)] = {
voice = rawID,
provider = provider,
class = classFile,
}
self:RememberSpell(spellID, specID)
return true
end
function Addon:RemoveAssignment(specID, spellID)
local specKey = tostring(specID)
local spellKey = tostring(spellID)
if self.db.assignments[specKey] then
self.db.assignments[specKey][spellKey] = nil
if not next(self.db.assignments[specKey]) then
self.db.assignments[specKey] = nil
end
end
end
function Addon:GetAssignments()
local result = {}
for specKey, spellTable in pairs(self.db.assignments) do
local specID = tonumber(specKey)
for spellKey, assignment in pairs(spellTable) do
local spellID = tonumber(spellKey)
local spell = self:GetSpellData(spellID)
local spec = self.SPEC_DATA[specID]
result[#result + 1] = {
specID = specID,
spellID = spellID,
spellName = spell and spell.name or ("Spell " .. spellKey),
spellIcon = spell and spell.icon or 134400,
specName = spec and spec.name or ("Spec " .. specKey),
classFile = assignment.class or (spec and spec.class),