Files
@ d6859ea7177f
Branch filter:
Location: ATITD-Tools/Desert-Paint-Codex/Services/PaletteService.cs - annotation
d6859ea7177f
2.0 KiB
text/x-csharp
Add some sanity checks on min/max concentration and min/max reagents in recipe generation. Also, clear out the search queue when generation has finished so the queue isn't loaded next time. This fixes the start/resume button state when entering the recipe generator after a prior run had finished.
40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 a5faa82faf6a a5faa82faf6a 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 | using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
using DesertPaintCodex.Models;
using DesertPaintCodex.Util;
namespace DesertPaintCodex.Services
{
internal static class PaletteService
{
private static readonly Regex ColorEntry = new(@"\#(?<red>\w\w)(?<green>\w\w)(?<blue>\w\w)\s*(?<name>\w+)");
public static List<PaintColor> Colors { get; } = new();
private static bool _initialized = false;
public static void Initialize()
{
if (_initialized) return;
string? colorsPath = FileUtils.FindApplicationResourceFile("colors.txt");
Debug.Assert(colorsPath != null);
Load(colorsPath);
_initialized = true;
}
public static void Load(string file)
{
using StreamReader reader = new StreamReader(file);
string? line;
while ((line = reader.ReadLine()) != null)
{
Match match = ColorEntry.Match(line);
if (match.Success)
{
Colors.Add(new PaintColor(match.Groups["name"].Value,
match.Groups["red"].Value,
match.Groups["green"].Value,
match.Groups["blue"].Value));
}
}
}
public static int Count => Colors.Count;
public static string FindNearest(PaintColor color)
{
int bestDistSq = int.MaxValue;
PaintColor? bestColor = null;
foreach (PaintColor paintColor in Colors)
{
int distSq = paintColor.GetDistanceSquared(color);
if (distSq >= bestDistSq) continue;
bestDistSq = distSq;
bestColor = paintColor;
}
Debug.Assert(bestColor != null);
return bestColor.Name;
}
}
}
|