-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcore.lua
More file actions
1054 lines (884 loc) · 29.5 KB
/
Copy pathcore.lua
File metadata and controls
1054 lines (884 loc) · 29.5 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
--[[
core.lua
Initiates the BagSync addon within Ace3, very important!
BagSync - All Rights Reserved - (c) 2025
License included with addon.
--]]
local BAGSYNC, BSYC = ... --grab the addon namespace
_G[BAGSYNC] = BSYC --add it to the global frame space, otherwise you won't be able to call it
local L = BSYC.L
local WOW_PROJECT_ID = _G.WOW_PROJECT_ID
local WOW_PROJECT_MAINLINE = _G.WOW_PROJECT_MAINLINE
local WOW_PROJECT_CLASSIC = _G.WOW_PROJECT_CLASSIC
local WOW_PROJECT_WRATH_CLASSIC = _G.WOW_PROJECT_WRATH_CLASSIC
--Get TOC version
--/dump select(4, GetBuildInfo())
--https://warcraft.wiki.gg/wiki/Template:API_LatestInterface
--use the ingame trace tool to debug stuff
--/etrace or /eventtrace
--Dump tables DevTools_Dump({ table }) or DevTools_Dump(table)
BSYC.IsRetail = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
BSYC.IsClassic = WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
BSYC.IsWLK_C = WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC
BSYC.DEFAULT_FONT_NAME = BSYC.DEFAULT_FONT_NAME or "Friz Quadrata TT"
BSYC.TOOLTIP_CACHE_MAX = BSYC.TOOLTIP_CACHE_MAX or 1000
BSYC.DEFAULT_ALLOW_LIST = BSYC.DEFAULT_ALLOW_LIST or {
bag = true,
bank = true,
reagents = true,
equip = true,
mailbox = true,
void = true,
auction = true,
warband = true,
}
-- NOTE: Keep this ordered list for UI and filter displays. It preserves the
-- legacy, user-facing order that was previously defined inline in modules.
-- We still support additional keys via DEFAULT_ALLOW_LIST; any extra keys
-- will be appended by GetDefaultAllowListKeys().
BSYC.DEFAULT_ALLOW_LIST_ORDER = BSYC.DEFAULT_ALLOW_LIST_ORDER or {
"bag",
"bank",
"reagents",
"equip",
"mailbox",
"void",
"auction",
"warband",
}
BSYC.__defaultAllowListKeys = BSYC.__defaultAllowListKeys or nil
BSYC.__defaultAllowListKeysWithGuild = BSYC.__defaultAllowListKeysWithGuild or nil
function BSYC:GetDefaultAllowListKeys(includeGuild)
-- Returns an ordered list of storage keys for UI/search filters.
-- We cannot rely on pairs(DEFAULT_ALLOW_LIST) order, so this uses
-- DEFAULT_ALLOW_LIST_ORDER as a stable base and then appends any
-- additional keys that might be added in the future.
-- includeGuild inserts "guild" before "warband" to match legacy UI order.
local cache = includeGuild and self.__defaultAllowListKeysWithGuild or self.__defaultAllowListKeys
if cache then return cache end
local list = {}
local seen = {}
for i = 1, #self.DEFAULT_ALLOW_LIST_ORDER do
local key = self.DEFAULT_ALLOW_LIST_ORDER[i]
if self.DEFAULT_ALLOW_LIST[key] then
list[#list + 1] = key
seen[key] = true
end
end
for k in pairs(self.DEFAULT_ALLOW_LIST) do
if not seen[k] then
list[#list + 1] = k
seen[k] = true
end
end
if includeGuild and not seen.guild then
local insertAt = #list + 1
for i = 1, #list do
if list[i] == "warband" then
insertAt = i
break
end
end
table.insert(list, insertAt, "guild")
end
if includeGuild then
self.__defaultAllowListKeysWithGuild = list
else
self.__defaultAllowListKeys = list
end
return list
end
-- centralized API compatibility table (preserves fallbacks for older clients like classic)
BSYC.API = BSYC.API or {}
local getContainerNumSlots = (C_Container and C_Container.GetContainerNumSlots) or GetContainerNumSlots
local getContainerItemInfo = (C_Container and C_Container.GetContainerItemInfo) or GetContainerItemInfo
BSYC.API.GetContainerNumSlots = getContainerNumSlots
BSYC.API.GetContainerItemInfo = getContainerItemInfo
BSYC.API.GetAddOnMetadata = (C_AddOns and C_AddOns.GetAddOnMetadata) or GetAddOnMetadata
BSYC.API.IsAddOnLoaded = (C_AddOns and C_AddOns.IsAddOnLoaded) or IsAddOnLoaded
BSYC.API.GetItemInfo = (C_Item and C_Item.GetItemInfo) or GetItemInfo
BSYC.API.GetItemCount = (C_Item and C_Item.GetItemCount) or GetItemCount
BSYC.API.GetSpellInfo = (C_Spell and C_Spell.GetSpellInfo) or GetSpellInfo
BSYC.API.GetSpellLink = (C_Spell and C_Spell.GetSpellLink) or GetSpellLink
BSYC.API.GetRecipeInfo = (C_TradeSkillUI and C_TradeSkillUI.GetRecipeInfo) or nil
BSYC.API.GetCurrencyInfo = (C_CurrencyInfo and C_CurrencyInfo.GetCurrencyInfo) or GetCurrencyInfo
BSYC.API.GetCurrencyListSize = (C_CurrencyInfo and C_CurrencyInfo.GetCurrencyListSize) or GetCurrencyListSize
BSYC.API.GetCurrencyListInfo = (C_CurrencyInfo and C_CurrencyInfo.GetCurrencyListInfo) or GetCurrencyListInfo
BSYC.API.GetCurrencyListLink = (C_CurrencyInfo and C_CurrencyInfo.GetCurrencyListLink) or GetCurrencyListLink
BSYC.API.ExpandCurrencyList = (C_CurrencyInfo and C_CurrencyInfo.ExpandCurrencyList) or ExpandCurrencyList
BSYC.API.LoadAddOn = (C_AddOns and C_AddOns.LoadAddOn) or LoadAddOn
-- normalize container item link + count across Classic/Retail
BSYC.API.GetContainerItemLinkCount = function(bagID, slotID)
if not getContainerItemInfo then return nil, nil end
local info, count, _, _, _, _, link = getContainerItemInfo(bagID, slotID)
if type(info) == "table" then
link = info.hyperlink
count = info.stackCount or 1
end
return link, count, info
end
BSYC.IsBankTabsActive = Enum.BagIndex.CharacterBankTab_1 ~= nil
BSYC.IsReagentBagActive = (Constants.InventoryConstants.NumReagentBagSlots or 0) > 0
--since FetchPurchasedBankTabData supports Guilds, it's possible in the future they will put it on a classic server with no Warband support. So lets do it as last resort
BSYC.isWarbandActive = (C_Container and C_Container.SortAccountBankBags) and (Enum and Enum.BagIndex and Enum.BagIndex.AccountBankTab_1) and (C_Bank and C_Bank.FetchPurchasedBankTabData)
--increment forceDBReset to reset the ENTIRE db forcefully
local forceDBReset = 3
BSYC.FakePetCode = 10000000000
BSYC_DL = {
DEBUG = 1,
INFO = 2,
TRACE = 3,
WARN = 4,
FINE = 5,
SL1 = 6,
SL2 = 7,
SL3 = 8,
SL4 = 9,
SL5 = 10,
}
local debugDefaults = {
enable = false,
cache = false,
DEBUG = false,
INFO = true,
TRACE = true,
WARN = false,
FINE = false,
SL1 = false,
SL2 = false,
SL3 = false,
SL4 = false,
SL5 = false,
}
if BSYC.isWarbandActive then
BSYC.WarbandIndex = {
tabs = {
Enum.BagIndex.AccountBankTab_1,
Enum.BagIndex.AccountBankTab_2,
Enum.BagIndex.AccountBankTab_3,
Enum.BagIndex.AccountBankTab_4,
Enum.BagIndex.AccountBankTab_5,
},
bags = {
[Enum.BagIndex.AccountBankTab_1] = 1,
[Enum.BagIndex.AccountBankTab_2] = 2,
[Enum.BagIndex.AccountBankTab_3] = 3,
[Enum.BagIndex.AccountBankTab_4] = 4,
[Enum.BagIndex.AccountBankTab_5] = 5,
},
}
end
StaticPopupDialogs["BAGSYNC_RESETDATABASE"] = {
text = L.ResetDBInfo,
button1 = L.Yes,
button2 = L.No,
OnAccept = function()
BagSyncDB = { ["forceDBReset§"] = forceDBReset }
ReloadUI()
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
}
StaticPopupDialogs["BAGSYNC_RESETDB_INFO"] = {
text = L.DatabaseReset,
button1 = OKAY,
button2 = nil,
timeout = 0,
OnAccept = function()
end,
OnCancel = function()
end,
whileDead = 1,
hideOnEscape = 1,
}
StaticPopupDialogs["BAGSYNC_RELOADUI"] = {
text = L.AddonCompartmentReloadMsg,
button1 = OKAY,
button2 = nil,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
}
function BSYC:ShowReloadUIPopup()
if StaticPopup_Show then
StaticPopup_Show("BAGSYNC_RELOADUI")
end
end
function BSYC.DEBUG(level, sName, ...)
if not BSYC.options or not BSYC.options.debug or not BSYC.options.debug.enable then return end
local Debug = BSYC:GetModule("Debug")
if not Debug then return end
Debug:AddMessage(level, sName, ...)
end
local function Debug(level, ...)
BSYC.DEBUG(level, "CORE", ...)
end
-- literal marker helper (no Lua patterns)
local function hasMark(s, mark)
return type(s) == "string" and s:find(mark, 1, true) ~= nil
end
BSYC.hasMark = hasMark
--use /framestack to debug windows and show tooltip information
--if you press SHIFT while doing the above command it gives you a bit more information
-- Mouse focus compatibility: some clients provide GetMouseFocus() (single region),
-- others provide GetMouseFoci() (returns ScriptRegion[]). Normalize to a single region.
function BSYC.GMF()
if type(_G.GetMouseFocus) == "function" then
return _G.GetMouseFocus()
end
if type(_G.GetMouseFoci) == "function" then
local regions = _G.GetMouseFoci()
if type(regions) == "table" then
return regions[1]
end
end
return nil
end
-- Unified hover check used throughout scroll lists. Prefer IsMouseOver() when available.
function BSYC:IsMouseOver(frame)
if not frame then return false end
if type(frame.IsMouseOver) == "function" then
local ok, res = pcall(frame.IsMouseOver, frame)
if ok then
return not not res
end
end
return self.GMF and (self.GMF() == frame) or false
end
-----------------------------------------------------------------
---
--this is only for hash tables that aren't indexed with 1,2,3,4 etc.. but use custom index keys
--if you are using table.insert() or tables that are indexed with numbers then use # instead for table length. #table as example
function BSYC:GetHashTableLen(tbl)
local count = 0
for _, __ in pairs(tbl) do
count = count + 1
end
return count
end
function BSYC:CopyArray(src)
if type(src) ~= "table" then return {} end
local out = {}
for i = 1, #src do
out[i] = src[i]
end
return out
end
function BSYC:OpenConfig()
if InCombatLockdown and InCombatLockdown() then return false end
local addonCategoryName = "BagSync"
if _G.Settings and type(_G.Settings.OpenToCategory) == "function" then
local category = self.settingsCategory
if not category and self.ConfigDialog and type(self.ConfigDialog._settingsCategories) == "table" then
category = self.ConfigDialog._settingsCategories[addonCategoryName]
end
local categoryID
if type(category) == "number" then
categoryID = category
elseif type(category) == "table" then
if type(category.GetID) == "function" then
categoryID = category:GetID()
elseif type(category.GetCategoryID) == "function" then
categoryID = category:GetCategoryID()
elseif type(category.ID) == "number" then
categoryID = category.ID
elseif type(category.id) == "number" then
categoryID = category.id
end
end
if categoryID ~= nil then
if pcall(_G.Settings.OpenToCategory, categoryID) then return true end
end
-- Some older clients accepted an addon name string here; keep as a last resort.
if pcall(_G.Settings.OpenToCategory, addonCategoryName) then return true end
end
if _G.InterfaceOptionsFrame_OpenToCategory then
if not self.IsRetail and _G.InterfaceOptionsFrame then
-- required on some clients to ensure panels are created before opening
_G.InterfaceOptionsFrame:Show()
end
local panel = self.blizzPanel or self.aboutPanel
if panel then
return pcall(_G.InterfaceOptionsFrame_OpenToCategory, panel)
end
end
return false
end
function BSYC:DecodeOpts(tblString, mergeOpts)
--Example = "petdata=245:12:4:5:3|auction=124567|foo=bar|tickle=elmo|test=12:3:4|forthe=horde"
local t = mergeOpts or {}
if type(tblString) ~= "string" or tblString == "" then return t end
for k, v in tblString:gmatch("([^=|]+)=([^|]*)") do
-- Only overwrite if we don't have an existing value; we don't want to overwrite any mergeOpts values that are newer.
if t[k] == nil then
t[k] = v
end
end
return t
end
function BSYC:EncodeOpts(tbl, link, removeOpts)
if not tbl then return end
--To Remove Opts: (example) BSYC:EncodeOpts(qOpts, link, {gtab=true})
if removeOpts ~= nil and type(removeOpts) ~= "table" then
removeOpts = nil
end
if link then
--when doing the split, make sure to merge our table
local xLink, xCount, xOpts = self:Split(link, nil, tbl)
if xLink then
xCount = tonumber(xCount) or 1
local parts = {}
for k, v in pairs(xOpts) do
if not removeOpts or not removeOpts[k] then
parts[#parts + 1] = k .. "=" .. tostring(v)
end
end
if #parts > 0 then
return xLink .. ";" .. xCount .. ";" .. table.concat(parts, "|")
end
return xLink .. ";" .. xCount
end
--this is an invalid ParseItemLink, return empty string
return
end
local parts = {}
for k, v in pairs(tbl) do
parts[#parts + 1] = k .. "=" .. tostring(v)
end
if #parts > 0 then
return table.concat(parts, "|")
end
end
function BSYC:Split(dataStr, skipOpts, mergeOpts)
if not dataStr then return nil, nil, nil end
if type(dataStr) == "number" then
dataStr = tostring(dataStr)
end
if type(dataStr) ~= "string" or dataStr == "" then
return nil, nil, nil
end
local qLink, qCount, qOpts = strsplit(";", dataStr, 3)
if not qLink or qLink == "" then
return nil, nil, nil
end
--only do Opts functions if we need too, otherwise just return the link and count
if not skipOpts or mergeOpts then
return qLink, tonumber(qCount) or qCount, self:DecodeOpts(qOpts, mergeOpts) or {}
end
return qLink, tonumber(qCount) or qCount, nil
end
function BagSync_ShowWindow(windowName)
if windowName == "Professions" and not BSYC.tracking.professions then return end
if windowName == "Currency" and not BSYC.tracking.currency then return end
if BSYC:GetModule(windowName).frame:IsVisible() then
BSYC:GetModule(windowName).frame:Hide()
else
BSYC:GetModule(windowName).frame:Show()
end
end
--This function will always return the base short itemID if no count is provided or if the count is less than 1.
--Note: In addition to above, the base itemID is returned as an integer unless the item has bonusID, in which case the itemID with bonusID string is returned.
BSYC.__parseCache = BSYC.__parseCache or {}
BSYC.__parseCacheSize = BSYC.__parseCacheSize or 0
local MAX_PARSE_CACHE = 5000
function BSYC:ParseItemLink(link, count)
if not link then return end
if not count then count = 1 end
if type(link) == "number" then
link = tostring(link)
end
-- hard cap protection (defensive)
if next(self.__parseCache) and self.__parseCacheSize > MAX_PARSE_CACHE then
wipe(self.__parseCache)
self.__parseCacheSize = 0
end
local cacheKey = link .. ";" .. tostring(count)
-- fast path
local cached = self.__parseCache[cacheKey]
if cached then
return cached
end
-- database entry short-circuit
local qLink, qCount = self:Split(link, true)
if qLink and qCount then
return link
end
-- battle pet handling
if link:find("battlepet:", 1, true) then
local parsed = self:CreateFakeID(link, count)
if parsed then
self.__parseCache[cacheKey] = parsed
self.__parseCacheSize = self.__parseCacheSize + 1
end
return parsed
end
local result = link:match("item:([%d:]+)")
local shortID = self:GetShortItemID(link)
-- profession frame bug workaround
if shortID and tonumber(shortID) == 0 and TradeSkillFrame then
local focusObj = self.GMF and self.GMF()
local focus = (focusObj and focusObj.GetName and focusObj:GetName()) or nil
if focus == "TradeSkillSkillIcon" then
if C_TradeSkillUI and C_TradeSkillUI.GetRecipeItemLink then
link = C_TradeSkillUI.GetRecipeItemLink(TradeSkillFrame.selectedSkill)
end
else
local i = type(focus) == "string" and focus:match("TradeSkillReagent(%d+)")
if i and C_TradeSkillUI and C_TradeSkillUI.GetRecipeReagentItemLink then
link = C_TradeSkillUI.GetRecipeReagentItemLink(TradeSkillFrame.selectedSkill, tonumber(i))
end
end
if link then
result = link:match("item:([%d:]+)")
shortID = self:GetShortItemID(link)
end
end
if result then
local linkSplit = { strsplit(":", result) }
result = shortID
if #linkSplit > 13 then
local bonusCount = tonumber(linkSplit[13]) or 0
if bonusCount > 0 then
for i = 2, #linkSplit do
if i < 13 or i > (13 + bonusCount) then
linkSplit[i] = ""
end
end
result = table.concat(linkSplit, ":")
end
end
end
link = result or shortID
if count > 1 then
link = link .. ";" .. count
end
self.__parseCache[cacheKey] = link
self.__parseCacheSize = self.__parseCacheSize + 1
return link
end
function BSYC:CreateFakeID(link, count, speciesID, level, breedQuality, maxHealth, power, speed, name)
if not BattlePetTooltip then return end
Debug(BSYC_DL.DEBUG, "CreateFakeID", link, count, speciesID, level, breedQuality, maxHealth, power, speed, name)
--https://github.com/tomrus88/BlizzardInterfaceCode/blob/8633e552f3335b8c66b1fbcea6760a5cd8bcc06b/Interface/FrameXML/BattlePetTooltip.lua
--this does not work with 82800 pet cages, it will return nil
--local speciesID, level, breedQuality, maxHealth, power, speed, name = BattlePetToolTip_UnpackBattlePetLink(battlePetLink)
local petData
if link and not speciesID then
local linkType, linkOptions, petName = LinkUtil.ExtractLink(link)
if linkType ~= "battlepet" then return end
--speciesID, level, breedQuality, maxHealth, power, speed, name
speciesID = linkOptions:match("(%d+):")
petData = linkOptions:match("%d+:%d+:%d+:%d+:%d+:%d+")
end
--either pass the link or speciesID
if speciesID then
if not petData then
petData = strjoin(":", speciesID, level or 0, breedQuality or 0, maxHealth or 0, power or 0, speed or 0)
end
--we do this so as to not interfere with standard itemid's. Example a speciesID can be 1345 but there is a real item with itemID 1345.
--to compensate for this we will use a ridiculous number to avoid conflicting with standard itemid's
local fakePetID = BSYC.FakePetCode + (speciesID * 100000)
if fakePetID then
if not count then count = 1 end
Debug(BSYC_DL.INFO, "FakeID [Created]", speciesID, link, name, fakePetID)
local encodeStr = self:EncodeOpts({petdata=petData})
if encodeStr then
return fakePetID..";"..count..";"..encodeStr
end
end
end
end
function BSYC:IsBattlePetFakeID(fakeID)
if not fakeID or not tonumber(fakeID) then return false end
fakeID = tonumber(fakeID)
if fakeID >= BSYC.FakePetCode then
return true
end
return false
end
function BSYC:FakeIDToSpeciesID(fakeID)
if not fakeID or not tonumber(fakeID) then return end
fakeID = tonumber(fakeID)
if fakeID >= BSYC.FakePetCode then
fakeID = (fakeID - BSYC.FakePetCode) / 100000
return fakeID
end
end
function BSYC:GetShortItemID(link)
if not link then return end
if type(link) == "number" then link = tostring(link) end
if link:find("battlepet:", 1, true) then
link = BSYC:CreateFakeID(link) -- may return nil if BattlePetTooltip missing
if not link then return end
end
return link:match("item:(%d+):")
or link:match("^(%d+):")
or (strsplit(";", link))
or link
end
function BSYC:GetShortCurrencyID(link)
if not link then return end
if type(link) == "number" then link = tostring(link) end
local id = link:match("currency:(%d+):") or link:match("currency:(%d+)$") or link:match("^(%d+):") or link
return tonumber(id)
end
function BSYC:SetDefaults(category, defaults)
local dbObj = BagSyncDB["options§"]
if category and dbObj[category] == nil then dbObj[category] = {} end
for k, v in pairs(defaults) do
if category and dbObj[category][k] == nil then
dbObj[category][k] = v
elseif not category and dbObj[k] == nil then
dbObj[k] = v
end
end
end
--- -------------------
--- FONT stuff
--- -------------------
function BSYC:GetLibSharedMedia()
local function tryLoadLib()
if self.__lsmLoadAttempted then return end
self.__lsmLoadAttempted = true
local loadAddon = BSYC.API and BSYC.API.LoadAddOn
if type(loadAddon) == "function" then
pcall(loadAddon, "LibSharedMedia-3.0")
end
end
local libStub = _G.LibStub
if type(libStub) ~= "table" and type(libStub) ~= "function" then
tryLoadLib()
libStub = _G.LibStub
if type(libStub) ~= "table" and type(libStub) ~= "function" then return nil end
end
local ok, sml = pcall(libStub, "LibSharedMedia-3.0", true)
if not ok or not sml then
tryLoadLib()
ok, sml = pcall(libStub, "LibSharedMedia-3.0", true)
if not ok or not sml then return nil end
end
if type(sml.List) ~= "function" or type(sml.Fetch) ~= "function" then return nil end
local mtFont = (sml.MediaType and sml.MediaType.FONT) or "font"
return sml, mtFont
end
function BSYC:GetBlizzardFontMap()
if self.__blizzFontMap then return self.__blizzFontMap end
local map = {}
local function add(name, path)
if type(name) ~= "string" or name == "" then return end
if type(path) ~= "string" or path == "" then return end
local p = path:lower()
if not (p:find("%.ttf$") or p:find("%.otf$")) then return end
map[name] = path
end
add("Friz Quadrata TT", _G.STANDARD_TEXT_FONT or "Fonts\\FRIZQT__.TTF")
add("Arial Narrow", "Fonts\\ARIALN.TTF")
add("Skurri", "Fonts\\SKURRI.TTF")
add("Morpheus", "Fonts\\MORPHEUS.TTF")
-- Add known Blizzard font globals (locale-dependent).
local knownGlobals = {
"STANDARD_TEXT_FONT",
"UNIT_NAME_FONT",
"DAMAGE_TEXT_FONT",
"NAMEPLATE_FONT",
"CHAT_FONT",
"RAID_WARNING_FONT",
"SYSTEM_FONT_NAME",
}
for i = 1, #knownGlobals do
local varName = knownGlobals[i]
add("Blizzard: " .. varName, _G[varName])
end
-- Best-effort scan for additional *_FONT globals.
for k, v in pairs(_G) do
if type(k) == "string" and k:find("_FONT$") and type(v) == "string" then
add("Blizzard: " .. k, v)
end
end
self.__blizzFontMap = map
self.__blizzFontList = nil
return map
end
function BSYC:GetBlizzardFontList()
if self.__blizzFontList then return self.__blizzFontList end
local map = self:GetBlizzardFontMap()
local list = {}
local seen = {}
local function push(name)
if name and map[name] and not seen[name] then
seen[name] = true
list[#list + 1] = name
end
end
-- Keep the traditional list first.
push("Friz Quadrata TT")
push("Arial Narrow")
push("Skurri")
push("Morpheus")
local rest = {}
for name in pairs(map) do
if not seen[name] then
rest[#rest + 1] = name
end
end
table.sort(rest, function(a, b)
return a:lower() < b:lower()
end)
for i = 1, #rest do
push(rest[i])
end
self.__blizzFontList = list
return list
end
function BSYC:GetFontPathOrNil(fontName)
if type(fontName) ~= "string" or fontName == "" then return nil end
local sml, mtFont = self:GetLibSharedMedia()
if sml then
local path = sml:Fetch(mtFont, fontName, true)
if type(path) == "string" and path ~= "" then return path end
return nil
end
return self:GetBlizzardFontMap()[fontName]
end
function BSYC:GetFontPath(fontName)
return self:GetFontPathOrNil(fontName)
or self:GetFontPathOrNil(self.DEFAULT_FONT_NAME)
or _G.STANDARD_TEXT_FONT
or "Fonts\\FRIZQT__.TTF"
end
function BSYC:GetAvailableFontNames()
local list
local sml, mtFont = self:GetLibSharedMedia()
if sml then
local ok, res = pcall(sml.List, sml, mtFont)
if ok and type(res) == "table" and #res > 0 then
list = self:CopyArray(res)
end
end
if not list then
list = self:GetBlizzardFontList()
end
local hasDefault = false
for _, name in ipairs(list) do
if name == self.DEFAULT_FONT_NAME then
hasDefault = true
break
end
end
if not hasDefault then
table.insert(list, 1, self.DEFAULT_FONT_NAME)
end
return list
end
function BSYC:CreateFonts()
if not BSYC.options then return end
local flags = ""
if BSYC.options.extTT_FontMonochrome and BSYC.options.extTT_FontOutline ~= "NONE" then
flags = "MONOCHROME,"..BSYC.options.extTT_FontOutline
elseif BSYC.options.extTT_FontMonochrome then
flags = "MONOCHROME"
elseif BSYC.options.extTT_FontOutline ~= "NONE" then
flags = BSYC.options.extTT_FontOutline
end
BSYC.__fontFlags = flags
local fontObject = CreateFont("BagSyncExtTT_Font")
local fontName = BSYC.options.extTT_Font or BSYC.DEFAULT_FONT_NAME
if not BSYC:GetFontPathOrNil(fontName) then
fontName = BSYC.DEFAULT_FONT_NAME
BSYC.options.extTT_Font = fontName
end
fontObject:SetFont(BSYC:GetFontPath(fontName), BSYC.options.extTT_FontSize, flags)
BSYC.__font = fontObject
if BSYC.GetModule then
local extTip = BSYC:GetModule("ExtTip", true)
if extTip and extTip.ApplyFont then
pcall(extTip.ApplyFont, extTip)
end
end
end
--------------------
function BSYC:CanDoCurrency()
--Classic servers do have some implementations of these features installed, so we have to do checks
--WOTLK has only a partial implementation of the C_CurrencyInfo API, so we have to check for that as well
if C_CurrencyInfo and C_CurrencyInfo.GetCurrencyListInfo then return true end
if GetCurrencyListInfo then return true end
if C_CurrencyInfo and C_CurrencyInfo.GetCurrencyListLink then return true end
if GetCurrencyListLink then return true end
return false
end
function BSYC:CanDoProfessions()
if not GetProfessions or not GetProfessionInfo then return false end
-- Retail (Dragonflight+): Uses C_TradeSkillUI
if C_TradeSkillUI and C_TradeSkillUI.GetAllRecipeIDs then
if not C_TradeSkillUI.IsTradeSkillLinked or not C_TradeSkillUI.IsTradeSkillGuild or not C_TradeSkillUI.IsNPCCrafting then return false end
if not C_TradeSkillUI.GetBaseProfessionInfo or not C_TradeSkillUI.GetChildProfessionInfo then return false end
if not C_TradeSkillUI.GetCategories or not C_TradeSkillUI.GetCategoryInfo then return false end
if not C_TradeSkillUI.GetRecipeInfo then return false end
return true
end
-- Classic (Vanilla/TBC/Wrath): Uses GetTradeSkillInfo/GetCraftInfo
if GetNumTradeSkills and GetTradeSkillInfo and GetTradeSkillRecipeLink then
return true
end
return false
end
local BSYC_FRAME_MODULE_LIST = {
"Blacklist",
"Whitelist",
"Currency",
"Professions",
"Recipes",
"Gold",
"Profiles",
"Search",
"SearchFilters",
"SortOrder",
"Debug",
"Details",
}
function BSYC:ResetFramePositions()
for i=1, #BSYC_FRAME_MODULE_LIST do
local mName = BSYC_FRAME_MODULE_LIST[i]
if BSYC:GetModule(mName, true) and BSYC:GetModule(mName).frame then
BSYC:GetModule(mName).frame:ClearAllPoints()
BSYC:GetModule(mName).frame:SetPoint("CENTER",UIParent,"CENTER", 0, 0)
end
end
end
function BSYC:GetBSYC_FrameLevel()
local count = 0
local moduleList = BSYC_FRAME_MODULE_LIST
for i=1, #moduleList do
local mName = moduleList[i]
if BSYC:GetModule(mName, true) and BSYC:GetModule(mName).frame and BSYC:GetModule(mName).frame:IsVisible() then
--20 is a nice healthy number to push the frame in levels, this compensates for frames within the frames that may have varying levels like scrollframes
count = count + 20
end
end
return count
end
function BSYC:SetBSYC_FrameLevel(module)
if module and module.frame then
local bsycLVL = self:GetBSYC_FrameLevel()
--set the frame level higher than any visible ones to overlap it
module.frame:SetFrameLevel(bsycLVL or 1)
--check for the closeBtn otherwise it overlaps, because the Blizzard template sets the framelevel to 510 for UIPanelCloseButton
if module.frame.closeBtn then
module.frame.closeBtn:SetFrameLevel((bsycLVL or 1) + 1) --you have to increment it at least once to draw over our frame background
end
end
end
BSYC.timerFrame = CreateFrame("Frame")
BSYC.timerFrame:Hide()
BSYC.timers = BSYC.timers or {}
BSYC.timersByName = BSYC.timersByName or {}
local HAS_C_TIMER = (C_Timer and type(C_Timer.NewTimer) == "function")
local function FireTimer(tmr)
Debug(BSYC_DL.SL3, "DoTimer", tmr.name, tmr.origDelay, tmr.object, tmr.func)
if type(tmr.func) == "string" then
local obj = tmr.object
local method = obj and obj[tmr.func]
if type(method) == "function" then
method(obj, unpack(tmr.argsList or {}, 1, tmr.argsCount))
end
elseif type(tmr.func) == "function" then
tmr.func(unpack(tmr.argsList or {}, 1, tmr.argsCount))
end
end
function BSYC:StartTimer(name, delay, selfObj, func, ...)
if not name then return end
delay = tonumber(delay) or 0
local argsCount = select("#", ...)
local argsList = { ... }
-- Enforce uniqueness by name; StartTimer is used as a debounce in many places.
self:StopTimer(name)
-- Prefer C_Timer when available (no OnUpdate scanning).
if HAS_C_TIMER then
local tmr = {
func = func,
object = selfObj,
origDelay = delay,
name = name,
argsCount = argsCount,
argsList = argsList,
}
self.timersByName[name] = tmr
tmr.handle = C_Timer.NewTimer(delay, function()
if self.timersByName[name] ~= tmr then return end -- replaced/cancelled
self.timersByName[name] = nil
FireTimer(tmr)
end)
return
end
-- Fallback: manual OnUpdate timers for older clients.
table.insert(self.timers, {
func = func,
object = selfObj,
delay = delay,
origDelay = delay,
name = name,
argsCount = argsCount,
argsList = argsList,
})
self.timerFrame:Show() --show frame to start the OnUpdate
end
function BSYC:StopTimer(name)
if not name then return end
-- C_Timer path
local tmr = self.timersByName and self.timersByName[name]
if tmr then
self.timersByName[name] = nil
if tmr.handle and type(tmr.handle.Cancel) == "function" then
tmr.handle:Cancel()
end
end
-- Fallback list removal (iterate backwards since we are using table.remove)
for i = #self.timers, 1, -1 do
if self.timers[i] and self.timers[i].name == name then
table.remove(self.timers, i)
end