diff --git a/filter_search_frame.lua b/filter_search_frame.lua index b155ef7..51d62df 100644 --- a/filter_search_frame.lua +++ b/filter_search_frame.lua @@ -697,6 +697,31 @@ function public.set_view(view) refresh = true end +function private.create_filter_query() + local category = UIDropDownMenu_GetSelectedValue(AuxFilterSearchFrameFiltersCategoryDropDown) + + return { + type = 'list', + start_page = AuxFilterSearchFrameFiltersAllPagesCheckButton:GetChecked() and 0 or AuxFilterSearchFrameFiltersPageEditBox:GetNumber(), + next_page = function(page, total_pages) + if AuxFilterSearchFrameFiltersAllPagesCheckButton:GetChecked() then + local last_page = max(total_pages - 1, 0) + if page < last_page then + return page + 1 + end + end + end, + name = AuxFilterSearchFrameFiltersNameInputBox:GetText(), + min_level = AuxFilterSearchFrameFiltersMinLevel:GetText(), + max_level = AuxFilterSearchFrameFiltersMaxLevel:GetText(), + slot = category and category.slot, + class = category and category.class, + subclass = category and category.subclass, + quality = UIDropDownMenu_GetSelectedValue(AuxFilterSearchFrameFiltersQualityDropDown), + usable = AuxFilterSearchFrameFiltersUsableCheckButton:GetChecked() + } +end + function public.start_search() Aux.scan.abort(function() @@ -713,7 +738,6 @@ function public.start_search() refresh = true - local category = UIDropDownMenu_GetSelectedValue(AuxFilterSearchFrameFiltersCategoryDropDown) local tooltip_patterns = {} for i=1,4 do local tooltip_pattern = getglobal('AuxFilterSearchFrameFiltersTooltipInputBox'..i):GetText() @@ -722,40 +746,49 @@ function public.start_search() end end - local query = { - type = 'list', - start_page = AuxFilterSearchFrameFiltersAllPagesCheckButton:GetChecked() and 0 or AuxFilterSearchFrameFiltersPageEditBox:GetNumber(), - next_page = function(page, total_pages) - if AuxFilterSearchFrameFiltersAllPagesCheckButton:GetChecked() then - local last_page = max(total_pages - 1, 0) - if page < last_page then - return page + 1 + local group = Aux.groups.parse_group(Aux.groups.test_group) + + local queries + + if false then + queries = { private.create_filter_query() } + else + queries = Aux.util.map(group, function(item_key) + return Aux.scan_util.create_item_query( + Aux.groups.parse_item_key(item_key), + 'list', + 0, + function(page, total_pages) + local last_page = max(total_pages - 1, 0) + if page < last_page then + return page + 1 + end end - end - end, - name = AuxFilterSearchFrameFiltersNameInputBox:GetText(), - min_level = AuxFilterSearchFrameFiltersMinLevel:GetText(), - max_level = AuxFilterSearchFrameFiltersMaxLevel:GetText(), - slot = category and category.slot, - class = category and category.class, - subclass = category and category.subclass, - quality = UIDropDownMenu_GetSelectedValue(AuxFilterSearchFrameFiltersQualityDropDown), - usable = AuxFilterSearchFrameFiltersUsableCheckButton:GetChecked() - } + ) + end) + end + Aux.scan.start{ - queries = { query }, - on_submit_query = function() - current_page = nil - end, + queries = queries, on_page_loaded = function(page, total_pages) - private.status_bar:update_status(100 * (page + 1) / total_pages, 100 * (page + 1) / total_pages) -- TODO + private.status_bar:update_status(100 * (page + 1) / total_pages) -- TODO private.status_bar:set_text(format('Scanning (Page %d / %d)', page + 1, total_pages)) end, + on_start_query = function(query_index) + private.status_bar:update_status(0, 100 * query_index / getn(queries)) -- TODO + private.status_bar:set_text(format('Processing query %d / %d', query_index, getn(queries))) + end, on_read_auction = function(auction_info) - if Aux.info.tooltip_match(tooltip_patterns, auction_info.tooltip) then - auctions = auctions or {} - tinsert(auctions, private.create_auction_record(auction_info)) + auctions = auctions or {} + if false then + if Aux.info.tooltip_match(tooltip_patterns, auction_info.tooltip) then + tinsert(auctions, private.create_auction_record(auction_info)) + end + else + if Aux.util.any(group, function(item_key) return auction_info.item_id == Aux.groups.parse_item_key(item_key) end) then + tinsert(auctions, private.create_auction_record(auction_info)) + end end end, on_complete = function() diff --git a/groups.lua b/groups.lua index d15d96b..4ec283a 100644 --- a/groups.lua +++ b/groups.lua @@ -1,3 +1,14 @@ -function load_group(datastring) - local item_keys = Aux.persistence.deserialize(datastring, ',') -end \ No newline at end of file +local m = {} +Aux.groups = m + + +function m.parse_group(datastring) + return Aux.persistence.deserialize(datastring, ',') +end + +function m.parse_item_key(item_key) + local _, _, item_id, suffix_id = strfind(item_key, '(%d+):?(%d*)') + return tonumber(item_id), suffix_id == '' and 0 or tonumber(suffix_id) +end + +m.test_group = '13127,9510,4438,16254,12006,13131,13012,4413,1482' \ No newline at end of file diff --git a/scan.lua b/scan.lua index 18f1fa7..7cd49cf 100644 --- a/scan.lua +++ b/scan.lua @@ -114,11 +114,15 @@ end function private.scan() + local start_query_index = state.params.start_query_index or 1 + local next_query_index = state.params.next_query_index or function(query_index) return query_index + 1 end - state.query_index = state.query_index and state.query_index + 1 or 1 + state.query_index = state.query_index and next_query_index(state.query_index) or start_query_index if current_query() then - state.page = current_query().start_page - return private.process_query() + wait_for_callback{state.params.on_start_query or Aux.util.pass, state.query_index, function() + state.page = current_query().start_page + return private.process_query() + end } else local on_complete = state.params.on_complete state = nil @@ -128,7 +132,6 @@ function private.scan() end end - function private.process_query() submit_query(function() diff --git a/scan_util.lua b/scan_util.lua index 98621e5..bd161bc 100644 --- a/scan_util.lua +++ b/scan_util.lua @@ -11,6 +11,7 @@ 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)