FANDOM


-- 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 name = data[game]['name']
    return string.format("\'\'[[%s|%s]]\'\'", link, name)
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 onscreen(text)
    return string.format(', on-screen: \'\'%s\'\'', text)
end
 
local function script(game, scriptsection)
    game = string.lower(game)
    local gamename = data[game]['name']
    return string.format(' [[%s script#%s|script &sect; "%s"]]', gamename, scriptsection, scriptsection)
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 == 'tpl' or game == 'jak2' then switchoutput = ', ' .. data[game]['guide'][brand] .. ', p. ' .. page
        else switchoutput = ', ' .. data[game]['guide'] .. ', p. ' .. page end
    else switchoutput = ', ' .. switch
    end
 
    return switchoutput
end
 
-- Produces the cite template.
function cite.main(frame)
	local args = getArgs(frame)
 
  	local gamesec = gamelink((args['game'] or args[1]))
	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']) end
	local switchsec = ''
	if args[2] then switchsec = switchfeatures(args[2], (args['game'] or args[1]), args['version'], args['brand'], args['p']) end
 
	local citeoutput = '{{#tag:ref|' .. gamesec .. missionsec .. filesec .. onscreentextsec .. scriptsec .. switchsec .. '}}'
 
	return frame:preprocess(citeoutput)
end
 
return cite

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.