refactor: formatting and pulling method out

This commit is contained in:
Anna 2020-11-05 19:49:24 -05:00
parent fa5980c61b
commit 4e81786a2a
4 changed files with 32 additions and 19 deletions

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Channels;
using System.Windows;
@ -42,7 +41,7 @@ namespace XIVChat_Desktop {
var colours = new List<Color>();
// ReSharper disable once LoopCanBeConvertedToQuery
foreach (var chunk in SplitList(key.ToList(), 3)) {
foreach (var chunk in key.ToList().Chunks(3)) {
var r = chunk[0];
var g = chunk.Count > 1 ? chunk[1] : (byte)0;
var b = chunk.Count > 2 ? chunk[2] : (byte)0;
@ -53,12 +52,6 @@ namespace XIVChat_Desktop {
return colours;
}
private static IEnumerable<List<T>> SplitList<T>(List<T> locations, int nSize) {
for (int i = 0; i < locations.Count; i += nSize) {
yield return locations.GetRange(i, Math.Min(nSize, locations.Count - i));
}
}
private static string ToHexString(IEnumerable<byte> bytes) {
return string.Join("", bytes.Select(b => b.ToString("X2")));
}

12
XIVChat Desktop/Util.cs Normal file
View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
namespace XIVChat_Desktop {
public static class Util {
public static IEnumerable<List<T>> Chunks<T>(this List<T> locations, int nSize) {
for (int i = 0; i < locations.Count; i += nSize) {
yield return locations.GetRange(i, Math.Min(nSize, locations.Count - i));
}
}
}
}

View File

@ -13,25 +13,25 @@
</PropertyGroup>
<ItemGroup>
<None Remove="fonts\ffxiv.ttf"/>
<None Remove="ic_launcher-playstore.png"/>
<None Remove="Resources\fonticon_ps4.tex.png"/>
<None Remove="fonts\ffxiv.ttf" />
<None Remove="ic_launcher-playstore.png" />
<None Remove="Resources\fonticon_ps4.tex.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ModernWpfUI" Version="0.9.2"/>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3"/>
<PackageReference Include="Sodium.Core" Version="1.2.3"/>
<PackageReference Include="ModernWpfUI" Version="0.9.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Sodium.Core" Version="1.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\XIVChatCommon\XIVChatCommon.csproj"/>
<ProjectReference Include="..\XIVChatCommon\XIVChatCommon.csproj" />
</ItemGroup>
<ItemGroup>
<Resource Include="fonts\ffxiv.ttf"/>
<Resource Include="ic_launcher-playstore.png"/>
<Resource Include="Resources\fonticon_ps4.tex.png"/>
<Resource Include="fonts\ffxiv.ttf" />
<Resource Include="ic_launcher-playstore.png" />
<Resource Include="Resources\fonticon_ps4.tex.png" />
</ItemGroup>
<ItemGroup>

View File

@ -82,6 +82,14 @@ namespace XIVChatCommon {
public TextChunk(string content) {
this.Content = content;
}
public TextChunk(uint? fallbackColour, uint? foreground, uint? glow, bool italic, string content) {
this.FallbackColour = fallbackColour;
this.Foreground = foreground;
this.Glow = glow;
this.Italic = italic;
this.Content = content;
}
}
[MessagePackObject]