working on basic functionality for the new filter search tab
This commit is contained in:
+148
-9
@@ -10,16 +10,19 @@ function m.find(test, query, page, status_bar, on_failure, on_success)
|
||||
|
||||
local pages = page > 0 and { page, page - 1 } or { page }
|
||||
|
||||
query = Aux.util.copy_table(query)
|
||||
query.start_page = nil
|
||||
query.next_page = function()
|
||||
if getn(pages) == 1 then
|
||||
status_bar:update_status(50, 50)
|
||||
local new_query = {
|
||||
type = query.type,
|
||||
validator = test,
|
||||
blizzard_query = query.blizzard_query,
|
||||
next_page = function()
|
||||
if getn(pages) == 1 then
|
||||
status_bar:update_status(50, 50)
|
||||
end
|
||||
local page = pages[1]
|
||||
tremove(pages, 1)
|
||||
return page
|
||||
end
|
||||
local page = pages[1]
|
||||
tremove(pages, 1)
|
||||
return page
|
||||
end
|
||||
}
|
||||
|
||||
Aux.scan.start{
|
||||
queries = { query },
|
||||
@@ -47,6 +50,9 @@ end
|
||||
function m.create_item_query(item_id, type, start_page, next_page)
|
||||
local item_info = Aux.static.item_info(item_id)
|
||||
|
||||
local function validator(auction_info)
|
||||
return auction_info.item_id == item_id
|
||||
end
|
||||
-- local class_index = Aux.item_class_index(item_info.class)
|
||||
-- local subclass_index = class_index and Aux.item_subclass_index(class_index, item_info.subclass) -- TODO test if needed
|
||||
|
||||
@@ -65,4 +71,137 @@ function m.create_item_query(item_id, type, start_page, next_page)
|
||||
quality = item_info.quality,
|
||||
usable = item_info.usable,
|
||||
}
|
||||
end
|
||||
|
||||
function m.parse_filter_string(filter_string)
|
||||
local parts = {Aux.persistence.deserialize(filter_string, ';')}
|
||||
|
||||
local filters = {}
|
||||
for _, str in ipairs(parts) do
|
||||
str = Aux.util.trim(str)
|
||||
if tonumber(str) then
|
||||
local filter = Aux.scan_util.create_item_query(tonumber(str))
|
||||
if filter then
|
||||
tinsert(filters, filter)
|
||||
end
|
||||
else
|
||||
local filter, error = m.filter(str)
|
||||
|
||||
if not filter then
|
||||
Aux.log('Invalid filter: '..error)
|
||||
elseif strlen(filter.query_string) > 63 then
|
||||
|
||||
else
|
||||
tinsert(filters, filter)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return filters
|
||||
end
|
||||
|
||||
function m.filter(filter_term)
|
||||
local parts = {Aux.persistence.deserialize(filter_term, '/')}
|
||||
local query_string, class, subclass, min_level, max_level, quality, usable_only, exact_only, even_only, min_profit, max_percentage
|
||||
|
||||
if getn(parts) == 0 then
|
||||
return false, 'Invalid Filter'
|
||||
end
|
||||
|
||||
for i, str in ipairs(parts) do
|
||||
str = Aux.util.trim(str)
|
||||
|
||||
if tonumber(str) then
|
||||
if not min_level then
|
||||
min_level = tonumber(str)
|
||||
elseif not max_level then
|
||||
max_level = tonumber(str)
|
||||
else
|
||||
return false, 'Invalid Min Level'
|
||||
end
|
||||
elseif not class and Aux.item_class_index(str) then
|
||||
if not class then
|
||||
class = Aux.item_class_index(str)
|
||||
else
|
||||
return false, 'Invalid Item Type'
|
||||
end
|
||||
elseif Aux.item_subclass_index(class, str) then
|
||||
if not subclass then
|
||||
subclass = Aux.item_subclass_index(class, str)
|
||||
else
|
||||
return false, 'Invalid Item SubType'
|
||||
end
|
||||
elseif Aux.item_quality_index(str) then
|
||||
if not quality then
|
||||
quality = Aux.item_quality_index(str)
|
||||
else
|
||||
return false, 'Invalid Item Rarity'
|
||||
end
|
||||
elseif strlower(str) == 'usable' then
|
||||
if not usable_only then
|
||||
usable_only = true
|
||||
else
|
||||
return false, 'Invalid Usable Only Filter'
|
||||
end
|
||||
elseif strlower(str) == 'exact' then
|
||||
if not exact_only then
|
||||
exact_only = true
|
||||
else
|
||||
return false, 'Invalid Exact Only Filter'
|
||||
end
|
||||
elseif strlower(str) == 'even' then
|
||||
if not even_only then
|
||||
even_only = true
|
||||
else
|
||||
return false, 'Invalid Even Only Filter'
|
||||
end
|
||||
elseif Aux.money.from_string(str) then
|
||||
min_profit = Aux.money.from_string(str)
|
||||
elseif i == 1 then
|
||||
query_string = str
|
||||
else
|
||||
return false, 'Unknown Filter'
|
||||
end
|
||||
end
|
||||
|
||||
min_level, max_level = min(min_level, max_level), max(min_level, max_level)
|
||||
|
||||
return { query_string or '', class or 0, subclass or 0, min_level or 0, max_level or 0, quality or 0, usable_only or 0, exact_only or nil, even_only or nil, min_profit }
|
||||
end
|
||||
|
||||
function m.blizzard_query(filter)
|
||||
return {
|
||||
name = filter.query_string,
|
||||
min_level = filter.min_level,
|
||||
max_level = filter.max_level,
|
||||
slot = filter.slot,
|
||||
class = filter.class,
|
||||
subclass = filter.subclass,
|
||||
usable = filter.usable_only,
|
||||
quality = filter.quality,
|
||||
}
|
||||
end
|
||||
|
||||
function m.validator(filter)
|
||||
|
||||
return function(record)
|
||||
|
||||
if filter.exact_only and record.name ~= record.name then
|
||||
return
|
||||
end
|
||||
|
||||
if filter.even_only and rem(record.aux_quantity, 5) ~= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
if filter.min_level > 0 and record.level < record.min_level then
|
||||
return
|
||||
end
|
||||
|
||||
if filter.max_level > 0 and record.level > record.max_level then
|
||||
return
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user