Module:Media

-- This modules serves as the code for Template:Media. local p = {} local formatting = require("Module:Formatting") local image = require("Module:Image") local tab2 = require("Module:Tab2") local utils = require("Module:Utils")

-- Create the type tabs. function p.CreateTypeTabs(media, mediaTypes) local games = utils.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 = utils.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 = utils.GetGames("all", "canon") local test for key, value in pairs(games) do if not utils.IsEmpty(media[mediaType["typeName"] .. " " .. value]) then if string.sub(media[mediaType["typeName"] .. " " .. value], 1, 5) == "File:" then outputImage = image.PrintImageInfobox(media[mediaType["typeName"] .. " " .. value]) else outputImage = media[mediaType["typeName"] .. " " .. value] end table.insert(tabs, key, {tabName = value, tabCaption = formatting.AbbToGame(value, true), tabContent = outputImage}) end end --Iterates through the games to find the most recent one (default). local mostRecentGame games = utils.GetGames("all", "release") for key, value in pairs(games) do if not utils.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 utils.GetGames lists) local defaultGameKey = utils.FindInList(utils.GetGames("all", "canon"), mostRecentGame) if defaultGameKey == nil then defaultGameKey = 1 end local result = tab2._Main(tabs, defaultGameKey, "bottom", "16%", "310px", "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", "20%", "", "center") return tostring(result) end

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

return p