Module:Main Page: Difference between revisions
Jump to navigation
Jump to search
MannedTooth (talk | contribs) No edit summary |
MannedTooth (talk | contribs) No edit summary |
||
Line 3: | Line 3: | ||
local tab2 = require("Module:Tab2") | local tab2 = require("Module:Tab2") | ||
local utilsCode = require("Module:UtilsCode") | local utilsCode = require("Module:UtilsCode") | ||
local utilsTable = require("Module:UtilsTable") | |||
function p._DisplayGameList(frame) | function p._DisplayGameList(frame) | ||
Line 51: | Line 52: | ||
end | end | ||
end | end | ||
-- Categorizes games in the proper tabs | |||
for key, game in ipairs(games) do | for key, game in ipairs(games) do | ||
local releaseYear = p.FormatReleaseDateYear(game["mainrelease"]) | local releaseYear = p.FormatReleaseDateYear(game["mainrelease"]) | ||
Line 65: | Line 68: | ||
:addClass("game") | :addClass("game") | ||
:wikitext("<span class='year'>" .. releaseYear .. "</span>[[" .. game["name"] .. "|" .. game["subtitle"] .. "]][[File:" .. game["initialism"] .. " Tile.png|link=]]")) | :wikitext("<span class='year'>" .. releaseYear .. "</span>[[" .. game["name"] .. "|" .. game["subtitle"] .. "]][[File:" .. game["initialism"] .. " Tile.png|link=]]")) | ||
end | |||
end | |||
-- Get biggest family size to add padding to smaller ones | |||
local firstLoop = true | |||
local biggestTableLength = 0 | |||
for key, family in ipairs(gameFamilies) do | |||
if firstLoop then | |||
biggestTableLength = #family["games"] | |||
firstLoop = false | |||
end | |||
if #family["games"] > biggestTableLength then | |||
biggestTableLength = #family["games"] | |||
end | end | ||
end | end | ||
-- Generating spin-off families of games | -- Generating spin-off families of games | ||
local familyContainer = mw.html.create("div") | |||
:addClass("family-container") | |||
for key, family in ipairs(gameFamilies) do | for key, family in ipairs(gameFamilies) do | ||
local familyRow = mw.html.create("div") | |||
:addClass(" | :addClass("spin-off-family") | ||
familyRow:node(mw.html.create("div") | |||
:addClass("spin-off-logo") | :addClass("spin-off-logo") | ||
:wikitext("[[File:" .. family["name"] .. " Family Tile.png|link=" .. family["name"] .. "]]")) | :wikitext("[[File:" .. family["name"] .. " Family Tile.png|link=" .. family["name"] .. "]]")) | ||
-- Determine if padding is needed | |||
local paddingNeeded = false | |||
if not (biggestTableLength % 2 == #family["games"] % 2) then | |||
paddingNeeded = true | |||
end | |||
if paddingNeeded then | |||
familyRow:node(mw.html.create("div") | |||
:addClass("spin-off-padding")) | |||
end | |||
for key2, game in ipairs(family["games"]) do | for key2, game in ipairs(family["games"]) do | ||
familyRow:node(mw.html.create("div") | |||
:addClass("game") | :addClass("game") | ||
:wikitext("<span class='year'>" .. p.FormatReleaseDateYear(game["mainrelease"]) .. "</span>[[" .. game["name"] .. "|" .. game["subtitle"] .. "]][[File:" .. game["initialism"] .. " Tile.png|link=]]")) | :wikitext("<span class='year'>" .. p.FormatReleaseDateYear(game["mainrelease"]) .. "</span>[[" .. game["name"] .. "|" .. game["subtitle"] .. "]][[File:" .. game["initialism"] .. " Tile.png|link=]]")) | ||
end | end | ||
if paddingNeeded then | |||
familyRow:node(mw.html.create("div") | |||
:addClass("spin-off-padding")) | |||
end | |||
familyContainer:node(familyRow) | |||
end | end | ||
spinoffs:node(familyContainer) | |||
-- Fill tabs | |||
local tabs = {} | local tabs = {} | ||
table.insert(tabs, 1, {tabName = "Main Series", tabCaption = "", tabContent = tostring(maingames)}) | table.insert(tabs, 1, {tabName = "Main Series", tabCaption = "", tabContent = tostring(maingames)}) | ||
Line 90: | Line 123: | ||
table.insert(tabs, 3, {tabName = "Spin-Offs", tabCaption = "", tabContent = tostring(spinoffs)}) | table.insert(tabs, 3, {tabName = "Spin-Offs", tabCaption = "", tabContent = tostring(spinoffs)}) | ||
-- Displays the result | |||
return tab2.Main(tabs, 1, "top", 3, "", "100%", "", "center") | return tab2.Main(tabs, 1, "top", 3, "", "100%", "", "center") | ||
end | end | ||
-- Only keeps the 4 first digit of a release date, should always return the year | |||
-- If the year provided is empty, it results TBA | |||
function p.FormatReleaseDateYear(release) | function p.FormatReleaseDateYear(release) | ||
local releaseYear = "TBA" | local releaseYear = "TBA" |
Revision as of 07:04, 12 November 2019
Documentation for this module may be created at Module:Main Page/Documentation
local p = {}
local cargo = mw.ext.cargo
local tab2 = require("Module:Tab2")
local utilsCode = require("Module:UtilsCode")
local utilsTable = require("Module:UtilsTable")
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
-- Categorizes games in the proper tabs
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("<span class='year'>" .. releaseYear .. "</span>[[" .. game["name"] .. "|" .. game["subtitle"] .. "]][[File:" .. game["initialism"] .. " Tile.png|link=]]"))
elseif game["type"] == "remake" then
remakes:node(mw.html.create("div")
:addClass("game")
:wikitext("<span class='year'>" .. releaseYear .. "</span>[[" .. game["name"] .. "|" .. game["subtitle"] .. "]][[File:" .. game["initialism"] .. " Tile.png|link=]]"))
elseif game["type"] == "spin-off" and utilsCode.IsEmpty(game["family"]) == true then
spinoffs:node(mw.html.create("div")
:addClass("game")
:wikitext("<span class='year'>" .. releaseYear .. "</span>[[" .. game["name"] .. "|" .. game["subtitle"] .. "]][[File:" .. game["initialism"] .. " Tile.png|link=]]"))
end
end
-- Get biggest family size to add padding to smaller ones
local firstLoop = true
local biggestTableLength = 0
for key, family in ipairs(gameFamilies) do
if firstLoop then
biggestTableLength = #family["games"]
firstLoop = false
end
if #family["games"] > biggestTableLength then
biggestTableLength = #family["games"]
end
end
-- Generating spin-off families of games
local familyContainer = mw.html.create("div")
:addClass("family-container")
for key, family in ipairs(gameFamilies) do
local familyRow = mw.html.create("div")
:addClass("spin-off-family")
familyRow:node(mw.html.create("div")
:addClass("spin-off-logo")
:wikitext("[[File:" .. family["name"] .. " Family Tile.png|link=" .. family["name"] .. "]]"))
-- Determine if padding is needed
local paddingNeeded = false
if not (biggestTableLength % 2 == #family["games"] % 2) then
paddingNeeded = true
end
if paddingNeeded then
familyRow:node(mw.html.create("div")
:addClass("spin-off-padding"))
end
for key2, game in ipairs(family["games"]) do
familyRow:node(mw.html.create("div")
:addClass("game")
:wikitext("<span class='year'>" .. p.FormatReleaseDateYear(game["mainrelease"]) .. "</span>[[" .. game["name"] .. "|" .. game["subtitle"] .. "]][[File:" .. game["initialism"] .. " Tile.png|link=]]"))
end
if paddingNeeded then
familyRow:node(mw.html.create("div")
:addClass("spin-off-padding"))
end
familyContainer:node(familyRow)
end
spinoffs:node(familyContainer)
-- Fill tabs
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)})
-- Displays the result
return tab2.Main(tabs, 1, "top", 3, "", "100%", "", "center")
end
-- Only keeps the 4 first digit of a release date, should always return the year
-- If the year provided is empty, it results TBA
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