Module:Ability/new/2

From Inkipedia, the Splatoon wiki
< Module:Ability
Revision as of 07:55, 6 March 2024 by Exaskliri (talk | contribs) (Testing two separate frame object calls: from an invoking template and from another module, instead of just the former.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Ability/new/2/doc

local p = {}
local gameShortened	=	require("Module:GameShortened")

local disambigName	=	{
	["Recon"]	=	true,
}

function p.requireFromModule(frame)
	return p.chipIcon(
		frame.args.game,
		frame.args.name,
		frame.args.size,
		frame.args.icononly
	)
end

function p.invokeFromTemplate(frame)
	local args		= frame:getParent().args
	local game		= args.game
	local name		= args.name
	local size		= args.size
	local icononly	= args.icononly
	return p.getAbilityIcon(game, name, size, icononly)
end

function p.getAbilityIcon(game, name, size, icononly)
	local result
	local abilityIcon
	local linkText			= name
	local displayText		= name
	local abilityFileName 	= name

	game	=	gameShortened.getGame(game)
	if size == nil then size = 24 end

	if name == "?" then
		linkText		= "Gear ability"
		displayText		= "None"	--Exaskliri wants to display link text by default, even for "?"
		abilityFileName	= "Locked"
	end
	if disambigName[name] then
		linkText = linkText .. " (ability)"
	end
	abilityIcon = string.format("[[File:%s_Ability_%s.png|%dpx|link=%s]]", game, abilityFileName, size, linkText)
	
	local iconSpan = mw.html.create("span")
	local padSize = size * 0.05
	iconSpan
		:css("display", "inline-block")
		:css("vertical-align", "middle")
		:css("width", size.."px")
		:css("height", size.."px")
		:css("background", "black")
		:css("border-radius", "50%")
		:css("padding", padSize.."px")
		:wikitext(abilityIcon)
	abilityIcon = tostring(iconSpan)
	
	result = abilityIcon
	if not icononly then
		result = abilityIcon .. " [[" ..linkText.. "|" ..displayText.. "]]"
	end

	return result
end

return p