From e63cc55c96d1ce2cf7078ce4d8d9063f4194362f Mon Sep 17 00:00:00 2001 From: Yamato <66829532+louis1706@users.noreply.github.com> Date: Mon, 29 Dec 2025 23:02:33 +0100 Subject: [PATCH] feat: Add Color32 converter for Config --- .../Configs/CustomConverters/ColorConverter.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/EXILED/Exiled.Loader/Features/Configs/CustomConverters/ColorConverter.cs b/EXILED/Exiled.Loader/Features/Configs/CustomConverters/ColorConverter.cs index fb29d8293..a29574ca8 100644 --- a/EXILED/Exiled.Loader/Features/Configs/CustomConverters/ColorConverter.cs +++ b/EXILED/Exiled.Loader/Features/Configs/CustomConverters/ColorConverter.cs @@ -30,7 +30,7 @@ public sealed class ColorConverter : IYamlTypeConverter public bool Accepts(Type type) { Type baseType = Nullable.GetUnderlyingType(type) ?? type; - return baseType == typeof(Color); + return baseType == typeof(Color) || baseType == typeof(Color32); } /// @@ -57,6 +57,8 @@ public object ReadYaml(IParser parser, Type type) List coordinates = ListPool.Pool.Get(4); int i = 0; + bool isColor32 = baseType == typeof(Color32); + while (!parser.TryConsume(out _)) { if (i++ % 2 == 0) @@ -71,6 +73,11 @@ public object ReadYaml(IParser parser, Type type) throw new InvalidDataException("Invalid float value."); } + if (isColor32) + { + coordinates.Add((byte)Mathf.Round(Mathf.Clamp01(coordinate) * 255f)); + } + coordinates.Add(coordinate); } @@ -99,6 +106,14 @@ public void WriteYaml(IEmitter emitter, object value, Type type) coordinates["b"] = color.b; coordinates["a"] = color.a; } + else if (value is Color32 color32) + { + color = color32; + coordinates["r"] = color.r; + coordinates["g"] = color.g; + coordinates["b"] = color.b; + coordinates["a"] = color.a; + } emitter.Emit(new MappingStart());