Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Infobox event: Difference between revisions

From Sekaipedia
Content deleted Content added
ChaoticShadow (talk | contribs)
No edit summary
ChaoticShadow (talk | contribs)
added virtual singer as event focus
Line 117: Line 117:
},
},
['unit focus'] = {
['unit focus'] = {
['VIRTUAL SINGER'] = 'VIRTUAL SINGER events',
['Leo/need'] = 'Leo/need events',
['Leo/need'] = 'Leo/need events',
['MORE MORE JUMP!'] = 'MORE MORE JUMP! events',
['MORE MORE JUMP!'] = 'MORE MORE JUMP! events',

Revision as of 06:05, 30 March 2022

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 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 cargo     = mw.ext.cargo

local p = {}

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 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' }),
		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

local function splitList(str)
	if str == nil then
		return nil
	end
	
	local list = mw.text.split(str, ',')
	for i=1,#list do
		list[i] = mw.text.trim(list[i])
	end
	
	return list
end



function p.main(frame)
	local args = getArgs(frame)
	local infobox = builder.new()
	
	infobox:setName('Infobox event')
		:setParams{
			{ name = 'event id' },
			{ name = 'event name', default = mw.title.getCurrentTitle().text },
			{ name = 'image', dFunc = formatImage },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'start' },
			{ name = 'end' },
			{ name = 'unit focus', pFunc = formatUnit },
			{ name = 'type' },
			{ name = 'characters', pFunc = splitList, dFunc = formatCharacters },
			{ name = 'attribute', dFunc = formatAttribute },
			{ name = 'event song id', dFunc = formatEventSong }
		}
		: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'
			}
		})


	infobox
		:addHeader({ tag = 'argth', content = 'event name' })
		:addImage({
			{ tag = 'argtd', content = 'image' },
		})
		: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' }
		})
		:addRow({
			{ tag = 'th', content = 'Bonus attribute' },
			{ tag = 'argtd', content = 'attribute' }
		})
		: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' } }
		)

	
	local categories = ""
	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Events]]" .. infobox:getCategories()
	end

	return infobox:tostring() .. categories
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.