Module:Spawn Locations

local p = {}

local Franchise = require("Module:Franchise") local Term = require("Module:Term") local utilsCargo = require("Module:UtilsCargo") local utilsMarkup = require("Module:UtilsMarkup") local utilsTable = require("Module:UtilsTable")

function p.Main(frame) local pageName = frame:getParent.args[1] or mw.title.getCurrentTitle.subpageText local cargoResults = utilsCargo.query("LocationFeatures", "_pageName, game", {		where = utilsCargo.holdsAny("subjects", {pageName}),		sortBy = "_pageName"	})

local locationsByGame = utilsTable.groupBy(cargoResults, "game") local gameCount = 0 local lastGame for game, results in pairs(locationsByGame) do		local locations = results locations = utilsTable.map(locations, "_pageName") locations = utilsTable.map(locations, function(page)			return Term.link(page, game)		end) -- We should consolidate games and remakes in case the remakes have different enemies at a location -- For now we just ignore remakes if not Franchise.isRemake(game) then locationsByGame[game] = utilsMarkup.list(locations) gameCount = gameCount + 1 lastGame = game else locationsByGame[game] = nil end end

if gameCount == 0 then return "" elseif gameCount == 1 then return locationsByGame[lastGame] else return frame:expandTemplate({			title = "Infobox Game Blocks",			args = locationsByGame,		}) end end

p.Templates = { ["Subject Locations"] = { description = "Lists the locations in which a given character, creature, enemy, item, or material appears.", purpose = " Lists the locations in which a given character, creature, enemy, item, or material appears. It works by listing all pages which have the given subject as an entry in .", usage = "This template is automatically added by Template:Infobox Enemy.", params = { [1] = {				name = "subject", type = "wiki-page-name", default = " ", desc = "A wiki page name. For testing only.", }		},		examples = { {"Green Bokoblin (Archer)"}, {"Skulltula"}, {"Non-Existent Enemy"}, }	} }

return p