working on big scan/control refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-02-25 16:31:11 +01:00
parent 5af1b28021
commit 1a0b7597bd
9 changed files with 52 additions and 162 deletions
+1 -4
View File
@@ -2,15 +2,12 @@
<Script file="auctions_frame.lua"/>
<Frame>
<Frame name="AuxAuctionsFrame" hidden="true" parent="AuxFrame" setAllPoints="true">
<Scripts>
<OnUpdate>
Aux.auctions_frame.on_update()
</OnUpdate>
</Scripts>
</Frame>
<Frame name="AuxAuctionsFrame" hidden="true" parent="AuxFrame" setAllPoints="true">
<Frames>
<Frame name="$parentListing" inherits="AuxFrameBoxTemplate">
<Anchors>
+1 -4
View File
@@ -2,15 +2,12 @@
<Script file="bids_frame.lua"/>
<Frame>
<Frame name="AuxBidsFrame" hidden="true" parent="AuxFrame" setAllPoints="true">
<Scripts>
<OnUpdate>
Aux.bids_frame.on_update()
</OnUpdate>
</Scripts>
</Frame>
<Frame name="AuxBidsFrame" hidden="true" parent="AuxFrame" setAllPoints="true">
<Frames>
<Frame name="$parentListing" inherits="AuxFrameBoxTemplate">
<Anchors>
+26 -100
View File
@@ -1,27 +1,19 @@
local private, public = {}, {}
Aux.control = public
local event_listeners = {}
local update_listeners = {}
private.event_listeners = {}
private.threads = {}
function Aux.control.on_event()
for listener, _ in pairs(event_listeners) do
function public.on_event()
for listener, _ in pairs(private.event_listeners) do
if event == listener.event and not listener.deleted then
listener.action()
end
end
end
function Aux.control.on_update()
event_listeners = Aux.util.set_filter(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
function public.on_update()
private.event_listeners = Aux.util.set_filter(private.event_listeners, function(l) return not l.deleted end)
for thread_id, k in pairs(private.threads) do
private.threads[thread_id] = nil
@@ -31,9 +23,7 @@ function Aux.control.on_update()
end
end
function Aux.control.event_listener(event, action)
function public.event_listener(event, action)
local self = {}
local listener = { event=event, action=action }
@@ -43,14 +33,14 @@ function Aux.control.event_listener(event, action)
end
function self:start()
Aux.util.set_add(event_listeners, listener)
Aux.util.set_add(private.event_listeners, listener)
AuxControlFrame:RegisterEvent(event)
return self
end
function self:stop()
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)
end
return self
@@ -59,32 +49,8 @@ function Aux.control.event_listener(event, action)
return self
end
function Aux.control.update_listener(action)
local self = {}
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()
function public.on_next_event(event, callback)
local listener = public.event_listener(event)
listener:set_action(function()
listener:stop()
@@ -94,68 +60,19 @@ function Aux.control.on_next_update(callback)
listener:start()
end
function Aux.control.on_next_event(event, callback)
local listener = Aux.control.event_listener(event)
listener:set_action(function()
listener:stop()
return callback()
end)
listener:start()
function public.on_next_update(callback)
return public.new_thread(callback)
end
function Aux.control.as_soon_as(p, callback)
local listener = Aux.control.update_listener()
listener:set_action(function()
if p() then
listener:stop()
return callback()
end
function public.as_soon_as(p, callback)
return public.new_thread(function()
return public.wait_until(p, callback)
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
do
local next_thread_id = 1
function public.new(k)
function public.new_thread(k)
local thread_id = next_thread_id
next_thread_id = next_thread_id + 1
private.threads[thread_id] = k
@@ -163,7 +80,7 @@ do
end
end
function public.kill(thread_id)
function public.kill_thread(thread_id)
private.threads[thread_id] = nil
end
@@ -171,3 +88,12 @@ function public.wait(...)
local k = tremove(arg, 1)
private.threads[public.thread_id] = function() return k(unpack(arg)) 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
+4 -4
View File
@@ -1,7 +1,7 @@
<Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
<Script file="core.lua"/>
<Script file="core.lua"/>
<Frame>
<Scripts>
<OnLoad>
@@ -12,9 +12,9 @@
this:RegisterEvent('AUCTION_BIDDER_LIST_UPDATE')
this:RegisterEvent('AUCTION_OWNED_LIST_UPDATE')
</OnLoad>
<OnEvent>
<OnEvent>
Aux.on_event()
</OnEvent>
</OnEvent>
</Scripts>
</Frame>
+4 -12
View File
@@ -3,14 +3,6 @@ Aux.post = public
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()
if state.posted < state.count or state.allow_partial then
if state.posted == state.count then
@@ -29,7 +21,7 @@ function private.process()
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
private.post_auction(stack_slot, function(stack_size)
@@ -58,14 +50,14 @@ function private.post_auction(slot, k)
ClearCursor()
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)
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)
end)
end
function public.stop()
if state then
Aux.control.kill(state.thread_id)
Aux.control.kill_thread(state.thread_id)
local callback = state.callback
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)
public.stop()
local thread_id = Aux.control.new(private.process)
local thread_id = Aux.control.new_thread(private.process)
state = {
thread_id = thread_id,
+5 -8
View File
@@ -2,19 +2,16 @@
<Script file="post_frame.lua"/>
<Frame>
<Scripts>
<OnUpdate>
Aux.post_frame.on_update()
</OnUpdate>
</Scripts>
</Frame>
<Frame name="AuxPostFrame" parent="AuxFrame" hidden="true">
<Anchors>
<Anchor point="TOPLEFT"><Offset><AbsDimension x="0" y="0"/></Offset></Anchor>
<Anchor point="BOTTOMRIGHT"><Offset><AbsDimension x="0" y="0"/></Offset></Anchor>
</Anchors>
<Scripts>
<OnUpdate>
Aux.post_frame.on_update()
</OnUpdate>
</Scripts>
<Frames>
<Frame name="$parentContent" inherits="AuxFrameBoxTemplate">
<Anchors>
+6 -14
View File
@@ -30,7 +30,7 @@ end
function public.start(params)
public.abort(params.type)
local thread_id = Aux.control.new(private.scan)
local thread_id = Aux.control.new_thread(private.scan)
threads[params.type] = {
id = thread_id,
params = params,
@@ -44,19 +44,11 @@ function public.abort(type)
thread.params.on_abort()
end
threads[t] = nil
Aux.control.kill(thread.id)
Aux.control.kill_thread(thread.id)
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)
if current_thread().params.type == 'bidder' then
return private.wait_for_bidder_results(k)
@@ -85,7 +77,7 @@ function private.wait_for_owner_results(k)
end)
end
private.as_soon_as(function() return updated end, k)
Aux.control.wait_until(function() return updated end, k)
end
function private.wait_for_list_results(k)
@@ -95,7 +87,7 @@ function private.wait_for_list_results(k)
updated = true
end)
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
local ok = updated and private.owner_data_complete() or last_update and GetTime() - last_update > 5
updated = false
@@ -137,7 +129,7 @@ function wait_for_callback(args) -- the arguments must not be nil!
if ok then
return k()
else
return private.as_soon_as(function() return ok end, k)
return Aux.control.wait_until(function() return ok end, k)
end
end
@@ -218,7 +210,7 @@ end
function submit_query(k)
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
current_thread().params.on_submit_query()
+1 -4
View File
@@ -2,15 +2,12 @@
<Script file="search_frame.lua"/>
<Frame name="AuxControlFrame">
<Frame name="AuxSearchFrame" hidden="true" parent="AuxFrame" setAllPoints="true">
<Scripts>
<OnUpdate>
Aux.search_frame.on_update()
</OnUpdate>
</Scripts>
</Frame>
<Frame name="AuxSearchFrame" hidden="true" parent="AuxFrame" setAllPoints="true">
<Frames>
<Frame name="$parentFilter" inherits="AuxFrameBoxTemplate">
<Anchors>
+4 -12
View File
@@ -1,14 +1,6 @@
local private, 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
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)
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
function private.item_key(slot)
@@ -114,7 +106,7 @@ end
function public.stop()
if state then
Aux.control.kill(state.thread_id)
Aux.control.kill_thread(state.thread_id)
local callback, slot = state.callback, state.target_slot
@@ -127,13 +119,13 @@ function public.stop()
end
function public.start(item_key, size, callback)
private.as_soon_as(function()
Aux.control.wait_until(function()
public.stop()
local slots = private.item_slots(item_key)
local target_slot = slots()
local thread_id = Aux.control.new(private.process)
local thread_id = Aux.control.new_thread(private.process)
state = {
thread_id = thread_id,