From 09671b7ac92351e7a7d46c5723c84798111e1787 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 5 Mar 2021 09:37:27 +0100 Subject: [PATCH] Add simple color validator / parser --- mods/CORE/mcl_util/init.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index 6c63c21abe..ec2aa3017d 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -405,3 +405,17 @@ function mcl_util.get_object_center(obj) pos.y = pos.y + (ymax - ymin) / 2.0 return pos end + +function mcl_util.get_color(colorstr) + local mc_color = mcl_colors[colorstr:upper()] + if mc_color then + return mc_color + end + if #colorstr ~= 7 or colorstr:sub(1, 1) ~= "#"then + return + end + local hex = tonumber(colorstr:sub(2, 7), 16) + if hex then + return colorstr, hex + end +end