More actions
Content deleted Content added
remove information about event boost, refer to section on pages instead |
m boost => bonus |
||
Line 135: | Line 135: | ||
{ tag = 'argtd', content = 'type', colspan = 18 } |
{ tag = 'argtd', content = 'type', colspan = 18 } |
||
}) |
}) |
||
:addHeader({ tag = 'th', content = 'Event |
:addHeader({ tag = 'th', content = 'Event Bonus' }, { subheader = true }) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = ' |
{ tag = 'th', content = 'Bonus Characters', colspan = 12 }, |
||
{ tag = 'argtd', content = 'characters', colspan = 18 } |
{ tag = 'argtd', content = 'characters', colspan = 18 } |
||
}) |
}) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = ' |
{ tag = 'th', content = 'Bonus Attribute', colspan = 12 }, |
||
{ tag = 'argtd', content = 'attribute', colspan = 18 } |
{ tag = 'argtd', content = 'attribute', colspan = 18 } |
||
}) |
}) |
Revision as of 16:17, 20 October 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|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 = 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 = 'Start Date', colspan = 12 },
{ tag = 'argtd', content = 'start', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'End Date', 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 Bonus' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Bonus Characters', colspan = 12 },
{ tag = 'argtd', content = 'characters', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Bonus Attribute', colspan = 12 },
{ tag = 'argtd', content = 'attribute', colspan = 18 }
})
: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 formatUnit(rawArgs['unit focus']) then
categories = categories .. "[[Category:" .. formatUnit(rawArgs['unit focus']) .. " events]]"
end
end
return infobox:tostring() .. categories
end
return p