Skip to content

Commit

Permalink
Merge branch 'master' into feature/rajas-of-asia-support
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains committed Sep 16, 2024
2 parents 4cfb3e1 + b09f0a9 commit 128d4b1
Show file tree
Hide file tree
Showing 57 changed files with 2,810 additions and 1,434 deletions.
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ updates:

- package-ecosystem: "nuget"
directory: "/ImperatorToCK3.UnitTests/"
# Check the nuget registry for updates every day (weekdays) schedule:
schedule:
interval: "weekly"

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jobs:
with:
fronter_dir: 'Fronter.NET'
release_dir: 'Publish'
self_contained: ${{ matrix.build != 'win-x64' }} # InnoSetup takes care of installing the .NET runtime on Windows.
build_updater: ${{ matrix.build != 'win-x64' }} # Windows release uses InnoSetup instead.
env:
BACKBLAZE_KEY_ID: ${{ secrets.BACKBLAZE_KEY_ID }}
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
path = Fronter.NET
url = https://github.com/ParadoxGameConverters/Fronter.NET

[submodule "InnoDependencyInstaller"]
path = InnoDependencyInstaller
url = https://github.com/IhateTrains/InnoDependencyInstaller.git
branch = NET-9
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using ImperatorToCK3.Mappers.TagTitle;
using ImperatorToCK3.Mappers.Trait;
using ImperatorToCK3.UnitTests.TestHelpers;
using Open.Collections;
using System.Collections.Generic;
using System.Linq;
using Xunit;
Expand Down Expand Up @@ -60,8 +61,8 @@ static CharacterCollectionTests() {
areas.LoadAreas(irModFS, irProvinces);
irRegionMapper = new ImperatorRegionMapper(areas, irMapData);
irRegionMapper.LoadRegions(irModFS, colorFactory);
var ck3ModFlags = new List<string>();

var ck3ModFlags = new System.Collections.Generic.OrderedDictionary<string, bool>();
cultures = new CultureCollection(colorFactory, new PillarCollection(colorFactory, ck3ModFlags), ck3ModFlags);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CultureCollectionTests {
private static readonly ModFilesystem ck3ModFS = new("TestFiles/CK3/game", Array.Empty<Mod>());
private static readonly PillarCollection pillars;
private static readonly ColorFactory colorFactory = new();
private static readonly List<string> ck3ModFlags = [];
private static readonly OrderedDictionary<string, bool> ck3ModFlags = [];

static CultureCollectionTests() {
pillars = new PillarCollection(colorFactory, []) {
Expand Down
26 changes: 26 additions & 0 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 commonItems.Serialization;
using ImperatorToCK3.CK3;
using ImperatorToCK3.CK3.Characters;
using ImperatorToCK3.CK3.Dynasties;
Expand Down Expand Up @@ -223,4 +224,29 @@ public void CultureIsBasedOnFirstImperatorMember() {

Assert.Equal("latin", dynasty.CultureId);
}

[Fact]
public void UnlocalizedNameIsCorrectlySerialized() {
// A dynasty can have a raw unlocalized name. If such name contains whitespace, it must be enclosed in quotes.
var reader = new BufferedReader(
"""
= {
name = "ve Iberia"
culture = georgian
}
""");
var dynasty = new Dynasty("georgian_dynn_Iberia", reader);
Assert.Equal("georgian_dynn_Iberia", dynasty.Id);
Assert.Equal("ve Iberia", dynasty.Name);
Assert.Equal("georgian", dynasty.CultureId);

var serialized = PDXSerializer.Serialize(dynasty);

Assert.Equal("""
{
name = "ve Iberia"
culture = georgian
}
""", serialized);
}
}
193 changes: 193 additions & 0 deletions ImperatorToCK3.UnitTests/CK3/ParserExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
using commonItems;
using ImperatorToCK3.CK3;
using System.Collections.Generic;
using Xunit;

namespace ImperatorToCK3.UnitTests.CK3;

[Collection("Sequential")]
[CollectionDefinition("Sequential", DisableParallelization = true)]
public class ParserExtensionsTests {
[Theory]
[InlineData(true, false, false, 0, 0)]
[InlineData(false, true, false, 1, 1)]
[InlineData(false, false, true, 2, 0)]
[InlineData(true, true, false, 0, 1)]
public void CorrectModDependentBranchesAreUsed(bool wtwsms, bool tfe, bool vanilla, int expectedValue1,
int expectedValue2) {
var ck3ModFlags = new Dictionary<string, bool> {["wtwsms"] = wtwsms, ["tfe"] = tfe, ["vanilla"] = vanilla,};

var blocReader = new BufferedReader(
"""
MOD_DEPENDENT = {
IF @wtwsms = { # Interpolated expression without brackets is valid, therefor should be supported.
value1 = 0
} ELSE_IF tfe = {# Simple mod flag string should be supported as well.
value1 = 1
} ELSE = {
value1 = 2
}
IF @[wtwsms|vanilla|tfe] = { # Logical OR, example of more complex interpolated expression.
value2 = 0
}
IF @[tfe] = { # Will override the previous value2.
value2 = 1
}
}
""");

int? value1 = null;
int? value2 = null;
var parser = new Parser();
parser.RegisterModDependentBloc(ck3ModFlags);
parser.RegisterKeyword("value1", reader => value1 = reader.GetInt());
parser.RegisterKeyword("value2", reader => value2 = reader.GetInt());
parser.ParseStream(blocReader);

Assert.Equal(expectedValue1, value1);
Assert.Equal(expectedValue2, value2);
}

[Fact]
public void ExceptionIsThrownWhenUnknownModFlagIsEncounteredInInterpolatedExpression() {
var reader1 = new BufferedReader(
"""
MOD_DEPENDENT = {
IF @[unknown_mod] = { # Undefined mod flag in interpolated expression.
value = 1
} ELSE = {
value = 2
}
}
""");

int? value = null;
Dictionary<string, bool> modFlags = new();

var parser1 = new Parser();
parser1.RegisterModDependentBloc(modFlags);
parser1.RegisterKeyword("value", reader => value = reader.GetInt());
Assert.Throws<NCalc.Exceptions.NCalcParameterNotDefinedException>(() => parser1.ParseStream(reader1));
Assert.Null(value);
}

[Fact]
public void VariableConditionResolvesToFalseWhenVariableIsNotDefined() {
var reader1 = new BufferedReader(
"""
MOD_DEPENDENT = {
IF @unknown_variable = { # Undefined variable in interpolated expression.
value = 1
} ELSE = {
value = 2
}
}
""");

int? value = null;
Dictionary<string, bool> modFlags = new();

var parser1 = new Parser();
parser1.RegisterModDependentBloc(modFlags);
parser1.RegisterKeyword("value", reader => value = reader.GetInt());
parser1.ParseStream(reader1); // Should not throw.
Assert.Equal(2, value);
}

[Fact]
public void ElseIfAfterElseIsIgnored() {
Dictionary<string, bool> ck3ModFlags = new() {{"wtwsms", false}, {"tfe", true}, {"vanilla", false},};

var blocReader = new BufferedReader(
"""
MOD_DEPENDENT = {
IF wtwsms = {
value = 0
} ELSE = {
value = 2
} ELSE_IF tfe = { # Should be ignored, even if the condition is true.
value = 3
}
}
""");

int? value = null;
var parser = new Parser();
parser.RegisterModDependentBloc(ck3ModFlags);
parser.RegisterKeyword("value", reader => value = reader.GetInt());
parser.ParseStream(blocReader);

Assert.Equal(2, value);
}

[Fact]
public void ElseAfterElseIsIgnored() {
Dictionary<string, bool> ck3ModFlags = new() {{"wtwsms", false}, {"tfe", true}, {"vanilla", false},};

var blocReader = new BufferedReader(
"""
MOD_DEPENDENT = {
IF wtwsms = {
value = 0
} ELSE = {
value = 2
} ELSE = {
value = 3
}
}
""");

int? value = null;
var parser = new Parser();
parser.RegisterModDependentBloc(ck3ModFlags);
parser.RegisterKeyword("value", reader => value = reader.GetInt());
parser.ParseStream(blocReader);

Assert.Equal(2, value);
}

[Fact]
public void ElseIfWithoutPrecedingIfIsIgnored() {
Dictionary<string, bool> ck3ModFlags = new() {{"wtwsms", false}, {"tfe", true}, {"vanilla", false},};

var blocReader = new BufferedReader(
"""
MOD_DEPENDENT = {
ELSE_IF tfe = { # Should be ignored, as there is no IF before it.
value = 3
}
}
""");

int? value = null;
var parser = new Parser();
parser.RegisterModDependentBloc(ck3ModFlags);
parser.RegisterKeyword("value", reader => value = reader.GetInt());
parser.ParseStream(blocReader);

Assert.Null(value);
}

[Fact]
public void ElseWithoutPrecedingIfIsIgnored() {
Dictionary<string, bool> ck3ModFlags = new() {{"wtwsms", false}, {"tfe", true}, {"vanilla", false},};

var blocReader = new BufferedReader(
"""
MOD_DEPENDENT = {
ELSE = { # Should be ignored, as there is no IF before it.
value = 3
}
}
""");

int? value = null;
var parser = new Parser();
parser.RegisterModDependentBloc(ck3ModFlags);
parser.RegisterKeyword("value", reader => value = reader.GetInt());
parser.ParseStream(blocReader);

Assert.Null(value);
}
}
2 changes: 1 addition & 1 deletion ImperatorToCK3.UnitTests/CK3/Religions/HolySiteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void HolySiteCanBeConstructedForBaronyAndFaithWithEffects() {
titles.LoadTitles(titlesReader);

var holySiteEffectMapper = new HolySiteEffectMapper("TestFiles/configurables/holy_site_effect_mappings.txt");
var imperatorEffects = new Dictionary<string, double> {
var imperatorEffects = new OrderedDictionary<string, double> {
{"discipline", 0.2f}, // will be converted to knight_effectiveness_mult with factor of 10
{"unmapped_effect", 1f}, // will be skipped
};
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3.UnitTests/CK3/Titles/LandedTitlesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static LandedTitlesTests() {

public LandedTitlesTests() {
var colorFactory = new ColorFactory();
var ck3ModFlags = Array.Empty<string>();
var ck3ModFlags = new OrderedDictionary<string, bool>();
PillarCollection pillars = new(colorFactory, ck3ModFlags);
cultures = new CultureCollection(colorFactory, pillars, ck3ModFlags);
}
Expand Down
4 changes: 2 additions & 2 deletions ImperatorToCK3.UnitTests/ImperatorToCK3.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>

<IsPackable>false</IsPackable>

Expand All @@ -16,7 +16,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="FluentAssertions" Version="6.12.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
Expand Down
6 changes: 4 additions & 2 deletions ImperatorToCK3.UnitTests/Mappers/Coa/CoaMapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

namespace ImperatorToCK3.UnitTests.Mappers.Coa;

public class CoaMapperTests {
[Collection("Sequential")]
[CollectionDefinition("Sequential", DisableParallelization = true)]
public sealed class CoaMapperTests {
private const string ImperatorRoot = "TestFiles/MapperTests/CoaMapper/Imperator/game";
private static readonly ModFilesystem imperatorModFs = new(ImperatorRoot, Array.Empty<Mod>());

Expand Down Expand Up @@ -51,7 +53,7 @@ public void GetCoaForFlagNameReturnsCoaOnMatch() {
"\t\tcolor1 =\"bone_white\"\n" +
"\t\tcolor2 =\"offwhite\"\n" +
"\t\tinstance ={\n" +
"\t\t\tscale ={-0.9 0.9 }\"\n" +
"\t\t\tscale ={-0.9 0.9 }\n" +
"\t\t}\n" +
"\t}\n" +
"\tcolored_emblem ={\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class TagTitleMapperTests {
private static readonly ColorFactory ColorFactory = new();

static TagTitleMapperTests() {
var ck3ModFlags = new List<string>();
var ck3ModFlags = new OrderedDictionary<string, bool>();
var pillars = new PillarCollection(ColorFactory, ck3ModFlags);
cultures = new CultureCollection(ColorFactory, pillars, ck3ModFlags);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task CoaIsOutputtedForCountryWithFlagSet() {

var ck3Religions = new ReligionCollection(titles);
var ck3RegionMapper = new CK3RegionMapper();
var ck3ModFlags = new List<string>();
var ck3ModFlags = new OrderedDictionary<string, bool>();
titles.ImportImperatorCountries(countries,
Array.Empty<Dependency>(),
new TagTitleMapper(),
Expand Down Expand Up @@ -102,7 +102,7 @@ public async Task CoaIsNotOutputtedForCountryWithoutFlagSet() {

var ck3Religions = new ReligionCollection(titles);
var ck3RegionMapper = new CK3RegionMapper();
var ck3ModFlags = new List<string>();
var ck3ModFlags = new OrderedDictionary<string, bool>();
titles.ImportImperatorCountries(countries,
Array.Empty<Dependency>(),
new TagTitleMapper(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using ImperatorToCK3.Outputter;
using ImperatorToCK3.UnitTests.TestHelpers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Xunit;
Expand All @@ -36,7 +37,7 @@ public async Task DynastiesAreOutputted() {
irRegionMapper.LoadRegions(irModFS, new ColorFactory());
var colorFactory = new ColorFactory();
irRegionMapper.LoadRegions(irModFS, colorFactory);
var ck3ModFlags = Array.Empty<string>();
var ck3ModFlags = new OrderedDictionary<string, bool>();
CultureMapper cultureMapper = new(irRegionMapper, new CK3RegionMapper(), new CultureCollection(colorFactory, new PillarCollection(colorFactory, ck3ModFlags), ck3ModFlags));

var characters = new CharacterCollection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ e_IRTOCK3_AMK = {
color1 ="bone_white"
color2 ="offwhite"
instance ={
scale ={-0.9 0.9 }"
scale ={-0.9 0.9 }
}
}
colored_emblem ={
Expand Down
Loading

0 comments on commit 128d4b1

Please sign in to comment.