Module:StatusEffect
Jump to navigation
Jump to search
StatusEffect contains details of Risk of Rain 2's status effects.
Documentation
Package items
statuseffect.StatusExpansion(frame)
(function)- Builds a template for a status effect's expansion.
- Parameter:
frame
Frame object (table) - Returns: Preprocessed wikitext of expansion template. (string)
statuseffect.SourceList(frame)
(function)- Builds a template for a status effect source list.
- Parameter:
frame
Frame object (table) - Returns: Preprocessed wikitext of list. (string)
statuseffect.GenerateTable(frame)
(function)- Builds a template for a status effect table.
- Parameter:
frame
Frame object (table) - Returns: Preprocessed wikitext of table. (string)
Modules and Lua Libraries | |
---|---|
Databases | |
Module:Challenges (/Data) • Module:Enemies (/Data) • M:Environments (/Data) • Module:Equipment (/Data) • M:Interactables (/Data) • M:Items (/Data, /LogbookData) • M:Lore (/Data) • M:Skills (/Data) • M:StatusEffect (/Data) • M:Survivors (/Data) • M:Test Version History (/Data) | |
Wiki | |
M:EnvironmentTooltip • M:ItemTooltip • M:MonsterTooltip • M:StatusEffectTooltip • M:SurvivorTooltip | |
Template Databases | |
T:FriendlyNameToInternal • T:InternalNameToFriendly • T:Keyword | |
Full MediaWiki List • Full Module List • Full Template List • Lua reference manual |
--- '''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
-- <nowiki>
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("{{" .. data.Expansion .. "|" .. data.Name .. "}}") or ""
end
function p.GetFriendlyName(frame)
local data = StatusData[frame.args[1]] or getData(frame.args[1])
if data == nil then
return error("StatusEffect.GetName: Invalid status effect '" .. frame.args[1] .. "'.")
end
return frame:preprocess(data.Name)
end
function p.GetInternalName(frame)
local data = StatusData[frame.args[1]] or getData(frame.args[1])
if data == nil then
return error("StatusEffect.GetName: Invalid status effect '" .. frame.args[1] .. "'.")
end
return frame:preprocess(data.InternalName)
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"
| [[File:%s.png|64px|center]]
| %s
| %s
| %s
| %s
]=]
--- Builds a template for a status effect source list.
-- @function p.SourceList
-- @param {table} frame Frame object
-- @return {string} Preprocessed wikitext of list.
function p.SourceList(frame)
local data = StatusData[frame.args[1]] or getData(frame.args[1])
if data == nil then
return error("StatusEffect.SourceList: Invalid status effect '" .. frame.args[1] .. "'.")
end
local ret = ""
for _, entry in pairs(data.Source) do
ret = ret .. "* " .. entry .. "\n"
end
return frame:preprocess(ret);
end
--- 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 "{{" .. entry.Expansion .. "|" .. entry.Name .. "}}" or "") .. entry.Name .. (entry.Stackable == true and "<br><span style=\"font-size:80%;\">{{Color|d|(stackable)}}</span>" or ""),
entry.Effect,
sourceString,
entry.InternalName
) .. "\n"
end
end
ret = ret .. "\n|}"
return frame:preprocess(ret)
end
return p