Module:Infobox costume

From Sekaipedia
Revision as of 08:11, 22 January 2022 by ChaoticShadow (talk | contribs) (add categories)

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


--------------------------
-- Module for [[Template:Infobox costume]]
------------------------
local getArgs   = require('Module:Arguments').getArgs
local yesno     = require('Module:Yesno')
local builder   = require('Module:InfoboxBuilder new')

local p = {}

local function formatImage(image_name)
	return string.format("[[File:%s|128px]]", image_name)
end

local function formatLink(link)
	return '[[' .. link .. ']]'
end

local function formatAccessory(accessory)
	-- probably should not use == with bool, but this is more explicit
	if accessory == true then
		return '✓'
	elseif accessory == false then
		return '✗'
	end
	
	return nil
end

local function getAccessoryClass(accessory)
	-- probably should not use == with bool, but this is more explicit
	if accessory == true then
		return 'true-cell'
	elseif accessory == false then
		return 'false-cell'
	end
	
	return nil
end

local function convertToBoolOrNil(val)
	return yesno(val, nil)
end


function p.main(frame)
	local args = getArgs(frame, { wrappers = { 'Template:Infobox costume' } })
	local infobox = builder.new()
	
	infobox:setName('Infobox costume')
		:setParams{
			{ name = 'costume id' },
			{ name = 'costume name', default = mw.title.getCurrentTitle().text },
			{ name = 'thumbnail', dFunc = formatImage },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'gender' },
			{ name = 'designer' },
			{ name = 'date' },
			{ name = 'unlock' },
			{ name = 'acquire' },
			{ name = 'price' },
			{ name = 'card', dFunc = formatLink },
			{ name = 'pass' },
			{ name = 'accessory', pFunc = convertToBoolOrNil, dFunc = formatAccessory },
			{ name = 'unique accessory', pFunc = convertToBoolOrNil, dFunc = formatAccessory },
			{ name = 'unique hair', pFunc = convertToBoolOrNil, dFunc = formatAccessory },
		}
		:setArgs(args)
		:processArgs()
		:setCategoryMap({
			['gender'] = {
				['Ladies'] = 'Ladies\' costumes',
				['Men']    = 'Men\'s costumes'
			},
			['accessory'] = {
				[true] = 'Costumes with accessories',
			},
			['unique accessory'] = {
				[true] = 'Costumes with unique accessories'
			},
			['unique hair'] = {
				[true] = 'Costumes with unique hair'
			},
		})


	infobox
		:addHeader({ tag = 'argth', content = 'costume name' })
		:addImage({
			{ tag = 'argtd', content = 'thumbnail' },
		})
		: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 = 'Costume Information' }, { subheader = true })
		:addRow({
			{ tag = 'th', content = 'Gender' },
			{ tag = 'argtd', content = 'gender' }
		})
		:addRow(
			{
				{ tag = 'th', content = 'Designer' },
				{ tag = 'argtd', content = 'designer' }
			},
			{ hideIfEmpty = { 'designer' } }
		)
		:addHeader({ tag = 'th', content = 'Acquisition Information'}, { subheader = true })
		:addRow({
			{ tag = 'th', content = 'Release date' },
			{ tag = 'argtd', content = 'date' },
		})
		:addRow({
			{ tag = 'th', content = 'Unlock method(s)' },
			{ tag = 'argtd', content = 'unlock' }
		})
		:addRow({
			{ tag = 'th', content = 'Acquition method(s)' },
			{ tag = 'argtd', content = 'acquire' },
		})
		:addRow(
			{
				{ tag = 'th', content = 'Price' },
				{ tag = 'argtd', content = 'price' }
			},
			{ hideIfEmpty = { 'price' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Associated card' },
				{ tag = 'argtd', content = 'card' }
			},
			{ hideIfEmpty = { 'card' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Mission Pass' },
				{ tag = 'argtd', content = 'pass' }
			},
			{ hideIfEmpty = { 'pass' } }
		)
		:addHeader({ tag = 'th', content = 'Accessory & Hair Information' }, { subheader = true })
		:addRow(
			{
				{ tag = 'th', content = 'Accessory' },
				{ tag = 'th', content = 'Unique Accessory' },
				{ tag = 'th', content = 'Unique Hair' },
			},
			{ defaultCss = { ['text-align'] = 'center'	} }
		)
		:addRow(
			{
				{ tag = 'argtd', content = 'accessory', classFunc = getAccessoryClass },
				{ tag = 'argtd', content = 'unique accessory', classFunc = getAccessoryClass },
				{ tag = 'argtd', content = 'unique hair', classFunc = getAccessoryClass }
			},
			{ defaultCss = { ['text-align'] = 'center' } }
		)
	
	local categories = ""
	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Costumes]]" .. infobox:getCategories()
	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.