working on big scan/control refactoring
This commit is contained in:
+1
-4
@@ -2,15 +2,12 @@
|
|||||||
|
|
||||||
<Script file="auctions_frame.lua"/>
|
<Script file="auctions_frame.lua"/>
|
||||||
|
|
||||||
<Frame>
|
<Frame name="AuxAuctionsFrame" hidden="true" parent="AuxFrame" setAllPoints="true">
|
||||||
<Scripts>
|
<Scripts>
|
||||||
<OnUpdate>
|
<OnUpdate>
|
||||||
Aux.auctions_frame.on_update()
|
Aux.auctions_frame.on_update()
|
||||||
</OnUpdate>
|
</OnUpdate>
|
||||||
</Scripts>
|
</Scripts>
|
||||||
</Frame>
|
|
||||||
|
|
||||||
<Frame name="AuxAuctionsFrame" hidden="true" parent="AuxFrame" setAllPoints="true">
|
|
||||||
<Frames>
|
<Frames>
|
||||||
<Frame name="$parentListing" inherits="AuxFrameBoxTemplate">
|
<Frame name="$parentListing" inherits="AuxFrameBoxTemplate">
|
||||||
<Anchors>
|
<Anchors>
|
||||||
|
|||||||
+1
-4
@@ -2,15 +2,12 @@
|
|||||||
|
|
||||||
<Script file="bids_frame.lua"/>
|
<Script file="bids_frame.lua"/>
|
||||||
|
|
||||||
<Frame>
|
<Frame name="AuxBidsFrame" hidden="true" parent="AuxFrame" setAllPoints="true">
|
||||||
<Scripts>
|
<Scripts>
|
||||||
<OnUpdate>
|
<OnUpdate>
|
||||||
Aux.bids_frame.on_update()
|
Aux.bids_frame.on_update()
|
||||||
</OnUpdate>
|
</OnUpdate>
|
||||||
</Scripts>
|
</Scripts>
|
||||||
</Frame>
|
|
||||||
|
|
||||||
<Frame name="AuxBidsFrame" hidden="true" parent="AuxFrame" setAllPoints="true">
|
|
||||||
<Frames>
|
<Frames>
|
||||||
<Frame name="$parentListing" inherits="AuxFrameBoxTemplate">
|
<Frame name="$parentListing" inherits="AuxFrameBoxTemplate">
|
||||||
<Anchors>
|
<Anchors>
|
||||||
|
|||||||
+26
-100
@@ -1,27 +1,19 @@
|
|||||||
local private, public = {}, {}
|
local private, public = {}, {}
|
||||||
Aux.control = public
|
Aux.control = public
|
||||||
|
|
||||||
local event_listeners = {}
|
private.event_listeners = {}
|
||||||
local update_listeners = {}
|
|
||||||
private.threads = {}
|
private.threads = {}
|
||||||
|
|
||||||
function Aux.control.on_event()
|
function public.on_event()
|
||||||
for listener, _ in pairs(event_listeners) do
|
for listener, _ in pairs(private.event_listeners) do
|
||||||
if event == listener.event and not listener.deleted then
|
if event == listener.event and not listener.deleted then
|
||||||
listener.action()
|
listener.action()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Aux.control.on_update()
|
function public.on_update()
|
||||||
event_listeners = Aux.util.set_filter(event_listeners, function(l) return not l.deleted end)
|
private.event_listeners = Aux.util.set_filter(private.event_listeners, function(l) return not l.deleted end)
|
||||||
update_listeners = Aux.util.set_filter(update_listeners, function(l) return not l.deleted end)
|
|
||||||
|
|
||||||
for listener, _ in pairs(update_listeners) do
|
|
||||||
if not listener.deleted then
|
|
||||||
listener.action()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for thread_id, k in pairs(private.threads) do
|
for thread_id, k in pairs(private.threads) do
|
||||||
private.threads[thread_id] = nil
|
private.threads[thread_id] = nil
|
||||||
@@ -31,9 +23,7 @@ function Aux.control.on_update()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function public.event_listener(event, action)
|
||||||
|
|
||||||
function Aux.control.event_listener(event, action)
|
|
||||||
local self = {}
|
local self = {}
|
||||||
|
|
||||||
local listener = { event=event, action=action }
|
local listener = { event=event, action=action }
|
||||||
@@ -43,14 +33,14 @@ function Aux.control.event_listener(event, action)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function self:start()
|
function self:start()
|
||||||
Aux.util.set_add(event_listeners, listener)
|
Aux.util.set_add(private.event_listeners, listener)
|
||||||
AuxControlFrame:RegisterEvent(event)
|
AuxControlFrame:RegisterEvent(event)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
function self:stop()
|
function self:stop()
|
||||||
listener.deleted = true
|
listener.deleted = true
|
||||||
if not Aux.util.any(Aux.util.set_to_array(event_listeners), function(l) return l.event == event end) then
|
if not Aux.util.any(Aux.util.set_to_array(private.event_listeners), function(l) return l.event == event end) then
|
||||||
AuxControlFrame:UnregisterEvent(event)
|
AuxControlFrame:UnregisterEvent(event)
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
@@ -59,32 +49,8 @@ function Aux.control.event_listener(event, action)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
function Aux.control.update_listener(action)
|
function public.on_next_event(event, callback)
|
||||||
local self = {}
|
local listener = public.event_listener(event)
|
||||||
|
|
||||||
local listener = { action=action }
|
|
||||||
|
|
||||||
function self:set_action(action)
|
|
||||||
listener.action = action
|
|
||||||
end
|
|
||||||
|
|
||||||
function self:start()
|
|
||||||
Aux.util.set_add(update_listeners, listener)
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
function self:stop()
|
|
||||||
listener.deleted = true
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Aux.control.on_next_update(callback)
|
|
||||||
local listener = Aux.control.update_listener()
|
|
||||||
|
|
||||||
listener:set_action(function()
|
listener:set_action(function()
|
||||||
listener:stop()
|
listener:stop()
|
||||||
@@ -94,68 +60,19 @@ function Aux.control.on_next_update(callback)
|
|||||||
listener:start()
|
listener:start()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Aux.control.on_next_event(event, callback)
|
function public.on_next_update(callback)
|
||||||
local listener = Aux.control.event_listener(event)
|
return public.new_thread(callback)
|
||||||
|
|
||||||
listener:set_action(function()
|
|
||||||
listener:stop()
|
|
||||||
return callback()
|
|
||||||
end)
|
|
||||||
|
|
||||||
listener:start()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Aux.control.as_soon_as(p, callback)
|
function public.as_soon_as(p, callback)
|
||||||
local listener = Aux.control.update_listener()
|
return public.new_thread(function()
|
||||||
|
return public.wait_until(p, callback)
|
||||||
listener:set_action(function()
|
|
||||||
if p() then
|
|
||||||
listener:stop()
|
|
||||||
return callback()
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
listener:start()
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Aux.control.controller()
|
|
||||||
local self = {}
|
|
||||||
|
|
||||||
local state
|
|
||||||
|
|
||||||
local listener = Aux.control.update_listener()
|
|
||||||
listener:set_action(function()
|
|
||||||
if state and state.p() then
|
|
||||||
local k = state.k
|
|
||||||
state = nil
|
|
||||||
return k()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
listener:start()
|
|
||||||
|
|
||||||
function self.wait(p, k)
|
|
||||||
state = {
|
|
||||||
k = k,
|
|
||||||
p = p,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
function self:reset()
|
|
||||||
state = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
function self:cleanup()
|
|
||||||
listener.stop()
|
|
||||||
end
|
|
||||||
|
|
||||||
return self
|
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
local next_thread_id = 1
|
local next_thread_id = 1
|
||||||
function public.new(k)
|
function public.new_thread(k)
|
||||||
local thread_id = next_thread_id
|
local thread_id = next_thread_id
|
||||||
next_thread_id = next_thread_id + 1
|
next_thread_id = next_thread_id + 1
|
||||||
private.threads[thread_id] = k
|
private.threads[thread_id] = k
|
||||||
@@ -163,7 +80,7 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.kill(thread_id)
|
function public.kill_thread(thread_id)
|
||||||
private.threads[thread_id] = nil
|
private.threads[thread_id] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -171,3 +88,12 @@ function public.wait(...)
|
|||||||
local k = tremove(arg, 1)
|
local k = tremove(arg, 1)
|
||||||
private.threads[public.thread_id] = function() return k(unpack(arg)) end
|
private.threads[public.thread_id] = function() return k(unpack(arg)) end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function public.wait_until(p, ...)
|
||||||
|
local k = tremove(arg, 1)
|
||||||
|
if p() then
|
||||||
|
return k(unpack(arg))
|
||||||
|
else
|
||||||
|
return public.wait(public.wait_until, p, function() return k(unpack(arg)) end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|||||||
@@ -3,14 +3,6 @@ Aux.post = public
|
|||||||
|
|
||||||
local state
|
local state
|
||||||
|
|
||||||
function private.as_soon_as(p, k)
|
|
||||||
if p() then
|
|
||||||
return k()
|
|
||||||
else
|
|
||||||
return Aux.control.wait(private.as_soon_as, p, k)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function private.process()
|
function private.process()
|
||||||
if state.posted < state.count or state.allow_partial then
|
if state.posted < state.count or state.allow_partial then
|
||||||
if state.posted == state.count then
|
if state.posted == state.count then
|
||||||
@@ -29,7 +21,7 @@ function private.process()
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
private.as_soon_as(function() return stacking_complete end, function()
|
Aux.control.wait_until(function() return stacking_complete end, function()
|
||||||
|
|
||||||
if stack_slot and Aux.info.container_item(stack_slot.bag, stack_slot.bag_slot).aux_quantity <= state.stack_size then
|
if stack_slot and Aux.info.container_item(stack_slot.bag, stack_slot.bag_slot).aux_quantity <= state.stack_size then
|
||||||
private.post_auction(stack_slot, function(stack_size)
|
private.post_auction(stack_slot, function(stack_size)
|
||||||
@@ -58,14 +50,14 @@ function private.post_auction(slot, k)
|
|||||||
ClearCursor()
|
ClearCursor()
|
||||||
local stack_size = Aux.info.container_item(slot.bag, slot.bag_slot).aux_quantity
|
local stack_size = Aux.info.container_item(slot.bag, slot.bag_slot).aux_quantity
|
||||||
StartAuction(max(1, Aux.round(state.unit_start_price * stack_size)), Aux.round(state.unit_buyout_price * stack_size), state.duration)
|
StartAuction(max(1, Aux.round(state.unit_start_price * stack_size)), Aux.round(state.unit_buyout_price * stack_size), state.duration)
|
||||||
private.as_soon_as(function() return not GetContainerItemInfo(slot.bag, slot.bag_slot) end, function()
|
Aux.control.wait_until(function() return not GetContainerItemInfo(slot.bag, slot.bag_slot) end, function()
|
||||||
return k(stack_size)
|
return k(stack_size)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.stop()
|
function public.stop()
|
||||||
if state then
|
if state then
|
||||||
Aux.control.kill(state.thread_id)
|
Aux.control.kill_thread(state.thread_id)
|
||||||
|
|
||||||
local callback = state.callback
|
local callback = state.callback
|
||||||
local posted = state.posted
|
local posted = state.posted
|
||||||
@@ -82,7 +74,7 @@ end
|
|||||||
function public.start(item_key, stack_size, duration, unit_start_price, unit_buyout_price, count, allow_partial, callback)
|
function public.start(item_key, stack_size, duration, unit_start_price, unit_buyout_price, count, allow_partial, callback)
|
||||||
public.stop()
|
public.stop()
|
||||||
|
|
||||||
local thread_id = Aux.control.new(private.process)
|
local thread_id = Aux.control.new_thread(private.process)
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
thread_id = thread_id,
|
thread_id = thread_id,
|
||||||
|
|||||||
+5
-8
@@ -2,19 +2,16 @@
|
|||||||
|
|
||||||
<Script file="post_frame.lua"/>
|
<Script file="post_frame.lua"/>
|
||||||
|
|
||||||
<Frame>
|
|
||||||
<Scripts>
|
|
||||||
<OnUpdate>
|
|
||||||
Aux.post_frame.on_update()
|
|
||||||
</OnUpdate>
|
|
||||||
</Scripts>
|
|
||||||
</Frame>
|
|
||||||
|
|
||||||
<Frame name="AuxPostFrame" parent="AuxFrame" hidden="true">
|
<Frame name="AuxPostFrame" parent="AuxFrame" hidden="true">
|
||||||
<Anchors>
|
<Anchors>
|
||||||
<Anchor point="TOPLEFT"><Offset><AbsDimension x="0" y="0"/></Offset></Anchor>
|
<Anchor point="TOPLEFT"><Offset><AbsDimension x="0" y="0"/></Offset></Anchor>
|
||||||
<Anchor point="BOTTOMRIGHT"><Offset><AbsDimension x="0" y="0"/></Offset></Anchor>
|
<Anchor point="BOTTOMRIGHT"><Offset><AbsDimension x="0" y="0"/></Offset></Anchor>
|
||||||
</Anchors>
|
</Anchors>
|
||||||
|
<Scripts>
|
||||||
|
<OnUpdate>
|
||||||
|
Aux.post_frame.on_update()
|
||||||
|
</OnUpdate>
|
||||||
|
</Scripts>
|
||||||
<Frames>
|
<Frames>
|
||||||
<Frame name="$parentContent" inherits="AuxFrameBoxTemplate">
|
<Frame name="$parentContent" inherits="AuxFrameBoxTemplate">
|
||||||
<Anchors>
|
<Anchors>
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ end
|
|||||||
function public.start(params)
|
function public.start(params)
|
||||||
public.abort(params.type)
|
public.abort(params.type)
|
||||||
|
|
||||||
local thread_id = Aux.control.new(private.scan)
|
local thread_id = Aux.control.new_thread(private.scan)
|
||||||
threads[params.type] = {
|
threads[params.type] = {
|
||||||
id = thread_id,
|
id = thread_id,
|
||||||
params = params,
|
params = params,
|
||||||
@@ -44,19 +44,11 @@ function public.abort(type)
|
|||||||
thread.params.on_abort()
|
thread.params.on_abort()
|
||||||
end
|
end
|
||||||
threads[t] = nil
|
threads[t] = nil
|
||||||
Aux.control.kill(thread.id)
|
Aux.control.kill_thread(thread.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function private.as_soon_as(p, k)
|
|
||||||
if p() then
|
|
||||||
return k()
|
|
||||||
else
|
|
||||||
return Aux.control.wait(private.as_soon_as, p, k)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function private.wait_for_results(k)
|
function private.wait_for_results(k)
|
||||||
if current_thread().params.type == 'bidder' then
|
if current_thread().params.type == 'bidder' then
|
||||||
return private.wait_for_bidder_results(k)
|
return private.wait_for_bidder_results(k)
|
||||||
@@ -85,7 +77,7 @@ function private.wait_for_owner_results(k)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
private.as_soon_as(function() return updated end, k)
|
Aux.control.wait_until(function() return updated end, k)
|
||||||
end
|
end
|
||||||
|
|
||||||
function private.wait_for_list_results(k)
|
function private.wait_for_list_results(k)
|
||||||
@@ -95,7 +87,7 @@ function private.wait_for_list_results(k)
|
|||||||
updated = true
|
updated = true
|
||||||
end)
|
end)
|
||||||
listener:start()
|
listener:start()
|
||||||
private.as_soon_as(function()
|
Aux.control.wait_until(function()
|
||||||
-- order important, owner_data_complete must be called after an update to request missing data
|
-- order important, owner_data_complete must be called after an update to request missing data
|
||||||
local ok = updated and private.owner_data_complete() or last_update and GetTime() - last_update > 5
|
local ok = updated and private.owner_data_complete() or last_update and GetTime() - last_update > 5
|
||||||
updated = false
|
updated = false
|
||||||
@@ -137,7 +129,7 @@ function wait_for_callback(args) -- the arguments must not be nil!
|
|||||||
if ok then
|
if ok then
|
||||||
return k()
|
return k()
|
||||||
else
|
else
|
||||||
return private.as_soon_as(function() return ok end, k)
|
return Aux.control.wait_until(function() return ok end, k)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -218,7 +210,7 @@ end
|
|||||||
|
|
||||||
function submit_query(k)
|
function submit_query(k)
|
||||||
if current_thread().page then
|
if current_thread().page then
|
||||||
private.as_soon_as(function() return current_thread().params.type ~= 'list' or CanSendAuctionQuery() end, function()
|
Aux.control.wait_until(function() return current_thread().params.type ~= 'list' or CanSendAuctionQuery() end, function()
|
||||||
|
|
||||||
if current_thread().params.on_submit_query then
|
if current_thread().params.on_submit_query then
|
||||||
current_thread().params.on_submit_query()
|
current_thread().params.on_submit_query()
|
||||||
|
|||||||
+1
-4
@@ -2,15 +2,12 @@
|
|||||||
|
|
||||||
<Script file="search_frame.lua"/>
|
<Script file="search_frame.lua"/>
|
||||||
|
|
||||||
<Frame name="AuxControlFrame">
|
<Frame name="AuxSearchFrame" hidden="true" parent="AuxFrame" setAllPoints="true">
|
||||||
<Scripts>
|
<Scripts>
|
||||||
<OnUpdate>
|
<OnUpdate>
|
||||||
Aux.search_frame.on_update()
|
Aux.search_frame.on_update()
|
||||||
</OnUpdate>
|
</OnUpdate>
|
||||||
</Scripts>
|
</Scripts>
|
||||||
</Frame>
|
|
||||||
|
|
||||||
<Frame name="AuxSearchFrame" hidden="true" parent="AuxFrame" setAllPoints="true">
|
|
||||||
<Frames>
|
<Frames>
|
||||||
<Frame name="$parentFilter" inherits="AuxFrameBoxTemplate">
|
<Frame name="$parentFilter" inherits="AuxFrameBoxTemplate">
|
||||||
<Anchors>
|
<Anchors>
|
||||||
|
|||||||
@@ -1,14 +1,6 @@
|
|||||||
local private, public = {}, {}
|
local private, public = {}, {}
|
||||||
Aux.stack = public
|
Aux.stack = public
|
||||||
|
|
||||||
function private.as_soon_as(p, k)
|
|
||||||
if p() then
|
|
||||||
return k()
|
|
||||||
else
|
|
||||||
return Aux.control.wait(private.as_soon_as, p, k)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local state
|
local state
|
||||||
|
|
||||||
function private.item_slots(item_key)
|
function private.item_slots(item_key)
|
||||||
@@ -47,7 +39,7 @@ function private.move_item(from_slot, to_slot, amount, k)
|
|||||||
SplitContainerItem(from_slot.bag, from_slot.bag_slot, amount)
|
SplitContainerItem(from_slot.bag, from_slot.bag_slot, amount)
|
||||||
PickupContainerItem(to_slot.bag, to_slot.bag_slot)
|
PickupContainerItem(to_slot.bag, to_slot.bag_slot)
|
||||||
|
|
||||||
return private.as_soon_as(function() return private.stack_size(to_slot) == size_before + amount end, k)
|
return Aux.control.wait_until(function() return private.stack_size(to_slot) == size_before + amount end, k)
|
||||||
end
|
end
|
||||||
|
|
||||||
function private.item_key(slot)
|
function private.item_key(slot)
|
||||||
@@ -114,7 +106,7 @@ end
|
|||||||
|
|
||||||
function public.stop()
|
function public.stop()
|
||||||
if state then
|
if state then
|
||||||
Aux.control.kill(state.thread_id)
|
Aux.control.kill_thread(state.thread_id)
|
||||||
|
|
||||||
local callback, slot = state.callback, state.target_slot
|
local callback, slot = state.callback, state.target_slot
|
||||||
|
|
||||||
@@ -127,13 +119,13 @@ function public.stop()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function public.start(item_key, size, callback)
|
function public.start(item_key, size, callback)
|
||||||
private.as_soon_as(function()
|
Aux.control.wait_until(function()
|
||||||
public.stop()
|
public.stop()
|
||||||
|
|
||||||
local slots = private.item_slots(item_key)
|
local slots = private.item_slots(item_key)
|
||||||
local target_slot = slots()
|
local target_slot = slots()
|
||||||
|
|
||||||
local thread_id = Aux.control.new(private.process)
|
local thread_id = Aux.control.new_thread(private.process)
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
thread_id = thread_id,
|
thread_id = thread_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user