Module:Color: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Sur (talk | contribs)
ported get_slot_color from Utilities, now more generic and supports other key types
 
Sur (talk | contribs)
m redirects for Souls and Healing to their respective key
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
local lang_module = require('Module:Lang')
local p = {}
local p = {}


-- Hash for color values
-- Hash for color values
local colors_data = {
local colors_data = {
["Weapon"] = {
["CitadelCategoryWeapon"] = {
hex = "c97a03",
        hex = "d5903f",
rgb = "201,122,3",
        rgb = "213,144,63",
hsl = "35,97%,40%",
        hsl = "30,70%,54%",
cmyk = "0%,39%,98%,21%"
        cmyk = "0%,32%,70%,16%"
},
    },
["Armor"] = {
["CitadelCategoryArmor"] = {
hex = "659818",
        hex = "74b01c",
rgb = "101,152,24",
        rgb = "116,176,28",
hsl = "82,73%,34%",
        hsl = "88,73%,40%",
cmyk = "34%,0%,84%,40%"
        cmyk = "34%,0%,84%,31%"
},
    },
["Tech"] = {
["CitadelCategoryTech"] = { --spirit
hex = "c288f0", -- purple
hex = "c288f0", -- purple
rgb = "194,136,240",
rgb = "194,136,240",
Line 21: Line 22:
cmyk = "19%,43%,0%,6%"
cmyk = "19%,43%,0%,6%"
},
},
["Souls"] = {
["Citadel_LaneStats_Souls"] = {
         hex = "98ffde",
         hex = "98ffde",
         rgb = "152,255,222",
         rgb = "152,255,222",
Line 27: Line 28:
         cmyk = "40%,0%,13%,0%"
         cmyk = "40%,0%,13%,0%"
     },
     },
     ["Healing"] = {
     ["Citadel_Profile_Stats_Healing"] = {
         hex = "00FF9A",
         hex = "00FF9A",
         rgb = "0,255,154",
         rgb = "0,255,154",
Line 33: Line 34:
         cmyk = "100%,0%,40%,0%"
         cmyk = "100%,0%,40%,0%"
     },
     },
     ["Abrams"] = {
     ["hero_atlas"] = { --abrams
         hex = "2193AE",
         hex = "2193AE",
         rgb = "33,147,174",
         rgb = "33,147,174",
Line 39: Line 40:
         cmyk = "81%,15%,0%,32%"
         cmyk = "81%,15%,0%,32%"
     },
     },
     ["Wraith"] = {
     ["hero_wraith"] = {  
         hex = "954E7A",
         hex = "954E7A",
         rgb = "149,78,122",
         rgb = "149,78,122",
Line 45: Line 46:
         cmyk = "0%,48%,18%,42%"
         cmyk = "0%,48%,18%,42%"
     },
     },
     ["Viscous"] = {
     ["hero_viscous"] = {
         hex = "8AC365",
         hex = "8AC365",
         rgb = "138,195,101",
         rgb = "138,195,101",
Line 51: Line 52:
         cmyk = "29%,0%,48%,24%"
         cmyk = "29%,0%,48%,24%"
     },
     },
     ["Grey Talon"] = {
     ["hero_orion"] = { --grey talon
         hex = "61B083",
         hex = "61B083",
         rgb = "97,176,131",
         rgb = "97,176,131",
Line 57: Line 58:
         cmyk = "45%,0%,26%,31%"
         cmyk = "45%,0%,26%,31%"
     },
     },
     ["Vindicta"] = {
     ["hero_hornet"] = { --vindicta
         hex = "87A8B8",
         hex = "87A8B8",
         rgb = "135,168,184",
         rgb = "135,168,184",
Line 63: Line 64:
         cmyk = "27%,9%,0%,28%"
         cmyk = "27%,9%,0%,28%"
     },
     },
     ["Infernus"] = {
     ["hero_inferno"] = { --infernus
         hex = "FF472E",
         hex = "FF472E",
         rgb = "253,71,46",
         rgb = "253,71,46",
Line 69: Line 70:
         cmyk = "0%,72%,82%,1%"
         cmyk = "0%,72%,82%,1%"
     },
     },
     ["McGinnis"] = {
     ["hero_forge"] = { --mcginnis
         hex = "466A9C",
         hex = "466A9C",
         rgb = "70,106,156",
         rgb = "70,106,156",
Line 75: Line 76:
         cmyk = "55%,32%,0%,39%"
         cmyk = "55%,32%,0%,39%"
     },
     },
     ["Haze"] = {
     ["hero_haze"] = {
         hex = "AE6231",
         hex = "AE6231",
         rgb = "174,98,49",
         rgb = "174,98,49",
Line 81: Line 82:
         cmyk = "0%,44%,72%,32%"
         cmyk = "0%,44%,72%,32%"
     },
     },
     ["Lady Geist"] = {
     ["hero_ghost"] = { --lady geist
         hex = "088A5C",
         hex = "088A5C",
         rgb = "8,138,92",
         rgb = "8,138,92",
Line 87: Line 88:
         cmyk = "94%,0%,33%,46%"
         cmyk = "94%,0%,33%,46%"
     },
     },
     ["Mirage"] = {
     ["hero_mirage"] = {
         hex = "87683C",
         hex = "87683C",
         rgb = "135,104,60",
         rgb = "135,104,60",
Line 93: Line 94:
         cmyk = "0%,23%,56%,47%"
         cmyk = "0%,23%,56%,47%"
     },
     },
     ["Lash"] = {
     ["hero_lash"] = {
         hex = "444C57",
         hex = "444C57",
         rgb = "68,76,87",
         rgb = "68,76,87",
Line 99: Line 100:
         cmyk = "22%,13%,0%,66%"
         cmyk = "22%,13%,0%,66%"
     },
     },
     ["Seven"] = {
     ["hero_gigawatt"] = { --seven
         hex = "EC963F",
         hex = "EC963F",
         rgb = "236,150,63",
         rgb = "236,150,63",
Line 105: Line 106:
         cmyk = "0%,36%,73%,8%"
         cmyk = "0%,36%,73%,8%"
     },
     },
     ["Yamato"] = {
     ["hero_yamato"] = {
         hex = "6F9181",
         hex = "6F9181",
         rgb = "111,145,129",
         rgb = "111,145,129",
Line 111: Line 112:
         cmyk = "23%,0%,11%,43%"
         cmyk = "23%,0%,11%,43%"
     },
     },
     ["Warden"] = {
     ["hero_warden"] = {
         hex = "566279",
         hex = "566279",
         rgb = "86,98,121",
         rgb = "86,98,121",
Line 117: Line 118:
         cmyk = "29%,19%,0%,53%"
         cmyk = "29%,19%,0%,53%"
     },
     },
     ["Bebop"] = {
     ["hero_bebop"] = {
         hex = "A04835",
         hex = "A04835",
         rgb = "160,72,53",
         rgb = "160,72,53",
Line 123: Line 124:
         cmyk = "0%,55%,67%,37%"
         cmyk = "0%,55%,67%,37%"
     },
     },
     ["Paradox"] = {
     ["hero_chrono"] = { --paradox
         hex = "993A53",
         hex = "993A53",
         rgb = "153,58,83",
         rgb = "153,58,83",
Line 129: Line 130:
         cmyk = "0%,62%,46%,40%"
         cmyk = "0%,62%,46%,40%"
     },
     },
     ["Dynamo"] = {
     ["hero_dynamo"] = {
         hex = "D0BA46",
         hex = "D0BA46",
         rgb = "208,186,70",
         rgb = "208,186,70",
Line 135: Line 136:
         cmyk = "0%,11%,66%,18%"
         cmyk = "0%,11%,66%,18%"
     },
     },
     ["Shiv"] = {
     ["hero_shiv"] = {
         hex = "A53D88",
         hex = "A53D88",
         rgb = "165,61,136",
         rgb = "165,61,136",
Line 141: Line 142:
         cmyk = "0%,63%,18%,35%"
         cmyk = "0%,63%,18%,35%"
     }
     }
}
local colors_order = {
"CitadelCategoryWeapon",
"CitadelCategoryArmor",
"CitadelCategoryTech",
"Citadel_LaneStats_Souls",
"Citadel_Profile_Stats_Healing",
"hero_atlas",
"hero_wraith",
"hero_viscous",
"hero_orion",
"hero_hornet",
"hero_inferno",
"hero_forge",
"hero_haze",
"hero_ghost",
"hero_mirage",
"hero_lash",
"hero_gigawatt",
"hero_yamato",
"hero_warden",
"hero_bebop",
"hero_chrono",
"hero_dynamo",
"hero_shiv"
}
}


