Repository navigation
Expand file tree
/
Copy pathKeystoneMeta.lua
More file actions
3392 lines (3139 loc) · 112 KB
/
Copy pathKeystoneMeta.lua
File metadata and controls
3392 lines (3139 loc) · 112 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
-- KeystoneMeta.lua
-- Compact Mythic+ representation companion. Consumes packaged KeystoneMetaData only.
-- Author : Xtendr
-- License: MIT
local ADDON_NAME = "KeystoneMeta"
local DB_DEFAULTS = {
minimap = { hide = false },
uiScale = 1.0,
bgOpacity = 1.0,
font = "Friz Quadrata TT",
fontOutline = "NONE",
compactRows = false,
followCurrentSpec = true,
showDailyMovement = true,
defaultView = "myspec",
defaultRole = "auto",
selectedSpecId = nil,
selectedDungeonId = nil,
selectedRole = "dps",
windowPosition = nil,
attachedOffset = nil,
settingsPosition = nil,
autoShowWithChallenges = true,
}
local DISCLAIMER = "Keystone Meta shows specialization representation among sampled top-ranked completed Mythic+ runs. Representation does not measure success rate or prove specialization strength."
local C = {
gold = { 1.00, 0.82, 0.00, 1 },
goldDim = { 0.78, 0.64, 0.28, 0.90 },
text = { 0.90, 0.90, 0.88, 1 },
muted = { 0.80, 0.80, 0.78, 1 },
muted2 = { 0.70, 0.70, 0.68, 1 },
green = { 0.30, 0.80, 0.30, 1 },
red = { 0.80, 0.34, 0.30, 1 },
hover = { 0.64, 0.36, 0.86, 0.10 },
selected = { 0.64, 0.36, 0.86, 0.16 },
element = { 0.17, 0.17, 0.17, 1.00 },
surface = { 0.12, 0.12, 0.12, 1.00 },
bg = { 0.08, 0.08, 0.08, 0.95 },
border = { 0.78, 0.64, 0.28, 0.90 },
inset = { 0.06, 0.04, 0.08, 0.90 },
purple = { 0.64, 0.36, 0.86, 1 },
}
local BD_EDGE = {
bgFile = "Interface\\Buttons\\WHITE8x8",
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 1,
}
local BD_PLAIN = { bgFile = "Interface\\Buttons\\WHITE8x8" }
local CHEVRON_ASSET = "Interface\\AddOns\\KeystoneMeta\\Assets\\chevron_right"
local MAIN_W = 318
local MAIN_H_PENDING = 220
local MAIN_H_POPULATED = 370
local MAIN_H_MAX = 480
local DETAIL_W, DETAIL_H = 348, 380
local SETTINGS_W = 340
local SETTINGS_LABEL_W = 118
local PAD = 12
local TOP_PAD = 10
local TITLE_H = 18
local SUBTITLE_GAP = 2
local SUBTITLE_H = 12
local AFTER_HEADER = 6
local SPEC_ROW_H = 26
local AFTER_SPEC = 2
local SUMMARY_H = 14
local AFTER_SUMMARY = 6
local SECTION_H = 16
local AFTER_SECTION = 2
local AFTER_LIST = 6
local FOOTER_H = 16
local BOTTOM_PAD = 10
local FOOTER_LINE_GAP = 8
local SCROLL_GUTTER = 26
local POPULATED_CHROME = TOP_PAD + TITLE_H + SUBTITLE_GAP + SUBTITLE_H + AFTER_HEADER
+ SPEC_ROW_H + AFTER_SPEC + SUMMARY_H + AFTER_SUMMARY
+ SECTION_H + AFTER_SECTION + AFTER_LIST + FOOTER_H + FOOTER_LINE_GAP + BOTTOM_PAD
local DIVIDER = { 0.25, 0.25, 0.25, 0.70 }
local ROW_H, ROW_H_COMPACT = 28, 24
local SHORT_COL_W = 48
local SHARE_COL_W = 44
local DELTA_COL_W = 42
local ROW_INSET = 8
local DETAIL_CHROME = TOP_PAD + TITLE_H + SUBTITLE_GAP + SUBTITLE_H + AFTER_HEADER + 26 + BOTTOM_PAD
local TITLE_SIZE = 14
local SPEC_SIZE = 13
local HEADER_SIZE = 12
local ROW_SIZE = 12
local META_SIZE = 12
local SCREEN_MARGIN = 16
local ATTACH_GAP = 10
local ACTION_BAR_CLEARANCE = 140
local TOOLTIP_MAX_WIDTH = 280
local TOOLTIP_EST_H = 160
local EMPTY_CELL = "--"
local SCOPE_SEP = " · "
local ROLE_ORDER = { "tank", "healer", "dps" }
local ROLE_LABEL = { tank = "Tank", healer = "Healer", dps = "DPS" }
-- Lua 5.1 allows 200 locals per function. Keep constants above and the
-- rest of the addon inside this nested function so the main chunk stays under the cap.
local function KeystoneMetaBoot()
local mainFrame
local detailFrame
local settingsFrame
local dropdownCatcher
local challengesHooked = false
local holdStandaloneUntilReanchor = false
local dismissedThisChallengesSession = false
local hidingWithParent = false
local cutoffsWatched = false
local viewState = {
specId = nil,
dungeonId = nil,
role = "dps",
}
local refreshFns = {}
local fontStrings = {}
local dungeonRows = {}
local specRows = {}
local RefreshUI
local PositionPanels
local HideMenus
local ApplyAnchor
local UpdateMinimapButton
local StyleScroll
local ShowMain
local ApplyCompanionVisibility
local specMenuOpen = false
local fallbackSpecMenus = {}
local function mixBD(frame)
if not frame.SetBackdrop then
Mixin(frame, BackdropTemplateMixin)
end
end
local function paint(frame, color, border)
mixBD(frame)
frame:SetBackdrop(BD_EDGE)
frame:SetBackdropColor(color[1], color[2], color[3], color[4] or 1)
local b = border or C.border
frame:SetBackdropBorderColor(b[1], b[2], b[3], b[4] or 1)
end
local function fill(frame, color)
mixBD(frame)
frame:SetBackdrop(BD_PLAIN)
frame:SetBackdropColor(color[1], color[2], color[3], color[4] or 1)
end
local function BackgroundAlpha()
local saved = KeystoneMetaDB
local alpha = type(saved) == "table" and saved.bgOpacity
if type(alpha) ~= "number" then
return 1
end
if alpha < 0.20 then
return 0.20
end
if alpha > 1 then
return 1
end
return alpha
end
local function CompanionIsDismissed()
if dismissedThisChallengesSession then
return true
end
local saved = KeystoneMetaDB
return type(saved) == "table" and saved.autoShowWithChallenges == false
end
local function SetCompanionDismissed(hidden)
dismissedThisChallengesSession = hidden and true or false
local saved = KeystoneMetaDB
if type(saved) == "table" then
saved.autoShowWithChallenges = not hidden
end
end
local function ApplyGoldOutline(frame)
if not frame then
return
end
local outline = frame.outline
if not outline then
outline = CreateFrame("Frame", nil, frame, "BackdropTemplate")
outline:SetAllPoints(frame)
mixBD(outline)
outline:SetBackdrop({
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 1,
})
outline:EnableMouse(false)
frame.outline = outline
end
outline:SetFrameLevel((frame:GetFrameLevel() or 0) + 50)
outline:SetBackdropColor(0, 0, 0, 0)
outline:SetBackdropBorderColor(C.border[1], C.border[2], C.border[3], C.border[4] or 1)
end
local function ApplyCompanionChrome(frame)
frame:SetToplevel(true)
frame:SetClampedToScreen(true)
frame:EnableMouse(true)
local alpha = BackgroundAlpha()
-- TooltipBackdropTemplate already matches Cutoffs. Fade the existing
-- Center fill; do not replace it with an opaque color texture.
if frame.NineSlice then
if frame.NineSlice.Center and frame.NineSlice.Center.SetAlpha then
frame.NineSlice.Center:SetAlpha(alpha)
end
if frame.Bg and frame.Bg.SetAlpha then
frame.Bg:SetAlpha(alpha)
end
if frame.outline then
ApplyGoldOutline(frame)
end
return
end
mixBD(frame)
frame:SetBackdrop(BD_EDGE)
frame:SetBackdropColor(C.bg[1], C.bg[2], C.bg[3], alpha)
if frame.outline then
frame:SetBackdropBorderColor(C.bg[1], C.bg[2], C.bg[3], alpha)
ApplyGoldOutline(frame)
else
frame:SetBackdropBorderColor(C.border[1], C.border[2], C.border[3], C.border[4] or 1)
end
end
local function CreateCompanionFrame(name, parent, strata)
local frame
local ok = pcall(function()
frame = CreateFrame("Frame", name, parent, "TooltipBackdropTemplate")
end)
if not ok or not frame then
frame = CreateFrame("Frame", name, parent, "BackdropTemplate")
end
ApplyCompanionChrome(frame)
if strata then
frame:SetFrameStrata(strata)
end
return frame
end
local function CreateThinDivider(parent)
local line = parent:CreateTexture(nil, "BACKGROUND")
line:SetHeight(1)
line:SetColorTexture(DIVIDER[1], DIVIDER[2], DIVIDER[3], DIVIDER[4])
return line
end
local function ApplyCompanionRowChrome(row)
local hi = row:CreateTexture(nil, "BACKGROUND")
hi:SetAllPoints()
hi:SetColorTexture(C.hover[1], C.hover[2], C.hover[3], C.hover[4])
hi:Hide()
row._highlight = hi
row.selected = row:CreateTexture(nil, "BACKGROUND", nil, -1)
row.selected:SetAllPoints()
row.selected:SetColorTexture(C.selected[1], C.selected[2], C.selected[3], C.selected[4])
row.selected:Hide()
row.accent = row:CreateTexture(nil, "ARTWORK")
row.accent:SetPoint("TOPLEFT")
row.accent:SetPoint("BOTTOMLEFT")
row.accent:SetWidth(2)
row.accent:SetColorTexture(C.gold[1], C.gold[2], C.gold[3], 0.85)
row.accent:Hide()
end
local function CreateChromeCloseButton(parent, onClick)
local btn = CreateFrame("Button", nil, parent)
btn:SetSize(18, 18)
btn:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -6, -8)
btn:SetFrameLevel(parent:GetFrameLevel() + 5)
local label = btn:CreateFontString(nil, "OVERLAY", "GameFontNormal")
label:SetPoint("CENTER", 0, 1)
label:SetText("x")
label:SetTextColor(C.muted[1], C.muted[2], C.muted[3], 1)
if label.SetShadowOffset then
label:SetShadowOffset(0, 0)
end
if label.SetShadowColor then
label:SetShadowColor(0, 0, 0, 0)
end
btn.label = label
btn:SetScript("OnEnter", function()
label:SetTextColor(C.gold[1], C.gold[2], C.gold[3], 1)
end)
btn:SetScript("OnLeave", function()
label:SetTextColor(C.muted[1], C.muted[2], C.muted[3], 1)
end)
btn:SetScript("OnClick", onClick)
return btn
end
local function PanelHeightForStatus(status)
if status == "ok" then
return MAIN_H_POPULATED
end
return MAIN_H_PENDING
end
local function db()
return KeystoneMetaDB
end
local function copyDefaults()
if type(KeystoneMetaDB) ~= "table" then
KeystoneMetaDB = {}
end
for key, value in pairs(DB_DEFAULTS) do
if KeystoneMetaDB[key] == nil then
if type(value) == "table" then
local clone = {}
for childKey, childValue in pairs(value) do
clone[childKey] = childValue
end
KeystoneMetaDB[key] = clone
else
KeystoneMetaDB[key] = value
end
end
end
KeystoneMetaDB.font = "Friz Quadrata TT"
KeystoneMetaDB.fontOutline = "NONE"
end
local function InCombat()
return InCombatLockdown and InCombatLockdown()
end
local function IsAddonLoaded(name)
if C_AddOns and C_AddOns.IsAddOnLoaded then
return C_AddOns.IsAddOnLoaded(name)
end
if IsAddOnLoaded then
return IsAddOnLoaded(name)
end
return false
end
local function GetData()
local data = KeystoneMetaData
if type(data) ~= "table" or data.schemaVersion ~= 1 then
return nil
end
return data
end
local function SortedDungeons()
local list = {}
local data = GetData()
if not data or type(data.dungeons) ~= "table" then
return list
end
for id, dungeon in pairs(data.dungeons) do
if type(id) == "number" and type(dungeon) == "table" then
list[#list + 1] = { id = id, dungeon = dungeon }
end
end
table.sort(list, function(a, b)
local left = a.dungeon.name or ""
local right = b.dungeon.name or ""
if left == right then
return a.id < b.id
end
return left < right
end)
return list
end
local function PopulatedPanelHeight()
local count = #SortedDungeons()
if count < 1 then
count = 8
end
local rowH = (db() and db().compactRows) and ROW_H_COMPACT or ROW_H
local height = POPULATED_CHROME + count * rowH
if height > MAIN_H_MAX then
return MAIN_H_MAX
end
return height
end
local function RoleKey(blizzardRole)
if blizzardRole == "TANK" then return "tank" end
if blizzardRole == "HEALER" then return "healer" end
return "dps"
end
local function SafeGetSpecialization()
if C_SpecializationInfo and C_SpecializationInfo.GetSpecialization then
local ok, spec = pcall(C_SpecializationInfo.GetSpecialization)
if ok then return spec end
end
if GetSpecialization then
local ok, spec = pcall(GetSpecialization)
if ok then return spec end
end
return nil
end
local function SafeGetSpecInfo(specIndex)
if C_SpecializationInfo and C_SpecializationInfo.GetSpecializationInfo then
local ok, id, name, _, icon, role = pcall(C_SpecializationInfo.GetSpecializationInfo, specIndex)
if ok and id then return id, name, icon, role end
end
if GetSpecializationInfo then
local ok, id, name, _, icon, role = pcall(GetSpecializationInfo, specIndex)
if ok and id then return id, name, icon, role end
end
return nil
end
local function SafeGetSpecByID(specId)
if not specId then return nil end
if GetSpecializationInfoByID then
local ok, id, name, _, icon, role, classFile, className = pcall(GetSpecializationInfoByID, specId)
if ok and id then
return id, name, icon, role, classFile, className
end
end
return specId, nil, nil, nil, nil, nil
end
local function PlayerSpec()
local index = SafeGetSpecialization()
if not index then return nil end
local id, name, icon, role = SafeGetSpecInfo(index)
if not id then return nil end
local _, _, _, _, classFile, className = SafeGetSpecByID(id)
return {
id = id,
name = name or ("Spec " .. id),
icon = icon,
role = RoleKey(role),
className = className,
classFile = classFile,
}
end
local function CollectSpecs()
local byId = {}
local function store(id, name, icon, role, classFile, className)
if not id then return end
byId[id] = {
id = id,
name = name or ("Spec " .. id),
icon = icon,
role = role or "dps",
className = className or "",
classFile = classFile,
}
end
local n = GetNumSpecializations and GetNumSpecializations() or 0
for i = 1, n do
local id, name, icon, role = SafeGetSpecInfo(i)
local _, _, _, _, classFile, className = SafeGetSpecByID(id)
store(id, name, icon, RoleKey(role), classFile, className)
end
local player = PlayerSpec()
if player then
store(player.id, player.name, player.icon, player.role, player.classFile, player.className)
end
for _, entry in ipairs(SortedDungeons()) do
local roles = entry.dungeon.roles or {}
for roleName, roleBlock in pairs(roles) do
local specs = roleBlock and roleBlock.specs or {}
for specId, spec in pairs(specs) do
if type(specId) == "number" and type(spec) == "table" then
local _, name, icon, _, classFile, className = SafeGetSpecByID(specId)
store(
specId,
spec.name or name,
icon,
roleName,
classFile,
spec.className or className
)
end
end
end
end
local list = {}
for _, spec in pairs(byId) do
list[#list + 1] = spec
end
table.sort(list, function(a, b)
if a.role ~= b.role then return a.role < b.role end
if a.name ~= b.name then return a.name < b.name end
return a.id < b.id
end)
return list
end
local CLASS_MENU_ORDER = {
"Death Knight",
"Demon Hunter",
"Druid",
"Evoker",
"Hunter",
"Mage",
"Monk",
"Paladin",
"Priest",
"Rogue",
"Shaman",
"Warlock",
"Warrior",
}
local function SafeGetNumSpecializations()
if C_SpecializationInfo and C_SpecializationInfo.GetNumSpecializations then
local ok, count = pcall(C_SpecializationInfo.GetNumSpecializations)
if ok and type(count) == "number" then
return count
end
end
if GetNumSpecializations then
local ok, count = pcall(GetNumSpecializations)
if ok and type(count) == "number" then
return count
end
end
return 0
end
local function CurrentClassSpecs()
local list = {}
local count = SafeGetNumSpecializations()
for i = 1, count do
local id, name, icon, role = SafeGetSpecInfo(i)
if id then
local _, _, _, _, classFile, className = SafeGetSpecByID(id)
list[#list + 1] = {
id = id,
name = name or ("Spec " .. id),
icon = icon,
role = RoleKey(role),
classFile = classFile,
className = className or "",
}
end
end
if #list == 0 then
local player = PlayerSpec()
if player then
list[1] = player
end
end
return list
end
local function CollectSpecsByClass()
local groups = {}
local byName = {}
for _, spec in ipairs(CollectSpecs()) do
local className = spec.className
if type(className) ~= "string" or className == "" then
className = spec.classFile or "Other"
end
local group = byName[className]
if not group then
group = { name = className, specs = {} }
byName[className] = group
groups[#groups + 1] = group
end
local seen = false
for _, existing in ipairs(group.specs) do
if existing.id == spec.id then
seen = true
break
end
end
if not seen then
group.specs[#group.specs + 1] = spec
end
end
local order = {}
for i, name in ipairs(CLASS_MENU_ORDER) do
order[name] = i
end
table.sort(groups, function(a, b)
local ia, ib = order[a.name] or 100, order[b.name] or 100
if ia ~= ib then
return ia < ib
end
return a.name < b.name
end)
for _, group in ipairs(groups) do
table.sort(group.specs, function(a, b)
if a.role ~= b.role then
return a.role < b.role
end
if a.name ~= b.name then
return a.name < b.name
end
return a.id < b.id
end)
end
return groups
end
local function SpecMenuLabel(spec)
local role = ROLE_LABEL[spec.role] or spec.role or "DPS"
local name = spec.name or ("Spec " .. tostring(spec.id))
if spec.icon then
return string.format("|T%s:16:16:0:0|t %s - %s", spec.icon, name, role)
end
return string.format("%s - %s", name, role)
end
local function FindSpecMeta(specId)
if specId then
for _, spec in ipairs(CollectSpecs()) do
if spec.id == specId then
return spec
end
end
local _, name, icon, role, classFile, className = SafeGetSpecByID(specId)
return {
id = specId,
name = name or ("Spec " .. tostring(specId)),
icon = icon,
className = className or "",
classFile = classFile,
role = RoleKey(role),
}
end
return {
id = nil,
name = "Specialization",
icon = nil,
className = "",
classFile = nil,
role = "dps",
}
end
local function DungeonUseful(dungeon)
local sample = dungeon and dungeon.sample or {}
return sample.status == "ok" and (sample.validRuns or 0) > 0
end
local function SpecInDungeon(dungeon, specId, role)
local roleBlock = dungeon and dungeon.roles and dungeon.roles[role]
local spec = roleBlock and roleBlock.specs and roleBlock.specs[specId]
if type(spec) == "table" then
return spec
end
return nil
end
local function RoleSpecList(dungeon, role)
local list = {}
local roleBlock = dungeon and dungeon.roles and dungeon.roles[role]
if not (roleBlock and roleBlock.specs) then
return list
end
for specId, spec in pairs(roleBlock.specs) do
if type(specId) == "number" and type(spec) == "table" then
list[#list + 1] = { id = specId, spec = spec }
end
end
table.sort(list, function(a, b)
local ra, rb = a.spec.representationRank or 999, b.spec.representationRank or 999
if ra ~= rb then return ra < rb end
return a.id < b.id
end)
return list
end
local function SnapshotStatus()
local data = GetData()
if not data then
return "pending_season_data"
end
if data.status == "pending_season_data" then
return "pending_season_data"
end
if data.season and data.season.slug == "pending" then
return "pending_season_data"
end
local anyUseful = false
local anyInsufficient = false
local anyDungeon = false
for _, entry in ipairs(SortedDungeons()) do
anyDungeon = true
local sample = entry.dungeon.sample or {}
if DungeonUseful(entry.dungeon) then
anyUseful = true
elseif sample.status == "insufficient_data" then
anyInsufficient = true
end
end
if anyUseful then
return "ok"
end
if anyInsufficient then
return "insufficient_data"
end
if not anyDungeon then
return "pending_season_data"
end
return "pending_season_data"
end
local function FormatPct(value)
if type(value) ~= "number" then return nil end
return string.format("%.1f%%", value)
end
local function FormatDelta(value)
if type(value) ~= "number" then return nil end
if math.abs(value) < 0.05 then return EMPTY_CELL end
if value > 0 then
return string.format("+%.1f", value)
end
return string.format("-%.1f", math.abs(value))
end
local function DeltaColor(value)
if type(value) ~= "number" or math.abs(value) < 0.05 then
return C.muted
end
if value > 0 then
return C.green
end
return C.red
end
local function FormatKey(value)
if type(value) ~= "number" or value <= 0 then return nil end
return string.format("+%d", value)
end
local function ClearFontShadow(fontString)
if not fontString then
return
end
if fontString.SetShadowOffset then
fontString:SetShadowOffset(0, 0)
end
if fontString.SetShadowColor then
fontString:SetShadowColor(0, 0, 0, 0)
end
end
local function ApplyFont(fontString, size, color, flags)
if not fontString then return end
if color then
fontString:SetTextColor(color[1], color[2], color[3], color[4] or 1)
end
ClearFontShadow(fontString)
end
local function TrackFontString(fs)
if fs then
fontStrings[#fontStrings + 1] = fs
end
return fs
end
local function CreateFS(parent, template, size, color)
local fs = parent:CreateFontString(nil, "OVERLAY", template or "GameFontHighlight")
ApplyFont(fs, size, color)
return TrackFontString(fs)
end
local function SafeSetText(fontString, text)
if not fontString then return end
if not fontString.GetFont or not fontString:GetFont() then
ApplyFont(fontString, ROW_SIZE, C.text)
end
fontString:SetText(text or "")
end
local function ClassColor(classFile)
local colors = RAID_CLASS_COLORS and classFile and RAID_CLASS_COLORS[classFile]
if colors then
return { colors.r, colors.g, colors.b, 1 }
end
return C.text
end
local function SetRoleIcon(texture, role)
texture:SetTexture("Interface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES")
if role == "tank" then
texture:SetTexCoord(0, 19 / 64, 22 / 64, 41 / 64)
elseif role == "healer" then
texture:SetTexCoord(20 / 64, 39 / 64, 1 / 64, 20 / 64)
else
texture:SetTexCoord(20 / 64, 39 / 64, 22 / 64, 41 / 64)
end
end
local function SetDropdownChevron(texture, open)
if not texture then return end
texture:SetTexture(CHEVRON_ASSET)
texture:SetTexCoord(0, 1, 0, 1)
texture:SetSize(18, 18)
texture:SetVertexColor(0.85, 0.85, 0.85, 0.95)
if texture.SetRotation then
texture:SetRotation(open and (math.pi / 2) or (-math.pi / 2))
end
end
local function SetHelpIcon(texture)
if not texture then return end
texture:SetTexture("Interface\\COMMON\\help-i")
if texture.GetTexture and not texture:GetTexture() then
texture:SetTexture("Interface\\FriendsFrame\\InformationIcon")
end
texture:SetVertexColor(1, 0.86, 0.35, 1)
end
local function ParseGeneratedAt(text)
if type(text) ~= "string" then return nil end
local y, m, d, hh, mm = text:match("^(%d+)%-(%d+)%-(%d+) (%d+):(%d+) UTC$")
if not y then return nil end
return time({
year = tonumber(y),
month = tonumber(m),
day = tonumber(d),
hour = tonumber(hh),
min = tonumber(mm),
sec = 0,
})
end
local function FreshnessLabel()
local data = GetData()
if not data then return nil end
if SnapshotStatus() ~= "ok" then
return nil
end
local stamp = ParseGeneratedAt(data.generatedAt)
if not stamp then
return data.generatedAt
end
local age = time() - stamp
if age > 36 * 3600 then
return "Stale"
end
if age < 3600 then
return "Updated just now"
end
return string.format("Updated %dh ago", math.floor(age / 3600))
end
local function ScopeLabel()
local data = GetData()
local scope = data and data.scope or {}
local affix = (scope.affixMode == "current") and "Current affixes" or "Full season"
local world = (data and data.isSynthetic) and "SYNTHETIC VISUAL TEST" or "World"
return table.concat({ world, affix }, SCOPE_SEP)
end
local function SampleCoverageLabel()
local runs = {}
for _, entry in ipairs(SortedDungeons()) do
if DungeonUseful(entry.dungeon) then
local valid = entry.dungeon.sample and entry.dungeon.sample.validRuns
if type(valid) == "number" and valid > 0 then
runs[#runs + 1] = valid
end
end
end
if #runs == 0 then
return nil
end
local lowest, highest = runs[1], runs[1]
for _, value in ipairs(runs) do
if value < lowest then lowest = value end
if value > highest then highest = value end
end
if lowest == highest then
return string.format("%d runs/dungeon", highest)
end
return string.format("Up to %d runs/dungeon", highest)
end
local function PopulatedFooterText()
local parts = {
SampleCoverageLabel() or (tostring(SampleTarget()) .. " runs/dungeon"),
"Raider.IO",
}
local fresh = FreshnessLabel()
if fresh and fresh ~= "" then
parts[#parts + 1] = fresh
end
return table.concat(parts, SCOPE_SEP)
end
local function PendingFooterText()
return "Awaiting first Raider.IO snapshot"
end
local function SampleTarget()
local data = GetData()
local scope = data and data.scope or {}
return tonumber(scope.targetRunsPerDungeon) or 500
end
local function CurrentSpecId()
if db() and db().followCurrentSpec then
local player = PlayerSpec()
if player then return player.id end
end
return viewState.specId or (db() and db().selectedSpecId)
end
local function CurrentRole()
local spec = FindSpecMeta(CurrentSpecId())
return spec and spec.role or "dps"
end
local function AverageForSpec(specId, role)
local shares, ranks = {}, {}
local roleCount = 0
for _, entry in ipairs(SortedDungeons()) do
if DungeonUseful(entry.dungeon) then
local spec = SpecInDungeon(entry.dungeon, specId, role)
local roleBlock = entry.dungeon.roles and entry.dungeon.roles[role]
local specCount = 0
if roleBlock and roleBlock.specs then
for _ in pairs(roleBlock.specs) do specCount = specCount + 1 end
end
roleCount = math.max(roleCount, specCount)
if spec and type(spec.roleSharePct) == "number" then
shares[#shares + 1] = spec.roleSharePct
if type(spec.representationRank) == "number" then
ranks[#ranks + 1] = spec.representationRank
end
end
end
end
local function mean(values)
if #values == 0 then return nil end
local sum = 0
for _, value in ipairs(values) do sum = sum + value end
return sum / #values
end
return {
share = mean(shares),
rank = mean(ranks),
roleCount = roleCount,
samples = #shares,
}
end
local function HideCatcher()
if not dropdownCatcher then return end
dropdownCatcher:Hide()
dropdownCatcher:EnableMouse(false)
end
local function EnsureCatcher()
if dropdownCatcher then return dropdownCatcher end
dropdownCatcher = CreateFrame("Frame", "KeystoneMetaMenuCatcher", UIParent)
dropdownCatcher:SetAllPoints()
-- DIALOG sits below TOOLTIP and below Blizzard MenuUtil frames.
-- A TOOLTIP catcher previously intercepted spec-row clicks.
dropdownCatcher:SetFrameStrata("DIALOG")
dropdownCatcher:SetFrameLevel(1)
dropdownCatcher:EnableMouse(false)
dropdownCatcher:Hide()
dropdownCatcher:SetScript("OnShow", function(self)
self:EnableMouse(true)
end)
dropdownCatcher:SetScript("OnHide", function(self)
self:EnableMouse(false)
end)
dropdownCatcher:SetScript("OnMouseDown", HideMenus)
return dropdownCatcher
end
local function CloseBlizzardMenus()