Ratchet & Clank Wiki
No edit summary
m (Reverted edits by ThetaSigma23 (talk) to last revision by Tim H)
Tag: Rollback
(37 intermediate revisions by 3 users not shown)
Line 8: Line 8:
 
local function gamelink(game)
 
local function gamelink(game)
 
game = string.lower(game)
 
game = string.lower(game)
local link = data[game]['link']
+
local link = data[game]['pagename']
local title = data[game]['title']
+
local shortname = data[game]['shortname']
 
local appendix = ''
 
local appendix = ''
 
if data[game]['appendix'] then appendix = ' ' .. data[game]['appendix'] end
 
if data[game]['appendix'] then appendix = ' ' .. data[game]['appendix'] end
return string.format("[" .. "[" .. "%s|\'\'%s\'\'%s]]", link, title, appendix)
+
return string.format("[" .. "[" .. "%s|\'\'%s\'\'%s]]", link, shortname, appendix)
 
end
 
end
   
Line 39: Line 39:
 
else
 
else
 
return string.format(' [' .. '[' .. '%s script#%s|script § \"%s\"]]', gamename, scriptsection, scriptsection)
 
return string.format(' [' .. '[' .. '%s script#%s|script § \"%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 § \"%s\"]]', gamename, transcriptsection, display)
 
else
  +
return string.format(' [' .. '[Project:Bulletin board/' .. '%s unused dialogue#%s|unused dialogue § \"%s\"]]', gamename, transcriptsection, transcriptsection)
 
end
 
end
 
end
 
end
Line 61: Line 76:
 
local extras = data[game]['extras']
 
local extras = data[game]['extras']
 
local extraspage = data[game]['extraspage']
 
local extraspage = data[game]['extraspage']
return string.format(' [' .. '[' .. '%s|%s § \"%s\"]]', extraspage, extras, extrasection)
+
return string.format(' [' .. '[' .. '%s#%s|%s § \"%s\"]]', extraspage, extrasection, extras, extrasection)
 
end
 
end
   
 
local function museum(game, museumsection)
 
local function museum(game, museumsection)
 
game = string.lower(game)
 
game = string.lower(game)
local museumpage = (data[game]['museumpage'])
+
local museumpage = data[game]['museumpage']
local museum = (data[game]['museum'])
+
local museum = data[game]['museum']
 
return string.format(' [' .. '[' .. '%s#%s|%s § %s]]', museumpage, museumsection, museum, museumsection)
 
return string.format(' [' .. '[' .. '%s#%s|%s § %s]]', museumpage, museumsection, museum, museumsection)
 
end
 
end
   
local function switchfeatures(switch, game, version, brand, page)
+
local function tcrf(game, tcrfsection, tcrfpagelink, tcrfpagedesc)
 
game = string.lower(game)
 
game = string.lower(game)
+
local pagelink
local switchoutput = ''
+
local desc
  +
if tcrfpagelink then
 
  +
pagelink = string.gsub(tcrfpagelink, '%s+', '_')
if switch == 'website'
 
  +
desc = tcrfpagedesc
then switchoutput = ', [' .. data[game]['website'] .. ' official website]'
 
 
else
elseif switch == 'manual'
 
then switchoutput = ', ' .. data[game]['manual'][version] .. ', p. ' .. page
+
pagelink = string.gsub(data[game]['title'], '%s+', '_')
elseif switch == 'guide'
+
desc = tcrfsection
then switchoutput = ', ' .. data[game]'guide' .. ', p. ' .. page
 
else switchoutput = ', ' .. switch
 
 
end
 
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)
return switchoutput
 
 
end
 
end
   
Line 92: Line 105:
 
local args = getArgs(frame)
 
local args = getArgs(frame)
 
 
local gamesec = ''
+
local game = args['game'] or args[1]
  +
if (args['game'] or args[1]) then gamesec = gamelink((args['game'] or args[1])) end
 
  +
local gamesec = gamelink(game)
  +
 
local contentsec = ''
 
 
  +
if args['mission']
local missionsec = ''
 
if args['mission'] then missionsec = missionlink(args['mission'], args['display']) end
+
then contentsec = missionlink(args['mission'], args['display'])
  +
elseif args['file']
 
 
then contentsec = gamefile(args['file'])
local filesec = ''
 
  +
elseif args['script']
if args['file'] then filesec = gamefile(args['file']) end
 
 
then contentsec = script(game, args['script'], args['display'])
 
  +
elseif args['unused']
local onscreentextsec = ''
 
if args['on-screen'] then onscreentextsec = onscreen(args['on-screen']) end
+
then contentsec = unused(game, args['unused'], args['display'])
  +
elseif args['menu']
 
  +
then contentsec = menu(game, args['menu'], args['display'])
local scriptsec = ''
 
  +
elseif args['extras']
if args['script'] then scriptsec = script((args['game'] or args[1]), args['script'], args['display']) end
 
 
then contentsec = extras(game, args['extras'])
 
  +
elseif args['museum']
local menusec = ''
 
if args['menu'] then menusec = menu((args['game'] or args[1]), args['menu'], args['display']) end
+
then contentsec = museum(game, args['museum'])
  +
elseif args['tcrf']
 
  +
then contentsec = tcrf(game, args['tcrf'], args['pagelink'], args['pagedesc'])
local extrasec = ''
 
  +
elseif args['guide']
if args['extras'] then extrasec = extras((args['game'] or args[1]), args['extras']) end
 
 
then contentsec = ", ''" .. data[game]['guide']['title'] .. "'', p. " .. args['guide']
 
 
elseif args['manual']
local museumsec = ''
 
if args['museum'] then extrasec = museum((args['game'] or args[1]), args['museum']) end
+
then contentsec = ', ' .. data[game]['manual'][args['region']] .. ', p. ' .. args['manual']
  +
elseif args[2] or args['other']
 
  +
then contentsec = ', ' .. (args[2] or args['other'])
local switchsec = ''
 
  +
end
if args[2] then switchsec = switchfeatures(args[2], (args['game'] or args[1]), args['version'], args['brand'], args['p']) end
 
  +
 
 
local refname = ''
 
local refname = ''
 
if args['name'] then refname = ' name="' .. args['name'] .. '"' end
 
if args['name'] then refname = ' name="' .. args['name'] .. '"' end
 
 
local citeoutput = '<ref' .. refname ..'>' .. gamesec .. missionsec .. filesec .. onscreentextsec .. scriptsec .. menusec .. extrasec .. switchsec .. '</ref>'
+
local citeoutput = '<ref' .. refname ..'>' .. gamesec .. contentsec .. '</ref>'
 
 
 
return frame:preprocess(citeoutput)
 
return frame:preprocess(citeoutput)
Line 128: Line 144:
   
 
return cite
 
return cite
  +
  +
--[[Category:Modules]]

Revision as of 09:34, 30 August 2020

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]['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]]