-
Notifications
You must be signed in to change notification settings - Fork 93
/
AllTheThings.lua
11322 lines (10849 loc) · 389 KB
/
AllTheThings.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
--------------------------------------------------------------------------------
-- A L L T H E T H I N G S --
--------------------------------------------------------------------------------
-- Copyright 2017-2024 Dylan Fortune (Crieve-Sargeras) --
--------------------------------------------------------------------------------
-- App locals
local appName, app = ...;
local L = app.L;
local AssignChildren, CloneClassInstance, GetRelativeValue = app.AssignChildren, app.CloneClassInstance, app.GetRelativeValue;
local IsQuestFlaggedCompleted = app.IsQuestFlaggedCompleted
-- Abbreviations
L.ABBREVIATIONS[L.UNSORTED .. " %> " .. L.UNSORTED] = "|T" .. app.asset("WindowIcon_Unsorted") .. ":0|t " .. L.SHORTTITLE .. " %> " .. L.UNSORTED;
-- Binding Localizations
BINDING_HEADER_ALLTHETHINGS = L.TITLE
BINDING_NAME_ALLTHETHINGS_TOGGLEACCOUNTMODE = L.TOGGLE_ACCOUNT_MODE
BINDING_NAME_ALLTHETHINGS_TOGGLECOMPLETIONISTMODE = L.TOGGLE_COMPLETIONIST_MODE
BINDING_NAME_ALLTHETHINGS_TOGGLEDEBUGMODE = L.TOGGLE_DEBUG_MODE
BINDING_NAME_ALLTHETHINGS_TOGGLEFACTIONMODE = L.TOGGLE_FACTION_MODE
BINDING_NAME_ALLTHETHINGS_TOGGLELOOTMODE = L.TOGGLE_LOOT_MODE
BINDING_HEADER_ALLTHETHINGS_PREFERENCES = PREFERENCES
BINDING_NAME_ALLTHETHINGS_TOGGLECOMPLETEDTHINGS = L.TOGGLE_COMPLETEDTHINGS
BINDING_NAME_ALLTHETHINGS_TOGGLECOMPLETEDGROUPS = L.TOGGLE_COMPLETEDGROUPS
BINDING_NAME_ALLTHETHINGS_TOGGLECOLLECTEDTHINGS = L.TOGGLE_COLLECTEDTHINGS
BINDING_NAME_ALLTHETHINGS_TOGGLEBOEITEMS = L.TOGGLE_BOEITEMS
BINDING_NAME_ALLTHETHINGS_TOGGLESOURCETEXT = L.TOGGLE_SOURCETEXT
BINDING_HEADER_ALLTHETHINGS_MODULES = L.MODULES
BINDING_NAME_ALLTHETHINGS_TOGGLEMAINLIST = L.TOGGLE_MAINLIST
BINDING_NAME_ALLTHETHINGS_TOGGLEMINILIST = L.TOGGLE_MINILIST
BINDING_NAME_ALLTHETHINGS_TOGGLE_PROFESSION_LIST = L.TOGGLE_PROFESSION_LIST
BINDING_NAME_ALLTHETHINGS_TOGGLE_RAID_ASSISTANT = L.TOGGLE_RAID_ASSISTANT
BINDING_NAME_ALLTHETHINGS_TOGGLE_WORLD_QUESTS_LIST = L.TOGGLE_WORLD_QUESTS_LIST
BINDING_NAME_ALLTHETHINGS_TOGGLERANDOM = L.TOGGLE_RANDOM
BINDING_NAME_ALLTHETHINGS_REROLL_RANDOM = L.REROLL_RANDOM
-- Performance Cache
local print, rawget, rawset, tostring, ipairs, pairs, tonumber, wipe, select, setmetatable, getmetatable, tinsert, tremove, type, math_floor
= print, rawget, rawset, tostring, ipairs, pairs, tonumber, wipe, select, setmetatable, getmetatable, tinsert, tremove, type, math.floor
-- Global WoW API Cache
local C_Map_GetMapInfo = C_Map.GetMapInfo;
local InCombatLockdown = _G.InCombatLockdown;
local IsInInstance = IsInInstance
-- WoW API Cache
local GetFactionName = app.WOWAPI.GetFactionName;
local GetItemInfo = app.WOWAPI.GetItemInfo;
local GetItemID = app.WOWAPI.GetItemID;
local GetSpellName = app.WOWAPI.GetSpellName;
local GetTradeSkillTexture = app.WOWAPI.GetTradeSkillTexture;
local C_TradeSkillUI = C_TradeSkillUI;
local C_TradeSkillUI_GetCategories, C_TradeSkillUI_GetCategoryInfo, C_TradeSkillUI_GetRecipeInfo, C_TradeSkillUI_GetRecipeSchematic, C_TradeSkillUI_GetTradeSkillLineForRecipe
= C_TradeSkillUI.GetCategories, C_TradeSkillUI.GetCategoryInfo, C_TradeSkillUI.GetRecipeInfo, C_TradeSkillUI.GetRecipeSchematic, C_TradeSkillUI.GetTradeSkillLineForRecipe;
-- App & Module locals
local ArrayAppend = app.ArrayAppend
local CacheFields, SearchForField, SearchForFieldContainer, SearchForObject
= app.CacheFields, app.SearchForField, app.SearchForFieldContainer, app.SearchForObject
local IsRetrieving = app.Modules.RetrievingData.IsRetrieving;
local GetProgressColorText = app.Modules.Color.GetProgressColorText;
local TryColorizeName = app.TryColorizeName;
local DESCRIPTION_SEPARATOR = app.DESCRIPTION_SEPARATOR;
local GetDisplayID = app.GetDisplayID
local ATTAccountWideData;
-- Color Lib
local GetProgressColor = app.Modules.Color.GetProgressColor;
local Colorize = app.Modules.Color.Colorize;
-- Coroutine Helper Functions
local Push = app.Push;
local StartCoroutine = app.StartCoroutine;
local Callback = app.CallbackHandlers.Callback;
local DelayedCallback = app.CallbackHandlers.DelayedCallback;
local AfterCombatCallback = app.CallbackHandlers.AfterCombatCallback;
app.UpdateRunner = app.CreateRunner("update");
app.FillRunner = app.CreateRunner("fill");
local LocalizeGlobal = app.LocalizeGlobal
local LocalizeGlobalIfAllowed = app.LocalizeGlobalIfAllowed
local contains = app.contains;
local containsValue = app.containsValue;
local indexOf = app.indexOf;
local CloneArray = app.CloneArray
-- Data Lib
local AllTheThingsAD = {}; -- For account-wide data.
local function formatNumericWithCommas(amount)
local k
while true do
amount, k = tostring(amount):gsub("^(-?%d+)(%d%d%d)", '%1,%2')
if k == 0 then
break
end
end
return amount
end
local function GetMoneyString(amount)
if amount > 0 then
local formatted
local gold,silver,copper = math_floor(amount / 100 / 100), math_floor((amount / 100) % 100), math_floor(amount % 100)
if gold > 0 then
formatted = formatNumericWithCommas(gold) .. "|T237618:0|t"
end
if silver > 0 then
formatted = (formatted or "") .. silver .. "|T237620:0|t"
end
if copper > 0 then
formatted = (formatted or "") .. copper .. "|T237617:0|t"
end
return formatted
end
return amount
end
do -- TradeSkill Functionality
local tradeSkillSpecializationMap = app.SkillDB.Specializations
local specializationTradeSkillMap = app.SkillDB.BaseSkills
local tradeSkillMap = app.SkillDB.Conversion
-- this is still required by Shared Modules
app.SkillIDToSpellID = app.SkillDB.SkillToSpell
local function GetBaseTradeSkillID(skillID)
return tradeSkillMap[skillID] or skillID;
end
local function GetTradeSkillSpecialization(skillID)
return tradeSkillSpecializationMap[skillID];
end
app.GetTradeSkillLine = function()
local profInfo = C_TradeSkillUI.GetBaseProfessionInfo();
return GetBaseTradeSkillID(profInfo.professionID);
end
app.GetSpecializationBaseTradeSkill = function(specializationID)
return specializationTradeSkillMap[specializationID];
end
-- Refreshes the known Trade Skills/Professions of the current character (app.CurrentCharacter.Professions)
local function RefreshTradeSkillCache()
local cache = app.CurrentCharacter.Professions;
wipe(cache);
-- "Professions" that anyone can "know"
for _,skillID in ipairs(app.SkillDB.AlwaysAvailable) do
cache[skillID] = true
end
-- app.PrintDebug("RefreshTradeSkillCache");
local prof1, prof2, archaeology, fishing, cooking, firstAid = GetProfessions();
for i,j in ipairs({prof1 or 0, prof2 or 0, archaeology or 0, fishing or 0, cooking or 0, firstAid or 0}) do
if j ~= 0 then
local prof = select(7, GetProfessionInfo(j));
cache[GetBaseTradeSkillID(prof)] = true;
-- app.PrintDebug("KnownProfession",j,GetProfessionInfo(j));
local specializations = GetTradeSkillSpecialization(prof);
if specializations ~= nil then
for _,spellID in pairs(specializations) do
if spellID and app.IsSpellKnownHelper(spellID) then
cache[spellID] = true;
end
end
end
end
end
end
app.AddEventHandler("OnStartup", RefreshTradeSkillCache)
app.AddEventHandler("OnStartup", function()
local conversions = app.Settings.InformationTypeConversionMethods;
conversions.professionName = function(skillID)
local texture = GetTradeSkillTexture(skillID or 0)
local name = GetSpellName(app.SkillDB.SkillToSpell[skillID] or 0) or C_TradeSkillUI.GetTradeSkillDisplayName(skillID) or RETRIEVING_DATA
return texture and "|T"..texture..":0|t "..name or name
end;
end);
app.AddEventRegistration("SKILL_LINES_CHANGED", function()
-- app.PrintDebug("SKILL_LINES_CHANGED")
-- seems to be a reliable way to notice a player has changed professions? not sure how else often it actually triggers... hopefully not too excessive...
DelayedCallback(RefreshTradeSkillCache, 2);
end)
end -- TradeSkill Functionality
local function GetCollectibleIcon(data, iconOnly)
if data.collectible then
local collected = data.collected
if not collected and data.collectedwarband then
return iconOnly and L.COLLECTED_WARBAND_ICON or L.COLLECTED_WARBAND;
end
return iconOnly and app.GetCollectionIcon(collected) or app.GetCollectionText(collected);
end
end
local function GetTrackableIcon(data, iconOnly, forSaved)
if data.trackable then
local saved = data.saved;
-- only show if the data is saved, or is not repeatable
if saved or not rawget(data, "repeatable") then
if forSaved then
-- if for saved, we ignore if it is un-saved for less clutter
if saved then
return iconOnly and app.GetCompletionIcon(saved) or app.GetSavedText(saved);
end
else
return iconOnly and app.GetCompletionIcon(saved) or app.GetCompletionText(saved);
end
end
end
end
local function GetCostIconForRow(data, iconOnly)
-- cost only for filled groups, or if itself is a cost
if data.filledCost or data.isCost or (data.progress == data.total and ((data.costTotal or 0) > 0)) then
return L[iconOnly and "COST_ICON" or "COST_TEXT"];
end
end
local function GetCostIconForTooltip(data, iconOnly)
-- cost only if itself is a cost
if data.filledCost or data.collectibleAsCost then
return L[iconOnly and "COST_ICON" or "COST_TEXT"];
end
end
local function GetUpgradeIconForRow(data, iconOnly)
-- upgrade only for filled groups, or if itself is an upgrade
if data.filledUpgrade or data.isUpgrade or (data.progress == data.total and ((data.upgradeTotal or 0) > 0)) then
return L[iconOnly and "UPGRADE_ICON" or "UPGRADE_TEXT"];
end
end
local function GetUpgradeIconForTooltip(data, iconOnly)
-- upgrade only if itself has an upgrade
if data.filledUpgrade or data.collectibleAsUpgrade then
return L[iconOnly and "UPGRADE_ICON" or "UPGRADE_TEXT"];
end
end
local function GetReagentIcon(data, iconOnly)
if data.filledReagent then
return L[iconOnly and "REAGENT_ICON" or "REAGENT_TEXT"];
end
end
local function GetProgressTextForRow(data)
-- build the row text from left to right with possible info
local text = {}
-- Reagent (show reagent icon)
local icon = GetReagentIcon(data, true);
if icon then
tinsert(text, icon)
end
-- Cost (show cost icon)
icon = GetCostIconForRow(data, true);
if icon then
tinsert(text, icon)
end
-- Upgrade (show upgrade icon)
icon = GetUpgradeIconForRow(data, true);
if icon then
tinsert(text, icon)
end
-- Progress Achievement
local statistic = data.statistic
if statistic then
tinsert(text, "["..statistic.."]")
end
-- Collectible
local stateIcon = GetCollectibleIcon(data, true)
if stateIcon then
tinsert(text, stateIcon)
end
-- Container
local total = data.total;
local isContainer = total and (total > 1 or (total > 0 and not data.collectible));
if isContainer then
local textContainer = GetProgressColorText(data.progress or 0, total)
tinsert(text, textContainer)
end
-- Non-collectible/total Container (only contains visible, non-collectibles...)
local g = data.g;
if not stateIcon and not isContainer and g and #g > 0 then
local headerText;
if data.expanded then
headerText = "---";
else
headerText = "+++";
end
tinsert(text, headerText)
end
-- Trackable (Only if no other text available)
if #text == 0 then
stateIcon = GetTrackableIcon(data, true)
if stateIcon then
tinsert(text, stateIcon)
end
end
return app.TableConcat(text, nil, "", " ");
end
local function GetProgressTextForTooltip(data)
-- build the row text from left to right with possible info
local text = {}
local iconOnly = app.Settings:GetTooltipSetting("ShowIconOnly");
-- Reagent (show reagent icon)
local icon = GetReagentIcon(data, iconOnly);
if icon then
tinsert(text, icon)
end
-- Cost (show cost icon)
icon = GetCostIconForTooltip(data, iconOnly);
if icon then
tinsert(text, icon)
end
-- Upgrade (show upgrade icon)
icon = GetUpgradeIconForTooltip(data, iconOnly);
if icon then
tinsert(text, icon)
end
-- Progress Achievement (this is a bit redundant with the 'Progress' information type for tooltips)
-- local statistic = data.statistic
-- if statistic then
-- tinsert(text, "["..statistic.."]")
-- end
-- Collectible
local stateIcon = GetCollectibleIcon(data, iconOnly)
if stateIcon then
tinsert(text, stateIcon)
end
-- Saved (only certain data types)
if data.npcID then
stateIcon = GetTrackableIcon(data, iconOnly, true)
if stateIcon then
tinsert(text, stateIcon)
end
end
-- Container
local total = data.total;
local isContainer = total and (total > 1 or (total > 0 and not data.collectible));
if isContainer then
local textContainer = GetProgressColorText(data.progress or 0, total)
if textContainer then
tinsert(text, textContainer)
end
end
-- Trackable (Only if no other text available)
if #text == 0 then
stateIcon = GetTrackableIcon(data, iconOnly)
if stateIcon then
tinsert(text, stateIcon)
end
end
return app.TableConcat(text, nil, "", " ");
end
app.GetProgressTextForRow = GetProgressTextForRow;
app.GetProgressTextForTooltip = GetProgressTextForTooltip;
-- Fields which are dynamic or pertain only to the specific ATT window and should never merge automatically
-- Maybe build from /base.lua:DefaultFields since those always are able to be dynamic
app.MergeSkipFields = {
-- true -> never
expanded = true,
indent = true,
g = true,
nmr = true,
nmc = true,
progress = true,
total = true,
visible = true,
modItemID = true,
rawlink = true,
sourceIgnored = true,
isCost = true,
costTotal = true,
isUpgrade = true,
upgradeTotal = true,
iconPath = true,
hash = true,
sharedDescription = true,
-- fields added to a group from GetSearchResults
tooltipInfo = true,
working = true,
-- update cached info
TLUG = true,
-- 1 -> only when cloning
e = 1,
u = 1,
c = 1,
up = 1,
pb = 1,
pvp = 1,
races = 1,
isDaily = 1,
isWeekly = 1,
isMonthly = 1,
isYearly = 1,
OnUpdate = 1,
requireSkill = 1,
modID = 1,
bonusID = 1,
};
-- Fields on a Thing which are specific to where the Thing is Sourced or displayed in a ATT window
app.SourceSpecificFields = {
-- Returns the 'most obtainable' event value from the provided set of event values
["e"] = function(...)
-- print("GetMostObtainableValue:")
-- app.PrintTable(vals)
local e;
local vals = select("#", ...);
for i=1,vals do
e = select(i, ...);
-- missing e value means NOT requiring an event
if not e then return; end
end
return e;
end,
-- Returns the 'most obtainable' unobtainable value from the provided set of unobtainable values
["u"] = function(...)
-- app.PrintDebug("GetMostObtainableValue:")
local max, check, new = -1, nil, nil;
local phases = L.PHASES;
local phase, u;
local vals = select("#", ...);
-- app.PrintDebug(...)
for i=1,vals do
u = select(i, ...);
-- missing u value means NOT unobtainable
if not u then return; end
phase = phases[u];
if phase then
check = phase.state or 0;
else
-- otherwise it's an invalid unobtainable filter
app.print("Invalid Unobtainable Filter:",u);
return;
end
-- track the highest unobtainable value, which is the most obtainable (according to PHASES)
if check > max then
new = u;
max = check;
elseif u > new then
new = u
end
end
-- app.PrintDebug("new:",new)
return new;
end,
-- Returns the 'highest' Removed with Patch value from the provided set of `rwp` values
["rwp"] = function(...)
local max, rwp = -1,nil;
local vals = select("#", ...);
for i=1,vals do
rwp = select(i, ...);
-- missing rwp value means NOT removed
if not rwp then return; end
-- track the highest rwp value, which is the furthest-future patch
if rwp > max then
max = rwp;
end
end
-- print("max:",max)
return max;
end,
-- Simple boolean
["pvp"] = true,
["pb"] = true,
["requireSkill"] = true,
};
-- Merges the properties of the t group into the g group, making sure not to alter the filterability of the group.
-- Additionally can specify that the object is being cloned so as to skip special merge restrictions
local function MergeProperties(g, t, noReplace, clone)
if g and t then
if g ~= t then
g.__merge = t
end
local skips = app.MergeSkipFields;
if noReplace then
for k,v in pairs(t) do
-- certain keys should never transfer to the merge group directly
if k == "parent" then
if not rawget(g, "sourceParent") then
g.sourceParent = v;
end
elseif not skips[k] then
if rawget(g, k) == nil then
g[k] = v;
end
end
end
elseif clone then
for k,v in pairs(t) do
-- certain keys should never transfer to the merge group directly
if k == "parent" then
if not rawget(g, "sourceParent") then
g.sourceParent = v;
end
elseif skips[k] ~= true then
g[k] = v;
end
end
else
for k,v in pairs(t) do
-- certain keys should never transfer to the merge group directly
if k == "parent" then
if not rawget(g, "sourceParent") then
g.sourceParent = v;
end
elseif not skips[k] then
g[k] = v;
end
end
end
-- custom special logic for fields which need to represent the commonality between all Sources of a group
-- loop through specific fields for custom logic
-- initial creation of a g object, has no key
if not g.key then
for k,_ in pairs(app.SourceSpecificFields) do
g[k] = t[k];
end
else
local gk, tk;
for k,f in pairs(app.SourceSpecificFields) do
-- existing is set
gk = g[k];
if gk then
tk = t[k];
-- no value on merger
if tk == nil then
-- app.PrintDebug(g.hash,"remove",k,gk,tk)
g[k] = nil;
elseif f and type(f) == "function" then
-- two different values with a compare function
-- app.PrintDebug(g.hash,"compare",k,gk,tk)
g[k] = f(gk, tk);
-- app.PrintDebug(g.hash,"result",g[k])
end
end
end
end
-- only copy metatable to g if another hasn't been set already
if not getmetatable(g) and getmetatable(t) then
setmetatable(g, getmetatable(t));
end
end
end
app.MergeProperties = MergeProperties;
-- The base logic for turning a Table of data into an 'object' that provides dynamic information concerning the type of object which was identified
-- based on the priority of possible key values
local function CreateObject(t, rootOnly)
-- app.PrintDebug("CO",t);
-- Commented this part out because there aren't enough class definitions exposed to the logic yet
-- Retail class design is still wildin' and doesn't use the CreateClass functionality
--local object = app.CloneClassInstance(t, rootOnly);
--if object and getmetatable(object) then return object; end
if not t then return {}; end
-- already an object, so need to create a new instance of the same data
if t.key then
local result = {};
-- app.PrintDebug("CO.key",t.key,t[t.key],"=>",result);
MergeProperties(result, t, nil, true);
-- include the raw g since it will be replaced at the end with new objects
result.g = t.g;
t = result;
-- if not getmetatable(t) then
-- app.PrintDebug(Colorize("Bad CreateObject (key without metatable) used:",app.Colors.ChatLinkError))
-- app.PrintTable(t)
-- end
-- app.PrintDebug("Merge done",result.key,result[result.key], t, result);
-- is it an array of raw datas which needs to be turned into an array of usable objects
elseif t[1] then
local result = {};
-- array
-- app.PrintDebug("CO.[]","=>",result);
for i,o in ipairs(t) do
result[i] = CreateObject(o, rootOnly);
end
return result;
-- use the highest-priority piece of data which exists in the table to turn it into an object
else
-- a table which somehow has a metatable which doesn't include a 'key' field
local meta = getmetatable(t);
if meta then
app.PrintDebug(Colorize("Bad CreateObject (metatable without key) used:",app.Colors.ChatLinkError))
app.PrintTable(t)
local result = {};
-- app.PrintDebug("CO.meta","=>",result);
MergeProperties(result, t, nil, true);
if not rootOnly and t.g then
local newg = {}
result.g = newg
for i,o in ipairs(t.g) do
newg[#newg+1] = CreateObject(o)
end
end
setmetatable(result, meta);
return result;
end
if t.mapID then
t = app.CreateMap(t.mapID, t);
elseif t.explorationID then
t = app.CreateExploration(t.explorationID, t);
elseif t.sourceID then
t = app.CreateItemSource(t.sourceID, t.itemID, t);
elseif t.encounterID then
t = app.CreateEncounter(t.encounterID, t);
elseif t.instanceID then
t = app.CreateInstance(t.instanceID, t);
elseif t.currencyID then
t = app.CreateCurrencyClass(t.currencyID, t);
elseif t.mountmodID then
t = app.CreateMountMod(t.mountmodID, t);
elseif t.speciesID then
t = app.CreateSpecies(t.speciesID, t);
elseif t.objectID then
t = app.CreateObject(t.objectID, t);
elseif t.flightpathID then
t = app.CreateFlightPath(t.flightpathID, t);
elseif t.followerID then
t = app.CreateFollower(t.followerID, t);
elseif t.illusionID then
t = app.CreateIllusion(t.illusionID, t);
elseif t.professionID then
t = app.CreateProfession(t.professionID, t);
elseif t.categoryID then
t = app.CreateCategory(t.categoryID, t);
elseif t.criteriaID then
t = app.CreateAchievementCriteria(t.criteriaID, t);
elseif t.achID or t.achievementID then
t = app.CreateAchievement(t.achID or t.achievementID, t);
elseif t.recipeID then
t = app.CreateRecipe(t.recipeID, t);
elseif t.factionID then
t = app.CreateFaction(t.factionID, t);
elseif t.heirloomID then
t = app.CreateHeirloom(t.heirloomID, t);
elseif t.azeriteessenceID then
t = app.CreateAzeriteEssence(t.azeriteessenceID, t);
elseif t.itemID or t.modItemID then
local itemID, modID, bonusID = app.GetItemIDAndModID(t.modItemID or t.itemID)
t.itemID = itemID
t.modID = modID
t.bonusID = bonusID
if t.toyID then
t = app.CreateToy(itemID, t);
elseif t.runeforgepowerID then
t = app.CreateRuneforgeLegendary(t.runeforgepowerID, t);
elseif t.conduitID then
t = app.CreateConduit(t.conduitID, t);
else
t = app.CreateItem(itemID, t);
end
elseif t.npcID or t.creatureID then
t = app.CreateNPC(t.npcID or t.creatureID, t);
elseif t.questID then
t = app.CreateQuest(t.questID, t);
-- Non-Thing groups
elseif t.classID then
t = app.CreateCharacterClass(t.classID, t);
elseif t.raceID then
t = app.CreateRace(t.raceID, t);
elseif t.headerID then
t = app.CreateNPC(t.headerID, t);
elseif t.expansionID then
t = app.CreateExpansion(t.expansionID, t);
elseif t.unit then
t = app.CreateUnit(t.unit, t);
elseif t.difficultyID then
t = app.CreateDifficulty(t.difficultyID, t);
elseif t.spellID then
t = app.CreateSpell(t.spellID, t);
elseif t.f or t.filterID then
t = app.CreateFilter(t.f or t.filterID, t);
elseif t.text then
t = app.CreateRawText(t.text, t)
else
-- app.PrintDebug("CO:raw");
-- app.PrintTable(t);
if rootOnly then
-- shallow copy the root table only, since using t as a metatable will allow .g to exist still on the table
-- app.PrintDebug("rootOnly copy of",t.text)
local result = {};
for k,v in pairs(t) do
result[k] = v;
end
t = result;
else
-- app.PrintDebug("metatable copy of",t.text)
t = setmetatable({}, { __index = t });
end
end
-- app.PrintDebug("CO.field","=>",t);
end
-- allows for copying an object without all of the sub-groups
if rootOnly then
t.g = nil;
else
-- app.PrintDebug("CreateObject key/value",t.key,t[t.key]);
-- if g, then replace each object in all sub groups with an object version of the table
local g = t.g;
if g then
local gNew = {};
for i,o in ipairs(g) do
gNew[i] = CreateObject(o)
end
t.g = gNew;
end
end
return t;
end
app.__CreateObject = CreateObject;
local function GetUnobtainableTexture(group)
if not group then return; end
if type(group) ~= "table" then
-- This function shouldn't be used with only u anymore!
app.print("Invalid use of GetUnobtainableTexture", group);
return;
end
-- Determine the texture color, default is green for events.
-- TODO: Use 4 for inactive events, use 5 for active events
local filter, u = 4, group.u;
if u then
-- only b = 0 (BoE), not BoA/BoP
-- removed, elite, bmah, tcg, summon
if u > 1 and u < 12 and group.itemID and (group.b or 0) == 0 then
filter = 2;
else
local phase = L.PHASES[u];
if phase then
if not phase.buildVersion or app.GameBuildVersion < phase.buildVersion then
filter = phase.state or 0;
else
-- This is a phase that's available. No icon.
return;
end
else
-- otherwise it's an invalid unobtainable filter
app.print("Invalid Unobtainable Filter:",u);
return;
end
end
return L.UNOBTAINABLE_ITEM_TEXTURES[filter];
end
if group.e then
return L.UNOBTAINABLE_ITEM_TEXTURES[app.Modules.Events.FilterIsEventActive(group) and 5 or 4];
end
end
app.GetUnobtainableTexture = GetUnobtainableTexture;
-- Returns an applicable Indicator Icon Texture for the specific group if one can be determined
app.GetIndicatorIcon = function(group)
-- Use the group's own indicator if defined
local groupIndicator = group.indicatorIcon
if groupIndicator then return groupIndicator end
-- Otherwise use some common logic
if group.saved then
if group.parent and group.parent.locks or group.repeatable then
return app.asset("known");
else
return app.asset("known_green");
end
end
return GetUnobtainableTexture(group);
end
local function GetRelativeFieldInSet(group, field, set)
if group then
return set[group[field]] or GetRelativeFieldInSet(group.sourceParent or group.parent, field, set);
end
end
-- Merges an Object into an existing set of Objects so as to not duplicate any incoming Objects
local MergeObject,
-- Nests an Object under another Object, only creating the 'g' group if necessary
-- ex. NestObject(parent, new, newCreate, index)
NestObject,
-- Merges multiple Objects into an existing set of Objects so as to not duplicate any incoming Objects
-- ex. MergeObjects(group, group2, newCreate)
MergeObjects,
-- Nests multiple Objects under another Object, only creating the 'g' group if necessary
-- ex. NestObjects(parent, groups, newCreate)
NestObjects,
-- Nests multiple Objects under another Object using an optional set of functions to determine priority on the adding of objects, only creating the 'g' group if necessary
-- ex. PriorityNestObjects(parent, groups, newCreate, function1, function2, ...)
PriorityNestObjects;
(function()
local function GetHash(t)
local hash = app.CreateHash(t);
app.PrintDebug(Colorize("No base .hash for t:",app.Colors.ChatLinkError),hash,t.text);
app.PrintTable(t)
return hash;
end
MergeObject = function(g, t, index, newCreate)
if g and t then
local hash = t.hash or GetHash(t);
for i,o in ipairs(g) do
if (o.hash or GetHash(o)) == hash then
MergeProperties(o, t, true);
NestObjects(o, t.g, newCreate);
return
end
end
if newCreate then t = CreateObject(t); end
if index then
tinsert(g, index, t);
else
g[#g + 1] = t
end
end
end
NestObject = function(p, t, newCreate, index)
if not p or not t then return end
local g = p.g;
if g then
MergeObject(g, t, index, newCreate);
elseif newCreate then
p.g = { CreateObject(t) };
else
p.g = { t };
end
end
MergeObjects = function(g, g2, newCreate)
if not g or not g2 then return end
if #g2 > 25 then
local t, hash, hashObj
local hashTable = {}
for i,o in ipairs(g) do
local hash = o.hash;
if hash then
-- are we merging the same object multiple times from one group?
hashObj = hashTable[hash]
if hashObj then
-- don't replace existing properties
MergeProperties(hashObj, o, true);
else
hashTable[hash] = o;
end
end
end
if newCreate then
for i,o in ipairs(g2) do
hash = o.hash;
-- print("_",hash);
if hash then
t = hashTable[hash];
if t then
MergeProperties(t, o, true);
NestObjects(t, o.g, newCreate);
else
t = CreateObject(o);
hashTable[hash] = t;
g[#g + 1] = t
end
else
g[#g + 1] = CreateObject(o)
end
end
else
for i,o in ipairs(g2) do
hash = o.hash;
-- print("_",hash);
if hash then
t = hashTable[hash];
if t then
MergeProperties(t, o, true);
NestObjects(t, o.g);
else
hashTable[hash] = o;
g[#g + 1] = o
end
else
g[#g + 1] = CreateObject(o)
end
end
end
else
for i,o in ipairs(g2) do
MergeObject(g, o, nil, newCreate);
end
end
end
NestObjects = function(p, g, newCreate)
if not g then return; end
local pg = p.g;
if pg then
MergeObjects(pg, g, newCreate);
elseif #g > 0 then
p.g = {};
MergeObjects(p.g, g, newCreate);
end
end
PriorityNestObjects = function(p, g, newCreate, ...)
if not g or #g == 0 then return; end
local pFuncs = {...};
if pFuncs[1] then
-- app.PrintDebug("PriorityNestObjects",#pFuncs,"Priorities",#g,"Objects")
-- setup containers for the priority buckets
local pBuckets, pBucket, skipped = {}, nil, nil;
for i,_ in ipairs(pFuncs) do
pBuckets[i] = {};
end
-- check each object
for _,o in ipairs(g) do
-- check each priority function
for i,pFunc in ipairs(pFuncs) do
-- if the function matches, put the object in the bucket
if pFunc(o) then
-- app.PrintDebug("Matched Priority Function",i,o.hash)
pBucket = pBuckets[i];
pBucket[#pBucket + 1] = o
break;
end
end
-- no bucket was found, put in skipped
if not pBucket then
-- app.PrintDebug("No Priority",o.hash)
if skipped then skipped[#skipped + 1] = o
else skipped = { o }; end
end
-- reset bucket
pBucket = nil;
end
-- then nest each bucket in order of priority
for i,pBucket in ipairs(pBuckets) do
-- app.PrintDebug("Nesting Priority Bucket",i,#pBucket)
NestObjects(p, pBucket, newCreate);
-- app.PrintDebug(".g",p.g and #p.g)
end
-- and nest anything skipped
-- app.PrintDebug("Nesting Skipped",skipped and #skipped)
NestObjects(p, skipped, newCreate);
-- app.PrintDebug(".g",p.g and #p.g)
else
NestObjects(p, g, newCreate);
end
-- app.PrintDebug("PNO-Done",#pFuncs,"Priorities",#g,"Objects",p.g and #p.g)
end
-- Merges multiple sources of an object into a single object. Can specify to clean out all sub-groups of the result
app.MergedObject = function(group, rootOnly)
if not group or not group[1] then return; end
local merged = CreateObject(group[1], rootOnly);
for i=2,#group do
MergeProperties(merged, group[i]);
end
-- for a merged object, clean any other references it might still have
merged.sourceParent = nil;
merged.parent = nil;
if rootOnly then
merged.g = nil;
end
return merged;
end
app.NestObject = NestObject
app.NestObjects = NestObjects
end)();
local ExpandGroupsRecursively;
do
local SkipAutoExpands = {
-- Specific HeaderID values should not expand
headerID = {
[app.HeaderConstants.ZONE_DROPS] = true,
[app.HeaderConstants.COMMON_BOSS_DROPS] = true,
[app.HeaderConstants.HOLIDAYS] = true
},
-- Item/Difficulty as Headers should not expand
itemID = true,
difficultyID = true,
}
local function SkipAutoExpand(group)
local key = group.key;
local skipKey = SkipAutoExpands[key];
if not skipKey then return; end
return skipKey == true or skipKey[group[key]];
end
ExpandGroupsRecursively = function(group, expanded, manual)
-- expand if there is any sub-group
if group.g then
-- app.PrintDebug("EGR",group.hash,expanded,manual);
-- if manually expanding
if (manual or (
-- not a skipped group for auto-expansion
not SkipAutoExpand(group) and
-- incomplete things actually exist below itself
((group.total or 0) > (group.progress or 0)) and
-- account/debug mode is active or it is not a 'saved' thing for this character
(app.MODE_DEBUG_OR_ACCOUNT or not group.saved))
) then
-- app.PrintDebug("EGR:expand");
group.expanded = expanded;
for _,subgroup in ipairs(group.g) do
ExpandGroupsRecursively(subgroup, expanded, manual);
end
end
end
end
end
local ResolveSymbolicLink;
-- Fills & returns a group with its symlink references, along with all sub-groups recursively if specified
-- This should only be used on a cloned group so the source group is not contaminated
local function FillSymLinks(group, recursive)