Module:Gallery List

local p = {}

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

local CATEGORY_INVALID_ARGS = ""

-- Generally the latest remake is the default tab but some remakes don't have enough images uploaded yet local DEFAULT_TAB_BLACKLIST = { ["OoT3D"] = true, ["MM3D"] = true, ["TPHD"] = true, ["SSHD"] = true, }

-- Enhanced ports may have the same assets as the original game -- There's no need to show a separate tab in those cases local ENHANCED_PORTS = { --["FSAE"] = true -- turns out FSAE does have its own sprites }

function p.Main(frame) local args, err = utilsArg.parse(frame:getParent.args, p.Templates["Gallery List"]) local categories = err and err.categoryText or "" local fileType = args.fileType local subjectType = args.subjectType local pagename = mw.title.getCurrentTitle.text

local tabData = {} local defaultTab = 1 for i, game in ipairs(Franchise.enumGames) do		local isListing = utilsString.endsWith(pagename, " in "..Franchise.shortName(game)) local subjects = args[game] if subjects then local gallery, subjectTerms = p.printGallery(subjectType, game, subjects, fileType) table.insert(tabData, {				label = Franchise.display(game),				content = gallery			}) if not DEFAULT_TAB_BLACKLIST[game] then defaultTab = #tabData end if not isListing then frame:expandTemplate({					title = "Location Features/Store",					args = {						feature = subjectType,						game = game,						subjects = table.concat(subjectTerms, ", ")					}				}) for j, remake in ipairs(Franchise.remakes(game)) do					if not args[remake] and not ENHANCED_PORTS[remake] then local gallery, subjectTerms = p.printGallery(subjectType, remake, subjects, fileType) table.insert(tabData, {							label = Franchise.display(remake),							content = gallery,						}) if not DEFAULT_TAB_BLACKLIST[remake] then defaultTab = #tabData end frame:expandTemplate({							title = "Location Features/Store",							args = {								feature = subjectType,								game = remake,								subjects = table.concat(subjectTerms, ", ")							}						}) end end end end end local output = utilsLayout.tabs(tabData, {		default = defaultTab,		tabOptions = {			collapse = true,		},	}) return output, categories end

function p.printGallery(subjectType, game, subjects, fileType) if not fileType then local graphics = Franchise.graphics(game) if subjectType == "Locations" then fileType = "" elseif graphics == "2D" then fileType = "Sprite" else fileType = "Model" end end

local links, terms = List.termList(game, subjects, { link = true }) local galleryEntries = {} for i= 1, #subjects do		local suffix = fileType local startIdx, endIdx, variant = string.find(terms[i], "%s*%[(%w+)]$") if variant then local term = string.sub(terms[i], 1, startIdx-1) terms[i] = Term.fetchTerm(term, game) or term links[i] = Term.link(term, game) if tonumber(variant) then suffix = suffix .. " " .. variant else suffix = variant .. " " .. suffix end end local file = string.format("File:%s %s %s.png", game, terms[i], suffix) local galleryEntry = string.format("%s|%s", file, links[i]) galleryEntries[i] = galleryEntry end galleryEntries = table.concat(galleryEntries, "\n") local gallery = mw.getCurrentFrame:extensionTag({		name = "gallery",		content = galleryEntries,	}) terms = utilsTable.unique(terms) return gallery, terms end

function p.templateData local paramOrder = {1, "fileType"} local params = { [1] = {			name = "subjectType", required = true, type = "string", enum = {"Characters", "Creatures", "Enemies", "Locations", "Items", "Materials", "Objects"}, desc = "The type of subject being listed.", trim = true, nilIfEmpty = true, },		fileType = { type = "string", desc = "Sets a custom filename suffix for gallery entries", },	}	for i, game in ipairs(Franchise.enumGames) do		if Franchise.isCanon(game) then table.insert(paramOrder, game) params[game] = { type = "string", desc = "Comma-separated list of wiki page names referring to subjects in "..Franchise.display(game), trim = true, nilIfEmpty = true, split = true, }		end end return { format = "block", params = params, paramOrder = paramOrder, } end

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

return p