Content added Content deleted
(migrated to infoboxbuilder) |
(migrated to infoboxbuilder new) |
||
Line 3: | Line 3: | ||
------------------------ |
------------------------ |
||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local InfoboxBuilder |
local InfoboxBuilder = require('Module:InfoboxBuilder new') |
||
local |
local DisplayFns = require('Module:InfoboxBuilderDisplayFunctions') |
||
local |
local ProcessingFns = require('Module:InfoboxBuilderProcessingFunctions') |
||
local QueryBuilder = require('Module:QueryBuilder') |
local QueryBuilder = require('Module:QueryBuilder') |
||
local cicon = require('Module:Character icon')._main |
local cicon = require('Module:Character icon')._main |
||
local utils = require('Module:Utilities') |
local utils = require('Module:Utilities') |
||
local icons = require('Module:Icons')._main |
|||
local p = {} |
local p = {} |
||
⚫ | |||
local function formatList(list) |
local function formatList(list) |
||
Line 85: | Line 83: | ||
if result then |
if result then |
||
return string.format('[[File:%s|150px|center]]<br>%s |
return string.format('[[File:%s|150px|center]]<br>%s<br>(%s)', result.image, result.english, result.japanese) |
||
end |
end |
||
Line 104: | Line 102: | ||
{ name = 'vlive id' }, |
{ name = 'vlive id' }, |
||
{ name = 'vlive name', default = mw.title.getCurrentTitle().text }, |
{ name = 'vlive name', default = mw.title.getCurrentTitle().text }, |
||
{ name = 'image' |
{ name = 'image' }, |
||
{ name = 'japanese' }, |
{ name = 'japanese' }, |
||
{ name = 'romaji' }, |
{ name = 'romaji' }, |
||
{ name = 'from' }, |
{ name = 'from' }, |
||
{ name = 'until' }, |
{ name = 'until' }, |
||
{ name = 'characters', |
{ name = 'characters', fn = ProcessingFns.stringToArray(';') }, |
||
{ name = 'song ids' |
{ name = 'song ids' }, |
||
{ name = 'stamp' |
{ name = 'stamp' }, |
||
{ name = 'stamp id' |
{ name = 'stamp id' }, |
||
{ name = 'title' |
{ name = 'title' }, |
||
} |
} |
||
:setArgs(args) |
:setArgs(args) |
||
Line 121: | Line 119: | ||
: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( |
||
Line 154: | Line 152: | ||
{ |
{ |
||
{ tag = 'th', content = 'Featured characters ' }, |
{ tag = 'th', content = 'Featured characters ' }, |
||
{ tag = 'argtd', content = 'characters' } |
{ tag = 'argtd', content = 'characters', fn = formatCharacters } |
||
} |
} |
||
) |
) |
||
Line 160: | Line 158: | ||
{ |
{ |
||
{ tag = 'th', content = 'Featured songs' }, |
{ tag = 'th', content = 'Featured songs' }, |
||
{ tag = 'argtd', content = 'song ids' } |
{ tag = 'argtd', content = 'song ids', fn = formatSongs } |
||
} |
} |
||
) |
) |
||
Line 169: | Line 167: | ||
:addImage( |
:addImage( |
||
{ |
{ |
||
{ tag = 'argtd', content = 'stamp' }, |
{ tag = 'argtd', content = 'stamp', fn = DisplayFns.image('150px') }, |
||
}, |
}, |
||
{ hideIfEmpty = { 'stamp' } } |
{ hideIfEmpty = { 'stamp' } } |
||
Line 175: | Line 173: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'argtd', content = 'stamp id' }, |
{ tag = 'argtd', content = 'stamp id', fn = formatStampId }, |
||
}, |
}, |
||
{ hideIfEmpty = { 'stamp id' } } |
{ hideIfEmpty = { 'stamp id' } } |
||
Line 185: | Line 183: | ||
:addImage( |
:addImage( |
||
{ |
{ |
||
{ tag = 'argtd', content = 'title' }, |
{ tag = 'argtd', content = 'title', fn = DisplayFns.image('150px') }, |
||
}, |
}, |
||
{ hideIfEmpty = { 'title' } } |
{ hideIfEmpty = { 'title' } } |
||
) |
) |
||
⚫ | |||
if mw.title.getCurrentTitle().namespace == 0 then |
if mw.title.getCurrentTitle().namespace == 0 then |
||
categories = "[[Category:Virtual lives]]" .. infobox:getCategories() |
categories = "[[Category:Virtual lives]]" .. infobox:getCategories() |
Revision as of 03:36, 18 October 2022
This module depends on the following other modules: |
![]() | This module uses the following Cargo tables: |
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 new')
local DisplayFns = require('Module:InfoboxBuilderDisplayFunctions')
local ProcessingFns = require('Module:InfoboxBuilderProcessingFunctions')
local QueryBuilder = require('Module:QueryBuilder')
local cicon = require('Module:Character icon')._main
local utils = require('Module:Utilities')
local p = {}
local function formatList(list)
if #list < 2 then
return list[1]
end
local ul = mw.html.create('ul')
for i=1,#list do
ul:tag('li')
:wikitext(list[i])
end
return tostring(ul)
end
local function formatCharacters(characters)
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)
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 formatList(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 result = qb:query()[1]
if result then
return string.format('[[File:%s|150px|center]]<br>%s<br>(%s)', 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' },
}
: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 },
},
{ hideIfEmpty = { 'stamp id' } }
)
:addHeader(
{ tag = 'th', content = 'Reward Title' },
{ hideIfEmpty = { 'title' }, subheader = true }
)
:addImage(
{
{ tag = 'argtd', content = 'title', fn = DisplayFns.image('150px') },
},
{ hideIfEmpty = { 'title' } }
)
local categories = ""
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Virtual lives]]" .. infobox:getCategories()
end
return infobox:tostring() .. categories
end
return p