Skip to content

Commit

Permalink
Log adjacencies file path for debugging (#1844) #patch
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains authored Mar 16, 2024
1 parent 149a80d commit 7a41344
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
From;To;Type;Through;start_x;start_y;stop_x;stop_y;Comment
496;497
496;497;sea;3759;0;0;1;1;Test adjacency
15 changes: 15 additions & 0 deletions ImperatorToCK3/CommonUtils/Map/Adjacency.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using CsvHelper.Configuration.Attributes;

namespace ImperatorToCK3.CommonUtils.Map;

public sealed class Adjacency {
[Index(0)] public long From { get; set; }
[Index(1)] public long To { get; set; }
[Index(2)] public string Type { get; set; } = string.Empty;
[Index(3)] public long Through { get; set; }
[Index(4)] public long StartX { get; set; }
[Index(5)] public long StartY { get; set; }
[Index(6)] public long StopX { get; set; }
[Index(7)] public long StopY { get; set; }
[Index(8)] public string Comment { get; set; } = string.Empty;
}
13 changes: 6 additions & 7 deletions ImperatorToCK3/CommonUtils/Map/MapData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using System.Linq;
using System.Runtime.InteropServices;

using Index = CsvHelper.Configuration.Attributes.IndexAttribute;

namespace ImperatorToCK3.CommonUtils.Map;

public sealed class MapData {
Expand Down Expand Up @@ -419,12 +421,13 @@ private void LoadAdjacencies(string adjacenciesFilename, ModFilesystem modFS) {
Logger.Warn($"Adjacencies file {adjacenciesFilename} not found!");
return;
}
Logger.Debug($"Loading adjacencies from \"{adjacenciesPath}\"...");

var reader = new StreamReader(adjacenciesPath);

var csvConfig = new CsvConfiguration(CultureInfo.InvariantCulture) {
Delimiter = ";",
HasHeaderRecord = true,
HasHeaderRecord = false, // Ignore header using ShouldSkipRecord instead.
AllowComments = true,
TrimOptions = TrimOptions.Trim,
IgnoreBlankLines = true,
Expand All @@ -435,15 +438,11 @@ private void LoadAdjacencies(string adjacenciesFilename, ModFilesystem modFS) {
}
cell = cell.Trim();
return cell.Length == 0 || cell[0] == '#';
return cell.Length == 0 || cell[0] == '#' || !ulong.TryParse(cell, out _);
}),
};
using CsvReader csv = new(reader, csvConfig);
var adjacency = new {
From = default(long),
To = default(long),
};
var records = csv.GetRecords(adjacency);
var records = csv.GetRecords<Adjacency>().ToList();

int count = 0;
foreach (var record in records) {
Expand Down

0 comments on commit 7a41344

Please sign in to comment.