Module:Character Colors: Difference between revisions

From fractalthorns wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:
local colors = {
local colors = {
AEMIL = {
AEMIL = {
eyes = { "red" },
eyes = { "red", "green" },
horns = { '#E29A56' },
horns = { '#E29A56' },
body = { '#56EB8E' }
body = { '#56EB8E' }

Revision as of 20:25, 13 December 2023

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

local p = {}

local colors = {
	AEMIL = {
		eyes = { "red", "green" },
		horns = { '#E29A56' },
		body = { '#56EB8E' }
	}
}

function p.get_table_for_character(frame)
	local character = frame.args[1]
	local result = {}
	
	local append_color_blocks = function(colors, color_type)
		for i, color in pairs(colors[color_type]) do
			local is_hex_code = string.find(color, "#") ~= nil
			if (is_hex_code) then
				result[#result + 1] = '<div style="background-color: ' .. color .. '"><strong><div style="color: white; border: 1px solid gray; padding: 4px 10px;">' .. color .. '</div></strong></div>'
			else
				result[#result + 1] = '<div><strong><div style="border: 2px solid ' .. color .. '; padding: 4px 10px;">' .. color .. '</div></strong></div>'
			end
		end
	end
	
	result[#result + 1] = '{| class="wikitable" style="width: 100%; margin: 0;"'
	result[#result + 1] = '|-'
	result[#result + 1] = '! scope="col" style="width: 50px"; | Eyes'
	result[#result + 1] = '| <div style="display: flex; flex-flow: col">'
	
	append_color_blocks(colors[character], "eyes")
	
	result[#result + 1] = '</div>'
	result[#result + 1] = '|-'
	result[#result + 1] = '! scope="col" style="width: 50px"; | Horns'
	result[#result + 1] = '| <div style="display: flex; flex-flow: col">'
	
	append_color_blocks(colors[character], "horns")
	
	result[#result + 1] = '</div>'
	result[#result + 1] = '|-'
	result[#result + 1] = '! scope="col" style="width: 50px"; | Body'
	result[#result + 1] = '| <div style="display: flex; flex-flow: col">'
	
	append_color_blocks(colors[character], "body")
	
	result[#result + 1] = '</div>'
	result[#result + 1] = '|}'
	
	mw.log(table.concat(result, "\n"))
	
	return table.concat(result, "\n")
end

return p