Module:Gallery List

local p = {}

local Constants = mw.loadData("Module:Constants/Data")

local Franchise = require("Module:Franchise") local Term = require("Module:Term") local utilsLayout = require("Module:UtilsLayout") local utilsPackage = require("Module:UtilsPackage") local utilsString = require("Module:UtilsString") local _utilsError = utilsPackage.lazyLoad("Module:UtilsError")

-- Generally the latest remake should be the default tab but it makes less sense if we have less images for the remake than we do the base game -- These are games for which we don't have enough images yet local DEFAULT_TAB_BLACKLIST = { ["OoT3D"] = true, ["MM3D"] = true, ["TPHD"] = true, ["SSHD"] = true, }

local REMAKE_BLACKLIST = { ["FSAE"] = true -- Aside from its exclusive stages, FSAE has the exact same sprites as FS so there's no point in showing both }

function p.Main(frame) local args = frame:getParent.args local tabData = {} local defaultTab = 1 local errors = {} local categories = "" local seenParams = {} local fileType = args.fileType seenParams["fileType"] = true for i, game in ipairs(Franchise.enumGames) do		local subjects = args[game] seenParams[game] = true if subjects then table.insert(tabData, {				label = Franchise.display(game),				content = p.printGallery(game, subjects, fileType),			}) if not DEFAULT_TAB_BLACKLIST[game] then defaultTab = #tabData end for j, remake in ipairs(Franchise.remakes(game)) do				if not REMAKE_BLACKLIST[remake] then table.insert(tabData, {						label = Franchise.display(remake),						content = p.printGallery(remake, subjects, fileType),					}) if not DEFAULT_TAB_BLACKLIST[remake] then defaultTab = #tabData end end end end end local tabs = utilsLayout.tabs(tabData, {		default = defaultTab,		tabOptions = {			collapse = true,		},	}) for k, v in pairs(args) do		if not seenParams[k] then local errorMessage = string.format("Invalid game ", k)			table.insert(errors, _utilsError.error(errorMessage, true)) categories = categories.."" end end errors = table.concat(errors, "\n") local output = errors..tabs return output, categories end

function p.printGallery(game, subjects, fileType) fileType = fileType or (Franchise.graphics(game) == "2D" and "Sprite" or "Model") subjects = utilsString.split(subjects)

local galleryEntries = {} for i, subject in ipairs(subjects) do		local subjectEnd = string.find(subject, "<") local additionalInfo = "" if subjectEnd then additionalInfo = string.sub(subject, subjectEnd, #subject) subject = string.sub(subject, 1, subjectEnd - 1) if utilsString.endsWith(subject, " ") then subject = utilsString.trim(subject) additionalInfo = " "..additionalInfo end end local term = Term.fetchTerm(subject, game) or subject local text = Term.link(subject, game)..additionalInfo local file = string.format("File:%s %s %s.png", game, term, fileType) local galleryEntry = string.format("%s|%s", file, text) table.insert(galleryEntries, galleryEntry) end galleryEntries = table.concat(galleryEntries, "\n") return mw.getCurrentFrame:extensionTag("gallery", galleryEntries) end

p.Templates = { ["Gallery List"] = {} }

return p