From 951498377c604993825d53250fd8ba28ec5ebe85 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Sat, 3 Oct 2015 01:25:05 +0200 Subject: [PATCH] scan improvements --- buy.xml | 8 ++-- control.lua | 101 ++++++++++++++++++++++------------------- control.xml | 2 +- scan.lua | 128 ++++++++++++++++++++-------------------------------- scan.xml | 16 +------ sell.lua | 6 +-- sell.xml | 8 ++-- util.lua | 10 ++++ 8 files changed, 124 insertions(+), 155 deletions(-) diff --git a/buy.xml b/buy.xml index 6cdf815..77ae4fc 100644 --- a/buy.xml +++ b/buy.xml @@ -374,8 +374,7 @@ - - + this:RegisterForDrag("LeftButton") this:StartMoving() @@ -388,7 +387,7 @@ - + @@ -426,7 +425,6 @@ - this:RegisterForDrag("LeftButton") this:StartMoving() @@ -440,7 +438,7 @@ - + diff --git a/control.lua b/control.lua index 81a3e2c..b6a3bc5 100644 --- a/control.lua +++ b/control.lua @@ -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 diff --git a/control.xml b/control.xml index 778c193..52db94d 100644 --- a/control.xml +++ b/control.xml @@ -2,7 +2,7 @@