Files
NHSE/NHSE.Parsing/ParseConverter.cs
Kurt b88c518d5c Update FieldItemEditor for 3.0.0 (#716)
Updates the Field Item Editor to render layers based on the entire map, and the per-patch positioning of each layer.
Import/export will gracefully handle upgrade/downgrade, and viewport import/export will gracefully update tiles rather than a per-acre basis.

Performance has also been slightly improved; no allocation is done anymore when updating the image.
2026-01-25 16:55:38 -06:00

50 lines
1.5 KiB
C#

using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
namespace NHSE.Parsing;
/// <summary>
/// Logic for converting various dumps to resources used by the Core project.
/// </summary>
public static class ParseConverter
{
/// <summary>
/// Converts {Hex, Name} to an index-able list of strings.
/// </summary>
/// <param name="input">Path to Key Value pair listing, with keys being hex numbers (without 0x prefix)</param>
/// <param name="output">File to write the result list to</param>
public static void ConvertItemStrings(string input, string output)
{
var result = ConvertItemList(input);
File.WriteAllLines(output, result);
}
private static string[] ConvertItemList(string path)
{
var lines = File.ReadAllLines(path);
var items = lines.Select(ParseItem.FromString).ToArray();
var max = items.Max(z => z.Index);
var result = new string[max + 1];
foreach (var item in items)
result[item.Index] = item.Name;
return result;
}
}
public readonly record struct ParseItem
{
public required int Index {get; init; }
public required string Name { get; init; }
[SetsRequiredMembers]
public ParseItem(string line)
{
var split = line.Split(", ");
Index = int.Parse(split[0], System.Globalization.NumberStyles.HexNumber);
Name = split[1];
}
public static ParseItem FromString(string s) => new(s);
}