Module:Media

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

-- Returns whether media of that type are provided. function p.CheckForType(media, mediaType) local result = false local games = utils.GetGames("all") for key, value in pairs(games) do if media[mediaType .. " " .. value] ~= nil then result = true end end return result end

function p.CreateTypeTab(media, mediaType) local result = {tabName = mediaType, tabContent = p.CreateGameTabs(media, mediaType)} return result end

function p.CreateGameTabs(media, mediaType) local games = utils.GetGames("all") local tabs = {} local outputImage for key, value in pairs(games) do if media[mediaType .. " " .. value] ~= nil then if string.match(media[mediaType .. " " .. value], "File:") ~= nil then outputImage = image.PrintImageInfobox(media[mediaType .. " " .. value]) else outputImage = media[mediaType .. " " .. value] end table.insert(tabs, {tabName = value, tabContent = outputImage}) end end local result = tab2._Main(tabs, 1, "bottom", "", "center") return tostring(result) end

-- Wrapper for Module calls. function p._Main(media) local hasArtworks = p.CheckForType(media, "Artwork") local hasRenders = p.CheckForType(media, "Render") local hasModels = p.CheckForType(media, "Model") local hasSprites = p.CheckForType(media, "Sprite") -- Create "types" tabs. local tabs = {} if hasArtworks then table.insert(tabs, p.CreateTypeTab(media, "Artwork")) end if hasRenders then table.insert(tabs, p.CreateTypeTab(media, "Render")) end if hasModels then table.insert(tabs, p.CreateTypeTab(media, "Model")) end if hasSprites then table.insert(tabs, p.CreateTypeTab(media, "Sprite")) end local result = tab2._Main(tabs, 1, "top", "", "center") return tostring(result) end

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

return p