Module:Databox Credits

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to: navigation, search

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

-- <nowiki>
--------------------------
-- Module for [[Template:Databox Credits]]
------------------------
local p = {}

-- "imports"
local onmain = require('Module:Mainonly').on_main
local infobox = require('Module:Infobox')

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

	ret:defineParams{
		{ name = 'name', func = 'name' },
		
		-- Developers
		{ name = 'developer', func = 'has_content' }, -- Developer
		{ name = 'design', func = 'has_content' }, -- Design
		{ name = 'designreview', func = 'has_content' }, -- Design review
		{ name = 'writing', func = 'has_content' }, -- Writing
		{ name = 'editing', func = 'has_content' }, -- Editing
		{ name = 'codereview', func = 'has_content' }, -- Code review
		{ name = 'conversion', func = 'has_content' }, -- Conversion
		{ name = 'techsupport', func = 'has_content' }, -- Technical Support
		{ name = 'engine', func = 'has_content' }, -- Engine
		{ name = 'bugfixes', func = 'has_content' }, -- Bug Fixes
		{ name = 'devother', func = { name = parseCredit, params = { 'devother' } } }, -- Custom
		
		-- Graphics
		{ name = 'artdirector', func = 'has_content' }, -- Art Director
		{ name = 'ui', func = 'has_content' }, -- UI
		{ name = 'characters', func = 'has_content' }, -- Characters
		{ name = 'environment', func = 'has_content' }, -- Environments
		{ name = 'animation', func = 'has_content' }, -- Animation
		{ name = 'graphics', func = 'has_content' }, -- Graphics
		{ name = 'concept', func = 'has_content' }, -- Concept
		{ name = 'modelling', func = 'has_content' }, -- Modelling
		{ name = 'graphicsother', func = { name = parseCredit, params = { 'graphicsother' } } }, -- Custom
		
		-- QA
		{ name = 'qahead', func = 'has_content' }, -- Head of QA
		{ name = 'qalead', func = 'has_content' }, -- Lead QA
		{ name = 'coretest', func = 'has_content' }, -- Core
		{ name = 'releasetest', func = 'has_content' }, -- Release
		{ name = 'qa', func = 'has_content' }, -- Quality assurance
		{ name = 'qaother', func = { name = parseCredit, params = { 'qaother' } } }, -- Custom
		
		-- Audio
		{ name = 'composition', func = 'has_content' }, -- Composition
		{ name = 'voiceacting', func = 'has_content' }, -- Voice Acting
		{ name = 'audioother', func = { name = parseCredit, params = { 'audioother' } } }, -- Custom
		
		-- Localisation
		{ name = 'german', func = 'has_content' }, -- German
		{ name = 'french', func = 'has_content' }, -- French
		{ name = 'ptbr', func = 'has_content' }, -- Brazillian-Protuguese
		{ name = 'locother', func = { name = parseCredit, params = { 'locother' } } }, -- Custom
		
		-- Other
		{ name = 'walkthrough', func = 'has_content' }, -- Walkthrough
		{ name = 'questhelp', func = 'has_content' }, -- Quest Help
		{ name = 'wiki', func = 'has_content' }, -- Wiki
		{ name = 'knowledgebase', func = 'has_content' }, -- Knowledge Base
		{ name = 'other', func = { name = parseCredit, params = { 'other' } } }, -- Custom
	}

	ret:setMaxButtons(4)
	ret:setAddRSWDataboxClass(true)
	ret:create()
	ret:cleanParams()
	ret:customButtonPlacement(true)
	
	ret:defineLinks({ links = {{ 'Template:%s', 'Databox' },
		{ 'Template_talk:%s', 'Talk page' }}, colspan = '2' })

	ret:defineName('Databox Credits')
	ret:addClass('wikitable')

	ret:addButtonsCaption()

	-- PARAMETER: name
	ret:addRow{
		{ tag = 'argh', content = 'name', colspan = '2', class = 'infobox-header' }
	}

	-- Developers header
	if ret:paramDefined('developer') or ret:paramDefined('design') or ret:paramDefined('designreview') or ret:paramDefined('writing') or ret:paramDefined('editing') or ret:paramDefined('codereview') or 
	ret:paramDefined('conversion') or ret:paramDefined('techsupport') or ret:paramDefined('engine') or ret:paramDefined('bugfixes') or ret:paramDefined('devother') then
		ret:addRow{
			{ tag = 'th', content = 'Developers', colspan = '2', class = 'infobox-header' }
		}
	end

	-- PARAMETER: developer
	if ret:paramDefined('developer') then
		ret:addRow{
			{ tag = 'th', content = 'Developer' },
			{ tag = 'argd', content = 'developer' }
		}
	end
	
	-- PARAMETER: design
	if ret:paramDefined('design') then
		ret:addRow{
			{ tag = 'th', content = 'Design' },
			{ tag = 'argd', content = 'design' }
		}
	end
	
	-- PARAMETER: designreview
	if ret:paramDefined('designreview') then
		ret:addRow{
			{ tag = 'th', content = 'Design review' },
			{ tag = 'argd', content = 'designreview' }
		}
	end
	
	-- PARAMETER: writing
	if ret:paramDefined('writing') then
		ret:addRow{
			{ tag = 'th', content = 'Writing' },
			{ tag = 'argd', content = 'writing' }
		}
	end
	
	-- PARAMETER: editing
	if ret:paramDefined('editing') then
		ret:addRow{
			{ tag = 'th', content = 'Editing' },
			{ tag = 'argd', content = 'editing' }
		}
	end
	
	-- PARAMETER: codereview
	if ret:paramDefined('codereview') then
		ret:addRow{
			{ tag = 'th', content = 'Code review' },
			{ tag = 'argd', content = 'codereview' }
		}
	end
	
	-- PARAMETER: conversion
	if ret:paramDefined('conversion') then
		ret:addRow{
			{ tag = 'th', content = 'Conversion' },
			{ tag = 'argd', content = 'conversion' }
		}
	end
	
	-- PARAMETER: techsupport
	if ret:paramDefined('techsupport') then
		ret:addRow{
			{ tag = 'th', content = 'Technical Support' },
			{ tag = 'argd', content = 'techsupport' }
		}
	end
	
	-- PARAMETER: engine
	if ret:paramDefined('engine') then
		ret:addRow{
			{ tag = 'th', content = 'Engine' },
			{ tag = 'argd', content = 'engine' }
		}
	end
	
	-- PARAMETER: devother
	if ret:paramDefined('devother') then
		for k, v in pairs(ret:param('devother')) do
			ret:addRow{
				{ tag = 'th', content = v['role'] },
				{ tag = 'td', content = v['credit'] }
			}
		end
	end
	
	-- Graphics header
	if ret:paramDefined('artdirector') or ret:paramDefined('ui') or ret:paramDefined('characters') or ret:paramDefined('environment') or ret:paramDefined('animation') or 
	ret:paramDefined('graphics') or ret:paramDefined('concept') or ret:paramDefined('modelling') or ret:paramDefined('graphicsother') then
		ret:addRow{
			{ tag = 'th', content = 'Art & Graphics', colspan = '2', class = 'infobox-header' }
		}
	end
	
	-- PARAMETER: artdirector
	if ret:paramDefined('artdirector') then
		ret:addRow{
			{ tag = 'th', content = 'Art Director' },
			{ tag = 'argd', content = 'artdirector' }
		}
	end
	
	-- PARAMETER: ui
	if ret:paramDefined('ui') then
		ret:addRow{
			{ tag = 'th', content = 'UI' },
			{ tag = 'argd', content = 'ui' }
		}
	end
	
	-- PARAMETER: characters
	if ret:paramDefined('characters') then
		ret:addRow{
			{ tag = 'th', content = 'Characters' },
			{ tag = 'argd', content = 'characters' }
		}
	end
	
	-- PARAMETER: environment
	if ret:paramDefined('environment') then
		ret:addRow{
			{ tag = 'th', content = 'Environments' },
			{ tag = 'argd', content = 'environment' }
		}
	end
	
	-- PARAMETER: animation
	if ret:paramDefined('animation') then
		ret:addRow{
			{ tag = 'th', content = 'Animation' },
			{ tag = 'argd', content = 'animation' }
		}
	end
	
	-- PARAMETER: graphics
	if ret:paramDefined('graphics') then
		ret:addRow{
			{ tag = 'th', content = 'Graphics' },
			{ tag = 'argd', content = 'graphics' }
		}
	end
	
	-- PARAMETER: concept
	if ret:paramDefined('concept') then
		ret:addRow{
			{ tag = 'th', content = 'Concept' },
			{ tag = 'argd', content = 'concept' }
		}
	end
	
	-- PARAMETER: modelling
	if ret:paramDefined('modelling') then
		ret:addRow{
			{ tag = 'th', content = 'Modelling' },
			{ tag = 'argd', content = 'modelling' }
		}
	end
	
	-- PARAMETER: graphicsother
	if ret:paramDefined('graphicsother') then
		for k, v in pairs(ret:param('graphicsother')) do
			ret:addRow{
				{ tag = 'th', content = v['role'] },
				{ tag = 'td', content = v['credit'] }
			}
		end
	end
	
	-- Quality Assurance header
	if ret:paramDefined('qahead') or ret:paramDefined('qalead') or ret:paramDefined('coretest') or ret:paramDefined('releasetest') or ret:paramDefined('qa') or ret:paramDefined('qaother') then
		ret:addRow{
			{ tag = 'th', content = 'Quality Assurance', colspan = '2', class = { 'infobox-header' } }
		}
	end
	
	-- PARAMETER: qahead
	if ret:paramDefined('qahead') then
		ret:addRow{
			{ tag = 'th', content = 'Head of QA' },
			{ tag = 'argd', content = 'qahead' }
		}
	end
	
	-- PARAMETER: qalead
	if ret:paramDefined('qalead') then
		ret:addRow{
			{ tag = 'th', content = 'Lead QA' },
			{ tag = 'argd', content = 'qalead' }
		}
	end
	
	-- PARAMETER: coretest
	if ret:paramDefined('coretest') then
		ret:addRow{
			{ tag = 'th', content = 'Core' },
			{ tag = 'argd', content = 'coretest' }
		}
	end
	
	-- PARAMETER: releasetest
	if ret:paramDefined('releasetest') then
		ret:addRow{
			{ tag = 'th', content = 'Release' },
			{ tag = 'argd', content = 'releasetest' }
		}
	end
	
	-- PARAMETER: leadtest
	if ret:paramDefined('leadtest') then
		ret:addRow{
			{ tag = 'th', content = 'Lead Tester' },
			{ tag = 'argd', content = 'leadtest' }
		}
	end
	
	-- PARAMETER: qa
	if ret:paramDefined('qa') then
		ret:addRow{
			{ tag = 'th', content = 'Quality assurance' },
			{ tag = 'argd', content = 'qa' }
		}
	end
	
	-- PARAMETER: qaother
	if ret:paramDefined('qaother') then
		for k, v in pairs(ret:param('qaother')) do
			ret:addRow{
				{ tag = 'th', content = v['role'] },
				{ tag = 'td', content = v['credit'] }
			}
		end
	end
	
	-- Audio header
	if ret:paramDefined('composition') or ret:paramDefined('voiceacting') or ret:paramDefined('audioother') then
		ret:addRow{
			{ tag = 'th', content = 'Audio', colspan = '2', class = 'infobox-header' }
		}
	end
	
	-- PARAMETER: composition
	if ret:paramDefined('composition') then
		ret:addRow{
			{ tag = 'th', content = 'Composition' },
			{ tag = 'argd', content = 'composition' }
		}
	end
	
	-- PARAMETER: voiceacting
	if ret:paramDefined('voiceacting') then
		ret:addRow{
			{ tag = 'th', content = 'Voice Acting' },
			{ tag = 'argd', content = 'voiceacting' }
		}
	end
	
	-- PARAMETER: audioother
	if ret:paramDefined('audioother') then
		for k, v in pairs(ret:param('audioother')) do
			ret:addRow{
				{ tag = 'th', content = v['role'] },
				{ tag = 'td', content = v['credit'] }
			}
		end
	end
	
	-- Localisation header
	if ret:paramDefined('german') or ret:paramDefined('french') or ret:paramDefined('ptbr') or ret:paramDefined('locother') then
		ret:addRow{
			{ tag = 'th', content = 'Localisation', colspan = '2', class = 'infobox-header' }
		}
	end
	
	-- PARAMETER: german
	if ret:paramDefined('german') then
		ret:addRow{
			{ tag = 'th', content = 'German' },
			{ tag = 'argd', content = 'german' }
		}
	end
	
	-- PARAMETER: french
	if ret:paramDefined('french') then
		ret:addRow{
			{ tag = 'th', content = 'French' },
			{ tag = 'argd', content = 'french' }
		}
	end
	
	-- PARAMETER: ptbr
	if ret:paramDefined('ptbr') then
		ret:addRow{
			{ tag = 'th', content = 'Brazillian-Protuguese' },
			{ tag = 'argd', content = 'ptbr' }
		}
	end
	
	-- PARAMETER: locother
	if ret:paramDefined('locother') then
		for k, v in pairs(ret:param('locother')) do
			ret:addRow{
				{ tag = 'th', content = v['role'] },
				{ tag = 'td', content = v['credit'] }
			}
		end
	end
	
	-- Other header
	if ret:paramDefined('walkthrough') or ret:paramDefined('questhelp') or ret:paramDefined('wiki') or ret:paramDefined('knowledgebase') or ret:paramDefined('other') then
		ret:addRow{
			{ tag = 'th', content = 'Other', colspan = '2', class = 'infobox-header' }
		}
	end
	
	-- PARAMETER: walkthrough
	if ret:paramDefined('walkthrough') then
		ret:addRow{
			{ tag = 'th', content = 'Walkthrough' },
			{ tag = 'argd', content = 'walkthrough' }
		}
	end
	
	-- PARAMETER: questhelp
	if ret:paramDefined('questhelp') then
		ret:addRow{
			{ tag = 'th', content = 'Quest Help' },
			{ tag = 'argd', content = 'questhelp' }
		}
	end
	
	-- PARAMETER: wiki
	if ret:paramDefined('wiki') then
		ret:addRow{
			{ tag = 'th', content = 'Wiki' },
			{ tag = 'argd', content = 'wiki' }
		}
	end
	
	-- PARAMETER: knowledgebase
	if ret:paramDefined('knowledgebase') then
		ret:addRow{
			{ tag = 'th', content = 'Knowledge Base' },
			{ tag = 'argd', content = 'knowledgebase' }
		}
	end
	
	-- PARAMETER: other
	if ret:paramDefined('other') then
		for k, v in pairs(ret:param('other')) do
			ret:addRow{
				{ tag = 'th', content = v['role'] },
				{ tag = 'td', content = v['credit'] }
			}
		end
	end
	
	ret:finish()
	if onmain() then
		local a1 = ret:param('all')
		local a2 = ret:categoryData()
		ret:wikitext(addcategories(a1, a2))
	end
	return ret:tostring()