Line 177: Line 203:
if no_wrap == nil or no_wrap == 'false' or no_wrap == "" then no_wrap = false else no_wrap = true end
if no_wrap == nil or no_wrap == 'false' or no_wrap == "" then no_wrap = false else no_wrap = true end
if debug_mode == nil or debug_mode == 'false' or debug_mode == "" then debug_mode = false end
if debug_mode == nil or debug_mode == 'false' or debug_mode == "" then debug_mode = false end
if (key == "Weapon" or
key == "Armor" or
key == "Tech") then
key = "CitadelCategory" .. key
elseif (key == "Souls") then
key = "Citadel_LaneStats_Souls"
elseif (key == "Healing") then
key = "Citadel_Profile_Stats_Healing"
end
local color_data = colors_data[slot]
local color_data = colors_data[slot]
Line 203: Line 241:
end
end


function p.list_keys(frame)
local ret = ''
for key, value in pairs(colors_data) do
ret = ret .. key .. ", "
end
return frame:preprocess(ret)
end
function p.write_previews(frame)
local ret = ''
-- Add headers
local headers = {"Key", "English", "Hex Code", "Colored div", "Colored Text", "Colored Underline"}
local header_row = ""
for _, header in ipairs(headers) do
header_row = header_row .. "<th>" .. header .. "</th>"
end
header_row = "<tr>" .. header_row .. "</tr>"
-- Add values
local rows = ""
local row
for i, key in ipairs(colors_order) do
local color_data = colors_data[key]
if color_data == nil then return "key " .. key .. " from colors_order is missing in colors_data" end
local hex = color_data['hex']
local english = lang_module.get_string(key, 'en')
row = ''
row = row .. "<td>" .. key .. "</td>"
row = row .. "<td>" .. english .. "</td>"
row = row .. "<td>" .. "#" .. hex .. "</td>"
row = row .. "<td>" .. "<div style=background-color:#" .. hex .. ";>" .. key .. "</div>" .. "</td>"
row = row .. "<td>" .. "<span style=color:#" .. hex .. ";>" .. key .. "</span>" .. "</td>"
row = row .. "<td>" .. '<span style="text-decoration: underline; text-decoration-color: #'..hex..';">' .. key .. "</span>" .. "</td>"
rows = rows .. "<tr>" .. row .. "</tr>"
end
return "<table>" .. header_row .. rows .. "</table>"
end
return p
return p

