From b71345287c655287b38a88a9534f35b801184d38 Mon Sep 17 00:00:00 2001 From: iht Date: Mon, 20 Jan 2025 18:16:26 +0100 Subject: [PATCH] Support Liquid syntax in succession_law_map --- ImperatorToCK3.UnitTests/CK3/Titles/TitleTests.cs | 2 +- .../Mappers/SuccessionLaw/SuccessionLawMapperTests.cs | 4 +++- .../{succession_law_map.txt => succession_law_map.liquid} | 0 ImperatorToCK3/CK3/World.cs | 2 +- .../{succession_law_map.txt => succession_law_map.liquid} | 0 ImperatorToCK3/Mappers/SuccessionLaw/SuccessionLawMapper.cs | 5 +++-- 6 files changed, 8 insertions(+), 5 deletions(-) rename ImperatorToCK3.UnitTests/TestFiles/configurables/{succession_law_map.txt => succession_law_map.liquid} (100%) rename ImperatorToCK3/Data_Files/configurables/{succession_law_map.txt => succession_law_map.liquid} (100%) diff --git a/ImperatorToCK3.UnitTests/CK3/Titles/TitleTests.cs b/ImperatorToCK3.UnitTests/CK3/Titles/TitleTests.cs index 9def27d0f..f51a38521 100644 --- a/ImperatorToCK3.UnitTests/CK3/Titles/TitleTests.cs +++ b/ImperatorToCK3.UnitTests/CK3/Titles/TitleTests.cs @@ -58,7 +58,7 @@ private class TitleBuilder { "TestFiles/configurables/governorMappings.txt", "TestFiles/configurables/country_rank_map.txt"); private GovernmentMapper governmentMapper = new(ck3GovernmentIds: Array.Empty()); - private SuccessionLawMapper successionLawMapper = new("TestFiles/configurables/succession_law_map.txt"); + private SuccessionLawMapper successionLawMapper = new("TestFiles/configurables/succession_law_map.txt", ck3ModFlags: []); private DefiniteFormMapper definiteFormMapper = new("TestFiles/configurables/definite_form_names.txt"); private readonly ReligionMapper religionMapper; diff --git a/ImperatorToCK3.UnitTests/Mappers/SuccessionLaw/SuccessionLawMapperTests.cs b/ImperatorToCK3.UnitTests/Mappers/SuccessionLaw/SuccessionLawMapperTests.cs index f16a15319..ee98ad054 100644 --- a/ImperatorToCK3.UnitTests/Mappers/SuccessionLaw/SuccessionLawMapperTests.cs +++ b/ImperatorToCK3.UnitTests/Mappers/SuccessionLaw/SuccessionLawMapperTests.cs @@ -10,6 +10,8 @@ namespace ImperatorToCK3.UnitTests.Mappers.SuccessionLaw; [Collection("Sequential")] [CollectionDefinition("Sequential", DisableParallelization = true)] public class SuccessionLawMapperTests { + private static OrderedDictionary ck3ModFlags = []; + [Fact] public void NonMatchGivesEmptySet() { var reader = new BufferedReader("link = { ir=implaw ck3 = ck3law }"); @@ -56,7 +58,7 @@ public void MultipleLawsCanBeReturned() { [Fact] public void MappingsAreReadFromFile() { - var mapper = new SuccessionLawMapper("TestFiles/configurables/succession_law_map.txt"); + var mapper = new SuccessionLawMapper("TestFiles/configurables/succession_law_map.txt", ck3ModFlags); Assert.Equal( new SortedSet { "ck3law1", "ck3law2" }, mapper.GetCK3LawsForImperatorLaws(new() { "implaw1" }) diff --git a/ImperatorToCK3.UnitTests/TestFiles/configurables/succession_law_map.txt b/ImperatorToCK3.UnitTests/TestFiles/configurables/succession_law_map.liquid similarity index 100% rename from ImperatorToCK3.UnitTests/TestFiles/configurables/succession_law_map.txt rename to ImperatorToCK3.UnitTests/TestFiles/configurables/succession_law_map.liquid diff --git a/ImperatorToCK3/CK3/World.cs b/ImperatorToCK3/CK3/World.cs index de3da2f26..13e3c131e 100644 --- a/ImperatorToCK3/CK3/World.cs +++ b/ImperatorToCK3/CK3/World.cs @@ -291,6 +291,7 @@ public World(Imperator.World impWorld, Configuration config, Thread? irCoaExtrac // Before we can import Imperator countries and governorships, the I:R CoA extraction thread needs to finish. irCoaExtractThread?.Join(); + SuccessionLawMapper successionLawMapper = new("configurables/succession_law_map.liquid", ck3ModFlags); List> countyLevelCountries = []; LandedTitles.ImportImperatorCountries( impWorld.Countries, @@ -1149,7 +1150,6 @@ private void DetermineCK3Dlcs(Configuration config) { private readonly DefiniteFormMapper definiteFormMapper = new(Path.Combine("configurables", "definite_form_names.txt")); private readonly NicknameMapper nicknameMapper = new(Path.Combine("configurables", "nickname_map.txt")); private readonly ProvinceMapper provinceMapper = new(); - private readonly SuccessionLawMapper successionLawMapper = new(Path.Combine("configurables", "succession_law_map.txt")); private readonly TagTitleMapper tagTitleMapper = new( tagTitleMappingsPath: Path.Combine("configurables", "title_map.txt"), governorshipTitleMappingsPath: Path.Combine("configurables", "governorMappings.txt"), diff --git a/ImperatorToCK3/Data_Files/configurables/succession_law_map.txt b/ImperatorToCK3/Data_Files/configurables/succession_law_map.liquid similarity index 100% rename from ImperatorToCK3/Data_Files/configurables/succession_law_map.txt rename to ImperatorToCK3/Data_Files/configurables/succession_law_map.liquid diff --git a/ImperatorToCK3/Mappers/SuccessionLaw/SuccessionLawMapper.cs b/ImperatorToCK3/Mappers/SuccessionLaw/SuccessionLawMapper.cs index f1a7fbb30..538b7bee7 100644 --- a/ImperatorToCK3/Mappers/SuccessionLaw/SuccessionLawMapper.cs +++ b/ImperatorToCK3/Mappers/SuccessionLaw/SuccessionLawMapper.cs @@ -1,4 +1,5 @@ using commonItems; +using ImperatorToCK3.CK3; using System.Collections.Generic; namespace ImperatorToCK3.Mappers.SuccessionLaw; @@ -7,11 +8,11 @@ public sealed class SuccessionLawMapper { private readonly Dictionary> impToCK3SuccessionLawMap = new(); public SuccessionLawMapper() { } - public SuccessionLawMapper(string filePath) { + public SuccessionLawMapper(string filePath, OrderedDictionary ck3ModFlags) { Logger.Info("Parsing succession law mappings..."); var parser = new Parser(); RegisterKeys(parser); - parser.ParseFile(filePath); + parser.ParseLiquidFile(filePath, ck3ModFlags); Logger.Info($"Loaded {impToCK3SuccessionLawMap.Count} succession law links."); Logger.IncrementProgress();