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)
m ChaoticShadow moved page Module:Infobox Event to Module:Infobox event without leaving a redirect
mNo edit summary
Tag: Undo
 
(34 intermediate revisions by 2 users not shown)
Line 3: Line 3:
------------------------
------------------------
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local builder = require('Module:InfoboxBuilder')
local InfoboxBuilder = require('Module:InfoboxBuilder')
local constants = require('Module:Constants')
local DisplayFns = require('Module:DisplayFunctions')
local utils = require('Module:Utilities')
local ProcessingFns = require('Module:ProcessingFunctions')
local icons = require('Module:Icons')._main
local QueryBuilder = require('Module:QueryBuilder')
local cargo = mw.ext.cargo
local aicon = require('Module:Attribute icon')._main
local cicon = require('Module:Character icon')._main
local VariablesLua = mw.ext.VariablesLua


local p = {}
local p = {}
local categories = ""


local function formatImage(image_name)
return string.format("[[File:%s|220px]]", image_name)
end


local function formatUnit(unit)
local function formatCharacters(characters)
if unit and unit ~= '' then
if characters == nil then return nil end
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 = {}
local resArr = {}
for i,v in ipairs(characterArr) do
for _, character in ipairs(characters) do
table.insert(resArr, icons({ v, size = '30px' }))
table.insert(resArr, cicon({ character, size = '30px' }))
end
end
Line 39: Line 26:


local function formatAttribute(attribute)
local function formatAttribute(attribute)
if attribute == nil then return nil end
return string.format(
return string.format(
"%s %s",
"%s %s",
icons({ attribute, size = '30px' }),
aicon({ attribute, size = '30px' }) or '',
utils.capitalize(attribute)
attribute
)
)
end
end


