From 5687f800a1f518133e7517a32d13f36db08d0b12 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Wed, 29 Dec 2021 15:28:12 +1000 Subject: [PATCH] Allow `"#RRGGBB"` format when parsing colours ("luacolor" in docs) --- src/BizHawk.Client.Common/lua/LuaDocumentation.cs | 2 +- src/BizHawk.Client.Common/lua/NLuaTableHelper.cs | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/BizHawk.Client.Common/lua/LuaDocumentation.cs b/src/BizHawk.Client.Common/lua/LuaDocumentation.cs index 9392975901..819a39d980 100644 --- a/src/BizHawk.Client.Common/lua/LuaDocumentation.cs +++ b/src/BizHawk.Client.Common/lua/LuaDocumentation.cs @@ -33,7 +33,7 @@ namespace BizHawk.Client.Common * luacolor ** Any of: ** a 32-bit number in the format 0xAARRGGBB; -** a string in the format ""#AARRGGBB""; +** a string in the format ""#RRGGBB"" or ""#AARRGGBB""; ** a string containing a CSS3/X11 color name e.g. ""blue"", ""palegoldenrod""; or ** a Color created with forms.createcolor. ** As noted above, luacolor? indicates nil may also be passed. diff --git a/src/BizHawk.Client.Common/lua/NLuaTableHelper.cs b/src/BizHawk.Client.Common/lua/NLuaTableHelper.cs index 0f3be7db1e..d066f5006b 100644 --- a/src/BizHawk.Client.Common/lua/NLuaTableHelper.cs +++ b/src/BizHawk.Client.Common/lua/NLuaTableHelper.cs @@ -86,7 +86,12 @@ namespace BizHawk.Client.Common case int i: return Color.FromArgb(i); case string s: - if (s[0] == '#' && s.Length == 9) return ParseColor(int.Parse(s.Substring(1), NumberStyles.HexNumber), safe, logCallback); + if (s[0] is '#' && (s.Length is 7 or 9)) + { + var i1 = uint.Parse(s.Substring(1), NumberStyles.HexNumber); + if (s.Length is 7) i1 |= 0xFF000000U; + return ParseColor(unchecked((int) i1), safe, logCallback); + } var fromName = Color.FromName(s); if (fromName.IsNamedColor) return fromName; if (safe) logCallback($"ParseColor: not a known color name (\"{s}\")");