RuneScape Wiki
mNo edit summary
Tag: sourceedit
mNo edit summary
Tag: sourceedit
Line 3: Line 3:
 
 
 
function p.main(frame)
 
function p.main(frame)
local rarity,item,qty,item_page,image
+
local rarity,item,qty,qtyraw,item_page,image
 
local args = frame:getParent().args
 
local args = frame:getParent().args
 
 
Line 10: Line 10:
 
qty = args[3] or 'no'
 
qty = args[3] or 'no'
 
-- item_page= args[4] or item
 
-- item_page= args[4] or item
  +
if qty ~= 'no' then
 
  +
qty = qty:upper():gsub('[^%dKM]','')
  +
qtyraw = qty:gsub('K','000'):gsub('M','000000')
  +
-- Look for 6+ digits
  +
if qty:find('%d%d%d%d%d%d') then
  +
-- replace millions first (10m+)
  +
qty = qty:gsub('^(%d%d%d?%d?)%d%d%d%d%d%d$','%1M')
  +
-- replace thousands next (100k to 9999k)
  +
-- this is ignored if millions are replaced
  +
qty = qty:gsub('^(%d%d%d%d?)%d%d%d$','%1K')
  +
end
  +
end
 
if item:lower() == 'coins' then
 
if item:lower() == 'coins' then
image = coins_image(qty)
+
image = coins_image(qtyraw)
 
else
 
else
 
image = item..'.png'
 
image = item..'.png'

Revision as of 15:55, 4 November 2015

Documentation for this module may be created at Module:Sandbox/doc

local p = {}
local coins_image = require('Module:Coins image')
 
function p.main(frame)
    local rarity,item,qty,qtyraw,item_page,image
    local args = frame:getParent().args
    
    rarity = args[1]
    item = args[2]
    qty = args[3] or 'no'
    -- item_page= args[4] or item
    if qty ~= 'no' then
        qty = qty:upper():gsub('[^%dKM]','')
        qtyraw = qty:gsub('K','000'):gsub('M','000000')
        -- Look for 6+ digits
        if qty:find('%d%d%d%d%d%d') then
            -- replace millions first (10m+)
            qty = qty:gsub('^(%d%d%d?%d?)%d%d%d%d%d%d$','%1M')
            -- replace thousands next (100k to 9999k)
            -- this is ignored if millions are replaced
            qty = qty:gsub('^(%d%d%d%d?)%d%d%d$','%1K')
        end
    end
    if item:lower() == 'coins' then
		image = coins_image(qtyraw)
	else
		image = item..'.png'
	end
    local ret = mw.html.create('div')
        :css({ width = '66px',
                height = '90px',
                position = 'relative' })

    -- Gem container
        :tag('div')
            :css({ width = '66px',
                    height = '90px',
                    position = 'absolute',
                    top = '0px',
                    left = '0px',
                    ['z-index'] = '1' })
            :wikitext(string.format('[[File:Treasure Hunter Gem - %s.png]]',rarity))
        :done()
    -- Item container
        :tag('div')
            :css({ width = '35px',
                    height = '35px',
                    position = 'absolute',
                    bottom = '27px',
                    left = '15px',
                    ['z-index'] = '2' })
            :wikitext(string.format('[[File:%s|35px|link=%s]]',image,item))
        :done()
    if qty ~= 'no' then
        qty = qty:upper():gsub('[^%dKM]','')
        -- Look for 6+ digits
        if qty:find('%d%d%d%d%d%d') then
            -- replace millions first (10m+)
            qty = qty:gsub('^(%d%d%d?%d?)%d%d%d%d%d%d$','%1M')
            -- replace thousands next (100k to 9999k)
            -- this is ignored if millions are replaced
            qty = qty:gsub('^(%d%d%d%d?)%d%d%d$','%1K')
        end
        local font_color
        if qty:find('K') then
            font_color = 'white'
        elseif qty:find('M') then
            font_color = 'green'
        else
            font_color = 'yellow'
        end
        ret:tag('div')
            :css({ position = 'absolute',
                    bottom = '48px',
                    left = '11px',
                    ['z-index'] = '3',
                    ['font-family'] = 'runescape-small',
                    ['font-size'] = '20px',
                    color = font_color,
                    ['text-shadow'] = '1px 1px 0px black' })
            :wikitext(qty)
        :done()
    end

    return tostring(ret)
end

return p