local function formatEventSong(song_id)
local function formatEventSong(songId)
if songId == nil or songId == '' then return nil end
local tables = 'Songs'
local fields = 'song_name, image, _pageName'
local args = {
local qb = QueryBuilder.new()
qb
where = 'song_id = ' .. song_id,
:setTables('songs')
}
:setFields([[
local results = cargo.query( tables, fields, args )
_pageName,
song_name,
jacket
]])
:addWhere('song_id', '=', songId)
local results = qb:query()
if #results > 0 then
if #results > 0 then
Line 63: Line 59:
})
})
:wikitext(string.format(
:wikitext(string.format(
'[[File:%s|180px|center|link=%s]][[%s|%s]]',
'[[File:%s|164px|center|class=notpageimage|link=%s]][[%s|%s]]',
result.image,
result.jacket,
result._pageName,
result._pageName,
result._pageName,
result._pageName,
Line 79: Line 75:
function p.main(frame)
function p.main(frame)
local args = getArgs(frame)
local args = getArgs(frame)
local infobox = builder.new()
local infobox = InfoboxBuilder.new()
infobox:setName('Infobox event')
infobox:setName('Infobox event')
:setWidth("330px")
:setParams{
:setParams{
{ name = 'event id' },
{ name = 'event id' },
{ name = 'event name', default = mw.title.getCurrentTitle().text },
{ name = 'event name', default = mw.title.getCurrentTitle().text },
{ name = 'image', func = formatImage },
{ name = 'image' },
{ name = 'japanese' },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'romaji' },
{ name = 'start' },
{ name = 'start' },
{ name = 'end' },
{ name = 'end' },
{ name = 'unit focus', func = formatUnit },
{ name = 'unit focus' },
{ name = 'type' },
{ name = 'type' },
{ name = 'characters', func = formatCharacters },
{ name = 'characters', fn = ProcessingFns.stringToArray(';') },
{ name = 'attribute', func = formatAttribute },
{ name = 'attribute' },
{ name = 'event song id', func = formatEventSong }
{ name = 'event song id' }
}
}
:setArgs(args)
:setArgs(args)
:processArgs()
:setCategoryMap({
['type'] = {
['Marathon'] = 'Marathon events',
['Cheerful Carnival'] = 'Cheerful Carnival events',
['World Link'] = 'World Link 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',
['All'] = 'Mixed Attribute events'
}
})



infobox
infobox
:addHeader({ tag = 'argth', content = 'event name' })
:addHeader({ tag = 'argth', content = 'event name' })
:addImage({
:addImage({
{ tag = 'argtd', content = 'image' },
{ tag = 'argtd', content = 'image', fn = DisplayFns.image('220px') },
})
})
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Japanese', colspan = 12 },
{ tag = 'th', content = 'Japanese' },
{ tag = 'argtd', content = 'japanese', colspan = 18 }
{ tag = 'argtd', content = 'japanese' }
},
},
{ hideIfEmpty = { 'japanese' } }
{ hideIfEmpty = { 'japanese' } }
Line 113: Line 134:
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Romaji', colspan = 12 },
{ tag = 'th', content = 'Romaji' },
{ tag = 'argtd', content = 'romaji', colspan = 18 }
{ tag = 'argtd', content = 'romaji' }
},
},
{ hideIfEmpty = { 'romaji' } }
{ hideIfEmpty = { 'romaji' } }
Line 120: Line 141:
:addHeader({ tag = 'th', content = 'Event Information' }, { subheader = true })
:addHeader({ tag = 'th', content = 'Event Information' }, { subheader = true })
:addRow({
:addRow({
{ tag = 'th', content = 'Start Date', colspan = 12 },
{ tag = 'th', content = 'Event ID' },
{ tag = 'argtd', content = 'start', colspan = 18 }
{ tag = 'argtd', content = 'event id' }
})
})
:addRow({
:addRow({
{ tag = 'th', content = 'End Date', colspan = 12 },
{ tag = 'th', content = 'Start date' },
{ tag = 'argtd', content = 'end', colspan = 18 }
{ tag = 'argtd', content = 'start' }
})
})
:addRow({
:addRow({
{ tag = 'th', content = 'Unit Focus', colspan = 12 },
{ tag = 'th', content = 'End date' },
{ tag = 'argtd', content = 'unit focus', colspan = 18 }
{ tag = 'argtd', content = 'end' }
})
})
:addRow({
:addRow({
{ tag = 'th', content = 'Event Type', colspan = 12 },
{ tag = 'th', content = 'Unit focus' },
{ tag = 'argtd', content = 'type', colspan = 18 }
{ tag = 'argtd', content = 'unit focus' }
})
:addRow({
{ tag = 'th', content = 'Event type' },
{ tag = 'argtd', content = 'type' }
})
})
:addHeader({ tag = 'th', content = 'Event Bonus' }, { subheader = true })
:addHeader({ tag = 'th', content = 'Event Bonus' }, { subheader = true })
:addRow({
:addRow({
{ tag = 'th', content = 'Bonus Characters', colspan = 12 },
{ tag = 'th', content = 'Bonus characters' },
{ tag = 'argtd', content = 'characters', colspan = 18 }
{ tag = 'argtd', content = 'characters', fn = formatCharacters }
})
})
:addRow({
:addRow({
{ tag = 'th', content = 'Bonus Attribute', colspan = 12 },
{ tag = 'th', content = 'Bonus attribute' },
{ tag = 'argtd', content = 'attribute', colspan = 18 }
{ tag = 'argtd', content = 'attribute', fn = formatAttribute }
})
})
:addHeader(
:addHeader(
Line 150: Line 175:
:addRow(
:addRow(
{
{
{
{ tag = 'argtd', content = 'event song id', css = { ['text-align'] = 'center' } }
tag = 'argtd',
content = 'event song id',
fn = formatEventSong,
css = { ['text-align'] = 'center' }
}
},
},
{ hideIfEmpty = { 'event song id' } }
{ hideIfEmpty = { 'event song id' } }
)
)


local categories = ''
if mw.title.getCurrentTitle().namespace == 0 then
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Events]]" .. categories
categories = '[[Category:Events]]' .. infobox:getCategories()
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
local rawArgs = infobox:getRawArgs()
if formatUnit(rawArgs['unit focus']) then
VariablesLua.vardefine('event id', rawArgs['event id'])
categories = categories .. "[[Category:" .. formatUnit(rawArgs['unit focus']) .. " events]]"
VariablesLua.vardefine('event name', rawArgs['event name'])
end
VariablesLua.vardefine('start date', rawArgs['start'])
VariablesLua.vardefine('end date', rawArgs['end'])
VariablesLua.vardefine('characters', rawArgs['characters'])
VariablesLua.vardefine('attribute', rawArgs['attribute'])
end
end



Latest revision as of 21:17, 22 January 2024

To generate {{Infobox event}}, invoke using the main function.


--------------------------
-- Module for [[Template:Infobox event]]
------------------------
local getArgs   = require('Module:Arguments').getArgs
local InfoboxBuilder = require('Module:InfoboxBuilder')
local DisplayFns     = require('Module:DisplayFunctions')
local ProcessingFns  = require('Module:ProcessingFunctions')
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)
	if characters == nil then return nil end
	
	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)
	if attribute == nil then return nil end
	
	return string.format(
		"%s %s",
		aicon({ attribute, size = '30px' }) or '',
		attribute
	)
end

local function formatEventSong(songId)
	if songId == nil or songId == '' then return nil end
	
	local qb = QueryBuilder.new()
	qb
		:setTables('songs')
		:setFields([[
			_pageName,
			song_name,
			jacket
		]])
		: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.jacket,
				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',
				['World Link']        = 'World Link 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',
				['All']        = 'Mixed Attribute 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('end date', rawArgs['end'])
		VariablesLua.vardefine('characters', rawArgs['characters'])
		VariablesLua.vardefine('attribute', rawArgs['attribute'])
	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.