refactoring
This commit is contained in:
@@ -100,16 +100,16 @@ function update_form()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function get_filter_builder_query()
|
function get_filter_builder_query()
|
||||||
local query_string
|
local filter_string
|
||||||
|
|
||||||
local function add(part)
|
local function add(part)
|
||||||
if part then
|
if part then
|
||||||
query_string = query_string and query_string..'/'..part or part
|
filter_string = filter_string and filter_string..'/'..part or part
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local name = blizzard_query.name
|
local name = blizzard_query.name
|
||||||
if not index(filter_util.parse_query_string(name), 'blizzard', 'name') then
|
if not index(filter_util.parse_filter_string(name), 'blizzard', 'name') then
|
||||||
name = filter_util.quote(name)
|
name = filter_util.quote(name)
|
||||||
end
|
end
|
||||||
add((name ~= '' or blizzard_query.exact) and name)
|
add((name ~= '' or blizzard_query.exact) and name)
|
||||||
@@ -134,10 +134,10 @@ function get_filter_builder_query()
|
|||||||
add(strlower(_G['ITEM_QUALITY'..quality..'_DESC']))
|
add(strlower(_G['ITEM_QUALITY'..quality..'_DESC']))
|
||||||
end
|
end
|
||||||
|
|
||||||
local post_filter_string = filter_util.query_string(temp-T('blizzard', tt, 'post', post_filter))
|
local post_filter_string = filter_util.filter_string(temp-T('blizzard', tt, 'post', post_filter))
|
||||||
add(post_filter_string ~= '' and post_filter_string)
|
add(post_filter_string ~= '' and post_filter_string)
|
||||||
|
|
||||||
return query_string or ''
|
return filter_string or ''
|
||||||
end
|
end
|
||||||
|
|
||||||
function set_form(components)
|
function set_form(components)
|
||||||
@@ -170,14 +170,14 @@ function clear_form()
|
|||||||
update_filter_display()
|
update_filter_display()
|
||||||
end
|
end
|
||||||
|
|
||||||
function import_query_string()
|
function import_filter_string()
|
||||||
local components, error = filter_util.parse_query_string(select(3, strfind(search_box:GetText(), '^([^;]*)')))
|
local components, error = filter_util.parse_filter_string(select(3, strfind(search_box:GetText(), '^([^;]*)')))
|
||||||
if components or log(error) then
|
if components or log(error) then
|
||||||
set_form(components)
|
set_form(components)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function export_query_string()
|
function export_filter_string()
|
||||||
search_box:SetText(get_filter_builder_query())
|
search_box:SetText(get_filter_builder_query())
|
||||||
filter_parameter_input:ClearFocus()
|
filter_parameter_input:ClearFocus()
|
||||||
end
|
end
|
||||||
@@ -265,7 +265,7 @@ function add_post_filter()
|
|||||||
str = str..'/'..filter_parameter_input:GetText()
|
str = str..'/'..filter_parameter_input:GetText()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local components, error, suggestions = filter_util.parse_query_string(str)
|
local components, error, suggestions = filter_util.parse_filter_string(str)
|
||||||
if components and getn(components.blizzard) == 0 and getn(components.post) == 1 then
|
if components and getn(components.blizzard) == 0 and getn(components.post) == 1 then
|
||||||
add_component(components.post[1])
|
add_component(components.post[1])
|
||||||
update_filter_display()
|
update_filter_display()
|
||||||
|
|||||||
@@ -327,7 +327,7 @@ function create_frames()
|
|||||||
gui.set_size(btn1, 80, 24)
|
gui.set_size(btn1, 80, 24)
|
||||||
btn1:SetText('Search')
|
btn1:SetText('Search')
|
||||||
btn1:SetScript('OnClick', function()
|
btn1:SetScript('OnClick', function()
|
||||||
export_query_string()
|
export_filter_string()
|
||||||
execute()
|
execute()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -335,13 +335,13 @@ function create_frames()
|
|||||||
btn2:SetPoint('LEFT', btn1, 'RIGHT', 5, 0)
|
btn2:SetPoint('LEFT', btn1, 'RIGHT', 5, 0)
|
||||||
gui.set_size(btn2, 80, 24)
|
gui.set_size(btn2, 80, 24)
|
||||||
btn2:SetText('Export')
|
btn2:SetText('Export')
|
||||||
btn2:SetScript('OnClick', export_query_string)
|
btn2:SetScript('OnClick', export_filter_string)
|
||||||
|
|
||||||
local btn3 = gui.button(frame.filter, 16)
|
local btn3 = gui.button(frame.filter, 16)
|
||||||
btn3:SetPoint('LEFT', btn2, 'RIGHT', 5, 0)
|
btn3:SetPoint('LEFT', btn2, 'RIGHT', 5, 0)
|
||||||
gui.set_size(btn3, 80, 24)
|
gui.set_size(btn3, 80, 24)
|
||||||
btn3:SetText('Import')
|
btn3:SetText('Import')
|
||||||
btn3:SetScript('OnClick', import_query_string)
|
btn3:SetScript('OnClick', import_filter_string)
|
||||||
end
|
end
|
||||||
do
|
do
|
||||||
local editbox = gui.editbox(frame.filter)
|
local editbox = gui.editbox(frame.filter)
|
||||||
@@ -515,7 +515,7 @@ function create_frames()
|
|||||||
input.change = function()
|
input.change = function()
|
||||||
local text = this:GetText()
|
local text = this:GetText()
|
||||||
if filter_util.filters[text] and filter_util.filters[text].input_type ~= '' then
|
if filter_util.filters[text] and filter_util.filters[text].input_type ~= '' then
|
||||||
local _, _, suggestions = filter_util.parse_query_string(text..'/')
|
local _, _, suggestions = filter_util.parse_filter_string(text..'/')
|
||||||
filter_parameter_input:SetNumeric(filter_util.filters[text].input_type == 'number')
|
filter_parameter_input:SetNumeric(filter_util.filters[text].input_type == 'number')
|
||||||
filter_parameter_input.complete = completion.complete(function() return suggestions or {} end)
|
filter_parameter_input.complete = completion.complete(function() return suggestions or {} end)
|
||||||
filter_parameter_input:Show()
|
filter_parameter_input:Show()
|
||||||
|
|||||||
+72
-74
@@ -117,8 +117,8 @@ public.filters = {
|
|||||||
validator = function(pct)
|
validator = function(pct)
|
||||||
return function(auction_record)
|
return function(auction_record)
|
||||||
return auction_record.unit_buyout_price > 0
|
return auction_record.unit_buyout_price > 0
|
||||||
and history.value(auction_record.item_key)
|
and aux.history.value(auction_record.item_key)
|
||||||
and auction_record.unit_buyout_price / history.value(auction_record.item_key) * 100 <= pct
|
and auction_record.unit_buyout_price / aux.history.value(auction_record.item_key) * 100 <= pct
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
@@ -128,8 +128,8 @@ public.filters = {
|
|||||||
validator = function(pct)
|
validator = function(pct)
|
||||||
return function(auction_record)
|
return function(auction_record)
|
||||||
return auction_record.unit_buyout_price > 0
|
return auction_record.unit_buyout_price > 0
|
||||||
and history.value(auction_record.item_key)
|
and aux.history.value(auction_record.item_key)
|
||||||
and auction_record.unit_buyout_price / history.value(auction_record.item_key) * 100 <= pct
|
and auction_record.unit_buyout_price / aux.history.value(auction_record.item_key) * 100 <= pct
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
@@ -138,7 +138,7 @@ public.filters = {
|
|||||||
input_type = 'money',
|
input_type = 'money',
|
||||||
validator = function(amount)
|
validator = function(amount)
|
||||||
return function(auction_record)
|
return function(auction_record)
|
||||||
return history.value(auction_record.item_key) and history.value(auction_record.item_key) * auction_record.aux_quantity - auction_record.bid_price >= amount
|
return aux.history.value(auction_record.item_key) and aux.history.value(auction_record.item_key) * auction_record.aux_quantity - auction_record.bid_price >= amount
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
@@ -147,7 +147,7 @@ public.filters = {
|
|||||||
input_type = 'money',
|
input_type = 'money',
|
||||||
validator = function(amount)
|
validator = function(amount)
|
||||||
return function(auction_record)
|
return function(auction_record)
|
||||||
return auction_record.buyout_price > 0 and history.value(auction_record.item_key) and history.value(auction_record.item_key) * auction_record.aux_quantity - auction_record.buyout_price >= amount
|
return auction_record.buyout_price > 0 and aux.history.value(auction_record.item_key) and aux.history.value(auction_record.item_key) * auction_record.aux_quantity - auction_record.buyout_price >= amount
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
@@ -156,7 +156,7 @@ public.filters = {
|
|||||||
input_type = 'money',
|
input_type = 'money',
|
||||||
validator = function(amount)
|
validator = function(amount)
|
||||||
return function(auction_record)
|
return function(auction_record)
|
||||||
local disenchant_value = disenchant.value(auction_record.slot, auction_record.quality, auction_record.level)
|
local disenchant_value = aux.disenchant.value(auction_record.slot, auction_record.quality, auction_record.level)
|
||||||
return disenchant_value and disenchant_value - auction_record.bid_price >= amount
|
return disenchant_value and disenchant_value - auction_record.bid_price >= amount
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -166,7 +166,7 @@ public.filters = {
|
|||||||
input_type = 'money',
|
input_type = 'money',
|
||||||
validator = function(amount)
|
validator = function(amount)
|
||||||
return function(auction_record)
|
return function(auction_record)
|
||||||
local disenchant_value = disenchant.value(auction_record.slot, auction_record.quality, auction_record.level)
|
local disenchant_value = aux.disenchant.value(auction_record.slot, auction_record.quality, auction_record.level)
|
||||||
return auction_record.buyout_price > 0 and disenchant_value and disenchant_value - auction_record.buyout_price >= amount
|
return auction_record.buyout_price > 0 and disenchant_value and disenchant_value - auction_record.buyout_price >= amount
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -223,10 +223,10 @@ do
|
|||||||
if self.exact then return end
|
if self.exact then return end
|
||||||
for number in present(tonumber(select(3, strfind(str, '^(%d+)$')))) do
|
for number in present(tonumber(select(3, strfind(str, '^(%d+)$')))) do
|
||||||
if number >= 1 and number <= 60 then
|
if number >= 1 and number <= 60 then
|
||||||
for filter in temp-set('min_level', 'max_level') do
|
for key in temp-set('min_level', 'max_level') do
|
||||||
if not self[filter] then
|
if not self[key] then
|
||||||
self[filter] = list(str, number)
|
self[key] = list(str, number)
|
||||||
return true
|
return list('blizzard', key, str, number)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -242,19 +242,18 @@ do
|
|||||||
local index, label = parser[2](select(3, unpack(parser)))
|
local index, label = parser[2](select(3, unpack(parser)))
|
||||||
if index then
|
if index then
|
||||||
self[parser[1]] = list(label, index)
|
self[parser[1]] = list(label, index)
|
||||||
return true
|
return list('blizzard', parser[1], label, index)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not self[str] and (str == 'usable' or str == 'exact' and self.name and size(self) == 1) then
|
if not self[str] and (str == 'usable' or str == 'exact' and self.name and size(self) == 1) then
|
||||||
self[str] = list(str, 1)
|
self[str] = list(str, 1)
|
||||||
|
return list('blizzard', str, 1)
|
||||||
elseif i == 1 and strlen(str) <= 63 then
|
elseif i == 1 and strlen(str) <= 63 then
|
||||||
self.name = list(str, unquote(str))
|
self.name = list(str, unquote(str))
|
||||||
|
return list('blizzard', 'name', str, unquote(str))
|
||||||
-- return nil, 'The name filter must not be longer than 63 characters' TODO
|
-- return nil, 'The name filter must not be longer than 63 characters' TODO
|
||||||
else
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
return true
|
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
function blizzard_filter_parser()
|
function blizzard_filter_parser()
|
||||||
@@ -276,8 +275,8 @@ function parse_parameter(input_type, str)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.parse_query_string(str)
|
function public.parse_filter_string(str)
|
||||||
local post_filter = t
|
local filter, post_filter = t, t
|
||||||
local blizzard_filter_parser = blizzard_filter_parser()
|
local blizzard_filter_parser = blizzard_filter_parser()
|
||||||
local parts = map(split(str, '/'), function(part) return strlower(trim(part)) end)
|
local parts = map(split(str, '/'), function(part) return strlower(trim(part)) end)
|
||||||
|
|
||||||
@@ -286,6 +285,7 @@ function public.parse_query_string(str)
|
|||||||
local operator = operator(parts[i])
|
local operator = operator(parts[i])
|
||||||
if operator then
|
if operator then
|
||||||
tinsert(post_filter, operator)
|
tinsert(post_filter, operator)
|
||||||
|
tinsert(filter, operator)
|
||||||
elseif filters[parts[i]] then
|
elseif filters[parts[i]] then
|
||||||
local input_type = filters[parts[i]].input_type
|
local input_type = filters[parts[i]].input_type
|
||||||
if input_type ~= '' then
|
if input_type ~= '' then
|
||||||
@@ -303,9 +303,14 @@ function public.parse_query_string(str)
|
|||||||
else
|
else
|
||||||
tinsert(post_filter, list('filter', parts[i]))
|
tinsert(post_filter, list('filter', parts[i]))
|
||||||
end
|
end
|
||||||
elseif not blizzard_filter_parser(parts[i], i) then
|
tinsert(filter, post_filter[getn(post_filter)])
|
||||||
if parts[i] ~= '' then
|
else
|
||||||
|
local part = blizzard_filter_parser(parts[i], i)
|
||||||
|
if part then
|
||||||
|
tinsert(filter, part)
|
||||||
|
elseif parts[i] ~= '' then
|
||||||
tinsert(post_filter, list('filter', 'tooltip', parts[i]))
|
tinsert(post_filter, list('filter', 'tooltip', parts[i]))
|
||||||
|
tinsert(filter, post_filter[getn(post_filter)])
|
||||||
else
|
else
|
||||||
return nil, 'Empty modifier'
|
return nil, 'Empty modifier'
|
||||||
end
|
end
|
||||||
@@ -313,18 +318,18 @@ function public.parse_query_string(str)
|
|||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
return T('blizzard', blizzard_filter_parser(), 'post', post_filter)
|
return T('all', filter, 'blizzard', blizzard_filter_parser(), 'post', post_filter)
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.query(query_string)
|
function public.query(filter_string)
|
||||||
local components, error, suggestions = parse_query_string(query_string)
|
local filter, error, suggestions = parse_filter_string(filter_string)
|
||||||
|
|
||||||
if not components then
|
if not filter then
|
||||||
return nil, suggestions or t, error
|
return nil, suggestions or t, error
|
||||||
end
|
end
|
||||||
|
|
||||||
local polish_notation_counter = 0
|
local polish_notation_counter = 0
|
||||||
for _, component in components.post do
|
for _, component in filter.post do
|
||||||
if component[1] == 'operator' then
|
if component[1] == 'operator' then
|
||||||
polish_notation_counter = max(polish_notation_counter, 1)
|
polish_notation_counter = max(polish_notation_counter, 1)
|
||||||
polish_notation_counter = polish_notation_counter + (tonumber(component[2]) or 1) - 1
|
polish_notation_counter = polish_notation_counter + (tonumber(component[2]) or 1) - 1
|
||||||
@@ -345,14 +350,14 @@ function public.query(query_string)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
blizzard_query = blizzard_query(components),
|
blizzard_query = blizzard_query(filter),
|
||||||
validator = validator(components),
|
validator = validator(filter),
|
||||||
prettified = prettified_query_string(components),
|
prettified = prettified_filter_string(filter),
|
||||||
}, M.suggestions(components)
|
}, M.suggestions(filter)
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.queries(query_string)
|
function public.queries(filter_string)
|
||||||
local parts = split(query_string, ';')
|
local parts = split(filter_string, ';')
|
||||||
local queries = t
|
local queries = t
|
||||||
for _, str in parts do
|
for _, str in parts do
|
||||||
str = trim(str)
|
str = trim(str)
|
||||||
@@ -367,44 +372,44 @@ function public.queries(query_string)
|
|||||||
return queries
|
return queries
|
||||||
end
|
end
|
||||||
|
|
||||||
function suggestions(components)
|
function suggestions(filter)
|
||||||
local suggestions = t
|
local suggestions = t
|
||||||
|
|
||||||
if components.blizzard.name and size(components.blizzard) == 1 then tinsert(suggestions, 'exact') end
|
if filter.blizzard.name and size(filter.blizzard) == 1 then tinsert(suggestions, 'exact') end
|
||||||
|
|
||||||
tinsert(suggestions, 'and'); tinsert(suggestions, 'or'); tinsert(suggestions, 'not'); tinsert(suggestions, 'tooltip')
|
tinsert(suggestions, 'and'); tinsert(suggestions, 'or'); tinsert(suggestions, 'not'); tinsert(suggestions, 'tooltip')
|
||||||
|
|
||||||
for key in filters do tinsert(suggestions, key) end
|
for key in filters do tinsert(suggestions, key) end
|
||||||
|
|
||||||
-- classes
|
-- classes
|
||||||
if not components.blizzard.class then
|
if not filter.blizzard.class then
|
||||||
for _, class in temp-{GetAuctionItemClasses()} do tinsert(suggestions, class) end
|
for _, class in temp-list(GetAuctionItemClasses()) do tinsert(suggestions, class) end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- subclasses
|
-- subclasses
|
||||||
if not components.blizzard.subclass then
|
if not filter.blizzard.subclass then
|
||||||
for _, subclass in temp-{GetAuctionItemSubClasses(index(components.blizzard.class, 2) or 0)} do
|
for _, subclass in temp-list(GetAuctionItemSubClasses(index(filter.blizzard.class, 2) or 0)) do
|
||||||
tinsert(suggestions, subclass)
|
tinsert(suggestions, subclass)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- slots
|
-- slots
|
||||||
if not components.blizzard.slot then
|
if not filter.blizzard.slot then
|
||||||
for _, invtype in temp-{GetAuctionInvTypes(index(components.blizzard.class, 2) or 0, index(components.blizzard.subclass, 2) or 0)} do
|
for _, invtype in temp-list(GetAuctionInvTypes(index(filter.blizzard.class, 2) or 0, index(filter.blizzard.subclass, 2) or 0)) do
|
||||||
tinsert(suggestions, _G[invtype])
|
tinsert(suggestions, _G[invtype])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- usable
|
-- usable
|
||||||
if not components.blizzard.usable then tinsert(suggestions, 'usable') end
|
if not filter.blizzard.usable then tinsert(suggestions, 'usable') end
|
||||||
|
|
||||||
-- rarities
|
-- rarities
|
||||||
if not components.blizzard.quality then
|
if not filter.blizzard.quality then
|
||||||
for i = 0, 4 do tinsert(suggestions, _G['ITEM_QUALITY'..i..'_DESC']) end
|
for i = 0, 4 do tinsert(suggestions, _G['ITEM_QUALITY'..i..'_DESC']) end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- item names
|
-- item names
|
||||||
if size(components.blizzard) + getn(components.post) == 1 and components.blizzard.name == '' then
|
if getn(filter.all) == 0 and filter.blizzard.name == '' then -- TODO
|
||||||
for _, name in _G.aux_auctionable_items do
|
for _, name in _G.aux_auctionable_items do
|
||||||
tinsert(suggestions, name..'/exact')
|
tinsert(suggestions, name..'/exact')
|
||||||
end
|
end
|
||||||
@@ -413,15 +418,13 @@ function suggestions(components)
|
|||||||
return suggestions
|
return suggestions
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.query_string(components)
|
function public.filter_string(filter)
|
||||||
local query_builder = query_builder()
|
local query_builder = query_builder()
|
||||||
|
|
||||||
for _, filter in components.blizzard do
|
for _, component in filter.all do
|
||||||
query_builder.append(filter[2] or filter[1])
|
if component[1] == 'blizzard' then
|
||||||
end
|
query_builder.append(filter[4] or filter[3])
|
||||||
|
elseif component[1] == 'operator' then
|
||||||
for _, component in components.post do
|
|
||||||
if component[1] == 'operator' then
|
|
||||||
query_builder.append(component[2]..(component[2] ~= 'not' and tonumber(component[3]) or ''))
|
query_builder.append(component[2]..(component[2] ~= 'not' and tonumber(component[3]) or ''))
|
||||||
elseif component[1] == 'filter' then
|
elseif component[1] == 'filter' then
|
||||||
query_builder.append(component[2])
|
query_builder.append(component[2])
|
||||||
@@ -437,23 +440,21 @@ function public.query_string(components)
|
|||||||
return query_builder.get()
|
return query_builder.get()
|
||||||
end
|
end
|
||||||
|
|
||||||
function prettified_query_string(components)
|
function prettified_filter_string(filter)
|
||||||
local prettified = query_builder()
|
local prettified = query_builder()
|
||||||
|
|
||||||
for key, filter in components.blizzard do
|
for _, component in filter.all do
|
||||||
if key == 'exact' then
|
if component[1] == 'blizzard' then
|
||||||
prettified.prepend(info.display_name(aux.cache.item_id(components.blizzard.name[2])) or color.blizzard('['..components.blizzard.name[2]..']'))
|
if component[2] == 'name' then
|
||||||
elseif key ~= 'name' then
|
if filter.blizzard.exact then
|
||||||
prettified.append(color.blizzard(filter[1]))
|
prettified.append(info.display_name(aux.cache.item_id(component[4])) or color.blizzard('['..component[4]..']'))
|
||||||
end
|
else
|
||||||
end
|
prettified.append(color.blizzard(component[4]))
|
||||||
|
end
|
||||||
if components.blizzard.name and not components.blizzard.exact and components.blizzard.name[2] ~= '' then
|
elseif component[2] ~= 'exact' then
|
||||||
prettified.prepend(color.blizzard(components.blizzard.name[2]))
|
prettified.append(color.blizzard(component[3]))
|
||||||
end
|
end
|
||||||
|
elseif component[1] == 'operator' then
|
||||||
for _, component in components.post do
|
|
||||||
if component[1] == 'operator' then
|
|
||||||
prettified.append(color.aux(component[2]..(component[2] ~= 'not' and tonumber(component[3]) or '')))
|
prettified.append(color.aux(component[2]..(component[2] ~= 'not' and tonumber(component[3]) or '')))
|
||||||
elseif component[1] == 'filter' then
|
elseif component[1] == 'filter' then
|
||||||
if component[2] ~= 'tooltip' then
|
if component[2] ~= 'tooltip' then
|
||||||
@@ -487,11 +488,9 @@ function public.unquote(name)
|
|||||||
return select(3, strfind(name, '^<(.*)>$')) or name
|
return select(3, strfind(name, '^<(.*)>$')) or name
|
||||||
end
|
end
|
||||||
|
|
||||||
function blizzard_query(components)
|
function blizzard_query(filter)
|
||||||
local filters = components.blizzard
|
local filters = filter.blizzard
|
||||||
|
|
||||||
local query = T('name', filters.name and filters.name[2])
|
local query = T('name', filters.name and filters.name[2])
|
||||||
|
|
||||||
local item_info, class_index, subclass_index, slot_index
|
local item_info, class_index, subclass_index, slot_index
|
||||||
local item_id = filters.name and aux.cache.item_id(filters.name[2])
|
local item_id = filters.name and aux.cache.item_id(filters.name[2])
|
||||||
item_info = item_id and info.item(item_id)
|
item_info = item_id and info.item(item_id)
|
||||||
@@ -501,7 +500,6 @@ function blizzard_query(components)
|
|||||||
subclass_index = info.item_subclass_index(class_index or 0, item_info.subclass)
|
subclass_index = info.item_subclass_index(class_index or 0, item_info.subclass)
|
||||||
slot_index = info.item_slot_index(class_index or 0, subclass_index or 0, item_info.slot)
|
slot_index = info.item_slot_index(class_index or 0, subclass_index or 0, item_info.slot)
|
||||||
end
|
end
|
||||||
|
|
||||||
if item_info then
|
if item_info then
|
||||||
query.min_level = item_info.level
|
query.min_level = item_info.level
|
||||||
query.max_level = item_info.level
|
query.max_level = item_info.level
|
||||||
@@ -518,10 +516,10 @@ function blizzard_query(components)
|
|||||||
return query
|
return query
|
||||||
end
|
end
|
||||||
|
|
||||||
function validator(components)
|
function validator(filter)
|
||||||
|
|
||||||
local validators = t
|
local validators = t
|
||||||
for i, component in components.post do
|
for i, component in filter.post do
|
||||||
local type, name, param = unpack(component)
|
local type, name, param = unpack(component)
|
||||||
if type == 'filter' then
|
if type == 'filter' then
|
||||||
validators[i] = filters[name].validator(parse_parameter(filters[name].input_type, param))
|
validators[i] = filters[name].validator(parse_parameter(filters[name].input_type, param))
|
||||||
@@ -529,12 +527,12 @@ function validator(components)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return function(record)
|
return function(record)
|
||||||
if components.blizzard.exact and strlower(info.item(record.item_id).name) ~= components.blizzard.name[2] then
|
if filter.blizzard.exact and strlower(info.item(record.item_id).name) ~= filter.blizzard.name[2] then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local stack = tt
|
local stack = tt
|
||||||
for i = getn(components.post), 1, -1 do
|
for i = getn(filter.post), 1, -1 do
|
||||||
local type, name, param = unpack(components.post[i])
|
local type, name, param = unpack(filter.post[i])
|
||||||
if type == 'operator' then
|
if type == 'operator' then
|
||||||
local args = tt
|
local args = tt
|
||||||
while (not param or param > 0) and getn(stack) > 0 do
|
while (not param or param > 0) and getn(stack) > 0 do
|
||||||
|
|||||||
Reference in New Issue
Block a user