--------------------------
-- Module for [[Template:Infobox event]]
------------------------
local getArgs = require('Module:Arguments').getArgs
local InfoboxBuilder = require('Module:InfoboxBuilder new')
local DisplayFns = require('Module:InfoboxBuilderDisplayFunctions')
local ProcessingFns = require('Module:InfoboxBuilderProcessingFunctions')
local QueryBuilder = require('Module:QueryBuilder')
local aicon = require('Module:Attribute icon')._main
local cicon = require('Module:Character icon')._main
local VariablesLua = mw.ext.VariablesLua
local p = {}
local function formatCharacters(characters)
local resArr = {}
for _, character in ipairs(characters) do
table.insert(resArr, cicon({ character, size = '30px' }))
end
return table.concat(resArr, " ")
end
local function formatAttribute(attribute)
return string.format(
"%s %s",
aicon({ attribute, size = '30px' }),
attribute
)
end
local function formatEventSong(songId)
local qb = QueryBuilder.new()
qb
:setTables('Songs')
:setFields([[
_pageName,
song_name,
image
]])
:addWhere('song_id', '=', songId)
local results = qb:query()
if #results > 0 then
local result = results[1]
local root = mw.html.create('div')
:css({
['display'] = 'flex',
['flex-direction'] = 'column',
['gap'] = '10px'
})
:wikitext(string.format(
'[[File:%s|164px|center|class=notpageimage|link=%s]][[%s|%s]]',
result.image,
result._pageName,
result._pageName,
result.song_name
))
return tostring(root)
end
return nil
end
function p.main(frame)
local args = getArgs(frame)
local infobox = InfoboxBuilder.new()
infobox:setName('Infobox event')
:setParams{
{ name = 'event id' },
{ name = 'event name', default = mw.title.getCurrentTitle().text },
{ name = 'image' },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'start' },
{ name = 'end' },
{ name = 'unit focus' },
{ name = 'type' },
{ name = 'characters', fn = ProcessingFns.stringToArray(';') },
{ name = 'attribute' },
{ name = 'event song id' }
}
:setArgs(args)
:processArgs()
:setCategoryMap({
['type'] = {
['Marathon'] = 'Marathon events',
['Cheerful Carnival'] = 'Cheerful Carnival events'
},
['unit focus'] = {
['VIRTUAL SINGER'] = 'VIRTUAL SINGER events',
['Leo/need'] = 'Leo/need events',
['MORE MORE JUMP!'] = 'MORE MORE JUMP! events',
['Vivid BAD SQUAD'] = 'Vivid BAD SQUAD events',
['Wonderlands×Showtime'] = 'Wonderlands×Showtime events',
['25-ji, Nightcord de.'] = '25-ji, Nightcord de. events',
['Mixed'] = 'Mixed events'
},
['attribute'] = {
['Cool'] = 'Cool events',
['Cute'] = 'Cute events',
['Happy'] = 'Happy events',
['Mysterious'] = 'Mysterious events',
['Pure'] = 'Pure events'
}
})
infobox
:addHeader({ tag = 'argth', content = 'event name' })
:addImage({
{ tag = 'argtd', content = 'image', fn = DisplayFns.image('220px') },
})
: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 = 'Event Information' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Event ID' },
{ tag = 'argtd', content = 'event id' }
})
:addRow({
{ tag = 'th', content = 'Start date' },
{ tag = 'argtd', content = 'start' }
})
:addRow({
{ tag = 'th', content = 'End date' },
{ tag = 'argtd', content = 'end' }
})
:addRow({
{ tag = 'th', content = 'Unit focus' },
{ tag = 'argtd', content = 'unit focus' }
})
:addRow({
{ tag = 'th', content = 'Event type' },
{ tag = 'argtd', content = 'type' }
})
:addHeader({ tag = 'th', content = 'Event Bonus' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Bonus characters' },
{ tag = 'argtd', content = 'characters', fn = formatCharacters }
})
:addRow({
{ tag = 'th', content = 'Bonus attribute' },
{ tag = 'argtd', content = 'attribute', fn = formatAttribute }
})
:addHeader(
{ tag = 'th', content = 'Event Song' },
{ hideIfEmpty = { 'event song id' }, subheader = true }
)
:addRow(
{
{
tag = 'argtd',
content = 'event song id',
fn = formatEventSong,
css = { ['text-align'] = 'center' }
}
},
{ hideIfEmpty = { 'event song id' } }
)
local categories = ""
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Events]]" .. infobox:getCategories()
local rawArgs = infobox:getRawArgs()
VariablesLua.vardefine('event id', rawArgs['event id'])
VariablesLua.vardefine('event name', rawArgs['event name'])
VariablesLua.vardefine('start date', rawArgs['start'])
VariablesLua.vardefine('characters', rawArgs['characters'])
VariablesLua.vardefine('attribute', rawArgs['attribute'])
end
return infobox:tostring() .. categories
end
return p