Jump to content

Module:Ability/Components/Infobox

From Creopedia

This documentation is transcluded from Module:Ability/Components/Infobox/doc.

Output an infobox for Module:Ability using Module:InfoboxLua.


require( 'strict' )

local infoboxLua = require( 'Module:InfoboxLua' )
local effect = require( 'Module:Effect' )
local getThumbnail = require( 'Module:Ability' ).getThumbnail

local p = {}

--- Ability icons are 30px of pixel art in EvoCreo 2, which is too small to read
--- as artwork at the top of an infobox. Shown at 2.5x, with pixelated rendering
--- (see Module:InfoboxLua/styles.css) so the upscale stays crisp rather than
--- being smoothed into a blur.
local ICON_SIZE = 75

--- @param evocreo2Data table
--- @return SectionComponentData|nil
local function getEvoCreo2Section( evocreo2Data )
	if not evocreo2Data then
		return nil
	end

	local section = {
		label = 'EvoCreo 2',
		columns = 2,
		items = {},
	}

	-- Every ability effect triggers on use and applies to the player, so the
	-- Notes block never appears here. The Effects list carries the whole story.
	for _, card in ipairs( effect.getInfoboxCards( evocreo2Data.abilityEffectMaps, 'ability' ) ) do
		table.insert( section.items, card )
	end

	return section
end

--- Build the infobox data needed from the raw data
---
--- @param context table
--- @return table
local function getInfoboxData( context )
	local data = context.data
	local args = context.args or {}

	return {
		title = data.name,
		image = {
			src = args.image or getThumbnail( data.name ),
			size = ICON_SIZE,
			class = 'cp-image-pixelated'
		},
		sections = {
			{
				sections = {
					getEvoCreo2Section( data.evocreo2 )
				}
			}
		}
	}
end

--- @param context ComponentContext
--- @return string
function p.render( context )
	return infoboxLua.render( getInfoboxData( context ) )
end

return p