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 04:47, 12 June 2021 by ChaoticShadow (talk | contribs)
--------------------------
-- Module for [[Template:Infobox Card]]
------------------------

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

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

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)
		
		if tonumber(rarity) > 2 then
			images = 
				images 
				..
				string.format(
					'|-|Trained=[[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
	
	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 addStatsRow(label, data1, data2)
	root:tag('tr')
			:attr('id', label)
			:tag('th')
				:attr('colspan', 12)
				:css('text-align', 'left')
				:wikitext(label)
				:done()
			:tag('td')
				:attr('colspan', 9)
				:wikitext(data1)
				:done()
			:tag('td')
				:attr('colspan', 9)
				:wikitext(data2)
				:done()
end

local function addStats(
	rarity,
	min_performance, max_performance,
	min_technique, max_technique,
	min_stamina, max_stamina)

	local levels = {
		['1'] = 20,
		['2'] = 30,
		['3'] = 50,
		['4'] = 60
	}

	local stats = {
		performance = {
			['min'] = tonumber(min_performance) or 0,
			['max'] = tonumber(max_performance) or 0
		},
		technique = {
			['min'] = tonumber(min_technique) or 0,
			['max'] = tonumber(max_technique) or 0
		},
		stamina = {
			['min'] = tonumber(min_stamina) or 0,
			['max'] = tonumber(max_stamina) or 0
		},
	}
	stats['power'] = {
		['min'] = stats['performance']['min'] + stats['technique']['min'] + stats['stamina']['min'],
		['max'] = stats['performance']['max'] + stats['technique']['max'] + stats['stamina']['max']
	}

	addHeader('Card Stats')
	addStatsRow('', 'Lvl. 1', 'Lvl. ' .. levels[rarity])
	addStatsRow('Performance', stats['performance']['min'], stats['performance']['max'])
	addStatsRow('Technique', stats['technique']['min'], stats['technique']['max'])
	addStatsRow('Stamina', stats['stamina']['min'], stats['stamina']['max'])
	addStatsRow('Power', stats['power']['min'], stats['power']['max'])
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'])
	
	addStats(
		args['rarity'],
		args['min performance'], args['max performance'],
		args['min technique'], args['max technique'],
		args['min stamina'], args['max stamina']
	)
	
	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.