refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-24 00:48:34 +02:00
parent bdc3d1bc33
commit 25d59cd625
3 changed files with 35 additions and 38 deletions
+6 -7
View File
@@ -59,7 +59,7 @@ do
function public.accessor.temp() return temp end; function mutator(t) return temp(t) end
function public.accessor.perm() return perm end; function mutator(t) return perm(t) end
function keys(t,k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,k14,k15,k16,k17,k18,k19,k20)
local function keys(t,k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,k14,k15,k16,k17,k18,k19,k20)
if not t then return end
if k1 ~= nil then t[k1] = true end
if k2 ~= nil then t[k2] = true end
@@ -83,7 +83,7 @@ do
if k20 ~= nil then t[k20] = true end
return t
end
function values(t,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18,v19,v20)
local function values(t,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18,v19,v20)
if not t then return end
if v1 ~= nil then tinsert(t, v1) end
if v2 ~= nil then tinsert(t, v2) end
@@ -107,7 +107,7 @@ do
if v20 ~= nil then tinsert(t, v20) end
return t
end
function pairs(t,k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6,k7,v7,k8,v8,k9,v9,k10,v10)
local function pairs(t,k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6,k7,v7,k8,v8,k9,v9,k10,v10)
if not t then return end
if k1 ~= nil then t[k1] = v1 end
if k2 ~= nil then t[k2] = v2 end
@@ -125,14 +125,13 @@ do
return {__call=f, __unm=function(self) return setmetatable(self, nil) end}
end
local set_mt, list_mt, object_mt = collector_mt(keys), collector_mt(values), collector_mt(pairs)
public.accessor()
set, list, object = function() return setmetatable(t, set_mt) end, function() return setmetatable(t, list_mt) end, function() return setmetatable(t, object_mt) end
private()
public.accessor.set, public.accessor.list, public.accessor.object = function() return setmetatable(t, set_mt) end, function() return setmetatable(t, list_mt) end, function() return setmetatable(t, object_mt) end
-- TODO or 'auto' 'free' 'deprecate' 'release' 'transient'?
end
local event_frame = CreateFrame 'Frame'
for event in temp-set('ADDON_LOADED', 'VARIABLES_LOADED', 'PLAYER_LOGIN', 'AUCTION_HOUSE_SHOW', 'AUCTION_HOUSE_CLOSED', 'AUCTION_BIDDER_LIST_UPDATE', 'AUCTION_OWNED_LIST_UPDATE') do
for event in -temp^set('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
+27 -30
View File
@@ -3,15 +3,17 @@ module 'cache' import 'info'
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'} -- TODO
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'}}
_g.aux_items = {}
_g.aux_item_ids = {}
_g.aux_auctionable_items = {}
_g.aux_merchant_buy = {}
_g.aux_merchant_sell = {}
_g.aux_characters = {}
_g.aux_items = t
_g.aux_item_ids = t
_g.aux_auctionable_items = t
_g.aux_merchant_buy = t
_g.aux_merchant_sell = t
_g.aux_characters = t
function LOAD()
import 'persistence' 'info'
@@ -35,29 +37,24 @@ end
do
local sell_scan_countdown, incomplete_buy_data
function on_merchant_show()
merchant_sell_scan()
incomplete_buy_data = not merchant_buy_scan()
end
function on_merchant_closed()
sell_scan_countdown = nil
incomplete_buy_data = false
end
function on_merchant_update()
if incomplete_buy_data then
incomplete_buy_data = not merchant_buy_scan()
end
end
function on_bag_update()
if MerchantFrame:IsVisible() then
sell_scan_countdown = 10
end
end
function merchant_on_update()
if sell_scan_countdown == 0 then
sell_scan_countdown = nil
@@ -90,17 +87,17 @@ function public.item_info(item_id)
local data_string = _g.aux_items[item_id]
if data_string then
local cached_data = persistence.read(items_schema, data_string)
return {
name = cached_data.name,
itemstring = 'item:'..item_id..':0:0:0',
quality = cached_data.quality,
level = cached_data.level,
class = cached_data.class,
subclass = cached_data.subclass,
slot = cached_data.slot,
max_stack = cached_data.max_stack,
texture = cached_data.texture,
}
return -object(
'name', cached_data.name,
'itemstring', 'item:'..item_id..':0:0:0',
'quality', cached_data.quality,
'level', cached_data.level,
'class', cached_data.class,
'subclass', cached_data.subclass,
'slot', cached_data.slot,
'max_stack', cached_data.max_stack,
'texture', cached_data.texture
)
end
end
@@ -129,15 +126,15 @@ 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, {
unit_price = unit_price,
limited = buy_info.limited and new_limited,
})
_g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, -object(
'unit_price', unit_price,
'limited', buy_info.limited and new_limited
))
else
_g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, {
unit_price = new_unit_price,
limited = new_limited,
})
_g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, -object(
'unit_price', new_unit_price,
'limited', new_limited
))
end
else
incomplete_data = true
+2 -1
View File
@@ -405,7 +405,8 @@ function update_inventory_records()
'quality', item_info.quality,
'aux_quantity', item_info.charges or item_info.count,
'max_stack', item_info.max_stack,
'max_charges', item_info.max_charges,
'max_charges', item_info.max_charges
)(
'availability', availability
)
else