Module:StatusEffectTooltip

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

StatusEffectTooltip create status effect tooltip.

Documentation

Package items

statuseffecttooltip.StatusAffectLink(frame) (function)
Creates a status effect link.
Parameter: frame Frame object (table)
Returns: Preprocessed wikitext of resultant link (string)


---	'''StatusEffectTooltip''' create status effect tooltip.
--	
--	@module		statuseffecttooltip
--	@alias		p
--	@author		[[User:Thundermaker300]]
--	@attribution	All who helped to update status effect templates
--	@require	[[Module:StatusEffect/Data]]
--	@release	stable
--	<nowiki>
local p = {}

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

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

function p.Image(frame)
	local data = StatusData[frame.args[1]] or getData(frame.args[1])
	if data == nil then
		return ""
	end
	return data.Image
end

local tooltip_template = '<span class="tooltip-block nomobile">' .. 
                            '<span class="tooltip-icon">' ..
                              '<span>%s</span>' ..
                              '' ..
                            '</span>' ..
                            '<span>' ..
                              '%s%s {{Color|%s|(%s)}} <br><span style=\"color:#959494\">%s</span><span class="makeshift-hr"></span>%s%s' ..
                            '</span>' ..
                          '</span>'

---	Creates a status effect link.
--	@function		p.StatusAffectLink
--	@param			{table} frame Frame object
--	@return			{string} Preprocessed wikitext of resultant link
function p.Tooltip(frame)
	local data = StatusData[frame.args[1]] or getData(frame.args[1])
	if data == nil then
		return error("StatusEffectTooltip.Tooltip(frame): Invalid status affect!")
	end
	local str = string.format(
		tooltip_template,
		data.Image and "[[File:" .. data.Image .. ".png|60px]]" or "",
		data.Expansion and "{{" .. data.Expansion .. "}}" or "",
		data.Name,
		((data.Type == "Debuff" and "hp") or (data.Type == "Buff" and "heal") and (data.Type == "Affix Buff" and "damage") or "white"),
		data.Type,
		data.EffectShort or "",
		data.Effect or "Unknown",
		(data.Stackable == true and "<br><span style=\"font-size:80%;\">{{Color|d|(stackable)}}</span>" or "")
	)
	return frame:preprocess(str)
end

return p