Module:Infobox character: Difference between revisions

From Sekaipedia
Content added Content deleted
mNo edit summary
No edit summary
 
(21 intermediate revisions by the same user not shown)
Line 1: Line 1:
--------------------------
--------------------------
-- Module for [[Template:Infobox Character]]
-- Module for [[Template:Infobox character]]
------------------------
------------------------
local builder = require('Module:InfoboxBuilder')
local getArgs = require('Module:Arguments').getArgs
local InfoboxBuilder = require('Module:InfoboxBuilder')
local DisplayFns = require('Module:DisplayFunctions')
local ProcessingFns = require('Module:ProcessingFunctions')
local constants = require('Module:Constants')


local p = {}
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|x300px]]", image_name)
end


local function formatUnit(unit)
local function formatUnit(unit)
if unit and unit ~= nil then
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]]",
return string.format("[[File:%s|150px|link=%s]]",
constants.get_unit_image(unit),
units[unit].image,
constants.get_unit(unit))
units[unit].link)
end
end
Line 44: Line 21:


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


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





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


infobox
infobox
:addHeader({ tag = 'argth', content = 'character name' })
:addHeader({ tag = 'argth', content = 'character name' })
:addImage{{ tag = 'argtd', content = 'character image' }}
:addImage{{
tag = 'argtd',
content = 'character image',
fn = DisplayFns.image('315px')
}}
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Japanese', colspan = 12 },
{ tag = 'th', content = 'Japanese' },
{ tag = 'argtd', content = 'japanese', colspan = 18 }
{ tag = 'argtd', content = 'japanese' }
}
}
)
)
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Romaji', colspan = 12 },
{ tag = 'th', content = 'Romaji' },
{ tag = 'argtd', content = 'romaji', colspan = 18 }
{ tag = 'argtd', content = 'romaji' }
}
}
)
)
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'English', colspan = 12 },
{ tag = 'th', content = 'English' },
{ tag = 'argtd', content = 'english', colspan = 18 }
{ tag = 'argtd', content = 'english' }
}
}
)
)
:addHeader({ tag = 'th', content = 'Unit'})
:addHeader({ tag = 'th', content = 'Unit'}, { subheader = true })
:addImage{{ tag = 'argtd', content = 'unit' }}
:addImage{{
tag = 'argtd',
content = 'unit',
fn = formatUnit
}}
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Position', colspan = 12 },
{ tag = 'th', content = 'Position' },
{ tag = 'argtd', content = 'position', colspan = 18 }
{ tag = 'argtd', content = 'position' }
},
},
{ hideIfEmpty = { 'position' } }
{ hideIfEmpty = { 'position' } }
)
)
:addHeader({ tag = 'th', content = 'Profile' })
:addHeader({ tag = 'th', content = 'Profile' }, { subheader = true })
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Gender', colspan = 12 },
{ tag = 'th', content = 'Gender' },
{ tag = 'argtd', content = 'gender', colspan = 18 }
{ tag = 'argtd', content = 'gender' }
}
}
)
)
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Birthday', colspan = 12 },
{ tag = 'th', content = 'Birthday' },
{ tag = 'argtd', content = 'birthday', colspan = 18 }
{ tag = 'argtd', content = 'birthday' }
}
}
)
)
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Height', colspan = 12 },
{ tag = 'th', content = 'Height' },
{ tag = 'argtd', content = 'height', colspan = 18 }
{ tag = 'argtd', content = 'height' }
}
}
)
)
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'School', colspan = 12 },
{ tag = 'th', content = 'School' },
{ tag = 'argtd', content = 'school', colspan = 18 }
{ tag = 'argtd', content = 'school', fn = formatSchool }
},
},
{ hideIfEmpty = { 'school' } }
{ hideIfEmpty = { 'school' } }
Line 151: Line 134:
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Hobbies', colspan = 12 },
{ tag = 'th', content = 'Hobbies' },
{ tag = 'argtd', content = 'hobbies', colspan = 18 }
{ tag = 'argtd', content = 'hobbies', fn = DisplayFns.list('unbulleted') }
},
},
{ hideIfEmpty = { 'hobbies' } }
{ hideIfEmpty = { 'hobbies' } }
Line 158: Line 141:
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Talents', colspan = 12 },
{ tag = 'th', content = 'Talents' },
{ tag = 'argtd', content = 'talents', colspan = 18 }
{ tag = 'argtd', content = 'talents', fn = DisplayFns.list('unbulleted') }
},
},
{ hideIfEmpty = { 'talents' } }
{ hideIfEmpty = { 'talents' } }
Line 165: Line 148:
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Dislikes', colspan = 12 },
{ tag = 'th', content = 'Dislikes' },
{ tag = 'argtd', content = 'dislikes', colspan = 18 }
{ tag = 'argtd', content = 'dislikes', fn = DisplayFns.list('unbulleted') }
},
},
{ hideIfEmpty = { 'dislikes' } }
{ hideIfEmpty = { 'dislikes' } }
Line 172: Line 155:
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Image Color', colspan = 12 },
{ tag = 'th', content = 'Bad at' },
{ tag = 'argtd', content = 'image color', colspan = 18 }
{ tag = 'argtd', content = 'bad at', fn = DisplayFns.list('unbulleted') }
},
{ hideIfEmpty = { 'bad at' } }
)
:addRow(
{
{ tag = 'th', content = 'Image color' },
{ tag = 'argtd', content = 'color', fn = formatColor }
}
}
)
)
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Seiyuu', colspan = 12 },
{ tag = 'th', content = 'Seiyuu' },
{ tag = 'argtd', content = 'seiyuu', colspan = 18 }
{ tag = 'argtd', content = 'seiyuu', fn = DisplayFns.list('unbulleted') }
}
}
)
)
local categories = ""
if mw.title.getCurrentTitle().namespace == 0 then
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Characters]]" .. categories
categories = "[[Category:Characters]]" .. categories

