This module depends on the following other modules: |
To generate {{Infobox card}}, invoke using the main function.
--------------------------
-- Module for [[Template:Infobox Card]]
------------------------
local getArgs = require('Module:Arguments').getArgs
local builder = require('Module:InfoboxBuilder')
local constants = require('Module:Constants')
local utils = require('Module:Utilities')
local icons = require('Module:Icons')._main
local p = {}
local categories = ""
local function formatImage(image_name)
return string.format("[[File:%s|220px]]", image_name)
end
local function formatAttribute(attribute)
if attribute and attribute ~= '' then
return string.format(
"%s %s",
icons({ attribute, size = '20px' }),
utils.capitalize(attribute)
)
end
return nil
end
local function formatRarity(rarity)
if rarity and
rarity ~= '' and
tonumber(rarity) >= 1 and
tonumber(rarity) <= 4 then
return icons({ value .. " star", size = '20px' })
end
return nil
end
local function formatUnit(unit)
if unit and unit ~= '' then
return string.format(
"%s [[%s]]",
icons({ unit, size = '20px' }),
constants.get_unit(unit)
)
end
return nil
end
local function formatToLink(val)
if val and val ~= '' then
return '[[' .. val .. ']]'
end
return nil
end
function p.main(frame)
local args = getArgs(frame)
local infobox = builder.new()
infobox:setName('Infobox Card')
:setWidth("330px")
:setParams{
{ name = 'card id' },
{ name = 'card name', default = mw.title.getCurrentTitle().text },
{ name = 'thumbnail', func = formatImage },
{ name = 'thumbnail trained', func = formatImage },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'character' },
{ name = 'attribute', func = formatAttribute },
{ name = 'rarity', func = formatRarity },
{ name = 'unit', func = formatUnit },
{ name = 'support unit' , func = formatUnit},
{ name = 'status' },
{ name = 'date' },
{ name = 'obtain' },
{ name = 'event', func = formatToLink },
{ name = 'banner', func = formatToLink }
}
:setArgs(args)
:setHeaderColorsByParam('attribute', constants.get_attribute_colors)
infobox
:addHeader({ tag = 'argth', content = 'card name' })
:addImage(
{
{ tag = 'argtd', content = 'thumbnail', title = 'Untrained' },
{ tag = 'argtd', content = 'thumbnail trained', title = 'Trained' }
}
)
:addRow({
{ tag = 'th', content = 'Japanese', colspan = 12 },
{ tag = 'argtd', content = 'japanese', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Romaji', colspan = 12 },
{ tag = 'argtd', content = 'romaji', colspan = 18 }
})
:addHeader({ tag = 'th', content = 'Card Information' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Character', colspan = 12 },
{ tag = 'argtd', content = 'character', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Attribute', colspan = 12 },
{ tag = 'argtd', content = 'attribute', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Unit', colspan = 12 },
{ tag = 'argtd', content = 'unit', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Support Unit', colspan = 12 },
{ tag = 'argtd', content = 'support unit', colspan = 18 }
})
:addHeader({ tag = 'th', content = 'Obtainment Information' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Status', colspan = 12 },
{ tag = 'argtd', content = 'status', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Release Date', colspan = 12 },
{ tag = 'argtd', content = 'date', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Obtainment Method', colspan = 12 },
{ tag = 'argtd', content = 'obtain', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Associated Event', colspan = 12 },
{ tag = 'argtd', content = 'event', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Debut Banner', colspan = 12 },
{ tag = 'argtd', content = 'banner', colspan = 18 }
})
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Cards]]" .. categories
end
return infobox:tostring() .. categories
end
return p