Latest revision as of 02:03, 3 November 2024

Overview[edit source]

Color related functions for retrieving wiki-standardized colors

Functions[edit source]

get_color[edit source]

Retrieve's the color of a given key in any color format (default hex).

Parameters[edit source]

  • key - key, options are CitadelCategoryTech, hero_lash, CitadelCategoryWeapon, hero_mirage, hero_haze, hero_atlas, hero_inferno, hero_ghost, hero_yamato, hero_dynamo, hero_chrono, hero_bebop, hero_gigawatt, hero_wraith, hero_warden, hero_shiv, CitadelCategoryArmor, hero_orion, Citadel_LaneStats_Souls, hero_hornet, hero_viscous, Citadel_Profile_Stats_Healing, hero_forge,
  • color_format - color format - Defaults to hex. Valid options are hex, rgb, hsl, cmyk
  • no_wrap - (OPTIONAL) - Defaults to false. Set to true to remove prefixes and postfixes of '#' from hex, or 'rgb()', 'hsl()', and 'cmyk()' from the other formats. May be useful for altering the values dynamically
  • debug_mode - (OPTIONAL) - Defaults to false. Used mostly for documentation purposes

Examples[edit source]

See examples at Template:Color

Previews[edit source]

KeyEnglishHex CodeColored divColored TextColored Underline
CitadelCategoryWeaponWeapon#d5903f
CitadelCategoryWeapon
CitadelCategoryWeaponCitadelCategoryWeapon
CitadelCategoryArmorVitality#74b01c
CitadelCategoryArmor
CitadelCategoryArmorCitadelCategoryArmor
CitadelCategoryTechSpirit#c288f0
CitadelCategoryTech
CitadelCategoryTechCitadelCategoryTech
Citadel_LaneStats_SoulsSouls#98ffde
Citadel_LaneStats_Souls
Citadel_LaneStats_SoulsCitadel_LaneStats_Souls
Citadel_Profile_Stats_HealingHealing#00FF9A
Citadel_Profile_Stats_Healing
Citadel_Profile_Stats_HealingCitadel_Profile_Stats_Healing
hero_atlasAbrams#2193AE
hero_atlas
hero_atlashero_atlas
hero_wraithWraith#954E7A
hero_wraith
hero_wraithhero_wraith
hero_viscousViscous#8AC365
hero_viscous
hero_viscoushero_viscous
hero_orionGrey Talon#61B083
hero_orion
hero_orionhero_orion
hero_hornetVindicta#87A8B8
hero_hornet
hero_hornethero_hornet
hero_infernoInfernus#FF472E
hero_inferno
hero_infernohero_inferno
hero_forgeMcGinnis#466A9C
hero_forge
hero_forgehero_forge
hero_hazeHaze#AE6231
hero_haze
hero_hazehero_haze
hero_ghostLady Geist#088A5C
hero_ghost
hero_ghosthero_ghost
hero_mirageMirage#87683C
hero_mirage
hero_miragehero_mirage
hero_lashLash#444C57
hero_lash
hero_lashhero_lash
hero_gigawattSeven#EC963F
hero_gigawatt
hero_gigawatthero_gigawatt
hero_yamatoYamato#6F9181
hero_yamato
hero_yamatohero_yamato
hero_wardenWarden#566279
hero_warden
hero_wardenhero_warden
hero_bebopBebop#A04835
hero_bebop
hero_bebophero_bebop
hero_chronoParadox#993A53
hero_chrono
hero_chronohero_chrono
hero_dynamoDynamo#D0BA46
hero_dynamo
hero_dynamohero_dynamo
hero_shivShiv#A53D88
hero_shiv
hero_shivhero_shiv

