Content added Content deleted
(using new icon modules) |
(using new infobox builder) |
||
Line 3: | Line 3: | ||
------------------------ |
------------------------ |
||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local builder = require('Module:InfoboxBuilder') |
local builder = require('Module:InfoboxBuilder new') |
||
local constants = require('Module:Constants') |
local constants = require('Module:Constants') |
||
local utils = require('Module:Utilities') |
local utils = require('Module:Utilities') |
||
Line 10: | Line 10: | ||
local ricon = require('Module:Rarity icon')._main |
local ricon = require('Module:Rarity icon')._main |
||
local icons = require('Module:Icons')._main |
local icons = require('Module:Icons')._main |
||
local p = {} |
local p = {} |
||
local categories = "" |
local categories = "" |
||
local function splitStringWithDelim(delim) |
|||
return function(str) |
|||
if str == nil then |
|||
return nil |
|||
end |
|||
local list = mw.text.split(str, delim) |
|||
for i=1,#list do |
|||
list[i] = mw.text.trim(list[i]) |
|||
end |
|||
return list |
|||
end |
|||
end |
|||
local function formatList(list) |
|||
if #list < 2 then |
|||
return list[1] |
|||
end |
|||
local ul = mw.html.create('ul') |
|||
for i=1,#list do |
|||
ul:tag('li') |
|||
:wikitext(list[i]) |
|||
end |
|||
return tostring(ul) |
|||
end |
|||
local function formatImage(image_name) |
local function formatImage(image_name) |
||
Line 100: | Line 129: | ||
infobox:setName('Infobox card') |
infobox:setName('Infobox card') |
||
:setWidth("330px") |
|||
:setParams{ |
:setParams{ |
||
{ name = 'card id' }, |
{ name = 'card id' }, |
||
{ name = 'card name', default = mw.title.getCurrentTitle().text }, |
{ name = 'card name', default = mw.title.getCurrentTitle().text }, |
||
{ name = 'thumbnail', |
{ name = 'thumbnail', dFunc = formatImage }, |
||
{ name = 'thumbnail trained', |
{ name = 'thumbnail trained', dFunc = formatImage }, |
||
{ name = 'japanese' }, |
{ name = 'japanese' }, |
||
{ name = 'romaji' }, |
{ name = 'romaji' }, |
||
{ name = 'character', |
{ name = 'character', dFunc = formatCharacter }, |
||
{ name = 'attribute', |
{ name = 'attribute', dFunc = formatAttribute }, |
||
{ name = 'rarity', |
{ name = 'rarity', dFunc = formatRarity }, |
||
{ name = 'unit', |
{ name = 'unit', dFunc = formatUnit }, |
||
{ name = 'support unit' , |
{ name = 'support unit' , dFunc = formatUnit}, |
||
{ name = 'status' }, |
{ name = 'status' }, |
||
{ name = 'date' }, |
{ name = 'date' }, |
||
{ name = 'obtain', |
{ name = 'obtain', pFunc = splitStringWithDelim(','), dFunc = formatList }, |
||
{ name = 'event', |
{ name = 'event', dFunc = formatToLink }, |
||
{ name = 'banner', |
{ name = 'banner', dFunc = formatToLink } |
||
} |
} |
||
:setArgs(args) |
:setArgs(args) |
||
:processArgs() |
|||
:setHeaderColorsByParam('attribute', constants.get_attribute_colors) |
|||
:setCategoryMap({ |
|||
['character'] = { |
|||
-- VIRTUAL SINGER |
|||
['Hatsune Miku'] = '[[Category:Hatsune Miku cards]]', |
|||
['Kagamine Rin'] = '[[Category:Kagamine Rin cards]]', |
|||
['Kagamine Len'] = '[[Category:Kagamine Len cards]]', |
|||
['Megurine Luka'] = '[[Category:Megurine Luka cards]]', |
|||
['MEIKO'] = '[[Category:MEIKO cards]]', |
|||
['KAITO'] = '[[Category:KAITO cards]]', |
|||
-- Leo/need |
|||
['Hoshino Ichika'] = '[[Category:Hoshino Ichika cards]]', |
|||
['Tenma Saki'] = '[[Category:Tenma Saki cards]]', |
|||
['Mochizuki Honami'] = '[[Category:Mochizuki Honami cards]]', |
|||
['Hinomori Shiho'] = '[[Category:Hinomori Shiho cards]]', |
|||
-- MORE MORE JUMP! |
|||
['Hanasato Minori'] = '[[Category:Hanasato Minori cards]]', |
|||
['Kiritani Haruka'] = '[[Category:Kiritani Haruka cards]]', |
|||
['Momoi Airi'] = '[[Category:Momoi Airi cards]]', |
|||
['Hinomori Shizuku'] = '[[Category:Hinomori Shizuku cards]]', |
|||
-- Vivid BAD SQUAD |
|||
['Azusawa Kohane'] = '[[Category:Azusawa Kohane cards]]', |
|||
['Shiraishi An'] = '[[Category:Shiraishi An cards]]', |
|||
['Shinonome Akito'] = '[[Category:Shinonome Akito cards]]', |
|||
['Aoyagi Toya'] = '[[Category:Aoyagi Toya cards]]', |
|||
-- Wonderlands×Showtime |
|||
['Tenma Tsukasa'] = '[[Category:Tenma Tsukasa cards]]', |
|||
['Otori Emu'] = '[[Category:Otori Emu cards]]', |
|||
['Kusanagi Nene'] = '[[Category:Kusanagi Nene cards]]', |
|||
['Kamishiro Rui'] = '[[Category:Kamishiro Rui cards]]', |
|||
-- 25-ji, Night Code de. |
|||
['Yoisaki Kanade'] = '[[Category:Yoisaki Kanade cards]]', |
|||
['Asahina Mafuyu'] = '[[Category:Asahina Mafuyu cards]]', |
|||
['Shinonome Ena'] = '[[Category:Shinonome Ena cards]]', |
|||
['Akiyama Mizuki'] = '[[Category:Akiyama Mizuki cards]]', |
|||
}, |
|||
['attribute'] = { |
|||
['Cool'] = '[[Category:Cool cards]]', |
|||
['Cute'] = '[[Category:Cute cards]]', |
|||
['Happy'] = '[[Category:Happy cards]]', |
|||
['Mysterious'] = '[[Category:Mysterious cards]]', |
|||
['Pure'] = '[[Category:Pure cards]]', |
|||
}, |
|||
['rarity'] = { |
|||
['1'] = '[[Category:1☆ cards]]', |
|||
['2'] = '[[Category:2☆ cards]]', |
|||
['3'] = '[[Category:3☆ cards]]', |
|||
['4'] = '[[Category:4☆ cards]]', |
|||
['Birthday'] = '[[Category:Birthday cards]]', |
|||
}, |
|||
['status'] = { |
|||
['Permanent'] = '[[Category:Permanent cards]]', |
|||
['Limited'] = '[[Category:Limited cards]]', |
|||
['Colorful Festival limited'] = '[[Category:Colorful Festival limited cards]]', |
|||
['Birthday limited'] = '[[Category:Birthday limited cards]]', |
|||
} |
|||
}) |
|||
infobox |
infobox |
||
Line 132: | Line 221: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Japanese' |
{ tag = 'th', content = 'Japanese' }, |
||
{ tag = 'argtd', content = 'japanese' |
{ tag = 'argtd', content = 'japanese' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'japanese' } } |
{ hideIfEmpty = { 'japanese' } } |
||
Line 139: | Line 228: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Romaji' |
{ tag = 'th', content = 'Romaji' }, |
||
{ tag = 'argtd', content = 'romaji' |
{ tag = 'argtd', content = 'romaji' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'romaji' } } |
{ hideIfEmpty = { 'romaji' } } |
||
Line 146: | Line 235: | ||
:addHeader({ tag = 'th', content = 'Card Information' }, { subheader = true }) |
:addHeader({ tag = 'th', content = 'Card Information' }, { subheader = true }) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = 'Card ID' |
{ tag = 'th', content = 'Card ID' }, |
||
{ tag = 'argtd', content = 'card id' |
{ tag = 'argtd', content = 'card id' } |
||
}) |
}) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = 'Character' |
{ tag = 'th', content = 'Character' }, |
||
{ tag = 'argtd', content = 'character' |
{ tag = 'argtd', content = 'character' } |
||
}) |
}) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = 'Attribute' |
{ tag = 'th', content = 'Attribute' }, |
||
{ tag = 'argtd', content = 'attribute' |
{ tag = 'argtd', content = 'attribute' } |
||
}) |
}) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = 'Rarity' |
{ tag = 'th', content = 'Rarity' }, |
||
{ tag = 'argtd', content = 'rarity' |
{ tag = 'argtd', content = 'rarity' } |
||
}) |
}) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = 'Unit' |
{ tag = 'th', content = 'Unit' }, |
||
{ tag = 'argtd', content = 'unit' |
{ tag = 'argtd', content = 'unit' } |
||
}) |
}) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Support unit' |
{ tag = 'th', content = 'Support unit' }, |
||
{ tag = 'argtd', content = 'support unit' |
{ tag = 'argtd', content = 'support unit' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'support unit' } } |
{ hideIfEmpty = { 'support unit' } } |
||
Line 174: | Line 263: | ||
:addHeader({ tag = 'th', content = 'Acquisition Information' }, { subheader = true }) |
:addHeader({ tag = 'th', content = 'Acquisition Information' }, { subheader = true }) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = 'Status' |
{ tag = 'th', content = 'Status' }, |
||
{ tag = 'argtd', content = 'status' |
{ tag = 'argtd', content = 'status' } |
||
}) |
}) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = 'Release date' |
{ tag = 'th', content = 'Release date' }, |
||
{ tag = 'argtd', content = 'date' |
{ tag = 'argtd', content = 'date' } |
||
}) |
}) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = 'Acquisition method(s)' |
{ tag = 'th', content = 'Acquisition method(s)' }, |
||
{ tag = 'argtd', content = 'obtain' |
{ tag = 'argtd', content = 'obtain' } |
||
}) |
}) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Associated event' |
{ tag = 'th', content = 'Associated event' }, |
||
{ tag = 'argtd', content = 'event' |
{ tag = 'argtd', content = 'event' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'event' } } |
{ hideIfEmpty = { 'event' } } |
||
Line 194: | Line 283: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Debut |
{ tag = 'th', content = 'Debut gacha' }, |
||
{ tag = 'argtd', content = 'banner' |
{ tag = 'argtd', content = 'banner' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'banner' } } |
{ hideIfEmpty = { 'banner' } } |
||
Line 201: | Line 290: | ||
if mw.title.getCurrentTitle().namespace == 0 then |
if mw.title.getCurrentTitle().namespace == 0 then |
||
categories = "[[Category:Cards]]" .. |
categories = "[[Category:Cards]]" .. infobox:getCategories() |
||
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 |
end |
||
Revision as of 03:59, 16 March 2022
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 new')
local constants = require('Module:Constants')
local utils = require('Module:Utilities')
local aicon = require('Module:Attribute icon')._main
local cicon = require('Module:Character icon')._main
local ricon = require('Module:Rarity icon')._main
local icons = require('Module:Icons')._main
local p = {}
local categories = ""
local function splitStringWithDelim(delim)
return function(str)
if str == nil then
return nil
end
local list = mw.text.split(str, delim)
for i=1,#list do
list[i] = mw.text.trim(list[i])
end
return list
end
end
local function formatList(list)
if #list < 2 then
return list[1]
end
local ul = mw.html.create('ul')
for i=1,#list do
ul:tag('li')
:wikitext(list[i])
end
return tostring(ul)
end
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",
aicon({ attribute, size = '20px' }),
utils.capitalize(attribute)
)
end
return nil
end
local function formatCharacter(character)
if character and charater ~= '' then
local icon = cicon({ 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 ricon({ rarity, '20px' })
elseif rarity == 'birthday' then
return ricon({ rarity, '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, { wrappers = 'Template:Infobox card' })
local infobox = builder.new()
infobox:setName('Infobox card')
:setParams{
{ name = 'card id' },
{ name = 'card name', default = mw.title.getCurrentTitle().text },
{ name = 'thumbnail', dFunc = formatImage },
{ name = 'thumbnail trained', dFunc = formatImage },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'character', dFunc = formatCharacter },
{ name = 'attribute', dFunc = formatAttribute },
{ name = 'rarity', dFunc = formatRarity },
{ name = 'unit', dFunc = formatUnit },
{ name = 'support unit' , dFunc = formatUnit},
{ name = 'status' },
{ name = 'date' },
{ name = 'obtain', pFunc = splitStringWithDelim(','), dFunc = formatList },
{ name = 'event', dFunc = formatToLink },
{ name = 'banner', dFunc = formatToLink }
}
:setArgs(args)
:processArgs()
:setCategoryMap({
['character'] = {
-- VIRTUAL SINGER
['Hatsune Miku'] = '[[Category:Hatsune Miku cards]]',
['Kagamine Rin'] = '[[Category:Kagamine Rin cards]]',
['Kagamine Len'] = '[[Category:Kagamine Len cards]]',
['Megurine Luka'] = '[[Category:Megurine Luka cards]]',
['MEIKO'] = '[[Category:MEIKO cards]]',
['KAITO'] = '[[Category:KAITO cards]]',
-- Leo/need
['Hoshino Ichika'] = '[[Category:Hoshino Ichika cards]]',
['Tenma Saki'] = '[[Category:Tenma Saki cards]]',
['Mochizuki Honami'] = '[[Category:Mochizuki Honami cards]]',
['Hinomori Shiho'] = '[[Category:Hinomori Shiho cards]]',
-- MORE MORE JUMP!
['Hanasato Minori'] = '[[Category:Hanasato Minori cards]]',
['Kiritani Haruka'] = '[[Category:Kiritani Haruka cards]]',
['Momoi Airi'] = '[[Category:Momoi Airi cards]]',
['Hinomori Shizuku'] = '[[Category:Hinomori Shizuku cards]]',
-- Vivid BAD SQUAD
['Azusawa Kohane'] = '[[Category:Azusawa Kohane cards]]',
['Shiraishi An'] = '[[Category:Shiraishi An cards]]',
['Shinonome Akito'] = '[[Category:Shinonome Akito cards]]',
['Aoyagi Toya'] = '[[Category:Aoyagi Toya cards]]',
-- Wonderlands×Showtime
['Tenma Tsukasa'] = '[[Category:Tenma Tsukasa cards]]',
['Otori Emu'] = '[[Category:Otori Emu cards]]',
['Kusanagi Nene'] = '[[Category:Kusanagi Nene cards]]',
['Kamishiro Rui'] = '[[Category:Kamishiro Rui cards]]',
-- 25-ji, Night Code de.
['Yoisaki Kanade'] = '[[Category:Yoisaki Kanade cards]]',
['Asahina Mafuyu'] = '[[Category:Asahina Mafuyu cards]]',
['Shinonome Ena'] = '[[Category:Shinonome Ena cards]]',
['Akiyama Mizuki'] = '[[Category:Akiyama Mizuki cards]]',
},
['attribute'] = {
['Cool'] = '[[Category:Cool cards]]',
['Cute'] = '[[Category:Cute cards]]',
['Happy'] = '[[Category:Happy cards]]',
['Mysterious'] = '[[Category:Mysterious cards]]',
['Pure'] = '[[Category:Pure cards]]',
},
['rarity'] = {
['1'] = '[[Category:1☆ cards]]',
['2'] = '[[Category:2☆ cards]]',
['3'] = '[[Category:3☆ cards]]',
['4'] = '[[Category:4☆ cards]]',
['Birthday'] = '[[Category:Birthday cards]]',
},
['status'] = {
['Permanent'] = '[[Category:Permanent cards]]',
['Limited'] = '[[Category:Limited cards]]',
['Colorful Festival limited'] = '[[Category:Colorful Festival limited cards]]',
['Birthday limited'] = '[[Category:Birthday limited cards]]',
}
})
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' },
{ tag = 'argtd', content = 'japanese' }
},
{ hideIfEmpty = { 'japanese' } }
)
:addRow(
{
{ tag = 'th', content = 'Romaji' },
{ tag = 'argtd', content = 'romaji' }
},
{ hideIfEmpty = { 'romaji' } }
)
:addHeader({ tag = 'th', content = 'Card Information' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Card ID' },
{ tag = 'argtd', content = 'card id' }
})
:addRow({
{ tag = 'th', content = 'Character' },
{ tag = 'argtd', content = 'character' }
})
:addRow({
{ tag = 'th', content = 'Attribute' },
{ tag = 'argtd', content = 'attribute' }
})
:addRow({
{ tag = 'th', content = 'Rarity' },
{ tag = 'argtd', content = 'rarity' }
})
:addRow({
{ tag = 'th', content = 'Unit' },
{ tag = 'argtd', content = 'unit' }
})
:addRow(
{
{ tag = 'th', content = 'Support unit' },
{ tag = 'argtd', content = 'support unit' }
},
{ hideIfEmpty = { 'support unit' } }
)
:addHeader({ tag = 'th', content = 'Acquisition Information' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Status' },
{ tag = 'argtd', content = 'status' }
})
:addRow({
{ tag = 'th', content = 'Release date' },
{ tag = 'argtd', content = 'date' }
})
:addRow({
{ tag = 'th', content = 'Acquisition method(s)' },
{ tag = 'argtd', content = 'obtain' }
})
:addRow(
{
{ tag = 'th', content = 'Associated event' },
{ tag = 'argtd', content = 'event' }
},
{ hideIfEmpty = { 'event' } }
)
:addRow(
{
{ tag = 'th', content = 'Debut gacha' },
{ tag = 'argtd', content = 'banner' }
},
{ hideIfEmpty = { 'banner' } }
)
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Cards]]" .. infobox:getCategories()
end
return infobox:tostring() .. categories
end
return p