Skip to content

Commit 45f20f2

Browse files
authored
Configurable CK3 bookmark date (#305) #minor
* Configurable CK3 bookmark date * Loc fixes * Remove unused variable in test
1 parent b486d31 commit 45f20f2

35 files changed

+150
-109
lines changed

ImperatorToCK3.UnitTests/CK3/Characters/CK3CharacterTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ public Character Build() {
3737
localizationMapper,
3838
provinceMapper,
3939
deathReasonMapper,
40-
convertBirthAndDeathDates
40+
convertBirthAndDeathDates,
41+
new Date(867, 1, 1),
42+
new Date(867, 1, 1)
4143
);
4244
return character;
4345
}

ImperatorToCK3.UnitTests/CK3/Dynasties/DynastyTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public Character Build() {
3535
localizationMapper,
3636
provinceMapper,
3737
deathReasonMapper,
38-
convertBirthAndDeathDates
38+
convertBirthAndDeathDates,
39+
new Date(867, 1, 1),
40+
new Date(867, 1, 1)
3941
);
4042
return character;
4143
}

ImperatorToCK3.UnitTests/CK3/Provinces/ProvinceDetailsTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace ImperatorToCK3.UnitTests.CK3.Provinces {
66
[Collection("Sequential")]
77
[CollectionDefinition("Sequential", DisableParallelization = true)]
88
public class ProvinceDetailsTests {
9+
private readonly Date ck3BookmarkDate = new(867, 1, 1);
910
[Fact] public void FieldsDefaultToCorrectValues() {
1011
var details = new ProvinceDetails();
1112
Assert.Equal(string.Empty, details.Culture);
@@ -19,7 +20,7 @@ public void DetailsCanBeLoadedFromStream() {
1920
var reader = new BufferedReader(
2021
"= { religion = orthodox\n random_param = random_stuff\n culture = roman\n}"
2122
);
22-
var details = new ProvinceDetails(reader);
23+
var details = new ProvinceDetails(reader, ck3BookmarkDate);
2324

2425
Assert.Equal("roman", details.Culture);
2526
Assert.Equal("orthodox", details.Religion);
@@ -35,7 +36,7 @@ public void DetailsAreLoadedFromDatedBlocks() {
3536
"850.1.1 = { religion=orthodox holding=castle_holding }" +
3637
"}"
3738
);
38-
var details = new ProvinceDetails(reader);
39+
var details = new ProvinceDetails(reader, ck3BookmarkDate);
3940

4041
Assert.Equal("castle_holding", details.Holding);
4142
Assert.Equal("orthodox", details.Religion);
@@ -51,7 +52,7 @@ public void DetailsCanBeCopyConstructed() {
5152
"\t850.1.1 = { religion=orthodox holding=castle_holding }" +
5253
"}"
5354
);
54-
var details1 = new ProvinceDetails(reader);
55+
var details1 = new ProvinceDetails(reader, ck3BookmarkDate);
5556
var details2 = new ProvinceDetails(details1);
5657

5758
Assert.Equal("castle_holding", details2.Holding);

ImperatorToCK3.UnitTests/CK3/Provinces/ProvinceMappingsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ImperatorToCK3.CK3.Provinces;
2+
using commonItems;
23
using Xunit;
34

45
namespace ImperatorToCK3.UnitTests.CK3.Provinces {
@@ -14,11 +15,10 @@ public void MappingsDefaultToEmpty() {
1415
[Fact]
1516
public void MappingsCanBeLoadedFromFile() {
1617
var provinceMappings = new ProvinceMappings(testFilePath);
17-
var province1 = new Province(id: 1, new commonItems.BufferedReader(string.Empty));
1818
Assert.Collection(provinceMappings.Mappings,
1919
mapping1 => { Assert.Equal((ulong)3, mapping1.Key); Assert.Equal((ulong)1, mapping1.Value); },
20-
mapping1 => { Assert.Equal((ulong)4, mapping1.Key); Assert.Equal((ulong)1, mapping1.Value); },
21-
mapping1 => { Assert.Equal((ulong)5, mapping1.Key); Assert.Equal((ulong)4, mapping1.Value); }
20+
mapping2 => { Assert.Equal((ulong)4, mapping2.Key); Assert.Equal((ulong)1, mapping2.Value); },
21+
mapping3 => { Assert.Equal((ulong)5, mapping3.Key); Assert.Equal((ulong)4, mapping3.Value); }
2222
);
2323
}
2424
}

ImperatorToCK3.UnitTests/CK3/Provinces/ProvinceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void ProvinceCanBeLoadedFromStream() {
2929
var reader = new BufferedReader(
3030
"{ culture=roman random_key=random_value religion=orthodox holding=castle_holding }"
3131
);
32-
var province = new Province(42, reader);
32+
var province = new Province(42, reader, new Date(867,1,1));
3333
Assert.Equal((ulong)42, province.ID);
3434
Assert.Equal("orthodox", province.Religion);
3535
Assert.Equal("roman", province.Culture);

ImperatorToCK3.UnitTests/CK3/Provinces/ProvincesTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Xunit;
2+
using commonItems;
23

34
namespace ImperatorToCK3.UnitTests.CK3.Provinces {
45
[Collection("Sequential")]
@@ -12,7 +13,7 @@ [Fact] public void ProvincesDefaltToEmpty() {
1213

1314
[Fact]
1415
public void ProvincesAreProperlyLoadedFromFile() {
15-
var provinces = new ImperatorToCK3.CK3.Provinces.Provinces("TestFiles/CK3ProvincesHistoryFile.txt");
16+
var provinces = new ImperatorToCK3.CK3.Provinces.Provinces("TestFiles/CK3ProvincesHistoryFile.txt", new Date(867,1,1));
1617

1718
Assert.Equal(4, provinces.StoredProvinces.Count);
1819
Assert.Equal("slovien", provinces.StoredProvinces[3080].Culture);

ImperatorToCK3.UnitTests/CK3/Titles/TitleHistoryTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using ImperatorToCK3.CK3.Titles;
22
using Xunit;
3+
using commonItems;
34

45
namespace ImperatorToCK3.UnitTests.CK3.Titles {
56
public class TitleHistoryTests {
@@ -33,7 +34,7 @@ public void DevelopmentLevelDefaultsToNull() {
3334

3435
[Fact]
3536
public void HistoryCanBeLoadedFromStream() {
36-
var titlesHistory = new TitlesHistory("TestFiles/title_history");
37+
var titlesHistory = new TitlesHistory("TestFiles/title_history", new Date(867,1,1));
3738
var history = titlesHistory.PopTitleHistory("k_rome");
3839

3940
Assert.Equal("67", history.Holder);
@@ -42,7 +43,7 @@ public void HistoryCanBeLoadedFromStream() {
4243

4344
[Fact]
4445
public void HistoryIsLoadedFromDatedBlocks() {
45-
var titlesHistory = new TitlesHistory("TestFiles/title_history");
46+
var titlesHistory = new TitlesHistory("TestFiles/title_history", new Date(867, 1, 1));
4647
var history = titlesHistory.PopTitleHistory("k_greece");
4748

4849
Assert.Equal("420", history.Holder);

ImperatorToCK3.UnitTests/CK3/Titles/TitleTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void CapitalBaronyDefaultsToZero() {
8787

8888
[Fact]
8989
public void HistoryCanBeAdded() {
90-
var titlesHistory = new TitlesHistory("TestFiles/title_history");
90+
var titlesHistory = new TitlesHistory("TestFiles/title_history", new Date(867,1,1));
9191
var history = titlesHistory.PopTitleHistory("k_greece");
9292
var title = new Title();
9393
title.AddHistory(new LandedTitles(), history);

ImperatorToCK3/CK3/Characters/Character.cs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,6 @@ public class Character {
2828

2929
public Imperator.Characters.Character? ImperatorCharacter { get; set; }
3030

31-
public void InitializeFromImperator(
32-
Imperator.Characters.Character impCharacter,
33-
ReligionMapper religionMapper,
34-
CultureMapper cultureMapper,
35-
TraitMapper traitMapper,
36-
NicknameMapper nicknameMapper,
37-
LocalizationMapper localizationMapper,
38-
ProvinceMapper provinceMapper, // used to determine ck3 province for religion mapper
39-
DeathReasonMapper deathReasonMapper,
40-
bool ConvertBirthAndDeathDates = true
41-
) {
42-
var dateOnConversion = new Date(867, 1, 1);
43-
InitializeFromImperator(impCharacter, religionMapper, cultureMapper, traitMapper, nicknameMapper, localizationMapper, provinceMapper, deathReasonMapper, ConvertBirthAndDeathDates, dateOnConversion);
44-
}
4531
public void InitializeFromImperator(
4632
Imperator.Characters.Character impCharacter,
4733
ReligionMapper religionMapper,
@@ -52,7 +38,8 @@ public void InitializeFromImperator(
5238
ProvinceMapper provinceMapper, // used to determine ck3 province for religion mapper
5339
DeathReasonMapper deathReasonMapper,
5440
bool convertBirthAndDeathDates,
55-
Date dateOnConversion
41+
Date dateOnConversion,
42+
Date ck3BookmarkDate
5643
) {
5744
ImperatorCharacter = impCharacter;
5845
ImperatorCharacter.CK3Character = this;
@@ -160,8 +147,8 @@ Date dateOnConversion
160147
DeathReason = deathReasonMapper.GetCK3ReasonForImperatorReason(impDeathReason);
161148
}
162149
if (!convertBirthAndDeathDates) { // if option to convert character age is chosen
163-
BirthDate.AddYears((int)new Date(867, 1, 1).DiffInYears(dateOnConversion));
164-
DeathDate?.AddYears((int)new Date(867, 1, 1).DiffInYears(dateOnConversion));
150+
BirthDate.AddYears((int)ck3BookmarkDate.DiffInYears(dateOnConversion));
151+
DeathDate?.AddYears((int)ck3BookmarkDate.DiffInYears(dateOnConversion));
165152
}
166153
}
167154

ImperatorToCK3/CK3/Provinces/Province.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
namespace ImperatorToCK3.CK3.Provinces {
77
public class Province {
88
public Province() { }
9-
public Province(ulong id, BufferedReader reader) {
9+
public Province(ulong id, BufferedReader reader, Date ck3BookmarkDate) {
1010
// Load from a country file, if one exists. Otherwise rely on defaults.
1111
ID = id;
12-
details = new ProvinceDetails(reader);
12+
details = new ProvinceDetails(reader, ck3BookmarkDate);
1313
}
1414
public Province(ulong id, Province otherProvince) {
1515
ID = id;

0 commit comments

Comments
 (0)