Module:Environments

---	Environments contains details of Risk of Rain 2's environments. --	--	@module		enemies --	@alias		p --	@author		User:Thundermaker300 --	@attribution	All who helped to update enemy infoboxes --	@require	Module:Environments/Data --	@release	stable --

local EnvData = mw.loadData('Module:Environments/Data').Environments

local p = {} table.unpack = unpack	-- pre-Lua 5.3 table library does not have unpack function

function pairsByKeys (t, f) -- Sort tables, copied from https://www.lua.org/pil/19.3.html local a = {} for n in pairs(t) do table.insert(a, n) end table.sort(a, f) local i = 0      -- iterator variable local iter = function   -- iterator function i = i + 1 if a[i] == nil then return nil else return a[i], t[a[i]] end end return iter end

---	Builds a template for an environment's expansion. --	@function		p.EnvironmentExpansion --	@param			{table} frame Frame object --	@return			{string} Preprocessed wikitext of expansion template. function p.EnvironmentExpansion(frame) local data = EnvData[frame.args[1]] if data == nil then return "" end return data.Expansion and frame:preprocess("") or "" end

function listDisplay(monsterName, note, family, isSub) -- handle children cases (beetle queen, gup, solus probe) local stars = "**" .. (isSub and "*" or "") local str = "* " .. (note == nil and "" or " (" .. note .. ")") .. (family == nil and "" or (" (" .. family .. " Family event)")) if (monsterName == "Beetle Queen") then str = str .. "\n" .. stars .. " "	elseif (monsterName == "Gup") then str = str .. "\n" .. stars .. " \n" .. stars .. "*" .. " "	elseif (monsterName == "Solus Control Unit" or monsterName == "Alloy Worship Unit") then str = str .. "\n" .. stars .. " "	end return str end

---	Builds a list of monsters, given environment --	@function		p.MonsterList --	@param			{table} frame Frame object --	@return			{string} Preprocessed wikitext of monster list. function p.MonsterList(frame) local data = EnvData[frame.args[1]] if data == nil then return error("Environments.MonsterList: Invalid environment: " .. frame.args[1]) end if data.Monsters == nil then return frame:preprocess("None.") end local ret = "" local familyFlag = false local loopFlag = false for _, entry in pairsByKeys(data.Monsters) do		if entry.FamilyEvent == nil and not entry.Loop then ret = ret .. "\n" .. listDisplay(entry.Name, entry.Note, nil, false) end if entry.FamilyEvent ~= nil then familyFlag = true end if entry.Loop == true then loopFlag = true end end if loopFlag then ret = ret .. "\n*After Looping:" for _, entry in pairsByKeys(data.Monsters) do			if entry.Loop == true and entry.FamilyEvent == nil then ret = ret .. "\n*" .. listDisplay(entry.Name, entry.Note, nil, true) end end end if familyFlag then ret = ret .. "\n* Family Event only:" for _, entry in pairsByKeys(data.Monsters) do			if entry.FamilyEvent ~= nil and not entry.Loop then ret = ret .. "\n*" .. listDisplay(entry.Name, entry.Note, entry.FamilyEvent, true) end end end return frame:preprocess(ret) end

local env_infobox = [=[

]=]

---	Builds a template for an environment's infobox. --	@function		p.EnvInfobox --	@param			{table} frame Frame object --	@return			{string} Preprocessed wikitext of environment infobox. function p.EnvInfobox(frame) local data = EnvData[frame.args[1]] if data == nil then return error("Invalid environment!") end return frame:preprocess(string.format( env_infobox, data.Name, data.Image, data.SubName or "", data.Stage or "Unknown", data.Soundtrack or "Unknown", data.LunarSeer or "", data.Description or "" )) end

return p