From c16bec4431eefb4943d0b9969c0187ab3447c20f Mon Sep 17 00:00:00 2001 From: Jeremy Pritts <49847914+ds5678@users.noreply.github.com> Date: Fri, 6 Oct 2023 13:56:34 -0400 Subject: [PATCH] Generic color struct constructors --- .../Program.cs | 55 +++++++++++++++++++ .../Rgb/Formats/ColorA.g.cs | 5 ++ .../Rgb/Formats/ColorR.g.cs | 5 ++ .../Rgb/Formats/ColorRG.g.cs | 6 ++ .../Rgb/Formats/ColorRGB.g.cs | 7 +++ .../Rgb/Formats/ColorRGBA.g.cs | 8 +++ 6 files changed, 86 insertions(+) diff --git a/AssetRipper.TextureDecoder.ColorGenerator/Program.cs b/AssetRipper.TextureDecoder.ColorGenerator/Program.cs index 90c10b2..67d1411 100644 --- a/AssetRipper.TextureDecoder.ColorGenerator/Program.cs +++ b/AssetRipper.TextureDecoder.ColorGenerator/Program.cs @@ -164,6 +164,8 @@ internal static partial class Program WriteProperty(writer, hasAlpha, typeName, 'A', maxValue); writer.WriteLineNoTabs(); + WriteConstructor(writer, name, hasRed, hasGreen, hasBlue, hasAlpha, typeName); + writer.WriteLineNoTabs(); WriteGetChannels(writer, typeName); writer.WriteLineNoTabs(); WriteSetChannels(writer, typeName, hasRed, hasGreen, hasBlue, hasAlpha); @@ -174,6 +176,59 @@ internal static partial class Program } } + private static void WriteConstructor(IndentedTextWriter writer, string declaringTypeName, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha, string channelTypeName) + { + writer.Write($"public {declaringTypeName}("); + if (hasRed) + { + writer.Write($"{channelTypeName} r"); + if (hasGreen || hasBlue || hasAlpha) + { + writer.Write(", "); + } + } + if (hasGreen) + { + writer.Write($"{channelTypeName} g"); + if (hasBlue || hasAlpha) + { + writer.Write(", "); + } + } + if (hasBlue) + { + writer.Write($"{channelTypeName} b"); + if (hasAlpha) + { + writer.Write(", "); + } + } + if (hasAlpha) + { + writer.Write($"{channelTypeName} a"); + } + writer.WriteLine(")"); + using (new CurlyBrackets(writer)) + { + if (hasRed) + { + writer.WriteLine("R = r;"); + } + if (hasGreen) + { + writer.WriteLine("G = g;"); + } + if (hasBlue) + { + writer.WriteLine("B = b;"); + } + if (hasAlpha) + { + writer.WriteLine("A = a;"); + } + } + } + private static void WriteGetChannels(IndentedTextWriter writer, string typeName) { writer.WriteLine($"public readonly void GetChannels(out {typeName} r, out {typeName} g, out {typeName} b, out {typeName} a)"); diff --git a/AssetRipper.TextureDecoder/Rgb/Formats/ColorA.g.cs b/AssetRipper.TextureDecoder/Rgb/Formats/ColorA.g.cs index 903f947..dd65671 100644 --- a/AssetRipper.TextureDecoder/Rgb/Formats/ColorA.g.cs +++ b/AssetRipper.TextureDecoder/Rgb/Formats/ColorA.g.cs @@ -24,6 +24,11 @@ public partial struct ColorA : IColor where T : unmanaged, INumberBase, public T A { get; set; } + public ColorA(T a) + { + A = a; + } + public readonly void GetChannels(out T r, out T g, out T b, out T a) { r = R; diff --git a/AssetRipper.TextureDecoder/Rgb/Formats/ColorR.g.cs b/AssetRipper.TextureDecoder/Rgb/Formats/ColorR.g.cs index ecfba39..01458ef 100644 --- a/AssetRipper.TextureDecoder/Rgb/Formats/ColorR.g.cs +++ b/AssetRipper.TextureDecoder/Rgb/Formats/ColorR.g.cs @@ -24,6 +24,11 @@ public partial struct ColorR : IColor where T : unmanaged, INumberBase, set { } } + public ColorR(T r) + { + R = r; + } + public readonly void GetChannels(out T r, out T g, out T b, out T a) { r = R; diff --git a/AssetRipper.TextureDecoder/Rgb/Formats/ColorRG.g.cs b/AssetRipper.TextureDecoder/Rgb/Formats/ColorRG.g.cs index 605ff98..0270eb1 100644 --- a/AssetRipper.TextureDecoder/Rgb/Formats/ColorRG.g.cs +++ b/AssetRipper.TextureDecoder/Rgb/Formats/ColorRG.g.cs @@ -20,6 +20,12 @@ public partial struct ColorRG : IColor where T : unmanaged, INumberBase set { } } + public ColorRG(T r, T g) + { + R = r; + G = g; + } + public readonly void GetChannels(out T r, out T g, out T b, out T a) { r = R; diff --git a/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB.g.cs b/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB.g.cs index 0f59af5..bd64fc8 100644 --- a/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB.g.cs +++ b/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB.g.cs @@ -16,6 +16,13 @@ public partial struct ColorRGB : IColor where T : unmanaged, INumberBase : IColor where T : unmanaged public T A { get; set; } + public ColorRGBA(T r, T g, T b, T a) + { + R = r; + G = g; + B = b; + A = a; + } + public readonly void GetChannels(out T r, out T g, out T b, out T a) { r = R;