Module:Creature ID

From Artifact Wiki
Jump to: navigation, search

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

This module provides a spell's color without the need of aditional arguments. It is retrieved from the Cargo table 'Creature', defined in the Creature Infobox template.

Preview


Spell ID template:
Rebel Decoy
Rebel Decoy
Rebel Decoy

Rebel Decoy

Creep
Creep
This creep is not in the database yet.
You can view or create the page here.
Attack
 ?
Health
 ?
[refresh card]

Usage


{{#invoke:Creature ID|main}}

local cargo = mw.ext.cargo
local getArgs = require( 'Module:Arguments' ).main
local getCreatureCard = require('Module:Card/Creature').getCard
local getIcon = require('Module:Icon').getIcon
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]
	local icon = ''
	local page = name
	local color = ''
	local formattedImage = ''

	local cargoOutput = p.getCargo(name)

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

	-- The Creature ID (icon + link).
	local creatureID = string.format('<span class="image-link">%s%s</span>', formattedIcon, formattedLink)
  
   local creatureCard = getCreatureCard(name, 175)
	
	return string.format([=[<div class="tooltip" style=""> %s <div class="tooltipbox" style="width: 174px; top: 100&#x25;; left: 105&#x25;;> %s </div></div>]=],
		creatureID, creatureCard or '')
end


-- Retrieves the color from the creature through the cargo database (defined via the Creature Infobox template).
function p.getCargo(name)
  return cargo.query('cards', '_pageTitle, color', { where='cards.type="Creep" AND cards.title="' .. name .. '"'})[1]
end

return p