Welcome to the Umamusume Wiki! If you want to contribute, please read the guidelines.

Module:Lyrics

From Umamusume Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:Lyrics/doc

local p = {}
local cargo = mw.ext.cargo
local Colors = require('Module:Colors')

local function query(charName, subColor)
	if not charName or charName == "" then
		return nil, nil
	end
	local query = {
		limit = '1',
		where = 'name_en="' .. charName .. '"',
	}
	local fields = {'color_main', 'color_sub', 'name_en'}
	local characters = cargo.query('Characters',
		table.concat(fields, ','), query)

	if characters and characters[1] then
		local color = subColor and characters[1].color_sub or characters[1].color_main
		local name = characters[1].name_en
		return color, name
	else
		return nil, nil
	end
end

local function subCheck(charName)
	if charName:sub(-1) == "-" then
		return charName:sub(1, -2), true
	else
		return charName, false
	end
end

function p.multicc(frame)
	local text = frame.args[1]
	local args = { ["text"] = text }
	
	for i = 2, 5 do
		local charName = frame.args[i]
        if charName then
			charName, subcolor = subCheck(charName)
        	
			local color, name = query(charName, subcolor)
			
			if color then
				color = Colors.findHighContrastColor(color, 'ffffff')
			end
			args["c" .. (i - 1)] = color
		    args["ch" .. (i - 1)] = name
		end
	end

	local template = frame:expandTemplate{
		title='Multicc/text',
		args=args
	}
	return template
end

function p.lyrics(frame)
	local text = frame.args[1]
	local charName = frame.args[2]
	local color = "000" --fallback
	if charName then
		charName, subcolor = subCheck(charName)
		
		local checkColor = query(charName, subcolor)
		
		if color then
			color = checkColor
		end
	end

	local contrastingColor = Colors.findHighContrastColor(color, 'ffffff')
	local template = frame:expandTemplate{
		title='Clr/text',
		args={
			color_main=contrastingColor,
			text=text
		}
	}
	return template
end

function p.singers(frame)
	local result = {}
	
	for i = 1, 15 do
		local charName = frame.args[i]
		if charName and charName ~= "" then
			charName, subcolor = subCheck(charName)
			
			local color, name = query(charName, subcolor)
			
			local contrastingColor = Colors.findHighContrastColor(color, 'ffffff')
			mw.log(color, contrastingColor, name)

        	local colorname = string.format('<span style="color:#%s;">%s</span>', contrastingColor, charName)
            table.insert(result, colorname)
		end
	end
	return table.concat(result, ' · ')
end

return p