some refactoring and shortcuts for and/or operators

This commit is contained in:
Manuel Simon Hirsig
2016-07-29 11:39:59 +02:00
parent e69fa45826
commit 5e3138c9e7
9 changed files with 159 additions and 141 deletions
+2 -6
View File
@@ -185,9 +185,7 @@ function private.scan_wdb()
if item_id <= MAX_ITEM_ID then
local t0 = GetTime()
Aux.control.as_soon_as(function() return GetTime() - t0 > 0.1 end, function()
return helper(item_id)
end)
Aux.control.as_soon_as(function() return GetTime() - t0 > 0.1 end, Aux.f(helper, item_id))
else
sort(aux_auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end)
end
@@ -209,9 +207,7 @@ function public.populate_wdb()
AuxTooltip:SetHyperlink('item:'..item_id)
end
Aux.control.on_next_update(function()
return helper(item_id + 1)
end)
Aux.control.on_next_update(Aux.f(helper, item_id + 1))
end
helper(MIN_ITEM_ID)
+17 -23
View File
@@ -5,24 +5,17 @@ private.state = nil
function private.process()
if m.state.posted < m.state.count then
local stacking_complete, target_slot
local stacking_complete
Aux.stack.start(
m.state.item_key,
m.state.stack_size,
function(slot)
stacking_complete = true
target_slot = slot
end
)
return Aux.control.wait_until(function() return stacking_complete end, function()
if target_slot then
return m.post_auction(target_slot, m.process)
local c = Aux.control.wait_for(function(slot)
if slot then
return m.post_auction(slot, m.process)
else
return m.stop()
end
end)
return Aux.stack.start(m.state.item_key, m.state.stack_size, c)
end
return m.stop()
@@ -41,20 +34,21 @@ function private.post_auction(slot, k)
StartAuction(max(1, Aux.round(m.state.unit_start_price * item_info.aux_quantity)), Aux.round(m.state.unit_buyout_price * item_info.aux_quantity), m.state.duration)
local posted
local listener = Aux.control.event_listener('CHAT_MSG_SYSTEM')
listener:set_action(function()
if arg1 == ERR_AUCTION_STARTED then
posted = true
listener:stop()
end
end)
listener:start()
Aux.control.wait_until(function() return posted end, function()
local c = Aux.control.wait_for(function()
m.state.posted = m.state.posted + 1
return k()
end)
local posted
local listener = Aux.control.event_listener('CHAT_MSG_SYSTEM')
listener:set_action(function()
if arg1 == ERR_AUCTION_STARTED then
listener:stop()
c()
end
end)
listener:start()
else
return m.stop()
end
+12 -13
View File
@@ -31,9 +31,8 @@ function public.start(params)
m.abort(m.threads[params.type].id)
end
local thread_id = Aux.control.new_thread(function()
return m.wait_for_callback(m.current_thread().params.on_scan_start, m.scan)
end)
local thread_id = Aux.control.new_thread(Aux.f(m.wait_for_callback, params.on_scan_start, m.scan))
m.threads[params.type] = {
id = thread_id,
params = params,
@@ -69,16 +68,14 @@ function private.wait_for_results(k)
end
function private.wait_for_owner_results(k)
local updated
if m.current_thread().page == Aux.current_owner_page then
updated = true
else
Aux.control.on_next_event('AUCTION_OWNED_LIST_UPDATE', function()
updated = true
end)
end
Aux.control.wait_until(function() return updated end, k)
local c = Aux.control.wait_for(k)
if m.current_thread().page == Aux.current_owner_page then
return c()
else
return Aux.control.on_next_event('AUCTION_OWNED_LIST_UPDATE', c)
end
end
function private.wait_for_list_results(k)
@@ -201,7 +198,9 @@ function private.scan_auctions_helper(i, k)
Aux.history.process_auction(auction_info)
if m.current_thread().params.auto_buy_validator and m.current_thread().params.auto_buy_validator(auction_info) then
return Aux.place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, function() return recurse(true) end)
local c = Aux.control.wait_for(recurse)
Aux.place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, Aux.f(c, true))
Aux.control.new_thread(Aux.control.sleep, 10, Aux.f(c, false))
elseif not m.current_query().validator or m.current_query().validator(auction_info) then
return m.wait_for_callback(m.current_thread().params.on_auction, auction_info, function(removed)
if removed then