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
Revision as of 03:21, 10 June 2021 by ChaoticShadow (talk | contribs) (added rarity row, stats section)
--------------------------
-- Module for [[Template:Infobox Card]]
------------------------

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

local p = {}
local _frame
local width = '300px'

local root

local colors = {
	cute       = { bg = '#ff70a8', text = '#ffffff' },
	cool       = { bg = '#435cff', text = '#ffffff'},
	pure       = { bg = '#00bf51', text = '#ffffff'},
	happy      = { bg = '#ff9821', text = '#ffffff'},
	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 = 300
	
	if untrained and rarity then
		local images = 
			string.format(
				'Untrained=[[File:%s|%dpx]]', 
				untrained, 
				image_size)
			.. 
			'<br><br>'
			..
			_frame:expandTemplate({
				title = 'Icons',
				args = { string.format("%sstar", rarity), size = '20px'}
			})
		
		if tonumber(rarity) > 2 then
			images = 
				images 
				..
				string.format(
					'|-|Trained=[[File:%s|%dpx]]',
					trained,
					image_size)
				.. 
				'<br><br>'
				..
				_frame:expandTemplate({
					title = 'Icons',
					args = { string.format("%sstar awakened", rarity), size = '20px'}
				})
		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
	
	if unit == 'vs' and subunit and units[subunit] then
		local subunit_info = units[subunit]
		root:tag('tr')
		:tag('td')
			:attr('colspan', 30)
			:css('text-align', 'center')
			:wikitext(
				string.format(
					"[[File:%s|100px|link=%s]]",
					subunit_info.image,
					subunit_info.link
				))
	end
end

local function addAttribute(attr)
	if attr then
		addRow(
			'Attribute',
			_frame:expandTemplate({
				title = 'Icons',
				args = { attr, size='20px' }
			}) .. ' ' .. attr:sub(1, 1):upper() .. attr:sub(2, -1)
		)
	end
end

local function addRarity(rarity)
	if rarity then
		addRow(
			'Rarity',
			_frame:expandTemplate({
				title = 'Icons',
				args = { string.format("%sstar", rarity), size = '20px'}
			})
		)
	end
end

local function addSideStories(story1, story2)
	root:tag('tr')
			:tag('td')
				:attr('colspan', 15)
				:tag('div')
					:css({
						['background-color'] = palette.bg,
						['text-align'] = 'center',
						padding = '5px',
						['border-radius'] = '5px',
						margin = '2px'
					})
					:wikitext(string.format(
						'[[%s|<span style="color:%s">Side Story 1</span>]]',
						story1 or '/Side Story 1',
						palette.text))
					:done()
				:done()
			:tag('td')
				:attr('colspan', 15)
				:tag('div')
					:css({
						['background-color'] = palette.bg,
						['text-align'] = 'center',
						padding = '5px',
						['border-radius'] = '5px',
						margin = '2px'
					})
					:wikitext(string.format(
						'[[%s|<span style="color:%s">Side Story 2</span>]]',
						story2 or '/Side Story 2',
						palette.text))
					:done()
				:done()
		
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['attribute'] and colors[args['attribute']] then
		palette = colors[args['attribute']]
	end
	
	root = mw.html.create('table')
	root
		:addClass('infobox')
		:css('width', width)
	
	addHeader(args['title'])
	addCardArt(args['rarity'], args['untrained'], args['trained'])
	addRow('Japanese', args['japanese'])
	addRow('Romaji', args['romaji'])
	
	addHeader('Unit')
	addUnit(args['unit'], args['subunit'])
	
	addHeader('Card Information')
	addRow('Character', args['character'])
	addAttribute(args['attribute'])
	addRarity(args['rarity'])
	addRow('Status', args['status'])
	addRow('Card Debut', args['debut'])
	addRow('Release Date', args['date'])
	
	addHeader('Card Stats')
	addRow('Performance', 0)
	addRow('Technique', 0)
	addRow('Stamina', 0)
	addRow('Power', 0)
	
	addHeader('Side Stories')
	addSideStories(args['story 1'], args['story 2'])
	
	local spacer = root:tag('tr')
	for i=1,30,1 do
		spacer:tag('td')
			:attr('colspan', 1)
			:css('width', 'calc(100% / 30)')
	end
	
	return tostring(root)
end

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