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'] return string.format("\'\'[" .. "[" .. "%s|%s]]\'\'", link, title) 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 onscreen(text) return string.format(', on-screen: \'\'%s\'\'', text) end

local function script(game, scriptsection, display) game = string.lower(game) local gamename = data[game]['title'] 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 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 if game == 'gameexception1' or game == 'gameexception2' then switchoutput = ', ' .. data[game]['guide'][brand] .. ', p. ' .. page --else switchoutput = ', ' .. data[game]['guide'] .. ', p. ' .. page end 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 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 .. switchsec .. ' '	return frame:preprocess(citeoutput) end

return cite