Module:Improvement ID

From Artifact Wiki
Jump to: navigation, search

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

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

Preview


Spell ID template:
Conflagration
Conflagration
Conflagration

Conflagration

Improvement
Improvement
This improvement is not in the database yet.
You can view or create the page here.
Description BG.png
[refresh card]

Usage


{{#invoke:Improvement ID|main}}

local cargo = mw.ext.cargo
local getArgs = require( 'Module:Arguments' ).main
local getImprovementCard = require('Module:Card/Improvement').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] or '20px'
	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)
	end
	
	formattedImage = getIcon('Improvement', size, name, name, "true")
  
	-- Formatting the link
	local formattedLink = string.format('[[%s|<span class="%s_text" style="font-weight: bold;">%s</span>]]', name, color, name)

	-- The Improvement ID (icon + link).
	local improvementID = string.format('<span class="image-link">%s %s</span>', formattedImage, formattedLink)
  
   local improvementCard = getImprovementCard(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>]=],
		improvementID, improvementCard or '')
end


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

return p