This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAuctionatorFilters.lua
executable file
·119 lines (101 loc) · 3.39 KB
/
AuctionatorFilters.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
--
-- Auctionator.Filters is an empty table on load, need to populate
-- with the possible filters
--
-- Here's what one entry looks like:
-- {
-- classID = integer (corresponding to ITEM_CLASS_IDS )
-- name = string (resolved by GetItemClassInfo( classID ))
-- filter = table (new QueryAuctionItems filterData format, { classID, subClassID (nil), inventoryType (nil) } )
-- subClasses = {
-- classID = integer (subClassID)
-- name = string (resolved by GetItemSubClassInfo( subClassID ))
-- filter = table (new QueryAuctionItems filterData format, { classID, subClassID, inventoryType (nil) } )
-- TODO: Probably want to use the inventoryType to create Armor slot filters as well...
-- }
-- }
local ITEM_CLASS_IDS = {
LE_ITEM_CLASS_WEAPON,
LE_ITEM_CLASS_ARMOR,
LE_ITEM_CLASS_CONTAINER,
LE_ITEM_CLASS_GEM,
LE_ITEM_CLASS_ITEM_ENHANCEMENT,
LE_ITEM_CLASS_CONSUMABLE,
LE_ITEM_CLASS_GLYPH,
LE_ITEM_CLASS_TRADEGOODS,
LE_ITEM_CLASS_RECIPE,
--LE_ITEM_CLASS_BATTLEPET,
LE_ITEM_CLASS_QUESTITEM,
LE_ITEM_CLASS_MISCELLANEOUS
}
Auctionator.Filter = {
classID = 0,
name = Auctionator.Constants.FilterDefault,
key = 0,
parentKey = nil,
filter = {},
subClasses = {}
}
-- TODO: Make this work, then can remove check in Atr_ASDD_Subclass_Initialize
-- Provides a null object for invalid lookups; intended use is for
-- rendering subclasses in Advanced Search UI
-- Auctionator.FilterLookup.__index = function()
-- return Auctionator.Filter:new()
-- end
function Auctionator.Filter.Find( key )
local filter = Auctionator.FilterLookup[ key ]
if filter == nil then
return Auctionator.Filter:new(), Auctionator.Filter:new()
elseif filter.parentKey == nil then
return filter, Auctionator.Filter:new()
else
return Auctionator.FilterLookup[ filter.parentKey ], filter
end
end
function Auctionator.Filter:new( options )
options = options or {}
setmetatable( options, self )
self.__index = self
return options
end
local function GenerateSubClasses( classID, parentName, parentKey )
local subClassesTable = { GetAuctionItemSubClasses( classID ) }
local subClasses = {}
local subFilters = {}
for index = 1, #subClassesTable do
local subClassID = subClassesTable[ index ]
local name = GetItemSubClassInfo( classID, subClassID )
local filter = { classID = classID, subClassID = subClassID }
local subClass = Auctionator.Filter:new({
classID = subClassID,
name = name,
key = parentKey .. [[/]] .. name,
parentKey = parentKey,
filter = { filter }
})
table.insert( subFilters, filter )
table.insert( subClasses, subClass )
end
return subClasses, subFilters
end
-- TODO: Will probably want to special case Armor for inventoryTypeFilters
for index, classID in ipairs( ITEM_CLASS_IDS ) do
local name = GetItemClassInfo( classID )
local key = name
local subClasses, filter = GenerateSubClasses( classID, name, key )
local categoryFilter = Auctionator.Filter:new({
classID = classID,
name = name,
key = key,
filter = filter,
subClasses = subClasses
})
table.insert( Auctionator.Filters, categoryFilter )
end
for index, filter in ipairs( Auctionator.Filters ) do
Auctionator.FilterLookup[ filter.key ] = filter
for i = 1, #filter.subClasses do
local subFilter = filter.subClasses[ i ]
Auctionator.FilterLookup[ subFilter.key ] = subFilter
end
end