Module:Franchise List
Jump to navigation
Jump to search
This module generates lists based on the entries in Data:Franchise.
This module exports the following functions.GameLinks
{{#invoke:Franchise List|GameLinks|type=|link=}}
Creates a list of links for each game in Data:Franchise, for use in navbox templates.
Parameters
Parameter | Status | Description | Accepted values |
---|---|---|---|
type | required | Indicates whether to generate links for main games or spin-off games. |
|
link | required | A templated article name used to generate a link for each game. Supported variables include: |
Examples
local p = {}
local h = {}
local Franchise = require("Module:Franchise")
local utilsPage = require("Module:UtilsPage")
local utilsString = require("Module:UtilsString")
function p.GameLinks(frame)
local args = frame.args
local links = {}
for i, gameCode in ipairs(Franchise.enumGames()) do
if Franchise.type(gameCode) == args.type and not Franchise.isRemake(gameCode) then
local link = args[gameCode] or args.link
local linkTemplates = utilsString.split(link)
if #linkTemplates > 1 then
local overrideLinks = {}
for i, linkTemplate in ipairs(linkTemplates) do
local pageOverride = h.interpolate(linkTemplate, {
article = Franchise.article(gameCode),
shortName = Franchise.shortName(gameCode),
})
local pageOverrideDisplay = pageOverride
-- Display only the unique part when there are multiple overrides rather than repeating the game title
-- e.g. FSA= Levels in $shortName, Stages in $shortName -> ''Four Swords Adventures'' (Levels ◦ Stages)
-- HWAoC= Items in $shortName, Weapons in $shortName -> ''Hyrule Warriors: Age of Calamity'' (Items ◦ Weapons)
local pageOverrideDisplay = string.gsub(pageOverrideDisplay, " in .+$", "")
local overrideLink = string.format("[[%s|%s]]", pageOverride, pageOverrideDisplay)
table.insert(overrideLinks, overrideLink)
end
overrideLinks = table.concat(overrideLinks, " ◦ ")
link = string.format("%s (%s)", Franchise.display(gameCode), overrideLinks)
table.insert(links, link)
else
local page = h.interpolate(link, {
article = Franchise.article(gameCode),
shortName = Franchise.shortName(gameCode),
})
if utilsPage.exists(page) then
local link = string.format("[[%s|%s]]", page, Franchise.display(gameCode))
local remakeLinks = {}
for i, remake in ipairs(Franchise.remakes(gameCode)) do
local link = args[remake] or args.link
local remakePage = h.interpolate(link, {
article = Franchise.article(remake),
shortName = Franchise.shortName(remake),
})
if utilsPage.exists(remakePage) then
-- Display only the suffix for remakes (remake name minus original name minus leading/trailing punctuation)
-- e.g. ''Link's Awakening'' (Nintendo Switch) -> Nintendo Switch
-- ''Hyrule Warriors: Definitive Edition'' -> ''Definitive Edition''
local remakeDisplay = string.gsub(Franchise.shortName(remake), Franchise.shortName(gameCode), "")
remakeDisplay = string.gsub(remakeDisplay, "^[%s(:]+", "")
if string.find(remakeDisplay, "%)$") then
remakeDisplay = string.gsub(remakeDisplay, "%)$", "")
else
remakeDisplay = "<i>"..remakeDisplay.."</i>"
end
local remakeLink = string.format("[[%s|%s]]", remakePage, remakeDisplay)
table.insert(remakeLinks, remakeLink)
end
end
if #remakeLinks > 0 then
remakeLinks = table.concat(remakeLinks, " ◦ ")
link = string.format("%s (%s)", link, remakeLinks)
end
table.insert(links, link)
end
end
end
end
return table.concat(links, ", ")
end
function h.interpolate(formatStr, vars)
return string.gsub(formatStr, "\$%S+", function(templateVar)
return vars[templateVar:sub(2)]
end)
end
function p.Documentation(frame)
return {
GameLinks = {
desc = "Creates a list of links for each game in [[Data:Franchise]], for use in [[:Category:Navbox templates|navbox templates]].",
frameParamsOrder = {"type", "link"},
frameParams = {
type = {
required = true,
enum = {"main", "spinoff"},
desc = "Indicates whether to generate links for main games or spin-off games.",
},
link = {
required = true,
desc = "<p>A templated article name used to generate a link for each game.<p><p>Supported variables include:"
.."\n*<code>$[[Module:Franchise#article_2|article]]</code>"
.."\n*<code>$[[Module:Franchise#shortName_2|shortName]]</code>",
}
},
cases = {
{
args = {
type = "main",
link = "Enemies in $shortName",
},
},
{
args = {
type = "spin-off",
link = "Characters in $shortName",
},
},
{
desc = "Overriding <code>link</code> for specific entries",
args = {
type = "spin-off",
link = "Dungeons in $shortName",
LCT = "Stages in $shortName",
}
},
{
desc = "Specifying multiple links per game",
args = {
type = "main",
link= "Locations in $shortName",
FSA = "Levels in $shortName, Stages in $shortName",
}
},
}
}
}
end
return p