Module:Cite

-- This module implements cite templates. -- See for the base template and a documentation. local cite = {} local getArgs = require('Dev:Arguments').getArgs local data = mw.loadData('Module:Codename')

-- Helper functions local function gamelink(game) game = string.lower(game) local link = data[game]['link'] local title = data[game]['title'] local appendix = '' if data[game]['appendix'] then appendix = ' ' .. data[game]['appendix'] end return string.format("[" .. "[" .. "%s|\'\'%s\'\'%s]]", link, title, appendix) end

local function missionlink(mission, display) if display then return string.format(', \"[' .. '[' .. '%s|%s]]\"', mission, display) else return string.format(', \"[' .. '[' .. '%s]]\"', mission) end end

local function gamefile(file) return string.format(', file: ', file) end

local function script(game, scriptsection, display) game = string.lower(game) local gamename = data[game]['link'] if display then return string.format(' [' .. '[' .. '%s script#%s|script &sect; \"%s\"]]', gamename, scriptsection, display) else return string.format(' [' .. '[' .. '%s script#%s|script &sect; \"%s\"]]', gamename, scriptsection, scriptsection) end end

local function extras(game, extrasection) game = string.lower(game) local gamename = (data[game]['shortname'] or data[game]['link']) return string.format(' [' .. '[' .. 'Extras#%s|Extras &sect; \"%s\"]]', gamename, extrasection) end

local function switchfeatures(switch, game, version, brand, page) game = string.lower(game) local switchoutput = '' if switch == 'website' then switchoutput = ', [' .. data[game]['website'] .. ' official website]' elseif switch == 'manual' then switchoutput = ', ' .. data[game]['manual'][version] .. ', p. ' .. page elseif switch == 'guide' then switchoutput = ', ' .. data[game]['guide'] .. ', p. ' .. page else switchoutput = ', ' .. switch end return switchoutput end

-- Produces the cite template. function cite.main(frame) local args = getArgs(frame) local gamesec = '' if (args['game'] or args[1]) then gamesec = gamelink((args['game'] or args[1])) end local missionsec = '' if args['mission'] then missionsec = missionlink(args['mission'], args['display']) end local filesec = '' if args['file'] then filesec = gamefile(args['file']) end local onscreentextsec = '' if args['on-screen'] then onscreentextsec = onscreen(args['on-screen']) end local scriptsec = '' if args['script'] then scriptsec = script((args['game'] or args[1]), args['script'], args['display']) end local extrasec = '' if args['extras'] then extrasec = script((args['game'] or args[1]), args['extras']) end local switchsec = '' if args[2] then switchsec = switchfeatures(args[2], (args['game'] or args[1]), args['version'], args['brand'], args['p']) end local refname = '' if args['name'] then refname = ' name="' .. args['name'] .. '"' end local citeoutput = '' .. gamesec .. missionsec .. filesec .. onscreentextsec .. scriptsec .. extrasec .. switchsec .. ' '	return frame:preprocess(citeoutput) end

return cite