From 0b13efd0b5e4c2d6c591955b4b328290e100e148 Mon Sep 17 00:00:00 2001 From: JonKazama-Hellion Date: Tue, 5 May 2026 10:21:46 +0200 Subject: [PATCH] feat(util): add HexToRgba parser for theme JSON --- HellionChat/Util/ColourUtil.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/HellionChat/Util/ColourUtil.cs b/HellionChat/Util/ColourUtil.cs index 63214f0..3373700 100755 --- a/HellionChat/Util/ColourUtil.cs +++ b/HellionChat/Util/ColourUtil.cs @@ -62,4 +62,20 @@ internal static class ColourUtil { return ((uint) a << 24) | ((uint) nb << 16) | ((uint) ng << 8) | nr; } + + public static uint HexToRgba(string hex) + { + ArgumentNullException.ThrowIfNull(hex); + var s = hex.StartsWith('#') ? hex[1..] : hex; + if (s.Length != 6 && s.Length != 8) + throw new FormatException($"Hex colour must be 6 or 8 hex digits, got {s.Length}: '{hex}'"); + + if (!uint.TryParse(s, System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture, out var value)) + throw new FormatException($"Hex colour '{hex}' is not a valid hexadecimal value"); + + if (s.Length == 6) + value = (value << 8) | 0xFFu; // RRGGBB → RRGGBBFF + + return value; + } }