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|156px]]", 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 formatCharacter(character)
if character and charater ~= '' then
local icon = icons({ character, size = '20px' })
if icon then
return string.format(
"%s [[%s]]",
icon,
character
)
end
return '[[' .. character .. ']]'
end
end
local function formatRarity(rarity)
if rarity and rarity ~= '' then
if tonumber(rarity) and
tonumber(rarity) >= 1 and
tonumber(rarity) <= 4 then
return string.format(
"%s %s☆",
icons({ rarity .. " star", size = '20px' }),
rarity
)
elseif rarity == 'birthday' then
return icons({ rarity, size = '20px' }) .. ' Birthday'
end
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 formatBreakCommas(val)
if val then
local split_val = mw.text.split(val, ',')
for i,v in ipairs(split_val) do
split_val[i] = mw.text.trim(v)
end
return table.concat(split_val, "<br>")
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', func = formatCharacter },
{ name = 'attribute', func = formatAttribute },
{ name = 'rarity', func = formatRarity },
{ name = 'unit', func = formatUnit },
{ name = 'support unit' , func = formatUnit},
{ name = 'status' },
{ name = 'date' },
{ name = 'obtain', func = formatBreakCommas },
{ 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 }
},
{ hideIfEmpty = { 'japanese' } }
)
:addRow(
{
{ tag = 'th', content = 'Romaji', colspan = 12 },
{ tag = 'argtd', content = 'romaji', colspan = 18 }
},
{ hideIfEmpty = { 'romaji' } }
)
: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 = 'Rarity', colspan = 12 },
{ tag = 'argtd', content = 'rarity', 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 }
},
{ hideIfEmpty = { 'support unit' } }
)
: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(s)', colspan = 12 },
{ tag = 'argtd', content = 'obtain', colspan = 18 }
})
:addRow(
{
{ tag = 'th', content = 'Associated Event', colspan = 12 },
{ tag = 'argtd', content = 'event', colspan = 18 }
},
{ hideIfEmpty = { 'event' } }
)
:addRow(
{
{ tag = 'th', content = 'Debut Banner', colspan = 12 },
{ tag = 'argtd', content = 'banner', colspan = 18 }
},
{ hideIfEmpty = { 'banner' } }
)
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Cards]]" .. categories
local rawArgs = infobox:getArgs('raw')
if rawArgs['character'] then
categories = categories .. string.format('[[Category:%s cards]]', rawArgs['character'])
end
if rawArgs['attribute'] then
local attrs = {
['cool'] = '[[Category:Cool cards]]',
['cute'] = '[[Category:Cute cards]]',
['happy'] = '[[Category:Happy cards]]',
['mysterious'] = '[[Category:Mysterious cards]]',
['pure'] = '[[Category:Pure cards]]'
}
if attrs[rawArgs['attribute']] then
categories = categories .. attrs[rawArgs['attribute']]
end
end
if rawArgs['rarity'] then
local rarities = {
['1'] = '[[Category:1☆ cards]]',
['2'] = '[[Category:2☆ cards]]',
['3'] = '[[Category:3☆ cards]]',
['4'] = '[[Category:4☆ cards]]',
['birthday'] = '[[Category:Birthday cards]]'
}
if rarities[rawArgs['rarity']] then
categories = categories .. rarities[rawArgs['rarity']]
end
end
if rawArgs['status'] then
local statuses = {
['Permanent'] = '[[Category:Permanent cards]]',
['Limited'] = '[[Category:Limited cards]]',
['Colorful Festival Limited'] = '[[Category:Colorful Festival limited cards]]',
['Birthday Limited'] = '[[Category:Birthday limited cards]]',
}
if statuses[rawArgs['status']] then
categories = categories .. statuses[rawArgs['status']]
end
end
end
return infobox:tostring() .. categories
end
return p