Module:Card/Improvement

From Artifact Wiki
Jump to: navigation, search

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

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

Usage


Within templates:

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

Within modules:

1 -- At the start of the program
2 local getImprovementCard = require('Module:Card/Improvement').getImprovementCard
1 -- Where you need the improvement card
2 local improvementCard = getImprovementCard('improvement name', width) -- width is optional

local cargo = mw.ext.cargo
local getArgs = require('Module:Arguments').main
local getIcon = require('Module:Icon').getIcon
local getAbility  = require('Module:Card/Ability').getAbilityCard
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 Item Card. You can use this function in other modules.
function p.getCard(name, width)
	if(p.isempty(name)) then
		return ''
	end
	
	width = width or properties.getCardWidth()
	local page = name
	local icon, circle = ''
	local mana, imageFile, ability, lane, color, heroName, rarity, description = ''

	local cargoOutput = p.getCargo(name)

	-- 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['icon'])) then
			improvementFile = cargoOutput['icon']
    	end
		if(not p.isempty(cargoOutput['mana'])) then
			mana = cargoOutput['mana']
		end
		if(not p.isempty(cargoOutput['_pageTitle'])) then
			page = cargoOutput['_pageTitle']
		end	
		if(not p.isempty(cargoOutput['ability'])) then
			ability = cargoOutput['ability']
		end
		if(not p.isempty(cargoOutput['lane'])) then
			lane = cargoOutput['lane']
		end
		if(not p.isempty(cargoOutput['color'])) then
			color = cargoOutput['color']
		end
		if(not p.isempty(cargoOutput['hero'])) then
			heroName = cargoOutput['hero']
		end
		if(not p.isempty(cargoOutput['rarity'])) then
			rarity = cargoOutput['rarity']
		end
		if(not p.isempty(cargoOutput['description'])) then
			description = cargoOutput['description']
		end
	else
		description = properties.getNoDatabaseDescription(name, "improvement")
	end
	
	return getCardLayout(width, page, name, "Improvement", color, rarity, nil, nil, cardset, illustrator, heroName, lane, initiative, releaseDate, imageFile, "Improvement", "Improvement", "Improvement", improvementFile, mana, nil, description, nil)
end


-- Retrieves the category, image, cost and description from the hero through the cargo database (defined via the Ability Infobox template).
function p.getCargo(name)
	return cargo.query('cards', '_pageTitle, mana, image, icon, hero, ability, lane, color, rarity, description', { where='cards.type="Improvement" 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