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

Module:Infobox card: Difference between revisions

From Sekaipedia
Content added Content deleted
mNo edit summary
mNo edit summary
 
(42 intermediate revisions by 2 users not shown)
Line 1:
--------------------------
-- Module for [[Template:Infobox Cardcard]]
------------------------
local buildergetArgs = require('Module:InfoboxBuilderArguments').getArgs
local constantsQueryBuilder = require('Module:ConstantsQueryBuilder')
local utils InfoboxBuilder = require('Module:UtilitiesInfoboxBuilder')
local iconsDisplayFns = require('Module:IconsDisplayFunctions')._main
local ProcessingFns = require('Module:ProcessingFunctions')
 
local aicon = require('Module:Attribute icon')._main
local cicon = require('Module:Character icon')._main
local ricon = require('Module:Rarity icon')._main
local uicon = require('Module:Unit icon')._main
local VariablesLua = mw.ext.VariablesLua
 
local p = {}
local categories = ""
 
local function formatImage(image_name)
return string.format("[[File:%s|156px]]", image_name)
end
 
local function formatAttribute(attribute)
if attribute and attribute ~= '' then
return string.format(
"%s [[%s]]",
iconsaicon({ attribute, size = '20px' }) or '',
utils.capitalize(attribute)
)
end
Line 29:
local function formatCharacter(character)
if character and charater ~= '' then
return string.format(
local icon = icons({ character, size = '20px' })
"%s [[%s]]",
if icon then
cicon({ character, size = '20px' }) or '',
return string.format(
character
"%s [[%s]]",
icon,)
character
)
end
return '[[' .. character .. ']]'
end
return nil
end
 
local function formatRarity(rarity)
if rarity and rarity ~= '' then
ifreturn tonumberricon({ rarity), and'20px' })
tonumber(rarity) >= 1 and
tonumber(rarity) <= 4 then
return icons({ rarity .. " star", size = '20px' })
elseif rarity == 'birthday' then
return icons({ rarity, size = '20px' }) .. ' Birthday'
end
end
 
Line 60 ⟶ 51:
return string.format(
"%s [[%s]]",
iconsuicon({ unit, size = '20px' }) or '',
constants.get_unit(unit)
)
end
return nil
end
 
local function formatBreakCommasformatEventId(valid)
local qb = QueryBuilder.new()
if val then
qb
local split_val = mw.text.split(val, ',')
:setTables('events')
for i,v in ipairs(split_val) do
:setFields([[
split_val[i] = mw.text.trim(v)
_pageName,
end
event_name,
]])
:setGroupBy('_pageName')
:setLimit(1)
:addWhere('event_id', '=', id)
local result = qb:query()[1]
return table.concat(split_val, "<br>")
if result then
return string.format('[[%s|%s]]', result._pageName, result.event_name)
end
return nil
 
end
 
local function formatToLinkformatGachaId(valid)
local qb = QueryBuilder.new()
if val and val ~= '' then
qb
return '[[' .. val .. ']]'
: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
Line 92 ⟶ 103:
 
function p.main(frame)
local args = getArgs(frame, { wrappers = 'Template:getParent(Infobox card' }).args
local infobox = builderInfoboxBuilder.new()
infobox:setName('Infobox card')
:setWidth("330px")
:setParams{
{ name = 'card id' },
{ name = 'card name', default = mw.title.getCurrentTitle().text },
{ name = 'thumbnail', func = formatImage },
{ name = 'thumbnail trained', func = formatImage },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'character', func = formatCharacter },
{ name = 'attribute', func = formatAttribute },
{ name = 'rarity', func = formatRarity },
{ name = 'unit', func = formatUnit },
{ name = 'support unit' , func = formatUnit},
{ name = 'status' },
{ name = 'date' },
{ name = 'obtainacquire', func fn = formatBreakCommasProcessingFns.stringToArray(',') },
{ name = 'event id', funcdFunc = formatToLinkformatEventId },
{ name = 'bannergacha id', funcdFunc = formatToLinkformatGachaId },
-- Compatability args
{ name = 'obtain', fn = ProcessingFns.stringToArray(',') },
{ name = 'event' },
{ name = 'banner' },
{ name = 'gacha' },
}
:setArgs(args)
:processArgs()
:setHeaderColorsByParam('attribute', constants.get_attribute_colors)
: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',
['Bloom Festival limited'] = 'Bloom Festival limited cards',
['Birthday limited'] = 'Birthday limited cards',
}
})
 
