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