module refactoring
This commit is contained in:
committed by
Simon Hirsig
parent
5e093306e6
commit
62ef2683f5
+12
-12
@@ -25,10 +25,10 @@ M.print = vararg-function(arg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local bids_loaded
|
local bids_loaded
|
||||||
function M.get_bids_loaded() return bids_loaded end
|
function M.get.bids_loaded() return bids_loaded end
|
||||||
|
|
||||||
local current_owner_page
|
local current_owner_page
|
||||||
function M.get_current_owner_page() return current_owner_page end
|
function M.get.current_owner_page() return current_owner_page end
|
||||||
|
|
||||||
local event_frame = CreateFrame'Frame'
|
local event_frame = CreateFrame'Frame'
|
||||||
for event in pairs(temp-S('ADDON_LOADED', 'VARIABLES_LOADED', 'PLAYER_LOGIN', 'AUCTION_HOUSE_SHOW', 'AUCTION_HOUSE_CLOSED', 'AUCTION_BIDDER_LIST_UPDATE', 'AUCTION_OWNED_LIST_UPDATE')) do
|
for event in pairs(temp-S('ADDON_LOADED', 'VARIABLES_LOADED', 'PLAYER_LOGIN', 'AUCTION_HOUSE_SHOW', 'AUCTION_HOUSE_CLOSED', 'AUCTION_BIDDER_LIST_UPDATE', 'AUCTION_OWNED_LIST_UPDATE')) do
|
||||||
@@ -37,10 +37,10 @@ end
|
|||||||
|
|
||||||
do
|
do
|
||||||
local handlers, handlers2 = {}, {}
|
local handlers, handlers2 = {}, {}
|
||||||
function M.set_LOAD(f)
|
function M.set.LOAD(f)
|
||||||
tinsert(handlers, f)
|
tinsert(handlers, f)
|
||||||
end
|
end
|
||||||
function M.set_LOAD2(f)
|
function M.set.LOAD2(f)
|
||||||
tinsert(handlers2, f)
|
tinsert(handlers2, f)
|
||||||
end
|
end
|
||||||
event_frame:SetScript('OnEvent', function()
|
event_frame:SetScript('OnEvent', function()
|
||||||
@@ -88,7 +88,7 @@ do
|
|||||||
for scope in pairs(temp-S('character', 'faction', 'realm', 'account')) do
|
for scope in pairs(temp-S('character', 'faction', 'realm', 'account')) do
|
||||||
local scope = scope
|
local scope = scope
|
||||||
M[scope .. '_data'] = function(key, init)
|
M[scope .. '_data'] = function(key, init)
|
||||||
if not cache[scope] then error('Cache not ready', 2) end
|
if not cache[scope] then error('Cache for ' .. scope .. ' data not ready.', 2) end
|
||||||
cache[scope][key] = cache[scope][key] or {}
|
cache[scope][key] = cache[scope][key] or {}
|
||||||
for k, v in pairs(init or empty) do
|
for k, v in pairs(init or empty) do
|
||||||
if cache[scope][key][k] == nil then
|
if cache[scope][key][k] == nil then
|
||||||
@@ -104,16 +104,16 @@ tab_info = {}
|
|||||||
function M.TAB(name)
|
function M.TAB(name)
|
||||||
local tab = O('name', name)
|
local tab = O('name', name)
|
||||||
local env = getfenv(2)
|
local env = getfenv(2)
|
||||||
function env.set_OPEN(f) tab.OPEN = f end
|
function env.set.OPEN(f) tab.OPEN = f end
|
||||||
function env.set_CLOSE(f) tab.CLOSE = f end
|
function env.set.CLOSE(f) tab.CLOSE = f end
|
||||||
function env.set_USE_ITEM(f) tab.USE_ITEM = f end
|
function env.set.USE_ITEM(f) tab.USE_ITEM = f end
|
||||||
function env.set_CLICK_LINK(f) tab.CLICK_LINK = f end
|
function env.set.CLICK_LINK(f) tab.CLICK_LINK = f end
|
||||||
tinsert(tab_info, tab)
|
tinsert(tab_info, tab)
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
local index
|
local index
|
||||||
function get_active_tab() return tab_info[index] end
|
function get.active_tab() return tab_info[index] end
|
||||||
function on_tab_click(i)
|
function on_tab_click(i)
|
||||||
CloseDropDownMenus()
|
CloseDropDownMenus()
|
||||||
do (index and active_tab.CLOSE or nop)() end
|
do (index and active_tab.CLOSE or nop)() end
|
||||||
@@ -159,7 +159,7 @@ end
|
|||||||
|
|
||||||
do
|
do
|
||||||
local locked
|
local locked
|
||||||
function M.get_bid_in_progress() return locked end
|
function M.get.bid_in_progress() return locked end
|
||||||
function M.place_bid(type, index, amount, on_success)
|
function M.place_bid(type, index, amount, on_success)
|
||||||
if locked then return end
|
if locked then return end
|
||||||
local money = GetMoney()
|
local money = GetMoney()
|
||||||
@@ -184,7 +184,7 @@ end
|
|||||||
|
|
||||||
do
|
do
|
||||||
local locked
|
local locked
|
||||||
function M.get_cancel_in_progress() return locked end
|
function M.get.cancel_in_progress() return locked end
|
||||||
function M.cancel_auction(index, on_success)
|
function M.cancel_auction(index, on_success)
|
||||||
if locked then return end
|
if locked then return end
|
||||||
locked = true
|
locked = true
|
||||||
|
|||||||
+2
-2
@@ -5,7 +5,7 @@ local event_frame = CreateFrame'Frame'
|
|||||||
local listeners, threads = T, T
|
local listeners, threads = T, T
|
||||||
|
|
||||||
local thread_id
|
local thread_id
|
||||||
function M.get_thread_id() return thread_id end
|
function M.get.thread_id() return thread_id end
|
||||||
|
|
||||||
function LOAD()
|
function LOAD()
|
||||||
event_frame:SetScript('OnUpdate', UPDATE)
|
event_frame:SetScript('OnUpdate', UPDATE)
|
||||||
@@ -50,7 +50,7 @@ end
|
|||||||
|
|
||||||
do
|
do
|
||||||
local id = 0
|
local id = 0
|
||||||
function get_unique_id()
|
function get.unique_id()
|
||||||
id = id + 1
|
id = id + 1
|
||||||
return id
|
return id
|
||||||
end
|
end
|
||||||
|
|||||||
+2
-2
@@ -15,7 +15,7 @@ end
|
|||||||
|
|
||||||
do
|
do
|
||||||
local next_push = 0
|
local next_push = 0
|
||||||
function get_next_push()
|
function get.next_push()
|
||||||
if time() > next_push then
|
if time() > next_push then
|
||||||
local date = date('*t')
|
local date = date('*t')
|
||||||
date.hour, date.min, date.sec = 24, 0, 0
|
date.hour, date.min, date.sec = 24, 0, 0
|
||||||
@@ -25,7 +25,7 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_new_record()
|
function get.new_record()
|
||||||
return temp-O('next_push', next_push, 'data_points', T)
|
return temp-O('next_push', next_push, 'data_points', T)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -49,7 +49,7 @@ do
|
|||||||
do (on_complete or nop)() end
|
do (on_complete or nop)() end
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_state()
|
function get.state()
|
||||||
for _, state in pairs(scan_states) do
|
for _, state in pairs(scan_states) do
|
||||||
if state.id == thread_id then
|
if state.id == thread_id then
|
||||||
return state
|
return state
|
||||||
@@ -58,7 +58,7 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_query()
|
function get.query()
|
||||||
return state.params.queries[state.query_index]
|
return state.params.queries[state.query_index]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ end
|
|||||||
do
|
do
|
||||||
tabs = gui.tabs(AuxFrame, 'DOWN')
|
tabs = gui.tabs(AuxFrame, 'DOWN')
|
||||||
tabs._on_select = on_tab_click
|
tabs._on_select = on_tab_click
|
||||||
function M.set_tab(id) tabs:select(id) end
|
function M.set.tab(id) tabs:select(id) end
|
||||||
end
|
end
|
||||||
do
|
do
|
||||||
local btn = gui.button(AuxFrame)
|
local btn = gui.button(AuxFrame)
|
||||||
|
|||||||
+1
-1
@@ -88,7 +88,7 @@ M.font_size = immutable-{
|
|||||||
|
|
||||||
do
|
do
|
||||||
local id = 1
|
local id = 1
|
||||||
function M.get_unique_name()
|
function M.get.unique_name()
|
||||||
id = id + 1
|
id = id + 1
|
||||||
return 'AuxFrame' .. id
|
return 'AuxFrame' .. id
|
||||||
end
|
end
|
||||||
|
|||||||
+1
-1
@@ -56,7 +56,7 @@ do
|
|||||||
M.static = setmetatable({}, {__metatable=false, __newindex=nop, __call=f, __sub=f})
|
M.static = setmetatable({}, {__metatable=false, __newindex=nop, __call=f, __sub=f})
|
||||||
end
|
end
|
||||||
|
|
||||||
M.get_T = acquire
|
M.get.T = acquire
|
||||||
|
|
||||||
do
|
do
|
||||||
local function ret(t)
|
local function ret(t)
|
||||||
|
|||||||
+24
-52
@@ -1,62 +1,34 @@
|
|||||||
if module then return end
|
if module then return end
|
||||||
local strfind, type, setmetatable, setfenv, _G = strfind, type, setmetatable, setfenv, getfenv(0)
|
local _G, setfenv, setmetatable, rawget = getfenv(0), setfenv, setmetatable, rawget
|
||||||
local error, nop, define, include, create_module, nop_default_mt, public_modifier_mt, proxy_mt
|
|
||||||
local loaded, defined, interfaces, environments = {}, {}, {}, {}
|
local loaded, defined, interfaces, environments = {}, {}, {}, {}
|
||||||
|
|
||||||
function nop() end
|
local function nop() end
|
||||||
function error(msg, ...) return _G.error(format(msg or '', unpack(arg)) .. '\n' .. debugstack(), 0) end
|
|
||||||
|
|
||||||
function define(self, k, v, private)
|
local function include(private, name)
|
||||||
if type(k) ~= 'string' or not strfind(k, '^[_%a][_%w]*') then error('Invalid identifier "%s".', k) end
|
local P = loaded[name] or error('No such module.', 2)
|
||||||
local _, _, prefix, suffix = strfind(k, '^(.?.?.?.?)([_%a].*)')
|
for k, v in P.public do private[k] = v end
|
||||||
local module = loaded[self]
|
|
||||||
local signature = (private and '-' or '+') .. k
|
|
||||||
module.defined[signature] = module.defined[signature] and error('Duplicate identifier "%s".', signature) or true
|
|
||||||
if private or not module.defined['-' .. k] then
|
|
||||||
module.fields[k] = v
|
|
||||||
if prefix == 'get_' then module.accessors[suffix] = v elseif prefix == 'set_' then module.mutators[suffix] = v end
|
|
||||||
end
|
|
||||||
if not private then
|
|
||||||
module.public_fields[k] = v
|
|
||||||
if prefix == 'get_' then module.public_accessors[suffix] = v elseif prefix == 'set_' then module.public_mutators[suffix] = v end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function include(self, name)
|
local function create_module(name)
|
||||||
local module = name and loaded[name] or error('No module "%s".', name)
|
local P, private, public, modifier
|
||||||
for k, v in pairs(module.public_fields) do define(self, k, v, true) end
|
local modifier = setmetatable({}, {
|
||||||
end
|
__metatable=false,
|
||||||
|
__newindex=function(_, k, v)
|
||||||
public_modifier_mt = {__metatable=false, __newindex=define}
|
public[k] = v
|
||||||
|
if rawget(private, k) == nil then
|
||||||
nop_default_mt = {__index=function() return nop end}
|
private[k] = v
|
||||||
|
end
|
||||||
function proxy_mt(fields, mutators)
|
end
|
||||||
return {__metatable=false, __index=fields, __newindex=function(_, k, v) return mutators[k](v) end}
|
})
|
||||||
end
|
local env = setmetatable(
|
||||||
|
{_G=_G, _M=private, M=modifier, include=function(name) include(private, name) end, nop=nop},
|
||||||
function create_module(name)
|
{__index=_G}
|
||||||
if type(name) ~= 'string' then error('Invalid module name "%s".', name) end
|
|
||||||
local P, environment, interface, public_modifier, accessors, mutators, fields, public_accessors, public_mutators, public_fields
|
|
||||||
environment, interface, public_modifier = {}, {}, setmetatable({}, public_modifier_mt)
|
|
||||||
accessors = {M=function() return public_modifier end}
|
|
||||||
mutators = setmetatable({_=nop}, {__index=function(_, k) return function(v) define(name, k, v, true) end end})
|
|
||||||
fields = setmetatable(
|
|
||||||
{_M=environment, _G=_G, include=function(interface) include(name, interface) end, nop=nop},
|
|
||||||
{__index=function(_, k) local accessor = accessors[k]; if accessor then return accessor() else return _G[k] end end}
|
|
||||||
)
|
)
|
||||||
public_accessors = setmetatable({}, nop_default_mt)
|
local public = {}
|
||||||
public_mutators = setmetatable({}, nop_default_mt)
|
local interface = setmetatable({}, {__metatable=false, __index=public})
|
||||||
public_fields = setmetatable({}, {__index=function(_, k) return public_accessors[k]() end})
|
P = {private=private, public=public}
|
||||||
setmetatable(environment, proxy_mt(fields, mutators))
|
environments[name], interfaces[name] = env, interface
|
||||||
setmetatable(interface, proxy_mt(public_fields, public_mutators))
|
loaded[name] = P
|
||||||
P = {
|
|
||||||
defined = {['-_M']=true, ['-_G']=true, ['-include']=true, ['-nop']=true, ['-M']=true, ['-set__']=true, ['-require']=true},
|
|
||||||
fields = fields, accessors = accessors, mutators = mutators,
|
|
||||||
public_fields = public_fields, public_accessors = public_accessors, public_mutators = public_mutators,
|
|
||||||
}
|
|
||||||
environments[name], interfaces[name] = environment, interface
|
|
||||||
loaded[name], loaded[public_modifier] = P, P
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function module(name) if not loaded[name] then create_module(name) end defined[name] = true; setfenv(2, environments[name]) end
|
function module(name) if not loaded[name] then create_module(name) end defined[name] = true; setfenv(2, environments[name]) end
|
||||||
|
|||||||
+13
-13
@@ -22,7 +22,7 @@ local settings_schema = {'tuple', '#', {duration='number'}, {start_price='number
|
|||||||
|
|
||||||
local scan_id, inventory_records, bid_records, buyout_records = 0, {}, {}, {}
|
local scan_id, inventory_records, bid_records, buyout_records = 0, {}, {}, {}
|
||||||
|
|
||||||
function get_default_settings()
|
function get.default_settings()
|
||||||
return O('duration', DURATION_8, 'start_price', 0, 'buyout_price', 0, 'hidden', false)
|
return O('duration', DURATION_8, 'start_price', 0, 'buyout_price', 0, 'hidden', false)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -41,16 +41,16 @@ end
|
|||||||
|
|
||||||
do
|
do
|
||||||
local bid_selections, buyout_selections = {}, {}
|
local bid_selections, buyout_selections = {}, {}
|
||||||
function get_bid_selection()
|
function get.bid_selection()
|
||||||
return bid_selections[selected_item.key]
|
return bid_selections[selected_item.key]
|
||||||
end
|
end
|
||||||
function set_bid_selection(record)
|
function set.bid_selection(record)
|
||||||
bid_selections[selected_item.key] = record
|
bid_selections[selected_item.key] = record
|
||||||
end
|
end
|
||||||
function get_buyout_selection()
|
function get.buyout_selection()
|
||||||
return buyout_selections[selected_item.key]
|
return buyout_selections[selected_item.key]
|
||||||
end
|
end
|
||||||
function set_buyout_selection(record)
|
function set.buyout_selection(record)
|
||||||
buyout_selections[selected_item.key] = record
|
buyout_selections[selected_item.key] = record
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -63,14 +63,14 @@ end
|
|||||||
|
|
||||||
do
|
do
|
||||||
local item
|
local item
|
||||||
function get_selected_item() return item end
|
function get.selected_item() return item end
|
||||||
function set_selected_item(v) item = v end
|
function set.selected_item(v) item = v end
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
local c = 0
|
local c = 0
|
||||||
function get_refresh() return c end
|
function get.refresh() return c end
|
||||||
function set_refresh(v) c = v end
|
function set.refresh(v) c = v end
|
||||||
end
|
end
|
||||||
|
|
||||||
function OPEN()
|
function OPEN()
|
||||||
@@ -88,21 +88,21 @@ function USE_ITEM(item_info)
|
|||||||
select_item(item_info.item_key)
|
select_item(item_info.item_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_unit_start_price()
|
function get.unit_start_price()
|
||||||
return selected_item and read_settings().start_price or 0
|
return selected_item and read_settings().start_price or 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function set_unit_start_price(amount)
|
function set.unit_start_price(amount)
|
||||||
local settings = read_settings()
|
local settings = read_settings()
|
||||||
settings.start_price = amount
|
settings.start_price = amount
|
||||||
write_settings(settings)
|
write_settings(settings)
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_unit_buyout_price()
|
function get.unit_buyout_price()
|
||||||
return selected_item and read_settings().buyout_price or 0
|
return selected_item and read_settings().buyout_price or 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function set_unit_buyout_price(amount)
|
function set.unit_buyout_price(amount)
|
||||||
local settings = read_settings()
|
local settings = read_settings()
|
||||||
settings.buyout_price = amount
|
settings.buyout_price = amount
|
||||||
write_settings(settings)
|
write_settings(settings)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ function USE_ITEM(item_info)
|
|||||||
execute(nil, false)
|
execute(nil, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
function set_subtab(tab)
|
function set.subtab(tab)
|
||||||
CloseDropDownMenus()
|
CloseDropDownMenus()
|
||||||
search_results_button:UnlockHighlight()
|
search_results_button:UnlockHighlight()
|
||||||
saved_searches_button:UnlockHighlight()
|
saved_searches_button:UnlockHighlight()
|
||||||
@@ -65,7 +65,7 @@ function set_subtab(tab)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.set_filter(filter_string)
|
function M.set.filter(filter_string)
|
||||||
search_box:SetFocus()
|
search_box:SetFocus()
|
||||||
search_box:SetText(filter_string)
|
search_box:SetText(filter_string)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ function update_form()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_filter_builder_query()
|
function get.filter_builder_query()
|
||||||
local filter_string
|
local filter_string
|
||||||
|
|
||||||
local function add(part)
|
local function add(part)
|
||||||
@@ -150,7 +150,7 @@ function get_filter_builder_query()
|
|||||||
return filter_string or ''
|
return filter_string or ''
|
||||||
end
|
end
|
||||||
|
|
||||||
function set_form(filter)
|
function set.form(filter)
|
||||||
clear_form()
|
clear_form()
|
||||||
for _, component in ipairs(filter.components) do
|
for _, component in ipairs(filter.components) do
|
||||||
if component[1] == 'blizzard' then
|
if component[1] == 'blizzard' then
|
||||||
@@ -184,7 +184,7 @@ end
|
|||||||
function import_filter_string()
|
function import_filter_string()
|
||||||
local filter, error = filter_util.parse_filter_string(select(3, strfind(search_box:GetText(), '^([^;]*)')))
|
local filter, error = filter_util.parse_filter_string(select(3, strfind(search_box:GetText(), '^([^;]*)')))
|
||||||
if filter or print(error) then
|
if filter or print(error) then
|
||||||
set_form(filter)
|
set.form(filter)
|
||||||
end
|
end
|
||||||
update_form()
|
update_form()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ end
|
|||||||
|
|
||||||
do
|
do
|
||||||
local id = 0
|
local id = 0
|
||||||
function get_search_scan_id()
|
function get.search_scan_id()
|
||||||
return id
|
return id
|
||||||
end
|
end
|
||||||
function set_search_scan_id(v)
|
function set.search_scan_id(v)
|
||||||
id = v
|
id = v
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -36,7 +36,7 @@ do
|
|||||||
local searches = {}
|
local searches = {}
|
||||||
local search_index = 1
|
local search_index = 1
|
||||||
|
|
||||||
function get_current_search()
|
function get.current_search()
|
||||||
return searches[search_index]
|
return searches[search_index]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ handlers = {
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_auto_buy_validator()
|
function get.auto_buy_validator()
|
||||||
local validators = T
|
local validators = T
|
||||||
for _, search in pairs(favorite_searches) do
|
for _, search in pairs(favorite_searches) do
|
||||||
if search.auto_buy then
|
if search.auto_buy then
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ end
|
|||||||
|
|
||||||
M.huge = 1.8 * 10 ^ 308
|
M.huge = 1.8 * 10 ^ 308
|
||||||
|
|
||||||
function M.get_modified()
|
function M.get.modified()
|
||||||
return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown()
|
return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -418,7 +418,7 @@ function M.item_quality_index(item_quality)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_inventory()
|
function M.get.inventory()
|
||||||
local bag, slot = 0, 0
|
local bag, slot = 0, 0
|
||||||
return function()
|
return function()
|
||||||
if not GetBagName(bag) or slot >= GetContainerNumSlots(bag) then
|
if not GetBagName(bag) or slot >= GetContainerNumSlots(bag) then
|
||||||
|
|||||||
Reference in New Issue
Block a user