big refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-20 13:04:44 +02:00
parent 9c2598646d
commit 180905f089
5 changed files with 52 additions and 68 deletions
+17 -32
View File
@@ -1,4 +1,4 @@
setglobal('aux', aux_module('core'))
setglobal('aux', aux_module 'core')
import 'util'
public.version = '5.0.0'
@@ -15,52 +15,37 @@ do
locked[t] = nil
tinsert(table_pool, t)
end
local function temp()
function public.temp()
local t = tremove(table_pool)
t = t and wipe(t) or {}
locked[t] = true
end
public.temp = temp
function public.static()
local t = tremove(table_pool)
t = t and wipe(t) or {}
locked[t] = true
end
function public.array(...) locked[arg] = true end
function public.set(...)
local set = temp()
for i=1,arg.n do self[arg[i]] = true end
return set
end
end
local temp = temp
--do
-- local table_pool = {}
-- onupdate clear tables TODO
-- local setn = g.table.setn
-- public.wipe = wipe
--end
do
local aux_module, getfenv, setfenv, gfind, tinsert = g.aux_module, g.getfenv, g.setfenv, g.string.gfind, g.tinsert
local interface, env = (function() return aux_module('interfaces'), getfenv() end)()
local root = (function() aux_module 'modules' return getfenv() end)()
function public.module(path)
local parts = gfind(path, '[%a_][%w_]*')
local name = parts() or ''
local env = root
for part in parts do
interface[(function() return aux_module(name), getfenv() end)()
env.public[part], env = (function() return aux_module(name), getfenv() end)()
env.import('modules', 'core', 'util')
name = name..'.'..part
end
local env
if path == 'core' then
env = getfenv()
elseif module_envs[path] then
env = module_envs[path]
else
local prefix
for name in gfind(path, '[%a_][%w_]*') do
local qualified_name = prefix and prefix..'.'..name or name
env = module_envs[qualified_name]
if not env then
(prefix and module_envs[prefix].public or public)[name], env = (function() return aux_module(qualified_name), getfenv() end)()
env.import('core', 'util')
env.mutable.LOAD = nil
module_envs[qualified_name] = env
end
prefix = qualified_name
end
end
setfenv(2, env)
end
end
+6 -4
View File
@@ -1,4 +1,4 @@
local tinsert, setfenv, rawget, rawset, setmetatable, mask, add, g = tinsert, setfenv, rawget, rawset, setmetatable, bit.band, bit.bor, getfenv(0)
local tinsert, setfenv, rawget, setmetatable, mask, add, g = tinsert, setfenv, rawget, setmetatable, bit.band, bit.bor, getfenv(0)
local DECLARED, ACCESSOR, MUTABLE, PUBLIC = 1, 2, 4, 8
local ACCESSOR_KEY, MUTABLE_KEY, PUBLIC_KEY = 'accessor', 'mutable', 'public'
local PROPERTY = {[ACCESSOR_KEY]=ACCESSOR, [MUTABLE_KEY]=MUTABLE, [PUBLIC_KEY]=PUBLIC}
@@ -24,9 +24,11 @@ local env_mt = {
end
end,
__newindex = function(self, key, value)
local properties = _metadata[self][key]
if mask(DECLARED+MUTABLE, _metadata[self][key]) == DECLARED then error('Field "%s" is immutable.', key) end
_metadata[self][key] = add(DECLARED, properties)
if not rawget(_metadata[self], key) then
_metadata[self][key] = DECLARED
elseif mask(MUTABLE, _metadata[self][key]) == 0 then
error('Field "%s" is immutable.', key)
end
_data[self][key] = value
end,
}
+26 -26
View File
@@ -55,7 +55,7 @@ public.search_config = {
title = 'Item',
width = 0.35,
init = item_column_init,
set = function(cell, record, _, _, _, indented)
fill = function(cell, record, _, _, _, indented)
cell.icon:SetTexture(record.texture)
if indented then
cell.spacer:SetWidth(10)
@@ -76,7 +76,7 @@ public.search_config = {
title = 'Lvl',
width = 0.035,
align = 'CENTER',
set = function(cell, record)
fill = function(cell, record)
local display_level = max(record.level, 1)
display_level = UnitLevel('player') < record.level and aux.gui.color.red(display_level) or display_level
cell:SetText(display_level)
@@ -89,7 +89,7 @@ public.search_config = {
title = 'Auctions',
width = 0.06,
align = 'CENTER',
set = function(cell, record, count, own, expandable)
fill = function(cell, record, count, own, expandable)
local numAuctionsText = expandable and aux.gui.color.link(count) or count
if own > 0 then
numAuctionsText = numAuctionsText..(' '..aux.gui.color.yellow('('..own..')'))
@@ -113,7 +113,7 @@ public.search_config = {
title = 'Stack Size',
width = 0.055,
align = 'CENTER',
set = function(cell, record)
fill = function(cell, record)
cell:SetText(record.aux_quantity)
end,
cmp = function(record_a, record_b, desc)
@@ -124,7 +124,7 @@ public.search_config = {
title = 'Time Left',
width = 0.04,
align = 'CENTER',
set = function(cell, record)
fill = function(cell, record)
cell:SetText(TIME_LEFT_STRINGS[record.duration or 0] or '---')
end,
cmp = function(record_a, record_b, desc)
@@ -135,7 +135,7 @@ public.search_config = {
title = 'Seller',
width = 0.13,
align = 'CENTER',
set = function(cell, record)
fill = function(cell, record)
cell:SetText(aux.is_player(record.owner) and (aux.gui.color.yellow(record.owner)) or (record.owner or '---'))
end,
cmp = function(record_a, record_b, desc)
@@ -155,7 +155,7 @@ public.search_config = {
width = 0.125,
align = 'RIGHT',
isPrice = true,
set = function(cell, record)
fill = function(cell, record)
local color
if record.high_bidder then
color = AUCTION_PCT_COLORS[2].color
@@ -191,7 +191,7 @@ public.search_config = {
width = 0.125,
align = 'RIGHT',
isPrice = true,
set = function(cell, record)
fill = function(cell, record)
local price = g.aux_price_per_unit and ceil(record.unit_buyout_price) or record.buyout_price
cell:SetText(price > 0 and aux.money.to_string(price, true, false) or '---')
end,
@@ -208,7 +208,7 @@ public.search_config = {
title = '% Hist. Value',
width = 0.08,
align = 'CENTER',
set = function(cell, record)
fill = function(cell, record)
local pct, bidPct = record_percentage(record)
cell:SetText((pct or bidPct) and percentage_historical(pct or bidPct, not pct) or '---')
end,
@@ -225,7 +225,7 @@ public.auctions_config = {
title = 'Item',
width = 0.35,
init = item_column_init,
set = function(cell, record, _, _, _, indented)
fill = function(cell, record, _, _, _, indented)
cell.icon:SetTexture(record.texture)
if indented then
cell.spacer:SetWidth(10)
@@ -246,7 +246,7 @@ public.auctions_config = {
title = 'Lvl',
width = 0.035,
align = 'CENTER',
set = function(cell, record)
fill = function(cell, record)
local display_level = max(record.level, 1)
display_level = UnitLevel('player') < record.level and aux.gui.color.red(display_level) or display_level
cell:SetText(display_level)
@@ -259,7 +259,7 @@ public.auctions_config = {
title = 'Auctions',
width = 0.06,
align = 'CENTER',
set = function(cell, record, count, own, expandable)
fill = function(cell, record, count, own, expandable)
local numAuctionsText = expandable and aux.gui.inline_color.link..count..FONT_COLOR_CODE_CLOSE or count
cell:SetText(numAuctionsText)
end,
@@ -280,7 +280,7 @@ public.auctions_config = {
title = 'Stack Size',
width = 0.055,
align = 'CENTER',
set = function(cell, record)
fill = function(cell, record)
cell:SetText(record.aux_quantity)
end,
cmp = function(record_a, record_b, desc)
@@ -291,7 +291,7 @@ public.auctions_config = {
title = 'Time Left',
width = 0.04,
align = 'CENTER',
set = function(cell, record)
fill = function(cell, record)
cell:SetText(TIME_LEFT_STRINGS[record.duration or 0] or '---')
end,
cmp = function(record_a, record_b, desc)
@@ -303,7 +303,7 @@ public.auctions_config = {
width = 0.125,
align = 'RIGHT',
isPrice = true,
set = function(cell, record)
fill = function(cell, record)
local price
if record.high_bidder then
price = g.aux_price_per_unit and ceil(record.high_bid / record.aux_quantity) or record.high_bid
@@ -333,7 +333,7 @@ public.auctions_config = {
width = 0.125,
align = 'RIGHT',
isPrice = true,
set = function(cell, record)
fill = function(cell, record)
local price = g.aux_price_per_unit and ceil(record.unit_buyout_price) or record.buyout_price
cell:SetText(price > 0 and aux.money.to_string(price, true, false) or '---')
end,
@@ -350,7 +350,7 @@ public.auctions_config = {
title = 'High Bidder',
width = 0.21,
align = 'CENTER',
set = function(cell, record)
fill = function(cell, record)
cell:SetText(record.high_bidder or aux.gui.color.red 'No Bids')
end,
cmp = function(record_a, record_b, desc)
@@ -372,7 +372,7 @@ public.bids_config = {
title = 'Item',
width = 0.35,
init = item_column_init,
set = function(cell, record, _, _, _, indented)
fill = function(cell, record, _, _, _, indented)
cell.icon:SetTexture(record.texture)
if indented then
cell.spacer:SetWidth(10)
@@ -393,7 +393,7 @@ public.bids_config = {
title = 'Auctions',
width = 0.06,
align = 'CENTER',
set = function(cell, record, count, own, expandable)
fill = function(cell, record, count, own, expandable)
local numAuctionsText = expandable and aux.gui.inline_color.link..count..FONT_COLOR_CODE_CLOSE or count
cell:SetText(numAuctionsText)
end,
@@ -414,7 +414,7 @@ public.bids_config = {
title = 'Stack Size',
width = 0.055,
align = 'CENTER',
set = function(cell, record)
fill = function(cell, record)
cell:SetText(record.aux_quantity)
end,
cmp = function(record_a, record_b, desc)
@@ -425,7 +425,7 @@ public.bids_config = {
title = 'Time Left',
width = 0.04,
align = 'CENTER',
set = function(cell, record)
fill = function(cell, record)
cell:SetText(TIME_LEFT_STRINGS[record.duration or 0] or '---')
end,
cmp = function(record_a, record_b, desc)
@@ -436,7 +436,7 @@ public.bids_config = {
title = 'Seller',
width = 0.13,
align = 'CENTER',
set = function(cell, record)
fill = function(cell, record)
cell:SetText(aux.is_player(record.owner) and (aux.gui.color.yellow(record.owner)) or (record.owner or '---'))
end,
cmp = function(record_a, record_b, desc)
@@ -456,7 +456,7 @@ public.bids_config = {
width = 0.125,
align = 'RIGHT',
isPrice = true,
set = function(cell, record)
fill = function(cell, record)
local price
if record.high_bidder then
price = g.aux_price_per_unit and ceil(record.high_bid / record.aux_quantity) or record.high_bid
@@ -486,7 +486,7 @@ public.bids_config = {
width = 0.125,
align = 'RIGHT',
isPrice = true,
set = function(cell, record)
fill = function(cell, record)
local price = g.aux_price_per_unit and ceil(record.unit_buyout_price) or record.buyout_price
cell:SetText(price > 0 and aux.money.to_string(price, true, false) or '---')
end,
@@ -503,7 +503,7 @@ public.bids_config = {
title = 'Status',
width = 0.115,
align = 'CENTER',
set = function(cell, record)
fill = function(cell, record)
local status
if record.high_bidder then
status = aux.gui.color.yellow 'High Bidder'
@@ -814,7 +814,7 @@ local methods = {
row.data = {record=record, expandable=expandable, indented=indented, numAuctions=numAuctions, expandKey=expandKey}
for i, column_config in self.config do
column_config.set(row.cells[i], record, displayNumAuctions, numPlayerAuctions, expandable, indented)
column_config.fill(row.cells[i], record, displayNumAuctions, numPlayerAuctions, expandable, indented)
end
end,
+2 -5
View File
@@ -11,9 +11,7 @@ local DEFAULT_COL_INFO = {{width=1}}
local function GetTableIndex(tbl, value)
for i, v in tbl do
if value == v then
return i
end
if value == v then return i end
end
end
@@ -106,7 +104,6 @@ local methods = {
st.updateSort = nil
end
-- set row data
for i=1, st.sizes.numRows do
st.rows[i].data = nil
if i > getn(st.rowData) then
@@ -337,7 +334,7 @@ local methods = {
local col = CreateFrame('Button', nil, row)
local text = col:CreateFontString()
text:SetFont(aux.gui.config.font, ST_ROW_TEXT_SIZE)
text:SetJustifyV('CENTER')
text:SetJustifyV 'CENTER'
text:SetPoint('TOPLEFT', 1, -1)
text:SetPoint('BOTTOMRIGHT', -1, 1)
col.text = text
+1 -1
View File
@@ -205,7 +205,7 @@ end
do
local mt = {__call = function(self, key) return self[key] end}
function public.hashset(...)
function public.hashset(...) -- TODO rename/remove?
local self = {}
for i=1,arg.n do self[arg[i]] = true end
return setmetatable(self, mt)