Module:Infobox character: Difference between revisions

From Sekaipedia
Content added Content deleted
mNo edit summary
(added new parameter)
Line 21: Line 21:


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


Line 65: Line 65:
local infobox = builder.new();
local infobox = builder.new();
infobox:setName('Infobox Group')
infobox:setName('Infobox Character')
:setWidth("330px")
:setWidth("330px")
infobox:setParams{
infobox:setParams{
Line 83: Line 83:
{ name = 'dislikes', func = breakLine },
{ name = 'dislikes', func = breakLine },
{ name = 'color', func = formatColor },
{ name = 'color', func = formatColor },
{ name = 'bad at', func = breakLine },
{ name = 'seiyuu' }
{ name = 'seiyuu' }
}
}
Line 175: Line 176:
{ tag = 'argtd', content = 'color', colspan = 18 }
{ tag = 'argtd', content = 'color', colspan = 18 }
}
}
)
:addRow(
{
{ tag = 'th', content = 'Bad at', colspan = 12 },
{ tag = 'argtd', content = 'bad at', colspan = 18 }
},
{ hideIfEmpty = { 'bad at' } }
)
)
:addRow(
:addRow(

Revision as of 06:46, 3 July 2021

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


--------------------------
-- Module for [[Template:Infobox Character]]
------------------------
local builder = require('Module:InfoboxBuilder')

local p = {}
local categories = ""

-- https://stackoverflow.com/questions/1426954/split-string-in-lua
local function split(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={}
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        table.insert(t, str)
    end
    return t
end


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

local function formatUnit(unit)
	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.' }
	}
	
	if units[unit] then
		return string.format("[[File:%s|150px|link=%s]]",
			units[unit].image,
			units[unit].link)
	end
	
	return nil
end

local function formatColor(color)
	return string.format(
		"%s <span style=\"height: 10px; width: 10px; background: %s; display: inline-block;margin-left: 5px;\"></span>",
		color,
		color
	);
end

local function breakLine(arg)
	if arg and arg ~= '' then
		return table.concat(split(arg, "\n"), "<br>")
	else
		return "<br>"
	end
end



function p.main(frame)
	local args = frame:getParent().args
	local infobox = builder.new();
	
	infobox:setName('Infobox Character')
		:setWidth("330px")
	infobox:setParams{
		{ name = 'character name', default = mw.title.getCurrentTitle().text },
		{ name = 'character image', func = formatImage },
		{ name = 'japanese' },
		{ name = 'romaji' },
		{ name = 'english' },
		{ name = 'unit', func = formatUnit },
		{ name = 'position' },
		{ name = 'gender' },
		{ name = 'birthday' },
		{ name = 'height' },
		{ name = 'school', func = breakLine },
		{ name = 'hobbies', func = breakLine },
		{ name = 'talents', func = breakLine },
		{ name = 'dislikes', func = breakLine },
		{ name = 'color', func = formatColor },
		{ name = 'bad at', func = breakLine },
		{ name = 'seiyuu' }
	}
	
	infobox
		:setArgs(args)
	
	if args['color'] and args['color'] ~= '' then
		infobox:setHeaderBackgroundColor(args['color'])
	end

	infobox
		:addHeader({ tag = 'argth', content = 'character name' })
		:addImage{{ tag = 'argtd', content = 'character image' }}
		:addRow(
			{
				{ tag = 'th', content = 'Japanese', colspan = 12 },
				{ tag = 'argtd', content = 'japanese', colspan = 18 }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Romaji', colspan = 12 },
				{ tag = 'argtd', content = 'romaji', colspan = 18 }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'English', colspan = 12 },
				{ tag = 'argtd', content = 'english', colspan = 18 }
			}
		)
		:addHeader({ tag = 'th', content = 'Unit'})
		:addImage{{ tag = 'argtd', content = 'unit' }}
		:addRow(
			{
				{ tag = 'th', content = 'Position', colspan = 12 },
				{ tag = 'argtd', content = 'position', colspan = 18 }
			},
			{ hideIfEmpty = { 'position' } }
		)
		:addHeader({ tag = 'th', content = 'Profile' })
		:addRow(
			{
				{ tag = 'th', content = 'Gender', colspan = 12 },
				{ tag = 'argtd', content = 'gender', colspan = 18 }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Birthday', colspan = 12 },
				{ tag = 'argtd', content = 'birthday', colspan = 18 }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Height', colspan = 12 },
				{ tag = 'argtd', content = 'height', colspan = 18 }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'School', colspan = 12 },
				{ tag = 'argtd', content = 'school', colspan = 18 }
			},
			{ hideIfEmpty = { 'school' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Hobbies', colspan = 12 },
				{ tag = 'argtd', content = 'hobbies', colspan = 18 }
			},
			{ hideIfEmpty = { 'hobbies' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Talents', colspan = 12 },
				{ tag = 'argtd', content = 'talents', colspan = 18 }
			},
			{ hideIfEmpty = { 'talents' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Dislikes', colspan = 12 },
				{ tag = 'argtd', content = 'dislikes', colspan = 18 }
			},
			{ hideIfEmpty = { 'dislikes' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Image Color', colspan = 12 },
				{ tag = 'argtd', content = 'color', colspan = 18 }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Bad at', colspan = 12 },
				{ tag = 'argtd', content = 'bad at', colspan = 18 }
			},
			{ hideIfEmpty = { 'bad at' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Seiyuu', colspan = 12 },
				{ tag = 'argtd', content = 'seiyuu', colspan = 18 }
			}
		)
		
	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Characters]]" .. 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.