RuneScape Wiki
Advertisement

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

-- <pre>
local p = {}

local coins_image = require('Module:Coins image')

local editbutton = require('Module:Edit button')
local edit = editbutton("'''?''' (edit)")

function p.main(frame)
	local args = frame:getParent().args

	local _args = {}
	for i=1,20 do
		local store = args['store'..i] or ''
		-- stop if nothing
		if not store:find('%S') then
			break
		end

		-- item cost
		local cost = string.lower(args['price'..i] or '')
		if cost == 'free' or cost == '0' or cost == 'sample' then
			cost = 0
		else
			if cost:find('%S') then
				cost = string.gsub(cost,',','')
				cost = tonumber(cost)
				if not cost then
					cost = edit
				end
			else
				cost = edit
			end
		end

		-- currency
		local currency = args['currency'..i] or ''
		if currency:find('%S') and not (string.match(currency:lower(),'^coin')) and cost ~= 0 then
			local currencyimg = args['currencyimg'..i]
			if currencyimg then
				currency = string.format('[[File:%s|link=]]%s ',currencyimg,currency)
			end
		elseif cost == 0 then
			currency = '-'
		else
			currency = string.format('[[File:%s|link=]]%s ',coins_image(tonumber(cost) or 100),'Coins')
		end

		-- base amount in stock
		local stock = args['stock'..i] or ''
		if stock:find('%S') then
			stock = string.gsub(stock,',','')
			stock = tonumber(stock)
			if not stock then
				stock = edit
			end
		else
			stock = edit
		end

		-- members only?
		local mems = string.lower(args['members'..i] or '')
		if mems == 'yes' then
			mems = true
		elseif mems == 'no' then
			mems = false
		else
			mems = 0
		end

		table.insert(_args, { store = store, cost = cost, currency = currency, stock = stock, mems = mems} )
	end

	return p._main(_args)
end

function p._main(args)
	local memsmap = {
		[true] = 'Yes',
		[false] = 'No',
		[0] = edit
	}

	local ret = mw.html.create('table')
			:addClass('wikitable')
			:tag('tr')
				:tag('th')
					:wikitext('Seller')
				:done()
				:tag('th')
					:wikitext('Cost')
				:done()
				:tag('th')
					:wikitext('Currency')
				:done()
				:tag('th')
					:wikitext('Base stock')
				:done()
				:tag('th')
					:wikitext('Members?')
				:done()
			:done()
	for _, v in ipairs(args) do
		local row = ret:tag('tr')
		if v.mems == true then
			row:css('background','#CCC')
		end

		row	:tag('td')
				:wikitext(v.store)
			:done()
			:tag('td')
				:css('text-align','right')
				:wikitext(v.cost)
			:done()
			:tag('td')
				:css('text-align','right')
				:wikitext(v.currency)
			:done()
			:tag('td')
				:css('text-align','right')
				:wikitext(v.stock)
			:done()
			:tag('td')
				:css('text-align','center')
				:wikitext(v.mems)
			:done()
		row:done()
	end

	return ret
end

return p
Advertisement