mirror of
https://github.com/kwsch/NHSE.git
synced 2026-09-30 22:06:37 -05:00
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.
50 lines
1.5 KiB
C#
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);
|
|
} |