2,020 Pages

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

-- 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]['pagename']
    local shortname = data[game]['shortname']
    local appendix = ''
    if data[game]['appendix'] then appendix = ' ' .. data[game]['appendix'] end
    return string.format("[" .. "[" .. "%s|\'\'%s\'\'%s]]", link, shortname, 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 unused(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(' [' .. '[Project:Bulletin board/' .. '%s unused dialogue#%s|unused dialogue &sect; \"%s\"]]', gamename, transcriptsection, display)
    else
        return string.format(' [' .. '[Project:Bulletin board/' .. '%s unused dialogue#%s|unused dialogue &sect; \"%s\"]]', gamename, transcriptsection, transcriptsection)
    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|%s &sect; \"%s\"]]', extraspage, extrasection, 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 desc
    if tcrfpagelink then
        pagelink = string.gsub(tcrfpagelink, '%s+', '_')
        desc = tcrfpagedesc
    else
        pagelink = string.gsub(data[game]['title'], '%s+', '_')
        desc = tcrfsection
    end
    local title = data[game]['title']
    return string.format(', [' .. 'https://tcrf.net/%s#%s %s on The Cutting Room Floor]', pagelink, string.gsub(tcrfsection, '%s+', '_'), desc)
end

-- Produces the cite template.
function cite.main(frame)
	local args = getArgs(frame)
	
	local game = args['game'] or args[1]
	
	local gamesec = gamelink(game)
  	
  	local contentsec = ''
  	    
	if args['mission']
	    then contentsec = missionlink(args['mission'], args['display'])
    elseif args['file']
        then contentsec = gamefile(args['file'])
    elseif args['script']
        then contentsec = script(game, args['script'], args['display'])
    elseif args['unused']
        then contentsec = unused(game, args['unused'], args['display'])
    elseif args['menu']
        then contentsec = menu(game, args['menu'], args['display'])
	elseif args['extras']
	    then contentsec = extras(game, args['extras'])
	elseif args['museum']
	    then contentsec = museum(game, args['museum'])
	elseif args['tcrf']
	    then contentsec = tcrf(game, args['tcrf'], args['pagelink'], args['pagedesc'])
	elseif args['guide']
	    then contentsec = ", ''" .. data[game]['guide']['title'] .. "'', p. " .. args['guide']
    elseif args['manual']
        then contentsec = ', ' .. data[game]['manual'][args['region']] .. ', p. ' .. args['manual']
    elseif args[2] or args['other']
        then contentsec = ', ' .. (args[2] or args['other'])
	end
	
	local refname = ''
	if args['name'] then refname = ' name="' .. args['name'] .. '"' end
	
	local citeoutput = '<ref' .. refname ..'>' .. gamesec .. contentsec .. '</ref>'
	
	return frame:preprocess(citeoutput)
end

return cite

--[[Category:Modules]]
Community content is available under CC-BY-SA unless otherwise noted.