Skip to content

Speed up the writing of the generated mod #2009

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 5 commits into from
Jun 23, 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
29 changes: 15 additions & 14 deletions ImperatorToCK3.UnitTests/Outputter/CoatOfArmsOutputterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Xunit;

namespace ImperatorToCK3.UnitTests.Outputter;
Expand All @@ -40,16 +41,16 @@ public CoatOfArmsOutputterTests() {
}

[Fact]
public void CoaIsOutputtedForCountryWithFlagSet() {
public async Task CoaIsOutputtedForCountryWithFlagSet() {
var titles = new Title.LandedTitles();

var countries = new CountryCollection();
var countryReader = new BufferedReader("tag=ADI flag=testFlag");
var country = Country.Parse(countryReader, 1);
countries.Add(country);

const string outputModName = "outputMod";
var outputPath = Path.Combine("output", outputModName, "common/coat_of_arms/coat_of_arms/zzz_IRToCK3_coas.txt");
const string outputModPath = "output/outputMod";
var outputPath = Path.Combine(outputModPath, "common/coat_of_arms/coat_of_arms/zzz_IRToCK3_coas.txt");
SystemUtils.TryCreateFolder(CommonFunctions.GetPath(outputPath));

var ck3Religions = new ReligionCollection(titles);
Expand All @@ -73,28 +74,28 @@ public void CoaIsOutputtedForCountryWithFlagSet() {
new List<KeyValuePair<Country, Dependency?>>()
);

CoatOfArmsOutputter.OutputCoas(outputModName, titles, new List<Dynasty>());
await CoatOfArmsOutputter.OutputCoas(outputModPath, titles, new List<Dynasty>());

using var file = File.OpenRead(outputPath);
await using var file = File.OpenRead(outputPath);
var reader = new StreamReader(file);

Assert.Equal("d_IRTOCK3_ADI={", reader.ReadLine());
Assert.Equal("\tpattern=\"pattern_solid.tga\"", reader.ReadLine());
Assert.Equal("\tcolor1=red color2=green color3=blue", reader.ReadLine());
Assert.Equal("}", reader.ReadLine());
Assert.Equal("d_IRTOCK3_ADI={", await reader.ReadLineAsync());
Assert.Equal("\tpattern=\"pattern_solid.tga\"", await reader.ReadLineAsync());
Assert.Equal("\tcolor1=red color2=green color3=blue", await reader.ReadLineAsync());
Assert.Equal("}", await reader.ReadLineAsync());
}

[Fact]
public void CoaIsNotOutputtedForCountryWithoutFlagSet() {
public async Task CoaIsNotOutputtedForCountryWithoutFlagSet() {
var titles = new Title.LandedTitles();

var countries = new CountryCollection();
var countryReader = new BufferedReader("tag=BDI");
var country = Country.Parse(countryReader, 2);
countries.Add(country);

const string outputModName = "outputMod";
var outputPath = Path.Combine("output", outputModName, "common/coat_of_arms/coat_of_arms/zzz_IRToCK3_coas.txt");
const string outputModPath = "output/outputMod";
var outputPath = Path.Combine(outputModPath, "common/coat_of_arms/coat_of_arms/zzz_IRToCK3_coas.txt");
SystemUtils.TryCreateFolder(CommonFunctions.GetPath(outputPath));

var ck3Religions = new ReligionCollection(titles);
Expand All @@ -118,9 +119,9 @@ public void CoaIsNotOutputtedForCountryWithoutFlagSet() {
new List<KeyValuePair<Country, Dependency?>>()
);

CoatOfArmsOutputter.OutputCoas(outputModName, titles, new List<Dynasty>());
await CoatOfArmsOutputter.OutputCoas(outputModPath, titles, new List<Dynasty>());

using var file = File.OpenRead(outputPath);
await using var file = File.OpenRead(outputPath);
var reader = new StreamReader(file);

Assert.True(reader.EndOfStream);
Expand Down
23 changes: 12 additions & 11 deletions ImperatorToCK3.UnitTests/Outputter/DynastiesOutputterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using ImperatorToCK3.Outputter;
using System;
using System.IO;
using System.Threading.Tasks;
using Xunit;

namespace ImperatorToCK3.UnitTests.Outputter;
Expand All @@ -22,7 +23,7 @@ public class DynastiesOutputterTests {
private static readonly Date ConversionDate = new(867, 1, 1);

[Fact]
public void DynastiesAreOutputted() {
public async Task DynastiesAreOutputted() {
const string outputModPath = "output/outputMod";
var locDB = new LocDB("english");
const string imperatorRoot = "TestFiles/Imperator/root";
Expand Down Expand Up @@ -56,20 +57,20 @@ public void DynastiesAreOutputted() {
File.Delete(outputPath);
}
SystemUtils.TryCreateFolder(CommonFunctions.GetPath(outputPath));
DynastiesOutputter.OutputDynasties(outputModPath, dynasties);
await DynastiesOutputter.OutputDynasties(outputModPath, dynasties);

using var file = File.OpenRead(outputPath);
await using var file = File.OpenRead(outputPath);
var reader = new StreamReader(file);

Assert.Equal("dynn_irtock3_1={", reader.ReadLine());
Assert.Equal("\tname = dynn_irtock3_1", reader.ReadLine());
Assert.Equal("}", reader.ReadLine());
Assert.Equal("dynn_irtock3_1={", await reader.ReadLineAsync());
Assert.Equal("\tname = dynn_irtock3_1", await reader.ReadLineAsync());
Assert.Equal("}", await reader.ReadLineAsync());

Assert.Equal("dynn_irtock3_2={", reader.ReadLine());
Assert.Equal("\tname = dynn_irtock3_2", reader.ReadLine());
Assert.Equal("\tculture = roman", reader.ReadLine());
Assert.Equal("}", reader.ReadLine());
Assert.True(string.IsNullOrWhiteSpace(reader.ReadLine()));
Assert.Equal("dynn_irtock3_2={", await reader.ReadLineAsync());
Assert.Equal("\tname = dynn_irtock3_2", await reader.ReadLineAsync());
Assert.Equal("\tculture = roman", await reader.ReadLineAsync());
Assert.Equal("}", await reader.ReadLineAsync());
Assert.True(string.IsNullOrWhiteSpace(await reader.ReadLineAsync()));
Assert.True(reader.EndOfStream);
}
}
12 changes: 6 additions & 6 deletions ImperatorToCK3.UnitTests/Outputter/NamedColorOutputterTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using commonItems;
using commonItems.Colors;
using ImperatorToCK3.Outputter;
using System.IO;
using System.Threading.Tasks;
using Xunit;

namespace ImperatorToCK3.UnitTests.Outputter;

public class NamedColorOutputterTests {
[Fact]
public void OutputterOutputsColorsNotFoundInCK3ColorCollection() {
public async Task OutputterOutputsColorsNotFoundInCK3ColorCollection() {
var imperatorColors = new NamedColorCollection {
["a"] = new(1, 1, 1),
["b"] = new(2, 2, 2),
Expand All @@ -22,16 +22,16 @@ public void OutputterOutputsColorsNotFoundInCK3ColorCollection() {
};

Directory.CreateDirectory("output/colors_test/common/named_colors");
NamedColorsOutputter.OutputNamedColors("colors_test", imperatorColors, ck3Colors);
var output = File.ReadAllText("output/colors_test/common/named_colors/IRtoCK3_colors_from_Imperator.txt");
await NamedColorsOutputter.OutputNamedColors("output/colors_test", imperatorColors, ck3Colors);
var output = await File.ReadAllTextAsync("output/colors_test/common/named_colors/IRtoCK3_colors_from_Imperator.txt");
Assert.DoesNotContain("a=", output);
Assert.DoesNotContain("b=", output);
Assert.DoesNotContain("c=rgb {3 3 3}", output);
Assert.DoesNotContain("d=rgb {4 4 4}", output);
}

[Fact]
public void OutputterOutputsNothingWhenThereIsNothingToOutput() {
public async Task OutputterOutputsNothingWhenThereIsNothingToOutput() {
var imperatorColors = new NamedColorCollection {
["a"] = new(1, 1, 1),
["b"] = new(2, 2, 2),
Expand All @@ -44,7 +44,7 @@ public void OutputterOutputsNothingWhenThereIsNothingToOutput() {
};

Directory.CreateDirectory("output/colors_test/common/named_colors");
NamedColorsOutputter.OutputNamedColors("colors_test2", imperatorColors, ck3Colors);
await NamedColorsOutputter.OutputNamedColors("colors_test2", imperatorColors, ck3Colors);
Assert.False(File.Exists("output/colors_test2/common/named_colors/IRtoCK3_colors_from_Imperator.txt"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
using ImperatorToCK3.Outputter;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Xunit;

namespace ImperatorToCK3.UnitTests.Outputter;

public class SuccessionTriggersOutputterTests {
[Fact]
public void PrimogenitureAndSeniorityTriggersAreOutputted() {
const string outputModName = "outputMod";
public async Task PrimogenitureAndSeniorityTriggersAreOutputted() {
const string outputModPath = "output/outputMod";
var outputFilePath = Path.Combine(
"output",
outputModName,
outputModPath,
"common",
"scripted_triggers",
"IRToCK3_succession_triggers.txt"
Expand All @@ -34,20 +34,20 @@ public void PrimogenitureAndSeniorityTriggersAreOutputted() {

SystemUtils.TryCreateFolder(CommonFunctions.GetPath(outputFilePath));

SuccessionTriggersOutputter.OutputSuccessionTriggers(outputModName, titles, date);
await SuccessionTriggersOutputter.OutputSuccessionTriggers(outputModPath, titles, date);

using var file = File.OpenRead(outputFilePath);
await using var file = File.OpenRead(outputFilePath);
var reader = new StreamReader(file);
Assert.Equal("historical_succession_access_single_heir_succession_law_trigger={", reader.ReadLine());
Assert.Equal("\tOR={", reader.ReadLine());
Assert.Equal("\t\thas_title=title:k_kingdom1", reader.ReadLine());
Assert.Equal("\t}", reader.ReadLine());
Assert.Equal("}", reader.ReadLine());
Assert.Equal("historical_succession_access_single_heir_dynasty_house_trigger={", reader.ReadLine());
Assert.Equal("\tOR={", reader.ReadLine());
Assert.Equal("\t\thas_title=title:k_kingdom2", reader.ReadLine());
Assert.Equal("\t}", reader.ReadLine());
Assert.Equal("}", reader.ReadLine());
Assert.Equal("historical_succession_access_single_heir_succession_law_trigger={", await reader.ReadLineAsync());
Assert.Equal("\tOR={", await reader.ReadLineAsync());
Assert.Equal("\t\thas_title=title:k_kingdom1", await reader.ReadLineAsync());
Assert.Equal("\t}", await reader.ReadLineAsync());
Assert.Equal("}", await reader.ReadLineAsync());
Assert.Equal("historical_succession_access_single_heir_dynasty_house_trigger={", await reader.ReadLineAsync());
Assert.Equal("\tOR={", await reader.ReadLineAsync());
Assert.Equal("\t\thas_title=title:k_kingdom2", await reader.ReadLineAsync());
Assert.Equal("\t}", await reader.ReadLineAsync());
Assert.Equal("}", await reader.ReadLineAsync());
Assert.True(reader.EndOfStream);
}
}
95 changes: 48 additions & 47 deletions ImperatorToCK3.UnitTests/Outputter/TitlesOutputterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
using ImperatorToCK3.CK3.Titles;
using ImperatorToCK3.Outputter;
using System.IO;
using System.Threading.Tasks;
using Xunit;

namespace ImperatorToCK3.UnitTests.Outputter;

public class TitlesOutputterTests {
[Fact]
public void TitlesAreOutputted() {
const string outputModName = "outputMod";
public async Task TitlesAreOutputted() {
const string outputModPath = "output/outputMod";

var titles = new Title.LandedTitles();
var kingdom = titles.Add("k_kingdom");
Expand All @@ -27,82 +28,82 @@ public void TitlesAreOutputted() {
var specialTitle = titles.Add("k_special_title");
specialTitle.History.AddFieldValue(new Date(20, 1, 1), "holder", "holder", "bob_42");

var titleHistoryPath = Path.Combine("output", outputModName, "history", "titles");
var titleHistoryPath = Path.Combine(outputModPath, "history", "titles");
var kingdomHistoryPath = Path.Combine(titleHistoryPath, "k_kingdom.txt");
var otherTitlesHistoryPath = Path.Combine(titleHistoryPath, "00_other_titles.txt");
SystemUtils.TryCreateFolder(titleHistoryPath);

var landedTitlesPath = Path.Combine("output", outputModName, "common", "landed_titles", "00_landed_titles.txt");
var landedTitlesPath = Path.Combine(outputModPath, "common", "landed_titles", "00_landed_titles.txt");
SystemUtils.TryCreateFolder(CommonFunctions.GetPath(landedTitlesPath));

TitlesOutputter.OutputTitles(outputModName, titles);
await TitlesOutputter.OutputTitles(outputModPath, titles);

Assert.True(File.Exists(kingdomHistoryPath));
using var kingdomHistoryFile = File.OpenRead(kingdomHistoryPath);
await using var kingdomHistoryFile = File.OpenRead(kingdomHistoryPath);
var reader = new StreamReader(kingdomHistoryFile);
Assert.Equal("k_kingdom={", reader.ReadLine());
Assert.Equal("\t20.1.1 = { liege = 0 }", reader.ReadLine());
Assert.Equal("}", reader.ReadLine());
Assert.Equal("k_kingdom={", await reader.ReadLineAsync());
Assert.Equal("\t20.1.1 = { liege = 0 }", await reader.ReadLineAsync());
Assert.Equal("}", await reader.ReadLineAsync());
Assert.True(reader.EndOfStream);

Assert.True(File.Exists(otherTitlesHistoryPath));
using var otherTitlesHistoryFile = File.OpenRead(otherTitlesHistoryPath);
await using var otherTitlesHistoryFile = File.OpenRead(otherTitlesHistoryPath);
reader = new StreamReader(otherTitlesHistoryFile);
Assert.Equal("k_special_title={", reader.ReadLine());
Assert.Equal("\t20.1.1 = { holder = bob_42 }", reader.ReadLine());
Assert.Equal("}", reader.ReadLine());
Assert.Equal("k_special_title={", await reader.ReadLineAsync());
Assert.Equal("\t20.1.1 = { holder = bob_42 }", await reader.ReadLineAsync());
Assert.Equal("}", await reader.ReadLineAsync());
Assert.True(reader.EndOfStream);

Assert.True(File.Exists(landedTitlesPath));
using var landedTitlesFile = File.OpenRead(landedTitlesPath);
await using var landedTitlesFile = File.OpenRead(landedTitlesPath);
reader = new StreamReader(landedTitlesFile);
Assert.Equal("k_kingdom = {", reader.ReadLine());
Assert.Equal("\td_duchy = {", reader.ReadLine());
Assert.Equal("\t\tc_county = {", reader.ReadLine());
Assert.Equal("\t\t\tb_barony = {", reader.ReadLine());
Assert.Equal("\t\t\t\tlandless = no", reader.ReadLine());
Assert.Equal("\t\t\t\tdefinite_form = no", reader.ReadLine());
Assert.Equal("\t\t\t\truler_uses_title_name = no", reader.ReadLine());
Assert.Equal("\t\t\t}", reader.ReadLine());
Assert.Equal("\t\t\tlandless = no", reader.ReadLine());
Assert.Equal("\t\t\tdefinite_form = no", reader.ReadLine());
Assert.Equal("\t\t\truler_uses_title_name = no", reader.ReadLine());
Assert.Equal("\t\t}", reader.ReadLine());
Assert.Equal("\t\tlandless = no", reader.ReadLine());
Assert.Equal("\t\tdefinite_form = no", reader.ReadLine());
Assert.Equal("\t\truler_uses_title_name = no", reader.ReadLine());
Assert.Equal("\t}", reader.ReadLine());
Assert.Equal("\tlandless = no", reader.ReadLine());
Assert.Equal("\tdefinite_form = no", reader.ReadLine());
Assert.Equal("\truler_uses_title_name = no", reader.ReadLine());
Assert.Equal("}", reader.ReadLine());
Assert.Equal("k_special_title = {", reader.ReadLine());
Assert.Equal("\tlandless = no", reader.ReadLine());
Assert.Equal("\tdefinite_form = no", reader.ReadLine());
Assert.Equal("\truler_uses_title_name = no", reader.ReadLine());
Assert.Equal("}", reader.ReadLine());
Assert.Equal("k_kingdom = {", await reader.ReadLineAsync());
Assert.Equal("\td_duchy = {", await reader.ReadLineAsync());
Assert.Equal("\t\tc_county = {", await reader.ReadLineAsync());
Assert.Equal("\t\t\tb_barony = {", await reader.ReadLineAsync());
Assert.Equal("\t\t\t\tlandless = no", await reader.ReadLineAsync());
Assert.Equal("\t\t\t\tdefinite_form = no", await reader.ReadLineAsync());
Assert.Equal("\t\t\t\truler_uses_title_name = no", await reader.ReadLineAsync());
Assert.Equal("\t\t\t}", await reader.ReadLineAsync());
Assert.Equal("\t\t\tlandless = no", await reader.ReadLineAsync());
Assert.Equal("\t\t\tdefinite_form = no", await reader.ReadLineAsync());
Assert.Equal("\t\t\truler_uses_title_name = no", await reader.ReadLineAsync());
Assert.Equal("\t\t}", await reader.ReadLineAsync());
Assert.Equal("\t\tlandless = no", await reader.ReadLineAsync());
Assert.Equal("\t\tdefinite_form = no", await reader.ReadLineAsync());
Assert.Equal("\t\truler_uses_title_name = no", await reader.ReadLineAsync());
Assert.Equal("\t}", await reader.ReadLineAsync());
Assert.Equal("\tlandless = no", await reader.ReadLineAsync());
Assert.Equal("\tdefinite_form = no", await reader.ReadLineAsync());
Assert.Equal("\truler_uses_title_name = no", await reader.ReadLineAsync());
Assert.Equal("}", await reader.ReadLineAsync());
Assert.Equal("k_special_title = {", await reader.ReadLineAsync());
Assert.Equal("\tlandless = no", await reader.ReadLineAsync());
Assert.Equal("\tdefinite_form = no", await reader.ReadLineAsync());
Assert.Equal("\truler_uses_title_name = no", await reader.ReadLineAsync());
Assert.Equal("}", await reader.ReadLineAsync());
Assert.True(reader.EndOfStream);
}

[Fact]
public void VariablesAreOutputted() {
const string outputModName = "outputMod2";
public async Task VariablesAreOutputted() {
const string outputModPath = "output/outputMod2";
var titles = new Title.LandedTitles();
titles.Variables.Add("default_ai_priority", 20);
titles.Variables.Add("default_ai_aggressiveness", 40);

var titleHistoryPath = Path.Combine("output", outputModName, "history", "titles");
var titleHistoryPath = Path.Combine(outputModPath, "history", "titles");
SystemUtils.TryCreateFolder(titleHistoryPath);
var landedTitlesPath = Path.Combine("output", outputModName, "common", "landed_titles", "00_landed_titles.txt");
var landedTitlesPath = Path.Combine(outputModPath, "common", "landed_titles", "00_landed_titles.txt");
SystemUtils.TryCreateFolder(CommonFunctions.GetPath(landedTitlesPath));

TitlesOutputter.OutputTitles(outputModName, titles);
await TitlesOutputter.OutputTitles(outputModPath, titles);

Assert.True(File.Exists(landedTitlesPath));
using var landedTitlesFile = File.OpenRead(landedTitlesPath);
await using var landedTitlesFile = File.OpenRead(landedTitlesPath);
var reader = new StreamReader(landedTitlesFile);
Assert.Equal("@default_ai_priority=20", reader.ReadLine());
Assert.Equal("@default_ai_aggressiveness=40", reader.ReadLine());
Assert.Equal("@default_ai_priority=20", await reader.ReadLineAsync());
Assert.Equal("@default_ai_aggressiveness=40", await reader.ReadLineAsync());
Assert.True(reader.EndOfStream);
}
}
Loading
Loading