-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCore.lua
More file actions
503 lines (440 loc) · 15.3 KB
/
Core.lua
File metadata and controls
503 lines (440 loc) · 15.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
local DEBUG = false
SetCollector = LibStub("AceAddon-3.0"):NewAddon("SetCollector", "AceConsole-3.0", "AceEvent-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("SetCollector", true)
local WOW_VERSION = select(4,GetBuildInfo())
local InventorySlots = {
['INVTYPE_HEAD'] = 1,
['INVTYPE_SHOULDER'] = 3,
['INVTYPE_BODY'] = 4,
['INVTYPE_CHEST'] = 5,
['INVTYPE_ROBE'] = 5,
['INVTYPE_WAIST'] = 6,
['INVTYPE_LEGS'] = 7,
['INVTYPE_FEET'] = 8,
['INVTYPE_WRIST'] = 9,
['INVTYPE_HAND'] = 10,
['INVTYPE_CLOAK'] = 15,
['INVTYPE_WEAPON'] = 16,
['INVTYPE_SHIELD'] = 17,
['INVTYPE_2HWEAPON'] = 16,
['INVTYPE_WEAPONMAINHAND'] = 16,
['INVTYPE_RANGED'] = 16,
['INVTYPE_RANGEDRIGHT'] = 16,
['INVTYPE_WEAPONOFFHAND'] = 17,
['INVTYPE_HOLDABLE'] = 17,
['INVTYPE_TABARD'] = 19,
}
local model = CreateFrame("DressUpModel","SetCollectorTooltipDressUpModel",UIParent)
--
-- Startup Functions
--
function SetCollector:OnInitialize()
SetCollector:SetupDB(true)
SetCollector:SetupUI(true)
if SetCollector:GetDebug() then SetCollector:Print("Initialized"); end
LibStub("AceConfig-3.0"):RegisterOptionsTable("SetCollector", SetCollector:GetOptions())
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("SetCollector", "Set Collector")
SetCollector:RegisterEvent("PLAYER_LOGIN")
end
function SetCollector:OnEnable()
if SetCollector:GetDebug() then SetCollector:Print("Enabled"); end
end
function SetCollector:OnDisable()
if SetCollector:GetDebug() then SetCollector:Print("Disabled"); end
end
function SetCollector:GetAppearanceInfo(itemLink)
if itemLink then
local appearanceID, sourceID, itemID, setIDs
itemID = GetItemInfoInstant(itemLink)
appearanceID, sourceID = C_TransmogCollection.GetItemInfo(itemLink)
if sourceID then
setIDs = C_TransmogSets.GetSetsContainingSourceID(sourceID)
end
return appearanceID, sourceID, itemID, setIDs
end
end
function SetCollector:IsDebugging() -- Redundant?
DEBUG = SetCollector:GetDebug()
return DEBUG
end
--
-- Local Functions
--
local function pairsByKeys(t, d)
local a = {}
for n in pairs(t) do table.insert(a, n) end
if d == "ASC" then
table.sort(a, function(a,b) return a<b end)
else
table.sort(a, function(a,b) return a>b end)
end
local i = 0 -- iterator variable
local iter = function () -- iterator function
i = i + 1
if a[i] == nil then return nil
else return a[i], t[a[i]]
end
end
return iter
end
--
-- Global Functions
--
function SetCollector:GetDebug()
DEBUG = SetCollector.db.global.debug
return DEBUG
end
function SetCollector:SetDebug(debug)
if debug == nil then
SetCollector.db.global.debug = not SetCollector.db.global.debug
else
SetCollector.db.global.debug = debug
end
end
function SetCollector:GetOptionsShowSet()
return SetCollector.db.global.tooltips.show_set
end
function SetCollector:SetOptionsShowSet()
if SetCollector.db.global.tooltips.show_set then SetCollector.db.global.tooltips.show_set = false
else SetCollector.db.global.tooltips.show_set = true
end
end
function SetCollector:GetOptionsShowSetLocation()
return SetCollector.db.global.tooltips.show_location
end
function SetCollector:SetOptionsShowSetLocation()
if SetCollector.db.global.tooltips.show_location then SetCollector.db.global.tooltips.show_location = false
else SetCollector.db.global.tooltips.show_location = true
end
end
function SetCollector:SortList(t, f, d)
if f == "key" then return pairsByKeys(t, d) -- Allow for explicit request to sort by key
-- Future sort alternatives here
else return pairsByKeys(t, d) -- Default to sort by key
end
end
function SetCollector:UpdateCollections()
local collections = SetCollector:GetCollectionsList()
SetCollector:UpdateScrollFrame(collections, DEBUG)
end
function SetCollector:PLAYER_LOGIN()
local DEBUG = SetCollector:GetDebug()
if DEBUG then SetCollector:Print("Running PLAYER_LOGIN processes"); end
SetCollector:InitializeFilter(DEBUG)
SetCollector:InitializeModel(DEBUG)
end
--
-- Slash Commands
--
SetCollector:RegisterChatCommand("setcollector", "MySlashProcessorFunc")
SetCollector:RegisterChatCommand("sc", "MySlashProcessorFunc")
function SetCollector:OptionsSetDebug()
if SetCollector.db.global.debug then SetCollector.db.global.debug = false
else SetCollector.db.global.debug = true
end
local message
if SetCollector:GetDebug() then message = "DEBUG_ON" else message = "DEBUG_OFF" end
SetCollector:Print(L[message])
end
function SetCollector:ToggleExpansion(parameters)
local expansions = SetCollector.db.global.expansions
if parameters == "0" then
expansions.v00 = not expansions.v00
elseif parameters == "1" then
expansions.v01 = not expansions.v01
elseif parameters == "2" then
expansions.v02 = not expansions.v02
elseif parameters == "3" then
expansions.v03 = not expansions.v03
elseif parameters == "4" then
expansions.v04 = not expansions.v04
elseif parameters == "5" then
expansions.v05 = not expansions.v05
elseif parameters == "6" then
expansions.v06 = not expansions.v06
elseif parameters == "7" then
expansions.v07 = not expansions.v07
elseif parameters == "8" then
expansions.v08 = not expansions.v08
elseif parameters == "9" then
expansions.v09 = not expansions.v09
elseif parameters == "10" then
expansions.v10 = not expansions.v10
end
SetCollector:Print(L["RELOAD"])
end
function SetCollector:PrintItem(itemID)
local sLink = select(2,GetItemInfo(itemID))
SetCollector:Print(sLink)
end
function SetCollector:ListSet(input)
local setID, parameters = input:match("^(%S*)%s*(.-)$")
local sets = C_TransmogSets.GetAllSets();
if (sets) then
for i, set in ipairs(sets) do
local setInfo = (set.setID and C_TransmogSets.GetSetInfo(set.setID)) or nil;
if (set.setID == tonumber(setID) or set.baseSetID == tonumber(setID)) then
if (set.baseSetID == nil) then
SetCollector:Print(set.setID.." "..(setInfo.name or nil))
else
SetCollector:Print(set.setID.." "..(setInfo.name or nil).." ("..set.baseSetID..")")
end
end
end
end
end
function SetCollector:ListAllSets()
local sets = C_TransmogSets.GetAllSets();
if (sets) then
for i, set in ipairs(sets) do
local setInfo = (set.setID and C_TransmogSets.GetSetInfo(set.setID)) or nil;
if (set.baseSetID == nil) then
SetCollector:Print(set.setID.." "..(setInfo.name or nil))
else
SetCollector:Print(set.setID.." "..(setInfo.name or nil).." ("..set.baseSetID..")")
end
end
end
end
function SetCollector:ListBaseSets()
local sets = C_TransmogSets.GetAllSets();
if (sets) then
for i, set in ipairs(sets) do
if (set.baseSetID == nil) then
local setInfo = (set.setID and C_TransmogSets.GetSetInfo(set.setID)) or nil;
SetCollector:Print(set.setID.." "..(setInfo.name or nil))
end
end
end
end
function SetCollector:ListSetSources(setID)
local setInfo = (setID and C_TransmogSets.GetSetInfo(setID)) or nil;
local sources = C_TransmogSets.GetSetPrimaryAppearances(setID);
SetCollector:Print(setID.." "..(setInfo.name or nil))
local function position(slot)
if slot == INVSLOT_HEAD then
return 1
elseif slot == INVSLOT_SHOULDER then
return 2
elseif slot == INVSLOT_BACK then
return 3
elseif slot == INVSLOT_CHEST then
return 4
elseif slot == INVSLOT_WRIST then
return 5
elseif slot == INVSLOT_HAND then
return 6
elseif slot == INVSLOT_WAIST then
return 7
elseif slot == INVSLOT_LEGS then
return 8
elseif slot == INVSLOT_FEET then
return 9
end
return slot + 10
end
local printable = {}
for pos in pairs(sources) do
local searchKey = sources[pos].appearanceID
local sourceInfo = C_TransmogCollection.GetSourceInfo(searchKey);
if (sourceInfo) then
local slot = C_Transmog.GetSlotForInventoryType(sourceInfo.invType);
if (slot) then
printable[position(slot)] = sourceInfo.visualID..","..searchKey.." ("..slot..")"
else
printable[position(slot)] = sourceInfo.visualID..","..searchKey
end
else
SetCollector:Print("ID: "..searchKey.." (No sourceinfo)")
end
end
for i=1, #printable do
SetCollector:Print(printable[i])
end
end
local function BitAND(a,b)--Bitwise and
local p,c=1,0
while a>0 and b>0 do
local ra,rb=a%2,b%2
if ra+rb>1 then c=c+p end
a,b,p=(a-ra)/2,(b-rb)/2,p*2
end
return c
end
function ParseClassMask(bits)
-- 0 == All classes can wear
if bits == 0 then
return "ANY_CLASS"
end
local map = {
WARRIOR = 0x001,
PALADIN = 0x002,
HUNTER = 0x004,
ROGUE = 0x008,
PRIEST = 0x010,
DEATHKNIGHT = 0x020,
SHAMAN = 0x040,
MAGE = 0x080,
WARLOCK = 0x100,
MONK = 0x200,
DRUID = 0x400,
DEMONHUNTER = 0x800,
DRAKTHYR = 0x1000
}
-- Check for exact match between class
for char, mask in pairs(map) do
if bits == mask then
return char .. ""
end
end
-- Check for "any" match between class
local any_map = {
ANY_PLATE = 0x001 + 0x002 + 0x020,
ANY_LEATHER = 0x008 + 0x200 + 0x800 + 0x400,
ANY_CLOTH = 0x010 + 0x080 + 0x100,
ANY_MAIL = 0x004 + 0x040 + 0x1000
}
for char, mask in pairs(any_map) do
if bits == mask then
return "ANY_CLASS"
end
end
-- hmm, weird case, better itemize
local parse = bits .. ": "
for char, mask in pairs(map) do
if (BitAND(bits, mask) == mask) then
parse = parse .. char .. " "
end
end
return parse
end
function ParseArmorMask(bits)
-- 0 == All classes can wear
if bits == 0 then
return "ANY_ARMOR"
end
local map = {
PLATE = 0x001 + 0x002 + 0x020,
LEATHER = 0x008 + 0x200 + 0x800 + 0x400,
CLOTH = 0x010 + 0x080 + 0x100,
MAIL = 0x004 + 0x040 + 0x1000
}
local parse = bits .. ": "
for char, mask in pairs(map) do
if (BitAND(bits, mask) > 0) then
return char .. ""
end
end
-- hmm, weird case, better itemize
local parse = bits .. ": "
for char, mask in pairs(map) do
if (BitAND(bits, mask) == mask) then
parse = parse .. char .. " "
end
end
return parse .. ""
end
function SetCollector:ExportSetData()
local tree = {}
local exportTree = {}
local sets = C_TransmogSets.GetAllSets()
if (sets) then
for i, set in ipairs(sets) do
local setInfo = (set.setID and C_TransmogSets.GetSetInfo(set.setID)) or nil
if (setInfo == nil) then
-- SetCollector:Print("Skipping set "..set.setID)
else
local setID = setInfo.setID or 0
local baseSetID = set.baseSetID or setID
local collection = "(missing)"
if (SetCollector.db.global.setMap["SET " .. setID] ~= nil) then
collection = SetCollector.db.global.setMap["SET " .. setID].collection
end
local strArmorMask = ParseArmorMask(setInfo.classMask)
local strClassMask = ParseClassMask(setInfo.classMask)
local strFaction = string.upper(setInfo.requiredFaction or "ANY_FACTION")
local strDesc = (setInfo.description or "(blank)")
local strLabel = (setInfo.label or "(blank)")
if (tree[setInfo.patchID] == nil) then
tree[setInfo.patchID] = {}
end
if (tree[setInfo.patchID][collection] == nil) then
tree[setInfo.patchID][collection] = {}
end
if (tree[setInfo.patchID][collection][baseSetID] == nil) then
tree[setInfo.patchID][collection][baseSetID] = {}
tree[setInfo.patchID][collection][baseSetID][baseSetID] = ""
end
tree[setInfo.patchID][collection][baseSetID][setID] = strDesc
-- Build: IncludeSet(COLLECTION,11000,2601,ANY_ARMOR,DEATHKNIGHT,ANY_FACTION,2614,2615,2616), -- Haunted Frostbrood Remains
local heading = " -- " .. strLabel -- "Dragonflight Season 1"
local lua2 = {"IncludeSet(SetCollector." .. collection, setInfo.patchID, baseSetID, strArmorMask, strClassMask, strFaction}
local lua2comment = {"), -- " .. setInfo.name}
for tempId, desc in pairs(tree[setInfo.patchID][collection][baseSetID]) do
if (baseSetID ~= tempId) then
table.insert(lua2, tempId)
table.insert(lua2comment, desc)
end
end
lua2 = table.concat(lua2,",") .. table.concat(lua2comment,", ")
if (exportTree[setInfo.patchID] == nil) then
exportTree[setInfo.patchID] = {}
end
if (exportTree[setInfo.patchID][setInfo.patchID] == nil) then
exportTree[setInfo.patchID][setInfo.patchID] = {}
end
if (exportTree[setInfo.patchID][setInfo.patchID][heading] == nil) then
exportTree[setInfo.patchID][setInfo.patchID][heading] = {}
end
exportTree[setInfo.patchID][setInfo.patchID][heading][baseSetID] = lua2
end
end
end
SetCollector.db.global.export = exportTree
SetCollector:Print("Done exporting")
end
function SetCollector:MySlashProcessorFunc(input)
local command, parameters = input:match("^(%S*)%s*(.-)$")
if command == "" then
SetCollector:ToggleUI()
elseif command == "show" then
SetCollector:ShowUI()
elseif command == "hide" then
SetCollector:HideUI()
elseif command == "docked" then
SetCollector:SetUIDockedAndUpdate()
elseif command == "button" then
SetCollector:ToggleMinimapButton()
elseif command == "version" then
SetCollector:ToggleExpansion(parameters)
elseif command == "debug" then
SetCollector:OptionsSetDebug()
elseif command == "resetdb" then
SetCollector:ResetDB()
elseif command == "item" then
if (parameters) then
SetCollector:PrintItem(parameters)
end
elseif command == "export" then
SetCollector:ExportSetData()
elseif command == "set" then
if (parameters ~= nil) then
SetCollector:ListSet(parameters)
--elseif (parameters == "sources") then
-- SetCollector:ListSetSources(parameters)
end
elseif command == "sources" then
if (parameters ~= nil) then
SetCollector:ListSetSources(parameters)
end
elseif command == "sets" then
-- TODO: add parameters for count and starting setID (or pagination)
if (parameters == "all") then
SetCollector:ListAllSets()
else
SetCollector:ListBaseSets()
end
else
SetCollector:Print(L["SLASH_HELP"])
end
end