Latest revision as of 15:32, 19 October 2022

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


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

local p = {}

local function formatUnit(unit)
	if unit and unit ~= nil then
		return string.format("[[File:%s|150px|link=%s]]",
			constants.get_unit_image(unit),
			constants.get_unit(unit))
	end
	
	return nil
end

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

local function formatSchool(list)
	if list == nil then return nil end
	
	return table.concat(list, '<br>')
end


function p.main(frame)
	local args = getArgs(frame)
	local infobox = InfoboxBuilder.new();
	
	infobox:setName('Infobox character')
		:setParams{
			{ name = 'character name', default = mw.title.getCurrentTitle().text },
			{ name = 'character image' },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'english' },
			{ name = 'unit' },
			{ name = 'position' },
			{ name = 'gender' },
			{ name = 'birthday' },
			{ name = 'height' },
			{ name = 'school', fn = ProcessingFns.stringToArray('\n') },
			{ name = 'hobbies', fn = ProcessingFns.stringToArray('\n') },
			{ name = 'talents', fn = ProcessingFns.stringToArray('\n') },
			{ name = 'dislikes', fn = ProcessingFns.stringToArray('\n') },
			{ name = 'bad at', fn = ProcessingFns.stringToArray('\n') },
			{ name = 'color' },
			{ name = 'seiyuu', fn = ProcessingFns.stringToArray('\n') }
		}
		:setArgs(args)
		:processArgs()
	
	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',
			fn = DisplayFns.image('315px')
		}}
		:addRow(
			{
				{ tag = 'th', content = 'Japanese' },
				{ tag = 'argtd', content = 'japanese' }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Romaji' },
				{ tag = 'argtd', content = 'romaji' }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'English' },
				{ tag = 'argtd', content = 'english' }
			}
		)
		:addHeader({ tag = 'th', content = 'Unit'}, { subheader = true })
		:addImage{{
			tag = 'argtd',
			content = 'unit',
			fn = formatUnit
		}}
		:addRow(
			{
				{ tag = 'th', content = 'Position' },
				{ tag = 'argtd', content = 'position' }
			},
			{ hideIfEmpty = { 'position' } }
		)
		:addHeader({ tag = 'th', content = 'Profile' }, { subheader = true })
		:addRow(
			{
				{ tag = 'th', content = 'Gender' },
				{ tag = 'argtd', content = 'gender' }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Birthday' },
				{ tag = 'argtd', content = 'birthday' }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Height' },
				{ tag = 'argtd', content = 'height' }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'School' },
				{ tag = 'argtd', content = 'school', fn = formatSchool }
			},
			{ hideIfEmpty = { 'school' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Hobbies' },
				{ tag = 'argtd', content = 'hobbies', fn = DisplayFns.list('unbulleted') }
			},
			{ hideIfEmpty = { 'hobbies' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Talents' },
				{ tag = 'argtd', content = 'talents', fn = DisplayFns.list('unbulleted') }
			},
			{ hideIfEmpty = { 'talents' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Dislikes' },
				{ tag = 'argtd', content = 'dislikes', fn = DisplayFns.list('unbulleted') }
			},
			{ hideIfEmpty = { 'dislikes' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Bad at' },
				{ tag = 'argtd', content = 'bad at', fn = DisplayFns.list('unbulleted') }
			},
			{ hideIfEmpty = { 'bad at' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Image color' },
				{ tag = 'argtd', content = 'color', fn = formatColor }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Seiyuu' },
				{ tag = 'argtd', content = 'seiyuu', fn = DisplayFns.list('unbulleted') }
			}
		)
		
	local categories = ""
	
	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.