Module:Main Page

local p = {} local cargo = mw.ext.cargo local tab2 = require("Module:Tab2") local utilsCode = require("Module:UtilsCode")

function p._DisplayGameList(frame) return p.DisplayGameList end

function p.DisplayGameList -- Get all stored games local tables = "Games" local fields = "name, subtitle, initialism, mainrelease, type, family, canonicity" local args = { orderBy = "mainrelease DESC" }	local games = cargo.query(tables, fields, args) -- Generate tabs local maingames = mw.html.create("div") :addClass("game-container main-games") local remakes = mw.html.create("div") :addClass("game-container remakes") local spinoffs = mw.html.create("div") :addClass("game-container spin-offs") -- Create a table of game families local gameFamilies = {} for key, game in ipairs(games) do		-- Check if the game belongs to a family if not utilsCode.IsEmpty(game["family"]) then local familyExists = false --Check if it exists for key2, family in ipairs(gameFamilies) do				if family["name"] == game["family"] then familyExists = true end end -- If the family doesn't exist, create it first if familyExists == false then table.insert(gameFamilies, { name = game["family"], games= {} }) end -- Add the game to the family for key2, family in ipairs(gameFamilies) do				if family["name"] == game["family"] then table.insert(family["games"], game) end end end end for key, game in ipairs(games) do		local releaseYear = p.FormatReleaseDateYear(game["mainrelease"]) if game["type"] == "main" then maingames:node(mw.html.create("div")				:addClass("game")				:wikitext(" " .. releaseYear .. " " .. game["subtitle"] .. "")) elseif game["type"] == "remake" then remakes:node(mw.html.create("div")				:addClass("game")				:wikitext(" " .. releaseYear .. " " .. game["subtitle"] .. "")) elseif game["type"] == "spin-off" and utilsCode.IsEmpty(game["family"]) == true then spinoffs:node(mw.html.create("div")				:addClass("game")				:wikitext(" " .. releaseYear .. " " .. game["subtitle"] .. "")) end end -- Generating spin-off families of games for key, family in ipairs(gameFamilies) do		spinoffs:node(mw.html.create("div")			:addClass("flex-line-break")) local familyContainer = mw.html.create("div") :addClass("family-container") familyContainer:node(mw.html.create("div")			:addClass("spin-off-logo")			:wikitext("")) for key2, game in ipairs(family["games"]) do			familyContainer:node(mw.html.create("div")				:addClass("game")				:wikitext(" " .. p.FormatReleaseDateYear(game["mainrelease"]) .. " " .. game["subtitle"] .. "")) end spinoffs:node(familyContainer) end local tabs = {} table.insert(tabs, 1, {tabName = "Main Series", tabCaption = "", tabContent = tostring(maingames)}) table.insert(tabs, 2, {tabName = "Remakes", tabCaption = "", tabContent = tostring(remakes)}) table.insert(tabs, 3, {tabName = "Spin-Offs", tabCaption = "", tabContent = tostring(spinoffs)}) return tab2.Main(tabs, 1, "top", 3, "", "100%", "", "center") end

function p.FormatReleaseDateYear(release) local releaseYear = "TBA" if not utilsCode.IsEmpty(release) then releaseYear = string.sub(release, 1, 4) end return releaseYear end

return p