2,875
edits
(Created page with "local Shared = require("Module:Shared") -- Locally index some functions for performance local sgsub, fixPagename, formatnum, tostring, type = string.gsub, Shared.fixPagename, Shared.formatnum, tostring, type local p = {} --Extension overrides for items that have non-png images --Name level overrides take precedence over type level overrides local extOverrides = { ["type"] = { ["skill"] = "svg", ["spellType"] = "svg", ["spell"] = "svg", ["curse"] = "svg", -- So...") |
(Add red colouring for negative currencies) |
||
Line 843: | Line 843: | ||
end | end | ||
function p._Currency(fileName, link, altText, | function p._Currency(fileName, link, altText, amount, maxAmount) | ||
local | local amountText = nil | ||
if tonumber( | local maxAmountText = nil | ||
if | if tonumber(amount) ~= nil then | ||
amountText = formatnum(amount) | |||
if (maxAmount ~= nil and maxAmount >= amount) then | |||
maxAmountText = ' - ' .. formatnum(maxAmount) | |||
end | end | ||
end | end | ||
Line 861: | Line 863: | ||
end | end | ||
local ret = {} | |||
table.insert(ret, '<span style="display:inline-block">') | |||
table.insert(ret, fileText) | |||
if amountText ~= nil then | |||
-- Colour number negative, if it's a number below 0 | |||
local amountNum = tonumber(amount) | |||
if amountNum < 0 then | |||
table.insert(ret, '<span style="color:red;"> ' .. amountText .. '</span>') | |||
else | |||
-- Otherwise, just add the number as is. | |||
table.insert(ret, ' ' .. amountText) | |||
end | |||
end | |||
table.insert(ret, maxAmountText or '') | |||
table.insert(ret, '</span>') | |||
return table.concat(ret) | |||
end | end | ||
function p.GP( | function p.GP(amount, maxAmount) | ||
return p._Currency('Coins.svg', 'Coins', 'GP', | return p._Currency('Coins.svg', 'Coins', 'GP', amount, maxAmount) | ||
end | end | ||
function p.SC( | function p.SC(amount, maxAmount) | ||
return p._Currency('Slayer Coins.svg', 'Currency#Slayer Coins', 'SC', | return p._Currency('Slayer Coins.svg', 'Currency#Slayer Coins', 'SC', amount, maxAmount) | ||
end | end | ||
function p.RC( | function p.RC(amount, maxAmount) | ||
return p._Currency('Raid_Coins.svg', 'Currency#Raid Coins', 'RC', | return p._Currency('Raid_Coins.svg', 'Currency#Raid Coins', 'RC', amount, maxAmount) | ||
end | end | ||
edits