Module:Skills

From Risk of Rain 2 Wiki
Jump to navigation Jump to search

Skills stores details of Risk of Rain 2' character skills.

Documentation

Package items

skills.Skill(frame) (function)
Gets the formatted skill description.
Parameter: frame Frame object (table)
Returns: Preprocessed wikitext of skill description (string)
skills.SkillTooltip(frame) (function)
Gets the formatted skill description for tooltips.
Parameter: frame Frame object (table)
Returns: Preprocessed wikitext of skill description (string)
skills.SkillSurvivor(frame) (function)
Given skill, gets survivor
Parameter: frame Frame object (table)
Returns: Preprocessed wikitext of skill survivor name (string)


---	'''Skills''' stores details of Risk of Rain 2' character skills.
--	
--	@module		skills
--	@alias		p
--	@author		[[User:Paradoxzyx|Paradoxzyx]]
--	@require	[[Module:Skills/Data]]
--	@release	stable
--<nowiki>
local p = {}

local data = require("Module:Skills/Data")
local all_skills = data.skills

---	Gets the formatted skill description. 
--	@function		p.Skill
--	@param			{table} frame Frame object
--	@return			{string} Preprocessed wikitext of skill description
function p.Skill(frame)
  return frame:preprocess(all_skills[frame.args[1]].Desc:gsub("|noTooltip=true", ""))
end

local tooltip_template = '<span class="tooltip-block nomobile">' .. 
                            '<span class="tooltip-icon">' ..
                              '<span>%s</span>' ..
                              '' ..
                            '</span>' ..
                            '<span>' ..
                              '<span>%s {{Color|%s|(%s)}}</span><span class="makeshift-hr"></span><span>%s</span>' ..
                            '</span>' ..
                          '</span>'
                          
function getTypeColor(t)
	if t == "Primary" or t == "Secondary" then
		return "damage"
	elseif t == "Utility" then
		return "utility"
	elseif t == "Special" then
		return "healing"
	elseif t == "Passive" then
		return "note"
	end
	
	return "common"
end

---	Gets the formatted skill description for tooltips. 
--	@function		p.SkillTooltip
--	@param			{table} frame Frame object
--	@return			{string} Preprocessed wikitext of skill description
function p.SkillTooltip(frame)
	local data = all_skills[frame.args[1]]
	if data == nil then
		return frame:preprocess("<span style=\"color:red\">" .. frame.args[1] .. " is not a valid skill.</span>")
	end
	local str = string.format(
			tooltip_template,
			"[[File:" .. (data.Image and data.Image or (data.Name .. ".png")) .. "|60px]]",
			data.Name,
			getTypeColor(data.Type),
			data.Type,
			data.Desc:gsub("{{Keyword", "{{Color") .. (data.Survivor == nil and "" or ("<br>Survivor: {{Color|" .. string.lower(data.Survivor) .. "|" .. data.Survivor .. "}}"))
		)
	return frame:preprocess(str)
end

---	Given skill, gets survivor
--	@function		p.SkillSurvivor
--	@param			{table} frame Frame object
--	@return			{string} Preprocessed wikitext of skill survivor name
function p.SkillSurvivor(frame)
	return frame:preprocess(all_skills[frame.args[1]].Survivor)
end

return p
--</nowiki>