Skip to content

Commit

Permalink
Make more classes internal, reduce interface use
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains committed Dec 16, 2024
1 parent 3e20ab2 commit 39754c8
Show file tree
Hide file tree
Showing 69 changed files with 82 additions and 84 deletions.
18 changes: 9 additions & 9 deletions ImperatorToCK3.UnitTests/CK3/Characters/CK3CharacterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion 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
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/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
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
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
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Titles/Title.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
namespace ImperatorToCK3.CK3.Titles;

[SerializationByProperties]
public sealed partial class Title : IPDXSerializable, IIdentifiable<string> {
internal sealed partial class Title : IPDXSerializable, IIdentifiable<string> {
public override string ToString() {
return Id;
}
Expand Down
4 changes: 2 additions & 2 deletions ImperatorToCK3/CK3/Titles/TitleCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace ImperatorToCK3.CK3.Titles;

public interface IReadOnlyTitleCollection : IReadOnlyCollection<Title> {
internal interface IReadOnlyTitleCollection : IReadOnlyCollection<Title> {
public bool ContainsKey(string key);
}

public class TitleCollection : IdObjectCollection<string, Title>, IReadOnlyTitleCollection;
internal class TitleCollection : IdObjectCollection<string, Title>, IReadOnlyTitleCollection;
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Titles/TitleHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ImperatorToCK3.CK3.Titles;

public partial class Title {
internal partial class Title {
public string GetHolderId(Date date) {
var idFromHistory = History.GetFieldValue("holder", date);
if (idFromHistory is not null) {
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Wars/War.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace ImperatorToCK3.CK3.Wars;

public sealed class War {
internal sealed class War {
public Date StartDate { get; } = "2.1.1";
public Date EndDate { get; }
public OrderedSet<string> TargetedTitles { get; } = [];
Expand Down
3 changes: 1 addition & 2 deletions ImperatorToCK3/CK3/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
using ImperatorToCK3.Mappers.UnitType;
using ImperatorToCK3.Outputter;
using log4net.Core;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
Expand All @@ -41,7 +40,7 @@

namespace ImperatorToCK3.CK3;

public sealed class World {
internal sealed class World {
public OrderedSet<Mod> LoadedMods { get; }
public ModFilesystem ModFS { get; }
public CK3LocDB LocDB { get; } = [];
Expand Down
3 changes: 1 addition & 2 deletions ImperatorToCK3/Imperator/Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
using Open.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;

namespace ImperatorToCK3.Imperator.Characters;

public sealed class Character : IIdentifiable<ulong> {
internal sealed class Character : IIdentifiable<ulong> {
public Character(ulong id) {
Id = id;
}
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/Imperator/Characters/CharacterCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace ImperatorToCK3.Imperator.Characters;

public sealed class CharacterCollection : ConcurrentIdObjectCollection<ulong, Character> {
internal sealed class CharacterCollection : ConcurrentIdObjectCollection<ulong, Character> {
public void LoadCharactersFromBloc(BufferedReader reader) {
var blocParser = new Parser();
blocParser.RegisterKeyword("character_database", LoadCharacters);
Expand Down
8 changes: 4 additions & 4 deletions ImperatorToCK3/Imperator/Countries/Country.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

namespace ImperatorToCK3.Imperator.Countries;

public sealed partial class Country : IIdentifiable<ulong> {
internal sealed partial class Country : IIdentifiable<ulong> {
public ulong Id { get; } = 0;
public bool PlayerCountry { get; set; }
private ulong? monarchId; // >=0 are valid
public Character? Monarch { get; private set; }
public string? PrimaryCulture { get; private set; }
public string? Religion { get; private set; }
public IList<RulerTerm> RulerTerms { get; set; } = [];
public IDictionary<string, int> HistoricalRegnalNumbers { get; private set; } = new Dictionary<string, int>();
public List<RulerTerm> RulerTerms { get; set; } = [];
public Dictionary<string, int> HistoricalRegnalNumbers { get; private set; } = [];
public string Tag { get; private set; } = "";
private string? historicalTag;
public string HistoricalTag {
Expand All @@ -43,7 +43,7 @@ public string HistoricalTag {
public Color? Color3 { get; private set; }
public CountryCurrencies Currencies { get; private set; } = new();
private readonly HashSet<ulong> parsedFamilyIds = [];
public IDictionary<ulong, Family> Families { get; private set; } = new Dictionary<ulong, Family>();
public Dictionary<ulong, Family> Families { get; private set; } = [];
public IReadOnlySet<string> Variables { get; private set; } = ImmutableHashSet<string>.Empty;
private readonly HashSet<Province> ownedProvinces = [];
private readonly List<bool> inventionBooleans = [];
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/Imperator/Countries/CountryCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace ImperatorToCK3.Imperator.Countries;

public sealed class CountryCollection : ConcurrentIdObjectCollection<ulong, Country> {
internal sealed class CountryCollection : ConcurrentIdObjectCollection<ulong, Country> {
public void LoadCountriesFromBloc(BufferedReader reader) {
var blocParser = new Parser();
blocParser.RegisterKeyword("country_database", LoadCountries);
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/Imperator/Countries/CountryFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace ImperatorToCK3.Imperator.Countries;

public sealed partial class Country {
internal sealed partial class Country {
private const string monarchyLawRegexStr = "succession_law|monarchy_military_reforms|monarchy_maritime_laws|monarchy_economic_law|monarchy_citizen_law" +
"|monarchy_religious_laws|monarchy_legitimacy_laws|monarchy_contract_law|monarchy_divinity_statutes|jewish_monarchy_divinity_statutes|monarchy_subject_laws";
private const string republicLawRegexStr = "republic_military_recruitment_laws_rom|republic_election_reforms_rom|corruption_laws_rom|republican_mediterranean_laws_rom|republican_religious_laws_rom|republic_integration_laws_rom|republic_citizen_laws_rom|republican_land_reforms_rom" +
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/Imperator/Countries/CountryName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace ImperatorToCK3.Imperator.Countries;

public sealed class CountryName : ICloneable {
internal sealed class CountryName : ICloneable {
public string Name { get; private set; } = "";
private string? adjective;
public CountryName? BaseName { get; private set; }
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/Imperator/Countries/RulerTerm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace ImperatorToCK3.Imperator.Countries;

public sealed class RulerTerm {
internal sealed class RulerTerm {
public sealed class PreImperatorRulerInfo {
public string? Name { get; set; }
public Date? BirthDate { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/Imperator/Families/Family.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace ImperatorToCK3.Imperator.Families;

public sealed class Family : IIdentifiable<ulong> {
internal sealed class Family : IIdentifiable<ulong> {
public ulong Id { get; } = 0;
public string Key { get; private set; } = "";
public string Culture { get; private set; } = "";
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/Imperator/Families/FamilyCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace ImperatorToCK3.Imperator.Families;

public sealed class FamilyCollection : IdObjectCollection<ulong, Family> {
internal sealed class FamilyCollection : IdObjectCollection<ulong, Family> {
public void LoadFamiliesFromBloc(BufferedReader reader) {
var blocParser = new Parser();
blocParser.RegisterKeyword("families", LoadFamilies);
Expand Down
Loading

0 comments on commit 39754c8

Please sign in to comment.