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

Module:Infobox virtual live: Difference between revisions

From Sekaipedia
Content added Content deleted
mNo edit summary
mNo edit summary
 
(35 intermediate revisions by 2 users not shown)
Line 1: Line 1:
--------------------------
--------------------------
-- Module for [[Template:Infobox Virtual Live]]
-- Module for [[Template:Infobox virtual live]]
------------------------
------------------------
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local builder = require('Module:InfoboxBuilder')
local InfoboxBuilder = require('Module:InfoboxBuilder')
local utils = require('Module:Utilities')
local DisplayFns = require('Module:DisplayFunctions')
local icons = require('Module:Icons')._main
local ProcessingFns = require('Module:ProcessingFunctions')
local cargo = mw.ext.cargo
local QueryBuilder = require('Module:QueryBuilder')
local cicon = require('Module:Character icon')._main


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

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

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


local function formatCharacters(characters)
local function formatCharacters(characters)
if characters == nil then return nil end
local characterArr = utils.split(characters, ',')
local resArr = {}
local resArr = {}
for i,v in ipairs(characterArr) do
for i,v in ipairs(characters) do
table.insert(resArr, icons({ v, size = '30px' }))
table.insert(resArr, cicon({ v, size = '30px' }))
end
end
return table.concat(resArr, " ")
return table.concat(resArr, ' ')
end
end


local function formatSongs(song_ids)
local function formatSongs(song_ids)
local idsArr = utils.split(song_ids, ',')
if song_ids == nil or song_ids == '' then return nil end
local queryArr = {}
for i,v in ipairs(idsArr) do
table.insert(queryArr, 'song_id = ' .. v)
end
local tables = 'Songs'
local qb = QueryBuilder.new()
qb
local fields = 'song_name, _pageName'
:setTables('songs')
local args = {
:setFields([[
where = table.concat(queryArr, " OR ")
_pageName,
}
song_name,
local results = cargo.query( tables, fields, args )
]])
:setGroupBy('_pageName')
:addWhereList('song_id', '=', song_ids, ',', 'OR')
local results = qb:query()
if #results > 0 then
if #results > 0 then
Line 56: Line 50:
end
end
return table.concat(resArr, "<br>")
return DisplayFns.list('unbulleted')(resArr)
end
end
return nil
return nil
end

local function formatStampId(id)
local qb = QueryBuilder.new()
qb
:setTables('stamps')
:setFields([[
image,
japanese,
english
]])
:setLimit(1)
:addWhere('stamp_id', '=', id)
local results = qb:query()
if #results > 0 then
local result = results[1]
return string.format(
'[[File:%s|125px|center]]<div>%s</div><div>(%s)</div>',
result.image,
result.english,
result.japanese
)
end
return nil
end

local function formatTitleId(id)
end
end


Line 65: Line 90:
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 Virtual Live')
infobox:setName('Infobox virtual live')
:setWidth("330px")
:setParams{
:setParams{
{ name = 'vlive id' },
{ name = 'vlive id' },
{ name = 'vlive name', default = mw.title.getCurrentTitle().text },
{ name = 'vlive name', default = mw.title.getCurrentTitle().text },
{ name = 'image', func = formatImage },
{ name = 'image' },
{ name = 'japanese' },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'romaji' },
{ name = 'from' },
{ name = 'from' },
{ name = 'until' },
{ name = 'until' },
{ name = 'characters', func = formatCharacters },
{ name = 'characters', fn = ProcessingFns.stringToArray(';') },
{ name = 'song ids', func = formatSongs },
{ name = 'song ids' },
{ name = 'stamp', func = formatRewardImage },
{ name = 'stamp' },
{ name = 'title', func = formatRewardImage },
{ name = 'stamp id' },
{ name = 'title' },
{ name = 'rewards' }
}
}
:setArgs(args)
:setArgs(args)
:processArgs()


infobox
infobox
:addHeader({ tag = 'argth', content = 'vlive name' })
:addHeader({ tag = 'argth', content = 'vlive name' })
:addImage({
:addImage({
{ tag = 'argtd', content = 'image' },
{ tag = 'argtd', content = 'image', fn = DisplayFns.image('250px') },
})
})
: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 98: Line 125:
: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 106: Line 133:
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'From', colspan = 12 },
{ tag = 'th', content = 'From' },
{ tag = 'argtd', content = 'from', colspan = 18 }
{ tag = 'argtd', content = 'from' }
}
}
)
)
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Until', colspan = 12 },
{ tag = 'th', content = 'Until' },
{ tag = 'argtd', content = 'until', colspan = 18 }
{ tag = 'argtd', content = 'until' }
}
}
)
)
Line 119: Line 146:
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Featured Characters ', colspan = 12 },
{ tag = 'th', content = 'Featured characters ' },
{ tag = 'argtd', content = 'characters', colspan = 18 }
{ tag = 'argtd', content = 'characters', fn = formatCharacters }
}
}
)
)
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Featured Songs', colspan = 12 },
{ tag = 'th', content = 'Featured songs' },
{ tag = 'argtd', content = 'song ids', colspan = 18 }
{ tag = 'argtd', content = 'song ids', fn = formatSongs }
}
}
)
)
:addHeader(
:addHeader(
{ tag = 'th', content = 'Reward Stamp' },
{ tag = 'th', content = 'Reward Stamp' },
{ hideIfEmpty = { 'stamp' }, subheader = true }
{ hideIfEmpty = { 'stamp', 'stamp id' }, subheader = true }
)
)
:addImage(
:addImage(
{
{
{ tag = 'argtd', content = 'stamp' },
{ tag = 'argtd', content = 'stamp', fn = DisplayFns.image('150px') },
},
},
{ hideIfEmpty = { 'stamp' } }
{ hideIfEmpty = { 'stamp' } }
)
:addRow(
{
{ tag = 'argtd', content = 'stamp id', fn = formatStampId },
},
{
defaultCss = { ['text-align'] = 'center' },
hideIfEmpty = { 'stamp id' }
}
)
)
:addHeader(
:addHeader(
Line 145: Line 181:
:addImage(
:addImage(
{
{
{ tag = 'argtd', content = 'title' },
{ tag = 'argtd', content = 'title', fn = DisplayFns.image('150px') },
},
},
{ hideIfEmpty = { 'title' } }
{ hideIfEmpty = { 'title' } }
)
:addHeader(
{ tag = 'th', content = 'Additional Rewards' },
{ hideIfEmpty = { 'rewards' }, subheader = true }
)
:addImage(
{
{ tag = 'argtd', content = 'rewards', fn = DisplayFns.image('65px') },
},
{ hideIfEmpty = { 'rewards' } }
)
)


local categories = ""
if mw.title.getCurrentTitle().namespace == 0 then
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Virtual lives]]" .. categories
categories = "[[Category:Virtual lives]]" .. infobox:getCategories()
local procArgs = infobox:getArgs('processed')
local rawArgs = infobox:getArgs('raw')
end
end



