Module:Media

-- This modules serves as the code for Template:Media. local p = {} local utilsCode = require("Module:UtilsCode") local utilsGame = require("Module:UtilsGame") local utilsTable = require("Module:UtilsTable") local image = require("Module:Image") local tab2 = require("Module:Tab2")

-- Create the type tabs. function p.CreateTypeTabs(media, mediaTypes) local games = utilsGame.OrderGames(utilsGame.GetGames("all"), "canon") -- Create the tabs local tabs = {} for mediaTypeKey, mediaTypeValue in pairs(mediaTypes) do		local hasMedia = false for gameKey, gameValue in pairs(games) do if media[mediaTypeValue["typeName"] .. " " .. gameValue] ~= nil then hasMedia = true end end if hasMedia then table.insert(tabs, mediaTypeKey, {tabName = mediaTypeValue["typeName"], tabCaption = mediaTypeValue["typeCaption"], tabContent = p.CreateGameTabs(media, mediaTypeValue)}) end end return tabs end

-- Returns the key of the type tab with the most recent game. function p.GetDefaultTypeTab(media, mediaTypes) local result local games = utilsGame.OrderGames(utilsGame.GetGames("all"), "release") local biggestKeys = {} for mediaTypeKey, mediaTypeValue in pairs(mediaTypes) do		for gameKey, gameValue in pairs(games) do if media[mediaTypeValue["typeName"] .. " " .. gameValue] ~= nil then biggestKeys[mediaTypeKey] = gameKey end end end local biggestValue = 1 local biggestKey = 1 for key, value in pairs(biggestKeys) do		if value > biggestValue then biggestValue = value biggestKey = key end end return biggestKey end

-- Creates game tabs for the media type providen. function p.CreateGameTabs(media, mediaType) local tabs = {} local outputImage -- Iterates through the games to create a tab local games = utilsGame.OrderGames(utilsGame.GetGames("all"), "canon") local test for key, value in pairs(games) do if not utilsCode.IsEmpty(media[mediaType["typeName"] .. " " .. value]) then if string.sub(media[mediaType["typeName"] .. " " .. value], 1, 5) == "File:" then outputImage = image.PrintRescaledDimensions(media[mediaType["typeName"] .. " " .. value], 320, 320) -- Adding category for pages with missing images in their infobox if string.sub(outputImage, 3, 19) == "File:No Image.png" then outputImage = outputImage .. " "				end else outputImage = media[mediaType["typeName"] .. " " .. value] end table.insert(tabs, key, {tabName = value, tabCaption = utilsGame.AbbToGame(value, true), tabContent = outputImage}) end end --Iterates through the games to find the most recent one (default). local mostRecentGame games = utilsGame.OrderGames(utilsGame.GetGames("all"), "release") for key, value in pairs(games) do if not utilsCode.IsEmpty(media[mediaType["typeName"] .. " " .. value]) then if (string.match(media[mediaType["typeName"] .. " " .. value], "No Image.png") == nil) then mostRecentGame = value end end end -- Getting this game's index in the "all", "canon" list, defaulting to 1 in	-- case it's not found (shouldn't happen except if there's an inconsistency	-- between the utilsGame.GetGames lists) local defaultGameKey = utilsTable.keyOf(utilsGame.OrderGames(utilsGame.GetGames("all"), "canon"), mostRecentGame) if defaultGameKey == nil then defaultGameKey = 1 end local result = tab2.Main(tabs, defaultGameKey, "bottom", 5, "100%", "320px", "320px", "center") return tostring(result) end

-- Wrapper for Module calls. function p._Main(media) -- Media types local mediaTypes = {{typeName = "Artwork", typeCaption = "Official artworks provided by Nintendo."}, {typeName = "Render", typeCaption = "Official models provided by Nintendo."}, {typeName = "Model", typeCaption = "Models extracted from games or screenshots."}, {typeName = "Sprite", typeCaption = "In-game sprites or icons."}, {typeName = "Screenshot", typeCaption = "Screenshots taken from in-game."}} -- Create "types" tabs. local tabs = p.CreateTypeTabs(media, mediaTypes) -- Get the default type tab local defaultTypeTab = p.GetDefaultTypeTab(media, mediaTypes) local result = tab2.Main(tabs, defaultTypeTab, "top", 4, "100%", "", "", "center") return tostring(result) end

-- Template:Media function p.Main(frame) local args = frame:getParent.args return p._Main(args) end

return p