local lang_module = require('Module:Lang')
local p = {}

-- Hash for color values
local colors_data = {
	["CitadelCategoryWeapon"] = {
        hex = "d5903f",
        rgb = "213,144,63",
        hsl = "30,70%,54%",
        cmyk = "0%,32%,70%,16%"
    },
	["CitadelCategoryArmor"] = {
        hex = "74b01c",
        rgb = "116,176,28",
        hsl = "88,73%,40%",
        cmyk = "34%,0%,84%,31%"
    },
	["CitadelCategoryTech"] = { --spirit
		hex = "c288f0", -- purple
		rgb = "194,136,240",
		hsl = "276,79%,74%",
		cmyk = "19%,43%,0%,6%"
	},
	["Citadel_LaneStats_Souls"] = {
        hex = "98ffde",
        rgb = "152,255,222",
        hsl = "162,100%,80%",
        cmyk = "40%,0%,13%,0%"
    },
    ["Citadel_Profile_Stats_Healing"] = {
        hex = "00FF9A",
        rgb = "0,255,154",
        hsl = "150,100%,50%",
        cmyk = "100%,0%,40%,0%"
    },
    ["hero_atlas"] = { --abrams
        hex = "2193AE",
        rgb = "33,147,174",
        hsl = "193,68%,41%",
        cmyk = "81%,15%,0%,32%"
    },
    ["hero_wraith"] = { 
        hex = "954E7A",
        rgb = "149,78,122",
        hsl = "320,31%,44%",
        cmyk = "0%,48%,18%,42%"
    },
    ["hero_viscous"] = {
        hex = "8AC365",
        rgb = "138,195,101",
        hsl = "98,47%,58%",
        cmyk = "29%,0%,48%,24%"
    },
    ["hero_orion"] = { --grey talon
        hex = "61B083",
        rgb = "97,176,131",
        hsl = "145,32%,54%",
        cmyk = "45%,0%,26%,31%"
    },
    ["hero_hornet"] = { --vindicta
        hex = "87A8B8",
        rgb = "135,168,184",
        hsl = "202,28%,63%",
        cmyk = "27%,9%,0%,28%"
    },
    ["hero_inferno"] = { --infernus
        hex = "FF472E",
        rgb = "253,71,46",
        hsl = "7,98%,59%",
        cmyk = "0%,72%,82%,1%"
    },
    ["hero_forge"] = { --mcginnis
        hex = "466A9C",
        rgb = "70,106,156",
        hsl = "215,38%,44%",
        cmyk = "55%,32%,0%,39%"
    },
    ["hero_haze"] = {
        hex = "AE6231",
        rgb = "174,98,49",
        hsl = "25,57%,44%",
        cmyk = "0%,44%,72%,32%"
    },
    ["hero_ghost"] = { --lady geist
        hex = "088A5C",
        rgb = "8,138,92",
        hsl = "162,88%,29%",
        cmyk = "94%,0%,33%,46%"
    },
    ["hero_mirage"] = {
        hex = "87683C",
        rgb = "135,104,60",
        hsl = "35,38%,38%",
        cmyk = "0%,23%,56%,47%"
    },
    ["hero_lash"] = {
        hex = "444C57",
        rgb = "68,76,87",
        hsl = "215,12%,30%",
        cmyk = "22%,13%,0%,66%"
    },
    ["hero_gigawatt"] = { --seven
        hex = "EC963F",
        rgb = "236,150,63",
        hsl = "30,83%,59%",
        cmyk = "0%,36%,73%,8%"
    },
    ["hero_yamato"] = {
        hex = "6F9181",
        rgb = "111,145,129",
        hsl = "150,13%,50%",
        cmyk = "23%,0%,11%,43%"
    },
    ["hero_warden"] = {
        hex = "566279",
        rgb = "86,98,121",
        hsl = "220,17%,41%",
        cmyk = "29%,19%,0%,53%"
    },
    ["hero_bebop"] = {
        hex = "A04835",
        rgb = "160,72,53",
        hsl = "11,50%,42%",
        cmyk = "0%,55%,67%,37%"
    },
    ["hero_chrono"] = { --paradox
        hex = "993A53",
        rgb = "153,58,83",
        hsl = "341,45%,41%",
        cmyk = "0%,62%,46%,40%"
    },
    ["hero_dynamo"] = {
        hex = "D0BA46",
        rgb = "208,186,70",
        hsl = "49,62%,54%",
        cmyk = "0%,11%,66%,18%"
    },
    ["hero_shiv"] = {
        hex = "A53D88",
        rgb = "165,61,136",
        hsl = "317,46%,44%",
        cmyk = "0%,63%,18%,35%"
    }
}
local colors_order = {
	"CitadelCategoryWeapon",
	"CitadelCategoryArmor",
	"CitadelCategoryTech",
	"Citadel_LaneStats_Souls",
	"Citadel_Profile_Stats_Healing",
	"hero_atlas",
	"hero_wraith",
	"hero_viscous",
	"hero_orion",
	"hero_hornet",
	"hero_inferno",
	"hero_forge",
	"hero_haze",
	"hero_ghost",
	"hero_mirage",
	"hero_lash",
	"hero_gigawatt",
	"hero_yamato",
	"hero_warden",
	"hero_bebop",
	"hero_chrono",
	"hero_dynamo",
	"hero_shiv"
}

