More actions
Content deleted Content added
m use div to make space |
m test adding unit information |
||
Line 180: | Line 180: | ||
elseif rawArgs['type'] == 'Cheerful Carnival' then |
elseif rawArgs['type'] == 'Cheerful Carnival' then |
||
categories = categories .. "[[Category:Cheerful Carnival events]]" |
categories = categories .. "[[Category:Cheerful Carnival events]]" |
||
end |
|||
if procArgs['unit focus'] == 'Mixed' then |
|||
categories = categories .. "[[Category:Mixed events]]" |
|||
elseif procArgs['unit focus'] == 'Leo/need events' then |
|||
categories = categories .. "[[Category:Leo/need events]]" |
|||
end |
end |
||
end |
end |
Revision as of 02:29, 10 September 2021
This module depends on the following other modules: |
This module uses the following Cargo tables: |
To generate {{Infobox event}}, invoke using the main function.
--------------------------
-- Module for [[Template:Infobox Event]]
------------------------
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 cargo = mw.ext.cargo
local p = {}
local categories = ""
local function formatImage(image_name)
return string.format("[[File:%s|220px]]", image_name)
end
local function formatUnit(unit)
if unit and unit ~= '' then
if string.lower(unit) == 'mixed' then
return 'Mixed'
elseif constants.get_unit(unit) then
return constants.get_unit(unit)
end
end
return nil
end
local function formatCharacters(characters)
local characterArr = utils.split(characters, ',')
local resArr = {}
for i,v in ipairs(characterArr) do
table.insert(resArr, icons({ v, size = '30px' }))
end
return table.concat(resArr, " ")
end
local function formatAttribute(attribute)
return string.format(
"%s %s",
icons({ attribute, size = '30px' }),
utils.capitalize(attribute)
)
end
local function formatEventSong(song_id)
local tables = 'Songs'
local fields = 'song_name, image, _pageName'
local args = {
where = 'song_id = ' .. song_id,
}
local results = cargo.query( tables, fields, args )
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|180px|center]][[%s|%s]]',
result.image,
result._pageName,
result.song_name
))
return tostring(root)
end
return nil
end
function p.main(frame)
local args = getArgs(frame)
local infobox = builder.new()
infobox:setName('Infobox Event')
:setWidth("330px")
:setParams{
{ name = 'event id' },
{ name = 'event name', default = mw.title.getCurrentTitle().text },
{ name = 'image', func = formatImage },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'start' },
{ name = 'end' },
{ name = 'unit focus', func = formatUnit },
{ name = 'type' },
{ name = 'characters', func = formatCharacters },
{ name = 'attribute', func = formatAttribute },
{ name = 'event song id', func = formatEventSong }
}
:setArgs(args)
infobox
:addHeader({ tag = 'argth', content = 'event name' })
:addImage({
{ tag = 'argtd', content = 'image' },
})
: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 = 'Event Information' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Event Start', colspan = 12 },
{ tag = 'argtd', content = 'start', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Event End', colspan = 12 },
{ tag = 'argtd', content = 'end', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Unit Focus', colspan = 12 },
{ tag = 'argtd', content = 'unit focus', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Event Type', colspan = 12 },
{ tag = 'argtd', content = 'type', colspan = 18 }
})
:addHeader({ tag = 'th', content = 'Event Boost' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Boost Characters', colspan = 12 },
{ tag = 'argtd', content = 'characters', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Boost Attribute', colspan = 12 },
{ tag = 'argtd', content = 'attribute', colspan = 18 }
})
:addRow({
{
tag = 'td',
content = [[A card that matches either the character or the
attribute contributes '''+20%''' to your party's event boost]],
css = { ['text-align'] = 'center' }
}
})
:addRow({
{
tag = 'td',
content = [[A card that matches both contributes '''+50%'''.]],
css = { ['text-align'] = 'center' }
}
})
:addHeader(
{ tag = 'th', content = 'Event Song' },
{ hideIfEmpty = { 'event song id' }, subheader = true }
)
:addRow(
{
{ tag = 'argtd', content = 'event song id', css = { ['text-align'] = 'center' } }
},
{ hideIfEmpty = { 'event song id' } }
)
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Events]]" .. categories
local procArgs = infobox:getArgs('processed')
local rawArgs = infobox:getArgs('raw')
if rawArgs['type'] == 'Marathon' then
categories = categories .. "[[Category:Marathon events]]"
elseif rawArgs['type'] == 'Cheerful Carnival' then
categories = categories .. "[[Category:Cheerful Carnival events]]"
end
if procArgs['unit focus'] == 'Mixed' then
categories = categories .. "[[Category:Mixed events]]"
elseif procArgs['unit focus'] == 'Leo/need events' then
categories = categories .. "[[Category:Leo/need events]]"
end
end
return infobox:tostring() .. categories
end
return p