From f0f002d69426fb4596cc4d42b4a33831e8f13165 Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Mon, 7 Jun 2021 02:01:11 -0400 Subject: [PATCH] refactor: consolidate utils --- XIVChatPlugin/Extensions.cs | 44 ------------------------------ XIVChatPlugin/Util.cs | 38 ++++++++++++++++++++++++++ XIVChatPlugin/XIVChatPlugin.csproj | 18 ++++++------ 3 files changed, 47 insertions(+), 53 deletions(-) delete mode 100644 XIVChatPlugin/Extensions.cs diff --git a/XIVChatPlugin/Extensions.cs b/XIVChatPlugin/Extensions.cs deleted file mode 100644 index dbb2b6b..0000000 --- a/XIVChatPlugin/Extensions.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; - -namespace XIVChatPlugin { - public static class Extensions { - public static string ToHexString(this IEnumerable bytes, bool upper = false, string separator = "") { - return string.Join(separator, bytes.Select(b => b.ToString(upper ? "X2" : "x2"))); - } - - public static List ToColours(this byte[] bytes) { - var colours = new List(); - - var colour = new Vector4(0f, 0f, 0f, 1f); - for (var i = 0; i < bytes.Length; i++) { - var idx = i % 3; - - if (i != 0 && idx == 0) { - colours.Add(colour); - colour = new Vector4(0f, 0f, 0f, 1f); - } - - switch (idx) { - case 0: - colour.X = bytes[i] / 255f; - break; - case 1: - colour.Y = bytes[i] / 255f; - break; - case 2: - colour.Z = bytes[i] / 255f; - break; - default: - throw new ApplicationException("unreachable code reached"); - } - } - - colours.Add(colour); - - return colours; - } - } -} diff --git a/XIVChatPlugin/Util.cs b/XIVChatPlugin/Util.cs index 08d06cc..f90674f 100644 --- a/XIVChatPlugin/Util.cs +++ b/XIVChatPlugin/Util.cs @@ -1,8 +1,46 @@ using System; using System.Collections.Generic; +using System.Linq; +using System.Numerics; namespace XIVChatPlugin { internal static class Util { + public static string ToHexString(this IEnumerable bytes, bool upper = false, string separator = "") { + return string.Join(separator, bytes.Select(b => b.ToString(upper ? "X2" : "x2"))); + } + + public static List ToColours(this byte[] bytes) { + var colours = new List(); + + var colour = new Vector4(0f, 0f, 0f, 1f); + for (var i = 0; i < bytes.Length; i++) { + var idx = i % 3; + + if (i != 0 && idx == 0) { + colours.Add(colour); + colour = new Vector4(0f, 0f, 0f, 1f); + } + + switch (idx) { + case 0: + colour.X = bytes[i] / 255f; + break; + case 1: + colour.Y = bytes[i] / 255f; + break; + case 2: + colour.Z = bytes[i] / 255f; + break; + default: + throw new ApplicationException("unreachable code reached"); + } + } + + colours.Add(colour); + + return colours; + } + public static int IndexOfCount(this string source, char toFind, int position) { var index = -1; for (var i = 0; i < position; i++) { diff --git a/XIVChatPlugin/XIVChatPlugin.csproj b/XIVChatPlugin/XIVChatPlugin.csproj index b253962..e7a066b 100644 --- a/XIVChatPlugin/XIVChatPlugin.csproj +++ b/XIVChatPlugin/XIVChatPlugin.csproj @@ -31,18 +31,18 @@ - - - - - - + + + + + + - + - - + +