Module:Icons/Sandbox: Difference between revisions

Add red colouring for negative currencies
(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, amt, maxAmt)
function p._Currency(fileName, link, altText, amount, maxAmount)
local amtText = nil
local amountText = nil
if tonumber(amt) ~= nil then
local maxAmountText = nil
amtText = formatnum(amt)
 
if maxAmt ~= nil and maxAmt >= amt then
if tonumber(amount) ~= nil then
amtText = amtText .. ' - ' .. formatnum(maxAmt)
amountText = formatnum(amount)
if (maxAmount ~= nil and maxAmount >= amount) then
maxAmountText = ' - ' .. formatnum(maxAmount)
end
end
end
end
Line 861: Line 863:
end
end


return '<span style="display:inline-block">' .. fileText .. (amtText ~= nil and '&nbsp;' .. amtText or '') .. '</span>'
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;">&nbsp;' .. amountText .. '</span>')
else
-- Otherwise, just add the number as is.
table.insert(ret, '&nbsp;' .. amountText)
end
end
table.insert(ret, maxAmountText or '')
table.insert(ret, '</span>')
return table.concat(ret)
end
end


function p.GP(amt, maxamt)
function p.GP(amount, maxAmount)
return p._Currency('Coins.svg', 'Coins', 'GP', amt, maxamt)
return p._Currency('Coins.svg', 'Coins', 'GP', amount, maxAmount)
end
end


function p.SC(amt, maxamt)
function p.SC(amount, maxAmount)
return p._Currency('Slayer Coins.svg', 'Currency#Slayer Coins', 'SC', amt, maxamt)
return p._Currency('Slayer Coins.svg', 'Currency#Slayer Coins', 'SC', amount, maxAmount)
end
end


function p.RC(amt, maxamt)
function p.RC(amount, maxAmount)
return p._Currency('Raid_Coins.svg', 'Currency#Raid Coins', 'RC', amt, maxamt)
return p._Currency('Raid_Coins.svg', 'Currency#Raid Coins', 'RC', amount, maxAmount)
end
end


918

edits