working on big scan/control refactoring
This commit is contained in:
+3
-3
@@ -97,9 +97,9 @@ function public.scan_auctions()
|
||||
selected_auction = nil
|
||||
private.update_listing()
|
||||
Aux.scan.start{
|
||||
type = 'owner',
|
||||
queries = {
|
||||
{
|
||||
type = 'owner',
|
||||
start_page = 0,
|
||||
}
|
||||
},
|
||||
@@ -144,7 +144,7 @@ function private.find_auction_and_cancel(record)
|
||||
return
|
||||
end
|
||||
|
||||
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
|
||||
Aux.scan_util.find(record, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
|
||||
if Aux.util.index_of(record, auction_records) then
|
||||
CancelAuction(index)
|
||||
private.record_remover(record)()
|
||||
@@ -162,7 +162,7 @@ do
|
||||
|
||||
found_index = nil
|
||||
|
||||
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
|
||||
Aux.scan_util.find(record, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
|
||||
|
||||
found_index = index
|
||||
|
||||
|
||||
+3
-3
@@ -117,9 +117,9 @@ function public.scan_bids()
|
||||
selected_auction = nil
|
||||
private.update_listing()
|
||||
Aux.scan.start{
|
||||
type = 'bidder',
|
||||
queries = {
|
||||
{
|
||||
type = 'bidder',
|
||||
start_page = 0,
|
||||
}
|
||||
},
|
||||
@@ -164,7 +164,7 @@ function private.find_auction_and_bid(record, buyout_mode)
|
||||
return
|
||||
end
|
||||
|
||||
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
|
||||
Aux.scan_util.find(record, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
|
||||
if Aux.util.index_of(record, auction_records) then
|
||||
Aux.place_bid('bidder', index, buyout_mode and record.buyout_price or record.bid_price, private.record_remover(record))
|
||||
end
|
||||
@@ -181,7 +181,7 @@ do
|
||||
|
||||
found_index = nil
|
||||
|
||||
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
|
||||
Aux.scan_util.find(record, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
|
||||
|
||||
found_index = index
|
||||
|
||||
|
||||
@@ -203,35 +203,31 @@ function Aux.on_auction_house_closed()
|
||||
end
|
||||
|
||||
function Aux.on_tab_click(index)
|
||||
Aux.post.stop()
|
||||
Aux.stack.stop()
|
||||
Aux.scan.abort(function()
|
||||
Aux.search_frame.on_close()
|
||||
Aux.post_frame.on_close()
|
||||
Aux.auctions_frame.on_close()
|
||||
Aux.bids_frame.on_close()
|
||||
Aux.search_frame.on_close()
|
||||
Aux.post_frame.on_close()
|
||||
Aux.auctions_frame.on_close()
|
||||
Aux.bids_frame.on_close()
|
||||
|
||||
AuxSearchFrame:Hide()
|
||||
AuxPostFrame:Hide()
|
||||
AuxAuctionsFrame:Hide()
|
||||
AuxBidsFrame:Hide()
|
||||
AuxSearchFrame:Hide()
|
||||
AuxPostFrame:Hide()
|
||||
AuxAuctionsFrame:Hide()
|
||||
AuxBidsFrame:Hide()
|
||||
|
||||
if index == 1 then
|
||||
AuxSearchFrame:Show()
|
||||
Aux.search_frame.on_open()
|
||||
elseif index == 2 then
|
||||
AuxPostFrame:Show()
|
||||
Aux.post_frame.on_open()
|
||||
elseif index == 3 then
|
||||
AuxAuctionsFrame:Show()
|
||||
Aux.auctions_frame.on_open()
|
||||
elseif index == 4 then
|
||||
AuxBidsFrame:Show()
|
||||
Aux.bids_frame.on_open()
|
||||
end
|
||||
if index == 1 then
|
||||
AuxSearchFrame:Show()
|
||||
Aux.search_frame.on_open()
|
||||
elseif index == 2 then
|
||||
AuxPostFrame:Show()
|
||||
Aux.post_frame.on_open()
|
||||
elseif index == 3 then
|
||||
AuxAuctionsFrame:Show()
|
||||
Aux.auctions_frame.on_open()
|
||||
elseif index == 4 then
|
||||
AuxBidsFrame:Show()
|
||||
Aux.bids_frame.on_open()
|
||||
end
|
||||
|
||||
Aux.active_panel = index
|
||||
end)
|
||||
Aux.active_panel = index
|
||||
end
|
||||
|
||||
function Aux.round(v)
|
||||
|
||||
@@ -778,6 +778,7 @@ function private.refresh_entries()
|
||||
private.status_bar:set_text('Scanning auctions...')
|
||||
|
||||
Aux.scan.start{
|
||||
type = 'list',
|
||||
no_wait_owner = true,
|
||||
queries = { query },
|
||||
on_page_loaded = function(page, total_pages)
|
||||
|
||||
@@ -20,14 +20,19 @@ function current_query()
|
||||
end
|
||||
|
||||
function current_thread()
|
||||
return threads[Aux.control.thread_id]
|
||||
for _, thread in pairs(threads) do
|
||||
if thread.id == Aux.control.thread_id then
|
||||
return thread
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function public.start(params)
|
||||
private.abort(params.type)
|
||||
|
||||
local thread_id = Aux.control.new(private.scan)
|
||||
threads[thread_id] = {
|
||||
threads[params.type] = {
|
||||
id = thread_id,
|
||||
params = params,
|
||||
}
|
||||
end
|
||||
@@ -41,13 +46,13 @@ function public.abort(k)
|
||||
end
|
||||
|
||||
function private.abort(type)
|
||||
for thread_id, thread in pairs(threads) do
|
||||
if not type or type == thread.type then
|
||||
if thread.on_abort then
|
||||
thread.on_abort()
|
||||
for t, thread in pairs(threads) do
|
||||
if not type or type == t then
|
||||
if thread.params.on_abort then
|
||||
thread.params.on_abort()
|
||||
end
|
||||
threads[thread_id] = nil
|
||||
Aux.control.kill(thread_id)
|
||||
threads[t] = nil
|
||||
Aux.control.kill(thread.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -61,11 +66,11 @@ function private.as_soon_as(p, k)
|
||||
end
|
||||
|
||||
function private.wait_for_results(k)
|
||||
if current_thread().type == 'bidder' then
|
||||
if current_thread().params.type == 'bidder' then
|
||||
return private.wait_for_bidder_results(k)
|
||||
elseif current_thread().type == 'owner' then
|
||||
elseif current_thread().params.type == 'owner' then
|
||||
return private.wait_for_owner_results(k)
|
||||
elseif current_thread().type == 'list' then
|
||||
elseif current_thread().params.type == 'list' then
|
||||
return private.wait_for_list_results(k)
|
||||
end
|
||||
end
|
||||
@@ -80,9 +85,13 @@ end
|
||||
|
||||
function private.wait_for_owner_results(k)
|
||||
local updated
|
||||
Aux.control.on_next_event('AUCTION_OWNED_LIST_UPDATE', function()
|
||||
if current_thread().page == Aux.current_owner_page then
|
||||
updated = true
|
||||
end)
|
||||
else
|
||||
Aux.control.on_next_event('AUCTION_OWNED_LIST_UPDATE', function()
|
||||
updated = true
|
||||
end)
|
||||
end
|
||||
|
||||
private.as_soon_as(function() return updated end, k)
|
||||
end
|
||||
@@ -109,9 +118,9 @@ function private.owner_data_complete()
|
||||
if current_thread().params.no_wait_owner then
|
||||
return true
|
||||
end
|
||||
local count, _ = GetNumAuctionItems(current_thread().type)
|
||||
local count, _ = GetNumAuctionItems(current_thread().params.type)
|
||||
for i=1,count do
|
||||
local auction_info = Aux.info.auction(i, current_thread().type)
|
||||
local auction_info = Aux.info.auction(i, current_thread().params.type)
|
||||
if auction_info and not auction_info.owner then
|
||||
return false
|
||||
end
|
||||
@@ -164,7 +173,7 @@ function private.process_query()
|
||||
|
||||
submit_query(function()
|
||||
|
||||
local count, _ = GetNumAuctionItems(current_thread().type)
|
||||
local count, _ = GetNumAuctionItems(current_thread().params.type)
|
||||
|
||||
scan_auctions(count, function()
|
||||
|
||||
@@ -198,11 +207,12 @@ function scan_auctions_helper(i, n, k)
|
||||
end
|
||||
end
|
||||
|
||||
local auction_info = Aux.info.auction(i, current_thread().type)
|
||||
local auction_info = Aux.info.auction(i, current_thread().params.type)
|
||||
if auction_info then
|
||||
auction_info.index = i
|
||||
auction_info.page = current_thread().page
|
||||
auction_info.query = current_query()
|
||||
auction_info.query_type = current_thread().params.type
|
||||
|
||||
Aux.history.process_auction(auction_info)
|
||||
|
||||
@@ -216,14 +226,14 @@ end
|
||||
|
||||
function submit_query(k)
|
||||
if current_thread().page then
|
||||
private.as_soon_as(function() return current_thread().type ~= 'list' or CanSendAuctionQuery() end, function()
|
||||
private.as_soon_as(function() return current_thread().params.type ~= 'list' or CanSendAuctionQuery() end, function()
|
||||
|
||||
if current_thread().params.on_submit_query then
|
||||
current_thread().params.on_submit_query()
|
||||
end
|
||||
if current_thread().type == 'bidder' then
|
||||
if current_thread().params.type == 'bidder' then
|
||||
GetBidderAuctionItems(current_thread().page)
|
||||
elseif current_thread().type == 'owner' then
|
||||
elseif current_thread().params.type == 'owner' then
|
||||
GetOwnerAuctionItems(current_thread().page)
|
||||
else
|
||||
QueryAuctionItems(
|
||||
@@ -239,7 +249,7 @@ function submit_query(k)
|
||||
)
|
||||
end
|
||||
private.wait_for_results(function()
|
||||
local _, total_count = GetNumAuctionItems(current_thread().type)
|
||||
local _, total_count = GetNumAuctionItems(current_thread().params.type)
|
||||
current_thread().total_pages = math.ceil(total_count / PAGE_SIZE)
|
||||
if current_thread().total_pages >= current_thread().page + 1 then
|
||||
wait_for_callback{current_thread().params.on_page_loaded or Aux.util.pass, current_thread().page, current_thread().total_pages, function()
|
||||
|
||||
+1
-1
@@ -22,8 +22,8 @@ function public.start_scan()
|
||||
|
||||
Aux.log('Scanning auctions ...')
|
||||
Aux.scan.start{
|
||||
type = 'list',
|
||||
queries = {{
|
||||
type = 'list',
|
||||
start_page = 0,
|
||||
}},
|
||||
on_page_loaded = function(page, total_pages)
|
||||
|
||||
+46
-43
@@ -1,55 +1,59 @@
|
||||
local m = {}
|
||||
Aux.scan_util = m
|
||||
|
||||
function m.find(test, query, page, status_bar, on_abort, on_failure, on_success)
|
||||
function m.find(auction_record, status_bar, on_abort, on_failure, on_success)
|
||||
|
||||
Aux.scan.abort(function()
|
||||
local function test(index)
|
||||
local auction_info = Aux.info.auction(index, auction_record.query_type)
|
||||
return auction_info and auction_info.search_signature == auction_record.search_signature
|
||||
end
|
||||
|
||||
status_bar:update_status(0, 0)
|
||||
status_bar:set_text('Searching auction...')
|
||||
Aux.scan.abort(auction_record.query_type)
|
||||
|
||||
local pages = page > 0 and { page, page - 1 } or { page }
|
||||
status_bar:update_status(0, 0)
|
||||
status_bar:set_text('Searching auction...')
|
||||
|
||||
local new_query = {
|
||||
type = query.type,
|
||||
validator = function(auction_info) return test(auction_info.index) end,
|
||||
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 pages = auction_record.page > 0 and { auction_record.page, auction_record.page - 1 } or { auction_record.page }
|
||||
|
||||
local found
|
||||
Aux.scan.start{
|
||||
queries = { new_query },
|
||||
on_read_auction = function(auction_info, ctrl)
|
||||
if test(auction_info.index) then
|
||||
found = true
|
||||
ctrl.suspend()
|
||||
status_bar:update_status(100, 100)
|
||||
status_bar:set_text('Auction found')
|
||||
return on_success(auction_info.index)
|
||||
end
|
||||
end,
|
||||
on_abort = function()
|
||||
if not found then
|
||||
status_bar:update_status(100, 100)
|
||||
status_bar:set_text('Auction not found')
|
||||
return on_abort()
|
||||
end
|
||||
end,
|
||||
on_complete = function()
|
||||
local query = {
|
||||
validator = function(auction_info) return test(auction_info.index) end,
|
||||
blizzard_query = auction_record.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 found
|
||||
Aux.scan.start{
|
||||
type = auction_record.query_type,
|
||||
queries = { query },
|
||||
on_read_auction = function(auction_info, ctrl)
|
||||
if test(auction_info.index) then
|
||||
found = true
|
||||
ctrl.suspend()
|
||||
status_bar:update_status(100, 100)
|
||||
status_bar:set_text('Auction found')
|
||||
return on_success(auction_info.index)
|
||||
end
|
||||
end,
|
||||
on_abort = function()
|
||||
if not found then
|
||||
status_bar:update_status(100, 100)
|
||||
status_bar:set_text('Auction not found')
|
||||
return on_failure()
|
||||
end,
|
||||
}
|
||||
end)
|
||||
return on_abort()
|
||||
end
|
||||
end,
|
||||
on_complete = function()
|
||||
status_bar:update_status(100, 100)
|
||||
status_bar:set_text('Auction not found')
|
||||
return on_failure()
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
function m.create_item_query(item_id)
|
||||
@@ -59,7 +63,6 @@ function m.create_item_query(item_id)
|
||||
if item_info then
|
||||
local filter = m.filter_from_string(item_info.name..'/exact')
|
||||
return {
|
||||
type = 'list',
|
||||
start_page = 0,
|
||||
validator = m.validator(filter),
|
||||
blizzard_query = m.blizzard_query(filter),
|
||||
|
||||
+75
-77
@@ -767,94 +767,94 @@ end
|
||||
end
|
||||
|
||||
function public.stop_search()
|
||||
Aux.scan.abort()
|
||||
Aux.scan.abort('list')
|
||||
end
|
||||
|
||||
function public.start_search(filter_string)
|
||||
|
||||
Aux.scan.abort(function()
|
||||
if filter_string then
|
||||
private.search_box:SetText(filter_string)
|
||||
end
|
||||
Aux.scan.abort('list')
|
||||
|
||||
local queries
|
||||
if filter_string then
|
||||
private.search_box:SetText(filter_string)
|
||||
end
|
||||
|
||||
local filters = Aux.scan_util.parse_filter_string(private.search_box:GetText())
|
||||
if filters then
|
||||
queries = Aux.util.map(filters, function(filter)
|
||||
return {
|
||||
start_page = 0,
|
||||
blizzard_query = Aux.scan_util.blizzard_query(filter),
|
||||
validator = Aux.scan_util.validator(filter),
|
||||
}
|
||||
end)
|
||||
else
|
||||
return
|
||||
end
|
||||
local queries
|
||||
|
||||
tinsert(aux_recent_searches, 1, { filter_string = private.search_box:GetText(), prettified = private.prettify_search(private.search_box:GetText()) })
|
||||
while getn(aux_recent_searches) > 50 do
|
||||
tremove(aux_recent_searches)
|
||||
end
|
||||
private.update_search_listings()
|
||||
local filters = Aux.scan_util.parse_filter_string(private.search_box:GetText())
|
||||
if filters then
|
||||
queries = Aux.util.map(filters, function(filter)
|
||||
return {
|
||||
start_page = 0,
|
||||
blizzard_query = Aux.scan_util.blizzard_query(filter),
|
||||
validator = Aux.scan_util.validator(filter),
|
||||
}
|
||||
end)
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
private.search_button:Hide()
|
||||
private.stop_button:Show()
|
||||
tinsert(aux_recent_searches, 1, { filter_string = private.search_box:GetText(), prettified = private.prettify_search(private.search_box:GetText()) })
|
||||
while getn(aux_recent_searches) > 50 do
|
||||
tremove(aux_recent_searches)
|
||||
end
|
||||
private.update_search_listings()
|
||||
|
||||
private.update_tab(RESULTS)
|
||||
private.search_button:Hide()
|
||||
private.stop_button:Show()
|
||||
|
||||
private.status_bar:update_status(0,0)
|
||||
private.status_bar:set_text('Scanning auctions...')
|
||||
private.update_tab(RESULTS)
|
||||
|
||||
private.results_listing:Clear()
|
||||
local scanned_records = {}
|
||||
private.results_listing:SetDatabase(scanned_records)
|
||||
private.status_bar:update_status(0,0)
|
||||
private.status_bar:set_text('Scanning auctions...')
|
||||
|
||||
local current_page, current_total_pages, current_query
|
||||
Aux.scan.start{
|
||||
type = 'list',
|
||||
queries = queries,
|
||||
on_page_loaded = function(page, total_pages)
|
||||
current_page = page + 1
|
||||
current_total_pages = total_pages
|
||||
private.results_listing:Clear()
|
||||
local scanned_records = {}
|
||||
private.results_listing:SetDatabase(scanned_records)
|
||||
|
||||
local current_page, current_total_pages, current_query
|
||||
Aux.scan.start{
|
||||
type = 'list',
|
||||
queries = queries,
|
||||
on_page_loaded = function(page, total_pages)
|
||||
current_page = page + 1
|
||||
current_total_pages = total_pages
|
||||
private.status_bar:update_status(100 * (current_query - 1) / getn(queries), 100 * (current_page - 1) / current_total_pages) -- TODO
|
||||
private.status_bar:set_text(format('Scanning %d / %d (Page %d / %d)', current_query, getn(queries), current_page, current_total_pages))
|
||||
end,
|
||||
on_page_scanned = function()
|
||||
private.results_listing:SetDatabase()
|
||||
end,
|
||||
on_start_query = function(query_index)
|
||||
current_query = query_index
|
||||
if current_page then
|
||||
private.status_bar:update_status(100 * (current_query - 1) / getn(queries), 100 * (current_page - 1) / current_total_pages) -- TODO
|
||||
private.status_bar:set_text(format('Scanning %d / %d (Page %d / %d)', current_query, getn(queries), current_page, current_total_pages))
|
||||
end,
|
||||
on_page_scanned = function()
|
||||
private.results_listing:SetDatabase()
|
||||
end,
|
||||
on_start_query = function(query_index)
|
||||
current_query = query_index
|
||||
if current_page then
|
||||
private.status_bar:update_status(100 * (current_query - 1) / getn(queries), 100 * (current_page - 1) / current_total_pages) -- TODO
|
||||
private.status_bar:set_text(format('Scanning %d / %d (Page %d / %d)', current_query, getn(queries), current_page, current_total_pages))
|
||||
else
|
||||
private.status_bar:update_status(100 * (current_query - 1) / getn(queries), 0) -- TODO
|
||||
private.status_bar:set_text(format('Scanning %d / %d', current_query, getn(queries)))
|
||||
end
|
||||
end,
|
||||
on_read_auction = function(auction_info)
|
||||
if getn(scanned_records) < 1000 then -- TODO static popup, remove discard
|
||||
tinsert(scanned_records, auction_info)
|
||||
end
|
||||
end,
|
||||
on_complete = function()
|
||||
private.results_listing:SetDatabase()
|
||||
private.status_bar:update_status(100, 100)
|
||||
private.status_bar:set_text('Done Scanning')
|
||||
else
|
||||
private.status_bar:update_status(100 * (current_query - 1) / getn(queries), 0) -- TODO
|
||||
private.status_bar:set_text(format('Scanning %d / %d', current_query, getn(queries)))
|
||||
end
|
||||
end,
|
||||
on_read_auction = function(auction_info)
|
||||
if getn(scanned_records) < 1000 then -- TODO static popup, remove discard
|
||||
tinsert(scanned_records, auction_info)
|
||||
end
|
||||
end,
|
||||
on_complete = function()
|
||||
private.results_listing:SetDatabase()
|
||||
private.status_bar:update_status(100, 100)
|
||||
private.status_bar:set_text('Done Scanning')
|
||||
|
||||
private.stop_button:Hide()
|
||||
private.search_button:Show()
|
||||
end,
|
||||
on_abort = function()
|
||||
private.results_listing:SetDatabase()
|
||||
private.status_bar:update_status(100, 100)
|
||||
private.status_bar:set_text('Done Scanning')
|
||||
private.stop_button:Hide()
|
||||
private.search_button:Show()
|
||||
end,
|
||||
}
|
||||
end)
|
||||
private.stop_button:Hide()
|
||||
private.search_button:Show()
|
||||
end,
|
||||
on_abort = function()
|
||||
private.results_listing:SetDatabase()
|
||||
private.status_bar:update_status(100, 100)
|
||||
private.status_bar:set_text('Done Scanning')
|
||||
private.stop_button:Hide()
|
||||
private.search_button:Show()
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
function private.test(record)
|
||||
@@ -875,7 +875,7 @@ function private.find_auction_and_bid(record, buyout_mode)
|
||||
return
|
||||
end
|
||||
|
||||
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
|
||||
Aux.scan_util.find(record, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
|
||||
if private.results_listing:ContainsRecord(record) then
|
||||
Aux.place_bid('list', index, buyout_mode and record.buyout_price or record.bid_price, private.record_remover(record))
|
||||
end
|
||||
@@ -893,9 +893,7 @@ do
|
||||
end
|
||||
|
||||
Aux.scan_util.find(
|
||||
private.test(record),
|
||||
record.query,
|
||||
record.page,
|
||||
record,
|
||||
private.status_bar,
|
||||
function()
|
||||
state = IDLE
|
||||
|
||||
Reference in New Issue
Block a user