added a module system
This commit is contained in:
+26
-21
@@ -1,11 +1,11 @@
|
||||
local private, public = {}, {}
|
||||
Aux.control = public
|
||||
local m, private, public = Aux:module'control'
|
||||
|
||||
private.event_listeners = {}
|
||||
private.threads = {}
|
||||
public.thread_id = Aux.null
|
||||
|
||||
function public.on_event()
|
||||
for listener, _ in pairs(private.event_listeners) do
|
||||
for listener, _ in m.event_listeners do
|
||||
if event == listener.event and not listener.deleted then
|
||||
listener.action()
|
||||
end
|
||||
@@ -13,22 +13,22 @@ function public.on_event()
|
||||
end
|
||||
|
||||
function public.on_update()
|
||||
private.event_listeners = Aux.util.set_filter(private.event_listeners, function(l) return not l.deleted end)
|
||||
m.event_listeners = Aux.util.set_filter(m.event_listeners, function(l) return not l.deleted end)
|
||||
local threads = {}
|
||||
for thread_id, thread in pairs(private.threads) do
|
||||
for thread_id, thread in m.threads do
|
||||
if not thread.killed then
|
||||
threads[thread_id] = thread
|
||||
end
|
||||
end
|
||||
private.threads = threads
|
||||
m.threads = threads
|
||||
|
||||
for thread_id, thread in pairs(private.threads) do
|
||||
for thread_id, thread in m.threads do
|
||||
if not thread.killed then
|
||||
local k = thread.k
|
||||
thread.k = nil
|
||||
public.thread_id = thread_id
|
||||
m.thread_id = thread_id
|
||||
k()
|
||||
public.thread_id = nil
|
||||
m.thread_id = Aux.null
|
||||
if not thread.k then
|
||||
thread.killed = true
|
||||
end
|
||||
@@ -46,14 +46,14 @@ function public.event_listener(event, action)
|
||||
end
|
||||
|
||||
function self:start()
|
||||
Aux.util.set_add(private.event_listeners, listener)
|
||||
Aux.util.set_add(m.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(private.event_listeners), function(l) return l.event == event end) then
|
||||
if not Aux.util.any(Aux.util.set_to_array(m.event_listeners), function(l) return l.event == event end) then
|
||||
AuxControlFrame:UnregisterEvent(event)
|
||||
end
|
||||
return self
|
||||
@@ -63,7 +63,7 @@ function public.event_listener(event, action)
|
||||
end
|
||||
|
||||
function public.on_next_event(event, callback)
|
||||
local listener = public.event_listener(event)
|
||||
local listener = m.event_listener(event)
|
||||
|
||||
listener:set_action(function()
|
||||
listener:stop()
|
||||
@@ -74,12 +74,12 @@ function public.on_next_event(event, callback)
|
||||
end
|
||||
|
||||
function public.on_next_update(callback)
|
||||
return public.new_thread(callback)
|
||||
return m.new_thread(callback)
|
||||
end
|
||||
|
||||
function public.as_soon_as(p, callback)
|
||||
return public.new_thread(function()
|
||||
return public.wait_until(p, callback)
|
||||
return m.new_thread(function()
|
||||
return m.wait_until(p, callback)
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -88,20 +88,25 @@ do
|
||||
function public.new_thread(k)
|
||||
local thread_id = next_thread_id
|
||||
next_thread_id = next_thread_id + 1
|
||||
private.threads[thread_id] = { k = k }
|
||||
m.threads[thread_id] = { k = k }
|
||||
return thread_id
|
||||
end
|
||||
end
|
||||
|
||||
function public.kill_thread(thread_id)
|
||||
if thread_id and private.threads[thread_id] then
|
||||
private.threads[thread_id].killed = true
|
||||
if m.threads[thread_id] then
|
||||
m.threads[thread_id].killed = true
|
||||
end
|
||||
end
|
||||
|
||||
function public.wait(...)
|
||||
local k = tremove(arg, 1)
|
||||
private.threads[public.thread_id].k = function() return k(unpack(arg)) end
|
||||
if type(arg[1]) == 'number' then
|
||||
local count = tremove(arg, 1)
|
||||
m.wait_until(function() count = count - 1 return count <= 0 end, unpack(arg))
|
||||
else
|
||||
local k = tremove(arg, 1)
|
||||
m.threads[m.thread_id].k = function() return k(unpack(arg)) end
|
||||
end
|
||||
end
|
||||
|
||||
function public.wait_until(p, ...)
|
||||
@@ -109,6 +114,6 @@ function public.wait_until(p, ...)
|
||||
if p() then
|
||||
return k(unpack(arg))
|
||||
else
|
||||
return public.wait(public.wait_until, p, function() return k(unpack(arg)) end)
|
||||
return m.wait(m.wait_until, p, function() return k(unpack(arg)) end)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,52 @@
|
||||
Aux = {
|
||||
version = '2.15.9',
|
||||
blizzard_ui_shown = false,
|
||||
orig = {},
|
||||
}
|
||||
function Aux_module(self, name)
|
||||
local module, data, is_public, private, public = {}, {}, {}, {}, {}
|
||||
setmetatable(private, {
|
||||
__newindex = function(_, key, value)
|
||||
rawset(data, key, value)
|
||||
is_public[key] = nil
|
||||
end,
|
||||
})
|
||||
setmetatable(public, {
|
||||
__newindex = function(_, key, value)
|
||||
rawset(data, key, value)
|
||||
is_public[key] = true
|
||||
end,
|
||||
})
|
||||
setmetatable(data, {
|
||||
__newindex = function(_, key)
|
||||
if data[key] == nil then
|
||||
error('Assignment of undeclared module attribute "'..key..'"!')
|
||||
end
|
||||
end,
|
||||
})
|
||||
setmetatable(module, {
|
||||
__index = function(_, key)
|
||||
if is_public[key] then
|
||||
return data[key]
|
||||
end
|
||||
end,
|
||||
})
|
||||
self.modules[name] = module
|
||||
return data, private, public
|
||||
end
|
||||
|
||||
function Aux_addon()
|
||||
local addon = {
|
||||
metadata = metadata,
|
||||
modules = {},
|
||||
module = Aux_module,
|
||||
}
|
||||
setmetatable(addon, {
|
||||
__index = addon.modules,
|
||||
})
|
||||
return addon
|
||||
end
|
||||
|
||||
Aux = Aux_addon()
|
||||
|
||||
Aux.version = '2.15.10'
|
||||
Aux.blizzard_ui_shown = false
|
||||
Aux.orig = {}
|
||||
|
||||
function Aux.on_load()
|
||||
Aux.log('Aux v'..Aux.version..' loaded.')
|
||||
@@ -47,6 +91,12 @@ function Aux.on_load()
|
||||
end)
|
||||
end
|
||||
|
||||
for _, module in Aux.modules do
|
||||
if module.LOAD then
|
||||
module:LOAD()
|
||||
end
|
||||
end
|
||||
|
||||
Aux.cache.on_load()
|
||||
Aux.persistence.on_load()
|
||||
Aux.tooltip.on_load()
|
||||
@@ -443,11 +493,19 @@ function Aux.hook(name, handler, object)
|
||||
end
|
||||
|
||||
if orig[name] then
|
||||
error('Already got a hook for '..name)
|
||||
error('"'..name..'"'..'is already hooked!')
|
||||
end
|
||||
|
||||
orig[name] = object[name]
|
||||
object[name] = handler
|
||||
end
|
||||
|
||||
Aux.huge = 2^100000
|
||||
function Aux.tab(name)
|
||||
local private, public = Aux.module(name)
|
||||
tinsert(Aux.tabs, Aux[name])
|
||||
return private, public
|
||||
end
|
||||
|
||||
Aux.huge = 2^100000
|
||||
|
||||
Aux.null = {}
|
||||
@@ -92,5 +92,4 @@ function public.start(item_key, stack_size, duration, unit_start_price, unit_buy
|
||||
posted = 0,
|
||||
callback = callback,
|
||||
}
|
||||
|
||||
end
|
||||
+18
-7
@@ -125,13 +125,24 @@ function private.update_auction_listing()
|
||||
record = auction_record,
|
||||
})
|
||||
end
|
||||
sort(auction_rows, function(a, b) return Aux.sort.multi_lt(
|
||||
a.record.unit_buyout_price == 0 and Aux.huge or a.record.unit_buyout_price, b.record.unit_buyout_price == 0 and Aux.huge or b.record.unit_buyout_price,
|
||||
a.record.unit_blizzard_bid, b.record.unit_blizzard_bid,
|
||||
a.record.stack_size, b.record.stack_size,
|
||||
b.record.own and 1 or 0, a.record.own and 1 or 0,
|
||||
a.record.duration, b.record.duration
|
||||
) end)
|
||||
sort(auction_rows, function(a, b)
|
||||
return Aux.sort.multi_lt(
|
||||
{
|
||||
a.record.unit_buyout_price == 0 and Aux.huge or a.record.unit_buyout_price,
|
||||
a.record.unit_blizzard_bid,
|
||||
a.record.stack_size,
|
||||
b.record.own and 1 or 0,
|
||||
a.record.duration,
|
||||
},
|
||||
{
|
||||
b.record.unit_buyout_price == 0 and Aux.huge or b.record.unit_buyout_price,
|
||||
b.record.unit_blizzard_bid,
|
||||
b.record.stack_size,
|
||||
a.record.own and 1 or 0,
|
||||
b.record.duration,
|
||||
}
|
||||
)
|
||||
end)
|
||||
end
|
||||
private.auction_listing:SetData(auction_rows)
|
||||
end
|
||||
|
||||
@@ -78,6 +78,7 @@ function Aux.post_frame.create_frames(private, public)
|
||||
{ name='Buy/ea', width=.23, align='RIGHT' },
|
||||
{ name='Buy Pct', width=.12, align='CENTER' }
|
||||
})
|
||||
private.auction_listing:EnableSorting(false)
|
||||
private.auction_listing:DisableSelection(true)
|
||||
private.auction_listing:SetHandler('OnClick', function(table, row_data, column, button)
|
||||
local column_index = Aux.util.index_of(column, column.row.cols)
|
||||
|
||||
@@ -629,8 +629,9 @@ function Aux.search_frame.create_frames(private, public)
|
||||
}
|
||||
|
||||
private.recent_searches_listing = Aux.listing.CreateScrollingTable(AuxSearchFrameSavedRecent)
|
||||
private.recent_searches_listing:DisableSelection(true)
|
||||
private.recent_searches_listing:SetColInfo({{name='Recent Searches', width=1}})
|
||||
private.recent_searches_listing:EnableSorting(false)
|
||||
private.recent_searches_listing:DisableSelection(true)
|
||||
private.recent_searches_listing:SetHandler('OnClick', handlers.OnClick)
|
||||
private.recent_searches_listing:SetHandler('OnEnter', handlers.OnEnter)
|
||||
private.recent_searches_listing:SetHandler('OnLeave', handlers.OnLeave)
|
||||
@@ -638,8 +639,9 @@ function Aux.search_frame.create_frames(private, public)
|
||||
Aux.gui.vertical_line(AuxSearchFrameSaved, 379)
|
||||
|
||||
private.favorite_searches_listing = Aux.listing.CreateScrollingTable(AuxSearchFrameSavedFavorite)
|
||||
private.favorite_searches_listing:DisableSelection(true)
|
||||
private.favorite_searches_listing:SetColInfo({{name='Favorite Searches', width=1}})
|
||||
private.favorite_searches_listing:EnableSorting(false)
|
||||
private.favorite_searches_listing:DisableSelection(true)
|
||||
private.favorite_searches_listing:SetHandler('OnClick', handlers.OnClick)
|
||||
private.favorite_searches_listing:SetHandler('OnEnter', handlers.OnEnter)
|
||||
private.favorite_searches_listing:SetHandler('OnLeave', handlers.OnLeave)
|
||||
|
||||
@@ -692,7 +692,7 @@ local methods = {
|
||||
self.isSorted = nil
|
||||
self:SetSelectedRecord(nil, true)
|
||||
|
||||
sort(self.records, function(a, b) return Aux.sort.multi_lt(a.search_signature, b.search_signature, tostring(a), tostring(b)) end)
|
||||
sort(self.records, function(a, b) return Aux.sort.multi_lt({a.search_signature, tostring(a)}, {b.search_signature, tostring(b)}) end)
|
||||
|
||||
local records = self.records
|
||||
if getn(records) == 0 then return end
|
||||
|
||||
@@ -176,6 +176,13 @@ local methods = {
|
||||
st.sortInfo.col = abs(defaultCol or 1)
|
||||
st.sortInfo.ascending = not defaultCol or defaultCol > 0
|
||||
st.updateSort = true
|
||||
for _, headCol in st.headCols do
|
||||
if value then
|
||||
headCol:EnableMouse(true)
|
||||
else
|
||||
headCol:EnableMouse(false)
|
||||
end
|
||||
end
|
||||
st:RefreshRows()
|
||||
end,
|
||||
|
||||
|
||||
+11
-5
@@ -37,11 +37,17 @@ function public.compare_from_lt(lt)
|
||||
end
|
||||
end
|
||||
|
||||
function public.multi_lt(...)
|
||||
for i=1,arg.n-1,2 do
|
||||
if arg[i] ~= arg[i+1] then
|
||||
return arg[i] < arg[i+1]
|
||||
function public.multi_lt(xs, ys)
|
||||
local i = 1
|
||||
while true do
|
||||
if xs[i] and ys[i] and xs[i] ~= ys[i] then
|
||||
return xs[i] < ys[i]
|
||||
elseif not xs[i] and ys[i] then
|
||||
return true
|
||||
elseif not ys[i] then
|
||||
return false
|
||||
end
|
||||
|
||||
i = i + 1
|
||||
end
|
||||
return false
|
||||
end
|
||||
Reference in New Issue
Block a user