Jump to content

Module:Infobox video game awards

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 風中的刀劍 (talk | contribs) at 06:36, 6 January 2016. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

require('Module:No globals')

local getArgs = require('Module:Arguments').getArgs
local p = {}

local function award(builder, text)
	builder:tag('th')
		:css('vertical-align', 'middle')
		:css('background-color', '#D9E8FF')
		:css('text-align', 'center')
		:wikitext(text)
end

local function won(builder, text)
	builder:tag('td')
		:css('vertical-align', 'middle')
		:css('text-align', 'center')
		:css('background-color', '#9F9')
		:wikitext(text)
end			

local function nom(builder, text)
	builder:tag('td')
		:css('vertical-align', 'middle')
		:css('text-align', 'center')
		:css('background-color', '#FDD')
		:wikitext(text)
end	

local function row(builder, args, i)
	builder = builder:tag('tr')
	award(builder, args['award' .. i])
	won(builder, args['award' .. i ..'W'] or 0)
	nom(builder, args['award' .. i ..'N'] or 0)
end

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	-- Main module code goes here.
	local ret, temp
	local totalW, totalN = 0, 0
	
-- Award list begin
	for i = 1, 99 do
		if args['award' ..i] then
			temp = ''
			break
		end
	end
	
	if temp then
		temp = mw.html.create('table')
			:attr('class', 'collapsible collapsed')
			:css('width', '100%')
			
		temp:tag('tr'):tag('th')
			:attr('colspan', '3')
			:css('background-color', '#D9E8FF')
			:css('text-align', 'center')
			:wikitext('Accolades')
			
		temp:tag('tr')
			:css('background-color', '#D9E8FF')
				:tag('th')
				:wikitext('Award')
				:css('text-align', 'center')
				:done()
			:tag('th')
				:css('background-color', '#cec')
				:css('text-size', '0.9em')
				:css('width', '5.8em')	
				:css('text-align', 'center')
				:wikitext('Won')
				:done()
			:tag('th')
				:css('background-color', '#fcd')
				:css('text-size', '0.9em')
				:css('width', '5.8em')
				:css('text-align', 'center')
				:wikitext('Nominated')
				:done()
				
		for i = 1, 99 do
			if args['award' .. i] then
				row(temp, args, i)
				totalW = totalW + (args['award' .. i ..'W'] or 0)
				totalN = totalN + (args['award' .. i ..'N'] or 0)
			end
		end
	end

-- Award list end

	ret = mw.html.create('table')
		:attr('class', 'infobox')
		:css('width', '20em')
		:css('font-size', '90%')
		:css('vertical-align', 'align')
		
	ret:tag('caption')
		:css('font-size', '9pt')
		:wikitext('List of accolades<i>' .. (args.title and (' received by' .. args.title) or '') .. '</i>')
		:done()

	if args.image then
		ret:tag('tr'):tag('td')
			:attr('colspan', '3')
			:css('text-align', 'center')
			:wikitext(args.image .. (args.caption and ('<div style="display: block;"/>' .. args.caption) or ''))
			:done():done()
	end

	if temp then
		ret:tag('tr'):tag('td')
			:attr('colspan', '3')
			:wikitext(tostring(temp))
			:done():done()
	end
		
	if args.totals ~= 'no' then
		local totalW = args.awards or totalW
		local totalN = args.nominations or totalN
		
		ret:tag('tr')
			:css('background-color', '#d9e8ff')
			:css('border-spacing', '4px 2px 2px')
			:tag('th')
				:attr('colspan', '3')
				:css('text-align', 'center')
				:wikitext('Total number of awards and nominations')
				:done()
			:done()
			
		ret:tag('tr')
			:css('font-weight', 'bold')
			:tag('th')
				:css('vertical-align', 'middle')
				:css('text-align', 'center')
				:css('background-color', '#9F9')
				:wikitext('Total')
				:done()
			:tag('td')
				:css('vertical-align', 'middle')
				:css('text-align', 'center')
				:css('background-color', '#9F9')
				:css('width', '5.9em')
				:wikitext(totalW)
				:done()
			:tag('td')
				:css('vertical-align', 'middle')
				:css('text-align', 'center')
				:css('background-color', '#FDD')
				:css('width', '5.9em')
				:wikitext(totalN)
				:done()
			:done()
	end
	
	if args.reflink ~= 'no' then
		ret:tag('tr'):tag('td')
			:css('vertical-align', 'middle')
			:css('text-align', 'center')
			:css('font-size', 'small')
			:wikitext('[[#References|Footnotes]]')
	end
	
	return ret
	
end

return p