Module:Media

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

local mediaTypes = { artwork = {caption = "Artwork", hover = "Official artworks provided by Nintendo."}, render = {caption = "Render", hover = "Official models provided by Nintendo."}, map = {caption = "Map", hover = "In-game map of an area."}, model = {caption = "Model", hover = "In-game models."}, screenshot = {caption = "Screenshot", hover = "In-game screenshots."}, sprite = {caption = "Sprite", hover = "In-game sprites or icons."}, }

-- Create the type tabs. function p.CreateTypeTabs(media, mediaOrder) local games = utilsGame.OrderGames(utilsGame.GetGames("all"), "canon") -- Create the tabs local tabs = {} for mediaKey, mediaValue in pairs(mediaOrder) do		local hasMedia = false for gameKey, gameValue in pairs(games) do if media[mediaValue .. " " .. gameValue] ~= nil then hasMedia = true end end if hasMedia then local tabNameValue = mediaTypes[string.lower(mediaValue)]["caption"] local tabCaptionValue = mediaTypes[string.lower(mediaValue)]["hover"] table.insert(tabs, mediaKey, {tabName = tabNameValue, tabCaption = tabCaptionValue, tabContent = p.CreateGameTabs(media, mediaValue)}) end end return tabs end

-- Returns the key of the type tab with the most recent game. function p.GetDefaultTypeTab(media, mediaOrder) local result local games = utilsGame.OrderGames(utilsGame.GetGames("all"), "release") local biggestKeys = {} for mediaKey, mediaValue in pairs(mediaOrder) do		for gameKey, gameValue in pairs(games) do if media[mediaValue .. " " .. gameValue] ~= nil then biggestKeys[mediaKey] = 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 .. " " .. value]) then if string.sub(media[mediaType .. " " .. value], 1, 5) == "File:" then outputImage = image.PrintRescaledDimensions(media[mediaType .. " " .. value], 320, 320) -- Adding category for pages with missing images in their infobox if string.sub(outputImage, 3, 26) == "File:No Image Upload.png" then local mediaType = utilsMisc.PluralizeFileType(mediaType) local game = utilsGame.AbbToGame(value) outputImage = outputImage .. " "				end else outputImage = media[mediaType .. " " .. 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 .. " " .. value]) then if (string.match(media[mediaType .. " " .. value], "No Image Upload.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", "center") return tostring(result) end

-- Wrapper for Module calls. function p._Main(media) -- Media types local mediaOrder = {"Artwork", "Render", "Model", "Sprite", "Screenshot", "Map", "Screenshots taken from in-game."} -- Create "types" tabs. local tabs = p.CreateTypeTabs(media, mediaOrder) -- Get the default type tab local defaultTypeTab = p.GetDefaultTypeTab(media, mediaOrder) 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

function p._InfoboxCall(frame) local args = frame.args local result = args["image"] if string.sub(args["image"], 1, 5) == "File:" then result = image.PrintRescaledDimensions(args["image"], 320, 320) end return result end

-- BETA FUNCTION, NOT TO BE USED PUBLICLY, NEEDS A LOT OF TINKERING function p._Image360(frame) local args = frame.args return p.Image360(args["image"]) end

function p.Image360(img) local directions = {{header = "⇩", fileDescriptive = ""}, {header = "⇨", fileDescriptive = "Right"}, {header = "⇧", fileDescriptive = "Up"}, {header = "⇦", fileDescriptive = "Left"}} local tabs = {} for key, value in ipairs(directions) do		local tempTable = mw.text.split(img, " ") table.insert(tempTable, #tempTable - 1, value["fileDescriptive"]) local file = table.concat(tempTable, " ") table.insert(tabs, {tabName = value["header"], tabCaption = "", tabContent = image.PrintRescaledDimensions(file, 320, 320)}) end local result = tab2.Main(tabs, 1, "top", 4, "100%", "320px", "320px", "center") return result end

return p