Content added Content deleted
(allow multiple values for obtain methods) |
(add attribute categories) |
||
Line 180: | Line 180: | ||
if mw.title.getCurrentTitle().namespace == 0 then |
if mw.title.getCurrentTitle().namespace == 0 then |
||
categories = "[[Category:Cards]]" .. categories |
categories = "[[Category:Cards]]" .. categories |
||
local rawArgs = infobox:getArgs('raw') |
|||
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 |
|||
end |
end |
||
Revision as of 03:26, 13 October 2021
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 formatRarity(rarity)
if rarity and rarity ~= '' then
if tonumber(rarity) and
tonumber(rarity) >= 1 and
tonumber(rarity) <= 4 then
return icons({ rarity .. " star", size = '20px' })
elseif rarity == 'birthday' then
return icons({ rarity, size = '20px' })
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 = formatToLink },
{ 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', 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['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
end
return infobox:tostring() .. categories
end
return p