Module:Franchise List

From Zelda Wiki, the Zelda encyclopedia
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

ParameterStatusDescriptionAccepted values
typerequiredIndicates whether to generate links for main games or spin-off games.
  • main
  • spinoff
linkrequired

A templated article name used to generate a link for each game.

Supported variables include:

Examples

#InputOutput
1
{{#invoke:Franchise List|GameLinks|type= main|link= Enemies in $shortName}}
The Legend of Zelda, The Adventure of Link, A Link to the Past, Link's Awakening (DXNintendo Switch), Ocarina of Time (3D), Majora's Mask, Oracle of Seasons, Oracle of Ages, Four Swords, The Wind Waker, Four Swords Adventures, The Minish Cap, Twilight Princess (HD), Phantom Hourglass, Spirit Tracks, Skyward Sword (HD), A Link Between Worlds, Tri Force Heroes, Breath of the Wild, Tears of the Kingdom
2
{{#invoke:Franchise List|GameLinks|type= spin-off|link= Characters in $shortName}}
The Faces of Evil, The Wand of Gamelon, Zelda's Adventure, Ancient Stone Tablets, Freshly-Picked Tingle's Rosy Rupeeland, Ripened Tingle's Balloon Trip of Love, Hyrule Warriors (Definitive Edition), Cadence of Hyrule, Hyrule Warriors: Age of Calamity
Overriding link for specific entries
3
{{#invoke:Franchise List|GameLinks|type= spin-off|link= Dungeons in $shortName|LCT= Stages in $shortName}}
BS The Legend of Zelda, Zelda's Adventure, Ancient Stone Tablets, Freshly-Picked Tingle's Rosy Rupeeland, Link's Crossbow Training, Cadence of Hyrule
Specifying multiple links per game
4
{{#invoke:Franchise List|GameLinks|type= main|link= Locations in $shortName|FSA= Levels in $shortName, Stages in $shortName}}
The Legend of Zelda, The Adventure of Link, A Link to the Past, Link's Awakening (Nintendo Switch), Ocarina of Time (3D), Majora's Mask, Oracle of Seasons, Oracle of Ages, The Wind Waker, Four Swords Adventures (LevelsStages), The Minish Cap, Twilight Princess, Phantom Hourglass, Spirit Tracks, Skyward Sword, A Link Between Worlds, Tri Force Heroes, Breath of the Wild, Tears of the Kingdom

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