Anonymous

Module:Icons: Difference between revisions

From Melvor Idle
_Currency: Conditional formatting for negative amounts, and refactor to avoid repeated string concatenation
mNo edit summary
(_Currency: Conditional formatting for negative amounts, and refactor to avoid repeated string concatenation)
Tag: Reverted
Line 843: Line 843:
end
end


function p._Currency(fileName, link, altText, amt, maxAmt)
function p._Currency(fileName, link, altText, amount, maxAmount)
local amtText = nil
local ret = {}
if tonumber(amt) ~= nil then
table.insert(ret, '<span style="display:inline-block">')
amtText = formatnum(amt)
-- Currency icon
if maxAmt ~= nil and maxAmt >= amt then
if fileName ~= nil then
amtText = amtText .. ' - ' .. formatnum(maxAmt)
table.insert(ret, '[[File:' .. fileName .. '|25px')
if link ~= nil then
table.insert(ret, '|link=' .. link)
end
end
table.insert(ret, '|alt=' .. ((altText == nil and '') or altText) .. ']]')
end
end
 
-- Currency amounts
local fileText = ''
if tonumber(amount) ~= nil then
if fileName ~= nil then
local function numColour(amount)
fileText = '[[File:' .. fileName .. '|25px'
if amount < 0 then
if link ~= nil then
return '<span style="color:red;">' .. formatnum(amount) .. '</span>'
fileText = fileText .. '|link=' .. link
else
return formatnum(amount)
end
end
table.insert(ret, '&nbsp;' .. numColour(amount))
if (tonumber(maxAmount) ~= nil and maxAmount > amount) then
table.insert(ret, ' - ' .. numColour(maxAmount))
end
end
fileText = fileText .. '|alt=' .. ((altText == nil and '') or altText) .. ']]'
end
end
 
table.insert(ret, '</span>')
return '<span style="display:inline-block">' .. fileText .. (amtText ~= nil and '&nbsp;' .. amtText or '') .. '</span>'
return table.concat(ret)
end
end