Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Infobox song

From Sekaipedia
Revision as of 04:38, 18 November 2021 by ChaoticShadow (talk | contribs)

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


--------------------------
-- Module for [[Template:Infobox Song]]
------------------------
local getArgs   = require('Module:Arguments').getArgs
local yesno     = require('Module:Yesno')
local builder   = require('Module:InfoboxBuilder')
local constants = require('Module:Constants')
local utils     = require('Module:Utilities')

local p = {}
local categories = ""

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

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

local function formatUnits(units)
	if units then
		local split_units = mw.text.split(units, ',')
		for i,v in ipairs(split_units) do
			split_units[i] = constants.get_unit(mw.text.trim(v))
		end
		
		return table.concat(split_units, "<br>") 
	end
	
	return nil
end

local function formatNames(names)
	if names then
		local split_names = utils.split(names, ",")
		for i,v in ipairs(split_names) do
			split_names[i] = v:match( "^%s*(.-)%s*$" )
		end
		
		return table.concat(split_names, "<br>")
	end
	
	return nil
end

local function formatMv(mv)
	local val = yesno(mv, 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 getMvCss(mv)
	local val = yesno(mv, 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

local function formatCommissioned(comm)
	local val = yesno(comm, nil)
	if val == true then
		return 'Yes'
	elseif val == false then
		return 'No'
	end
	
	return nil
end

local function difficultiesRow()
	local difficulties = { 'EASY', 'NORMAL', 'HARD', 'EXPERT', 'MASTER' }

	local row = {}
	
	for _,v in ipairs(difficulties) do
		table.insert(row,
			{
				content = v,
				tag = 'th',
				css = {
					['text-align']       = 'center',
					['color']            = '#FFFFFF',
					['border-radius']    = '5px',
					['background-color'] = constants.get_difficulty_color(v)
				}
			}
		)
	end
	
	return row
end


function p.main(frame)
	local args = getArgs(frame, { wrappers = { 'Template:Infobox song/en' } })
	local infobox = builder.new();
	
	infobox:setName('Infobox Song')
		:setWidth("330px")
		:setParams{
			{ name = 'song id' },
			{ name = 'song name', default = mw.title.getCurrentTitle().text },
			{ name = 'image', func = formatImage, default = 'Dummyalbumart.png' },
			{ name = 'image alt', func = formatImage },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'english' },
			{ name = 'singer', func = formatNames },
			{ name = 'producer', func = formatNames },
			{ name = 'unit', func = formatUnits },
			{ name = 'arranger', func = formatNames },
			{ name = 'composer', func = formatNames },
			{ name = 'lyricist', func = formatNames },
			{ name = 'commissioned', func = formatCommissioned },
			{ name = 'bpm' },
			{ name = 'duration' },
			{ name = 'date' },
			{ name = '3d mv', func = formatMv },
			{ name = '2d mv', func = formatMv },
			{ name = 'original mv', func = formatMv },
			{ name = 'easy difficulty' },
			{ name = 'normal difficulty' },
			{ name = 'hard difficulty' },
			{ name = 'expert difficulty' },
			{ name = 'master difficulty' },
			{ name = 'easy notes' },
			{ name = 'normal notes' },
			{ name = 'hard notes' },
			{ name = 'expert notes' },
			{ name = 'master notes' },
		}
		:setArgs(args)

	infobox
		:addHeader({ tag = 'argth', content = 'song name' })
		:addImage(
			{
				{ tag = 'argtd', content = 'image', title = 'Original' },
				{ tag = 'argtd', content = 'image alt', title = 'Alternate' }
			}
		)
		: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' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'English', colspan = 12 },
				{ tag = 'argtd', content = 'english', colspan = 18 }
			},
			{ hideIfEmpty = { 'english' } }
		)
		:addHeader({ tag = 'th', content = 'Song Information' }, { subheader = true })
		:addRow(
			{
				{ tag = 'th', content = 'Original Singer(s)', colspan = 12 },
				{ tag = 'argtd', content = 'singer', colspan = 18 }
			},
			{ hideIfEmpty = { 'singer' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Producer(s)', colspan = 12 },
				{ tag = 'argtd', content = 'producer', colspan = 18 }
			}
		)
		:addHeader({ tag = 'th', content = 'In-game Information' }, { subheader = true })
		:addRow(
			{
				{ tag = 'th', content = 'Unit(s)', colspan = 12 },
				{ tag = 'argtd', content = 'unit', colspan = 18 }
			},
			{ hideIfEmpty = { 'unit' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Arranger(s)', colspan = 12 },
				{ tag = 'argtd', content = 'arranger', colspan = 18 }
			},
			{ hideIfEmpty = { 'arranger' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Composer(s)', colspan = 12 },
				{ tag = 'argtd', content = 'composer', colspan = 18 }
			},
			{ hideIfEmpty = { 'composer' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Lyricist(s)', colspan = 12 },
				{ tag = 'argtd', content = 'lyricist', colspan = 18 }
			},
			{ hideIfEmpty = { 'lyricist' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Commissioned', colspan = 12 },
				{ tag = 'argtd', content = 'commissioned', colspan = 18 }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'BPM', colspan = 12 },
				{ tag = 'argtd', content = 'bpm', colspan = 18 }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Duration', colspan = 12 },
				{ tag = 'argtd', content = 'duration', colspan = 18 }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Release Date', colspan = 12 },
				{ tag = 'argtd', content = 'date', colspan = 18 }
			}
		)
		:addHeader({ tag = 'th', content = 'Music Video' }, { subheader = true })
		:addRow(
			{
				{ tag = 'th', content = '3D' },
				{ tag = 'th', content = '2D' },
				{ tag = 'th', content = 'Original' }
			},
			{ default_css = { ['text-align'] = 'center'	} }
		)
		:addRow(
			{
				{ tag = 'argtd', content = '3d mv', param_css = { getMvCss } },
				{ tag = 'argtd', content = '2d mv', param_css = { getMvCss }  },
				{ tag = 'argtd', content = 'original mv', param_css = { getMvCss }  }
			},
			{ default_css = { ['text-align'] = 'center' } }
		)
		:addHeader({ tag = 'th', content = 'Difficulties' }, { subheader = true })
		:addRow(difficultiesRow())
		:addRow(
			{
				{ tag = 'argtd', content = 'easy difficulty' },
				{ tag = 'argtd', content = 'normal difficulty' },
				{ tag = 'argtd', content = 'hard difficulty' },
				{ tag = 'argtd', content = 'expert difficulty' },
				{ tag = 'argtd', content = 'master difficulty' }
			},
			{ default_css = { ['text-align'] = 'center' } }
		)
		:addHeader({ tag = 'th', content = 'Notes' }, { subheader = true })
		:addRow(difficultiesRow())
		:addRow(
			{
				{ tag = 'argtd', content = 'easy notes' },
				{ tag = 'argtd', content = 'normal notes' },
				{ tag = 'argtd', content = 'hard notes' },
				{ tag = 'argtd', content = 'expert notes' },
				{ tag = 'argtd', content = 'master notes' }
			},
			{ default_css = { ['text-align'] = 'center' } }
		)
	
	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Songs]]" .. categories
		
		local procArgs = infobox:getArgs('processed')
		local rawArgs = infobox:getArgs('raw')
		
		if yesno(rawArgs['commissioned'], nil) then
			categories = categories .. "[[Category:Commissioned Songs]]"
		end
		
		if yesno(rawArgs['3d mv'], nil) then
			categories = categories .. "[[Category:Songs with 3D MV]]"
		end
		if yesno(rawArgs['2d mv'], nil) then
			categories = categories .. "[[Category:Songs with 2D MV]]"
		end
		if yesno(rawArgs['original mv'], nil) then
			categories = categories .. "[[Category:Songs with Original MV]]"
		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.