-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTargetMarks.lua
More file actions
1438 lines (1304 loc) · 50.3 KB
/
Copy pathTargetMarks.lua
File metadata and controls
1438 lines (1304 loc) · 50.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
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
---------------------------------------------------------------------------
-- PugzRaidTools - Target Marks
-- Mouseover-driven NPC marking based on the active preset. Each NPC entry can
-- hold multiple mark priorities per modifier slot, matching the old
-- AutoMarker flow without requiring duplicate UI rows.
---------------------------------------------------------------------------
local addonName, PRT = ...
PRT.TARGET_MARK_SLOTS = { "main", "alt1", "alt2" }
PRT.TARGET_MARKS_DEFAULT_VERSION = 2
local normalizedTargetMarksEntries = setmetatable({}, { __mode = "k" })
local targetMarksDebug = {
enabled = false,
counters = {},
baseline = nil,
}
local targetMarksRuntimeDebug = {
enabled = false,
counters = {},
baselineMS = 0,
recent = {},
modifierRecent = {},
pending = {},
requestSerial = 0,
}
local TARGET_MARK_RUNTIME_RECENT_LIMIT = 12
local TARGET_MARK_MODIFIER_RECENT_LIMIT = 8
local TARGET_MARK_VERIFY_DELAYS = { 0.10, 0.20, 0.40, 0.80 }
local function CountTargetMarksDebug(key, amount)
if not targetMarksDebug.enabled then return end
local counters = targetMarksDebug.counters
counters[key] = (counters[key] or 0) + (amount or 1)
end
local function ReadLuaHeapKB(forceGC)
if type(collectgarbage) ~= "function" then return nil end
if forceGC then
pcall(collectgarbage, "collect")
end
local ok, value = pcall(collectgarbage, "count")
return ok and tonumber(value) or nil
end
local function ReadAddonMemoryKB()
if type(UpdateAddOnMemoryUsage) == "function" then
UpdateAddOnMemoryUsage()
end
if type(GetAddOnMemoryUsage) ~= "function" then return nil end
return tonumber(GetAddOnMemoryUsage(addonName or "PugzRaidTools"))
end
local function CaptureTargetMarksMemory(forceGC)
local luaHeapKB = ReadLuaHeapKB(forceGC)
return {
addonKB = ReadAddonMemoryKB(),
luaHeapKB = luaHeapKB,
time = type(GetTime) == "function" and GetTime() or 0,
}
end
function PRT:IsTargetMarksMemoryDebugEnabled()
return targetMarksDebug.enabled
end
function PRT:CountTargetMarksDebug(key, amount)
CountTargetMarksDebug(key, amount)
end
function PRT:GetTargetMarksDebugCounters()
return targetMarksDebug.counters
end
function PRT:SetTargetMarksMemoryDebug(enabled)
enabled = enabled and true or false
if enabled then
targetMarksDebug.enabled = true
targetMarksDebug.counters = {}
targetMarksDebug.baseline = CaptureTargetMarksMemory(false)
PRT.Print("Target Marks memory debug enabled. Scroll the list, then use /prt debugui mem.")
return
end
if targetMarksDebug.enabled then
self:DumpTargetMarksMemoryDebug(false, "final")
end
targetMarksDebug.enabled = false
targetMarksDebug.baseline = nil
PRT.Print("Target Marks memory debug disabled.")
end
function PRT:DumpTargetMarksMemoryDebug(forceGC, label)
local snapshot = CaptureTargetMarksMemory(forceGC)
local baseline = targetMarksDebug.baseline or snapshot
local addonDelta = snapshot.addonKB and baseline.addonKB
and (snapshot.addonKB - baseline.addonKB) or nil
local luaDelta = snapshot.luaHeapKB and baseline.luaHeapKB
and (snapshot.luaHeapKB - baseline.luaHeapKB) or nil
local counters = targetMarksDebug.counters
PRT.Print(("TARGET MARKS MEMORY %s%s addon=%s delta=%s luaHeap(all addons)=%s delta=%s"):format(
tostring(label or "snapshot"),
forceGC and " after-GC" or "",
snapshot.addonKB and ("%.1fKB"):format(snapshot.addonKB) or "unavailable",
addonDelta and ("%+.1fKB"):format(addonDelta) or "unavailable",
snapshot.luaHeapKB and ("%.1fKB"):format(snapshot.luaHeapKB) or "unavailable",
luaDelta and ("%+.1fKB"):format(luaDelta) or "unavailable"))
PRT.Print(("normalization calls=%d rebuilt=%d slotReads=%d groupScans=%d entriesScanned=%d"):format(
counters.entryEnsureCalls or 0,
counters.entryNormalizationRebuilds or 0,
counters.slotListReads or 0,
counters.groupEnsureCalls or 0,
counters.groupEntriesScanned or 0))
PRT.Print(("scroll requests=%d refreshes=%d unchangedSkips=%d rowBindings=%d refreshTime=%.2fms"):format(
counters.visibleRefreshRequests or 0,
counters.visibleRefreshes or 0,
counters.unchangedRangeSkips or 0,
counters.rowBindings or 0,
counters.visibleRefreshMs or 0))
PRT.Print(("created while tracing rows=%d markButtons=%d"):format(
counters.rowFramesCreated or 0,
counters.markButtonsCreated or 0))
local panel = self.targetMarksPanel
if panel and panel.GetTargetMarksDebugSummary then
local summary = panel:GetTargetMarksDebugSummary()
PRT.Print(("current groupEntries=%d visible=%d-%d pooledRows=%d markButtons=%d editStates=%d scroll=%.1f"):format(
summary.groupEntries or 0,
summary.visibleStart or 0,
summary.visibleEnd or 0,
summary.pooledRows or 0,
summary.markButtons or 0,
summary.editStates or 0,
summary.scrollOffset or 0))
end
end
local function TargetMarksNowMS()
if type(debugprofilestop) == "function" then
return debugprofilestop()
end
if type(GetTime) == "function" then
return (GetTime() or 0) * 1000
end
return 0
end
local function CountTargetMarksRuntime(key, amount)
if not targetMarksRuntimeDebug.enabled then return end
local counters = targetMarksRuntimeDebug.counters
counters[key] = (counters[key] or 0) + (amount or 1)
end
local function PushTargetMarksRuntimeRecent(message)
if not targetMarksRuntimeDebug.enabled then return end
local elapsed = math.max(0,
TargetMarksNowMS() - (targetMarksRuntimeDebug.baselineMS or 0))
local recent = targetMarksRuntimeDebug.recent
recent[#recent + 1] = ("+%.3fs %s"):format(
elapsed / 1000, tostring(message or ""))
if #recent > TARGET_MARK_RUNTIME_RECENT_LIMIT then
table.remove(recent, 1)
end
end
local function PushTargetMarksModifierRecent(message)
if not targetMarksRuntimeDebug.enabled then return end
local elapsed = math.max(0,
TargetMarksNowMS() - (targetMarksRuntimeDebug.baselineMS or 0))
local recent = targetMarksRuntimeDebug.modifierRecent
recent[#recent + 1] = ("+%.3fs %s"):format(
elapsed / 1000, tostring(message or ""))
if #recent > TARGET_MARK_MODIFIER_RECENT_LIMIT then
table.remove(recent, 1)
end
end
local function ResetTargetMarksRuntimeDebug()
targetMarksRuntimeDebug.counters = {}
targetMarksRuntimeDebug.baselineMS = TargetMarksNowMS()
targetMarksRuntimeDebug.recent = {}
targetMarksRuntimeDebug.modifierRecent = {}
targetMarksRuntimeDebug.pending = {}
targetMarksRuntimeDebug.requestSerial = 0
end
local function BeginTargetMarkAttempt(trigger)
if not targetMarksRuntimeDebug.enabled then return nil end
CountTargetMarksRuntime("attempts")
CountTargetMarksRuntime("trigger_" .. tostring(trigger or "unknown"))
return TargetMarksNowMS()
end
local function FinishTargetMarkAttempt(startMS, outcome)
if not startMS or not targetMarksRuntimeDebug.enabled then return end
local elapsed = math.max(0, TargetMarksNowMS() - startMS)
local counters = targetMarksRuntimeDebug.counters
CountTargetMarksRuntime("result_" .. tostring(outcome or "unknown"))
counters.attemptTotalMS = (counters.attemptTotalMS or 0) + elapsed
counters.attemptMaxMS = math.max(counters.attemptMaxMS or 0, elapsed)
if elapsed >= 2 then
CountTargetMarksRuntime("slowAttempts")
end
end
local function FinishTargetMarkVerification(pending, outcome, source, observed)
if not pending
or targetMarksRuntimeDebug.pending[pending.guid] ~= pending then
return false
end
targetMarksRuntimeDebug.pending[pending.guid] = nil
CountTargetMarksRuntime("verification_" .. outcome)
if outcome == "confirmed" then
local latency = math.max(0, TargetMarksNowMS() - pending.requestedMS)
local counters = targetMarksRuntimeDebug.counters
counters.confirmLatencyTotalMS =
(counters.confirmLatencyTotalMS or 0) + latency
counters.confirmLatencyMaxMS =
math.max(counters.confirmLatencyMaxMS or 0, latency)
PushTargetMarksRuntimeRecent(
("confirmed %s npc=%s mark=%s in %.1fms via %s"):format(
pending.name ~= "" and pending.name or pending.guid,
tostring(pending.npcId or "?"),
tostring(pending.markId or "?"),
latency,
tostring(source or "check")))
else
PushTargetMarksRuntimeRecent(
("%s %s npc=%s requested=%s observed=%s"):format(
outcome,
pending.name ~= "" and pending.name or pending.guid,
tostring(pending.npcId or "?"),
tostring(pending.markId or "?"),
tostring(observed or 0)))
end
return true
end
local function ObserveTargetMarkVerification(source, expectedGuid)
if not targetMarksRuntimeDebug.enabled then return false end
local guid = type(UnitGUID) == "function" and UnitGUID("mouseover") or nil
local pending = targetMarksRuntimeDebug.pending[expectedGuid or guid]
if not pending then return false end
if guid ~= pending.guid then
return FinishTargetMarkVerification(
pending, "target_lost", source, 0)
end
local observed = type(GetRaidTargetIndex) == "function"
and (GetRaidTargetIndex("mouseover") or 0) or 0
if observed == pending.markId then
return FinishTargetMarkVerification(
pending, "confirmed", source, observed)
end
return false
end
local function ScheduleTargetMarkVerification(
guid, npcId, name, markId, trigger)
if not targetMarksRuntimeDebug.enabled then return end
targetMarksRuntimeDebug.requestSerial =
targetMarksRuntimeDebug.requestSerial + 1
local pending = {
serial = targetMarksRuntimeDebug.requestSerial,
guid = guid,
npcId = npcId,
name = name or "",
markId = markId,
trigger = trigger or "unknown",
requestedMS = TargetMarksNowMS(),
}
targetMarksRuntimeDebug.pending[guid] = pending
CountTargetMarksRuntime("markRequests")
PushTargetMarksRuntimeRecent(
("requested %s npc=%s mark=%s trigger=%s"):format(
pending.name ~= "" and pending.name or guid,
tostring(npcId or "?"),
tostring(markId or "?"),
pending.trigger))
if not C_Timer or type(C_Timer.After) ~= "function" then return end
local checkIndex = 1
local function Check()
if not targetMarksRuntimeDebug.enabled
or targetMarksRuntimeDebug.pending[guid] ~= pending then
return
end
if ObserveTargetMarkVerification("timer", guid) then return end
checkIndex = checkIndex + 1
local delay = TARGET_MARK_VERIFY_DELAYS[checkIndex]
if delay then
C_Timer.After(delay, Check)
return
end
local observed = type(GetRaidTargetIndex) == "function"
and (GetRaidTargetIndex("mouseover") or 0) or 0
FinishTargetMarkVerification(
pending, "unconfirmed", "timer", observed)
end
C_Timer.After(TARGET_MARK_VERIFY_DELAYS[checkIndex], Check)
end
function PRT:IsTargetMarksRuntimeDebugEnabled()
return targetMarksRuntimeDebug.enabled
end
function PRT:GetTargetMarksRuntimeDebugCounters()
return targetMarksRuntimeDebug.counters
end
function PRT:ResetTargetMarksRuntimeDebug()
ResetTargetMarksRuntimeDebug()
PRT.Print("Target Marks runtime diagnostics cleared.")
end
function PRT:SetTargetMarksRuntimeDebug(enabled)
enabled = enabled and true or false
if enabled then
targetMarksRuntimeDebug.enabled = true
ResetTargetMarksRuntimeDebug()
if self._targetMarksFrame then
self._targetMarksFrame:RegisterEvent("RAID_TARGET_UPDATE")
end
PRT.Print(
"Target Marks runtime diagnostics enabled. Mark targets normally, then use /prt debug target.")
return
end
if targetMarksRuntimeDebug.enabled then
self:DumpTargetMarksRuntimeDebug("final")
end
targetMarksRuntimeDebug.enabled = false
targetMarksRuntimeDebug.pending = {}
if self._targetMarksFrame then
self._targetMarksFrame:UnregisterEvent("RAID_TARGET_UPDATE")
end
PRT.Print("Target Marks runtime diagnostics disabled.")
end
function PRT:DumpTargetMarksRuntimeDebug(label)
local counters = targetMarksRuntimeDebug.counters
local attempts = counters.attempts or 0
local confirmations = counters.verification_confirmed or 0
local pendingCount = 0
for _ in pairs(targetMarksRuntimeDebug.pending) do
pendingCount = pendingCount + 1
end
PRT.Print(("TARGET MARKS RUNTIME %s elapsed=%.1fs attempts=%d requests=%d confirmed=%d pending=%d"):format(
tostring(label or "snapshot"),
math.max(0, TargetMarksNowMS()
- (targetMarksRuntimeDebug.baselineMS or 0)) / 1000,
attempts,
counters.markRequests or 0,
confirmations,
pendingCount))
PRT.Print(("triggers mouseover=%d modifier=%d raidTargetUpdates=%d results requested=%d existing=%d tracked=%d"):format(
counters.trigger_mouseover or 0,
counters.trigger_modifier or 0,
counters.raidTargetUpdates or 0,
counters.result_requested or 0,
counters.result_existing_mark or 0,
counters.result_already_tracked or 0))
PRT.Print(("modifier events=%d presses=%d releases=%d slotChanges=%d stateResets=%d"):format(
counters.modifierEvents or 0,
counters.modifierPresses or 0,
counters.modifierReleases or 0,
counters.modifierSlotChanges or 0,
counters.modifierStateResets or 0))
PRT.Print(("skips disabled=%d noPreset=%d noModifier=%d group=%d permission=%d player=%d noGuid=%d noNpc=%d noRule=%d noMark=%d"):format(
counters.result_disabled or 0,
counters.result_no_preset or 0,
counters.result_no_modifier or 0,
counters.result_not_grouped or 0,
counters.result_no_permission or 0,
counters.result_player or 0,
counters.result_no_guid or 0,
counters.result_no_npc_id or 0,
counters.result_no_rule or 0,
counters.result_no_available_mark or 0))
PRT.Print(("cache builds=%d entries=%d total=%.2fms max=%.2fms; attempts avg=%.3fms max=%.3fms slow=%d"):format(
counters.cacheBuilds or 0,
counters.cacheEntries or 0,
counters.cacheBuildTotalMS or 0,
counters.cacheBuildMaxMS or 0,
attempts > 0 and ((counters.attemptTotalMS or 0) / attempts) or 0,
counters.attemptMaxMS or 0,
counters.slowAttempts or 0))
PRT.Print(("verification confirmed=%d lost=%d unconfirmed=%d latency avg=%.1fms max=%.1fms"):format(
confirmations,
counters.verification_target_lost or 0,
counters.verification_unconfirmed or 0,
confirmations > 0
and ((counters.confirmLatencyTotalMS or 0) / confirmations) or 0,
counters.confirmLatencyMaxMS or 0))
local recent = targetMarksRuntimeDebug.recent
local first = math.max(1, #recent - 3)
for i = first, #recent do
PRT.Print("recent " .. recent[i])
end
local modifierRecent = targetMarksRuntimeDebug.modifierRecent
local modifierFirst = math.max(1, #modifierRecent - 5)
for i = modifierFirst, #modifierRecent do
PRT.Print("modifier " .. modifierRecent[i])
end
end
PRT.TARGET_MARK_MODIFIER_ITEMS = {
{ text = "CTRL", value = "CTRL" },
{ text = "ALT", value = "ALT" },
{ text = "SHIFT", value = "SHIFT" },
{ text = "Disabled", value = "NONE" },
}
local LEGACY_TARGET_MARK_GROUPS = {
{ name = "Naxxramas", rows = {
{ 15976, "Venom Stalker", 8 },
{ 15975, "Carrion Spinner", 7 },
{ 15975, "Carrion Spinner", 5 },
{ 15975, "Carrion Spinner", 6 },
{ 15975, "Carrion Spinner", 4 },
{ 15975, "Carrion Spinner", 3 },
{ 15974, "Dread Creeper", 7 },
{ 15974, "Dread Creeper", 5 },
{ 15974, "Dread Creeper", 6 },
{ 15974, "Dread Creeper", 4 },
{ 15974, "Dread Creeper", 3 },
{ 15956, "Anub'Rekhan", 8 },
{ 16573, "Crypt Guard", 7 },
{ 16573, "Crypt Guard", 6 },
{ 15978, "Crypt Reaver", 8 },
{ 16453, "Necro Stalker", 8 },
{ 16453, "Necro Stalker", 7 },
{ 16453, "Necro Stalker", 6 },
{ 16453, "Necro Stalker", 5 },
{ 16505, "Naxxramas Follower", 8 },
{ 16505, "Naxxramas Follower", 7 },
{ 16506, "Naxxramas Worshipper", 5 },
{ 16506, "Naxxramas Worshipper", 4 },
{ 16506, "Naxxramas Worshipper", 3 },
{ 16506, "Naxxramas Worshipper", 6 },
{ 15953, "Faerlina", 2 },
{ 15979, "Tomb Horror", 8 },
{ 16447, "Plagued Ghoul", 8 },
{ 16447, "Plagued Ghoul", 7 },
{ 16447, "Plagued Ghoul", 6 },
{ 16447, "Plagued Ghoul", 5 },
{ 16146, "Deathknight", 7 },
{ 16146, "Deathknight", 6 },
{ 16146, "Deathknight", 5 },
{ 16145, "Deathknight Captain", 8 },
{ 16145, "Deathknight Captain", 7 },
{ 16145, "Deathknight Captain", 6 },
{ 16145, "Deathknight Captain", 5 },
{ 16165, "Necro Knight", 8 },
{ 16165, "Necro Knight", 7 },
{ 16164, "Shade of Naxxramas", 4 },
{ 16156, "Dark Touched Warrior", 5 },
{ 16156, "Dark Touched Warrior", 4 },
{ 16156, "Dark Touched Warrior", 3 },
{ 16157, "Doom Touched Warrior", 5 },
{ 16157, "Doom Touched Warrior", 4 },
{ 16157, "Doom Touched Warrior", 3 },
{ 16158, "Death Touched Warrior", 5 },
{ 16158, "Death Touched Warrior", 4 },
{ 16158, "Death Touched Warrior", 3 },
{ 16163, "Deathknight Cavalier", 8 },
{ 16163, "Deathknight Cavalier", 7 },
{ 16163, "Deathknight Cavalier", 6 },
{ 16861, "Death Lord", 6 },
{ 16067, "Skeletal Steed", 8 },
{ 16067, "Skeletal Steed", 7 },
{ 16803, "Deathknight Understudy", 8 },
{ 16803, "Deathknight Understudy", 7 },
{ 16803, "Deathknight Understudy", 6 },
{ 16803, "Deathknight Understudy", 5 },
{ 16194, "Unholy Axe", 7 },
{ 16194, "Unholy Axe", 8 },
{ 16215, "Unholy Staff", 8 },
{ 16215, "Unholy Staff", 7 },
{ 16216, "Unholy Sword", 7 },
{ 16216, "Unholy Sword", 8 },
{ 16216, "Unholy Sword", 6 },
{ 16216, "Unholy Sword", 5 },
{ 16452, "Necro Knight Guardian", 8 },
{ 16452, "Necro Knight Guardian", 7 },
{ 16451, "Deathknight Vindicator", 6 },
{ 16064, "Thane Korth'azz", 8 },
{ 16062, "Highlord Mograine", 7 },
{ 16063, "Sir Zeliek", 6 },
{ 16065, "Lady Blaumeux", 5 },
{ 16017, "Patchwork Golem", 8 },
{ 16017, "Patchwork Golem", 7 },
{ 16017, "Patchwork Golem", 6 },
{ 16017, "Patchwork Golem", 5 },
{ 16018, "Bile Retcher", 6 },
{ 16018, "Bile Retcher", 8 },
{ 16375, "Sewage Slime", 8 },
{ 16375, "Sewage Slime", 7 },
{ 16375, "Sewage Slime", 6 },
{ 16029, "Sludge Belcher", 8 },
{ 16029, "Sludge Belcher", 7 },
{ 16021, "Living Monstrosity", 8 },
{ 16020, "Mad Scientist", 7 },
{ 16020, "Mad Scientist", 6 },
{ 16020, "Mad Scientist", 5 },
{ 16020, "Mad Scientist", 4 },
{ 16022, "Surgical Assistant", 2 },
{ 16022, "Surgical Assistant", 1 },
{ 16025, "Stitched Spewer", 8 },
{ 16025, "Stitched Spewer", 7 },
{ 16025, "Stitched Spewer", 6 },
{ 16025, "Stitched Spewer", 5 },
{ 16244, "Infectious Ghoul", 6 },
{ 16244, "Infectious Ghoul", 5 },
{ 16244, "Infectious Ghoul", 4 },
{ 16244, "Infectious Ghoul", 3 },
{ 16243, "Plague Slime", 8 },
{ 16243, "Plague Slime", 7 },
{ 16168, "Stoneskin Gargoyle", 8 },
{ 16168, "Stoneskin Gargoyle", 7 },
{ 16297, "Mutated Grub", 8 },
{ 16297, "Mutated Grub", 7 },
{ 16286, "Spore", 8 },
{ 16286, "Spore", 7 },
{ 16286, "Spore", 6 },
{ 16368, "Necropolis Acolytes", 8 },
{ 16368, "Necropolis Acolytes", 7 },
{ 16449, "Spirit of Naxxramas", 4 },
{ 16193, "Skeletal Smith", 8 },
{ 16193, "Skeletal Smith", 7 },
{ 16193, "Skeletal Smith", 6 },
{ 16446, "Plagued Gargoyle", 8 },
{ 16446, "Plagued Gargoyle", 7 },
{ 16446, "Plagued Gargoyle", 6 },
} },
{ name = "AQ40", rows = {
{ 15263, "Boss", 4 },
{ 15511, "Lord Kri", 8 },
{ 15543, "Princess Yauj", 7 },
{ 15544, "Vem", 6 },
{ 15516, "Battleguard Sartura", 8 },
{ 15984, "Sartura's Royal Guard", 7 },
{ 15984, "Sartura's Royal Guard", 6 },
{ 15984, "Sartura's Royal Guard", 5 },
{ 15229, "Vekniss Soldier", 8 },
{ 15262, "Obsidian Eradicator", 4 },
{ 15262, "Obsidian Eradicator", 3 },
{ 15264, "Anubisath Sentinel (Start 4 packs)", 8 },
{ 15264, "Anubisath Sentinel (Start 4 packs)", 7 },
{ 15264, "Anubisath Sentinel (Start 4 packs)", 6 },
{ 15264, "Anubisath Sentinel (Start 4 packs)", 5 },
{ 15247, "Qiraji Brainwasher", 8 },
{ 15247, "Qiraji Brainwasher", 7 },
{ 15230, "Vekniss Warrior", 8 },
{ 15230, "Vekniss Warrior", 7 },
{ 15230, "Vekniss Warrior", 6 },
{ 15233, "Vekniss Guardian (Knockup / Bleed packs)", 6 },
{ 15233, "Vekniss Guardian (Knockup / Bleed packs)", 5 },
{ 15233, "Vekniss Guardian (Knockup / Bleed packs)", 4 },
{ 15233, "Vekniss Guardian (Knockup / Bleed packs)", 4 },
{ 15233, "Vekniss Guardian (Knockup / Bleed packs)", 8 },
{ 15233, "Vekniss Guardian (Knockup / Bleed packs)", 7 },
{ 15240, "Vekniss Hive Crawler (Scorpians Fankriss)", 8 },
{ 15240, "Vekniss Hive Crawler (Scorpians Fankriss)", 7 },
{ 15240, "Vekniss Hive Crawler (Scorpians Fankriss)", 6 },
{ 15240, "Vekniss Hive Crawler (Scorpians Fankriss)", 5 },
{ 15235, "Vekniss Stinger (Big White Wasps)", 7 },
{ 15236, "Vekniss Wasp (Small wasps)", 6 },
{ 15236, "Vekniss Wasp (Small wasps)", 5 },
{ 15236, "Vekniss Wasp (Small wasps)", 4 },
{ 15249, "Qiraji Lasher", 8 },
{ 15249, "Qiraji Lasher", 3 },
{ 15277, "Anubisath Defender", 8 },
{ 15277, "Anubisath Defender", 7 },
{ 15277, "Anubisath Defender", 6 },
{ 15277, "Anubisath Defender", 5 },
{ 234830, "Anubisath Defender", 8 },
{ 234830, "Anubisath Defender", 7 },
{ 234830, "Anubisath Defender", 6 },
{ 234830, "Anubisath Defender", 5 },
{ 15537, "Anubisath Warrior", 5 },
{ 15538, "Anubisath Swarmguard", 5 },
{ 15252, "Qiraji Champion", 4 },
{ 15246, "Qiraji Mindslayer", 5 },
{ 15246, "Qiraji Mindslayer", 6 },
{ 15246, "Qiraji Mindslayer", 7 },
{ 15246, "Qiraji Mindslayer", 8 },
{ 234762, "Qiraji Mindslayer", 6 },
{ 234762, "Qiraji Mindslayer", 5 },
{ 234762, "Qiraji Mindslayer", 7 },
{ 234762, "Qiraji Mindslayer", 8 },
{ 15250, "Qiraji Slayer", 8 },
{ 15250, "Qiraji Slayer", 7 },
{ 15250, "Qiraji Slayer", 6 },
{ 15250, "Qiraji Slayer", 5 },
{ 234800, "Qiraji Slayer", 8 },
{ 234800, "Qiraji Slayer", 7 },
{ 234800, "Qiraji Slayer", 6 },
{ 234800, "Qiraji Slayer", 5 },
{ 15312, "Obsidian Nullifier", 8 },
{ 15312, "Obsidian Nullifier", 7 },
{ 15311, "Anubisath Warder", 6 },
} },
{ name = "BWL", rows = {
{ 12464, "Death Talon Seether", 5 },
{ 12464, "Death Talon Seether", 6 },
{ 12464, "Death Talon Seether", 7 },
{ 12465, "Death Talon Wyrmkin", 8 },
{ 12465, "Death Talon Wyrmkin", 3 },
{ 12463, "Death Talon Flamescale", 7 },
{ 12463, "Death Talon Flamescale", 6 },
{ 12463, "Death Talon Flamescale", 5 },
{ 12467, "Death Talon Captain", 4 },
{ 12468, "Death Talon Hatcher", 8 },
{ 12468, "Death Talon Hatcher", 7 },
{ 12468, "Death Talon Hatcher", 6 },
{ 12458, "Blackwing Taskmaster", 4 },
{ 12458, "Blackwing Taskmaster", 5 },
{ 12458, "Blackwing Taskmaster", 6 },
{ 12458, "Blackwing Taskmaster", 7 },
{ 12458, "Blackwing Taskmaster", 8 },
{ 12459, "Blackwing Warlock", 8 },
{ 12459, "Blackwing Warlock", 7 },
{ 12461, "Death Talon Overseer", 6 },
{ 12457, "Blackwing Spellbinder", 5 },
{ 12457, "Blackwing Spellbinder", 4 },
{ 12460, "Death Talon Wyrmguard", 2 },
{ 12460, "Death Talon Wyrmguard", 7 },
{ 12460, "Death Talon Wyrmguard", 6 },
} },
{ name = "MC", rows = {
{ 12118, "Lucifron", 8 },
{ 12118, "Lucifron", 7 },
{ 12119, "Flamewaker Protector", 8 },
{ 12119, "Flamewaker Protector", 7 },
{ 12259, "Gehennas", 8 },
{ 11664, "Flamewaker Elite", 7 },
{ 11664, "Flamewaker Elite", 6 },
{ 11664, "Flamewaker Elite", 3 },
{ 11664, "Flamewaker Elite", 4 },
{ 11664, "Flamewaker Elite", 5 },
{ 12099, "Firesworn", 1 },
{ 12099, "Firesworn", 2 },
{ 12099, "Firesworn", 3 },
{ 12099, "Firesworn", 4 },
{ 12099, "Firesworn", 5 },
{ 12099, "Firesworn", 6 },
{ 12099, "Firesworn", 7 },
{ 12099, "Firesworn", 8 },
{ 12098, "Sulfuron", 8 },
{ 11662, "Flamewaker Priest", 7 },
{ 11662, "Flamewaker Priest", 6 },
{ 11662, "Flamewaker Priest", 5 },
{ 11662, "Flamewaker Priest", 4 },
{ 11988, "Golemagg", 8 },
{ 11672, "Core Rager", 7 },
{ 11672, "Core Rager", 6 },
{ 11663, "Flamewaker Healer", 7 },
{ 11663, "Flamewaker Healer", 8 },
{ 11663, "Flamewaker Healer", 6 },
{ 11663, "Flamewaker Healer", 5 },
{ 11663, "Flamewaker Healer", 4 },
{ 11659, "Molten Destroyer", 8 },
{ 11659, "Molten Destroyer", 7 },
{ 11658, "Molten Giant", 7 },
{ 11658, "Molten Giant", 8 },
{ 11668, "Firelord", 6 },
{ 11668, "Firelord", 7 },
{ 11665, "Lava Annihilator", 5 },
{ 11665, "Lava Annihilator", 6 },
{ 12101, "Lava Surger", 4 },
{ 11673, "Ancient Core Hound", 8 },
{ 11673, "Ancient Core Hound", 7 },
{ 11673, "Ancient Core Hound", 6 },
{ 11666, "Firewalker", 8 },
{ 11667, "Flameguard", 7 },
{ 12076, "Lava Elemental", 6 },
{ 12076, "Lava Elemental", 5 },
{ 12100, "Lava Reaver", 6 },
} },
}
local function GetModifierDown(key)
if key == "CTRL" then return IsControlKeyDown() end
if key == "ALT" then return IsAltKeyDown() end
if key == "SHIFT" then return IsShiftKeyDown() end
return false
end
local function SaveObservedMark(state, guid, markId, name, source)
if not guid or not markId or markId <= 0 then return end
for existingMarkId, info in pairs(state) do
if info and info.guid == guid and existingMarkId ~= markId then
state[existingMarkId] = nil
end
end
state[markId] = {
guid = guid,
name = name or "",
source = source,
}
end
local function UnitAlreadyTracked(state, guid)
for _, info in pairs(state) do
if info and info.guid == guid then
return true
end
end
return false
end
local function FinalizeGroupImport(groups, currentGroup, currentEntry)
if currentEntry and currentGroup then
currentGroup.entries[#currentGroup.entries + 1] = currentEntry
end
if currentGroup then
groups[#groups + 1] = currentGroup
end
end
local function SanitizeExportValue(text)
text = tostring(text or "")
text = text:gsub("\r\n", " "):gsub("\r", " "):gsub("\n", " ")
return text
end
local function AppendMark(list, markId)
markId = tonumber(markId) or 0
if markId > 0 then
list[#list + 1] = markId
end
end
local function AppendMarks(list, marks)
if type(marks) == "table" then
for _, markId in ipairs(marks) do
AppendMark(list, markId)
end
else
AppendMark(list, marks)
end
end
local function ParseMarkList(text)
local out = {}
text = tostring(text or "")
for token in text:gmatch("[^,%s]+") do
AppendMark(out, token)
end
return out
end
local function SerializeMarkList(list)
local out = {}
for _, markId in ipairs(list or {}) do
markId = tonumber(markId) or 0
if markId > 0 then
out[#out + 1] = tostring(markId)
end
end
return table.concat(out, ",")
end
local function NewEntry(npcId, targetName)
local entry = {
npcId = tonumber(npcId) or 0,
targetName = tostring(targetName or ""),
marks = {
main = {},
alt1 = {},
alt2 = {},
},
}
normalizedTargetMarksEntries[entry] = true
return entry
end
local function BuildLegacyEntries(rows)
local entries = {}
local lookup = {}
for _, row in ipairs(rows or {}) do
local npcId = tonumber(row[1]) or 0
local key = tostring(npcId)
local entry = lookup[key]
if not entry then
entry = NewEntry(npcId, row[2] or "")
lookup[key] = entry
entries[#entries + 1] = entry
elseif (entry.targetName or "") == "" and row[2] and row[2] ~= "" then
entry.targetName = tostring(row[2])
end
AppendMark(entry.marks.main, row[3])
end
return entries
end
function PRT:CreateTargetMarksEntry(npcId, targetName)
return NewEntry(npcId, targetName)
end
function PRT:CreateLegacyTargetMarksPreset()
local groups = {}
for i, group in ipairs(LEGACY_TARGET_MARK_GROUPS) do
groups[i] = {
name = group.name,
entries = BuildLegacyEntries(group.rows),
}
end
return {
name = "Default",
groups = groups,
}
end
function PRT:GetTargetMarksPreset(name)
if not name or name == "" then return nil end
local db = self:GetDB()
local tm = db.targetMarks or {}
for _, preset in ipairs(tm.presets or {}) do
if preset.name == name then
return preset
end
end
return nil
end
function PRT:GetActiveTargetMarksPreset()
local db = self:GetDB()
local tm = db.targetMarks or {}
return self:GetTargetMarksPreset(tm.activePreset)
end
function PRT:EnsureTargetMarksEntryDefaults(entry)
if not entry then return end
CountTargetMarksDebug("entryEnsureCalls")
if normalizedTargetMarksEntries[entry] then
return entry
end
CountTargetMarksDebug("entryNormalizationRebuilds")
entry.npcId = tonumber(entry.npcId) or 0
entry.targetName = tostring(entry.targetName or "")
local marks = type(entry.marks) == "table" and entry.marks or {}
local normalized = {
main = {},
alt1 = {},
alt2 = {},
}
AppendMarks(normalized.main, marks.main)
AppendMarks(normalized.alt1, marks.alt1)
AppendMarks(normalized.alt2, marks.alt2)
-- Migrate prior scalar/flat storage to the new list-based structure.
AppendMarks(normalized.main, entry.mainMarks)
AppendMarks(normalized.alt1, entry.alt1Marks or entry.altMarks1)
AppendMarks(normalized.alt2, entry.alt2Marks or entry.altMarks2)
AppendMark(normalized.main, entry.mainMark)
AppendMark(normalized.alt1, entry.altMark1)
AppendMark(normalized.alt2, entry.altMark2)
entry.marks = normalized
entry.mainMarks = nil
entry.alt1Marks = nil
entry.alt2Marks = nil
entry.alt3Marks = nil
entry.altMarks1 = nil
entry.altMarks2 = nil
entry.altMarks3 = nil
entry.mainMark = nil
entry.altMark1 = nil
entry.altMark2 = nil
entry.altMark3 = nil
normalizedTargetMarksEntries[entry] = true
return entry
end
local function GroupHasDuplicateNpcIds(entries)
local seen = {}
for _, entry in ipairs(entries or {}) do
local npcId = tonumber(entry and entry.npcId) or 0
if npcId > 0 then
if seen[npcId] then
return true
end
seen[npcId] = true
end
end
return false
end
function PRT:CollapseTargetMarksEntries(entries)
local collapsed = {}
local lookup = {}
for _, rawEntry in ipairs(entries or {}) do
self:EnsureTargetMarksEntryDefaults(rawEntry)
local npcId = tonumber(rawEntry.npcId) or 0
local entry
if npcId > 0 then
local key = tostring(npcId)
entry = lookup[key]
if not entry then
entry = NewEntry(rawEntry.npcId, rawEntry.targetName)
lookup[key] = entry
collapsed[#collapsed + 1] = entry
elseif entry.targetName == "" and rawEntry.targetName ~= "" then
entry.targetName = rawEntry.targetName
end
else
entry = NewEntry(rawEntry.npcId, rawEntry.targetName)
collapsed[#collapsed + 1] = entry
end
for _, slot in ipairs(self.TARGET_MARK_SLOTS) do
AppendMarks(entry.marks[slot], rawEntry.marks and rawEntry.marks[slot])
end
end
return collapsed
end
function PRT:GetTargetMarksSlotList(entry, slot)
CountTargetMarksDebug("slotListReads")
self:EnsureTargetMarksEntryDefaults(entry)
entry.marks[slot] = entry.marks[slot] or {}
return entry.marks[slot]
end
function PRT:EnsureTargetMarksGroupDefaults(group)
if not group then return end
CountTargetMarksDebug("groupEnsureCalls")
group.name = PRT.Trim(group.name or "") ~= "" and group.name or "Group"
group.entries = group.entries or {}
CountTargetMarksDebug("groupEntriesScanned", #group.entries)
if GroupHasDuplicateNpcIds(group.entries) then
group.entries = self:CollapseTargetMarksEntries(group.entries)
else
for _, entry in ipairs(group.entries) do
self:EnsureTargetMarksEntryDefaults(entry)
end
end
end
function PRT:EnsureTargetMarksPresetDefaults(preset)
if not preset then return end
CountTargetMarksDebug("presetEnsureCalls")
preset.name = PRT.Trim(preset.name or "") ~= "" and preset.name or "Preset"
preset.groups = preset.groups or {}
for _, group in ipairs(preset.groups) do
self:EnsureTargetMarksGroupDefaults(group)
end
end
function PRT:EnsureTargetMarksDBDefaults()
local db = self:GetDB()
db.targetMarks = db.targetMarks or {}
local tm = db.targetMarks
if tm.enabled == nil then tm.enabled = false end
if tm.allowSolo == nil then tm.allowSolo = false end
tm.activePreset = tm.activePreset or ""
tm.presets = tm.presets or {}
tm.modifiers = tm.modifiers or {}
if tm.modifiers.main == nil then tm.modifiers.main = "CTRL" end
if tm.modifiers.alt1 == nil then tm.modifiers.alt1 = "ALT" end
if tm.modifiers.alt2 == nil then tm.modifiers.alt2 = "SHIFT" end
if #tm.presets == 0 then
tm.presets[1] = self:CreateLegacyTargetMarksPreset()
tm.defaultVersion = self.TARGET_MARKS_DEFAULT_VERSION
elseif (tm.defaultVersion or 0) < self.TARGET_MARKS_DEFAULT_VERSION then
for i, preset in ipairs(tm.presets) do
if preset.name == "Default" then
tm.presets[i] = self:CreateLegacyTargetMarksPreset()
break
end
end