From e976d3da0db5dc7c9f06e535f738f6d8353b5b8b Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Sat, 20 Feb 2016 07:22:48 +0100 Subject: [PATCH] some refactoring for post/stack --- post.lua | 52 ++++++++++++++++++++++++++-------------------------- scan.lua | 10 ++++------ stack.lua | 23 +++++++++++------------ 3 files changed, 41 insertions(+), 44 deletions(-) diff --git a/post.lua b/post.lua index 00358a4..3110a7f 100644 --- a/post.lua +++ b/post.lua @@ -49,31 +49,6 @@ function private.process() end end -function public.stop(k) - Aux.control.on_next_update(function() - private.stop() - - if k then - return k() - end - end) -end - -function private.stop() - controller().reset() - if state then - local callback = state.callback - local posted = state.posted - local partial_stack = state.partial_stack - - state = nil - - if callback then - callback(posted, partial_stack) - end - end -end - function private.post_auction(slot, k) ClearCursor() ClickAuctionSellItemButton() @@ -88,8 +63,33 @@ function private.post_auction(slot, k) end) end +function private.stop() + controller().reset() + if state then + local callback = state.callback + local posted = state.posted + local partial_stack = state.partial_stack + + state = nil + + if callback then + callback(posted, partial_stack) + end + end +end + +function public.stop(k) + controller().wait(function() + private.stop() + + if k then + return k() + end + end) +end + function public.start(item_key, stack_size, duration, unit_start_price, unit_buyout_price, count, allow_partial, callback) - Aux.control.on_next_update(function() + controller().wait(function() private.stop() state = { diff --git a/scan.lua b/scan.lua index 019808e..7929734 100644 --- a/scan.lua +++ b/scan.lua @@ -13,7 +13,7 @@ end)() local state -local scan_auctions, scan_auctions_helper, submit_query, wait_for_callback, wait_for_results, wait_for_owner_data, on_abort, current_query +local scan_auctions, scan_auctions_helper, submit_query, wait_for_callback, wait_for_results, wait_for_owner_data, abort, current_query function private.default_next_page(page, total_pages) local last_page = max(total_pages - 1, 0) @@ -28,7 +28,7 @@ end function public.start(params) return controller().wait(function() return true end, function() - on_abort() + abort() state = { params = params, @@ -40,9 +40,7 @@ end function public.abort(k) return controller().wait(function() return true end, function() - on_abort() - - state = nil + abort() if k then return k() @@ -50,7 +48,7 @@ function public.abort(k) end) end -function on_abort() +function abort() local on_abort = Aux.util.safe_index{state, 'params', 'on_abort' } state = nil if on_abort then diff --git a/stack.lua b/stack.lua index e92ea8e..e51da82 100644 --- a/stack.lua +++ b/stack.lua @@ -112,20 +112,9 @@ function private.max_stack(slot) return container_item_info and container_item_info.max_stack end -function public.stop(k) - Aux.control.on_next_update(function() - private.stop() - - if k then - return k() - end - end) -end - function private.stop() controller().reset() if state then - local callback, slot = state.callback, state.target_slot state = nil @@ -136,8 +125,18 @@ function private.stop() end end +function public.stop(k) + controller().wait(function() + private.stop() + + if k then + return k() + end + end) +end + function public.start(item_key, size, callback) - Aux.control.on_next_update(function() + controller().wait(function() private.stop() local slots = private.item_slots(item_key)