Content added Content deleted
(migrated to infoboxbuilder new) Tag: Reverted |
(Undo revision 53915 by ChaoticShadow (talk)) Tag: Undo |
||
Line 4: | Line 4: | ||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local QueryBuilder = require('Module:QueryBuilder') |
local QueryBuilder = require('Module:QueryBuilder') |
||
local InfoboxBuilder = require('Module:InfoboxBuilder |
local InfoboxBuilder = require('Module:InfoboxBuilder') |
||
local |
local DisplayFunctions = require('Module:InfoboxBuilderDisplayFunctions') |
||
local |
local ProcessingFunctions = require('Module:InfoboxBuilderProcessingFunctions') |
||
local utils = require('Module:Utilities') |
|||
local aicon = require('Module:Attribute icon')._main |
local aicon = require('Module:Attribute icon')._main |
||
local cicon = require('Module:Character icon')._main |
local cicon = require('Module:Character icon')._main |
||
local ricon = require('Module:Rarity icon')._main |
local ricon = require('Module:Rarity icon')._main |
||
local |
local icons = require('Module:Icons')._main |
||
local VariablesLua = mw.ext.VariablesLua |
local VariablesLua = mw.ext.VariablesLua |
||
local p = {} |
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 formatAttribute(attribute) |
local function formatAttribute(attribute) |
||
Line 51: | Line 68: | ||
return string.format( |
return string.format( |
||
"%s [[%s]]", |
"%s [[%s]]", |
||
icons({ unit, size = '20px' }), |
|||
unit |
unit |
||
) |
) |
||
Line 110: | Line 127: | ||
{ name = 'card id' }, |
{ name = 'card id' }, |
||
{ name = 'card name', default = mw.title.getCurrentTitle().text }, |
{ name = 'card name', default = mw.title.getCurrentTitle().text }, |
||
⚫ | |||
⚫ | |||
name = 'thumbnail', |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
{ name = 'japanese' }, |
{ name = 'japanese' }, |
||
{ name = 'romaji' }, |
{ name = 'romaji' }, |
||
{ name = 'character' }, |
{ name = 'character', dFunc = formatCharacter }, |
||
{ name = 'attribute' }, |
{ name = 'attribute', dFunc = formatAttribute }, |
||
{ name = 'rarity' }, |
{ name = 'rarity', dFunc = formatRarity }, |
||
{ name = 'unit' }, |
{ name = 'unit', dFunc = formatUnit }, |
||
{ name = 'support unit' }, |
{ name = 'support unit' , dFunc = formatUnit }, |
||
{ name = 'status' }, |
{ name = 'status' }, |
||
{ name = 'date' }, |
{ name = 'date' }, |
||
⚫ | |||
{ name = 'acquire', fn = ProcessingFns.stringToArray(',') }, |
|||
⚫ | |||
pFunc = ProcessingFunctions.convertStringToArray(','), |
|||
dFunc = formatList |
|||
⚫ | |||
{ name = 'event id', dFunc = formatEventId }, |
{ name = 'event id', dFunc = formatEventId }, |
||
{ name = 'gacha id', dFunc = formatGachaId }, |
{ name = 'gacha id', dFunc = formatGachaId }, |
||
{ |
|||
-- Compatability args |
|||
name = 'obtain', |
|||
pFunc = ProcessingFunctions.convertStringToArray(','), |
|||
{ name = 'event' }, |
|||
dFunc = formatList |
|||
}, |
|||
{ name = 'event', dFunc = DisplayFunctions.generateLink }, |
|||
{ name = 'banner', dFunc = DisplayFunctions.generateLink }, |
|||
{ name = 'gacha', dFunc = DisplayFunctions.generateLink }, |
|||
} |
} |
||
:setArgs(args) |
:setArgs(args) |
||
Line 196: | Line 226: | ||
infobox |
infobox |
||
:addHeader({ tag = 'argth', content = 'card name' }) |
:addHeader({ tag = 'argth', content = 'card name' }) |
||
:addImage( |
:addImage( |
||
{ |
{ |
||
tag = 'argtd', |
{ tag = 'argtd', content = 'thumbnail', tabName = 'Untrained' }, |
||
content = 'thumbnail', |
{ tag = 'argtd', content = 'thumbnail trained', tabName = 'Trained' } |
||
tabName = 'Untrained', |
|||
⚫ | |||
⚫ | |||
⚫ | |||
tag = 'argtd', |
|||
content = 'thumbnail trained', |
|||
tabName = 'Trained', |
|||
⚫ | |||
} |
} |
||
) |
|||
:addRow( |
:addRow( |
||
{ |
{ |
||
Line 231: | Line 253: | ||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = 'Character' }, |
{ tag = 'th', content = 'Character' }, |
||
{ tag = 'argtd', content = 'character' |
{ tag = 'argtd', content = 'character' } |
||
}) |
}) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = 'Attribute' }, |
{ tag = 'th', content = 'Attribute' }, |
||
{ tag = 'argtd', content = 'attribute' |
{ tag = 'argtd', content = 'attribute' } |
||
}) |
}) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = 'Rarity' }, |
{ tag = 'th', content = 'Rarity' }, |
||
{ tag = 'argtd', content = 'rarity' |
{ tag = 'argtd', content = 'rarity' } |
||
}) |
}) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = 'Unit' }, |
{ tag = 'th', content = 'Unit' }, |
||
{ tag = 'argtd', content = 'unit' |
{ tag = 'argtd', content = 'unit' } |
||
}) |
}) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Support unit' }, |
{ tag = 'th', content = 'Support unit' }, |
||
{ tag = 'argtd', content = 'support unit' |
{ tag = 'argtd', content = 'support unit' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'support unit' } } |
{ hideIfEmpty = { 'support unit' } } |
||
Line 264: | Line 286: | ||
{ |
{ |
||
{ tag = 'th', content = 'Acquisition method(s)' }, |
{ tag = 'th', content = 'Acquisition method(s)' }, |
||
{ tag = 'argtd', content = 'obtain' |
{ tag = 'argtd', content = 'obtain' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'obtain' } } |
{ hideIfEmpty = { 'obtain' } } |
||
Line 270: | Line 292: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Acquisition method(s)' }, |
|||
⚫ | |||
{ tag = 'argtd', content = 'acquire' } |
|||
⚫ | |||
fn = DisplayFns.pluralHeader({ 'Acquisition method', 'Acquisition methods' }) |
|||
⚫ | |||
⚫ | |||
tag = 'argtd', |
|||
content = 'acquire', |
|||
fn = DisplayFns.list('unbulleted') |
|||
⚫ | |||
}, |
}, |
||
{ hideIfEmpty = { 'acquire' } } |
{ hideIfEmpty = { 'acquire' } } |
||
Line 286: | Line 300: | ||
{ |
{ |
||
{ tag = 'th', content = 'Associated event' }, |
{ tag = 'th', content = 'Associated event' }, |
||
{ tag = 'argtd', content = 'event' |
{ tag = 'argtd', content = 'event' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'event' } } |
{ hideIfEmpty = { 'event' } } |
||
Line 293: | Line 307: | ||
{ |
{ |
||
{ tag = 'th', content = 'Debut gacha' }, |
{ tag = 'th', content = 'Debut gacha' }, |
||
{ tag = 'argtd', content = 'banner' |
{ tag = 'argtd', content = 'banner' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'banner' } } |
{ hideIfEmpty = { 'banner' } } |
||
Line 300: | Line 314: | ||
{ |
{ |
||
{ tag = 'th', content = 'Debut gacha' }, |
{ tag = 'th', content = 'Debut gacha' }, |
||
{ tag = 'argtd', content = 'gacha' |
{ tag = 'argtd', content = 'gacha' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'gacha' } } |
{ hideIfEmpty = { 'gacha' } } |
||
) |
) |
||
⚫ | |||
if mw.title.getCurrentTitle().namespace == 0 then |
if mw.title.getCurrentTitle().namespace == 0 then |
||
categories = "[[Category:Cards]]" .. infobox:getCategories() |
categories = "[[Category:Cards]]" .. infobox:getCategories() |
Revision as of 03:02, 18 October 2022
This module depends on the following other modules: |
To generate {{Infobox card}}, invoke using the main function.
--------------------------
-- Module for [[Template:Infobox card]]
------------------------
local getArgs = require('Module:Arguments').getArgs
local QueryBuilder = require('Module:QueryBuilder')
local InfoboxBuilder = require('Module:InfoboxBuilder')
local DisplayFunctions = require('Module:InfoboxBuilderDisplayFunctions')
local ProcessingFunctions = require('Module:InfoboxBuilderProcessingFunctions')
local utils = require('Module:Utilities')
local aicon = require('Module:Attribute icon')._main
local cicon = require('Module:Character icon')._main
local ricon = require('Module:Rarity icon')._main
local icons = require('Module:Icons')._main
local VariablesLua = mw.ext.VariablesLua
local p = {}
local categories = ""
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 formatAttribute(attribute)
if attribute and attribute ~= '' then
return string.format(
"%s [[%s]]",
aicon({ attribute, size = '20px' }),
attribute
)
end
return nil
end
local function formatCharacter(character)
if character and charater ~= '' then
return string.format(
"%s [[%s]]",
cicon({ character, size = '20px' }),
character
)
end
return nil
end
local function formatRarity(rarity)
if rarity and rarity ~= '' then
return ricon({ rarity, '20px' })
end
return nil
end
local function formatUnit(unit)
if unit and unit ~= '' then
return string.format(
"%s [[%s]]",
icons({ unit, size = '20px' }),
unit
)
end
return nil
end
local function formatEventId(id)
local qb = QueryBuilder.new()
qb
:setTables('events')
:setFields([[
_pageName,
event_name,
]])
:setGroupBy('_pageName')
:setLimit(1)
:addWhere('event_id', '=', id)
local result = qb:query()[1]
if result then
return string.format('[[%s|%s]]', result._pageName, result.event_name)
end
return nil
end
local function formatGachaId(id)
local qb = QueryBuilder.new()
qb
:setTables('gachas')
:setFields([[
_pageName,
gacha_name,
]])
:setGroupBy('_pageName')
:setLimit(1)
:addWhere('gacha_id', '=', id)
local result = qb:query()[1]
if result then
return string.format('[[%s|%s]]', result._pageName, result.gacha_name)
end
return nil
end
function p.main(frame)
local args = getArgs(frame, { wrappers = 'Template:Infobox card' })
local infobox = InfoboxBuilder.new()
infobox:setName('Infobox card')
:setParams{
{ name = 'card id' },
{ name = 'card name', default = mw.title.getCurrentTitle().text },
{
name = 'thumbnail',
dFunc = DisplayFunctions.generateImage('156px')
},
{
name = 'thumbnail trained',
dFunc = DisplayFunctions.generateImage('156px')
},
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'character', dFunc = formatCharacter },
{ name = 'attribute', dFunc = formatAttribute },
{ name = 'rarity', dFunc = formatRarity },
{ name = 'unit', dFunc = formatUnit },
{ name = 'support unit' , dFunc = formatUnit },
{ name = 'status' },
{ name = 'date' },
{
name = 'acquire',
pFunc = ProcessingFunctions.convertStringToArray(','),
dFunc = formatList
},
{ name = 'event id', dFunc = formatEventId },
{ name = 'gacha id', dFunc = formatGachaId },
{
name = 'obtain',
pFunc = ProcessingFunctions.convertStringToArray(','),
dFunc = formatList
},
{ name = 'event', dFunc = DisplayFunctions.generateLink },
{ name = 'banner', dFunc = DisplayFunctions.generateLink },
{ name = 'gacha', dFunc = DisplayFunctions.generateLink },
}
:setArgs(args)
:processArgs()
:setCategoryMap({
['character'] = {
-- VIRTUAL SINGER
['Hatsune Miku'] = 'Hatsune Miku cards',
['Kagamine Rin'] = 'Kagamine Rin cards',
['Kagamine Len'] = 'Kagamine Len cards',
['Megurine Luka'] = 'Megurine Luka cards',
['MEIKO'] = 'MEIKO cards',
['KAITO'] = 'KAITO cards',
-- Leo/need
['Hoshino Ichika'] = 'Hoshino Ichika cards',
['Tenma Saki'] = 'Tenma Saki cards',
['Mochizuki Honami'] = 'Mochizuki Honami cards',
['Hinomori Shiho'] = 'Hinomori Shiho cards',
-- MORE MORE JUMP!
['Hanasato Minori'] = 'Hanasato Minori cards',
['Kiritani Haruka'] = 'Kiritani Haruka cards',
['Momoi Airi'] = 'Momoi Airi cards',
['Hinomori Shizuku'] = 'Hinomori Shizuku cards',
-- Vivid BAD SQUAD
['Azusawa Kohane'] = 'Azusawa Kohane cards',
['Shiraishi An'] = 'Shiraishi An cards',
['Shinonome Akito'] = 'Shinonome Akito cards',
['Aoyagi Toya'] = 'Aoyagi Toya cards',
-- Wonderlands×Showtime
['Tenma Tsukasa'] = 'Tenma Tsukasa cards',
['Otori Emu'] = 'Otori Emu cards',
['Kusanagi Nene'] = 'Kusanagi Nene cards',
['Kamishiro Rui'] = 'Kamishiro Rui cards',
-- 25-ji, Night Code de.
['Yoisaki Kanade'] = 'Yoisaki Kanade cards',
['Asahina Mafuyu'] = 'Asahina Mafuyu cards',
['Shinonome Ena'] = 'Shinonome Ena cards',
['Akiyama Mizuki'] = 'Akiyama Mizuki cards',
},
['attribute'] = {
['Cool'] = 'Cool cards',
['Cute'] = 'Cute cards',
['Happy'] = 'Happy cards',
['Mysterious'] = 'Mysterious cards',
['Pure'] = 'Pure cards',
},
['rarity'] = {
['1'] = '1☆ cards',
['2'] = '2☆ cards',
['3'] = '3☆ cards',
['4'] = '4☆ cards',
['Birthday'] = 'Birthday cards',
},
['status'] = {
['Permanent'] = 'Permanent cards',
['Limited'] = 'Limited cards',
['Colorful Festival limited'] = 'Colorful Festival limited cards',
['Birthday limited'] = 'Birthday limited cards',
}
})
infobox
:addHeader({ tag = 'argth', content = 'card name' })
:addImage(
{
{ tag = 'argtd', content = 'thumbnail', tabName = 'Untrained' },
{ tag = 'argtd', content = 'thumbnail trained', tabName = 'Trained' }
}
)
: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 = 'Card Information' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Card ID' },
{ tag = 'argtd', content = 'card id' }
})
:addRow({
{ tag = 'th', content = 'Character' },
{ tag = 'argtd', content = 'character' }
})
:addRow({
{ tag = 'th', content = 'Attribute' },
{ tag = 'argtd', content = 'attribute' }
})
:addRow({
{ tag = 'th', content = 'Rarity' },
{ tag = 'argtd', content = 'rarity' }
})
:addRow({
{ tag = 'th', content = 'Unit' },
{ tag = 'argtd', content = 'unit' }
})
:addRow(
{
{ tag = 'th', content = 'Support unit' },
{ tag = 'argtd', content = 'support unit' }
},
{ hideIfEmpty = { 'support unit' } }
)
:addHeader({ tag = 'th', content = 'Acquisition Information' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Status' },
{ tag = 'argtd', content = 'status' }
})
:addRow({
{ tag = 'th', content = 'Release date' },
{ tag = 'argtd', content = 'date' }
})
:addRow(
{
{ tag = 'th', content = 'Acquisition method(s)' },
{ tag = 'argtd', content = 'obtain' }
},
{ hideIfEmpty = { 'obtain' } }
)
:addRow(
{
{ tag = 'th', content = 'Acquisition method(s)' },
{ tag = 'argtd', content = 'acquire' }
},
{ hideIfEmpty = { 'acquire' } }
)
:addRow(
{
{ tag = 'th', content = 'Associated event' },
{ tag = 'argtd', content = 'event' }
},
{ hideIfEmpty = { 'event' } }
)
:addRow(
{
{ tag = 'th', content = 'Debut gacha' },
{ tag = 'argtd', content = 'banner' }
},
{ hideIfEmpty = { 'banner' } }
)
:addRow(
{
{ tag = 'th', content = 'Debut gacha' },
{ tag = 'argtd', content = 'gacha' }
},
{ hideIfEmpty = { 'gacha' } }
)
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Cards]]" .. infobox:getCategories()
local rawArgs = infobox:getRawArgs()
VariablesLua.vardefine( 'card id', rawArgs['card id'] )
VariablesLua.vardefine( 'rarity', rawArgs['rarity'] )
VariablesLua.vardefine( 'character', rawArgs['character'] )
VariablesLua.vardefine( 'support unit', rawArgs['support unit'] )
VariablesLua.vardefine( 'attribute', rawArgs['attribute'] )
VariablesLua.vardefine( 'date', rawArgs['date'] )
VariablesLua.vardefine( 'event id', rawArgs['event id'] )
end
local viewerLink = ''
if tonumber(args['card id']) then
viewerLink = frame:expandTemplate{
title = 'Sekai Viewer card link'
}
end
return infobox:tostring() .. categories .. viewerLink
end
return p