Ratchet & Clank Wiki
Advertisement
This page contains Lua code for Template:Cite.

-- This module implements cite templates.
-- See {{cite}} 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: <code>%s</code>', file)
end

local function script(game, scriptsection, display)
    game = string.lower(game)
    local gamename
    if data[game]['appendix'] then
        gamename = data[game]['title'] .. ' ' .. data[game]['appendix']
    else
        gamename = data[game]['shortname']
    end
    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 menu(game, transcriptsection, display)
    game = string.lower(game)
    local gamename
    if data[game]['appendix'] then
        gamename = data[game]['title'] .. ' ' .. data[game]['appendix']
    else
        gamename = data[game]['shortname']
    end
    if display then
        return string.format(' [' .. '[' .. '%s menu transcript#%s|menu &sect; \"%s\"]]', gamename, transcriptsection, display)
    else
        return string.format(' [' .. '[' .. '%s menu transcript#%s|menu &sect; \"%s\"]]', gamename, transcriptsection, transcriptsection)
    end
end

local function extras(game, extrasection)
    game = string.lower(game)
    local extras = data[game]['extras']
    local extraspage = data[game]['extraspage']
    return string.format(' [' .. '[' .. '%s|%s &sect; \"%s\"]]', extraspage, extras, extrasection)
end

local function museum(game, museumsection)
    game = string.lower(game)
    local museumpage = data[game]['museumpage']
    local museum = data[game]['museum']
    return string.format(' [' .. '[' .. '%s#%s|%s &sect; %s]]', museumpage, museumsection, museum, museumsection)
end

local function tcrf(game, tcrfsection, tcrfpagelink, tcrfpagedesc)
    game = string.lower(game)
    local pagelink
    local pagedesc
    if tcrfpage then
        pagelink = tcrfpagelink
        pagedesc = tcrfpagedesc
    else
        pagelink = data[game]['title']
        pagedesc = 'The Cutting Room Floor entry'
    end
    local title = data[game]['title']
    return string.format('[' .. 'https://tcrf.net/%s#%s|', pagelink, tcrfsection, pagedesc, tcrfsection)
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 menusec = ''
	if args['menu'] then menusec = menu((args['game'] or args[1]), args['menu'], args['display']) end
	    
	local extrasec = ''
	if args['extras'] then extrasec = extras((args['game'] or args[1]), args['extras']) end
	    
	local museumsec = ''
	if args['museum'] then extrasec = museum((args['game'] or args[1]), args['museum']) end
	    
	local tcrfsec = ''
	if args['tcrf'] then extrasec = tcrf((args['game'] or args[1]), args['tcrf'], args['pagelink'], args['pagedesc']) 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 = '<ref' .. refname ..'>' .. gamesec .. missionsec .. filesec .. onscreentextsec .. scriptsec .. menusec .. extrasec .. switchsec .. '</ref>'
	
	return frame:preprocess(citeoutput)
end

return cite
Advertisement