-- Hash for format configuration
local color_formats = {
	hex = {
		prefix = "#",
		postfix = ""
	},
	rgb = {
		prefix = "rgb(",
		postfix = ")"
	},
	hsl = {
		prefix = "hsl(",
		postfix = ")"
	},
	cmyk = {
		prefix = "cmyk(",
		postfix = ")"
	}
}

function p.get_color(key, color_format, no_wrap, debug_mode)
	if type(key) == 'table' and key.args then
		frame = key
		key = frame.args[1]
		color_format = frame.args[2]
		no_wrap = frame.args["no_wrap"]
		debug_mode = frame.args["debug_mode"]
	end
	
	-- Validate arguments
	if key == nil or key == "" then return "'key' parameter must be provided" end
	if color_format == nil or color_format == "" then color_format = "hex" end
	if no_wrap == nil or no_wrap == 'false' or no_wrap == "" then no_wrap = false else no_wrap = true end
	if debug_mode == nil or debug_mode == 'false' or debug_mode == "" then debug_mode = false end
	
	
	if (key == "Weapon" or
		key == "Armor" or
		key == "Tech") then
		key = "CitadelCategory" .. key
	elseif (key == "Souls") then
		key = "Citadel_LaneStats_Souls"
	elseif (key == "Healing") then
		key = "Citadel_Profile_Stats_Healing"
	end
	
	
	local color_data = colors_data[slot]
	if color_data == nil then return "slot '" .. key .. "' was not in slots_data map" end
	
	--Retrieve the color
	local color = color_data[color_format]
	if color == nil then
		return "color_format '" .. color_format .. "' is not in slots_data map"
	end
	
	-- Add prefix and postfix wrapping
	if not no_wrap then
		-- Retrieve prefix and postfix
		prefix = color_formats[color_format]['prefix']
		postfix = color_formats[color_format]['postfix']
		-- Add to color
		color = prefix .. color .. postfix
	end
	
	-- Return result
	if debug_mode then
		return " " .. color
	end
	return color
