refactoring
This commit is contained in:
+22
-22
@@ -8,12 +8,12 @@ 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'}}
|
||||
|
||||
_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
|
||||
_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'
|
||||
@@ -29,7 +29,7 @@ function LOAD()
|
||||
event_listener('NEW_AUCTION_UPDATE', function()
|
||||
for info in present(info.auction_sell_item()) do
|
||||
for item_id in present(item_id(info.name)) do
|
||||
_g.aux_merchant_sell[_m.item_id(info.name)] = info.vendor_price / (_m.info.max_item_charges(item_id) or info.count)
|
||||
_G.aux_merchant_sell[M.item_id(info.name)] = info.vendor_price / (M.info.max_item_charges(item_id) or info.count)
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -76,15 +76,15 @@ end
|
||||
|
||||
function public.merchant_info(item_id)
|
||||
local buy_info
|
||||
if _g.aux_merchant_buy[item_id] then
|
||||
buy_info = persistence.read(merchant_buy_schema, _g.aux_merchant_buy[item_id])
|
||||
if _G.aux_merchant_buy[item_id] then
|
||||
buy_info = persistence.read(merchant_buy_schema, _G.aux_merchant_buy[item_id])
|
||||
end
|
||||
|
||||
return _g.aux_merchant_sell[item_id], buy_info and buy_info.unit_price, buy_info and buy_info.limited
|
||||
return _G.aux_merchant_sell[item_id], buy_info and buy_info.unit_price, buy_info and buy_info.limited
|
||||
end
|
||||
|
||||
function public.item_info(item_id)
|
||||
local data_string = _g.aux_items[item_id]
|
||||
local data_string = _G.aux_items[item_id]
|
||||
if data_string then
|
||||
local cached_data = persistence.read(items_schema, data_string)
|
||||
return -object(
|
||||
@@ -102,7 +102,7 @@ function public.item_info(item_id)
|
||||
end
|
||||
|
||||
function public.item_id(item_name)
|
||||
return _g.aux_item_ids[strlower(item_name)]
|
||||
return _G.aux_item_ids[strlower(item_name)]
|
||||
end
|
||||
|
||||
function merchant_buy_scan()
|
||||
@@ -114,8 +114,8 @@ function merchant_buy_scan()
|
||||
if link then
|
||||
local item_id = info.parse_link(link)
|
||||
local new_unit_price, new_limited = price / count, stock >= 0
|
||||
if _g.aux_merchant_buy[item_id] then
|
||||
local buy_info = persistence.read(merchant_buy_schema, _g.aux_merchant_buy[item_id])
|
||||
if _G.aux_merchant_buy[item_id] then
|
||||
local buy_info = persistence.read(merchant_buy_schema, _G.aux_merchant_buy[item_id])
|
||||
|
||||
local unit_price
|
||||
if buy_info.limited and not new_limited then
|
||||
@@ -126,12 +126,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, -object(
|
||||
_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, -object(
|
||||
_G.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, -object(
|
||||
'unit_price', new_unit_price,
|
||||
'limited', new_limited
|
||||
))
|
||||
@@ -148,7 +148,7 @@ function merchant_sell_scan()
|
||||
for slot in info.inventory do temp=slot
|
||||
local item_info = temp-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
|
||||
@@ -160,9 +160,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, -object(
|
||||
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, -object(
|
||||
'name', name,
|
||||
'quality', quality,
|
||||
'level', level,
|
||||
@@ -174,7 +174,7 @@ function scan_wdb(item_id)
|
||||
))
|
||||
local tooltip = info.tooltip(function(tooltip) tooltip: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
|
||||
@@ -185,7 +185,7 @@ function scan_wdb(item_id)
|
||||
local t0 = GetTime()
|
||||
thread(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
|
||||
|
||||
|
||||
+2
-2
@@ -147,7 +147,7 @@ function scan_page(i)
|
||||
end
|
||||
|
||||
local auction_info = info.auction(i, state.params.type)
|
||||
if auction_info and (auction_info.owner or state.params.ignore_owner or _g.aux_ignore_owner) then
|
||||
if auction_info and (auction_info.owner or state.params.ignore_owner or _G.aux_ignore_owner) then
|
||||
auction_info.index = i
|
||||
auction_info.page = state.page
|
||||
auction_info.blizzard_query = query.blizzard_query
|
||||
@@ -218,7 +218,7 @@ function wait_for_list_results(send_signal, signal_received)
|
||||
last_update = GetTime()
|
||||
updated = true
|
||||
end)
|
||||
local ignore_owner = state.params.ignore_owner or _g.aux_ignore_owner
|
||||
local ignore_owner = state.params.ignore_owner or _G.aux_ignore_owner
|
||||
return thread(when, function()
|
||||
-- short circuiting order important, owner_data_complete must be called iif an update has happened.
|
||||
local ok = updated and (ignore_owner or owner_data_complete('list')) or last_update and GetTime() - last_update > 5
|
||||
|
||||
+31
-31
@@ -1,7 +1,7 @@
|
||||
module 'slash' import 'persistence'
|
||||
|
||||
_g.SLASH_AUX1 = '/aux'
|
||||
function _g.SlashCmdList.AUX(command)
|
||||
_G.SLASH_AUX1 = '/aux'
|
||||
function _G.SlashCmdList.AUX(command)
|
||||
if not command then return end
|
||||
local arguments = tokenize(command)
|
||||
if arguments[1] == 'clear' and arguments[2] == 'history' then
|
||||
@@ -11,71 +11,71 @@ function _g.SlashCmdList.AUX(command)
|
||||
persistence.dataset.post = nil
|
||||
log 'Post settings cleared.'
|
||||
elseif arguments[1] == 'clear' and arguments[2] == 'datasets' then
|
||||
_g.aux_datasets = {}
|
||||
_G.aux_datasets = {}
|
||||
log 'Datasets cleared.'
|
||||
elseif arguments[1] == 'clear' and arguments[2] == 'merchant' and arguments[3] == 'buy' then
|
||||
_g.aux_merchant_buy = {}
|
||||
_G.aux_merchant_buy = {}
|
||||
log 'Merchant buy prices cleared.'
|
||||
elseif arguments[1] == 'clear' and arguments[2] == 'merchant' and arguments[3] == 'sell' then
|
||||
_g.aux_merchant_sell = {}
|
||||
_G.aux_merchant_sell = {}
|
||||
log 'Merchant sell prices cleared.'
|
||||
elseif arguments[1] == 'clear' and arguments[2] == 'item' and arguments[3] == 'cache' then
|
||||
_g.aux_items = {}
|
||||
_g.aux_item_ids = {}
|
||||
_g.aux_auctionable_items = {}
|
||||
_G.aux_items = {}
|
||||
_G.aux_item_ids = {}
|
||||
_G.aux_auctionable_items = {}
|
||||
log 'Item cache cleared.'
|
||||
elseif arguments[1] == 'populate' and arguments[2] == 'wdb' then
|
||||
cache.populate_wdb()
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'value' then
|
||||
_g.aux_tooltip_value = not _g.aux_tooltip_value
|
||||
log('Historical value in tooltip '..(_g.aux_tooltip_value and 'enabled' or 'disabled')..'.')
|
||||
_G.aux_tooltip_value = not _G.aux_tooltip_value
|
||||
log('Historical value in tooltip '..(_G.aux_tooltip_value and 'enabled' or 'disabled')..'.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'daily' then
|
||||
_g.aux_tooltip_daily = not _g.aux_tooltip_daily
|
||||
log('Market value in tooltip '..(_g.aux_tooltip_daily and 'enabled' or 'disabled')..'.')
|
||||
_G.aux_tooltip_daily = not _G.aux_tooltip_daily
|
||||
log('Market value in tooltip '..(_G.aux_tooltip_daily and 'enabled' or 'disabled')..'.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'vendor' and arguments[3] == 'buy' then
|
||||
_g.aux_tooltip_vendor_buy = not _g.aux_tooltip_vendor_buy
|
||||
log('Vendor buy price in tooltip '..(_g.aux_tooltip_vendor_buy and 'enabled' or 'disabled')..'.')
|
||||
_G.aux_tooltip_vendor_buy = not _G.aux_tooltip_vendor_buy
|
||||
log('Vendor buy price in tooltip '..(_G.aux_tooltip_vendor_buy and 'enabled' or 'disabled')..'.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'vendor' and arguments[3] == 'sell' then
|
||||
_g.aux_tooltip_vendor_sell = not _g.aux_tooltip_vendor_sell
|
||||
log('Vendor sell price in tooltip '..(_g.aux_tooltip_vendor_sell and 'enabled' or 'disabled')..'.')
|
||||
_G.aux_tooltip_vendor_sell = not _G.aux_tooltip_vendor_sell
|
||||
log('Vendor sell price in tooltip '..(_G.aux_tooltip_vendor_sell and 'enabled' or 'disabled')..'.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'disenchant' and arguments[3] == 'value' then
|
||||
_g.aux_tooltip_disenchant_value = not _g.aux_tooltip_disenchant_value
|
||||
log('Disenchant value in tooltip '..(_g.aux_tooltip_disenchant_value and 'enabled' or 'disabled')..'.')
|
||||
_G.aux_tooltip_disenchant_value = not _G.aux_tooltip_disenchant_value
|
||||
log('Disenchant value in tooltip '..(_G.aux_tooltip_disenchant_value and 'enabled' or 'disabled')..'.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'disenchant' and arguments[3] == 'distribution' then
|
||||
_g.aux_tooltip_disenchant_distribution = not _g.aux_tooltip_disenchant_distribution
|
||||
log('Disenchant distribution in tooltip '..(_g.aux_tooltip_disenchant_distribution and 'enabled' or 'disabled')..'.')
|
||||
_G.aux_tooltip_disenchant_distribution = not _G.aux_tooltip_disenchant_distribution
|
||||
log('Disenchant distribution in tooltip '..(_G.aux_tooltip_disenchant_distribution and 'enabled' or 'disabled')..'.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'disenchant' and arguments[3] == 'source' then
|
||||
_g.aux_tooltip_disenchant_source = not _g.aux_tooltip_disenchant_source
|
||||
log('Disenchant source in tooltip '..(_g.aux_tooltip_disenchant_source and 'enabled' or 'disabled')..'.')
|
||||
_G.aux_tooltip_disenchant_source = not _G.aux_tooltip_disenchant_source
|
||||
log('Disenchant source in tooltip '..(_G.aux_tooltip_disenchant_source and 'enabled' or 'disabled')..'.')
|
||||
elseif arguments[1] == 'ignore' and arguments[2] == 'owner' then
|
||||
_g.aux_ignore_owner = not _g.aux_ignore_owner
|
||||
log('Ignoring of owner '..(_g.aux_ignore_owner and 'enabled' or 'disabled')..'.')
|
||||
_G.aux_ignore_owner = not _G.aux_ignore_owner
|
||||
log('Ignoring of owner '..(_G.aux_ignore_owner and 'enabled' or 'disabled')..'.')
|
||||
elseif arguments[1] == 'chars' and arguments[2] == 'add' then
|
||||
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
|
||||
local name = gsub(strlower(arguments[i]), '^%l', strupper)
|
||||
if not _g.aux_characters[realm][name] then
|
||||
_g.aux_characters[realm][name] = true
|
||||
if not _G.aux_characters[realm][name] then
|
||||
_G.aux_characters[realm][name] = true
|
||||
log('Character "'..name..'" added.')
|
||||
end
|
||||
end
|
||||
elseif arguments[1] == 'chars' and arguments[2] == 'remove' then
|
||||
local realm = GetCVar 'realmName'
|
||||
if not _g.aux_characters[realm] then
|
||||
if not _G.aux_characters[realm] then
|
||||
return
|
||||
end
|
||||
for i=3,getn(arguments) do
|
||||
local name = gsub(strlower(arguments[i]), '^%l', strupper)
|
||||
if _g.aux_characters[realm][name] then
|
||||
_g.aux_characters[realm][name] = nil
|
||||
if _G.aux_characters[realm][name] then
|
||||
_G.aux_characters[realm][name] = nil
|
||||
log('Character "'..name..'" removed.')
|
||||
end
|
||||
end
|
||||
elseif arguments[1] == 'chars' then
|
||||
local realm = GetCVar 'realmName'
|
||||
local chars = {}
|
||||
for name in _g.aux_characters[realm] or {} do
|
||||
for name in _G.aux_characters[realm] or {} do
|
||||
tinsert(chars, name)
|
||||
end
|
||||
if getn(chars) > 0 then
|
||||
|
||||
+9
-9
@@ -1,6 +1,6 @@
|
||||
module 'tooltip' import 'info' 'disenchant' 'cache' 'money' 'history'
|
||||
|
||||
_g.aux_tooltip_value = true
|
||||
_G.aux_tooltip_value = true
|
||||
|
||||
game_tooltip_hooks = t
|
||||
mutable.hooked_setter = nil
|
||||
@@ -9,7 +9,7 @@ mutable.game_tooltip_money = nil
|
||||
function LOAD()
|
||||
for name, f in game_tooltip_hooks do
|
||||
local name, f = name, f
|
||||
_m.hook(name, GameTooltip, function(...) temp=arg
|
||||
M.hook(name, GameTooltip, function(...) temp=arg
|
||||
hooked_setter = true
|
||||
game_tooltip_money = 0
|
||||
local ret = {orig[GameTooltip][name](unpack(arg))}
|
||||
@@ -42,7 +42,7 @@ end
|
||||
function extend_tooltip(tooltip, link, quantity)
|
||||
local item_id, suffix_id = info.parse_link(link)
|
||||
quantity = IsShiftKeyDown() and quantity or 1
|
||||
if _g.aux_tooltip_disenchant_source then
|
||||
if _G.aux_tooltip_disenchant_source then
|
||||
local color = {r=.7, g=.7, b=.7}
|
||||
local type, range = disenchant.source(item_id)
|
||||
if type == 'CRYSTAL' then
|
||||
@@ -58,7 +58,7 @@ function extend_tooltip(tooltip, link, quantity)
|
||||
for item_info in present(info.item(item_id)) do
|
||||
local distribution = disenchant.distribution(item_info.slot, item_info.quality, item_info.level)
|
||||
if getn(distribution) > 0 then
|
||||
if _g.aux_tooltip_disenchant_distribution then
|
||||
if _G.aux_tooltip_disenchant_distribution then
|
||||
local color = {r=.8, g=.8, b=.2}
|
||||
|
||||
tooltip:AddLine('Disenchants into:', color.r, color.g, color.b)
|
||||
@@ -67,7 +67,7 @@ function extend_tooltip(tooltip, link, quantity)
|
||||
tooltip:AddLine(format(' %s%% %s (%s-%s)', event.probability * 100, info.display_name(event.item_id, true) or 'item:'..event.item_id, event.min_quantity, event.max_quantity), color.r, color.g, color.b)
|
||||
end
|
||||
end
|
||||
if _g.aux_tooltip_disenchant_value then
|
||||
if _G.aux_tooltip_disenchant_value then
|
||||
local color = {r=.1, g=.6, b=.6}
|
||||
|
||||
local disenchant_value = disenchant.value(item_info.slot, item_info.quality, item_info.level)
|
||||
@@ -75,14 +75,14 @@ function extend_tooltip(tooltip, link, quantity)
|
||||
end
|
||||
end
|
||||
end
|
||||
if _g.aux_tooltip_vendor_buy then
|
||||
if _G.aux_tooltip_vendor_buy then
|
||||
local color = {r=.8, g=.5, b=.1}
|
||||
local _, price, limited = cache.merchant_info(item_id)
|
||||
if price then
|
||||
tooltip:AddLine('Vendor Buy '..(limited and '(limited): ' or ': ')..money.to_string2(price * quantity), color.r, color.g, color.b)
|
||||
end
|
||||
end
|
||||
if _g.aux_tooltip_vendor_sell then
|
||||
if _G.aux_tooltip_vendor_sell then
|
||||
local color = {r=.8, g=.5, b=.1}
|
||||
local price = cache.merchant_info(item_id)
|
||||
if price ~= 0 then
|
||||
@@ -94,10 +94,10 @@ function extend_tooltip(tooltip, link, quantity)
|
||||
local item_key = (item_id or 0)..':'..(suffix_id or 0)
|
||||
local value = history.value(item_key)
|
||||
if auctionable then
|
||||
if _g.aux_tooltip_value then
|
||||
if _G.aux_tooltip_value then
|
||||
tooltip:AddLine('Value: '..(value and money.to_string2(value * quantity) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
|
||||
end
|
||||
if _g.aux_tooltip_daily then
|
||||
if _G.aux_tooltip_daily then
|
||||
local market_value = history.market_value(item_key)
|
||||
tooltip:AddLine('Today: '..(market_value and money.to_string2(market_value * quantity)..' ('..auction_listing.percentage_historical(round(market_value / value * 100))..')' or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user