forked from Tuller/LibItemSearch-1.0
-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFilters.lua
216 lines (173 loc) · 6.11 KB
/
Filters.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
--[[
Copyright 2013-2025 João Cardoso
ItemSearch is distributed under the terms of the GNU General Public License (Version 3).
As a special exception, the copyright holders of this library give you permission to embed it
with independent modules to produce an addon, regardless of the license terms of these
independent modules, and to copy and distribute the resulting software under terms of your
choice, provided that you also meet, for each embedded independent module, the terms and
conditions of the license of that module. Permission is not granted to modify this library.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This file is part of ItemSearch.
--]]
local Lib = LibStub('ItemSearch-1.3')
if Lib.Filters then return end
local C = LibStub('C_Everywhere')
local Parser = LibStub('CustomSearch-1.0')
local inRetail = C_TooltipInfo and true
--[[ Baseline ]]--
Lib.Filters = {}
Lib.Filters.tooltip = {
tags = {'t', 'tip', 'tooltip'},
onlyTags = not C_TooltipInfo,
canSearch = function(self, operator, search)
return not operator and search
end,
match = function(self, item, _, search)
local where = item.location
local data = where and (where.bagID and C.TooltipInfo.GetBagItem(where.bagID, where.slotIndex) or
where.equipmentSlotIndex and C.TooltipInfo.GetInventoryItem(where.unitID or 'player', where.equipmentSlotIndex))
or C.TooltipInfo.GetHyperlink(item.link)
if data then
for i, line in ipairs(data.lines) do
if Parser:Find(search, line.leftText) then
return true
end
end
end
end
}
Lib.Filters.class = {
tags = {'c', 'class'},
canSearch = function(self, operator, search)
return not operator and search
end,
match = function(self, item, _, search)
local class, subClass = select(6, C.Item.GetItemInfo(item.link))
return Parser:Find(search, class, subClass)
end
}
Lib.Filters.level = {
tags = {'l', 'level', 'lvl', 'ilvl'},
canSearch = function(self, operator, search)
return (operator or not inRetail) and tonumber(search)
end,
match = function(self, item, operator, num)
local lvl = item.location and C.Item.GetCurrentItemLevel(item.location)
or select(4, C.Item.GetItemInfo(item.link))
if lvl then
return Parser:Compare(operator, lvl, num)
end
end
}
Lib.Filters.requiredlevel = {
tags = {'r', 'req', 'rl', 'reql', 'reqlvl'},
canSearch = function(self, operator, search)
return (operator or not inRetail) and tonumber(search)
end,
match = function(self, item, operator, num)
local lvl = select(5, C.Item.GetItemInfo(item.link))
if lvl then
return Parser:Compare(operator, lvl, num)
end
end
}
Lib.Filters.bind = {
keywords = {
bop = LE_ITEM_BIND_ON_ACQUIRE,
boe = LE_ITEM_BIND_ON_EQUIP,
bou = LE_ITEM_BIND_ON_USE,
boq = LE_ITEM_BIND_QUEST,
},
canSearch = function(self, operator, search)
return not operator and self.keywords[search]
end,
match = function(self, item, _, target)
return target == select(14, C.Item.GetItemInfo(item.link))
end
}
Lib.Filters.quality = {
tags = {'q', 'quality', 'rarity'},
keywords = {},
canSearch = function(self, _, search)
for quality, name in pairs(self.keywords) do
if Parser:Find(search, name) then
return quality
end
end
end,
match = function(self, item, operator, target)
local quality = item.link:find('battlepet') and tonumber(item.link:match('%d+:%d+:(%d+)'))
or C.Item.GetItemQualityByID(item.link)
return Parser:Compare(operator, quality, target)
end,
}
for i = 0, #ITEM_QUALITY_COLORS do
Lib.Filters.quality.keywords[i] = _G['ITEM_QUALITY' .. i .. '_DESC']:lower()
end
if LE_EXPANSION_LEVEL_CURRENT > 0 then
Lib.Filters.expansion = {
tags = {'e', 'expac', 'expansion'},
keywords = {},
canSearch = function(self, operator, search)
for expac, name in pairs(self.keywords) do
if Parser:Find(search, name) then
return expac
end
end
end,
match = function(self, item, operator, target)
local expac = select(15, C.Item.GetItemInfo(item.link))
return Parser:Compare(operator, expac, target)
end
}
for i = 0, NUM_LE_EXPANSION_LEVELS do
Lib.Filters.expansion.keywords[i] = _G['EXPANSION_NAME' .. i]:lower()
end
end
--[[ Classic Fallbacks ]]--
Lib.Filters.name = {
tags = {'n', 'name'},
onlyTags = inRetail,
canSearch = function(self, operator, search)
return not operator and search
end,
match = function(self, item, _, search)
return Parser:Find(search, C.Item.GetItemNameByID(item.link) or item.link:match('%[(.+)%]'))
end
}
Lib.Filters.slot = {
tags = {'s', 'slot'},
onlyTags = inRetail,
canSearch = function(self, operator, search)
return not operator and search
end,
match = function(self, item, _, search)
local equipSlot = select(9, C.Item.GetItemInfo(item.link))
return Parser:Find(search, _G[equipSlot])
end
}
Lib.Filters.bound = {
onlyTags = inRetail,
canSearch = function(self, operator, search)
return not operator and Parser:Find(search, ITEM_SOULBOUND)
end,
match = function(self, item)
return item.location and C.Item.IsBound(item.location)
end
}
Lib.Filters.sets = {
tags = {'s', 'set'},
onlyTags = inRetail,
canSearch = function(self, operator, search)
return not operator and search
end,
match = function(self, item, _, search)
local id = item.link:match('item:(%d+)')
if id then
return Lib:BelongsToSet(tonumber(id), search)
end
end
}