end

function parseCredit(str)
	local ret = {}
	for u in mw.text.gsplit(str, '%s*;%s*') do
		local v = mw.text.split(u, '%s*:%s*')
		local role = v[1]
		local credit = v[2]
		if role and credit then
			table.insert(ret, { ['role'] = role, ['credit'] = credit })
		end
	end
	return ret
end

function addcategories(args, catargs)
	function is_def(x, y)
		y = y or 'd'
		if infobox.isDefined(x) then
			return infobox.isDefined(x[y])
		end
		return false
	end
	
	local ret = {}
	
	local cat_map = {
		-- Added if the parameter has content
		defined = {
		},
		-- Added if the parameter has no content
		notdefined = {
		},
	}
	
	-- Run and add mapped categories
	for n, v in pairs(cat_map.defined) do
		if catargs[n] and catargs[n].one_defined then
			table.insert(ret,v)
		end
	end
	for n, v in pairs(cat_map.notdefined) do
		if catargs[n] and catargs[n].all_defined == false then
			table.insert(ret,v)
		end
	end
	
	-- combine table and format category wikicode
	for i, v in ipairs(ret) do
		if (v ~= '') then
			ret[i] = string.format('[[Category:%s]]', v)
		end
	end

	return table.concat(ret, '')
end

return p
-- </nowiki>