Skip to content

Commit

Permalink
Support Liquid syntax in succession_law_map
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains committed Jan 20, 2025
1 parent 8216eb9 commit b713452
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ImperatorToCK3.UnitTests/CK3/Titles/TitleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private class TitleBuilder {
"TestFiles/configurables/governorMappings.txt",
"TestFiles/configurables/country_rank_map.txt");
private GovernmentMapper governmentMapper = new(ck3GovernmentIds: Array.Empty<string>());
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace ImperatorToCK3.UnitTests.Mappers.SuccessionLaw;
[Collection("Sequential")]
[CollectionDefinition("Sequential", DisableParallelization = true)]
public class SuccessionLawMapperTests {
private static OrderedDictionary<string, bool> ck3ModFlags = [];

[Fact]
public void NonMatchGivesEmptySet() {
var reader = new BufferedReader("link = { ir=implaw ck3 = ck3law }");
Expand Down Expand Up @@ -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<string> { "ck3law1", "ck3law2" },
mapper.GetCK3LawsForImperatorLaws(new() { "implaw1" })
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyValuePair<Country, Dependency?>> countyLevelCountries = [];
LandedTitles.ImportImperatorCountries(
impWorld.Countries,
Expand Down Expand Up @@ -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"),
Expand Down
5 changes: 3 additions & 2 deletions ImperatorToCK3/Mappers/SuccessionLaw/SuccessionLawMapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using commonItems;
using ImperatorToCK3.CK3;
using System.Collections.Generic;

namespace ImperatorToCK3.Mappers.SuccessionLaw;
Expand All @@ -7,11 +8,11 @@ public sealed class SuccessionLawMapper {
private readonly Dictionary<string, SortedSet<string>> impToCK3SuccessionLawMap = new();

public SuccessionLawMapper() { }
public SuccessionLawMapper(string filePath) {
public SuccessionLawMapper(string filePath, OrderedDictionary<string, bool> 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();
Expand Down

0 comments on commit b713452

Please sign in to comment.