refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-09-04 21:21:47 +02:00
parent e888efcf2a
commit 867505c1a8
23 changed files with 172 additions and 173 deletions
+5 -5
View File
@@ -88,7 +88,7 @@ function public.item_info(item_id)
local cached_data = persistence.read(items_schema, data_string)
return T(
'name', cached_data.name,
'itemstring', 'item:'..item_id..':0:0:0',
'itemstring', 'item:' .. item_id .. ':0:0:0',
'quality', cached_data.quality,
'level', cached_data.level,
'class', cached_data.class,
@@ -157,7 +157,7 @@ function scan_wdb(item_id)
local processed = 0
while processed <= 100 and item_id <= MAX_ITEM_ID do
local itemstring = 'item:'..item_id
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
@@ -193,9 +193,9 @@ function public.populate_wdb(item_id)
print 'Cache populated.'
return
end
if not GetItemInfo('item:'..item_id) then
print('Fetching item '..item_id..'.')
AuxTooltip:SetHyperlink('item:'..item_id)
if not GetItemInfo('item:' .. item_id) then
print('Fetching item ' .. item_id .. '.')
AuxTooltip:SetHyperlink('item:' .. item_id)
end
thread(populate_wdb, item_id + 1)
end
+1 -1
View File
@@ -70,7 +70,7 @@ end
function public.value(slot, quality, level)
local expectation
for _, event in distribution(slot, quality, level) do
local value = aux.history.value(event.item_id..':'..0)
local value = aux.history.value(event.item_id .. ':' .. 0)
if not value then
return
else
+12 -12
View File
@@ -30,28 +30,28 @@ function _G.SlashCmdList.AUX(command)
aux.cache.populate_wdb()
elseif arguments[1] == 'tooltip' and arguments[2] == 'value' then
_G.aux_tooltip_value = not _G.aux_tooltip_value
print('Historical value in tooltip '..(_G.aux_tooltip_value and 'enabled' or 'disabled')..'.')
print('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
print('Market value in tooltip '..(_G.aux_tooltip_daily and 'enabled' or 'disabled')..'.')
print('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
print('Vendor buy price in tooltip '..(_G.aux_tooltip_vendor_buy and 'enabled' or 'disabled')..'.')
print('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
print('Vendor sell price in tooltip '..(_G.aux_tooltip_vendor_sell and 'enabled' or 'disabled')..'.')
print('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
print('Disenchant value in tooltip '..(_G.aux_tooltip_disenchant_value and 'enabled' or 'disabled')..'.')
print('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
print('Disenchant distribution in tooltip '..(_G.aux_tooltip_disenchant_distribution and 'enabled' or 'disabled')..'.')
print('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
print('Disenchant source in tooltip '..(_G.aux_tooltip_disenchant_source and 'enabled' or 'disabled')..'.')
print('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
print('Ignoring of owner '..(_G.aux_ignore_owner and 'enabled' or 'disabled')..'.')
print('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 t
@@ -59,7 +59,7 @@ function _G.SlashCmdList.AUX(command)
local name = gsub(strlower(arguments[i]), '^%l', strupper)
if not _G.aux_characters[realm][name] then
_G.aux_characters[realm][name] = true
print('Character "'..name..'" added.')
print('Character "' .. name .. '" added.')
end
end
elseif arguments[1] == 'chars' and arguments[2] == 'remove' then
@@ -71,7 +71,7 @@ function _G.SlashCmdList.AUX(command)
local name = gsub(strlower(arguments[i]), '^%l', strupper)
if _G.aux_characters[realm][name] then
_G.aux_characters[realm][name] = nil
print('Character "'..name..'" removed.')
print('Character "' .. name .. '" removed.')
end
end
elseif arguments[1] == 'chars' then
@@ -81,11 +81,11 @@ function _G.SlashCmdList.AUX(command)
tinsert(chars, name)
end
if getn(chars) > 0 then
print('Your characters: "'..join(chars, ', ')..'".')
print('Your characters: "' .. join(chars, ', ') .. '".')
else
print 'You don\'t have any additional characters. To add your characters type "/aux chars add NAME1 NAME2 NAME3...".'
end
else
print('Unknown command: "'..command..'"')
print('Unknown command: "' .. command .. '"')
end
end
+10 -10
View File
@@ -33,7 +33,7 @@ function LOAD()
local name, _, quality = GetItemInfo(arg[1])
if not IsShiftKeyDown() and not IsControlKeyDown() and name then
local color_code = select(4, GetItemQualityColor(quality))
local link = color_code.. '|H'..arg[1]..'|h['..name..']|h'..FONT_COLOR_CODE_CLOSE
local link = color_code .. '|H' .. arg[1] .. '|h[' .. name .. ']|h' .. FONT_COLOR_CODE_CLOSE
extend_tooltip(ItemRefTooltip, link, 1)
end
return result
@@ -66,14 +66,14 @@ function extend_tooltip(tooltip, link, quantity)
tooltip:AddLine('Disenchants into:', color.r, color.g, color.b)
sort(distribution, function(a,b) return a.probability > b.probability end)
for _, event in distribution do
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)
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
local color = {r=.1, g=.6, b=.6}
local disenchant_value = disenchant.value(item_info.slot, item_info.quality, item_info.level)
tooltip:AddLine('Disenchant Value: '..(disenchant_value and money.to_string2(disenchant_value) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
tooltip:AddLine('Disenchant Value: ' .. (disenchant_value and money.to_string2(disenchant_value) or GRAY_FONT_COLOR_CODE .. '---' .. FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
end
end
end
@@ -81,27 +81,27 @@ function extend_tooltip(tooltip, link, quantity)
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)
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
local color = {r=.8, g=.5, b=.1}
local price = cache.merchant_info(item_id)
if price ~= 0 then
tooltip:AddLine('Vendor Sell: '..(price and money.to_string2(price * quantity) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
tooltip:AddLine('Vendor Sell: ' .. (price and money.to_string2(price * quantity) or GRAY_FONT_COLOR_CODE .. '---' .. FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
end
end
local color = {r=1, g=1, b=.6}
local auctionable = not item_info or info.auctionable(info.tooltip(function(tooltip) tooltip:SetHyperlink(item_info.itemstring) end), item_info.quality)
local item_key = (item_id or 0)..':'..(suffix_id or 0)
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
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)
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
local market_value = history.market_value(item_key)
tooltip:AddLine('Today: '..(market_value and money.to_string2(market_value * quantity)..' ('..aux.auction_listing.percentage_historical(round(market_value / value * 100))..')' or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
tooltip:AddLine('Today: ' .. (market_value and money.to_string2(market_value * quantity) .. ' (' .. aux.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
end
@@ -115,7 +115,7 @@ function game_tooltip_hooks:SetHyperlink(itemstring)
local name, _, quality = GetItemInfo(itemstring)
if name then
local hex = select(4, GetItemQualityColor(quality))
local link = hex.. '|H'..itemstring..'|h['..name..']|h'..FONT_COLOR_CODE_CLOSE
local link = hex .. '|H' .. itemstring .. '|h[' .. name .. ']|h' .. FONT_COLOR_CODE_CLOSE
extend_tooltip(GameTooltip, link, 1)
end
end
@@ -155,7 +155,7 @@ function game_tooltip_hooks:SetInboxItem(index)
for id in present(name and cache.item_id(name)) do
local _, itemstring, quality = GetItemInfo(id)
local hex = select(4, GetItemQualityColor(tonumber(quality)))
local link = hex.. '|H'..itemstring..'|h['..name..']|h'..FONT_COLOR_CODE_CLOSE
local link = hex .. '|H' .. itemstring .. '|h[' .. name .. ']|h' .. FONT_COLOR_CODE_CLOSE
extend_tooltip(GameTooltip, link, quantity)
end
end