Module:Infobox costume

From Sekaipedia
Revision as of 18:40, 18 December 2021 by ChaoticShadow (talk | contribs) (add mission pass row)

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')

local p = {}
local categories = ""

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

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

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

local function getAccessoryCss(accessory)
	local val = yesno(accessory, nil)
	-- probably should not use == with bool, but this is more explicit
	if val == true then
		return {
			['background-color'] = 'lightgreen',
			['font-weight'] = 'bold'
		}
	elseif val == false then
		return {
			['background-color'] = 'pink',
			['font-weight'] = 'bold'
		}
	end
	
	return nil
end



function p.main(frame)
	local args = getArgs(frame)
	local infobox = builder.new()
	
	infobox:setName('Infobox costume')
		:setWidth("330px")
		:setParams{
			{ name = 'costume id' },
			{ name = 'costume name', default = mw.title.getCurrentTitle().text },
			{ name = 'thumbnail', func = formatImage },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'gender' },
			{ name = 'designer' },
			{ name = 'date' },
			{ name = 'acquire' },
			{ name = 'price' },
			{ name = 'card', func = formatLink },
			{ name = 'pass' },
			{ name = 'accessory', func = formatAccessory },
			{ name = 'unique accessory', func = formatAccessory },
			{ name = 'unique hair', func = formatAccessory },
		}
		:setArgs(args)

	infobox
		:addHeader({ tag = 'argth', content = 'costume name' })
		:addImage({
			{ tag = 'argtd', content = 'thumbnail' },
		})
		:addRow(
			{
				{ tag = 'th', content = 'Japanese', colspan = 12 },
				{ tag = 'argtd', content = 'japanese', colspan = 18 }
			},
			{ hideIfEmpty = { 'japanese' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Romaji', colspan = 12 },
				{ tag = 'argtd', content = 'romaji', colspan = 18 }
			},
			{ hideIfEmpty = { 'romaji' } }
		)
		:addHeader({ tag = 'th', content = 'Costume Information' }, { subheader = true })
		:addRow({
			{ tag = 'th', content = 'Gender', colspan = 12 },
			{ tag = 'argtd', content = 'gender', colspan = 18 }
		})
		:addRow(
			{
				{ tag = 'th', content = 'Designer', colspan = 12 },
				{ tag = 'argtd', content = 'designer', colspan = 18 }
			},
			{ hideIfEmpty = { 'designer' } }
		)
		:addHeader({ tag = 'th', content = 'Acquisition Information'}, { subheader = true })
		:addRow({
			{ tag = 'th', content = 'Release date', colspan = 12 },
			{ tag = 'argtd', content = 'date', colspan = 18 },
		})
		:addRow({
			{ tag = 'th', content = 'Acquition method(s)', colspan = 12 },
			{ tag = 'argtd', content = 'acquire', colspan = 18 },
		})
		:addRow(
			{
				{ tag = 'th', content = 'Price', colspan = 12 },
				{ tag = 'argtd', content = 'price', colspan = 18 }
			},
			{ hideIfEmpty = { 'price' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Associated card', colspan = 12 },
				{ tag = 'argtd', content = 'card', colspan = 18 }
			},
			{ hideIfEmpty = { 'card' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Mission Pass', colspan = 12 },
				{ tag = 'argtd', content = 'pass', colspan = 18 }
			},
			{ 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' },
			},
			{ default_css = { ['text-align'] = 'center'	} }
		)
		:addRow(
			{
				{ tag = 'argtd', content = 'accessory', param_css = { getAccessoryCss } },
				{ tag = 'argtd', content = 'unique accessory', param_css = { getAccessoryCss } },
				{ tag = 'argtd', content = 'unique hair', param_css = { getAccessoryCss } }
			},
			{ default_css = { ['text-align'] = 'center' } }
		)

		
	
	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Costumes]]" .. categories
		
		local procArgs = infobox:getArgs('processed')
		local rawArgs = infobox:getArgs('raw')
		
		if yesno(rawArgs['accessory'], nil) then
			categories = categories .. "[[Category:Costumes with accessories]]"
		end
		if yesno(rawArgs['unique accessory'], nil) then
			categories = categories .. "[[Category:Costumes with unique accessories]]"
		end
		if yesno(rawArgs['unique hair'], nil) then
			categories = categories .. "[[Category:Costumes with unique hair]]"
		end
		
		if rawArgs['gender'] == 'Ladies' then
			categories = categories .. "[[Category:Ladies' costumes]]"
		elseif rawArgs['gender'] == 'Men' then
			categories = categories .. "[[Category:Men's costumes]]"
		end
	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.