Latest revision as of 23:03, 7 May 2024

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


--------------------------
-- Module for [[Template:Infobox virtual live]]
------------------------
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 cicon  = require('Module:Character icon')._main

local p = {}

local function formatCharacters(characters)
	if characters == nil then return nil end
	
	local resArr = {}
	for i,v in ipairs(characters) do
		table.insert(resArr, cicon({ v, size = '30px' }))
	end
	
	return table.concat(resArr, ' ')
end

local function formatSongs(song_ids)
	if song_ids == nil or song_ids == '' then return nil end
	
	local qb = QueryBuilder.new()
	qb
		:setTables('songs')
		:setFields([[
			_pageName,
			song_name,
		]])
		:setGroupBy('_pageName')
		:addWhereList('song_id', '=', song_ids, ',', 'OR')
	
    local results = qb:query()
	
	if #results > 0 then
		local resArr = {}
		for i,v in ipairs(results) do
			table.insert(
				resArr,
				string.format(
					'[[%s|%s]]',
					v._pageName,
					v.song_name
				)
			)
		end
		
		return DisplayFns.list('unbulleted')(resArr)
	end
	
	return nil
end

local function formatStampId(id)
	local qb = QueryBuilder.new()
	qb
		:setTables('stamps')
		:setFields([[
			image,
			japanese,
			english
		]])
		:setLimit(1)
		:addWhere('stamp_id', '=', id)
	
	local results = qb:query()
	
	if #results > 0 then
		local result = results[1]
		return string.format(
			'[[File:%s|125px|center]]<div>%s</div><div>(%s)</div>',
			result.image,
			result.english,
			result.japanese
		)
	end
	
	return nil
end

local function formatTitleId(id)
	
end


function p.main(frame)
	local args = getArgs(frame)
	local infobox = InfoboxBuilder.new()
	
	infobox:setName('Infobox virtual live')
		:setParams{
			{ name = 'vlive id' },
			{ name = 'vlive name', default = mw.title.getCurrentTitle().text },
			{ name = 'image' },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'from' },
			{ name = 'until' },
			{ name = 'characters', fn = ProcessingFns.stringToArray(';') },
			{ name = 'song ids' },
			{ name = 'stamp' },
			{ name = 'stamp id' },
			{ name = 'title' },
            { name = 'rewards' }
		}
		:setArgs(args)
		:processArgs()

	infobox
		:addHeader({ tag = 'argth', content = 'vlive name' })
		:addImage({
			{ tag = 'argtd', content = 'image', fn = DisplayFns.image('250px') },
		})
		: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 = 'Availability Period' }, { subheader = true })
		:addRow(
			{
				{ tag = 'th', content = 'From' },
				{ tag = 'argtd', content = 'from' }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Until' },
				{ tag = 'argtd', content = 'until' }
			}
		)
		:addHeader({ tag = 'th', content = 'Virtual Live Information' }, { subheader = true })
		:addRow(
			{
				{ tag = 'th', content = 'Featured characters ' },
				{ tag = 'argtd', content = 'characters', fn = formatCharacters }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Featured songs' },
				{ tag = 'argtd', content = 'song ids', fn = formatSongs }
			}
		)
		:addHeader(
			{ tag = 'th', content = 'Reward Stamp' },
			{ hideIfEmpty = { 'stamp', 'stamp id' }, subheader = true }
		)
		:addImage(
			{
				{ tag = 'argtd', content = 'stamp', fn = DisplayFns.image('150px') },
			},
			{ hideIfEmpty = { 'stamp' } }
		)
		:addRow(
			{
				{ tag = 'argtd', content = 'stamp id', fn = formatStampId },
			},
			{ 
				defaultCss = { ['text-align'] = 'center' },
				hideIfEmpty = { 'stamp id' }
			}
		)
		:addHeader(
			{ tag = 'th', content = 'Reward Title' },
			{ hideIfEmpty = { 'title' }, subheader = true }
		)
		:addImage(
			{
				{ tag = 'argtd', content = 'title', fn = DisplayFns.image('150px') },
			},
			{ hideIfEmpty = { 'title' } }
		)
		:addHeader(
			{ tag = 'th', content = 'Additional Rewards' },
			{ hideIfEmpty = { 'rewards' }, subheader = true }
		)
		:addImage(
			{
				{ tag = 'argtd', content = 'rewards', fn = DisplayFns.image('65px') },
			},
			{ hideIfEmpty = { 'rewards' } }
		)

	local categories = ""
	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Virtual lives]]" .. 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.