end

function p.list_keys(frame)
	local ret = ''
	for key, value in pairs(colors_data) do
		ret = ret .. key .. ", "
	end
	return frame:preprocess(ret)
end

function p.write_previews(frame)
	local ret = ''
	
	-- Add headers
	local headers = {"Key", "English", "Hex Code", "Colored div", "Colored Text", "Colored Underline"}
	local header_row = ""
	for _, header in ipairs(headers) do
		header_row = header_row .. "<th>" .. header .. "</th>"
	end
	header_row = "<tr>" .. header_row .. "</tr>"
	
	-- Add values
	local rows = ""
	local row
	for i, key in ipairs(colors_order) do
		local color_data = colors_data[key]
		if color_data == nil then return "key " .. key .. " from colors_order is missing in colors_data" end
		local hex = color_data['hex']
		local english = lang_module.get_string(key, 'en')
		row = ''
		row = row .. "<td>" .. key .. "</td>"
		row = row .. "<td>" .. english .. "</td>"
		row = row .. "<td>" .. "#" .. hex .. "</td>"
		row = row .. "<td>" .. "<div style=background-color:#" .. hex .. ";>" .. key .. "</div>" .. "</td>"
		row = row .. "<td>" .. "<span style=color:#" .. hex .. ";>" .. key .. "</span>" .. "</td>"
		row = row .. "<td>" .. '<span style="text-decoration: underline; text-decoration-color: #'..hex..';">' .. key .. "</span>" .. "</td>"
		rows = rows .. "<tr>" .. row .. "</tr>"
	end
	
	return "<table>" .. header_row .. rows .. "</table>"
end
return p