Module:Combat level

-- -- -- Implements and -- -- @notes When this template is used in sortable tables it requires a custom parser --       See MediaWiki:Common.js for it's implementation --

local p = {} local commas = require( 'Module:Addcommas' ) local num = require( 'Module:Number' )

-- -- -- function p.calc( frame ) local args = frame:getParent.args -- for or     local a = args[1] or args['Amount'] or args['amount'] return p._amount( a ) end

-- -- -- function p.rusty( frame ) local args = frame:getParent.args local a = args[1] or args['Amount'] or args['amount'] return p._amount( a, true ) end

function p._amount ( a, rusty )

local a = tostring( a ) or '0' local color = 'green' local img = '1'

-- strip commas from input for things like -- which returns the price formatted with commas a = commas._strip( a )

-- dirty way of replicating #expr for the short term -- should be able to be replaced by backporting --  --   -- only do this if required so as not to impact performance too much if tonumber( a ) == nil then a = mw.getCurrentFrame:preprocess( '' ) if tonumber( a ) == nil then a = '0' end end

-- round to 2 d.p.   a = num._round( tonumber( a ), 2 )

-- set the color -- blue for positive, red for negative, green for zero if a > 0 then -- blue color = '#014cc0' elseif a < 0 then -- red color = '#c02614' end

-- set the coins image local num = math.abs( a ) local amounts = { 1000, 250, 100, 25, 5, 4, 3, 2 } for _, v in pairs( amounts ) do       if num >= v then img = tostring( v ) break end end

if not rusty then img = '' else img = '' end

-- format the number with commas a = commas._add( a )

-- create span tag local span = mw.html.create( 'span' ) span :addClass( 'coins-templ' ) :css( {           ['white-space'] = 'nowrap',            ['color'] = color        } ) :wikitext( img .. ' ' .. a )

return tostring( span )

end

return p