Open main menu

Artifact Wiki β

Module:Card/Spell

< Module:Card

Documentation for Module:Card/Spell [edit] [edit doc]

This module provides a spell's formatted card without the need of additional arguments. The resources are retrieved from the Cargo table 'Spells', defined in the Spell Infobox template.

Usage


Within templates:

{{#invoke:Card/Spell|main}}

Within modules:

1 -- At the start of the program
2 local getSpellCard = require('Module:Card/Spell').getSpellCard
1 -- Where you need the spell card
2 local spellCard = getSpellCard('spell name', width) -- width is optional

local cargo = mw.ext.cargo
local getArgs = require('Module:Arguments').main
local getIcon = require('Module:Icon').getIcon
local getHeroIcon = require('Module:Hero_Icon').getHeroIcon
local properties = require('Module:Properties')
local getCardLayout = require('Module:Card/Layout').getCardLayout1
local p = {}


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


function p._main(args)
	local name = args[1]	-- 1. template argument (Name)
	local width = args[2]	-- 2. template argument (Width) [optional]
	
	return p.getCard(name, width)
end

-- Returns the formatted Spell Card. You can use this function in other modules.
function p.getCard(name, width)
	if(p.isempty(name)) then
		return ''
	end
	
	local cargoOutput = p.getCargo(name)
	
	local page = name
	local mana, imageFile, description, lane, heroName, color, rarity, initiative, formattedIcon = ''

	-- When available, the icon, cooldown, type and description get set to the one found in the database.
	if(cargoOutput ~= nil) then
		if(not p.isempty(cargoOutput['image'])) then
			imageFile = cargoOutput['image']
		end
		if(not p.isempty(cargoOutput['description'])) then
			description = cargoOutput['description']
    	end
		if(not p.isempty(cargoOutput['mana'])) then
			mana = cargoOutput['mana']
		end
		if(not p.isempty(cargoOutput['lane'])) then
			lane = cargoOutput['lane']
		end
		if(not p.isempty(cargoOutput['hero'])) then
			heroName = cargoOutput['hero']
		end
		if(not p.isempty(cargoOutput['color'])) then
			color = cargoOutput['color']
		end
		if(not p.isempty(cargoOutput['_pageTitle'])) then
			page = cargoOutput['_pageTitle']
		end
		if(not p.isempty(cargoOutput['rarity'])) then
			rarity = cargoOutput['rarity']
		end
		if(not p.isempty(cargoOutput['initiative'])) then
			initiative = cargoOutput['initiative']
		end
	else
		description = properties.getNoDatabaseDescription(name, "spell")
	end

	return getCardLayout(width, page, name, "Spell", color, rarity, nil, nil, cardset, illustrator, heroName, lane, initiative, releaseDate, imageFile, "Spell", "Spell", "Spell", nil, mana, nil, description, nil)
end


-- Retrieves the color, lane, mana, hero, image and description from the spell through the cargo database (defined via the Spell Infobox template).
function p.getCargo(name)
	return cargo.query('cards', '_pageTitle, color, lane, mana, hero, image, description, rarity, initiative', { where='cards.type="Spell" AND cards.title="' .. name .. '"'})[1]
end


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

function p.floor(d)
	return math.floor(d)
end
return p