Skip to content

Don't output culture and faith for provinces that are not county capitals #2139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions ImperatorToCK3.UnitTests/Outputter/ProvinceOutputterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,70 @@ namespace ImperatorToCK3.UnitTests.Outputter;
[CollectionDefinition("Sequential", DisableParallelization = true)]
public class ProvinceOutputterTests {
[Fact]
public void CultureIsOutputted() {
public void CultureIsOutputtedIfProvinceIsCountyCapital() {
var provReader = new BufferedReader("culture=roman");
var province = new Province(1, provReader);

var sb = new StringBuilder();
ProvinceOutputter.WriteProvince(sb, province);
ProvinceOutputter.WriteProvince(sb, province, isCountyCapital: true);

var sr = new StringReader(sb.ToString());
Assert.Equal("1={", sr.ReadLine());
Assert.Equal("\tculture = roman", sr.ReadLine());
Assert.Equal("\tholding = none", sr.ReadLine());
Assert.Equal("}", sr.ReadLine());
}

[Fact]
public void CultureIsNotOutputtedIfProvinceIsNotCountyCapital() {
var provReader = new BufferedReader("culture=roman");
var province = new Province(1, provReader);

var sb = new StringBuilder();
ProvinceOutputter.WriteProvince(sb, province, isCountyCapital: false);

var sr = new StringReader(sb.ToString());
Assert.Equal("1={", sr.ReadLine());
Assert.Equal("\tholding = none", sr.ReadLine());
Assert.Equal("}", sr.ReadLine());
}

[Fact]
public void ReligionIsOutputted() {
public void ReligionIsOutputtedIfProvinceIsCountyCapital() {
var provReader = new BufferedReader("religion=orthodox");
var province = new Province(1, provReader);

var sb = new StringBuilder();
ProvinceOutputter.WriteProvince(sb, province);
ProvinceOutputter.WriteProvince(sb, province, isCountyCapital: true);

var sr = new StringReader(sb.ToString());
Assert.Equal("1={", sr.ReadLine());
Assert.Equal("\treligion = orthodox", sr.ReadLine());
Assert.Equal("\tholding = none", sr.ReadLine());
Assert.Equal("}", sr.ReadLine());
}

[Fact]
public void ReligionIsNotOutputtedIfProvinceIsNotCountyCapital() {
var provReader = new BufferedReader("religion=orthodox");
var province = new Province(1, provReader);

var sb = new StringBuilder();
ProvinceOutputter.WriteProvince(sb, province, isCountyCapital: false);

var sr = new StringReader(sb.ToString());
Assert.Equal("1={", sr.ReadLine());
Assert.Equal("\tholding = none", sr.ReadLine());
Assert.Equal("}", sr.ReadLine());
}

[Fact]
public void HoldingIsOutputted() {
var provReader = new BufferedReader("holding = castle_holding");
var province = new Province(1, provReader);

var sb = new StringBuilder();
ProvinceOutputter.WriteProvince(sb, province);
ProvinceOutputter.WriteProvince(sb, province, isCountyCapital: true);

var sr = new StringReader(sb.ToString());
Assert.Equal("1={", sr.ReadLine());
Expand All @@ -60,7 +88,7 @@ public void BuildingsAreOutputted() {
var province = new Province(1, provReader);

var sb = new StringBuilder();
ProvinceOutputter.WriteProvince(sb, province);
ProvinceOutputter.WriteProvince(sb, province, isCountyCapital: true);

var sr = new StringReader(sb.ToString());
Assert.Equal("1={", sr.ReadLine());
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Provinces/ProvinceHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void SetCultureId(string cultureId, Date? date) {
var historyValue = History.GetFieldValue("holding", date);
return historyValue switch {
StringOfItem stringOfItem => stringOfItem.ToString(),
string cultureStr => cultureStr,
string holdingTypeStr => holdingTypeStr,
_ => null
};
}
Expand Down
8 changes: 7 additions & 1 deletion ImperatorToCK3/Outputter/ProvinceOutputter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
namespace ImperatorToCK3.Outputter;

public static class ProvinceOutputter {
public static void WriteProvince(StringBuilder sb, Province province) {
public static void WriteProvince(StringBuilder sb, Province province, bool isCountyCapital) {
// If the province is not a county capital, remove the "culture" and "faith" fields.
if (!isCountyCapital) {
province.History.Fields.Remove("culture");
province.History.Fields.Remove("faith");
}

var serializedHistory = PDXSerializer.Serialize(province.History, indent: "\t");
if (string.IsNullOrWhiteSpace(serializedHistory.Trim())) {
return;
Expand Down
12 changes: 10 additions & 2 deletions ImperatorToCK3/Outputter/ProvincesOutputter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using ImperatorToCK3.CK3.Titles;
using ImperatorToCK3.CommonUtils;
using Open.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace ImperatorToCK3.Outputter;
Expand All @@ -15,6 +17,12 @@ public static async Task OutputProvinces(
Title.LandedTitles titles
) {
Logger.Info("Writing provinces...");

HashSet<ulong> countyCapitalProvinceIds = titles.Counties
.Select(title => title.CapitalBaronyProvinceId)
.Where(id => id is not null)
.Select(id => id!.Value)
.ToHashSet();

// Output provinces to files named after their de jure kingdoms.
var alreadyOutputtedProvinces = new ConcurrentHashSet<ulong>();
Expand All @@ -27,7 +35,7 @@ Title.LandedTitles titles
continue;
}

ProvinceOutputter.WriteProvince(sb, province);
ProvinceOutputter.WriteProvince(sb, province, countyCapitalProvinceIds.Contains(province.Id));
alreadyOutputtedProvinces.Add(province.Id);
}

Expand All @@ -50,7 +58,7 @@ Title.LandedTitles titles

if (duchy.DuchyContainsProvince(province.Id)) {
sb.AppendLine($"# {duchy.Id}");
ProvinceOutputter.WriteProvince(sb, province);
ProvinceOutputter.WriteProvince(sb, province, countyCapitalProvinceIds.Contains(province.Id));
alreadyOutputtedProvinces.Add(province.Id);
}
}
Expand Down
Loading