Module:Franchise List

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", 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", 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 = ""..remakeDisplay..""							end							local remakeLink = string.format("%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 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 = " A templated article name used to generate a link for each game. Supported variables include:" .."\n* " .."\n* ", }			},			cases = { {					args = { type = "main", link = "Enemies in $shortName", },				},				{					args = { type = "spin-off", link = "Characters in $shortName", },				},				{					desc = "Overriding  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