refactorings
This commit is contained in:
+24
-24
@@ -1,4 +1,4 @@
|
||||
local m, public, private = Aux.module'cache'
|
||||
local m, public, private = aux.module'cache'
|
||||
|
||||
local MIN_ITEM_ID, MAX_ITEM_ID = 1, 30000
|
||||
local items_schema = {'record', '#', {name='string'}, {quality='number'}, {level='number'}, {class='string'}, {subclass='string'}, {slot='string'}, {max_stack='number'}, {texture='string'}}
|
||||
@@ -14,19 +14,19 @@ aux_characters = {}
|
||||
function public.LOAD()
|
||||
m.scan_wdb()
|
||||
|
||||
Aux.control.event_listener('MERCHANT_SHOW', m.on_merchant_show)
|
||||
Aux.control.event_listener('MERCHANT_CLOSED', m.on_merchant_closed)
|
||||
Aux.control.event_listener('MERCHANT_UPDATE', m.on_merchant_update)
|
||||
Aux.control.event_listener('BAG_UPDATE', m.on_bag_update)
|
||||
aux.control.event_listener('MERCHANT_SHOW', m.on_merchant_show)
|
||||
aux.control.event_listener('MERCHANT_CLOSED', m.on_merchant_closed)
|
||||
aux.control.event_listener('MERCHANT_UPDATE', m.on_merchant_update)
|
||||
aux.control.event_listener('BAG_UPDATE', m.on_bag_update)
|
||||
|
||||
CreateFrame('Frame', nil, MerchantFrame):SetScript('OnUpdate', m.merchant_on_update)
|
||||
|
||||
Aux.control.event_listener('NEW_AUCTION_UPDATE', function()
|
||||
local info = Aux.info.auction_sell_item()
|
||||
aux.control.event_listener('NEW_AUCTION_UPDATE', function()
|
||||
local info = aux.info.auction_sell_item()
|
||||
if info then
|
||||
local item_id = Aux.cache.item_id(info.name)
|
||||
local item_id = aux.cache.item_id(info.name)
|
||||
if item_id then
|
||||
aux_merchant_sell[Aux.cache.item_id(info.name)] = info.vendor_price / (Aux.info.max_item_charges(item_id) or info.count)
|
||||
aux_merchant_sell[aux.cache.item_id(info.name)] = info.vendor_price / (aux.info.max_item_charges(item_id) or info.count)
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -79,7 +79,7 @@ end
|
||||
function public.merchant_info(item_id)
|
||||
local buy_info
|
||||
if aux_merchant_buy[item_id] then
|
||||
buy_info = Aux.persistence.read(merchant_buy_schema, aux_merchant_buy[item_id])
|
||||
buy_info = aux.persistence.read(merchant_buy_schema, aux_merchant_buy[item_id])
|
||||
end
|
||||
|
||||
return aux_merchant_sell[item_id], buy_info and buy_info.unit_price, buy_info and buy_info.limited
|
||||
@@ -88,7 +88,7 @@ end
|
||||
function public.item_info(item_id)
|
||||
local data_string = aux_items[item_id]
|
||||
if data_string then
|
||||
local cached_data = Aux.persistence.read(items_schema, data_string)
|
||||
local cached_data = aux.persistence.read(items_schema, data_string)
|
||||
return {
|
||||
name = cached_data.name,
|
||||
itemstring = 'item:'..item_id..':0:0:0',
|
||||
@@ -114,10 +114,10 @@ function private.merchant_buy_scan()
|
||||
local _, _, price, count, stock = GetMerchantItemInfo(i)
|
||||
local link = GetMerchantItemLink(i)
|
||||
if link then
|
||||
local item_id = Aux.info.parse_hyperlink(link)
|
||||
local item_id = aux.info.parse_hyperlink(link)
|
||||
local new_unit_price, new_limited = price / count, stock >= 0
|
||||
if aux_merchant_buy[item_id] then
|
||||
local buy_info = Aux.persistence.read(merchant_buy_schema, aux_merchant_buy[item_id])
|
||||
local buy_info = aux.persistence.read(merchant_buy_schema, aux_merchant_buy[item_id])
|
||||
|
||||
local unit_price
|
||||
if buy_info.limited and not new_limited then
|
||||
@@ -128,12 +128,12 @@ function private.merchant_buy_scan()
|
||||
unit_price = min(buy_info.unit_price, new_unit_price)
|
||||
end
|
||||
|
||||
aux_merchant_buy[item_id] = Aux.persistence.write(merchant_buy_schema, {
|
||||
aux_merchant_buy[item_id] = aux.persistence.write(merchant_buy_schema, {
|
||||
unit_price = unit_price,
|
||||
limited = buy_info.limited and new_limited,
|
||||
})
|
||||
else
|
||||
aux_merchant_buy[item_id] = Aux.persistence.write(merchant_buy_schema, {
|
||||
aux_merchant_buy[item_id] = aux.persistence.write(merchant_buy_schema, {
|
||||
unit_price = new_unit_price,
|
||||
limited = new_limited,
|
||||
})
|
||||
@@ -147,8 +147,8 @@ function private.merchant_buy_scan()
|
||||
end
|
||||
|
||||
function private.merchant_sell_scan()
|
||||
for slot in Aux.util.inventory() do
|
||||
local item_info = Aux.info.container_item(unpack(slot))
|
||||
for slot in aux.util.inventory() do
|
||||
local item_info = aux.info.container_item(unpack(slot))
|
||||
if item_info then
|
||||
aux_merchant_sell[item_info.item_id] = item_info.tooltip_money / item_info.aux_quantity
|
||||
end
|
||||
@@ -164,7 +164,7 @@ function private.scan_wdb(item_id)
|
||||
local name, _, quality, level, class, subclass, max_stack, slot, texture = GetItemInfo(itemstring)
|
||||
if name and not aux_item_ids[strlower(name)] then
|
||||
aux_item_ids[strlower(name)] = item_id
|
||||
aux_items[item_id] = Aux.persistence.write(items_schema, {
|
||||
aux_items[item_id] = aux.persistence.write(items_schema, {
|
||||
name = name,
|
||||
quality = quality,
|
||||
level = level,
|
||||
@@ -174,8 +174,8 @@ function private.scan_wdb(item_id)
|
||||
max_stack = max_stack,
|
||||
texture = texture,
|
||||
})
|
||||
local tooltip = Aux.info.tooltip(function(tt) tt:SetHyperlink(itemstring) end)
|
||||
if Aux.info.auctionable(tooltip, quality) then
|
||||
local tooltip = aux.info.tooltip(function(tt) tt:SetHyperlink(itemstring) end)
|
||||
if aux.info.auctionable(tooltip, quality) then
|
||||
tinsert(aux_auctionable_items, strlower(name))
|
||||
end
|
||||
processed = processed + 1
|
||||
@@ -185,7 +185,7 @@ function private.scan_wdb(item_id)
|
||||
|
||||
if item_id <= MAX_ITEM_ID then
|
||||
local t0 = GetTime()
|
||||
Aux.control.as_soon_as(function() return GetTime() - t0 > 0.1 end, m.scan_wdb, item_id)
|
||||
aux.control.as_soon_as(function() return GetTime() - t0 > 0.1 end, m.scan_wdb, item_id)
|
||||
else
|
||||
sort(aux_auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end)
|
||||
end
|
||||
@@ -195,14 +195,14 @@ function public.populate_wdb(item_id)
|
||||
item_id = item_id or MIN_ITEM_ID
|
||||
|
||||
if item_id > MAX_ITEM_ID then
|
||||
Aux.log('Cache populated.')
|
||||
aux.log('Cache populated.')
|
||||
return
|
||||
end
|
||||
|
||||
if not GetItemInfo('item:'..item_id) then
|
||||
Aux.log('Fetching item '..item_id..'.')
|
||||
aux.log('Fetching item '..item_id..'.')
|
||||
AuxTooltip:SetHyperlink('item:'..item_id)
|
||||
end
|
||||
|
||||
Aux.control.thread(m.populate_wdb, item_id + 1)
|
||||
aux.control.thread(m.populate_wdb, item_id + 1)
|
||||
end
|
||||
Reference in New Issue
Block a user