scan improvements
This commit is contained in:
@@ -374,8 +374,7 @@
|
||||
|
||||
<Frame name="AuxBuyBuyoutDialog" frameStrata="FULLSCREEN_DIALOG" toplevel="true" enableMouse="true" hidden="true" movable="true">
|
||||
<Size><AbsDimension x="230" y="140" /></Size>
|
||||
<Anchors><Anchor point="TOPLEFT"><Offset><AbsDimension x="300" y="-150"/></Offset></Anchor></Anchors>
|
||||
|
||||
<Anchors><Anchor point="TOPLEFT"><Offset><AbsDimension x="300" y="-150"/></Offset></Anchor></Anchors>
|
||||
<Scripts>
|
||||
<OnLoad>this:RegisterForDrag("LeftButton")</OnLoad>
|
||||
<OnDragStart>this:StartMoving()</OnDragStart>
|
||||
@@ -388,7 +387,7 @@
|
||||
</Backdrop>
|
||||
<Frames>
|
||||
<SimpleHTML name="$parentHTML">
|
||||
<Size><AbsDimension x="200" y="110" /></Size>
|
||||
<Size><AbsDimension x="200" y="1" /></Size>
|
||||
<Anchors><Anchor point="TOPLEFT"><Offset><AbsDimension x="30" y="-30"/></Offset></Anchor></Anchors>
|
||||
<FontStringHeader1 inherits="GameFontNormalWhite"/>
|
||||
</SimpleHTML>
|
||||
@@ -426,7 +425,6 @@
|
||||
|
||||
<Size><AbsDimension x="230" y="170" /></Size>
|
||||
<Anchors><Anchor point="TOPLEFT"><Offset><AbsDimension x="300" y="-135"/></Offset></Anchor></Anchors>
|
||||
|
||||
<Scripts>
|
||||
<OnLoad>this:RegisterForDrag("LeftButton")</OnLoad>
|
||||
<OnDragStart>this:StartMoving()</OnDragStart>
|
||||
@@ -440,7 +438,7 @@
|
||||
|
||||
<Frames>
|
||||
<SimpleHTML name="$parentHTML">
|
||||
<Size><AbsDimension x="200" y="110" /></Size>
|
||||
<Size><AbsDimension x="200" y="1" /></Size>
|
||||
<Anchors><Anchor point="TOPLEFT"><Offset><AbsDimension x="30" y="-30"/></Offset></Anchor></Anchors>
|
||||
</SimpleHTML>
|
||||
<Frame name="$parentHighestBid" inherits="SmallMoneyFrameTemplate">
|
||||
|
||||
+54
-47
@@ -1,35 +1,39 @@
|
||||
Aux.control = {}
|
||||
|
||||
local event_listeners = {}
|
||||
|
||||
local update_listeners = {}
|
||||
|
||||
function Aux.control.on_event()
|
||||
for listener, _ in pairs(event_listeners) do
|
||||
if event == listener.event then
|
||||
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
|
||||
listener.action()
|
||||
if not listener.deleted then
|
||||
listener.action()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
function Aux.control.event_listener(event, action) -- async!
|
||||
function Aux.control.event_listener(event, action)
|
||||
local self = {}
|
||||
|
||||
local listener = { event=event, action=action }
|
||||
|
||||
function self:set_action(self, action)
|
||||
function self.set_action(action)
|
||||
listener.action = action
|
||||
end
|
||||
|
||||
function self:start(self)
|
||||
function self.start()
|
||||
Aux.util.set_add(event_listeners, listener)
|
||||
if not Aux.util.any(event_listeners, function(l) return l.event == event end) then
|
||||
AuxControlFrame:RegisterEvent(event)
|
||||
@@ -37,8 +41,8 @@ function Aux.control.event_listener(event, action) -- async!
|
||||
return self
|
||||
end
|
||||
|
||||
function self:stop(self)
|
||||
Aux.util.set_remove(event_listeners, listener)
|
||||
function self.stop()
|
||||
listener.deleted = true
|
||||
if not Aux.util.any(event_listeners, function(l) return l.event == event end) then
|
||||
AuxControlFrame:UnregisterEvent(event)
|
||||
end
|
||||
@@ -53,84 +57,87 @@ function Aux.control.update_listener(action)
|
||||
|
||||
local listener = { action=action }
|
||||
|
||||
function self:set_action(self, action)
|
||||
function self.set_action(action)
|
||||
listener.action = action
|
||||
end
|
||||
|
||||
function self:start(self)
|
||||
function self.start()
|
||||
Aux.util.set_add(update_listeners, listener)
|
||||
return self
|
||||
end
|
||||
|
||||
function self:stop(self)
|
||||
Aux.util.set_remove(update_listeners, listener)
|
||||
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()
|
||||
callback()
|
||||
return callback()
|
||||
end)
|
||||
|
||||
listener:start()
|
||||
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()
|
||||
end
|
||||
|
||||
function Aux.control.as_soon_as(p, callback)
|
||||
local listener = Aux.control.update_listener()
|
||||
|
||||
listener:set_action(function()
|
||||
listener.set_action(function()
|
||||
if p() then
|
||||
callback()
|
||||
listener:stop()
|
||||
listener.stop()
|
||||
return callback()
|
||||
end
|
||||
end)
|
||||
|
||||
listener:start()
|
||||
end
|
||||
|
||||
function Aux.control.on_next_event(event, callback)
|
||||
local ok
|
||||
|
||||
local listener = Aux.control.event_listener(event)
|
||||
|
||||
listener:set_action(function()
|
||||
listener:stop()
|
||||
ok = true
|
||||
end)
|
||||
|
||||
listener:start()
|
||||
|
||||
Aux.control.as_soon_as(function() return ok end, callback)
|
||||
listener.start()
|
||||
end
|
||||
|
||||
|
||||
|
||||
function Aux.control.timer()
|
||||
function Aux.control.controller()
|
||||
local self = {}
|
||||
|
||||
local t_0
|
||||
local state
|
||||
|
||||
function self:start(self)
|
||||
t_0 = GetTime()
|
||||
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:after(self, t, callback)
|
||||
Aux.util.as_soon_as(function() return t_0 and GetTime() - t_0 > t end, callback)
|
||||
function self.cleanup()
|
||||
listener.stop()
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function Aux.control.after_time(t, callback)
|
||||
local timer = Aux.control.timer()
|
||||
timer:start()
|
||||
timer:after(t, callback)
|
||||
end
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
<Script file="control.lua"/>
|
||||
|
||||
<Frame>
|
||||
<Frame name="AuxControlFrame">
|
||||
<Scripts>
|
||||
<OnEvent>
|
||||
Aux.control.on_event()
|
||||
|
||||
@@ -2,110 +2,79 @@ Aux.scan = {}
|
||||
|
||||
local AUCTIONS_PER_PAGE = 50
|
||||
|
||||
|
||||
local controller = (function()
|
||||
local controller
|
||||
return function()
|
||||
controller = controller or Aux.control.controller()
|
||||
return controller
|
||||
end
|
||||
end)()
|
||||
|
||||
local state, abort, new_job
|
||||
|
||||
-- forward declaration of local functions
|
||||
local wait, wait_after, wait_for_function, wait_until, listen_for_event
|
||||
local wait_for_callback, wait_for_results, wait_for_update
|
||||
local scan, scan_auctions, scan_auctions_helper, submit_query
|
||||
|
||||
|
||||
|
||||
function Aux.scan.on_update()
|
||||
if abort then
|
||||
if state and state.job and state.job.on_abort then
|
||||
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
|
||||
|
||||
function Aux.scan.start(job)
|
||||
abort = true
|
||||
new_job = job
|
||||
Aux.scan.abort(function() --;
|
||||
wait_for_update(function() --;
|
||||
state = {
|
||||
job = job,
|
||||
page = job.page
|
||||
}
|
||||
return scan()
|
||||
end)end)
|
||||
end
|
||||
|
||||
function Aux.scan.abort()
|
||||
abort = true
|
||||
function Aux.scan.abort(k)
|
||||
wait_for_update(function() --;
|
||||
if state and state.job and state.job.on_abort then
|
||||
state.job.on_abort()
|
||||
end
|
||||
state = nil
|
||||
|
||||
if k then
|
||||
return k()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
|
||||
function wait(timeout, k)
|
||||
state.continuation = k
|
||||
local start_time = GetTime()
|
||||
state.ready = function()
|
||||
return GetTime() - start_time >= timeout
|
||||
end
|
||||
function wait_for_results(k)
|
||||
local ok
|
||||
Aux.control.on_next_event('AUCTION_ITEM_LIST_UPDATE', function()
|
||||
ok = true
|
||||
end)
|
||||
|
||||
return controller().wait(function() return ok end, k)
|
||||
end
|
||||
|
||||
function wait_from()
|
||||
local from
|
||||
return function()
|
||||
from = GetTime()
|
||||
end,
|
||||
function(timeout, k)
|
||||
state.continuation = k
|
||||
state.ready = function()
|
||||
return from and GetTime() - from >= timeout
|
||||
end
|
||||
end
|
||||
function wait_for_update(k)
|
||||
return controller().wait(function() return true end, k)
|
||||
end
|
||||
|
||||
function listen_for_event(e)
|
||||
local occurred
|
||||
Aux.scan.on_event = function()
|
||||
if event == e then
|
||||
occurred = true
|
||||
end
|
||||
end
|
||||
return function(k)
|
||||
state.continuation = k
|
||||
state.ready = function()
|
||||
return occurred
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function wait_for_function(f, args, k)
|
||||
state.continuation = k
|
||||
local complete
|
||||
state.ready = function()
|
||||
return complete
|
||||
end
|
||||
function wait_for_callback(f, args, k)
|
||||
local ok
|
||||
|
||||
if not f then
|
||||
complete = true
|
||||
ok = true
|
||||
else
|
||||
tinsert(args, 1, function() complete = true end)
|
||||
tinsert(args, 1, function() ok = true end)
|
||||
f(unpack(args))
|
||||
end
|
||||
end
|
||||
|
||||
function wait_until(p, k)
|
||||
state.continuation = k
|
||||
state.ready = function()
|
||||
return p()
|
||||
end
|
||||
return controller().wait(function() return ok end, k)
|
||||
end
|
||||
|
||||
|
||||
|
||||
function scan()
|
||||
|
||||
wait_for_function(state.job.on_start_page, {state.page}, function() --;
|
||||
wait_for_callback(state.job.on_start_page, {state.page}, function() --;
|
||||
|
||||
submit_query(function() --;
|
||||
|
||||
@@ -123,17 +92,18 @@ function scan()
|
||||
if state.job.on_complete then
|
||||
state.job.on_complete()
|
||||
end
|
||||
state = nil
|
||||
end
|
||||
|
||||
end)end)end)
|
||||
end
|
||||
|
||||
function scan_auctions(count, k)
|
||||
scan_auctions_helper(1, count, k)
|
||||
return scan_auctions_helper(1, count, k)
|
||||
end
|
||||
|
||||
function scan_auctions_helper(i, n, k)
|
||||
wait_for_function(state.job.on_read_auction, {i}, function() --;
|
||||
wait_for_callback(state.job.on_read_auction, {i}, function() --;
|
||||
|
||||
if i >= n then
|
||||
return k()
|
||||
@@ -146,8 +116,8 @@ end
|
||||
|
||||
function submit_query(k)
|
||||
if state.page then
|
||||
wait_until(CanSendAuctionQuery, function() --;
|
||||
local wait_for_event = listen_for_event('AUCTION_ITEM_LIST_UPDATE')
|
||||
controller().wait(CanSendAuctionQuery, function() --;
|
||||
wait_for_results(k)
|
||||
QueryAuctionItems(
|
||||
state.job.query.name,
|
||||
state.job.query.min_level,
|
||||
@@ -159,10 +129,8 @@ function submit_query(k)
|
||||
state.job.query.usable,
|
||||
state.job.query.quality
|
||||
)
|
||||
wait_for_event(k)
|
||||
|
||||
end)
|
||||
else
|
||||
k()
|
||||
return k()
|
||||
end
|
||||
end
|
||||
@@ -1,19 +1,5 @@
|
||||
<Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
|
||||
|
||||
<Script file="scan.lua"/>
|
||||
|
||||
<!-- Frame to handle all core events -->
|
||||
<Frame>
|
||||
<Scripts>
|
||||
<OnLoad>
|
||||
this:RegisterEvent("AUCTION_ITEM_LIST_UPDATE")
|
||||
</OnLoad>
|
||||
<OnEvent>
|
||||
Aux.scan.on_event()
|
||||
</OnEvent>
|
||||
<OnUpdate>
|
||||
Aux.scan.on_update()
|
||||
</OnUpdate>
|
||||
</Scripts>
|
||||
</Frame>
|
||||
|
||||
</Ui>
|
||||
@@ -506,7 +506,7 @@ end
|
||||
-----------------------------------------
|
||||
|
||||
function report(item_name, stack_size, buyout_price, posted)
|
||||
AuxBuyReportHTML:SetText(string.format(
|
||||
AuxSellReportHTML:SetText(string.format(
|
||||
[[
|
||||
<html>
|
||||
<body>
|
||||
@@ -528,7 +528,7 @@ function report(item_name, stack_size, buyout_price, posted)
|
||||
Aux.util.format_money(buyout_price)
|
||||
))
|
||||
|
||||
AuxBuyReportHTML:SetSpacing(3)
|
||||
AuxSellReportHTML:SetSpacing(3)
|
||||
|
||||
AuxBuyReport:Show()
|
||||
AuxSellReport:Show()
|
||||
end
|
||||
|
||||
@@ -395,7 +395,7 @@
|
||||
</EditBox>
|
||||
</frames>
|
||||
</frame>
|
||||
<Frame name="AuxBuyReport" frameStrata="FULLSCREEN_DIALOG" toplevel="true" parent="UIParent" enableMouse="true" hidden="true">
|
||||
<Frame name="AuxSellReport" frameStrata="FULLSCREEN_DIALOG" toplevel="true" parent="UIParent" enableMouse="true" hidden="true">
|
||||
<Size><AbsDimension x="400" y="180" /></Size>
|
||||
<Anchors><Anchor point="TOP"><Offset><AbsDimension x="0" y="-90"/></Offset></Anchor></Anchors>
|
||||
|
||||
@@ -406,8 +406,8 @@
|
||||
</Backdrop>
|
||||
|
||||
<Frames>
|
||||
<SimpleHTML name="AuxBuyReportHTML">
|
||||
<Size><AbsDimension x="420" y="420" /></Size>
|
||||
<SimpleHTML name="AuxSellReportHTML">
|
||||
<Size><AbsDimension x="420" y="1" /></Size>
|
||||
<Anchors><Anchor point="TOPLEFT"><Offset><AbsDimension x="30" y="-30"/></Offset></Anchor></Anchors>
|
||||
<FontString inherits="GameFontHighlightSmall"/>
|
||||
<FontStringHeader1 inherits="GameFontNormal"/>
|
||||
@@ -418,7 +418,7 @@
|
||||
<Anchors><Anchor point="BOTTOMRIGHT"><Offset><AbsDimension x="-20" y="15"/></Offset></Anchor></Anchors>
|
||||
<Scripts>
|
||||
<OnClick>
|
||||
AuxBuyReport:Hide()
|
||||
AuxSellReport:Hide()
|
||||
</OnClick>
|
||||
</Scripts>
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user