big refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-22 08:00:33 +02:00
parent 853ab22e15
commit 71adb9c916
34 changed files with 83 additions and 81 deletions
+12 -12
View File
@@ -1,10 +1,10 @@
aux.module 'cache'
module 'cache'
MIN_ITEM_ID = 1
MAX_ITEM_ID = 30000
items_schema = {'record', '#', {name='string'}, {quality='number'}, {level='number'}, {class='string'}, {subclass='string'}, {slot='string'}, {max_stack='number'}, {texture='string'}}
merchant_buy_schema = {'record', '#', {unit_price='number'}, {limited='boolean'} }
merchant_buy_schema = {'record', '#', {unit_price='number'}, {limited='boolean'}}
_g.aux_items = {}
_g.aux_item_ids = {}
@@ -24,8 +24,8 @@ function LOAD()
CreateFrame('Frame', nil, MerchantFrame):SetScript('OnUpdate', merchant_on_update)
control.event_listener('NEW_AUCTION_UPDATE', function()
for _, info in {info.auction_sell_item()} do
for _, item_id in {cache.item_id(info.name)} do
for info in present(info.auction_sell_item()) do
for item_id in present(cache.item_id(info.name)) do
_g.aux_merchant_sell[cache.item_id(info.name)] = info.vendor_price / (info.max_item_charges(item_id) or info.count)
end
end
@@ -128,12 +128,12 @@ function merchant_buy_scan()
unit_price = min(buy_info.unit_price, new_unit_price)
end
_g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, {
g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, {
unit_price = unit_price,
limited = buy_info.limited and new_limited,
})
else
_g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, {
g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, {
unit_price = new_unit_price,
limited = new_limited,
})
@@ -150,7 +150,7 @@ function merchant_sell_scan()
for slot in inventory do
local item_info = info.container_item(unpack(slot))
if item_info then
_g.aux_merchant_sell[item_info.item_id] = item_info.tooltip_money / item_info.aux_quantity
g.aux_merchant_sell[item_info.item_id] = item_info.tooltip_money / item_info.aux_quantity
end
end
end
@@ -162,9 +162,9 @@ function scan_wdb(item_id)
while processed <= 100 and item_id <= MAX_ITEM_ID do
local itemstring = 'item:'..item_id
local name, _, quality, level, class, subclass, max_stack, slot, texture = GetItemInfo(itemstring)
if name and not _g.aux_item_ids[strlower(name)] then
_g.aux_item_ids[strlower(name)] = item_id
_g.aux_items[item_id] = persistence.write(items_schema, {
if name and not g.aux_item_ids[strlower(name)] then
g.aux_item_ids[strlower(name)] = item_id
g.aux_items[item_id] = persistence.write(items_schema, {
name = name,
quality = quality,
level = level,
@@ -176,7 +176,7 @@ function scan_wdb(item_id)
})
local tooltip = info.tooltip(function(tt) tt:SetHyperlink(itemstring) end)
if info.auctionable(tooltip, quality) then
tinsert(_g.aux_auctionable_items, strlower(name))
tinsert(g.aux_auctionable_items, strlower(name))
end
processed = processed + 1
end
@@ -187,7 +187,7 @@ function scan_wdb(item_id)
local t0 = GetTime()
control.thread(control.when, function() return GetTime() - t0 > 0.1 end, scan_wdb, item_id)
else
sort(_g.aux_auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end)
sort(g.aux_auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end)
end
end
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'disenchant'
module 'disenchant'
UNCOMMON = 2
RARE = 3
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'history'
module 'history'
local history_schema = {'record', '#', {next_push='number'}, {daily_min_buyout='number'}, {daily_max_price='number'}, {data_points={'list', ';', {'record', '@', {market_value='number'}, {time='number'}}}}}
value_cache = {}
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'post'
module 'post'
state = nil
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'scan'
module 'scan'
PAGE_SIZE = 50
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'stack'
module 'stack'
state = nil
+5 -8
View File
@@ -1,4 +1,5 @@
aux.module 'tooltip'
module 'tooltip'
import 'gui' 'lol' 'kek'
_g.aux_tooltip_value = true
@@ -206,15 +207,11 @@ end
function game_tooltip_hooks:SetCraftItem(skill, slot)
local link, quantity
if slot then
link = GetCraftReagentItemLink(skill, slot)
quantity = ({GetCraftReagentInfo(skill, slot)})[3]
link, quantity = GetCraftReagentItemLink(skill, slot), select(3, GetCraftReagentInfo(skill, slot))
else
link = GetCraftItemLink(skill)
quantity = 1
end
if link then
extend_tooltip(GameTooltip, link, quantity)
link, quantity = GetCraftItemLink(skill), 1
end
if link then extend_tooltip(GameTooltip, link, quantity) end
end
function game_tooltip_hooks:SetCraftSpell(slot)
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'control'
module 'control'
event_frame = CreateFrame 'Frame'
listeners = {}
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'core'
module 'core'
public.bids_loaded = false
public.current_owner_page = nil
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'gui'
module 'gui'
public.config = {
colors = {
+13 -23
View File
@@ -1,43 +1,33 @@
local aux_module, setn, tinsert, tremove, setfenv = aux_module, table.setn, tinsert, tremove, setfenv
local aux = aux_module 'core'
_g.aux = aux.interface
ADDON = aux
function INIT()
import{['']='modules', ['']='core', ['']='util'}
end
module 'core' -- .interface {x = 'core'} {y='core'} 'kek'
public.version = '5.0.0'
do
local table_pool, auto_recycle = {}, {}
local function wipe(t) -- like with a cloth or something
for k in t do t[k] = nil end
setn(t, 0); return t
function public.wipe(t) -- like with a cloth or something
for k in t do t[k] = nil end; setn(t, 0)
end
function public.recycle(t)
auto_recycle[t] = nil
tinsert(table_pool, wipe(t))
-- log(getn(table_pool))
auto_recycle[t] = nil; wipe(t); tinsert(table_pool, t)
end
public.temp = setmetatable({}, {__sub = function(_, t) auto_recycle[t] = true return t end})
function public.getter.t() return tremove(table_pool) or {} end
CreateFrame('Frame'):SetScript('OnUpdate', function()
for t in auto_recycle do recycle(t) end
recycle(auto_recycle); auto_recycle = t
CreateFrame 'Frame' :SetScript('OnUpdate', function()
for t in auto_recycle do recycle(t); log(getn(table_pool)) end
wipe(auto_recycle)
end)
end
do
local modules = {}
local function module_env(name) aux_module(name) return _m end
function public.module(name)
local env = module_env(name)
if not modules[name] then env.import(temp-{['']='modules', ['']='core', ['']='util'}) end
setfenv(2, env); modules[name] = true
end
end
local event_frame = CreateFrame 'Frame'
for _, event in temp-{'ADDON_LOADED', 'VARIABLES_LOADED', 'PLAYER_LOGIN', 'AUCTION_HOUSE_SHOW', 'AUCTION_HOUSE_CLOSED', 'AUCTION_BIDDER_LIST_UPDATE', 'AUCTION_OWNED_LIST_UPDATE'} do
event_frame:RegisterEvent(event)
end
ADDON_LOADED = {}
ADDON_LOADED = t
do
local variables_loaded_hooks, player_login_hooks = t, t
function public.setter.LOAD(f) tinsert(variables_loaded_hooks, f) end
+11 -6
View File
@@ -1,4 +1,5 @@
local type, setmetatable, setfenv, unpack, mask, _g = type, setmetatable, setfenv, unpack, bit.band, getfenv(0)
local _g = getfenv(); setfenv(0, setmetatable({}, {__index = function(_, key) return key end}))
local type, setmetatable, setfenv, unpack, mask = _g.type, _g.setmetatable, _g.setfenv, _g.unpack, _g.bit.band, _g.getfenv(0)
local PRIVATE, PUBLIC, MUTABLE, PROPERTY, GETTER, SETTER = 0, 1, 2, 4, 8, 16
local MODIFIER = {private=PRIVATE, public=PUBLIC, mutable=MUTABLE, getter=GETTER+PROPERTY, setter=SETTER+PROPERTY}
local MODIFIER_MASK, PROPERTY_MASK = {private=MUTABLE+GETTER+SETTER, public=MUTABLE+GETTER+SETTER, mutable=PRIVATE+PUBLIC, getter=PRIVATE+PUBLIC, setter=PRIVATE+PUBLIC}, PRIVATE+PUBLIC
@@ -74,7 +75,8 @@ do
end
end
end
function _g.aux_module(name)
function INIT() end
function module(name)
if not _modules[name] then
local state, getters, setters, imports, env, interface, declarator
imports, env, interface, declarator = {}, setmetatable({}, env_mt), setmetatable({}, interface_mt), setmetatable({}, declarator_mt)
@@ -84,21 +86,22 @@ function _g.aux_module(name)
getter=function() state.modifiers = PROPERTY+GETTER return declarator end, setter=function() state.modifiers = PROPERTY+SETTER return declarator end}
setters = {getter=function(value) set_property(getters, state.property, value) end, setter=function(value) set_property(setters, state.property, value) end}
state = {
name=name, env=env, interface=interface, imports={}, declarator_state=PRIVATE,
name=name, env=env, interface=interface, imports={}, modifiers=PRIVATE,
metadata = setmetatable({_g=PRIVATE, _m=PRIVATE, _i=PRIVATE, import=PRIVATE, private=PROPERTY+GETTER, public=PROPERTY+GETTER, mutable=PROPERTY+GETTER, getter=PROPERTY+GETTER+SETTER, setter=PROPERTY+GETTER+SETTER}, lock_mt),
data = {_g=_g, _m=env, _i=interface, import=function(t) import(imports, t) end},
getters=getters, setters=setters,
}
_modules[name], _state[env], _state[interface], _state[declarator] = state, state, state, state
setfenv(INIT, env); INIT()
end
local module = _modules[name]
setfenv(2, module.env)
return module
end
local frame = CreateFrame 'Frame'
frame:RegisterEvent 'PLAYER_LOGIN'
frame:RegisterEvent 'ADDON_LOADED'
frame:SetScript('OnEvent', function()
lock_mt.__newindex = function() error 'Modules are frozen after the loading phase.' end
if arg1 ~= ADDON then return end
local count = 0
local t0 = GetTime()
for _, module in _modules do
@@ -119,5 +122,7 @@ frame:SetScript('OnEvent', function()
end
end
end
_g.aux.log('imported: '..count..' in '..(GetTime()-t0))
aux.log('imported: '..count..' in '..(GetTime()-t0))
lock_mt.__newindex = function() error 'Modules are frozen after the loading phase.' end
setfenv(0, _g)
end)
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'auction_listing'
module 'auction_listing'
_g.aux_price_per_unit = false
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'item_listing'
module 'item_listing'
local ROW_HEIGHT = 39
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'listing'
module 'listing'
local ST_COUNT = 0
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'auctions_tab'
module 'auctions_tab'
aux.tab(3, 'Auctions')
auction_records = nil
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'auctions_tab'
module 'auctions_tab'
function create_frames()
frame = CreateFrame('Frame', nil, frame)
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'bids_tab'
module 'bids_tab'
aux.tab(4, 'Bids')
auction_records = nil
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'bids_tab'
module 'bids_tab'
function create_frames()
frame = CreateFrame('Frame', nil, frame)
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'post_tab'
module 'post_tab'
aux.tab(2, 'Post')
local DURATION_4, DURATION_8, DURATION_24 = 120, 480, 1440
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'post_tab'
module 'post_tab'
function create_frames()
frame = CreateFrame('Frame', nil, frame)
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'search_tab'
module 'search_tab'
aux.tab(1, 'Search')
StaticPopupDialogs['AUX_SEARCH_TABLE_FULL'] = {
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'search_tab'
module 'search_tab'
function valid_level(str)
local level = tonumber(str)
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'search_tab'
module 'search_tab'
FILTER_SPACING = 28.5
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'search_tab'
module 'search_tab'
_g.aux_auto_buy_filter = ''
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'search_tab'
module 'search_tab'
_g.aux_favorite_searches = {}
_g.aux_recent_searches = {}
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'completion'
module 'completion'
function public:complete_filter()
if IsControlKeyDown() then -- TODO problem is ctrl-v, maybe find a better solution
+1 -3
View File
@@ -1,6 +1,4 @@
aux.module 'util'
local temp, recycle, getn = _g.aux.temp, _g.aux.recycle, _g.getn
module 'util'
function public.copy(t)
local copy = {}
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'filter'
module 'filter'
function default_filter(str)
return {
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'info'
module 'info'
CreateFrame('GameTooltip', 'AuxTooltip', nil, 'GameTooltipTemplate')
AuxTooltip:SetScript('OnTooltipAddMoney', function()
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'money'
module 'money'
GOLD_TEXT = '|cffffd70ag|r'
SILVER_TEXT = '|cffc7c7cfs|r'
+13 -1
View File
@@ -1,4 +1,4 @@
aux.module 'persistence'
module 'persistence'
_g.aux_datasets = {}
@@ -19,6 +19,18 @@ function public.load_dataset()
return _g.aux_datasets[dataset_key]
end
--do TODO syntactic sugar
-- local mt = {
-- __unm = function(self, separator)
-- self.separator = separator
-- end,
-- __call = function(self, field) end
-- }
-- function public.getter.record()
--
-- end
--end
function public.read(schema, str)
if schema == 'string' then
return str
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'scan_util'
module 'scan_util'
function public.find(auction_record, status_bar, on_abort, on_failure, on_success)
+1 -1
View File
@@ -1,4 +1,4 @@
aux.module 'sorting'
module 'sorting'
public.LT = {}
public.EQ = {}