Skip to content

Commit

Permalink
Fix dynamic empire adjective using unlocalized county adjective (#2065)…
Browse files Browse the repository at this point in the history
… #patch
  • Loading branch information
IhateTrains authored Jul 10, 2024
1 parent e3066de commit a417dce
Show file tree
Hide file tree
Showing 23 changed files with 451 additions and 299 deletions.
24 changes: 17 additions & 7 deletions ImperatorToCK3.UnitTests/CK3/Characters/CK3CharacterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using commonItems.Localization;
using commonItems.Mods;
using FluentAssertions;
using ImperatorToCK3.CK3;
using ImperatorToCK3.CK3.Characters;
using ImperatorToCK3.CK3.Cultures;
using ImperatorToCK3.CK3.Dynasties;
Expand Down Expand Up @@ -70,7 +71,8 @@ public class CK3CharacterBuilder {
private CultureMapper cultureMapper = new(IRRegionMapper, new CK3RegionMapper(), cultures);
private TraitMapper traitMapper = new("TestFiles/configurables/trait_map.txt", CK3ModFS);
private NicknameMapper nicknameMapper = new("TestFiles/configurables/nickname_map.txt");
private LocDB locDB = new("english");
private LocDB irLocDB = new("english");
private CK3LocDB ck3LocDB = new(CK3ModFS);
private ProvinceMapper provinceMapper = new();
private DeathReasonMapper deathReasonMapper = new();

Expand All @@ -84,7 +86,8 @@ public Character Build() {
cultureMapper,
traitMapper,
nicknameMapper,
locDB,
irLocDB,
ck3LocDB,
irMapData,
provinceMapper,
deathReasonMapper,
Expand Down Expand Up @@ -119,8 +122,12 @@ public CK3CharacterBuilder WithNicknameMapper(NicknameMapper nicknameMapper) {
this.nicknameMapper = nicknameMapper;
return this;
}
public CK3CharacterBuilder WithLocDB(LocDB locDB) {
this.locDB = locDB;
public CK3CharacterBuilder WithIRLocDB(LocDB irLocDB) {
this.irLocDB = irLocDB;
return this;
}
public CK3CharacterBuilder WithCK3LocDB(CK3LocDB ck3LocDB) {
this.ck3LocDB = ck3LocDB;
return this;
}
public CK3CharacterBuilder WithProvinceMapper(ProvinceMapper provinceMapper) {
Expand Down Expand Up @@ -382,12 +389,15 @@ public void NameCanBeInitializedFromImperator() {
var nameLocBlock = locDB.AddLocBlock("alexandros");
nameLocBlock["english"] = "Alexandros";

var ck3LocDB = new TestCK3LocDB();

var character = builder
.WithImperatorCharacter(imperatorCharacter)
.WithLocDB(locDB)
.WithIRLocDB(locDB)
.WithCK3LocDB(ck3LocDB)
.Build();
Assert.Equal("alexandros", character.GetName(ConversionDate));
Assert.Equal("Alexandros", character.Localizations["alexandros"]["english"]);
Assert.Equal("Alexandros", ck3LocDB.GetLocBlockForKey("alexandros")!["english"]);
}

[Fact]
Expand Down Expand Up @@ -502,7 +512,7 @@ public void DeadLandlessCharactersArePurgedIfChildless() {
landedCharacter.Father = fatherOfLandedCharacter;
childlessRelative.Father = fatherOfLandedCharacter;

var dynasty = new ImperatorToCK3.CK3.Dynasties.Dynasty(irFamily, irCharacters, new CulturesDB(), CultureMapper, new LocDB("english"), ConversionDate);
var dynasty = new ImperatorToCK3.CK3.Dynasties.Dynasty(irFamily, irCharacters, new CulturesDB(), CultureMapper, new LocDB("english"), new TestCK3LocDB(), ConversionDate);
var dynasties = new DynastyCollection { dynasty };
Assert.Equal(dynasty.Id, landedCharacter.GetDynastyId(ConversionDate));
Assert.Equal(dynasty.Id, fatherOfLandedCharacter.GetDynastyId(ConversionDate));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void MarriageDateCanBeEstimatedFromChild() {
new ProvinceMapper(),
new DeathReasonMapper(),
new DNAFactory(irModFS, ck3ModFS),
new TestCK3LocDB(),
endDate,
configuration);

Expand Down Expand Up @@ -141,6 +142,7 @@ public void MarriageDateCanBeEstimatedFromUnbornChild() {
new ProvinceMapper(),
new DeathReasonMapper(),
new DNAFactory(irModFS, ck3ModFS),
new TestCK3LocDB(),
endDate,
configuration);

Expand Down Expand Up @@ -192,6 +194,7 @@ public void OnlyEarlyPregnanciesAreImportedFromImperator() {
new ProvinceMapper(),
new DeathReasonMapper(),
new DNAFactory(irModFS, ck3ModFS),
new TestCK3LocDB(),
conversionDate,
configuration);

Expand Down Expand Up @@ -297,6 +300,7 @@ public void ImperatorCountriesGoldCanBeDistributedAmongRulerAndVassals() {
var traitMapper = new TraitMapper();
var nicknameMapper = new NicknameMapper();
var deathReasonMapper = new DeathReasonMapper();
var ck3LocDB = new TestCK3LocDB();

// Import Imperator ruler and governors.
var characters = new CharacterCollection();
Expand All @@ -310,6 +314,7 @@ public void ImperatorCountriesGoldCanBeDistributedAmongRulerAndVassals() {
provinceMapper,
deathReasonMapper,
new DNAFactory(irModFS, ck3ModFS),
ck3LocDB,
conversionDate,
config);

Expand All @@ -319,6 +324,7 @@ public void ImperatorCountriesGoldCanBeDistributedAmongRulerAndVassals() {
Array.Empty<Dependency>(),
tagTitleMapper,
imperatorWorld.LocDB,
ck3LocDB,
provinceMapper,
coaMapper,
new GovernmentMapper(ck3GovernmentIds: Array.Empty<string>()),
Expand All @@ -340,6 +346,7 @@ public void ImperatorCountriesGoldCanBeDistributedAmongRulerAndVassals() {
provinces,
tagTitleMapper,
imperatorWorld.LocDB,
ck3LocDB,
config,
provinceMapper,
definiteFormMapper,
Expand Down
27 changes: 16 additions & 11 deletions ImperatorToCK3.UnitTests/CK3/Dynasties/DynastyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using commonItems.Colors;
using commonItems.Localization;
using commonItems.Mods;
using ImperatorToCK3.CK3;
using ImperatorToCK3.CK3.Characters;
using ImperatorToCK3.CK3.Dynasties;
using ImperatorToCK3.CK3.Religions;
Expand Down Expand Up @@ -82,6 +83,7 @@ public Character Build() {
traitMapper,
nicknameMapper,
locDB,
new CK3LocDB(ck3ModFS),
irMapData,
provinceMapper,
deathReasonMapper,
Expand Down Expand Up @@ -140,8 +142,8 @@ public void IdAndNameAreProperlyConverted() {
var reader = new BufferedReader(string.Empty);
var family = Family.Parse(reader, 45);

var locMapper = new LocDB("english");
var dynasty = new Dynasty(family, characters, new CulturesDB(), CultureMapper, locMapper, BookmarkDate);
var irLocDB = new LocDB("english");
var dynasty = new Dynasty(family, characters, new CulturesDB(), CultureMapper, irLocDB, new TestCK3LocDB(), BookmarkDate);

Assert.Equal("dynn_irtock3_45", dynasty.Id);
Assert.Equal("dynn_irtock3_45", dynasty.Name);
Expand All @@ -153,12 +155,14 @@ public void LocalizationIsConverted() {
var reader = new BufferedReader("key = cornelii");
var family = Family.Parse(reader, 45);

var locDB = new LocDB("english");
var dynLoc = locDB.AddLocBlock("cornelii");
var irLocDB = new LocDB("english");
var dynLoc = irLocDB.AddLocBlock("cornelii");
dynLoc["english"] = "Cornelii";
var dynasty = new Dynasty(family, characters, new CulturesDB(), CultureMapper, locDB, BookmarkDate);

var ck3LocDB = new TestCK3LocDB();
var dynasty = new Dynasty(family, characters, new CulturesDB(), CultureMapper, irLocDB, ck3LocDB, BookmarkDate);

Assert.Equal("Cornelii", dynasty.LocalizedName!["english"]);
Assert.Equal("Cornelii", ck3LocDB.GetLocBlockForKey(dynasty.Id)!["english"]);
}

[Fact]
Expand All @@ -167,10 +171,11 @@ public void LocalizationDefaultsToUnlocalizedKey() {
var reader = new BufferedReader("key = cornelii");
var family = Family.Parse(reader, 45);

var locDB = new LocDB("english");
var dynasty = new Dynasty(family, characters, new CulturesDB(), CultureMapper, locDB, BookmarkDate);
var irLocDB = new LocDB("english");
var ck3LocDB = new TestCK3LocDB();
var dynasty = new Dynasty(family, characters, new CulturesDB(), CultureMapper, irLocDB, ck3LocDB, BookmarkDate);

Assert.Equal("cornelii", dynasty.LocalizedName!["english"]);
Assert.Equal("cornelii", ck3LocDB.GetLocBlockForKey(dynasty.Id)!["english"]);
}
[Fact]
public void CultureIsBasedOnFirstImperatorMember() {
Expand Down Expand Up @@ -201,7 +206,7 @@ public void CultureIsBasedOnFirstImperatorMember() {
new CK3RegionMapper(),
Cultures
);
var locDB = new LocDB("english");
var irLocDB = new LocDB("english");
var ck3Member1 = new CK3CharacterBuilder()
.WithCultureMapper(cultureMapper)
.WithImperatorCharacter(member1)
Expand All @@ -214,7 +219,7 @@ public void CultureIsBasedOnFirstImperatorMember() {
.WithCultureMapper(cultureMapper)
.WithImperatorCharacter(member3)
.Build();
var dynasty = new Dynasty(family, characters, new CulturesDB(), cultureMapper, locDB, BookmarkDate);
var dynasty = new Dynasty(family, characters, new CulturesDB(), cultureMapper, irLocDB, new TestCK3LocDB(), BookmarkDate);

Assert.Equal("latin", dynasty.CultureId);
}
Expand Down
9 changes: 6 additions & 3 deletions ImperatorToCK3.UnitTests/CK3/Titles/LandedTitlesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public void GovernorshipsCanBeRecognizedAsCountyLevel() {
var tagTitleMapper = new TagTitleMapper();
var provinceMapper = new ProvinceMapper();
provinceMapper.LoadMappings(provinceMappingsPath, "test_version");
var locDB = new LocDB("english");
var irLocDB = new LocDB("english");
var ck3Religions = new ReligionCollection(titles);
var religionMapper = new ReligionMapper(ck3Religions, irRegionMapper, ck3RegionMapper);
var cultureMapper = new CultureMapper(irRegionMapper, ck3RegionMapper, cultures);
Expand All @@ -293,12 +293,15 @@ public void GovernorshipsCanBeRecognizedAsCountyLevel() {
provinceMapper,
deathReasonMapper,
dnaFactory,
new TestCK3LocDB(),
conversionDate,
config
);

var ck3LocDB = new TestCK3LocDB();

// Import country 589.
titles.ImportImperatorCountries(imperatorWorld.Countries, imperatorWorld.Dependencies, tagTitleMapper, locDB, provinceMapper, coaMapper, new GovernmentMapper(ck3GovernmentIds: Array.Empty<string>()), new SuccessionLawMapper(), definiteFormMapper, religionMapper, cultureMapper, nicknameMapper, characters, conversionDate, config, new List<KeyValuePair<Country, Dependency?>>());
titles.ImportImperatorCountries(imperatorWorld.Countries, imperatorWorld.Dependencies, tagTitleMapper, irLocDB, ck3LocDB, provinceMapper, coaMapper, new GovernmentMapper(ck3GovernmentIds: Array.Empty<string>()), new SuccessionLawMapper(), definiteFormMapper, religionMapper, cultureMapper, nicknameMapper, characters, conversionDate, config, new List<KeyValuePair<Country, Dependency?>>());
Assert.Collection(titles,
title => Assert.Equal("c_county1", title.Id),
title => Assert.Equal("b_barony1", title.Id),
Expand All @@ -312,7 +315,7 @@ public void GovernorshipsCanBeRecognizedAsCountyLevel() {
var provinces = new ProvinceCollection(ck3ModFS);
provinces.ImportImperatorProvinces(imperatorWorld, titles, cultureMapper, religionMapper, provinceMapper, conversionDate, config);
// Country 589 is imported as duchy-level title, so its governorship of galatia_region will be county level.
titles.ImportImperatorGovernorships(imperatorWorld, provinces, tagTitleMapper, locDB, config, provinceMapper, definiteFormMapper, irRegionMapper, coaMapper, countyLevelGovernorships);
titles.ImportImperatorGovernorships(imperatorWorld, provinces, tagTitleMapper, irLocDB, ck3LocDB, config, provinceMapper, definiteFormMapper, irRegionMapper, coaMapper, countyLevelGovernorships);

Assert.Collection(titles,
title => Assert.Equal("c_county1", title.Id),
Expand Down
2 changes: 2 additions & 0 deletions ImperatorToCK3.UnitTests/CK3/Titles/RulerTermTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void ImperatorRulerTermIsCorrectlyConverted() {
new ImperatorToCK3.CK3.Characters.CharacterCollection(),
govMapper,
new LocDB("english"),
new TestCK3LocDB(),
new ReligionMapper(ck3Religions, irRegionMapper, ck3RegionMapper),
new CultureMapper(irRegionMapper, ck3RegionMapper, new CultureCollection(new ColorFactory(), new PillarCollection(new ColorFactory(), []), [])),
new NicknameMapper("TestFiles/configurables/nickname_map.txt"),
Expand Down Expand Up @@ -98,6 +99,7 @@ public void PreImperatorTermIsCorrectlyConverted() {
ck3Characters,
govMapper,
new LocDB("english"),
new TestCK3LocDB(),
religionMapper,
new CultureMapper(new BufferedReader("link = { ir=spartan ck3=greek }"), irRegionMapper, ck3RegionMapper, cultures),
new NicknameMapper("TestFiles/configurables/nickname_map.txt"),
Expand Down
17 changes: 2 additions & 15 deletions ImperatorToCK3.UnitTests/CK3/Titles/TitleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Xunit;
using CharacterCollection = ImperatorToCK3.CK3.Characters.CharacterCollection;
using ImperatorToCK3.Mappers.Region;
using ImperatorToCK3.UnitTests.TestHelpers;
using System;
using System.IO;

Expand Down Expand Up @@ -77,6 +78,7 @@ public Title BuildFromTag() {
dependency: null,
imperatorCountries,
locDB,
new TestCK3LocDB(),
provinceMapper,
coaMapper,
tagTitleMapper,
Expand Down Expand Up @@ -171,21 +173,6 @@ public void TitlePrimitivesCanBeLoaded() {
Assert.Equal("c_roma", title.CapitalCountyId);
}

[Fact]
public void LocalizationCanBeSet() {
var titles = new Title.LandedTitles();
var title = titles.Add("k_testtitle");
var nameLoc = title.Localizations.AddLocBlock(title.Id);
nameLoc["english"] = "engloc";
nameLoc["french"] = "frloc";
nameLoc["german"] = "germloc";
nameLoc["russian"] = "rusloc";
nameLoc["simp_chinese"] = "simploc";
nameLoc["spanish"] = "spaloc";

Assert.Equal("engloc", title.Localizations.GetLocBlockForKey(title.Id)!["english"]);
}

[Fact]
public void MembersDefaultToBlank() {
var titles = new Title.LandedTitles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using ImperatorToCK3.Mappers.Religion;
using ImperatorToCK3.Mappers.SuccessionLaw;
using ImperatorToCK3.Mappers.TagTitle;
using ImperatorToCK3.UnitTests.TestHelpers;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -80,6 +81,7 @@ public void TitleCanBeMatchedFromGovernorship() {
Array.Empty<Dependency>(),
mapper,
new LocDB("english"),
new TestCK3LocDB(),
provMapper,
new CoaMapper(),
new GovernmentMapper(ck3GovernmentIds: Array.Empty<string>()),
Expand Down Expand Up @@ -154,6 +156,7 @@ public void TitleCanBeGeneratedFromGovernorship() {
Array.Empty<Dependency>(),
mapper,
new LocDB("english"),
new TestCK3LocDB(),
provMapper,
new CoaMapper(),
new GovernmentMapper(ck3GovernmentIds: Array.Empty<string>()),
Expand Down Expand Up @@ -247,6 +250,7 @@ public void GovernorshipCanBeRegistered() {
Array.Empty<Dependency>(),
mapper,
new LocDB("english"),
new TestCK3LocDB(),
provMapper,
new CoaMapper(),
new GovernmentMapper(ck3GovernmentIds: Array.Empty<string>()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using ImperatorToCK3.Mappers.SuccessionLaw;
using ImperatorToCK3.Mappers.TagTitle;
using ImperatorToCK3.Outputter;
using ImperatorToCK3.UnitTests.TestHelpers;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -60,6 +61,7 @@ public async Task CoaIsOutputtedForCountryWithFlagSet() {
Array.Empty<Dependency>(),
new TagTitleMapper(),
new LocDB("english"),
new TestCK3LocDB(),
new ProvinceMapper(),
new CoaMapper(irModFS),
new GovernmentMapper(ck3GovernmentIds: Array.Empty<string>()),
Expand Down Expand Up @@ -105,6 +107,7 @@ public async Task CoaIsNotOutputtedForCountryWithoutFlagSet() {
Array.Empty<Dependency>(),
new TagTitleMapper(),
new LocDB("english"),
new TestCK3LocDB(),
new ProvinceMapper(),
new CoaMapper(irModFS),
new GovernmentMapper(ck3GovernmentIds: Array.Empty<string>()),
Expand Down
8 changes: 5 additions & 3 deletions ImperatorToCK3.UnitTests/Outputter/DynastiesOutputterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using ImperatorToCK3.Mappers.Culture;
using ImperatorToCK3.Mappers.Region;
using ImperatorToCK3.Outputter;
using ImperatorToCK3.UnitTests.TestHelpers;
using System;
using System.IO;
using System.Threading.Tasks;
Expand All @@ -25,7 +26,8 @@ public class DynastiesOutputterTests {
[Fact]
public async Task DynastiesAreOutputted() {
const string outputModPath = "output/outputMod";
var locDB = new LocDB("english");
var irLocDB = new LocDB("english");
var ck3LocDB = new TestCK3LocDB();
const string imperatorRoot = "TestFiles/Imperator/root";
ModFilesystem irModFS = new(imperatorRoot, Array.Empty<Mod>());
var irMapData = new MapData(irModFS);
Expand All @@ -42,11 +44,11 @@ public async Task DynastiesAreOutputted() {
var cultures = new CulturesDB();

var family1 = new Family(1);
var dynasty1 = new Dynasty(family1, characters, cultures, cultureMapper, locDB, ConversionDate);
var dynasty1 = new Dynasty(family1, characters, cultures, cultureMapper, irLocDB, ck3LocDB, ConversionDate);
dynasties.Add(dynasty1);

var family2 = new Family(2);
var dynasty2 = new Dynasty(family2, characters, cultures, cultureMapper, locDB, ConversionDate) {
var dynasty2 = new Dynasty(family2, characters, cultures, cultureMapper, irLocDB, ck3LocDB, ConversionDate) {
CultureId = "roman"
};
dynasties.Add(dynasty2);
Expand Down
7 changes: 7 additions & 0 deletions ImperatorToCK3.UnitTests/TestHelpers/TestCK3LocDB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using ImperatorToCK3.CK3;

namespace ImperatorToCK3.UnitTests.TestHelpers;

public class TestCK3LocDB : CK3LocDB {
public TestCK3LocDB() { }
}
Loading

0 comments on commit a417dce

Please sign in to comment.