17,101
edits
(Add red colouring for negative currencies) |
(_Currency: Format negative maxAmount values also, and refactor to avoid repeated string concatenation) |
||
Line 844: | Line 844: | ||
function p._Currency(fileName, link, altText, amount, maxAmount) | function p._Currency(fileName, link, altText, amount, maxAmount) | ||
local | local ret = {} | ||
table.insert(ret, '<span style="display:inline-block">') | |||
-- Currency icon | |||
if fileName ~= nil then | if fileName ~= nil then | ||
table.insert(ret, '[[File:' .. fileName .. '|25px') | |||
if link ~= nil then | if link ~= nil then | ||
table.insert(ret, '|link=' .. link) | |||
end | end | ||
table.insert(ret, '|alt=' .. ((altText == nil and '') or altText) .. ']]') | |||
end | end | ||
-- Currency amounts | |||
if tonumber(amount) ~= nil then | |||
local function numColour(amount) | |||
if amount < 0 then | |||
return '<span style="color:red;">' .. formatnum(amount) .. '</span>' | |||
else | |||
return formatnum(amount) | |||
local | end | ||
end | |||
table.insert(ret, ' ' .. numColour(amount)) | |||
if (tonumber(maxAmount) ~= nil and maxAmount > amount) then | |||
table.insert(ret, ' - ' .. numColour(maxAmount)) | |||
table.insert(ret, ' | |||
end | end | ||
end | end | ||
table.insert(ret, '</span>') | table.insert(ret, '</span>') | ||