Module:Hero ID

From Artifact Wiki
Jump to: navigation, search

Documentation for Module:Hero ID [edit] [edit doc]

Info Icon.png See also: Hero ID template.

This module provides a hero's icon and color without the need of aditional arguments. They are retrieved from the Cargo table 'Heroes', defined in the Hero Infobox template.


Hero ID template:
Axe Axe


{{#invoke:Hero ID|main}}

local cargo = mw.ext.cargo
local getArgs = require( 'Module:Arguments' ).main
local getHeroIcon = require('Module:Hero Icon').getHeroIcon
local getHeroCard = require('Module:Card/Hero').getCard
local p = {}

function p.main( frame )
	local args = getArgs()
	return p._main( args )

function p._main( args )
	local name = args[1]
	local size = args[2]
	return p.getHeroID(name, size)

-- Returns the formatted hero icon. You can use this function in other modules.
function p.getHeroID(name, size)
	local color = ''
	local formattedImage = ''
	formattedImage = getHeroIcon(name, size, false)

	local cargoOutput = p.getCargo(name)

	-- When available, the color get set to the one found in the database.
	if(cargoOutput ~= nil) then
		color = cargoOutput['color'] or ''
		color = string.lower(color)
	-- Formatting the link
	local formattedLink = string.format('[[%s|<span class="%s_text" style="font-weight: bold;">%s</span>]]', name, color, name)

	-- The Hero ID (icon + link)
	local heroID = string.format('<span class="image-link">%s%s</span>', formattedImage, formattedLink)
	local heroCard = getHeroCard(name, 175)
	return string.format([=[<div class="tooltip" style=""> %s <div class="tooltipbox" style="display: inline-box; top: 98&#x25;; left: 50px;> %s </div></div>]=],
		heroID, (heroCard or ''))

-- Retrieves the icon and color from the hero through the cargo database (defined via the Hero Infobox template).
function p.getCargo(name)
	return cargo.query('Cards, Heroes', 'Cards.Color=color', { where='Cards.Name="' .. name .. '"', join='Cards.ID=Heroes.ID'})[1]

function p.isempty(s)
  return s == nil or s == ''

return p