From Artifact Wiki
Jump to: navigation, search

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

This module provides a abilities formatted card without the need of additional arguments. The resources are retrieved from the Cargo table 'Abilities', defined in the Ability Infobox template.


Within templates:


Within modules:

1 -- At the start of the program
2 local getAbilityCard = require('Module:Card/Ability').getAbilityCard
1 -- Where you need the ability card
2 local abilityCard = getAbilityCard('ability name', width) -- width is optional

local cargo = mw.ext.cargo
local getArgs = require( 'Module:Arguments' ).main
local p = {}

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

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

-- Returns the formatted Ability Card. You can also use this function in other modules.
function p.getAbilityCard(name, width)
	if(p.isempty(name)) then
		return ''
	width = width or 200
	local icon = 'File:No_Icon.png'
	local cooldown = ''
	local _type = 'active'
	local description = ''
	local page = ''
	local formattedCooldown = ''
	local formattedDescription = ''

	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['_pageName'])) then
			page = cargoOutput['_pageName']
		if(not p.isempty(cargoOutput['icon'])) then
			icon = cargoOutput['icon']
		if(not p.isempty(cargoOutput['cooldown'])) then
			cooldown = cargoOutput['cooldown']
		if(not p.isempty(cargoOutput['abilityType'])) then
			_type = cargoOutput['abilityType']
		if(not p.isempty(cargoOutput['description'])) then
			description = cargoOutput['description']
		return ''
	-- Scale sizes
	local scale = width / 250
	-- Table
	local border    = p.floor(5 * scale)
	local textTable = string.format([=[<table style="color: #DDDDDD; margin: 2px; border-collapse: collapse; border: none; width: %spx; background-color: #40424f; border-radius: %spx;">]=], width, border)
	-- Icon
	local iconPadding = p.floor(5 * scale)
	local iconSize    = p.floor(47 * scale)
	local textIcon    = string.format([=[<td rowspan="2" style="padding: %spx; width: 1px;"> [[%s|%spx|link=%s|%s]] </td>]=], iconPadding, icon, iconSize, page, name)
	-- Name
	local nameFontSize = p.floor(17 * scale)
	local namePadding  = p.floor(10 * scale)
	local nameLimit    = name
	local textName     = string.format([=[<td style="overflow: hidden;">[[%s|<span style="color: white; font-size: %spx; font-weight: bold; margin: 0; padding-top: %spx;"> %s </span>]]</td>]=], page, nameFontSize, namePadding, nameLimit)
	-- Cooldown
	if(not p.isempty(cooldown)) then
		local cooldownSize    = p.floor(18 * scale)
		local cooldownPadding = p.floor(7 * scale)
		formattedCooldown     = string.format([==[<td rowspan="2"> [[File:Cooldown Icon.png|%spx]] </td><td rowspan="2" style="color: white; font-weight: bold; padding: 0; padding-right: %spx;"> %s </td>]==], cooldownSize, cooldownPadding, cooldown)
	local textCooldown = formattedCooldown

	-- Type
	local typeFontSize = p.floor(16 * scale)
	local typePadding  = p.floor(3 * scale)
	local typeName = 'Active Ability'
	if(not p.isempty(_type)) then
		_type = string.lower(_type)
		if(_type == 'active' or _type == 'active ability') then					-- Active Ability
			typeName = 'Active Ability'
		elseif(_type == 'reactive' or _type == 'reactive ability') then			-- Reactive Ability
			typeName = 'Reactive Ability'
		elseif(_type == 'passive' or _type == 'passive ability') then			-- Passive Ability
			typeName = 'Passive Ability'
		elseif(_type == 'improvement') then										-- Improvement
			typeName = 'Improvement'
		elseif(_type == 'continuous' or _type == 'continuous effect') then		-- Continuous Effect
			typeName = 'Continuous Effect'
	local textType     = string.format([=[<td style="font-size: %spx; padding-bottom: %spx;"> %s </td>]=], typeFontSize, typePadding, typeName)
	-- Description
	if(not p.isempty(description)) then
		local descriptionPadding  = p.floor(10 * scale)
		local descriptionFontSize = p.floor(16 * scale)
		formattedDescription      = string.format([==[<tr><td class="ab_des" colspan="4" style="background-color: #111111; font-size: %spx; padding: %spx;"> %s </td></tr>]==], descriptionFontSize, descriptionPadding, description)
	local textDescription = formattedDescription

	-- The actual output.
	return string.format([==[ %s <tr> %s %s %s </tr><tr> %s </tr> %s </table>]==], textTable, textIcon, textName, textCooldown, textType, textDescription)

-- Retrieves the icon, cooldown, type and description from the hero through the cargo database (defined via the Ability Infobox template).
function p.getCargo(name)
	return cargo.query('cards', '_pageName, icon, cooldown, abilityType, description', { where='cards.type="Ability" AND cards.title="' .. name .. '"'})[1]

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

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