infobox
:addHeader({ tag = 'argth', content = 'card name' })
:addImage({
{
{ tag = 'argtd', content = 'thumbnail', title = 'Untrained' },
{ tag = 'argtd', content = 'thumbnail trained', title = 'Trained' }
tabName = 'Untrained',
fn = DisplayFns.image('156px')
},
{
tag = 'argtd',
content = 'thumbnail trained',
tabName = 'Trained',
fn = DisplayFns.image('156px')
}
})
:addRow(
{
{ tag = 'th', content = 'Japanese', colspan = 12 },
{ tag = 'argtd', content = 'japanese', colspan = 18 }
},
{ hideIfEmpty = { 'japanese' } }
Line 135 ⟶ 220:
:addRow(
{
{ tag = 'th', content = 'Romaji', colspan = 12 },
{ tag = 'argtd', content = 'romaji', colspan = 18 }
},
{ hideIfEmpty = { 'romaji' } }
Line 142 ⟶ 227:
:addHeader({ tag = 'th', content = 'Card Information' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'CharacterCard ID', colspan = 12 },
{ tag = 'argtd', content = 'charactercard id', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'AttributeCharacter', colspan = 12 },
{ tag = 'argtd', content = 'attributecharacter', colspanfn = 18formatCharacter }
})
:addRow({
{ tag = 'th', content = 'RarityAttribute', colspan = 12 },
{ tag = 'argtd', content = 'rarityattribute', colspanfn = 18formatAttribute }
})
:addRow({
{ tag = 'th', content = 'UnitRarity', colspan = 12 },
{ tag = 'argtd', content = 'unitrarity', colspanfn = 18formatRarity }
})
:addRow({
{ tag = 'th', content = 'Unit' },
{ tag = 'argtd', content = 'unit', fn = formatUnit }
})
:addRow(
{
{ tag = 'th', content = 'Support Unitunit', colspan = 12 },
{ tag = 'argtd', content = 'support unit', colspanfn = 18formatUnit }
},
{ hideIfEmpty = { 'support unit' } }
)
:addHeader({ tag = 'th', content = 'ObtainmentAcquisition Information' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Status', colspan = 12 },
{ tag = 'argtd', content = 'status', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Release Datedate', colspan = 12 },
{ tag = 'argtd', content = 'date', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Obtainment Method(s)', colspan = 12 },
{ tag = 'argtd', content = 'obtain', colspan = 18 }
})
:addRow(
{
{ tag = 'th', content = 'AssociatedAcquisition Eventmethod(s)', colspan = 12 },
{ tag = 'argtd', content = 'eventobtain', colspanfn = 18DisplayFns.list('unbulleted') }
},
{ hideIfEmpty = { 'obtain' } }
)
:addRow(
{
{
tag = 'argth',
content = 'acquire',
fn = DisplayFns.pluralHeader({ 'Acquisition method', 'Acquisition methods' })
},
{
tag = 'argtd',
content = 'acquire',
fn = DisplayFns.list('unbulleted')
}
},
{ hideIfEmpty = { 'acquire' } }
)
:addRow(
{
{ tag = 'th', content = 'Associated event' },
{ tag = 'argtd', content = 'event', fn = DisplayFns.link }
},
{ hideIfEmpty = { 'event' } }
Line 186 ⟶ 293:
:addRow(
{
{ tag = 'th', content = 'Debut Bannergacha', colspan = 12 },
{ tag = 'argtd', content = 'banner', colspanfn = 18DisplayFns.link }
},
{ hideIfEmpty = { 'banner' } }
)
:addRow(
{
{ tag = 'th', content = 'Debut gacha' },
{ tag = 'argtd', content = 'gacha', fn = DisplayFns.link }
},
{ hideIfEmpty = { 'gacha' } }
)
local categories = ''
if mw.title.getCurrentTitle().namespace == 0 then
categories = "'[[Category:Cards]]"' .. categoriesinfobox:getCategories()
local rawArgs = infobox:getArgsgetRawArgs('raw')
VariablesLua.vardefine( 'card id', rawArgs['card id'] )
ifVariablesLua.vardefine( 'rarity', rawArgs['characterrarity'] then)
categories = categories .. stringVariablesLua.formatvardefine('[[Category:%s cards]]'character', rawArgs['character'] )
VariablesLua.vardefine( 'support unit', rawArgs['support unit'] )
end
VariablesLua.vardefine( 'attribute', rawArgs['attribute'] )
ifVariablesLua.vardefine( 'date', rawArgs['attributedate'] then)
VariablesLua.vardefine( 'event id', rawArgs['event id'] )
local attrs = {
['cool'] = '[[Category:Cool cards]]',
['cute'] = '[[Category:Cute cards]]',
['happy'] = '[[Category:Happy cards]]',
['mysterious'] = '[[Category:Mysterious cards]]',
['pure'] = '[[Category:Pure cards]]'
}
if attrs[rawArgs['attribute']] then
categories = categories .. attrs[rawArgs['attribute']]
end
end
if rawArgs['rarity'] then
local rarities = {
['1'] = '[[Category:1☆ cards]]',
['2'] = '[[Category:2☆ cards]]',
['3'] = '[[Category:3☆ cards]]',
['4'] = '[[Category:4☆ cards]]',
['birthday'] = '[[Category:Birthday cards]]'
}
if rarities[rawArgs['rarity']] then
categories = categories .. rarities[rawArgs['rarity']]
end
end
 
if rawArgs['status'] then
local statuses = {
['Permanent'] = '[[Category:Permanent cards]]',
['Limited'] = '[[Category:Limited cards]]',
['Colorful Festival Limited'] = '[[Category:Colorful Festival limited cards]]',
['Birthday Limited'] = '[[Category:Birthday limited cards]]',
}
if statuses[rawArgs['status']] then
categories = categories .. statuses[rawArgs['status']]
end
end
 
 
end
 

Latest revision as of 14:47, 30 June 2024

--------------------------
-- Module for [[Template:Infobox card]]
------------------------
local getArgs      = require('Module:Arguments').getArgs
local QueryBuilder = require('Module:QueryBuilder')
local InfoboxBuilder = require('Module:InfoboxBuilder')
local DisplayFns     = require('Module:DisplayFunctions')
local ProcessingFns  = require('Module:ProcessingFunctions')
local aicon = require('Module:Attribute icon')._main
local cicon = require('Module:Character icon')._main
local ricon = require('Module:Rarity icon')._main
local uicon = require('Module:Unit icon')._main
local VariablesLua = mw.ext.VariablesLua

local p = {}

local function formatAttribute(attribute)
	if attribute and attribute ~= '' then
		return string.format(
			"%s [[%s]]",
			aicon({ attribute, size = '20px' }) or '',
			attribute
		)
	end
	
	return nil
end

local function formatCharacter(character)
	if character and charater ~= '' then
		return string.format(
			"%s [[%s]]",
			cicon({ character, size = '20px' }) or '',
			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]]",
			uicon({ unit, size = '20px' }) or '',
			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' },
			{ name = 'thumbnail trained' },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'character' },
			{ name = 'attribute' },
			{ name = 'rarity' },
			{ name = 'unit' },
			{ name = 'support unit' },
			{ name = 'status' },
			{ name = 'date' },
			{ name = 'acquire',	fn = ProcessingFns.stringToArray(',') },
			{ name = 'event id', dFunc = formatEventId },
			{ name = 'gacha id', dFunc = formatGachaId },
			-- Compatability args
			{ name = 'obtain', fn = ProcessingFns.stringToArray(',') },
			{ name = 'event' },
			{ name = 'banner' },
			{ name = 'gacha' },
		}
		: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',
				['Bloom Festival limited'] = 'Bloom Festival limited cards',
				['Birthday limited'] = 'Birthday limited cards',
			}
		})

	infobox
		:addHeader({ tag = 'argth', content = 'card name' })
		:addImage({
			{ 
				tag = 'argtd', 
				content = 'thumbnail', 
				tabName = 'Untrained',
				fn = DisplayFns.image('156px')
			},
			{ 
				tag = 'argtd', 
				content = 'thumbnail trained', 
				tabName = 'Trained',
				fn = DisplayFns.image('156px')
			}
		})
		: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', fn = formatCharacter }
		})
		:addRow({
			{ tag = 'th', content = 'Attribute' },
			{ tag = 'argtd', content = 'attribute', fn = formatAttribute }
		})
		:addRow({
			{ tag = 'th', content = 'Rarity' },
			{ tag = 'argtd', content = 'rarity', fn = formatRarity }
		})
		:addRow({
			{ tag = 'th', content = 'Unit' },
			{ tag = 'argtd', content = 'unit', fn = formatUnit }
		})
		:addRow(
			{
				{ tag = 'th', content = 'Support unit' },
				{ tag = 'argtd', content = 'support unit', fn = formatUnit }
			},
			{ 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', fn = DisplayFns.list('unbulleted') }
			},
			{ hideIfEmpty = { 'obtain' } }
		)
		:addRow(
			{
				{
					tag = 'argth', 
					content = 'acquire',
					fn = DisplayFns.pluralHeader({ 'Acquisition method', 'Acquisition methods' })
				},
				{
					tag = 'argtd', 
					content = 'acquire',
					fn = DisplayFns.list('unbulleted')
				}
			},
			{ hideIfEmpty = { 'acquire' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Associated event' },
				{ tag = 'argtd', content = 'event', fn = DisplayFns.link }
			},
			{ hideIfEmpty = { 'event' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Debut gacha' },
				{ tag = 'argtd', content = 'banner', fn = DisplayFns.link }
			},
			{ hideIfEmpty = { 'banner' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Debut gacha' },
				{ tag = 'argtd', content = 'gacha', fn = DisplayFns.link }
			},
			{ hideIfEmpty = { 'gacha' } }
		)
	
	local categories = ''
	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

	return infobox:tostring() .. categories
end

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