Module:DropsLineTH

-- -- Implements Template:DropsLineTH -- TODO: Implement Module:Exchange when it goes live Remove 'frame' from main arguments, only need it to expand a template local p = {} local params = require('Module:Paramtest') local commas = require('Module:Addcommas') local get_price = require('Module:Exchange')._price

local images = { agility = {image='Agility-icon',link='Agility'}, attack = {image='Attack-icon',link='Attack'}, constitution = {image='Constitution-icon',link='Constitution'}, construction = {image='Construction-icon',link='Construction'}, cooking = {image='Cooking-icon',link='Cooking'}, crafting = {image='Crafting-icon',link='Crafting'}, defence = {image='Defence-icon',link='Defence'}, divination = {image='Divination-icon',link='Divination'}, dungeoneering = {image='Dungeoneering-icon',link='Dungeoneering'}, farming = {image='Farming-icon',link='Farming'}, firemaking = {image='Firemaking-icon',link='Firemaking'}, fishing = {image='Fishing-icon',link='Fishing'}, fletching = {image='Fletching-icon',link='Fletching'}, herblore = {image='Herblore-icon',link='Herblore'}, hunter = {image='Hunter-icon',link='Hunter'}, magic = {image='Magic-icon',link='Magic'}, mining = {image='Mining-icon',link='Mining'}, prayer = {image='Prayer-icon',link='Prayer'}, ranged = {image='Ranged-icon',link='Ranged'}, runecrafting = {image='Runecrafting-icon',link='Runecrafting'}, slayer = {image='Slayer-icon',link='Slayer'}, smithing = {image='Smithing-icon',link='Smithing'}, strength = {image='Strength-icon',link='Strength'}, summoning = {image='Summoning-icon',link='Summoning'}, thieving = {image='Thieving-icon',link='Thieving'}, woodcutting = {image='Woodcutting-icon',link='Woodcutting'}, lucky = {image='Lucky icon'}, extra = {image='Extras item icon'}, extras = {image='Extras item icon'}, cosmetic = {image='Cosmetic item icon'}, ['cosmetic items'] = {image='Cosmetic item icon'}, useful = {image='Useful Item icon'}, ['useful items'] = {image='Useful Item icon'}, ['super rare'] = {image='Super Rare icon'}, prismatic = {image='Prismatic item icon'}, promotional = {image='Promotional icon'}, varies = {'Varies'} }

local rarity_colors = { common = '#C5D0DF', ['fairly common'] = '#D5D110', ['f. common'] = '#D5D110', uncommon = '#CA9402', rare = '#C10808', ['very rare'] = '#8B0093', lucky = '#8B0093' }

function p.main(frame) local args = frame:getParent.args local name = args.Name or 'item' local rarity,raritynotes, quantity,convert, name_notes,gemw = params.defaults{ {args.Rarity,nil}, {args.Raritynotes,nil}, {args.Quantity,'Unknown'}, {args.convert,'Unknown'}, {args.Namenotes,nil}, {args.gemw,'gemw'} }	if rarity then rarity = rarity:gsub('[Ff]airly%s','F. ') end if convert and convert:find('%d') then convert = commas._add(convert) if mw.ustring.find(convert,'[-–]') then convert = mw.ustring.gsub(convert,'–','-') local convs = mw.text.split(convert,'%s*-%s*') convert = convs[1]..'–'..convs[2] end end if not quantity or quantity:find('[Uu]nknown') then quantity = {nil} elseif mw.ustring.find(quantity,'[-–]') then mw.ustring.gsub(quantity,'–','-') local qtys = mw.text.split(quantity,'%s*-%s*') quantity = { tonumber(qtys[1]), tonumber(qtys[2]) } else quantity = commas._strip(quantity) quantity = { tonumber(quantity) } end

local category = args.category or ''

local image

if gemw:lower == 'no' then if args.Image then image = args.Image else image = name..'.png' end else image = name..'.png' end

return p._main{ name, name_notes, image, gemw, quantity, rarity, raritynotes, convert, category, frame } end

function p._main(...) local name,namenotes, image,gemw, quantity, rarity,raritynotes, convert,category, frame = unpack(...)

local price if gemw:lower == 'no' then price = 'Not sold' else price = get_price(name) if #quantity == 1 then price = commas._add(price * quantity[1]) elseif #quantity == 2 then price = commas._add(price * quantity[1])..'–'..commas._add(price * quantity[2]) end end if image then image = '' else image = '' end name = ..name.. if namenotes then name = name..' '..namenotes end local qtytext if #quantity == 1 then if quantity[1] then qtytext = commas._add(quantity[1]) else qtytext = 'Unknown' end elseif #quantity == 2 then qtytext = commas._add(quantity[1])..'–'..commas._add(quantity[2]) else qtytext = 'Unknown' end

local rare_bg, rare_color if rarity and rarity_colors[string.lower(rarity)] then rare_bg = rarity_colors[string.lower(rarity)] if string.lower(rarity) == 'rare' or			string.lower(rarity) == 'very rare' then rare_color = '#FFFFFF' else rare_color = '#000000' end if raritynotes then rarity = rarity..' '..raritynotes end else rare_bg = '#FFFFFF' rarity = 'Unknown' end local catimg = images[category:lower] if catimg and catimg.image then catimg = '' elseif catimg then catimg = 'Varies' else catimg = '' end

local ret = mw.html.create('tr') :tag('td') :wikitext(image) :done :tag('td') :css('text-align','left') :wikitext(name) :done :tag('td') :wikitext(qtytext) :done :tag('td') :css({ background = rare_bg,						color = rare_color }) :wikitext(rarity) :done :tag('td') :wikitext(price) :done :tag('td') :wikitext(convert) :done :tag('td') :wikitext(catimg) :done :done return ret end

return p