Difference between revisions of "Module:Hero ID"

From Artifact Wiki
Jump to: navigation, search
m
(Update module to work with the new database)
Line 31: Line 31:
 
-- When available, the color get set to the one found in the database.
 
-- When available, the color get set to the one found in the database.
 
if(cargoOutput ~= nil) then
 
if(cargoOutput ~= nil) then
color = cargoOutput['color'] or ''
+
color = cargoOutput['Color'] or ''
 
color = string.lower(color)
 
color = string.lower(color)
 
end
 
end
Line 50: Line 50:
 
-- Retrieves the icon and color from the hero through the cargo database (defined via the Hero Infobox template).
 
-- Retrieves the icon and color from the hero through the cargo database (defined via the Hero Infobox template).
 
function p.getCargo(name)
 
function p.getCargo(name)
return cargo.query('cards', 'color', { where='cards.type="Hero" AND cards.title="' .. name .. '"'})[1]
+
return cargo.query('Cards, Heroes', 'Color', { where='Cards.Name="' .. name .. '"', join='Cards.ID=Heroes.ID'})[1]
 
end
 
end
  

Revision as of 01:51, 14 April 2020

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.

Preview


Hero ID template:
Axe Axe
Axe

Usage


{{#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 )
end


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


-- 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)
	end
  
	-- 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 ''))
end


-- 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', 'Color', { where='Cards.Name="' .. name .. '"', join='Cards.ID=Heroes.ID'})[1]
end


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

return p