Skip to content

Commit

Permalink
Make more classes internal, reduce interface use (#2365)
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains authored Dec 16, 2024
1 parent 3e20ab2 commit f10e4c9
Show file tree
Hide file tree
Showing 89 changed files with 150 additions and 153 deletions.
20 changes: 10 additions & 10 deletions ImperatorToCK3.UnitTests/CK3/Characters/CK3CharacterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static CK3CharacterTests() {
CultureMapper = new CultureMapper(IRRegionMapper, new CK3RegionMapper(), cultures);
}

public class CK3CharacterBuilder {
internal class CK3CharacterBuilder {
private Configuration config = new() {
CK3BookmarkDate = ConversionDate,
CK3Path = CK3Path
Expand All @@ -76,7 +76,7 @@ public class CK3CharacterBuilder {
private ProvinceMapper provinceMapper = new();
private DeathReasonMapper deathReasonMapper = new();

public Character Build() {
internal Character Build() {
IRRegionMapper.LoadRegions(IRModFS, new ColorFactory());

var character = new Character(
Expand All @@ -98,19 +98,19 @@ public Character Build() {
);
return character;
}
public CK3CharacterBuilder WithImperatorCharacter(ImperatorToCK3.Imperator.Characters.Character imperatorCharacter) {
internal CK3CharacterBuilder WithImperatorCharacter(ImperatorToCK3.Imperator.Characters.Character imperatorCharacter) {
this.imperatorCharacter = imperatorCharacter;
return this;
}
public CK3CharacterBuilder WithCharacterCollection(CharacterCollection characters) {
internal CK3CharacterBuilder WithCharacterCollection(CharacterCollection characters) {
this.characters = characters;
return this;
}
public CK3CharacterBuilder WithReligionMapper(ReligionMapper religionMapper) {
internal CK3CharacterBuilder WithReligionMapper(ReligionMapper religionMapper) {
this.religionMapper = religionMapper;
return this;
}
public CK3CharacterBuilder WithCultureMapper(CultureMapper cultureMapper) {
internal CK3CharacterBuilder WithCultureMapper(CultureMapper cultureMapper) {
this.cultureMapper = cultureMapper;
return this;
}
Expand Down Expand Up @@ -512,17 +512,17 @@ public void DeadLandlessCharactersArePurgedIfChildless() {
landedCharacter.Father = fatherOfLandedCharacter;
childlessRelative.Father = fatherOfLandedCharacter;

var dynasty = new ImperatorToCK3.CK3.Dynasties.Dynasty(irFamily, irCharacters, new CulturesDB(), CultureMapper, new LocDB("english"), new TestCK3LocDB(), ConversionDate);
var dynasty = new 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));
Assert.Equal(dynasty.Id, childlessRelative.GetDynastyId(ConversionDate));

ck3Characters.PurgeUnneededCharacters(titles, dynasties, new HouseCollection(), ConversionDate);

ck3Characters.Should().BeEquivalentTo(new[] {
ck3Characters.Should().BeEquivalentTo([
fatherOfLandedCharacter,
landedCharacter,
fatherOfLandedCharacter
});
]);
}
}
4 changes: 2 additions & 2 deletions ImperatorToCK3.UnitTests/ImperatorToCK3.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="FluentAssertions" Version="8.0.0-alpha.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.49">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace ImperatorToCK3.UnitTests.TestHelpers;

public class TestCK3CultureCollection() : CultureCollection(colorFactory, new PillarCollection(colorFactory, ck3ModFlags), ck3ModFlags) {
internal class TestCK3CultureCollection() : CultureCollection(colorFactory, new PillarCollection(colorFactory, ck3ModFlags), ck3ModFlags) {
private static readonly ColorFactory colorFactory = new();
private static readonly OrderedDictionary<string, bool> ck3ModFlags = [];

Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3.UnitTests/TestHelpers/TestImperatorWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace ImperatorToCK3.UnitTests.TestHelpers;

public class TestImperatorWorld(Configuration config) : World(config);
internal class TestImperatorWorld(Configuration config) : World(config);
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Armies/MenAtArmsType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace ImperatorToCK3.CK3.Armies;

[SerializationByProperties]
public sealed partial class MenAtArmsType : IIdentifiable<string>, IPDXSerializable {
internal sealed partial class MenAtArmsType : IIdentifiable<string>, IPDXSerializable {
[NonSerialized] public string Id { get; }

[SerializedName("can_recruit")] public StringOfItem CanRecruit { get; private set; } = new("{}");
Expand Down
8 changes: 4 additions & 4 deletions ImperatorToCK3/CK3/Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace ImperatorToCK3.CK3.Characters;

public sealed class Character : IIdentifiable<string> {
internal sealed class Character : IIdentifiable<string> {
public string Id { get; }
public bool FromImperator { get; init; } = false;

Expand Down Expand Up @@ -150,11 +150,11 @@ public string? DeathReason {
}
}

public IList<Pregnancy> Pregnancies { get; } = new List<Pregnancy>();
public List<Pregnancy> Pregnancies { get; } = [];

public IDictionary<string, int> MenAtArmsStacksPerType { get; } = new Dictionary<string, int>();
public Dictionary<string, int> MenAtArmsStacksPerType { get; } = [];

public IDictionary<string, string> PrisonerIds { get; } = new Dictionary<string, string>(); // <prisoner id, imprisonment type>
public Dictionary<string, string> PrisonerIds { get; } = []; // <prisoner id, imprisonment type>

internal DNA? DNA { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Characters/CharacterCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace ImperatorToCK3.CK3.Characters;

public sealed partial class CharacterCollection : ConcurrentIdObjectCollection<string, Character> {
internal sealed partial class CharacterCollection : ConcurrentIdObjectCollection<string, Character> {
internal void ImportImperatorCharacters(
Imperator.World impWorld,
ReligionMapper religionMapper,
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Characters/CharactersLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace ImperatorToCK3.CK3.Characters;

public sealed partial class CharacterCollection {
internal sealed partial class CharacterCollection {
public void LoadCK3Characters(ModFilesystem ck3ModFS, Date bookmarkDate) {
Logger.Info("Loading characters from CK3...");

Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Cultures/Culture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace ImperatorToCK3.CK3.Cultures;

public sealed class Culture : IIdentifiable<string>, IPDXSerializable {
internal sealed class Culture : IIdentifiable<string>, IPDXSerializable {
public string Id { get; }
public Color Color { get; }
public OrderedSet<string> ParentCultureIds { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Cultures/CultureCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace ImperatorToCK3.CK3.Cultures;

public class CultureCollection : IdObjectCollection<string, Culture> {
internal class CultureCollection : IdObjectCollection<string, Culture> {
public CultureCollection(ColorFactory colorFactory, PillarCollection pillarCollection, OrderedDictionary<string, bool> ck3ModFlags) {
this.PillarCollection = pillarCollection;
InitCultureDataParser(colorFactory, ck3ModFlags);
Expand Down
6 changes: 3 additions & 3 deletions ImperatorToCK3/CK3/Cultures/CultureData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

namespace ImperatorToCK3.CK3.Cultures;

public record CultureData {
public IEnumerable<string> InvalidatingCultureIds { get; set; } = new List<string>();
internal record CultureData {
public List<string> InvalidatingCultureIds { get; set; } = [];
public Color? Color { get; set; }
public OrderedSet<string> ParentCultureIds { get; set; } = new();
public Pillar? Heritage { get; set; }
public Pillar? Language { get; set; }
public OrderedSet<string> TraditionIds { get; set; } = new();
public OrderedSet<NameList> NameLists { get; } = new();

public IList<KeyValuePair<string, StringOfItem>> Attributes { get; } = new List<KeyValuePair<string, StringOfItem>>();
public List<KeyValuePair<string, StringOfItem>> Attributes { get; } = [];
}
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Cultures/Pillar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace ImperatorToCK3.CK3.Cultures;

public sealed class Pillar : IIdentifiable<string>, IPDXSerializable {
internal sealed class Pillar : IIdentifiable<string>, IPDXSerializable {
public string Id { get; }
public string Type { get; }
public Color? Color { get; }
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Cultures/PillarCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace ImperatorToCK3.CK3.Cultures;

public sealed class PillarCollection : IdObjectCollection<string, Pillar> {
internal sealed class PillarCollection : IdObjectCollection<string, Pillar> {
private readonly Dictionary<string, string> mergedPillarsDict = [];

public PillarCollection(ColorFactory colorFactory, OrderedDictionary<string, bool> ck3ModFlags) {
Expand Down
8 changes: 4 additions & 4 deletions ImperatorToCK3/CK3/Cultures/PillarData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace ImperatorToCK3.CK3.Cultures;

public record PillarData {
public IEnumerable<string> InvalidatingPillarIds { get; set; } = new List<string>();
internal record PillarData {
public List<string> InvalidatingPillarIds { get; set; } = [];
public string? Type { get; set; }
public Color? Color { get; set; }
public IList<KeyValuePair<string, StringOfItem>> Attributes { get; } = new List<KeyValuePair<string, StringOfItem>>();

public List<KeyValuePair<string, StringOfItem>> Attributes { get; } = [];
}
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Dynasties/Dynasty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace ImperatorToCK3.CK3.Dynasties;

[SerializationByProperties]
public sealed partial class Dynasty : IPDXSerializable, IIdentifiable<string> {
internal sealed partial class Dynasty : IPDXSerializable, IIdentifiable<string> {
public Dynasty(Family irFamily, CharacterCollection irCharacters, CulturesDB irCulturesDB, CultureMapper cultureMapper, LocDB irLocDB, CK3LocDB ck3LocDB, Date date) {
FromImperator = true;
Id = $"dynn_irtock3_{irFamily.Id}";
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Dynasties/DynastyCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace ImperatorToCK3.CK3.Dynasties;

public sealed class DynastyCollection : ConcurrentIdObjectCollection<string, Dynasty> {
internal sealed class DynastyCollection : ConcurrentIdObjectCollection<string, Dynasty> {
public void ImportImperatorFamilies(Imperator.World irWorld, CultureMapper cultureMapper, LocDB irLocDB, CK3LocDB ck3LocDB, Date date) {
Logger.Info("Importing Imperator families...");

Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Dynasties/HouseCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace ImperatorToCK3.CK3.Dynasties;

public sealed class HouseCollection : ConcurrentIdObjectCollection<string, House> {
internal sealed class HouseCollection : ConcurrentIdObjectCollection<string, House> {
public void LoadCK3Houses(ModFilesystem ck3ModFS) {
Logger.Info("Loading dynasty houses from CK3...");

Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Provinces/Province.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace ImperatorToCK3.CK3.Provinces;

public sealed partial class Province : IIdentifiable<ulong> {
internal sealed partial class Province : IIdentifiable<ulong> {
public ulong Id { get; } = 0;
public ulong? BaseProvinceId { get; private set; }

Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Provinces/ProvinceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace ImperatorToCK3.CK3.Provinces;

public sealed class ProvinceCollection : IdObjectCollection<ulong, Province> {
internal sealed class ProvinceCollection : IdObjectCollection<ulong, Province> {
public ProvinceCollection() { }
public ProvinceCollection(ModFilesystem ck3ModFs) {
LoadProvincesHistory(ck3ModFs);
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 @@ -8,7 +8,7 @@

namespace ImperatorToCK3.CK3.Provinces;

public sealed partial class Province {
internal sealed partial class Province {
public string? GetFaithId(Date date) {
var historyValue = History.GetFieldValue("faith", date);
return historyValue switch {
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Religions/Faith.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace ImperatorToCK3.CK3.Religions;

public sealed class Faith : IIdentifiable<string>, IPDXSerializable {
internal sealed class Faith : IIdentifiable<string>, IPDXSerializable {
public string Id { get; }
public Religion Religion { get; set; }
public Color? Color { get; }
Expand Down
10 changes: 5 additions & 5 deletions ImperatorToCK3/CK3/Religions/FaithData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace ImperatorToCK3.CK3.Religions;

public record FaithData {
public IEnumerable<string> InvalidatingFaithIds { get; set; } = new List<string>();
internal record FaithData {
public List<string> InvalidatingFaithIds { get; set; } = [];
public Color? Color { get; set; }
public string? ReligiousHeadTitleId { get; set; }
public IList<string> DoctrineIds { get; } = new List<string>();
public IList<string> HolySiteIds { get; init; } = new List<string>();
public List<string> DoctrineIds { get; } = [];
public List<string> HolySiteIds { get; init; } = [];

public IList<KeyValuePair<string, StringOfItem>> Attributes { get; init; } = new List<KeyValuePair<string, StringOfItem>>();
public List<KeyValuePair<string, StringOfItem>> Attributes { get; init; } = [];
}
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Religions/HolySite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace ImperatorToCK3.CK3.Religions;

[SerializationByProperties]
public sealed partial class HolySite : IIdentifiable<string>, IPDXSerializable {
internal sealed partial class HolySite : IIdentifiable<string>, IPDXSerializable {
[NonSerialized] public string Id { get; }
[NonSerialized] public bool IsFromConverter { get; }
[NonSerialized] public Title? County { get; }
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Religions/Religion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace ImperatorToCK3.CK3.Religions;

public sealed class Religion : IIdentifiable<string>, IPDXSerializable {
internal sealed class Religion : IIdentifiable<string>, IPDXSerializable {
public string Id { get; }
public OrderedSet<string> DoctrineIds { get; } = new();

Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Religions/ReligionCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace ImperatorToCK3.CK3.Religions;

public sealed class ReligionCollection(Title.LandedTitles landedTitles) : IdObjectCollection<string, Religion> {
internal sealed class ReligionCollection(Title.LandedTitles landedTitles) : IdObjectCollection<string, Religion> {
private readonly Dictionary<string, OrderedSet<string>> replaceableHolySitesByFaith = [];
public IReadOnlyDictionary<string, OrderedSet<string>> ReplaceableHolySitesByFaith => replaceableHolySitesByFaith;
public IdObjectCollection<string, HolySite> HolySites { get; } = [];
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Titles/LandedTitles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

namespace ImperatorToCK3.CK3.Titles;

public sealed partial class Title {
internal sealed partial class Title {
private readonly LandedTitles parentCollection;

// This is a recursive class that scrapes common/landed_titles looking for title colors, landlessness,
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Titles/RulerTerm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace ImperatorToCK3.CK3.Titles;

public sealed class RulerTerm {
internal sealed class RulerTerm {
public string? CharacterId { get; }
public Date StartDate { get; }
public string? Government { get; }
Expand Down
Loading

0 comments on commit f10e4c9

Please sign in to comment.