forked from nebularg/PitBull4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.lua
executable file
·2006 lines (1788 loc) · 56 KB
/
Main.lua
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
-- Constants ----------------------------------------------------------------
local _G = _G
-- luacheck: globals ReloadUI SecureButton_GetModifiedUnit
local L = LibStub("AceLocale-3.0"):GetLocale("PitBull4")
local SINGLETON_CLASSIFICATIONS = {
"player",
"pet",
"pettarget",
"target",
"targettarget",
"targettargettarget",
"focus",
"focustarget",
"focustargettarget",
}
local UNIT_GROUPS = {
"party",
"partytarget",
"partytargettarget",
"partypet",
"partypettarget",
"partypettargettarget",
"arena",
"arenatarget",
"arenatargettarget",
"arenapet",
"arenapettarget",
"arenapettargettarget",
"raid",
"raidtarget",
"raidtargettarget",
"raidpet",
"raidpettarget",
"raidpettargettarget",
"boss",
"bosstarget",
"bosstargettarget",
}
local NORMAL_UNITS = {
"player",
"pet",
"target",
"focus",
-- "mouseover",
}
for i = 1, _G.MAX_PARTY_MEMBERS do
NORMAL_UNITS[#NORMAL_UNITS+1] = "party" .. i
NORMAL_UNITS[#NORMAL_UNITS+1] = "partypet" .. i
end
for i = 1, 5 do
NORMAL_UNITS[#NORMAL_UNITS+1] = "arena" .. i
NORMAL_UNITS[#NORMAL_UNITS+1] = "arenapet" .. i
end
for i = 1, _G.MAX_RAID_MEMBERS do
NORMAL_UNITS[#NORMAL_UNITS+1] = "raid" .. i
end
for i = 1, _G.MAX_BOSS_FRAMES do
NORMAL_UNITS[#NORMAL_UNITS+1] = "boss" .. i
end
do
local tmp = NORMAL_UNITS
NORMAL_UNITS = {}
for i, v in ipairs(tmp) do
NORMAL_UNITS[v] = true
end
tmp = nil
end
local LibSharedMedia = LibStub("LibSharedMedia-3.0", true)
local DEFAULT_LSM_FONT = "Arial Narrow"
if LibSharedMedia and not LibSharedMedia:IsValid("font", DEFAULT_LSM_FONT) then -- non-Western languages
DEFAULT_LSM_FONT = LibSharedMedia:GetDefault("font")
end
local CURRENT_CONFIG_VERSION = 5
local DATABASE_DEFAULTS = {
profile = {
addon_states_migrated = false,
lock_movement = false,
frame_snap = true,
minimap_icon = {
hide = false,
minimapPos = 200,
radius = 80,
},
units = {
['**'] = {
enabled = false,
anchor = "CENTER",
relative_to = "0", -- UIParent
relative_point = "CENTER",
position_x = 0,
position_y = 0,
size_x = 1, -- this is a multiplier
size_y = 1, -- this is a multiplier
font_multiplier = 1,
scale = 1,
layout = L["Normal"],
horizontal_mirror = false,
vertical_mirror = false,
vehicle_swap = true,
click_through = false,
tooltip = 'always',
},
},
groups = {
['**'] = {
enabled = false,
sort_method = "INDEX",
sort_direction = "ASC",
horizontal_spacing = 30,
vertical_spacing = 30,
direction = "down_right",
units_per_column = _G.MAX_RAID_MEMBERS,
unit_group = "party",
include_player = false,
group_filter = nil,
group_by = nil,
use_pet_header = nil,
anchor = "", -- automatic from growth direction
relative_to = "0", -- UIParent
relative_point = "CENTER",
position_x = 0,
position_y = 0,
size_x = 1, -- this is a multiplier
size_y = 1, -- this is a multiplier
font_multiplier = 1,
scale = 1,
layout = L["Normal"],
horizontal_mirror = false,
vertical_mirror = false,
vehicle_swap = true,
click_through = false,
tooltip = 'always',
exists = false, -- used to force the group to exist even if all values are default
show_when = {
solo = false,
party = true,
raid = false,
raid10 = false,
raid15 = false,
raid20 = false,
raid25 = false,
raid30 = false,
raid40 = false,
},
}
},
made_groups = false,
made_units = false,
group_anchors_updated = false,
layouts = {
['**'] = {
size_x = 200,
size_y = 60,
opacity_min = 0.1,
opacity_max = 1,
opacity_smooth = true,
scale = 1,
font = DEFAULT_LSM_FONT,
font_size = 1,
bar_texture = LibSharedMedia and LibSharedMedia:GetDefault("statusbar") or "Blizzard",
bar_spacing = 2,
bar_padding = 2,
indicator_spacing = 3,
indicator_size = 15,
indicator_bar_inside_horizontal_padding = 3,
indicator_bar_inside_vertical_padding = 3,
indicator_bar_outside_margin = 3,
indicator_root_inside_horizontal_padding = 2,
indicator_root_inside_vertical_padding = 5,
indicator_root_outside_margin = 5,
strata = 'MEDIUM',
level = 1, -- minimum 1, since 0 needs to be available
exists = false, -- used to force the layout to exist even if all values are default
},
},
colors = {
class = { -- filled in by RAID_CLASS_COLORS
UNKNOWN = { 204/255, 204/255, 204/255 },
},
power = { -- filled in by PowerBarColor
["PB4_ALTERNATE"] = { 0.7, 0.7, 0.6 }, -- Fallback alternate power color
},
reaction = { -- filled in by FACTION_BAR_COLORS
unknown = { 204/255, 204/255, 204/255 },
civilian = { 48/255, 113/255, 191/255 },
paragon = { 66/255, 107/255, 1 },
tapped = { 127/255, 127/255, 127/255 },
},
},
class_order = {},
role_order = { "TANK", "HEALER", "DAMAGER", "NONE" },
}
}
for class, color in pairs(_G.RAID_CLASS_COLORS) do
DATABASE_DEFAULTS.profile.colors.class[class] = { color.r, color.g, color.b }
end
for power_token, color in pairs(_G.PowerBarColor) do
if type(power_token) == "string" then
if color.r then
DATABASE_DEFAULTS.profile.colors.power[power_token] = { color.r, color.g, color.b }
end
end
end
for reaction, color in pairs(_G.FACTION_BAR_COLORS) do
DATABASE_DEFAULTS.profile.colors.reaction[reaction] = { color.r, color.g, color.b }
end
local DEFAULT_GROUPS = {
[L["Party"]] = {
enabled = true,
unit_group = "party",
exists = true,
anchor = "", -- automatic from growth direction
relative_to = "0", -- UIParent
relative_point = "TOPLEFT",
position_x = 10,
position_y = -260,
},
[L["Party pets"]] = {
-- enabled = true,
unit_group = "partypet",
exists = true,
},
[L["Boss"]] = {
enabled = true,
unit_group = "boss",
exists = true,
anchor = "", -- automatic from growth direction
relative_to = "0", -- UIParent
relative_point = "RIGHT",
position_x = -290,
position_y = 225,
show_when = {
solo = true,
party = true,
raid = true,
raid10 = true,
raid15 = true,
raid20 = true,
raid25 = true,
raid30 = true,
raid40 = true,
},
}
}
local DEFAULT_UNITS = {
[L["Player"]] = {
enabled = true,
unit = "player",
anchor = "TOPLEFT",
relative_to = "0", -- UIParent
relative_point = "TOPLEFT",
position_x = 10,
position_y = -25,
},
[L["Player's pet"]] = {
enabled = true,
unit = "pet",
anchor = "TOP",
relative_to = "SPlayer",
relative_point = "BOTTOM",
position_x = 0,
position_y = -30,
},
[format(L["%s's target"],L["Player's pet"])]= {
unit = "pettarget"
},
[L["Target"]] = {
enabled = true,
unit = "target",
anchor = "TOPLEFT",
relative_to = "0", -- UIParent
relative_point = "TOPLEFT",
position_x = 250,
position_y = -25,
},
[format(L["%s's target"],L["Target"])] = {
enabled = true,
unit = "targettarget",
anchor = "LEFT",
relative_to = "STarget",
relative_point = "RIGHT",
position_x = 0,
position_y = 0,
},
[format(L["%s's target"],format(L["%s's target"],L["Target"]))] = {
unit = "targettargettarget",
},
[L["Focus"]] = {
enabled = true,
unit = "focus",
anchor = "TOPLEFT",
relative_to = "0", -- UIParent
relative_point = "TOPLEFT",
position_x = 250,
position_y = -260,
},
[format(L["%s's target"],L["Focus"])]= {
unit = "focustarget",
},
[format(L["%s's target"],format(L["%s's target"],L["Focus"]))] = {
unit = "focustargettarget",
},
}
local LOCALIZED_NAMES = {}
do
for i = 1, GetNumClasses() do
local info = C_CreatureInfo.GetClassInfo(i)
LOCALIZED_NAMES[info.classFile] = info.className
end
for i = 1, 77 do
local info = C_CreatureInfo.GetRaceInfo(i)
if info and not LOCALIZED_NAMES[info.clientFileString] then
LOCALIZED_NAMES[info.clientFileString] = info.raceName
end
end
setmetatable(LOCALIZED_NAMES, { __index = function(self, key)
self[key] = key
return key
end })
end
-----------------------------------------------------------------------------
local _, PitBull4 = ...
PitBull4 = LibStub("AceAddon-3.0"):NewAddon(PitBull4, "PitBull4", "AceEvent-3.0", "AceTimer-3.0")
_G.PitBull4 = PitBull4
local DEBUG = PitBull4.DEBUG
local expect = PitBull4.expect
PitBull4.version = "@project-version@"
if PitBull4.version:match("@") then
PitBull4.version = "Development"
end
PitBull4.L = L
PitBull4.SINGLETON_CLASSIFICATIONS = SINGLETON_CLASSIFICATIONS
PitBull4.UNIT_GROUPS = UNIT_GROUPS
PitBull4.LOCALIZED_NAMES = LOCALIZED_NAMES
local db
if not _G.ClickCastFrames then
-- for click-to-cast addons
_G.ClickCastFrames = {}
end
do
-- unused tables go in this set
-- if the garbage collector comes around, they'll be collected properly
local cache = setmetatable({}, {__mode='k'})
--- Return a table
-- @usage local t = PitBull4.new()
-- @return a blank table
function PitBull4.new()
local t = next(cache)
if t then
cache[t] = nil
return t
end
return {}
end
local wipe = _G.wipe
--- Delete a table, clearing it and putting it back into the queue
-- @usage local t = PitBull4.new()
-- t = del(t)
-- @return nil
function PitBull4.del(t)
if DEBUG then
expect(t, 'typeof', 'table')
expect(t, 'not_inset', cache)
end
wipe(t)
cache[t] = true
return nil
end
end
local do_nothing = function() end
local new, del = PitBull4.new, PitBull4.del
-- A set of all unit frames
local all_frames = {}
PitBull4.all_frames = all_frames
-- A list of all unit frames
local all_frames_list = {}
PitBull4.all_frames_list = all_frames_list
-- A set of all unit frames with the is_wacky flag set to true
local wacky_frames = {}
PitBull4.wacky_frames = wacky_frames
PitBull4.num_wacky_frames = 0
-- A set of all unit frames with the is_wacky flag set to false
local non_wacky_frames = {}
PitBull4.non_wacky_frames = non_wacky_frames
-- A set of all unit frames with the is_singleton flag set to true
local singleton_frames = {}
PitBull4.singleton_frames = singleton_frames
-- A set of all unit frames with the is_singleton flag set to false
local member_frames = {}
PitBull4.member_frames = member_frames
-- A set of all group headers
local all_headers = {}
PitBull4.all_headers = all_headers
-- metatable that automatically creates keys that return tables on access
local auto_table__mt = {__index = function(self, key)
if key == nil then
return nil
end
local value = {}
self[key] = value
return value
end}
-- A dictionary of UnitID to a set of all unit frames of that UnitID
local unit_id_to_frames = setmetatable({}, auto_table__mt)
PitBull4.unit_id_to_frames = unit_id_to_frames
-- A dictionary of UnitID to a set of all unit frames of that UnitID, plus wacky frames that are the same unit.
local unit_id_to_frames_with_wacky = setmetatable({}, auto_table__mt)
PitBull4.unit_id_to_frames_with_wacky = unit_id_to_frames_with_wacky
-- A dictionary of classification to a set of all unit frames of that classification
local classification_to_frames = setmetatable({}, auto_table__mt)
PitBull4.classification_to_frames = classification_to_frames
-- A dictionary of unit group to a set of all group headers of that unit group
local unit_group_to_headers = setmetatable({}, auto_table__mt)
PitBull4.unit_group_to_headers = unit_group_to_headers
-- A dictionary of super-unit group to a set of all group headers of that super-unit group
local super_unit_group_to_headers = setmetatable({}, auto_table__mt)
PitBull4.super_unit_group_to_headers = super_unit_group_to_headers
local name_to_header = {}
PitBull4.name_to_header = name_to_header
-- A dictionary of UnitID to GUID for non-wacky units
local unit_id_to_guid = {}
PitBull4.unit_id_to_guid = unit_id_to_guid
-- A dictionary of GUID to a set of UnitIDs for non-wacky units
local guid_to_unit_ids = {}
PitBull4.guid_to_unit_ids = guid_to_unit_ids
-- A list of frames that need to be anchored because their relative frame
-- did not exist when we tried to anchor them. The key is the frame and the
-- value is the relative_to value, see the documentation for Utils.GetRelativeFrame()
-- for the details of the relative_to value.
local frames_to_anchor = {}
PitBull4.frames_to_anchor = frames_to_anchor
local function get_best_unit(guid)
if not guid then
return nil
end
local guid_to_unit_ids__guid = guid_to_unit_ids[guid]
if not guid_to_unit_ids__guid then
return nil
end
return (next(guid_to_unit_ids__guid))
end
PitBull4.get_best_unit = get_best_unit
local function refresh_guid(unit,new_guid)
if not NORMAL_UNITS[unit] then
return
end
local old_guid = unit_id_to_guid[unit]
if new_guid == old_guid then
return
end
unit_id_to_guid[unit] = new_guid
if old_guid then
local guid_to_unit_ids__old_guid = guid_to_unit_ids[old_guid]
guid_to_unit_ids__old_guid[unit] = nil
if not next(guid_to_unit_ids__old_guid) then
guid_to_unit_ids[old_guid] = del(guid_to_unit_ids__old_guid)
end
end
if new_guid then
local guid_to_unit_ids__new_guid = guid_to_unit_ids[new_guid]
if not guid_to_unit_ids__new_guid then
guid_to_unit_ids__new_guid = new()
guid_to_unit_ids[new_guid] = guid_to_unit_ids__new_guid
end
guid_to_unit_ids__new_guid[unit] = true
end
for frame in PitBull4:IterateWackyFrames() do
if frame.best_unit == unit or frame.guid == new_guid then
frame:UpdateBestUnit()
end
end
end
local function refresh_all_guids()
for unit in pairs(NORMAL_UNITS) do
local guid = UnitGUID(unit)
refresh_guid(unit,guid)
end
end
--- Wrap the given function so that any call to it will be piped through PitBull4:RunOnLeaveCombat.
-- @param func function to call
-- @usage myFunc = PitBull4:OutOfCombatWrapper(func)
-- @usage MyNamespace.MyMethod = PitBull4:OutOfCombatWrapper(MyNamespace.MyMethod)
-- @return the wrapped function
function PitBull4:OutOfCombatWrapper(func)
if DEBUG then
expect(func, 'typeof', 'function')
end
return function(...)
return PitBull4:RunOnLeaveCombat(func, ...)
end
end
-- iterate through a set of frames and return those that are shown
local function iterate_shown_frames(set, frame)
frame = next(set, frame)
if frame == nil then
return
end
if frame:IsShown() then
return frame
end
return iterate_shown_frames(set, frame)
end
-- iterate through a set of headers and return those that have a group_db set
local function iterate_used_headers(set, header)
header = next(set, header)
if header == nil then
return
end
if header.group_db then
return header
end
return iterate_used_headers(set, header)
end
-- iterate through and return only the keys of a table
local function half_next(set, key)
key = next(set, key)
if key == nil then
return nil
end
return key
end
-- iterate through and return only the keys of a table. Once exhausted, recycle the table.
local function half_next_with_del(set, key)
key = next(set, key)
if key == nil then
del(set)
return nil
end
return key
end
--- Iterate over all frames.
-- This iterates over only shown frames unless also_hidden is passed in.
-- @param also_hidden also return frames that are hidden
-- @usage for frame in PitBull4:IterateFrames() do
-- doSomethingWith(frame)
-- end
-- @usage for frame in PitBull4:IterateFrames(true) do
-- doSomethingWith(frame)
-- end
-- @return iterator which returns frames
function PitBull4:IterateFrames(also_hidden)
if DEBUG then
expect(also_hidden, 'typeof', 'boolean;nil')
end
return not also_hidden and iterate_shown_frames or half_next, all_frames
end
--- Iterate over all wacky frames.
-- This iterates over only shown frames unless also_hidden is passed in.
-- @param also_hidden also return frames that are hidden
-- @usage for frame in PitBull4:IterateWackyFrames() do
-- doSomethingWith(frame)
-- end
-- @usage for frame in PitBull4:IterateWackyFrames(true) do
-- doSomethingWith(frame)
-- end
-- @return iterator which returns frames
function PitBull4:IterateWackyFrames(also_hidden)
if DEBUG then
expect(also_hidden, 'typeof', 'boolean;nil')
end
return not also_hidden and iterate_shown_frames or half_next, wacky_frames
end
--- Iterate over all non-wacky frames.
-- This iterates over only shown frames unless also_hidden is passed in.
-- @param also_hidden also return frames that are hidden
-- @usage for frame in PitBull4:IterateNonWackyFrames() do
-- doSomethingWith(frame)
-- end
-- @usage for frame in PitBull4:IterateNonWackyFrames(true) do
-- doSomethingWith(frame)
-- end
-- @return iterator which returns frames
function PitBull4:IterateNonWackyFrames(also_hidden, only_non_wacky)
if DEBUG then
expect(also_hidden, 'typeof', 'boolean;nil')
end
return not also_hidden and iterate_shown_frames or half_next, non_wacky_frames
end
--- Iterate over all singleton frames.
-- This iterates over only shown frames unless also_hidden is passed in.
-- @param also_hidden also return frames that are hidden
-- @usage for frame in PitBull4:IterateSingletonFrames() do
-- doSomethingWith(frame)
-- end
-- @usage for frame in PitBull4:IterateSingletonFrames(true) do
-- doSomethingWith(frame)
-- end
-- @return iterator which returns frames
function PitBull4:IterateSingletonFrames(also_hidden)
if DEBUG then
expect(also_hidden, 'typeof', 'boolean;nil')
end
return not also_hidden and iterate_shown_frames or half_next, singleton_frames
end
--- Iterate over all member frames.
-- This iterates over only shown frames unless also_hidden is passed in.
-- @param also_hidden also return frames that are hidden
-- @usage for frame in PitBull4:IterateNonWackyFrames() do
-- doSomethingWith(frame)
-- end
-- @usage for frame in PitBull4:IterateNonWackyFrames(true) do
-- doSomethingWith(frame)
-- end
-- @return iterator which returns frames
function PitBull4:IterateMemberFrames(also_hidden)
if DEBUG then
expect(also_hidden, 'typeof', 'boolean;nil')
end
return not also_hidden and iterate_shown_frames or half_next, member_frames
end
--- Iterate over all frames with the given unit ID
-- This iterates over only shown frames unless also_hidden is passed in.
-- @param unit the UnitID of the unit in question
-- @param also_hidden also return frames that are hidden
-- @param dont_include_wacky don't include wacky frames that are the same unit
-- @usage for frame in PitBull4:IterateFramesForUnitID("player") do
-- doSomethingWith(frame)
-- end
-- @usage for frame in PitBull4:IterateFramesForUnitID("party1", true) do
-- doSomethingWith(frame)
-- end
-- @usage for frame in PitBull4:IterateFramesForUnitID("party1", false, true) do
-- doSomethingWith(frame)
-- end
-- @return iterator which returns frames
function PitBull4:IterateFramesForUnitID(unit, also_hidden, dont_include_wacky)
if DEBUG then
expect(unit, 'typeof', 'string')
expect(also_hidden, 'typeof', 'boolean;nil')
expect(dont_include_wacky, 'typeof', 'boolean;nil')
end
local id = PitBull4.Utils.GetBestUnitID(unit)
if not id then
if DEBUG then
error(("Bad argument #1 to `IterateFramesForUnitID'. %q is not a valid UnitID"):format(tostring(unit)), 2)
else
return function () end
end
end
return not also_hidden and iterate_shown_frames or half_next, (not dont_include_wacky and unit_id_to_frames_with_wacky or unit_id_to_frames)[id]
end
--- Iterate over all shown frames with the given UnitIDs.
-- To iterate over hidden frames as well, pass in true as the last argument.
-- @param ... a tuple of UnitIDs.
-- @usage for frame in PitBull4:IterateFramesForUnitIDs("player", "target", "pet") do
-- somethingAwesome(frame)
-- end
-- @usage for frame in PitBull4:IterateFramesForUnitIDs("player", "target", "pet", true) do
-- somethingAwesome(frame)
-- end
-- @return iterator which returns frames
function PitBull4:IterateFramesForUnitIDs(...)
local t = new()
local n = select('#', ...)
local also_hidden = ((select(n, ...)) == true)
if also_hidden then
n = n - 1
end
for i = 1, n do
local unit = (select(i, ...))
local frames = unit_id_to_frames_with_wacky[unit]
for frame in pairs(frames) do
if also_hidden or frame:IsShown() then
t[frame] = true
end
end
end
return half_next_with_del, t
end
--- Iterate over all frames with the given classification.
-- This iterates over only shown frames unless also_hidden is passed in.
-- @param classification the classification to check
-- @param also_hidden also return frames that are hidden
-- @usage for frame in PitBull4:IterateFramesForClassification("player") do
-- doSomethingWith(frame)
-- end
-- @usage for frame in PitBull4:IterateFramesForClassification("party", true) do
-- doSomethingWith(frame)
-- end
-- @return iterator which returns frames
function PitBull4:IterateFramesForClassification(classification, also_hidden)
if DEBUG then
expect(classification, 'typeof', 'string')
expect(also_hidden, 'typeof', 'boolean;nil')
end
local frames = rawget(classification_to_frames, classification)
if not frames then
return do_nothing
end
return not also_hidden and iterate_shown_frames or half_next, frames
end
local function layout_iter(layout, frame)
frame = next(all_frames, frame)
if not frame then
return nil
end
if frame.layout == layout then
return frame
end
return layout_iter(layout, frame)
end
local function layout_shown_iter(layout, frame)
frame = next(all_frames, frame)
if not frame then
return nil
end
if frame.layout == layout and frame:IsShown() then
return frame
end
return layout_iter(layout, frame)
end
--- Iterate over all frames with the given layout.
-- This iterates over only shown frames unless also_hidden is passed in.
-- @param layout the layout to check
-- @param also_hidden also return frames that are hidden
-- @usage for frame in PitBull4:IterateFramesForLayout("Normal") do
-- frame:UpdateLayout()
-- end
-- @usage for frame in PitBull4:IterateFramesForLayout("Normal", true) do
-- frame:UpdateLayout()
-- end
-- @return iterator which returns frames
function PitBull4:IterateFramesForLayout(layout, also_hidden)
if DEBUG then
expect(layout, 'typeof', 'string')
expect(also_hidden, 'typeof', 'boolean;nil')
end
return not also_hidden and layout_shown_iter or layout_iter, layout
end
--- call :Update() on all frames with the given layout
-- @param layout the layout to check
-- @usage PitBull4:UpdateForLayout("Normal")
function PitBull4:UpdateForLayout(layout)
for frame in self:IterateFramesForLayout(layout) do
frame:Update(true, true)
end
end
local function guid_iter(guid, frame)
frame = next(all_frames, frame)
if not frame then
return nil
end
if frame.guid == guid then
return frame
end
return guid_iter(guid, frame)
end
--- Iterate over all frames with the given GUID
-- @param guid the GUID to check. can be nil, which will cause no frames to return.
-- @usage for frame in PitBull4:IterateFramesForGUID("0x0000000000071278") do
-- doSomethingWith(frame)
-- end
-- @return iterator which returns frames
function PitBull4:IterateFramesForGUID(guid)
if DEBUG then
expect(guid, 'typeof', 'string;nil')
end
if not guid then
return do_nothing
end
return guid_iter, guid, nil
end
local function guids_iter(guids, frame)
frame = next(all_frames, frame)
if not frame then
del(guids)
return nil
end
if guids[frame.guid] then
return frame
end
return guids_iter(guids, frame)
end
--- Iterate over all frames with the given GUIDs
-- @param ... the GUIDs to check. Can be nil.
-- @usage for frame in PitBull4:IterateFramesForGUIDs(UnitGUID) do
-- doSomethingWith(frame)
-- end
-- @return iterator which returns frames
function PitBull4:IterateFramesForGUIDs(...)
local guids = new()
for i = 1, select('#', ...) do
local guid = (select(i, ...))
if DEBUG then
expect(guid, 'typeof', 'string;nil')
end
if guid then
guids[guid] = true
end
end
if not next(guids) then
guids = del(guids)
return do_nothing
end
return guids_iter, guids, nil
end
local function name_iter(state, frame)
frame = next(all_frames, frame)
if not frame then
return nil
end
local name,server = state.name, state.server
if frame.guid and frame.unit then
local frame_name, frame_server = UnitName(frame.unit)
if frame_name == name and (not server and server ~= "" or server == frame_server) then
return frame
end
end
return name_iter(state, frame)
end
local state = {}
--- Iterate over all frames with the given name
-- @param name the name to check. can be nil, which will cause no frames to return.
-- @param server the name of the realm, can be nil, which will cause only the name to be matched.
-- @usage for frame in PitBull4:IterateFramesForName("Someguy") do
-- doSomethingWith(frame)
-- end
-- @return iterator which returns frames
function PitBull4:IterateFramesForName(name,server)
if DEBUG then
expect(name, 'typeof', 'string;nil')
end
if not name then
return do_nothing
end
state.name = name
state.server = server
return name_iter, state, nil
end
--- Iterate over all headers.
-- @param also_unused also return headers unused by the current profile.
-- @usage for header in PitBull4:IterateHeaders()
-- doSomethingWith(header)
-- end
-- @return iterator which returns headers
function PitBull4:IterateHeaders(also_unused)
return not also_unused and iterate_used_headers or half_next, all_headers
end
--- Iterate over all headers with the given classification.
-- @param unit_group the unit group to check
-- @usage for header in PitBull4:IterateHeadersForUnitGroup("party")
-- doSomethingWith(header)
-- end
-- @return iterator which returns headers
function PitBull4:IterateHeadersForUnitGroup(unit_group)
if DEBUG then
expect(unit_group, 'typeof', 'string')
end
local headers = rawget(unit_group_to_headers, unit_group)
if not headers then
return do_nothing
end
return iterate_shown_frames, headers
end
--- Iterate over all headers with the given super-classification.
-- @param super_unit_group the super-unit group to check. This can be "party" or "raid"
-- @usage for header in PitBull4:IterateHeadersForSuperUnitGroup("party")
-- doSomethingWith(header)
-- end
-- @return iterator which returns headers
function PitBull4:IterateHeadersForSuperUnitGroup(super_unit_group)
if DEBUG then
expect(super_unit_group, 'typeof', 'string')
expect(super_unit_group, 'inset', 'party;raid;boss;arena')
end
local headers = rawget(super_unit_group_to_headers, super_unit_group)
if not headers then
return do_nothing
end
return iterate_shown_frames, headers
end
local function return_same(object, key)
if key then
return nil
else
return object
end
end
--- Iterate over all headers with the given name.
-- @param name the name to check
-- @usage for header in PitBull4:IterateHeadersForName("Party pets")
-- doSomethingWith(header)
-- end
-- @return iterator which returns zero or one header