optimization

This commit is contained in:
Manuel Simon Hirsig
2018-02-17 13:15:57 +01:00
parent bf0b70e33f
commit 60fdb00a6b
+26 -23
View File
@@ -294,19 +294,20 @@ function M.tooltip(setter, arg1, arg2)
return tooltip, AuxTooltip.money
end
function item_charges(tooltip)
for _, line in tooltip do
local pattern = '^' .. gsub(gsub(ITEM_SPELL_CHARGES_P1, '%%d', '(%%d+)'), '%%%d+%$d', '(%%d+)') .. '$'
do
local pattern = '^' .. gsub(gsub(ITEM_SPELL_CHARGES_P1, '%%d', '(%%d+)'), '%%%d+%$d', '(%%d+)') .. '$'
function item_charges(tooltip)
for _, line in tooltip do
local _, _, left_charges_string = strfind(line.left_text or '', pattern)
local _, _, right_charges_string = strfind(line.right_text or '', pattern)
local _, _, left_charges_string = strfind(line.left_text or '', pattern)
local _, _, right_charges_string = strfind(line.right_text or '', pattern)
local charges = tonumber(left_charges_string) or tonumber(right_charges_string)
if charges then
return max(1, charges) -- TODO kronos bug? should never be 0
end
end
return 1
local charges = tonumber(left_charges_string) or tonumber(right_charges_string)
if charges then
return max(1, charges) -- TODO kronos bug? should never be 0
end
end
return 1
end
end
do
@@ -340,17 +341,19 @@ do
end
end
function M.durability(tooltip)
for _, line in tooltip do
local pattern = '^' .. gsub(gsub(DURABILITY_TEMPLATE, '%%d', '(%%d+)'), '%%%d+%$d', '(%%d+)') .. '$'
local _, _, left_durability_string, left_max_durability_string = strfind(line.left_text or '', pattern)
local _, _, right_durability_string, right_max_durability_string = strfind(line.right_text or '', pattern)
local durability = tonumber(left_durability_string) or tonumber(right_durability_string)
local max_durability = tonumber(left_max_durability_string) or tonumber(right_max_durability_string)
if durability then
return durability, max_durability
end
end
do
local pattern = '^' .. gsub(gsub(DURABILITY_TEMPLATE, '%%d', '(%%d+)'), '%%%d+%$d', '(%%d+)') .. '$'
function M.durability(tooltip)
for _, line in tooltip do
local _, _, left_durability_string, left_max_durability_string = strfind(line.left_text or '', pattern)
local _, _, right_durability_string, right_max_durability_string = strfind(line.right_text or '', pattern)
local durability = tonumber(left_durability_string) or tonumber(right_durability_string)
local max_durability = tonumber(left_max_durability_string) or tonumber(right_max_durability_string)
if durability then
return durability, max_durability
end
end
end
end
function M.item_key(link)