big refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-22 22:30:16 +02:00
parent 3a40cddda1
commit c2cef5b142
8 changed files with 52 additions and 102 deletions
+5 -54
View File
@@ -65,12 +65,11 @@ do
end) end)
do do
local mt = {__call = function(self, key) return self[key] end} public.set = modifier(function(t)
public.set = modifier(function(table) local self = _m.t
local self = t for _, v in t do self[v] = true end
for _, v in table do self[v] = true end recycle(t)
recycle(table) return self
return setmetatable(self, mt)
end) end)
end end
@@ -113,54 +112,6 @@ do
end) end)
end end
function LOAD()
import :_ 'util' 'gui'
do
local frame = CreateFrame('Frame', gui.name, UIParent)
tinsert(UISpecialFrames, 'aux_frame1')
gui.set_window_style(frame)
gui.set_size(frame, 768, 447)
frame:SetPoint('LEFT', 100, 0)
frame:SetToplevel(true)
frame:SetMovable(true)
frame:EnableMouse(true)
frame:SetClampedToScreen(true)
frame:RegisterForDrag 'LeftButton'
frame:SetScript('OnDragStart', function() this:StartMoving() end)
frame:SetScript('OnDragStop', function() this:StopMovingOrSizing() end)
frame:SetScript('OnShow', function() PlaySound 'AuctionWindowOpen' end)
frame:SetScript('OnHide', function() PlaySound 'AuctionWindowClose' CloseAuctionHouse() end)
frame.content = CreateFrame('Frame', nil, frame)
frame.content:SetPoint('TOPLEFT', 4, -80)
frame.content:SetPoint('BOTTOMRIGHT', -4, 35)
frame:Hide()
public.frame = frame
end
do
local tabs = gui.tabs(frame, 'DOWN')
tabs._on_select = on_tab_click
for _, tab in _m.tabs do tabs:create_tab(tab.name) end
function public.set_tab(id) tabs:select(id) end
end
do
local btn = gui.button(frame, 16)
btn:SetPoint('BOTTOMRIGHT', -6, 6)
gui.set_size(btn, 65, 24)
btn:SetText 'Close'
btn:SetScript('OnClick', L(frame.Hide, frame))
public.close_button = btn
end
do
local btn = gui.button(frame, 16)
btn:SetPoint('RIGHT', close_button, 'LEFT' , -5, 0)
gui.set_size(btn, 65, 24)
btn:SetText 'Default UI'
btn:SetScript('OnClick',function()
if AuctionFrame:IsVisible() then HideUIPanel(AuctionFrame) else ShowUIPanel(AuctionFrame) end
end)
end
end
function public.log(...) function public.log(...)
local msg = '[aux]' local msg = '[aux]'
for i=1,arg.n do msg = msg..' '..tostring(arg[i]) end for i=1,arg.n do msg = msg..' '..tostring(arg[i]) end
+2 -2
View File
@@ -1,8 +1,8 @@
module 'aux' module 'aux'
event_frame = CreateFrame 'Frame' event_frame = CreateFrame 'Frame'
listeners = {} listeners = t
threads = {} threads = t
public.thread_id = nil public.thread_id = nil
function LOAD() function LOAD()
+8 -10
View File
@@ -1,8 +1,6 @@
module 'disenchant' module 'disenchant'
UNCOMMON = 2 UNCOMMON, RARE, EPIC = 2, 3, 4
RARE = 3
EPIC = 4
do do
local data = { local data = {
@@ -41,7 +39,7 @@ do
end end
function LOAD() function LOAD()
armor = set-from ARMOR = set-from
'INVTYPE_HEAD' 'INVTYPE_HEAD'
'INVTYPE_NECK' 'INVTYPE_NECK'
'INVTYPE_SHOULDER' 'INVTYPE_SHOULDER'
@@ -57,7 +55,7 @@ function LOAD()
'INVTYPE_TRINKET' 'INVTYPE_TRINKET'
'INVTYPE_CLOAK' 'INVTYPE_CLOAK'
'INVTYPE_HOLDABLE' 'INVTYPE_HOLDABLE'
weapon = set-from WEAPON = set-from
'INVTYPE_2HWEAPON' 'INVTYPE_2HWEAPON'
'INVTYPE_WEAPONMAINHAND' 'INVTYPE_WEAPONMAINHAND'
'INVTYPE_WEAPON' 'INVTYPE_WEAPON'
@@ -81,14 +79,14 @@ function public.value(slot, quality, level)
end end
function public.distribution(slot, quality, level) function public.distribution(slot, quality, level)
if not (armor(slot) or weapon(slot)) or level == 0 then if not (ARMOR[slot] or WEAPON[slot]) or level == 0 then
return {} return tt
end end
local function p(probability_armor, probability_weapon) local function p(probability_armor, probability_weapon)
if armor(slot) then if ARMOR[slot] then
return probability_armor return probability_armor
elseif weapon(slot) then elseif WEAPON[slot] then
return probability_weapon return probability_weapon
end end
end end
@@ -193,5 +191,5 @@ function public.distribution(slot, quality, level)
return {{item_id=20725, min_quantity=1, max_quantity=2, probability=1}} return {{item_id=20725, min_quantity=1, max_quantity=2, probability=1}}
end end
end end
return {} return tt
end end
+3 -3
View File
@@ -52,7 +52,7 @@ function SlashCmdList.AUX(command)
local realm = GetCVar 'realmName' local realm = GetCVar 'realmName'
_g.aux_characters[realm] = _g.aux_characters[realm] or {} _g.aux_characters[realm] = _g.aux_characters[realm] or {}
for i=3,getn(arguments) do for i=3,getn(arguments) do
local name = string.gsub(strlower(arguments[i]), '^%l', strupper) local name = gsub(strlower(arguments[i]), '^%l', strupper)
if not _g.aux_characters[realm][name] then if not _g.aux_characters[realm][name] then
_g.aux_characters[realm][name] = true _g.aux_characters[realm][name] = true
log('Character "'..name..'" added.') log('Character "'..name..'" added.')
@@ -64,7 +64,7 @@ function SlashCmdList.AUX(command)
return return
end end
for i=3,getn(arguments) do for i=3,getn(arguments) do
local name = string.gsub(strlower(arguments[i]), '^%l', strupper) local name = gsub(strlower(arguments[i]), '^%l', strupper)
if _g.aux_characters[realm][name] then if _g.aux_characters[realm][name] then
_g.aux_characters[realm][name] = nil _g.aux_characters[realm][name] = nil
log('Character "'..name..'" removed.') log('Character "'..name..'" removed.')
@@ -77,7 +77,7 @@ function SlashCmdList.AUX(command)
tinsert(chars, name) tinsert(chars, name)
end end
if getn(chars) > 0 then if getn(chars) > 0 then
log('Your characters: "'..table.concat(chars, ', ')..'".') log('Your characters: "'..join(chars, ', ')..'".')
else else
log 'You don\'t have any additional characters. To add your characters type "/aux chars add NAME1 NAME2 NAME3...".' log 'You don\'t have any additional characters. To add your characters type "/aux chars add NAME1 NAME2 NAME3...".'
end end
+10 -9
View File
@@ -1,21 +1,23 @@
local type, setmetatable, setfenv, unpack, mask, _g = type, setmetatable, setfenv, unpack, bit.band, getfenv(0) local type, setmetatable, setfenv, unpack, mask, _g = type, setmetatable, setfenv, unpack, bit.band, getfenv(0)
local PRIVATE, PUBLIC, MUTABLE, PROPERTY, ACCESSOR, MUTATOR = 0, 1, 2, 4, 8, 16 local PRIVATE, PUBLIC, MUTABLE, PROPERTY, ACCESSOR, MUTATOR = 0, 1, 2, 4, 8, 16
local error, modifier_error, property_error, immutable_error, collision_error, set_property, env_mt, interface_mt, declarator_mt, importer_mt local error, import_error, modifier_error, property_error, immutable_error, collision_error, set_property, env_mt, interface_mt, declarator_mt, importer_mt
local _state, _modules = {}, {} local _state, _modules = {}, {}
function error(message, ...) return function() _g.error(format(message, unpack(arg))..'\n'..debugstack(3, 10, 0), 0) end end function error(message, ...) return function() _g.error(format(message, unpack(arg))..'\n'..debugstack(3, 10, 0), 0) end end
modifier_error = error 'Invalid modifiers.' import_error, modifier_error, property_error = error 'Invalid modifiers.', error 'Invalid modifiers.', error 'Accessor/Mutator must be function.'
property_error = error 'Accessor/Mutator must be function.' immutable_error, collision_error = function(key) return error('Field "%s" is immutable.', key) end, function(key) return error('Field "%s" already exists.', key) end
function immutable_error(key) return error('Field "%s" is immutable.', key) end
function collision_error(key) return error('Field "%s" already exists.', key) end
importer_mt = {__metatable=false} importer_mt = {__metatable=false}
function importer_mt.__index(self, key) _state[self][self] = key; return self end function importer_mt.__index(self, key)
if type(key) ~= 'string' then import_error() end
_state[self][self] = key; return self
end
function importer_mt.__call(self, arg1, arg2) function importer_mt.__call(self, arg1, arg2)
local name, state, module, alias local name, state, module, alias
name = arg2 or arg1 name = arg2 or arg1
if type(name) ~= 'string' then import_error() end
state, module = _state[self], _modules[name] state, module = _state[self], _modules[name]
alias, state[self] = state[self] or name, nil alias, state[self] = state[self] or name, nil
if module then if module then
if alias == '_' then if alias == '' then
for key, modifiers in module.metadata do for key, modifiers in module.metadata do
if not state.metadata[key] and mask(PUBLIC, modifiers) ~= 0 then if not state.metadata[key] and mask(PUBLIC, modifiers) ~= 0 then
state.metadata[key], state.data[key], state.accessors[key], state.mutators[key] = modifiers, module.data[key], module.accessors[key], module.mutators[key] state.metadata[key], state.data[key], state.accessors[key], state.mutators[key] = modifiers, module.data[key], module.accessors[key], module.mutators[key]
@@ -90,7 +92,6 @@ do
end end
end end
end end
function INIT() end
function module(name) function module(name)
if not _modules[name] then if not _modules[name] then
local state, accessors, mutators, env, interface, declarator, importer local state, accessors, mutators, env, interface, declarator, importer
@@ -106,7 +107,7 @@ function module(name)
data = {_g=_g, _m=env, _i=interface, import=importer}, accessors=accessors, mutators=mutators, data = {_g=_g, _m=env, _i=interface, import=importer}, accessors=accessors, mutators=mutators,
} }
_modules[name], _state[env], _state[interface], _state[declarator], _state[importer] = state, state, state, state, state _modules[name], _state[env], _state[interface], _state[declarator], _state[importer] = state, state, state, state, state
setfenv(INIT, env); INIT() importer [''] (ADDON)
end end
setfenv(2, _modules[name].env) setfenv(2, _modules[name].env)
end end
+1 -1
View File
@@ -315,7 +315,7 @@ function create_frames()
if filters then if filters then
tinsert(_g.aux_favorite_searches, 1, { tinsert(_g.aux_favorite_searches, 1, {
filter_string = search_box:GetText(), filter_string = search_box:GetText(),
prettified = table.concat(map(filters, function(filter) return filter.prettified end), ';'), prettified = join(map(filters, function(filter) return filter.prettified end), ';'),
}) })
end end
update_search_listings() update_search_listings()
+22 -22
View File
@@ -1,13 +1,6 @@
module 'util' module 'util'
function public.copy(t) public.join = _g.join
local copy = {}
for k, v in t do copy[k] = v end
table.setn(t, getn(t))
return copy
end
public.join = _g.table.concat
function public.replicate(count, value) function public.replicate(count, value)
if count > 0 then return value, replicate(count - 1, value) end if count > 0 then return value, replicate(count - 1, value) end
@@ -112,9 +105,16 @@ do
end end
function public.expand(array, ...) function public.expand(array, ...)
local table = {} local t = t
for i=1,arg.n do table[arg[i]] = array[i] end for i=1,arg.n do t[arg[i]] = array[i] end
return table return t
end
function public.copy(t)
local copy = _m.t
for k, v in t do copy[k] = v end
table.setn(t, getn(t))
return copy
end end
function public.select(i, ...) function public.select(i, ...)
@@ -135,13 +135,13 @@ function public.key(value, t)
end end
function public.keys(t) function public.keys(t)
local ks = {} local ks = _m.t
for k in t do tinsert(ks, k) end for k in t do tinsert(ks, k) end
return ks return ks
end end
function public.values(t) function public.values(t)
local vs = {} local vs = _m.t
for _, v in t do tinsert(vs, v) end for _, v in t do tinsert(vs, v) end
return vs return vs
end end
@@ -185,20 +185,20 @@ function public.all(xs, p)
return true return true
end end
function public.filter(xs, p) function public.filter(t0, p)
local ys = {} local t = t
for k, x in xs do for k, x in t0 do
if p(x, k) then if p(x, k) then
ys[k] = x t[k] = x
end end
end end
return ys return t
end end
function public.map(xs, f) function public.map(t0, f)
local ys = {} local t = t
for k, x in xs do ys[k] = f(x, k) end for k, x in t0 do t[k] = f(x, k) end
return ys return t
end end
function public.trim(str) function public.trim(str)
+1 -1
View File
@@ -166,7 +166,7 @@ function public.bid_update(auction_record)
auction_record.unit_blizzard_bid = auction_record.blizzard_bid / auction_record.aux_quantity auction_record.unit_blizzard_bid = auction_record.blizzard_bid / auction_record.aux_quantity
auction_record.unit_bid_price = auction_record.bid_price / auction_record.aux_quantity auction_record.unit_bid_price = auction_record.bid_price / auction_record.aux_quantity
auction_record.high_bidder = 1 auction_record.high_bidder = 1
auction_record.search_signature = table.concat({auction_record.item_id, auction_record.suffix_id, auction_record.enchant_id, auction_record.start_price, auction_record.buyout_price, auction_record.bid_price, auction_record.aux_quantity, auction_record.duration, 1, _g.aux_ignore_owner and (is_player(auction_record.owner) and 0 or 1) or (auction_record.owner or '?')}, ':') auction_record.search_signature = join({auction_record.item_id, auction_record.suffix_id, auction_record.enchant_id, auction_record.start_price, auction_record.buyout_price, auction_record.bid_price, auction_record.aux_quantity, auction_record.duration, 1, _g.aux_ignore_owner and (is_player(auction_record.owner) and 0 or 1) or (auction_record.owner or '?')}, ':')
end end
function public.set_tooltip(itemstring, owner, anchor) function public.set_tooltip(itemstring, owner, anchor)