Nibble math works better than parsing things manually
This commit is contained in:
+6
-24
@@ -1,38 +1,20 @@
|
||||
using System.Drawing;
|
||||
using System.Text.RegularExpressions;
|
||||
using System;
|
||||
using SixLabors.ImageSharp;
|
||||
|
||||
namespace fxl.codes.kisekae.Models
|
||||
{
|
||||
public class PaletteModel
|
||||
{
|
||||
private const string Regex = "%([a-zA-Z0-9\\-]*\\.[kKcCfF]+)[\\s]*;(.*)";
|
||||
|
||||
public PaletteModel(string line)
|
||||
{
|
||||
var matcher = new Regex(Regex);
|
||||
var match = matcher.Match(line);
|
||||
var parts = line.Split(';');
|
||||
FileName = parts[0].Replace("%", "").Trim();
|
||||
|
||||
foreach (var group in matcher.GetGroupNames())
|
||||
{
|
||||
if (group == "0") continue;
|
||||
|
||||
match.Groups.TryGetValue(group, out var value);
|
||||
if (string.IsNullOrEmpty(value?.Value)) continue;
|
||||
|
||||
switch (group)
|
||||
{
|
||||
case "1":
|
||||
FileName = value.Value;
|
||||
break;
|
||||
case "2":
|
||||
Comment = value.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (parts.Length > 1) Comment = parts[1].Trim();
|
||||
}
|
||||
|
||||
public string FileName { get; }
|
||||
public string Comment { get; }
|
||||
internal Color[] Colors { get; set; }
|
||||
public Color[] Colors { get; set; } = Array.Empty<Color>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user