-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
6129 lines (5453 loc) · 188 KB
/
Core.lua
File metadata and controls
6129 lines (5453 loc) · 188 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
--[[
QuestTogether Core (No Ace Dependencies)
This file intentionally contains a lot of explanatory comments.
The goal is to make the addon understandable even for someone new to WoW addon development.
Key responsibilities in this file:
1. Create and expose the global addon table.
2. Initialize and maintain SavedVariables with defaults.
3. Handle addon lifecycle (load, login, enable/disable).
4. Provide utility methods used by the other files (events/comms/options/tests).
5. Implement slash commands and shared behavior like announcements.
]]
local addonName, addonTable = ...
-- Reuse an existing global table if it already exists (for safety), otherwise use the loader table.
local QuestTogether = _G.QuestTogether or addonTable or {}
_G.QuestTogether = QuestTogether
local raw_tostring = tostring
local raw_string_match = string.match
local raw_string_find = string.find
local raw_issecretvalue = type(issecretvalue) == "function" and issecretvalue or nil
local raw_canaccessvalue = type(canaccessvalue) == "function" and canaccessvalue or nil
local raw_canaccesstable = type(canaccesstable) == "function" and canaccesstable or nil
local DEBUG_WINDOW_TITLE = "QuestTogether Debug Window"
local DEBUG_WINDOW_HINT =
"Shared QuestTogether debug window. Use the category dropdown and Search field to filter. Quotes force exact phrase matches. Click Select All, then Ctrl+C."
local COPYABLE_WINDOW_DEFAULT_CONTROL_HEIGHT = 24
local COPYABLE_WINDOW_DEBUG_CONTROL_HEIGHT = 52
local COPYABLE_WINDOW_MIN_WIDTH = 400
local function NormalizeQuestInfoFlagValue(rawValue)
if QuestTogether and QuestTogether.IsSecretValue and QuestTogether:IsSecretValue(rawValue) then
return nil
end
if type(rawValue) == "boolean" then
return rawValue
end
local numericFlag = QuestTogether and QuestTogether.SafeToNumber
and QuestTogether:SafeToNumber(rawValue)
or nil
if numericFlag ~= nil then
return numericFlag ~= 0
end
return nil
end
local function CanAccessForeignValue(rawValue)
if raw_canaccessvalue then
local ok, canAccess = pcall(raw_canaccessvalue, rawValue)
if not ok or not canAccess then
return false
end
end
if QuestTogether and QuestTogether.IsSecretValue and QuestTogether:IsSecretValue(rawValue) then
return false
end
return true
end
local function CanAccessForeignTable(rawTable)
if type(rawTable) ~= "table" then
return false
end
if raw_canaccesstable then
local ok, canAccess = pcall(raw_canaccesstable, rawTable)
if not ok or not canAccess then
return false
end
end
return CanAccessForeignValue(rawTable)
end
local function SanitizeQuestInfoEnumValue(rawValue)
if not CanAccessForeignValue(rawValue) then
return nil
end
local numericValue = QuestTogether and QuestTogether.SafeToNumber and QuestTogether:SafeToNumber(rawValue) or nil
if numericValue == nil then
return nil
end
numericValue = math.floor(numericValue + 0.5)
if numericValue < 0 then
return nil
end
return numericValue
end
local function BuildSanitizedQuestLogInfoRecord(questLogIndex, titleValue, isHeaderValue, isHiddenValue, isTaskValue, isOnMapValue, hasLocalPOIValue, isCompleteValue, questIDValue, displayQuestIDValue, isWorldQuestValue)
local numericQuestLogIndex = QuestTogether and QuestTogether.SafeToNumber
and QuestTogether:SafeToNumber(questLogIndex)
or nil
if not numericQuestLogIndex or numericQuestLogIndex <= 0 then
return nil
end
local titleIsSecret = QuestTogether and QuestTogether.IsSecretValue and QuestTogether:IsSecretValue(titleValue)
local sanitizedInfo = {
title = (type(titleValue) == "string" and not titleIsSecret) and titleValue or nil,
questLogIndex = math.floor(numericQuestLogIndex + 0.5),
isHeader = NormalizeQuestInfoFlagValue(isHeaderValue) == true,
isHidden = NormalizeQuestInfoFlagValue(isHiddenValue) == true,
isTask = NormalizeQuestInfoFlagValue(isTaskValue) == true,
isOnMap = NormalizeQuestInfoFlagValue(isOnMapValue) == true,
hasLocalPOI = NormalizeQuestInfoFlagValue(hasLocalPOIValue) == true,
isComplete = NormalizeQuestInfoFlagValue(isCompleteValue) == true,
}
local numericQuestID = QuestTogether and QuestTogether.SafeToNumber
and QuestTogether:SafeToNumber(questIDValue)
or nil
if not numericQuestID or numericQuestID <= 0 then
numericQuestID = QuestTogether and QuestTogether.SafeToNumber
and QuestTogether:SafeToNumber(displayQuestIDValue)
or nil
end
if numericQuestID and numericQuestID > 0 then
sanitizedInfo.questID = math.floor(numericQuestID + 0.5)
end
local normalizedIsWorldQuest = NormalizeQuestInfoFlagValue(isWorldQuestValue)
if normalizedIsWorldQuest ~= nil then
sanitizedInfo.isWorldQuest = normalizedIsWorldQuest
end
return sanitizedInfo
end
local function BuildSanitizedQuestLogInfoFromRawInfo(questLogIndex, rawInfo)
if not CanAccessForeignTable(rawInfo) then
return nil
end
local sanitizedInfo = BuildSanitizedQuestLogInfoRecord(
questLogIndex,
rawInfo.title,
rawInfo.isHeader,
rawInfo.isHidden,
rawInfo.isTask,
rawInfo.isOnMap,
rawInfo.hasLocalPOI,
rawInfo.isComplete,
rawInfo.questID,
rawInfo.displayQuestID,
rawInfo.isWorldQuest
)
if not sanitizedInfo then
return nil
end
sanitizedInfo.campaignID = SanitizeQuestInfoEnumValue(rawInfo.campaignID)
sanitizedInfo.frequency = SanitizeQuestInfoEnumValue(rawInfo.frequency)
sanitizedInfo.questClassification = SanitizeQuestInfoEnumValue(rawInfo.questClassification)
return sanitizedInfo
end
local function MergeSanitizedQuestLogInfo(primaryInfo, fallbackInfo)
if type(primaryInfo) ~= "table" then
return type(fallbackInfo) == "table" and fallbackInfo or nil
end
if type(fallbackInfo) ~= "table" then
return primaryInfo
end
local mergedInfo = {}
mergedInfo.questLogIndex = primaryInfo.questLogIndex or fallbackInfo.questLogIndex
mergedInfo.title = primaryInfo.title or fallbackInfo.title
mergedInfo.questID = primaryInfo.questID or fallbackInfo.questID
mergedInfo.isHeader = primaryInfo.isHeader == true or fallbackInfo.isHeader == true
mergedInfo.isHidden = primaryInfo.isHidden == true or fallbackInfo.isHidden == true
mergedInfo.isTask = primaryInfo.isTask == true or fallbackInfo.isTask == true
mergedInfo.isOnMap = primaryInfo.isOnMap == true or fallbackInfo.isOnMap == true
mergedInfo.hasLocalPOI = primaryInfo.hasLocalPOI == true or fallbackInfo.hasLocalPOI == true
mergedInfo.isComplete = primaryInfo.isComplete == true or fallbackInfo.isComplete == true
mergedInfo.campaignID = primaryInfo.campaignID or fallbackInfo.campaignID
mergedInfo.frequency = primaryInfo.frequency or fallbackInfo.frequency
mergedInfo.questClassification = primaryInfo.questClassification or fallbackInfo.questClassification
if primaryInfo.isWorldQuest ~= nil then
mergedInfo.isWorldQuest = primaryInfo.isWorldQuest == true
elseif fallbackInfo.isWorldQuest ~= nil then
mergedInfo.isWorldQuest = fallbackInfo.isWorldQuest == true
end
return mergedInfo
end
local function GetSnapshotBuilderQuestLogInfo(questLogIndex)
local numericQuestLogIndex = QuestTogether and QuestTogether.SafeToNumber
and QuestTogether:SafeToNumber(questLogIndex)
or nil
if not numericQuestLogIndex or numericQuestLogIndex <= 0 then
return nil
end
numericQuestLogIndex = math.floor(numericQuestLogIndex + 0.5)
local questInfo = QuestTogether and QuestTogether.API and QuestTogether.API.GetQuestLogInfo
and QuestTogether.API.GetQuestLogInfo(numericQuestLogIndex)
or nil
return questInfo
end
local function SafeText(value, fallback)
if QuestTogether and QuestTogether.SafeToString then
return QuestTogether:SafeToString(value, fallback ~= nil and fallback or "<secret>")
end
local ok, textValue = pcall(raw_tostring, value)
if ok then
return textValue
end
if fallback ~= nil then
return fallback
end
return "<secret>"
end
local function SafeMatch(text, pattern)
local safeText = SafeText(text, "")
if safeText == "" then
return nil
end
local ok, first, second, third, fourth = pcall(raw_string_match, safeText, pattern)
if not ok then
return nil
end
return first, second, third, fourth
end
local function SafeFind(text, pattern, init, plain)
local safeText = SafeText(text, "")
if safeText == "" then
return nil
end
local ok, firstIndex, secondIndex = pcall(raw_string_find, safeText, pattern, init, plain)
if not ok then
return nil
end
return firstIndex, secondIndex
end
local tostring = SafeText
QuestTogether.addonName = addonName or "QuestTogether"
QuestTogether.commPrefix = "QuestTogether"
QuestTogether.announcementChannelName = "QuestTogetherAnnounce1"
QuestTogether.questLogWindowName = "QuestTogether"
QuestTogether.CHAT_BUBBLE_SIZE_MIN = 80
QuestTogether.CHAT_BUBBLE_SIZE_MAX = 160
QuestTogether.CHAT_BUBBLE_SIZE_STEP = 5
QuestTogether.CHAT_BUBBLE_DURATION_MIN = 1
QuestTogether.CHAT_BUBBLE_DURATION_MAX = 8
QuestTogether.CHAT_BUBBLE_DURATION_STEP = 0.5
QuestTogether.ANNOUNCEMENT_NEARBY_RADIUS = 5
-- Runtime state flags.
QuestTogether.isInitialized = QuestTogether.isInitialized or false
QuestTogether.hasLoggedIn = QuestTogether.hasLoggedIn or false
QuestTogether.isEnabled = QuestTogether.isEnabled or false
QuestTogether.activeProfileKey = QuestTogether.activeProfileKey or nil
QuestTogether.activeCharacterKey = QuestTogether.activeCharacterKey or nil
QuestTogether.pendingPingRequests = QuestTogether.pendingPingRequests or {}
QuestTogether.pendingQuestCompareRequests = QuestTogether.pendingQuestCompareRequests or {}
QuestTogether.debugLogLines = QuestTogether.debugLogLines or {}
QuestTogether.debugLogTextLengthSum = QuestTogether.debugLogTextLengthSum or 0
QuestTogether.debugLogStoreNormalized = QuestTogether.debugLogStoreNormalized or false
QuestTogether.debugLogRefreshBatchDepth = QuestTogether.debugLogRefreshBatchDepth or 0
QuestTogether.debugLogRefreshPending = QuestTogether.debugLogRefreshPending or false
QuestTogether.isRunningTests = QuestTogether.isRunningTests or false
QuestTogether.DEBUG_LOG_MAX_LINES = 400
QuestTogether.DEBUG_LOG_MAX_CHARS = 200000
QuestTogether.DEBUG_DEFAULT_CATEGORY = "DEBUG"
QuestTogether.DEBUG_ALL_CATEGORIES = "ALL"
-- Work queues / state tables used by event handlers.
QuestTogether.onQuestLogUpdate = QuestTogether.onQuestLogUpdate or {}
QuestTogether.questsCompleted = QuestTogether.questsCompleted or {}
QuestTogether.pendingQuestRemovals = QuestTogether.pendingQuestRemovals or {}
QuestTogether.worldQuestAreaStateByQuestID = QuestTogether.worldQuestAreaStateByQuestID or {}
QuestTogether.bonusObjectiveAreaStateByQuestID = QuestTogether.bonusObjectiveAreaStateByQuestID or {}
-- Default settings for SavedVariables.
QuestTogether.DEFAULTS = {
profile = {
enabled = true,
announceAccepted = true,
announceCompleted = true,
announceReadyToTurnIn = true,
announceRemoved = true,
announceProgress = true,
announceWorldQuestAreaEnter = true,
announceWorldQuestAreaLeave = true,
announceWorldQuestProgress = true,
announceWorldQuestCompleted = true,
announceBonusObjectiveAreaEnter = true,
announceBonusObjectiveAreaLeave = true,
announceBonusObjectiveProgress = true,
announceBonusObjectiveCompleted = true,
showChatBubbles = true,
hideMyOwnChatBubbles = false,
showChatLogs = true,
chatLogDestination = "main",
mirrorChatLogsToMainChat = false,
showProgressFor = "party_nearby",
devLogAllAnnouncements = false,
chatBubbleSize = 100,
chatBubbleDuration = 3,
emoteOnQuestCompletion = true,
emoteOnNearbyPlayerQuestCompletion = true,
nameplateQuestIconEnabled = true,
nameplateQuestIconStyle = "prefix",
nameplateQuestHealthColorEnabled = true,
nameplateQuestHealthColor = {
r = 0.95,
g = 0.45,
b = 0.05,
},
-- Stored per profile so each character/profile can pick its own chat tab.
questLogChatFrameID = nil,
},
global = {
questTrackers = {},
personalBubbleAnchors = {},
debugLogCategoryFilter = "ALL",
debugLogSearchFilter = "",
debugLogPrefixFilter = "",
},
}
QuestTogether.nameplateQuestIconStyleLabels = {
left = "Left",
right = "Right",
top = "Top",
prefix = "Prefix",
}
QuestTogether.nameplateQuestIconStyleOrder = {
"left",
"right",
"top",
"prefix",
}
QuestTogether.showProgressForLabels = {
party_nearby = "Party & Nearby Players",
party_only = "Party Only",
}
QuestTogether.showProgressForOrder = {
"party_nearby",
"party_only",
}
QuestTogether.chatLogDestinationLabels = {
main = "Main Chat Window",
separate = "Separate Chat Window",
}
QuestTogether.chatLogDestinationOrder = {
"main",
"separate",
}
QuestTogether.chatLogLinkType = "questtogetherlog"
QuestTogether.chatLogQuestLinkType = "questtogetherquest"
QuestTogether.chatLogCoordLinkType = "questtogethercoord"
QuestTogether.questTitleLinkEventTypes = {
QUEST_ACCEPTED = true,
QUEST_COMPLETED = true,
QUEST_READY_TO_TURN_IN = true,
QUEST_REMOVED = true,
WORLD_QUEST_ENTERED = true,
WORLD_QUEST_LEFT = true,
WORLD_QUEST_COMPLETED = true,
BONUS_OBJECTIVE_ENTERED = true,
BONUS_OBJECTIVE_LEFT = true,
BONUS_OBJECTIVE_COMPLETED = true,
}
QuestTogether.DEFAULT_PERSONAL_BUBBLE_ANCHOR = {
point = "CENTER",
relativePoint = "CENTER",
x = 0,
y = 120,
}
function QuestTogether:IsShowProgressFor(value)
for _, candidate in ipairs(self.showProgressForOrder) do
if candidate == value then
return true
end
end
return false
end
function QuestTogether:IsChatLogDestination(value)
for _, candidate in ipairs(self.chatLogDestinationOrder) do
if candidate == value then
return true
end
end
return false
end
function QuestTogether:GetChatLogDestinationLabel(value)
return self.chatLogDestinationLabels[value] or tostring(value)
end
function QuestTogether:NormalizeChatBubbleSizeValue(value)
local numericValue = self:SafeToNumber(value)
if not numericValue then
return nil
end
local step = self.CHAT_BUBBLE_SIZE_STEP or 5
numericValue = math.floor((numericValue / step) + 0.5) * step
if numericValue < self.CHAT_BUBBLE_SIZE_MIN or numericValue > self.CHAT_BUBBLE_SIZE_MAX then
return nil
end
return numericValue
end
function QuestTogether:IsChatBubbleSize(value)
return self:NormalizeChatBubbleSizeValue(value) ~= nil
end
function QuestTogether:NormalizeChatBubbleDurationValue(value)
local numericValue = self:SafeToNumber(value)
if not numericValue then
return nil
end
local step = self.CHAT_BUBBLE_DURATION_STEP or 0.5
numericValue = math.floor((numericValue / step) + 0.5) * step
numericValue = math.floor((numericValue * 10) + 0.5) / 10
if numericValue < self.CHAT_BUBBLE_DURATION_MIN or numericValue > self.CHAT_BUBBLE_DURATION_MAX then
return nil
end
return numericValue
end
function QuestTogether:IsChatBubbleDuration(value)
return self:NormalizeChatBubbleDurationValue(value) ~= nil
end
function QuestTogether:IsNameplateQuestIconStyle(styleKey)
for _, candidate in ipairs(self.nameplateQuestIconStyleOrder) do
if candidate == styleKey then
return true
end
end
return false
end
function QuestTogether:GetNameplateQuestIconStyleLabel(styleKey)
return self.nameplateQuestIconStyleLabels[styleKey] or tostring(styleKey)
end
function QuestTogether:GetNameplateQuestIconStyle()
local configured = self:GetOption("nameplateQuestIconStyle")
if self:IsNameplateQuestIconStyle(configured) then
return configured
end
return self.DEFAULTS.profile.nameplateQuestIconStyle
end
function QuestTogether:GetShowProgressForLabel(value)
return self.showProgressForLabels[value] or tostring(value)
end
function QuestTogether:GetChatBubbleSizeLabel(sizeKey)
local numericValue = self:NormalizeChatBubbleSizeValue(sizeKey)
if not numericValue then
return tostring(sizeKey)
end
return tostring(numericValue) .. "%"
end
function QuestTogether:GetChatBubbleDurationLabel(durationValue)
local numericValue = self:NormalizeChatBubbleDurationValue(durationValue)
if not numericValue then
return tostring(durationValue)
end
if math.abs(numericValue - math.floor(numericValue)) < 0.001 then
return string.format("%d sec", numericValue)
end
return string.format("%.1f sec", numericValue)
end
function QuestTogether:GetPersonalBubbleAnchorKey()
if self.GetPlayerFullName then
local fullName = self:GetPlayerFullName()
if fullName and fullName ~= "" then
return fullName
end
end
local playerName = self:GetPlayerName()
if playerName and playerName ~= "" then
return playerName
end
return "player"
end
function QuestTogether:GetPersonalBubbleAnchorStore()
if not self.db or not self.db.global then
return nil
end
if type(self.db.global.personalBubbleAnchors) ~= "table" then
self.db.global.personalBubbleAnchors = {}
end
return self.db.global.personalBubbleAnchors
end
function QuestTogether:GetPersonalBubbleAnchor()
local defaults = self.DEFAULT_PERSONAL_BUBBLE_ANCHOR
local anchor = {
point = defaults.point,
relativePoint = defaults.relativePoint,
x = defaults.x,
y = defaults.y,
}
local store = self:GetPersonalBubbleAnchorStore()
local key = self:GetPersonalBubbleAnchorKey()
local saved = store and store[key] or nil
if type(saved) ~= "table" then
return anchor
end
if type(saved.point) == "string" and saved.point ~= "" then
anchor.point = saved.point
end
if type(saved.relativePoint) == "string" and saved.relativePoint ~= "" then
anchor.relativePoint = saved.relativePoint
end
local numericX = self:SafeToNumber(saved.x)
if numericX ~= nil then
anchor.x = numericX
end
local numericY = self:SafeToNumber(saved.y)
if numericY ~= nil then
anchor.y = numericY
end
return anchor
end
function QuestTogether:SetPersonalBubbleAnchor(point, relativePoint, offsetX, offsetY)
local store = self:GetPersonalBubbleAnchorStore()
if not store then
return false
end
local defaults = self.DEFAULT_PERSONAL_BUBBLE_ANCHOR
local numericOffsetX = self:SafeToNumber(offsetX)
local numericOffsetY = self:SafeToNumber(offsetY)
store[self:GetPersonalBubbleAnchorKey()] = {
point = type(point) == "string" and point ~= "" and point or defaults.point,
relativePoint = type(relativePoint) == "string" and relativePoint ~= "" and relativePoint or defaults.relativePoint,
x = numericOffsetX ~= nil and numericOffsetX or defaults.x,
y = numericOffsetY ~= nil and numericOffsetY or defaults.y,
}
if self.ApplySavedPersonalBubbleAnchor then
self:ApplySavedPersonalBubbleAnchor()
end
if self.RefreshPersonalBubbleAnchorVisualState then
self:RefreshPersonalBubbleAnchorVisualState()
end
return true
end
function QuestTogether:ResetPersonalBubbleAnchor()
local store = self:GetPersonalBubbleAnchorStore()
if not store then
return false
end
store[self:GetPersonalBubbleAnchorKey()] = nil
if self.ApplySavedPersonalBubbleAnchor then
self:ApplySavedPersonalBubbleAnchor()
end
if self.RefreshPersonalBubbleAnchorVisualState then
self:RefreshPersonalBubbleAnchorVisualState()
end
return true
end
-- Emotes used when celebrating completed quests.
QuestTogether.completionEmotes = {
"applaud",
"bow",
"cheer",
"clap",
"commend",
"congratulate",
"curtsey",
"dance",
"golfclap",
"happy",
"highfive",
"huzzah",
"impressed",
"praise",
"proud",
"roar",
"sexy",
"smirk",
"strut",
"victory",
}
-- The runtime event list that should only be registered while the addon is enabled.
QuestTogether.runtimeEvents = {
"CHAT_MSG_ADDON",
"QUEST_ACCEPTED",
"QUEST_TURNED_IN",
"QUEST_REMOVED",
"UNIT_QUEST_LOG_CHANGED",
"QUEST_LOG_UPDATE",
"QUEST_POI_UPDATE",
"AREA_POIS_UPDATED",
"PLAYER_INSIDE_QUEST_BLOB_STATE_CHANGED",
"ZONE_CHANGED",
"ZONE_CHANGED_INDOORS",
"ZONE_CHANGED_NEW_AREA",
"PLAYER_REGEN_ENABLED",
"PLAYER_ENTERING_WORLD",
"ADDON_RESTRICTION_STATE_CHANGED",
"SUPER_TRACKING_CHANGED",
"GROUP_JOINED",
"GROUP_ROSTER_UPDATE",
}
--[[
API wrapper table.
Why this exists:
- Production code uses these wrappers to call WoW globals.
- Tests can replace one or more wrappers to observe behavior without touching global WoW APIs.
]]
-- API wrapper layer:
-- Guard Blizzard calls that can throw (invalid token, secure context, or transient data race)
-- so runtime features fail soft instead of tainting shared execution paths.
QuestTogether.API = QuestTogether.API or {
Delay = function(seconds, callback)
C_Timer.After(seconds, callback)
end,
JoinPermanentChannel = function(name, password, chatFrameId, hasVoice)
return JoinPermanentChannel(name, password, chatFrameId, hasVoice)
end,
LeaveChannelByName = function(name)
return LeaveChannelByName(name)
end,
GetChannelName = function(name)
return GetChannelName(name)
end,
GetNumChatWindows = function()
return NUM_CHAT_WINDOWS or 0
end,
GetChatWindowInfo = function(chatFrameID)
return FCF_GetChatWindowInfo(chatFrameID)
end,
GetChatFrameByID = function(chatFrameID)
local chatFrame = FCF_GetChatFrameByID(chatFrameID)
if QuestTogether and QuestTogether.CanAccessForeignFrame and not QuestTogether:CanAccessForeignFrame(chatFrame) then
return nil
end
return chatFrame
end,
GetCVar = function(cvarName)
if not (C_CVar and C_CVar.GetCVar and type(cvarName) == "string" and cvarName ~= "") then
return nil
end
local ok, value = pcall(C_CVar.GetCVar, cvarName)
if not ok then
return nil
end
if QuestTogether and QuestTogether.IsSecretValue and QuestTogether:IsSecretValue(value) then
return nil
end
return value
end,
GetInstanceInfo = function()
if type(GetInstanceInfo) ~= "function" then
return nil
end
local ok, name, instanceType, difficultyID, difficultyName, maxPlayers, dynamicDifficulty, isDynamic, instanceMapID, instanceGroupSize =
pcall(GetInstanceInfo)
if not ok then
return nil
end
return {
name = name,
instanceType = instanceType,
difficultyID = difficultyID,
difficultyName = difficultyName,
maxPlayers = maxPlayers,
dynamicDifficulty = dynamicDifficulty,
isDynamic = isDynamic,
instanceMapID = instanceMapID,
instanceGroupSize = instanceGroupSize,
}
end,
RemoveChatWindowChannel = function(chatFrame, channelName)
if QuestTogether and QuestTogether.CanAccessForeignFrame and not QuestTogether:CanAccessForeignFrame(chatFrame) then
return nil
end
if chatFrame and chatFrame.RemoveChannel then
return chatFrame:RemoveChannel(channelName)
end
if type(ChatFrame_RemoveChannel) == "function" and chatFrame then
return ChatFrame_RemoveChannel(chatFrame, channelName)
end
return nil
end,
AddMessageEventFilter = function(eventName, filterFunc)
if type(ChatFrame_AddMessageEventFilter) == "function" then
ChatFrame_AddMessageEventFilter(eventName, filterFunc)
end
end,
RemoveMessageEventFilter = function(eventName, filterFunc)
if type(ChatFrame_RemoveMessageEventFilter) == "function" then
ChatFrame_RemoveMessageEventFilter(eventName, filterFunc)
end
end,
OpenChatWindow = function(name, noDefaultChannels)
return FCF_OpenNewWindow(name, noDefaultChannels)
end,
CloseChatWindow = function(chatFrame)
if QuestTogether and QuestTogether.CanAccessForeignFrame and not QuestTogether:CanAccessForeignFrame(chatFrame) then
return nil
end
return FCF_Close(chatFrame)
end,
SetChatWindowFontSize = function(chatFrame, fontSize)
if QuestTogether and QuestTogether.CanAccessForeignFrame and not QuestTogether:CanAccessForeignFrame(chatFrame) then
return nil
end
return FCF_SetChatWindowFontSize(nil, chatFrame, fontSize)
end,
RegisterAddonPrefix = function(prefix)
local ok, result = pcall(C_ChatInfo.RegisterAddonMessagePrefix, prefix)
return ok and result or nil
end,
SendAddonMessage = function(prefix, message, channel, target)
local ok, result = pcall(C_ChatInfo.SendAddonMessage, prefix, message, channel, target)
return ok and result or nil
end,
IsInInstanceGroup = function()
return IsInGroup(LE_PARTY_CATEGORY_INSTANCE)
end,
IsInParty = function()
return UnitInParty("player")
end,
IsInRaid = function()
return IsInRaid()
end,
IsInInstance = function()
local inInstance = IsInInstance()
return inInstance and true or false
end,
InCombatLockdown = function()
if InCombatLockdown then
return InCombatLockdown() and true or false
end
return false
end,
DoEmote = function(emoteToken, target)
DoEmote(emoteToken, target)
end,
IsMounted = function()
return IsMounted()
end,
GetFaction = function()
local faction = UnitFactionGroup("player")
return faction
end,
Random = function(low, high)
return math.random(low, high)
end,
GetTime = function()
return GetTime()
end,
ReloadUI = function()
if type(ReloadUI) ~= "function" then
return false
end
local ok = pcall(ReloadUI)
return ok and true or false
end,
IsModifiedClick = function(action)
if type(IsModifiedClick) ~= "function" then
return false
end
local ok, modified = pcall(IsModifiedClick, action)
return ok and modified and true or false
end,
UnitExists = function(unitToken)
local ok, exists = pcall(UnitExists, unitToken)
return ok and exists and true or false
end,
UnitGUID = function(unitToken)
local ok, guidValue = pcall(UnitGUID, unitToken)
if not ok then
return nil
end
if QuestTogether and QuestTogether.IsSecretValue and QuestTogether:IsSecretValue(guidValue) then
return nil
end
return guidValue
end,
UnitFullName = function(unitToken)
local ok, unitName, unitRealm = pcall(UnitFullName, unitToken)
if not ok then
return nil, nil
end
if QuestTogether and QuestTogether.IsSecretValue then
if QuestTogether:IsSecretValue(unitName) then
unitName = nil
end
if QuestTogether:IsSecretValue(unitRealm) then
unitRealm = nil
end
end
return unitName, unitRealm
end,
UnitClass = function(unitToken)
local ok, className, classFile = pcall(UnitClass, unitToken)
if not ok then
return nil, nil
end
if QuestTogether and QuestTogether.IsSecretValue then
if QuestTogether:IsSecretValue(className) then
className = nil
end
if QuestTogether:IsSecretValue(classFile) then
classFile = nil
end
end
return className, classFile
end,
UnitRace = function(unitToken)
local ok, raceName = pcall(UnitRace, unitToken)
if not ok then
return nil
end
if QuestTogether and QuestTogether.IsSecretValue and QuestTogether:IsSecretValue(raceName) then
return nil
end
return raceName
end,
UnitLevel = function(unitToken)
local ok, levelValue = pcall(UnitLevel, unitToken)
if not ok then
return nil
end
if QuestTogether and QuestTogether.IsSecretValue and QuestTogether:IsSecretValue(levelValue) then
return nil
end
return levelValue
end,
UnitName = function(unitToken)
local ok, unitName = pcall(UnitName, unitToken)
if not ok then
return nil
end
if QuestTogether and QuestTogether.IsSecretValue and QuestTogether:IsSecretValue(unitName) then
return nil
end
return unitName
end,
UnitHealth = function(unitToken)
local ok, unitHealth = pcall(UnitHealth, unitToken)
if not ok then
return nil
end
if QuestTogether and QuestTogether.IsSecretValue and QuestTogether:IsSecretValue(unitHealth) then
return nil
end
return unitHealth
end,
UnitHealthMax = function(unitToken)
local ok, maxHealth = pcall(UnitHealthMax, unitToken)
if not ok then
return nil
end
if QuestTogether and QuestTogether.IsSecretValue and QuestTogether:IsSecretValue(maxHealth) then
return nil
end
return maxHealth
end,
UnitIsDeadOrGhost = function(unitToken)
if type(UnitIsDeadOrGhost) == "function" then
local ok, result = pcall(UnitIsDeadOrGhost, unitToken)
return ok and result and true or false
end
if type(UnitIsDead) == "function" then
local ok, result = pcall(UnitIsDead, unitToken)
return ok and result and true or false
end
return false
end,
UnitIsPlayer = function(unitToken)
local ok, result = pcall(UnitIsPlayer, unitToken)
return ok and result and true or false
end,
GetQuestLogIndexForQuestID = function(questID)
if InCombatLockdown and InCombatLockdown() then
return nil
end
local numericQuestID = QuestTogether and QuestTogether.NormalizeQuestID and QuestTogether:NormalizeQuestID(questID)
or nil
if not numericQuestID then
return nil
end
local snapshotState = QuestTogether
and QuestTogether.GetQuestSnapshotStateStore
and QuestTogether:GetQuestSnapshotStateStore()
or nil
local snapshotByQuestID = snapshotState and snapshotState.byQuestID or nil
local snapshot = snapshotByQuestID and snapshotByQuestID[numericQuestID] or nil
if type(snapshot) == "table" then
local snapshotQuestLogIndex = QuestTogether
and QuestTogether.SafeToNumber
and QuestTogether:SafeToNumber(snapshot.questLogIndex)
or nil
if snapshotQuestLogIndex and snapshotQuestLogIndex > 0 then
return math.floor(snapshotQuestLogIndex + 0.5)
end
end
local numericCount = QuestTogether and QuestTogether.API and QuestTogether.API.GetNumQuestLogEntries
and QuestTogether.API.GetNumQuestLogEntries()
or 0
numericCount = QuestTogether and QuestTogether.SafeToNumber and QuestTogether:SafeToNumber(numericCount) or nil
if numericCount and numericCount > 0 then
numericCount = math.floor(numericCount + 0.5)
for questLogIndex = 1, numericCount do
local entryInfo = QuestTogether and QuestTogether.API and QuestTogether.API.GetQuestLogInfo
and QuestTogether.API.GetQuestLogInfo(questLogIndex)
or nil
local normalizedEntryQuestID = entryInfo
and QuestTogether
and QuestTogether.NormalizeQuestID
and QuestTogether:NormalizeQuestID(entryInfo.questID)
or nil
if normalizedEntryQuestID == numericQuestID then
return questLogIndex
end
end
end
return nil
end,
IsQuestFlaggedCompleted = function(questID)
local numericQuestID = QuestTogether and QuestTogether.NormalizeQuestID and QuestTogether:NormalizeQuestID(questID)
or nil
if not numericQuestID then
return false
end
if C_QuestLog and C_QuestLog.IsQuestFlaggedCompleted then
local ok, isCompleted = pcall(C_QuestLog.IsQuestFlaggedCompleted, numericQuestID)
return ok and isCompleted and true or false
end
return false
end,
IsQuestReadyForTurnIn = function(questID)
local numericQuestID = QuestTogether and QuestTogether.NormalizeQuestID and QuestTogether:NormalizeQuestID(questID)
or nil
if not numericQuestID then
return false
end
if C_QuestLog and C_QuestLog.ReadyForTurnIn then
local ok, isReady = pcall(C_QuestLog.ReadyForTurnIn, numericQuestID)
return ok and isReady and true or false
end
return false
end,
IsQuestComplete = function(questID)
local numericQuestID = QuestTogether and QuestTogether.NormalizeQuestID and QuestTogether:NormalizeQuestID(questID)
or nil
if not numericQuestID then
return false
end