Module:Trait/Components/Infobox
Appearance
This documentation is transcluded from Module:Trait/Components/Infobox/doc.
Output an infobox for Module:Trait using Module:InfoboxLua.
require( 'strict' )
local infoboxLua = require( 'Module:InfoboxLua' )
local effect = require( 'Module:Effect' )
local getThumbnail = require( 'Module:Trait' ).getThumbnail
local p = {}
--- Trait 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 rarityId number
--- @return string|nil
local function getRarityHtml( rarityId )
local rarityTable = mw.loadJsonData( 'Module:GameData/EvoCreo2/RarityTable.json' )
local rarity = rarityTable[rarityId]
if not rarity or not rarity.name then
return nil
end
return require( 'Module:Rarity' )._main( rarity.nameId )
end
--- @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 = {
{
label = 'Rarity',
content = getRarityHtml( evocreo2Data.rarityId )
}
},
}
for _, card in ipairs( effect.getInfoboxCards( evocreo2Data.traitEffectMaps, 'trait' ) ) 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