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 05:07, 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 won(text, style)
	return ' style="vertical-align: middle; text-align: center; background-color: #9F9;' .. (style or '') .. '" |' .. text
end

local function nom(text, style)
	return ' style="vertical-align: middle; text-align: center; background-color: #FDD;' .. (style or '') .. '" |' .. text
end

local function core(args, i)
	if args['award' .. i] == nil then return end
	local ret

	ret =
		'|- style="background-color: #ddddff;"' .. '\n' ..
		'! style="text-align: center; font-weight: bold;" | ' .. args['award' .. i] .. '\n' ..
		'|' .. won(args['award' .. i ..'W']) .. '\n' ..
		'|' .. nom(args['award' .. i ..'N']) .. '\n'
		
	return ret
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

	ret =
		'{| class="infobox" style="width: 20em; font-size: 90%; vertical-align: middle;"\n' ..
		'|+ style="font-size: 9pt; font-weight: bold;" | List of accolades<i>' .. (args.title and (' received by' .. args.title) or '') .. '</i>\n'
		
	if args.image then
		ret = ret .. '|-\n'
		ret = ret .. '| colspan="3" style="text-align: center;" | ' .. args.image .. '\n' .. (args.caption and ('<div style="display: block;"/>' .. args.caption) or '') .. '\n'
	end
	
	for i = 1, 99 do
		if args['award' .. i] then
			temp = temp .. core(args, i)
			totalW = totalW + args['award' .. i ..'W']
			totalN = totalN + args['award' .. i ..'N']
		end
	end
	
	if temp ~= '' then
		ret = ret ..
			'|-\n' ..
			'| colspan="3" |\n' ..
			'{| class="collapsible collapsed" style="width: 100%;" |\n' ..
			'! colspan=3 style="background-color: #D9E8FF; text-align: center;" | Accolades\n' ..
			'|-\n' ..
			'|- style="background-color: #D9E8FF; font-weight: bold;"\n' ..
			'! style="text-align:center;" | Award\n' ..
			'! style="text-align:center; background: #cceecc; text-size:0.9em; width: 5.8em; | Won\n' ..
			'! style="text-align:center; background: #ffccdd; text-size:0.9em; width: 5.8em;"| Nominated\n' ..
			temp ..
			'|}\n'
	end
	
	if args.totals ~= 'no' then
		local totalW = args.awards or totalW
		local totalN = args.nominations or totalN
		ret = ret ..
			'|- style="background:#d9e8ff; border-spacing: 4px 2px 2px;"\n' ..
			'! style="text-align:center;" colspan="3"| <b>Total number of awards and nominations</b>\n' ..
			'|- style="font-weight: bold;"\n' ..
			'|' .. won('Totals').. '\n' ..
			'|' .. won(tostring(totalW), 'width: 6em;') .. '\n' ..
			'|' .. nom(tostring(totalN), 'width: 6em;') .. '\n'
	end
		
	if args.refsect ~= 'no' then
		ret = ret ..
			'|- style="background:#d9e8ff;"\n' ..
			'| colspan="3" style="font-size: smaller; text-align:center;"| [[#References|Footnotes]]\n' ..
			'|}'
	end
	
	return ret
	
end

return p