Module:Infobox unit

From Sekaipedia

To generate {{Infobox unit}}, invoke using the main function.


--------------------------
-- Module for [[Template:Infobox unit]]
------------------------
local getArgs   = require('Module:Arguments').getArgs
local InfoboxBuilder = require('Module:InfoboxBuilder')
local DisplayFns     = require('Module:DisplayFunctions')
local ProcessingFns  = require('Module:ProcessingFunctions')

local p = {}

local function formatMembers(members)
	local linkedMembers = {}

	for _, member in ipairs(members) do
		table.insert(linkedMembers, "[[" .. member .. "]]")
	end
	
	return DisplayFns.list('unbulleted')(linkedMembers)
end


function p.main(frame)
	local args = getArgs(frame)
	local infobox = InfoboxBuilder.new();
	
	infobox:setName('Infobox unit')
		:setParams{
			{ name = 'name', default = mw.title.getCurrentTitle().text },
			{ name = 'unit image brand new world' },
			{ name = 'unit image' },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'english' },
			{ name = 'logo' },
			{ name = 'members', fn = ProcessingFns.stringToArray(',') },
			{ name = 'virtual singers', fn = ProcessingFns.stringToArray(',') }
		}
		:setArgs(args)
		:processArgs()

	infobox
		:addHeader({ tag = 'argth', content = 'name' })
		:addImage({ 
			{
				tag = 'argtd',
				content = 'unit image brand new world',
				fn = DisplayFns.image('300px'),
				tabName = 'Brand New World'
			},
			{
				tag = 'argtd', 
				content = 'unit image', 
				fn = DisplayFns.image('300px'),
				tabName = 'Original'
			},	
		})
		:addRow(
			{
				{ tag = 'th', content = 'Japanese' },
				{ tag = 'argtd', content = 'japanese' }
			},
			{ hideIfEmpty = { 'japanese' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Romaji' },
				{ tag = 'argtd', content = 'romaji' }
			},
			{ hideIfEmpty = { 'romaji' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'English' },
				{ tag = 'argtd', content = 'english' }
			},
			{ hideIfEmpty = { 'english' } }
		)
		:addHeader({ tag = 'th', content = 'Logo'}, { subheader = true })
		:addImage{{ 
			tag = 'argtd', 
			content = 'logo', 
			fn = DisplayFns.image('200px') 
		}}
		:addHeader({ tag = 'th', content = 'Information' }, { subheader = true })
		:addRow(
			{
				{ tag = 'th', content = 'Members' },
				{ tag = 'argtd', content = 'members', fn = formatMembers }
			},
			{ hideIfEmpty = { 'members' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Virtual Singers' },
				{ tag = 'argtd', content = 'virtual singers', fn = formatMembers }
			},
			{ hideIfEmpty = { 'virtual singers' } }
		)
		
	local categories = ""
	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Units]]" .. categories
	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.