big refactoring
This commit is contained in:
+5
-7
@@ -37,15 +37,13 @@ do
|
|||||||
call(on_complete)
|
call(on_complete)
|
||||||
end
|
end
|
||||||
|
|
||||||
private.state{
|
function private.state.get()
|
||||||
get = function()
|
local _, state = next(filter(scan_states, function(state) return state.id == control.thread_id end))
|
||||||
local _, state = next(filter(scan_states, function(state) return state.id == control.thread_id end))
|
return state
|
||||||
return state
|
end
|
||||||
end,
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private.query{get=function() return state.params.queries[state.query_index] end}
|
function private.query.get() return state.params.queries[state.query_index] end
|
||||||
|
|
||||||
function wait_for_callback(...)
|
function wait_for_callback(...)
|
||||||
local send_signal, signal_received = signal()
|
local send_signal, signal_received = signal()
|
||||||
|
|||||||
+1
-1
@@ -44,7 +44,7 @@ end
|
|||||||
|
|
||||||
do
|
do
|
||||||
local id = 0
|
local id = 0
|
||||||
private.id{get=function() id = id + 1; return id end}
|
function private.id.get() id = id + 1; return id end
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.kill_listener(listener_id)
|
function public.kill_listener(listener_id)
|
||||||
|
|||||||
@@ -63,13 +63,13 @@ tabs = {}
|
|||||||
function public.tab(index, name)
|
function public.tab(index, name)
|
||||||
local module_env = getfenv(2)
|
local module_env = getfenv(2)
|
||||||
local tab = {name=name, env=module_env}
|
local tab = {name=name, env=module_env}
|
||||||
module_env.public.ACTIVE{get=function() return tab == active_tab end}
|
function module_env.public.ACTIVE.get() return tab == active_tab end
|
||||||
for _, handler in temp-{'OPEN', 'CLOSE', 'CLICK_LINK', 'USE_ITEM'} do module_env.mutable[handler] = nil end
|
for _, handler in temp-{'OPEN', 'CLOSE', 'CLICK_LINK', 'USE_ITEM'} do module_env.mutable[handler] = nil end
|
||||||
tabs[index] = tab
|
tabs[index] = tab
|
||||||
end
|
end
|
||||||
do
|
do
|
||||||
local active_tab_index
|
local active_tab_index
|
||||||
private.active_tab{get=function() return tabs[active_tab_index] end}
|
function private.active_tab.get() return tabs[active_tab_index] end
|
||||||
function on_tab_click(index)
|
function on_tab_click(index)
|
||||||
call(active_tab_index and active_tab.env.CLOSE)
|
call(active_tab_index and active_tab.env.CLOSE)
|
||||||
active_tab_index = index
|
active_tab_index = index
|
||||||
@@ -88,11 +88,9 @@ end
|
|||||||
|
|
||||||
do
|
do
|
||||||
local locked
|
local locked
|
||||||
public.bid_in_progress{get=function() return locked end}
|
function public.bid_in_progress.get() return locked end
|
||||||
function public.place_bid(type, index, amount, on_success)
|
function public.place_bid(type, index, amount, on_success)
|
||||||
if locked then
|
if locked then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
local money = GetMoney()
|
local money = GetMoney()
|
||||||
PlaceAuctionBid(type, index, amount)
|
PlaceAuctionBid(type, index, amount)
|
||||||
if money >= amount then
|
if money >= amount then
|
||||||
@@ -110,11 +108,9 @@ end
|
|||||||
|
|
||||||
do
|
do
|
||||||
local locked
|
local locked
|
||||||
public.cancel_in_progress{get=function() return locked end}
|
function public.cancel_in_progress.get() return locked end
|
||||||
function public.cancel_auction(index, on_success)
|
function public.cancel_auction(index, on_success)
|
||||||
if locked then
|
if locked then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
locked = true
|
locked = true
|
||||||
CancelAuction(index)
|
CancelAuction(index)
|
||||||
control.event_listener('CHAT_MSG_SYSTEM', function(kill)
|
control.event_listener('CHAT_MSG_SYSTEM', function(kill)
|
||||||
|
|||||||
@@ -60,24 +60,20 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
public.color{
|
public.color.get = color_accessor(function(color)
|
||||||
get = color_accessor(function(color)
|
local r, g, b, a = unpack(color)
|
||||||
local r, g, b, a = unpack(color)
|
return setmetatable({r/255, g/255, b/255, a}, mt)
|
||||||
return setmetatable({r/255, g/255, b/255, a}, mt)
|
end)
|
||||||
end),
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
public.inline_color{
|
public.inline_color.get = color_accessor(function(color)
|
||||||
get = color_accessor(function(color)
|
local r, g, b, a = unpack(color)
|
||||||
local r, g, b, a = unpack(color)
|
return format('|c%02X%02X%02X%02X', a, r, g, b)
|
||||||
return format('|c%02X%02X%02X%02X', a, r, g, b)
|
end)
|
||||||
end),
|
|
||||||
}
|
|
||||||
|
|
||||||
do
|
do
|
||||||
local id = 0
|
local id = 0
|
||||||
public.name{get=function() id = id + 1; return 'aux_frame'..id end}
|
function public.name.get() id = id + 1; return 'aux_frame'..id end
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ do
|
|||||||
-- log(getn(table_pool))
|
-- log(getn(table_pool))
|
||||||
end
|
end
|
||||||
public.temp = setmetatable({}, {__sub = function(_, t) auto_recycle[t] = true return t end})
|
public.temp = setmetatable({}, {__sub = function(_, t) auto_recycle[t] = true return t end})
|
||||||
public.t{get=function() return tremove(table_pool) or {} end}
|
function public.t.get() return tremove(table_pool) or {} end
|
||||||
CreateFrame('Frame'):SetScript('OnUpdate', function()
|
CreateFrame('Frame'):SetScript('OnUpdate', function()
|
||||||
for t in auto_recycle do recycle(t) end
|
for t in auto_recycle do recycle(t) end
|
||||||
recycle(auto_recycle)
|
recycle(auto_recycle)
|
||||||
@@ -43,8 +43,8 @@ end
|
|||||||
ADDON_LOADED = {}
|
ADDON_LOADED = {}
|
||||||
do
|
do
|
||||||
local variables_loaded_hooks, player_login_hooks = t, t
|
local variables_loaded_hooks, player_login_hooks = t, t
|
||||||
public.LOAD{set=function(f) tinsert(variables_loaded_hooks, f) end}
|
function public.LOAD.set(f) tinsert(variables_loaded_hooks, f) end
|
||||||
public.LOAD2{set=function(f) tinsert(player_login_hooks, f) end}
|
function public.LOAD2.set(f) tinsert(player_login_hooks, f) end
|
||||||
event_frame:SetScript('OnEvent', function()
|
event_frame:SetScript('OnEvent', function()
|
||||||
if event == 'ADDON_LOADED' then
|
if event == 'ADDON_LOADED' then
|
||||||
if ADDON_LOADED[arg1] then ADDON_LOADED[arg1]() end
|
if ADDON_LOADED[arg1] then ADDON_LOADED[arg1]() end
|
||||||
|
|||||||
+3
-3
@@ -5,7 +5,7 @@ local MODIFIER_MASK, PROPERTY_MASK = {private=MUTABLE+PROPERTY, public=MUTABLE+P
|
|||||||
local error, declaration_error, immutable_error, collision_error, void_error, import, define_property, lock_mt, env_mt, interface_mt, declarator_mt, property_mt
|
local error, declaration_error, immutable_error, collision_error, void_error, import, define_property, lock_mt, env_mt, interface_mt, declarator_mt, property_mt
|
||||||
lock_mt = {}
|
lock_mt = {}
|
||||||
local _state, _modules = {}, setmetatable({}, lock_mt)
|
local _state, _modules = {}, setmetatable({}, lock_mt)
|
||||||
function error(message, level, ...) _g.error(format(message, unpack(arg))..'\n'..debugstack(3, 5, 0), level + 1) end
|
function error(message, level, ...) _g.error(format(message, unpack(arg))..'\n'..debugstack(3, 5, 0), (level or 1) + 1) end
|
||||||
function declaration_error(level) error('Malformed declaration.', level + 1) end
|
function declaration_error(level) error('Malformed declaration.', level + 1) end
|
||||||
function immutable_error(key, level) error('Field "%s" is immutable.', level + 1, key) end
|
function immutable_error(key, level) error('Field "%s" is immutable.', level + 1, key) end
|
||||||
function collision_error(key, level) error('Field "%s" already exists.', level + 1, key) end
|
function collision_error(key, level) error('Field "%s" already exists.', level + 1, key) end
|
||||||
@@ -86,9 +86,9 @@ function _g.aux_module(name)
|
|||||||
local state, imports, env, interface, declarator, property
|
local state, imports, env, interface, declarator, property
|
||||||
imports, env, interface, declarator, property = {}, setmetatable({}, env_mt), setmetatable({}, interface_mt), setmetatable({}, declarator_mt), setmetatable({}, property_mt)
|
imports, env, interface, declarator, property = {}, setmetatable({}, env_mt), setmetatable({}, interface_mt), setmetatable({}, declarator_mt), setmetatable({}, property_mt)
|
||||||
state = {
|
state = {
|
||||||
name = name, env = env, interface = interface, imports = {}, declarator_state = PRIVATE,
|
name=name, env=env, interface=interface, imports={}, declarator_state=PRIVATE,
|
||||||
metadata = setmetatable({_g=PRIVATE, _m=PRIVATE, _i=PRIVATE, import=PRIVATE, private=PROPERTY, public=PROPERTY, getter=PROPERTY, setter=PROPERTY, mutable=PROPERTY}, lock_mt),
|
metadata = setmetatable({_g=PRIVATE, _m=PRIVATE, _i=PRIVATE, import=PRIVATE, private=PROPERTY, public=PROPERTY, getter=PROPERTY, setter=PROPERTY, mutable=PROPERTY}, lock_mt),
|
||||||
data = {_g=_g, _m=env, _i=interface, import=function(t) import(imports, t) end},
|
data = {_g=_g, _m=env, _i=interface, property=property, import=function(t) import(imports, t) end},
|
||||||
getters = {private=function() state.modifiers = PRIVATE return declarator end, public=function() state.modifiers = PUBLIC return declarator end, mutable=function() state.modifiers = MUTABLE return declarator end},
|
getters = {private=function() state.modifiers = PRIVATE return declarator end, public=function() state.modifiers = PUBLIC return declarator end, mutable=function() state.modifiers = MUTABLE return declarator end},
|
||||||
setters = {},
|
setters = {},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ do
|
|||||||
local searches = {}
|
local searches = {}
|
||||||
local search_index = 1
|
local search_index = 1
|
||||||
|
|
||||||
private.current_search{get=function() return searches[search_index] end}
|
function private.current_search.get() return searches[search_index] end
|
||||||
|
|
||||||
function update_search(index)
|
function update_search(index)
|
||||||
searches[search_index].status_bar:Hide()
|
searches[search_index].status_bar:Hide()
|
||||||
|
|||||||
+17
-21
@@ -25,13 +25,11 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i=1,9 do public[join{replicate(i, 'x')}] = setter(i) end
|
for i=1,9 do public[join{replicate(i, 'x')}] = setter(i) end
|
||||||
public.__{
|
function public.__.get()
|
||||||
get = function()
|
assert(charges > 0)
|
||||||
assert(charges > 0)
|
charges = charges - 1
|
||||||
charges = charges - 1
|
return value
|
||||||
return value
|
end
|
||||||
end,
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
@@ -89,7 +87,7 @@ end
|
|||||||
|
|
||||||
public.huge = 1.8*10^308
|
public.huge = 1.8*10^308
|
||||||
|
|
||||||
public.modified{get=function() return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() end}
|
function public.modified.get() return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() end
|
||||||
|
|
||||||
--do TODO
|
--do TODO
|
||||||
-- local _state = setmetatable({}, {__mode='kv'})
|
-- local _state = setmetatable({}, {__mode='kv'})
|
||||||
@@ -247,20 +245,18 @@ end
|
|||||||
|
|
||||||
function public.round(x) return floor(x + 0.5) end
|
function public.round(x) return floor(x + 0.5) end
|
||||||
|
|
||||||
public.inventory{
|
function public.inventory.get()
|
||||||
get = function()
|
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
|
repeat bag = bag + 1 until GetBagName(bag) or bag > 4
|
||||||
repeat bag = bag + 1 until GetBagName(bag) or bag > 4
|
slot = 1
|
||||||
slot = 1
|
else
|
||||||
else
|
slot = slot + 1
|
||||||
slot = slot + 1
|
|
||||||
end
|
|
||||||
if bag <= 4 then return {bag, slot}, bag_type(bag) end
|
|
||||||
end
|
end
|
||||||
end,
|
if bag <= 4 then return {bag, slot}, bag_type(bag) end
|
||||||
}
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function public.bag_type(bag)
|
function public.bag_type(bag)
|
||||||
if bag == 0 then
|
if bag == 0 then
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ do
|
|||||||
realm = GetCVar 'realmName'
|
realm = GetCVar 'realmName'
|
||||||
end
|
end
|
||||||
|
|
||||||
private.dataset_key{get=function() return realm..'|'..faction end}
|
function private.dataset_key.get() return realm..'|'..faction end
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.load_dataset()
|
function public.load_dataset()
|
||||||
|
|||||||
Reference in New Issue
Block a user