Module:StatusEffect

---	StatusEffect contains details of Risk of Rain 2's status effects. --	--	@module		statuseffect --	@alias		p --	@author		User:Thundermaker300 --	@attribution	All who helped to update status effect templates --	@require	Module:StatusEffect/Data --	@release	stable --

local StatusData = mw.loadData('Module:StatusEffect/Data').StatusEffects

local p = {}

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

function getData(unfriendlyName) for _, entry in pairs(StatusData) do		if entry.InternalName == unfriendlyName then return entry end end return nil end

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

function p.TypeCount(frame) local c = 0 for _, entry in pairs(StatusData) do		if entry.Type == frame.args[1] or frame.args[1]:lower == "all" then c = c + 1 end end return c end

local table_start = [=[ {| class="article-table floatheader" style="width:100%;max-width:1000px" ! style="width:15%" | Icon ! Name ! Effect ! style="width:25%" | Source ! Internal Name ]=]

local table_template = [=[ ]=]
 * - id="%s"
 * %s.png
 * %s
 * %s
 * %s
 * %s

---	Builds a template for a status effect table. --	@function		p.GenerateTable --	@param			{table} frame Frame object --	@return			{string} Preprocessed wikitext of table. function p.GenerateTable(frame) local t = frame.args[1] local ret = table_start .. "\n" for _, entry in pairsByKeys(StatusData) do		if (entry.Type ~= nil and entry.Type:lower == t:lower) or t:lower == "all" then local sourceString = "\n" for _, source in pairsByKeys(entry.Source) do sourceString = sourceString .. "* " .. source .. "\n" end ret = ret .. string.format(			table_template,			entry.Name,			entry.Image,			(entry.Expansion and "" or "") .. entry.Name,			entry.Effect,			sourceString,			entry.InternalName			) .. "\n" end end ret = ret .. "\n|}" return frame:preprocess(ret) end

return p