Module:Card/Item

From Artifact Wiki
Jump to: navigation, search

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

Info Icon.png See also: Item Card template.

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

Usage


Within templates:

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

Within modules:

1 -- At the start of the program
2 local getItemCard = require('Module:Card/Item').getItemCard
1 -- Where you need the item card
2 local itemCard = getItemCard('item name', width) -- width is optional

local cargo = mw.ext.cargo
local getArgs = require('Module:Arguments').main
local getIconFile = require('Module:Icon').getFile
local getAbility  = require('Module:Card/Ability').getAbilityCard
local getCardLayout = require('Module:Card/Layout').getCardLayout1
local properties = require('Module:Properties')
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
	
	local page = name
	local category, cost, imageFile, description, ability, rarity, formattedIcon = ''

	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['description'])) then
			description = cargoOutput['description']
    	end
		if(not p.isempty(cargoOutput['cost'])) then
			cost = cargoOutput['cost']
		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['itemType'])) then
			category = cargoOutput['itemType']
		end
		if(not p.isempty(cargoOutput['rarity'])) then
			rarity = cargoOutput['rarity']
		end
	else 
		description = properties.getNoDatabaseDescription(name, "item")
	end
	
	-- The formatted Item Card
	return getCardLayout(width, page, name, "Item", '#c69747', rarity, category, nil, cardset, illustrator, nil, nil, initiative, releaseDate, imageFile, category, category, nil, nil, nil, cost, description, ability)
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, itemType, image, cost, description, ability, rarity', { where='cards.Type="Item" 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