Module:Main Page

local p = {}

local File = require("Module:File") local Franchise = require("Module:Franchise") local utilsLayout = require("Module:UtilsLayout") local utilsMarkup = require("Module:UtilsMarkup") local utilsString = require("Module:UtilsString") local utilsTable = require("Module:UtilsTable")

local SPINOFF_FAMILIES = { {		name = "Hyrule Warriors", page = "Hyrule Warriors", },	{		name = "Tingle", page = "Tingle (Series)", },	{		name = "BS-X", page = "BS-X", },	{		name = "CD-i", page = "Philips CD-i" }, }

function p.Games(frame) return p.printGames end

function p.printGames local gamesByType = utilsTable.groupBy(Franchise.enumGames, Franchise.type) local main = gamesByType["main"] local remakes = gamesByType["remake"] local spinoffs = gamesByType["spin-off"] -- By default remakes are placed after their originals, so we have to re-sort by release date table.sort(remakes, function(a, b)		local aRelease = Franchise.releaseDate(a)		local bRelease = Franchise.releaseDate(b)		return aRelease < bRelease and aRelease ~= bRelease and aRelease ~= ""	end) main = utilsTable.reverse(main) remakes = utilsTable.reverse(remakes) spinoffs = utilsTable.reverse(spinoffs) local mainTiles = p.printGameContainer(main) local remakeTiles = p.printGameContainer(remakes) local spinoffTiles = p.printSpinoffContainer(spinoffs) local tabData = { {			label = "Main Series", content = mainTiles, },		{			label = "Remakes", content = remakeTiles, },		{			label = "Spin-Offs", content = spinoffTiles }	}	return utilsLayout.tabs(tabData, {		align = "center",		tabOptions = {			stretch = true,		},	}) end

function p.printGameContainer(games) local html = mw.html.create("div"):addClass("gamenav") for _, game in ipairs(games) do		p.addGame(html, game) end return tostring(html) end

function p.printSpinoffContainer(games) local html = mw.html.create("div"):addClass("gamenav") local gamesByFamily = utilsTable.groupBy(games, Franchise.family)

for _, game in ipairs(gamesByFamily[""] or {}) do		p.addGame(html, game) end gamesByFamily[""] = nil

for _, family in ipairs(SPINOFF_FAMILIES) do		html:node(p.printFamily(family, gamesByFamily)) end html = html:done return tostring(html) end

function p.printFamily(family, gamesByFamily) local games = gamesByFamily[family.name] or {} local logo = utilsMarkup.file(family.name .. " Family Tile.png", {		link = family.page,	}) local html = mw.html.create("div"):addClass("gamenav__spin-off-family") html:tag("div") :addClass("spin-off-logo") :wikitext(logo) :done for _, game in ipairs(games) do		p.addGame(html, game) end return tostring(html) end

function p.addGame(html, game) local release = p.printRelease(game) local link = utilsMarkup.link(Franchise.article(game), Franchise.shortName(game)) local tile, tileExists = File.image(game .. " Tile.png", {		link = "",		class = "gamenav__game-img",	}) if tileExists then html:tag("div") :addClass("gamenav__game") :wikitext(release..link..tile) :done end end

function p.printRelease(game) local release = Franchise.releaseDate(game) if utilsString.isEmpty(release) then release = "TBA" else release = release:sub(1, 4) end return utilsMarkup.class("gamenav__game-year", release) end

return p