Parser now creates lists only when it is necessary

This commit is contained in:
2025-04-10 16:12:48 +05:00
parent 08f1d7b0f5
commit 74d09c51a0
5 changed files with 31 additions and 23 deletions
@@ -5,5 +5,5 @@ public interface ISaveDataFilter
public string SearchString { get; }
public ISearchExpression SearchExpression { get; }
public void Apply(Dictionary<string, List<object>> data);
public void Apply(Dictionary<string, object> data);
}
@@ -1,5 +1,5 @@
using System.Linq;
using ParsedDict = System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<object>>;
using ParsedDict = System.Collections.Generic.Dictionary<string, object>;
namespace ParadoxSaveParser.WebAPI.SaveDataFilters;
@@ -38,12 +38,11 @@ public class SaveDataFilterEU4 : ISaveDataFilter
public void Apply(ParsedDict data)
{
var countries = (ParsedDict)data["countries"][0];
var countries = (ParsedDict)data["countries"];
var countries_filtered = countries.Where(pair
=> pair.Value.Count > 0
&& ((ParsedDict)pair.Value[0]).TryGetValue("raw_development", out var raw_development)
&& (double)raw_development[0] > 0
=> ((ParsedDict)pair.Value).TryGetValue("raw_development", out var raw_development)
&& (double)raw_development > 0
).ToDictionary();
data["countries"][0] = countries_filtered;
data["countries"] = countries_filtered;
}
}