continuation based scan completed
This commit is contained in:
@@ -63,17 +63,16 @@ function Aux.buy.SearchButton_onclick()
|
|||||||
|
|
||||||
set_message('Scanning auctions ...')
|
set_message('Scanning auctions ...')
|
||||||
Aux.scan.start{
|
Aux.scan.start{
|
||||||
query = search_query,
|
query = search_query,
|
||||||
start_page = 0,
|
page = 0,
|
||||||
on_start_page = function(i)
|
on_start_page = function(k, i)
|
||||||
current_page = i
|
current_page = i
|
||||||
set_message('Scanning auctions: page ' .. i + 1 .. ' ...')
|
set_message('Scanning auctions: page ' .. i + 1 .. ' ...')
|
||||||
end,
|
k()
|
||||||
on_read_auction = function(i)
|
end,
|
||||||
local auction_item = Aux.info.auction_item(i)
|
on_read_auction = function(k, i)
|
||||||
if not auction_item then
|
local auction_item = Aux.info.auction_item(i)
|
||||||
return
|
if auction_item then
|
||||||
end
|
|
||||||
local stack_size = auction_item.charges or auction_item.count
|
local stack_size = auction_item.charges or auction_item.count
|
||||||
if (auction_item.name == search_query.name or search_query.name == '' or not AuxBuyExactCheckButton:GetChecked()) and tooltip_match(tooltip_patterns, auction_item.tooltip) then
|
if (auction_item.name == search_query.name or search_query.name == '' or not AuxBuyExactCheckButton:GetChecked()) and tooltip_match(tooltip_patterns, auction_item.tooltip) then
|
||||||
record_auction(
|
record_auction(
|
||||||
@@ -88,24 +87,27 @@ function Aux.buy.SearchButton_onclick()
|
|||||||
current_page
|
current_page
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end,
|
end
|
||||||
on_complete = function()
|
k()
|
||||||
entries = entries or {}
|
end,
|
||||||
AuxBuyStopButton:Hide()
|
on_complete = function()
|
||||||
AuxBuySearchButton:Show()
|
entries = entries or {}
|
||||||
refresh = true
|
AuxBuyStopButton:Hide()
|
||||||
end,
|
AuxBuySearchButton:Show()
|
||||||
on_abort = function()
|
refresh = true
|
||||||
entries = entries or {}
|
end,
|
||||||
AuxBuyStopButton:Hide()
|
on_abort = function()
|
||||||
AuxBuySearchButton:Show()
|
entries = entries or {}
|
||||||
refresh = true
|
AuxBuyStopButton:Hide()
|
||||||
end,
|
AuxBuySearchButton:Show()
|
||||||
next_page = function(page, auctions)
|
refresh = true
|
||||||
if auctions == Aux.scan.MAX_AUCTIONS_PER_PAGE then
|
end,
|
||||||
return page + 1
|
next_page = function(page, total_pages)
|
||||||
end
|
local last_page = max(total_pages - 1, 0)
|
||||||
end,
|
if page < last_page then
|
||||||
|
return page + 1
|
||||||
|
end
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -159,17 +161,23 @@ function AuxBuyEntry_OnClick()
|
|||||||
|
|
||||||
Aux.scan.start{
|
Aux.scan.start{
|
||||||
query = search_query,
|
query = search_query,
|
||||||
start_page = entry.page ~= current_page and entry.page,
|
page = entry.page ~= current_page and entry.page,
|
||||||
on_read_auction = function(i)
|
on_start_page = function(k, page)
|
||||||
|
current_page = page
|
||||||
|
k()
|
||||||
|
end,
|
||||||
|
on_read_auction = function(k, i)
|
||||||
local auction_item = Aux.info.auction_item(i)
|
local auction_item = Aux.info.auction_item(i)
|
||||||
|
|
||||||
if not auction_item then
|
if not auction_item then
|
||||||
|
k()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local stack_size = auction_item.charges or auction_item.count
|
local stack_size = auction_item.charges or auction_item.count
|
||||||
|
|
||||||
if not auction_item.tooltip or not stack_size or not auction_item.buyout_price then
|
if not auction_item.tooltip or not stack_size or not auction_item.buyout_price then
|
||||||
|
k()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -202,6 +210,7 @@ function AuxBuyEntry_OnClick()
|
|||||||
AuxBuyBuyoutDialogBuyButton:Enable()
|
AuxBuyBuyoutDialogBuyButton:Enable()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
k()
|
||||||
end,
|
end,
|
||||||
on_complete = function()
|
on_complete = function()
|
||||||
if not found then
|
if not found then
|
||||||
|
|||||||
@@ -1,140 +1,128 @@
|
|||||||
Aux.scan = {}
|
Aux.scan = {}
|
||||||
|
|
||||||
Aux.scan.MAX_AUCTIONS_PER_PAGE = 50
|
local AUCTIONS_PER_PAGE = 50
|
||||||
|
|
||||||
local ready
|
|
||||||
local continuation
|
|
||||||
|
|
||||||
local current_job
|
|
||||||
local current_page
|
|
||||||
|
|
||||||
local wait, wait_for_results, wait_after, wait_for_function, wait_until_can_query, scan, scan_page, ready -- TODO
|
local state, abort, new_job
|
||||||
|
|
||||||
-- forward declaration of local functions
|
-- forward declaration of local functions
|
||||||
local submit_query, start_processing_page
|
local wait, wait_after, wait_for_function, wait_until, wait_for_event
|
||||||
|
local scan, scan_auctions, scan_auctions_helper, submit_query
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Aux.scan.on_event()
|
function Aux.scan.on_event()
|
||||||
if current_job and ready and ready(event) then
|
if state and state.ready and state.ready(event) then
|
||||||
resume = nil
|
state.ready = nil
|
||||||
continuation()
|
state.continuation()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Aux.scan.on_update()
|
function Aux.scan.on_update()
|
||||||
if current_job and ready and ready() then
|
if abort then
|
||||||
resume = nil
|
if state and state.job and state.job.on_abort then
|
||||||
continuation()
|
state.job.on_abort()
|
||||||
|
end
|
||||||
|
state = nil
|
||||||
|
abort = false
|
||||||
|
elseif new_job then
|
||||||
|
state = {
|
||||||
|
job = new_job,
|
||||||
|
page = new_job.page
|
||||||
|
}
|
||||||
|
new_job = nil
|
||||||
|
scan()
|
||||||
|
elseif state and state.ready and state.ready() then
|
||||||
|
state.ready = nil
|
||||||
|
state.continuation()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Aux.scan.start(job)
|
function Aux.scan.start(job)
|
||||||
Aux.scan.abort()
|
abort = true
|
||||||
|
new_job = job
|
||||||
scan(job)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function wait(timeout)
|
function Aux.scan.abort()
|
||||||
|
abort = true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function wait(timeout, k)
|
||||||
|
state.continuation = k
|
||||||
local start_time = GetTime()
|
local start_time = GetTime()
|
||||||
resume = function()
|
state.ready = function()
|
||||||
return GetTime() - start_time >= timeout
|
return GetTime() - start_time >= timeout
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function wait_after()
|
function wait_after()
|
||||||
local last
|
local last
|
||||||
return function wait(timeout)
|
return function()
|
||||||
resume = function()
|
last = GetTime()
|
||||||
|
end,
|
||||||
|
function(timeout, k)
|
||||||
|
state.continuation = k
|
||||||
|
state.ready = function()
|
||||||
return GetTime() - last >= timeout
|
return GetTime() - last >= timeout
|
||||||
end
|
end
|
||||||
coroutine:yield()
|
|
||||||
end,
|
|
||||||
function()
|
|
||||||
last = GetTime()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function wait_for_results(k)
|
function wait_for_event(e, k)
|
||||||
continuation = k
|
state.continuation = k
|
||||||
local start_time = GetTime()
|
state.ready = function(event)
|
||||||
resume = function(event)
|
return event == e
|
||||||
return event == "AUCTION_ITEM_LIST_UPDATE"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function wait_for_function(f, args, k)
|
function wait_for_function(f, args, k)
|
||||||
if not f then k() end
|
state.continuation = k
|
||||||
local done
|
local complete
|
||||||
tinsert(args, function() done = true end, 1)
|
state.ready = function()
|
||||||
f(unpack(args))
|
return complete
|
||||||
resume = function(event)
|
end
|
||||||
return done
|
|
||||||
|
if not f then
|
||||||
|
complete = true
|
||||||
|
else
|
||||||
|
tinsert(args, 1, function() complete = true end)
|
||||||
|
f(unpack(args))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function wait_until(p)
|
function wait_until(p, k)
|
||||||
resume = function()
|
state.continuation = k
|
||||||
|
state.ready = function()
|
||||||
return p()
|
return p()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function start_processing_page()
|
|
||||||
page_state = {}
|
|
||||||
local count, total_count = GetNumAuctionItems("list")
|
|
||||||
page_state.index = 1
|
|
||||||
page_state.count = count
|
|
||||||
page_state.total_count = total_count
|
|
||||||
|
|
||||||
if current_job.on_start_page then
|
|
||||||
wait_for_function(current_job.on_start_page, {current_page})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function Aux.scan.complete()
|
|
||||||
if current_job and current_job.on_complete then
|
|
||||||
current_job.on_complete()
|
|
||||||
end
|
|
||||||
|
|
||||||
current_job = nil
|
|
||||||
current_page = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function Aux.scan.abort()
|
|
||||||
if current_job and current_job.on_abort then
|
|
||||||
current_job.on_abort()
|
|
||||||
end
|
|
||||||
|
|
||||||
current_job = nil
|
|
||||||
current_page = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function scan()
|
function scan()
|
||||||
|
|
||||||
scan_page(current_page, function()
|
wait_for_function(state.job.on_start_page, {state.page}, function() --;
|
||||||
|
|
||||||
current_page = current_job.next_page and current_job.next_page(current_page)
|
|
||||||
if current_page then
|
|
||||||
return Aux.scan.complete()
|
|
||||||
else
|
|
||||||
return scan()
|
|
||||||
end
|
|
||||||
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function scan_page(page, k)
|
|
||||||
wait_for_function(current_job.on_start_page, {current_page}, function()
|
|
||||||
|
|
||||||
submit_query(function()
|
|
||||||
|
|
||||||
wait_for_results(function()
|
|
||||||
|
|
||||||
|
submit_query(function() --;
|
||||||
|
|
||||||
local count, total_count = GetNumAuctionItems("list")
|
local count, total_count = GetNumAuctionItems("list")
|
||||||
|
|
||||||
scan_auctions(count, k)
|
scan_auctions(count, function() --;
|
||||||
|
|
||||||
|
local total_pages = math.ceil(total_count / AUCTIONS_PER_PAGE)
|
||||||
|
|
||||||
|
state.page = state.job.next_page and state.job.next_page(state.page, total_pages)
|
||||||
|
|
||||||
|
if state.page then
|
||||||
|
return scan()
|
||||||
|
else
|
||||||
|
if state.job.on_complete then
|
||||||
|
state.job.on_complete()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end)end)end)
|
end)end)end)
|
||||||
end
|
end
|
||||||
@@ -144,9 +132,9 @@ function scan_auctions(count, k)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function scan_auctions_helper(i, n, k)
|
function scan_auctions_helper(i, n, k)
|
||||||
wait_for_function(current_job.on_read_auction, {current_page}, function()
|
wait_for_function(state.job.on_read_auction, {i}, function() --;
|
||||||
|
|
||||||
if i == n then
|
if i >= n then
|
||||||
return k()
|
return k()
|
||||||
else
|
else
|
||||||
return scan_auctions_helper(i + 1, n, k)
|
return scan_auctions_helper(i + 1, n, k)
|
||||||
@@ -156,19 +144,23 @@ function scan_auctions_helper(i, n, k)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function submit_query(k)
|
function submit_query(k)
|
||||||
wait_until(CanSendAuctionQuery, function()
|
if state.page then
|
||||||
QueryAuctionItems(
|
wait_until(CanSendAuctionQuery, function() --;
|
||||||
current_job.query.name,
|
QueryAuctionItems(
|
||||||
current_job.query.min_level,
|
state.job.query.name,
|
||||||
current_job.query.max_level,
|
state.job.query.min_level,
|
||||||
current_job.query.slot,
|
state.job.query.max_level,
|
||||||
current_job.query.class,
|
state.job.query.slot,
|
||||||
current_job.query.subclass,
|
state.job.query.class,
|
||||||
current_page,
|
state.job.query.subclass,
|
||||||
current_job.query.usable,
|
state.page,
|
||||||
current_job.query.quality
|
state.job.query.usable,
|
||||||
)
|
state.job.query.quality
|
||||||
|
)
|
||||||
return k()
|
wait_for_event('AUCTION_ITEM_LIST_UPDATE', function() --;
|
||||||
end)
|
return k()
|
||||||
end
|
end)end)
|
||||||
|
else
|
||||||
|
k()
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -263,9 +263,8 @@ function Aux_OnNewAuctionUpdate()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if not Aux.scan.idle() then
|
Aux.scan.abort()
|
||||||
Aux.scan.abort()
|
|
||||||
end
|
|
||||||
|
|
||||||
local auctionItemName, auctionItemTexture, auctionItemStackSize = GetAuctionSellItemInfo()
|
local auctionItemName, auctionItemTexture, auctionItemStackSize = GetAuctionSellItemInfo()
|
||||||
local auction_sell_item = Aux.info.auction_sell_item()
|
local auction_sell_item = Aux.info.auction_sell_item()
|
||||||
@@ -300,35 +299,38 @@ function Aux_RefreshEntries()
|
|||||||
|
|
||||||
set_message('Scanning auctions ...')
|
set_message('Scanning auctions ...')
|
||||||
Aux.scan.start{
|
Aux.scan.start{
|
||||||
query = {
|
query = {
|
||||||
name = name,
|
name = name,
|
||||||
class = class_index,
|
class = class_index,
|
||||||
subclass = subclass_index,
|
subclass = subclass_index,
|
||||||
},
|
},
|
||||||
start_page = 0,
|
page = 0,
|
||||||
on_start_page = function(i)
|
on_start_page = function(k, i)
|
||||||
set_message('Scanning auctions: page ' .. i + 1 .. ' ...')
|
set_message('Scanning auctions: page ' .. i + 1 .. ' ...')
|
||||||
end,
|
k()
|
||||||
on_read_auction = function(i)
|
end,
|
||||||
local auction_item = Aux.info.auction_item(i)
|
on_read_auction = function(k, i)
|
||||||
if auction_item and auction_item.name == name then
|
local auction_item = Aux.info.auction_item(i)
|
||||||
local stack_size = auction_item.charges or auction_item.count
|
if auction_item and auction_item.name == name then
|
||||||
record_auction(auction_item.name, stack_size, auction_item.buyout_price, auction_item.duration, auction_item.owner)
|
local stack_size = auction_item.charges or auction_item.count
|
||||||
end
|
record_auction(auction_item.name, stack_size, auction_item.buyout_price, auction_item.duration, auction_item.owner)
|
||||||
end,
|
end
|
||||||
on_abort = function()
|
k()
|
||||||
auxSellEntries[name] = nil
|
end,
|
||||||
end,
|
on_abort = function()
|
||||||
on_complete = function()
|
auxSellEntries[name] = nil
|
||||||
auxSellEntries[name] = auxSellEntries[name] or { created = GetTime() }
|
end,
|
||||||
Aux_SelectAuxEntry()
|
on_complete = function()
|
||||||
Aux_UpdateRecommendation()
|
auxSellEntries[name] = auxSellEntries[name] or { created = GetTime() }
|
||||||
end,
|
Aux_SelectAuxEntry()
|
||||||
next_page = function(page, auctions)
|
Aux_UpdateRecommendation()
|
||||||
if auctions == Aux.scan.MAX_AUCTIONS_PER_PAGE then
|
end,
|
||||||
return page + 1
|
next_page = function(page, total_pages)
|
||||||
end
|
local last_page = max(total_pages - 1, 0)
|
||||||
end,
|
if page < last_page then
|
||||||
|
return page + 1
|
||||||
|
end
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -426,9 +428,7 @@ end
|
|||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
|
|
||||||
function AuxSellRefreshButton_OnClick()
|
function AuxSellRefreshButton_OnClick()
|
||||||
if not Aux.scan.idle() then
|
Aux.scan.abort()
|
||||||
Aux.scan.abort()
|
|
||||||
end
|
|
||||||
Aux_RefreshEntries()
|
Aux_RefreshEntries()
|
||||||
Aux_SelectAuxEntry()
|
Aux_SelectAuxEntry()
|
||||||
Aux_UpdateRecommendation()
|
Aux_UpdateRecommendation()
|
||||||
|
|||||||
Reference in New Issue
Block a user