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

Module:Infobox card

From Sekaipedia
--------------------------
-- Module for [[Template:Infobox Card]]
------------------------

local getArgs = require('Module:Arguments').getArgs

local p = {}
local _frame

local root

local colors = {
	cute       = { bg = '#FF70A8', text = '#FFFFFF' },
	cool       = { bg = '', text = ''},
	pure       = { bg = '', text = ''},
	happy      = { bg = '', text = ''},
	mysterious = { bg = '#8651BC', text = '#FFFFFF' }
}
local palette = { bg = '#000000', text = '#FFFFFF' }

local units = {
	vs       = { image = 'Virtualsingerlogo.png', link = 'VIRTUAL SINGER' },
	ln       = { image = 'Leoneedlogo.png',       link = 'Leo/need' },
	mmj      = { image = 'MMJ_logo.png',          link = 'MORE MORE JUMP!'},
	vbs      = { image = 'Vivid_logo.png',        link = 'Vivid BAD SQUAD'},
	wxs      = { image = 'Wonderlandsxswowtimelogo.png', link = 'Wonderlands×Showtime' },
	['25ji'] = { image = '25ji-logo.png',         link = '25-ji, Night Code de.' }
}

local function addHeader(label)
	root:tag('tr')
		:tag('th')
			:attr('colspan', 30)
			:css({
				['text-align'] = 'center',
				['background-color'] = palette.bg,
				color = palette.text
			})
			:wikitext(label)
end

local function addRow(label, data)
	if data then
		root:tag('tr')
			:attr('id', label)
			:tag('th')
				:attr('colspan', 12)
				:css('text-align', 'left')
				:wikitext(label)
				:done()
			:tag('td')
				:attr('colspan', 18)
				:wikitext(data)
				:done()
	end
end

local function addCardArt(rarity, untrained , trained)
	local image_size = 220
	
	if untrained and rarity then
		local images = string.format(
			'Trained=[[File:%s|%dpx]]', 
			untrained, 
			image_size)
		
		if tonumber(rarity) > 2 and trained then
			images = images . string.format(
				'|-|Untrained=[[File:%s|%dpx]]',
				trained,
				image_size)
		end
			
		root:tag('tr')
			:tag('td')
				:attr('colspan', 30)
				:css('text-align', 'center')
				:wikitext(frame:callParserFunction({
					name = '#tag',
					args = { 'tabber', images }
				}))
	end
end

local function addUnit(unit, subunit)
	if unit and units[unit] then
		local unit_info = units[unit]
		
		root:tag('tr')
			:tag('td')
			:attr('colspan', 30)
			:css('text-align', 'center')
			:wikitext(
				string.format(
					"[[File:%s|150px|link=%s]]",
					unit_info.image,
					unit_info.link
				))
	end
end

local function addAttribute(attr)
	if attr then
		root:tag('tr')
				:tag('td')
				:attr('colspan', 30)
				:css('text-align', 'center')
				:wikitext(
					_frame:expandTemplate({
						title = 'Icons',
						args = { attr, size='20px' }
					})
				)
	end
end

function p.main(frame)
	_frame = frame
	args = getArgs(frame)
	
	if args['bg color'] or args['text color'] then
		if args['bg color'] then
			palette.bg = args['bg color']
		end
		if args['text color'] then
			palette.text = args['text color']
		end
	elseif args.unit and colors[args.unit] then
		palette = colors[args['unit']]
	end
	
	root = mw.html.create('table')
	root
		:addClass('infobox')
		:css('width', width)
	
	addHeader(args['title'])
	addCardArt(args['untrained'], args['trained'])
	addRarity(args['rarity'])
	addRow('Japanese', args['japanese'])
	addRow('Romaji', args['romaji'])
	
	addHeader('Unit')
	addUnit(args['unit'], args['subunit'])
	
	addHeader('Card Information')
	-- addAttribute
	addRow('Character', args['character'])
	addRow('Release Date', args['date'])
	addRow('Status', args['status'])
	addRow('Card Debut', args['debut'])
	addRow('Card ID', args['id'])
	
	addHeader('Side Stories')
	
	local spacer = root:tag('tr')
	for i=1,30,1 do
		spacer:tag('td')
			:attr('colspan', 1)
			:css('width', 'calc(100% / 30)')
	end
	
end

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