Skip to content

Commit

Permalink
Make Unit and UnitTypeMapper internal, reduce interface use
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains committed Dec 15, 2024
1 parent 69dfd99 commit ebe8f0e
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions ImperatorToCK3/CK3/Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ public bool LinkJailor(Date date) {
return true;
}

public void ImportUnitsAsMenAtArms(
internal void ImportUnitsAsMenAtArms(
IEnumerable<Unit> countryUnits,
Date date,
UnitTypeMapper unitTypeMapper,
Expand Down Expand Up @@ -761,7 +761,7 @@ CK3LocDB ck3LocDB

History.AddFieldValue(date, "effects", "effect", new StringOfItem(sb.ToString()));
}
public void ImportUnitsAsSpecialTroops(
internal void ImportUnitsAsSpecialTroops(
IEnumerable<Unit> countryUnits,
Imperator.Characters.CharacterCollection imperatorCharacters,
Date date,
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 @@ -622,7 +622,7 @@ static void AddGoldToCharacter(Character character, double gold) {
Logger.IncrementProgress();
}

public void ImportLegions(
internal void ImportLegions(
Title.LandedTitles titles,
UnitCollection imperatorUnits,
Imperator.Characters.CharacterCollection imperatorCharacters,
Expand Down
4 changes: 2 additions & 2 deletions ImperatorToCK3/Imperator/Armies/Unit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace ImperatorToCK3.Imperator.Armies;

public sealed class Unit : IIdentifiable<ulong> {
internal sealed class Unit : IIdentifiable<ulong> {
public ulong Id { get; }
public bool IsArmy { get; private set; } = true;
public bool IsLegion { get; private set; } = false;
Expand All @@ -17,7 +17,7 @@ public sealed class Unit : IIdentifiable<ulong> {
private List<ulong> CohortIds { get; } = new();

public LocBlock? LocalizedName { get; private set; }
public IDictionary<string, int> MenPerUnitType { get; }
public Dictionary<string, int> MenPerUnitType { get; }

public Unit(ulong id, BufferedReader legionReader, UnitCollection unitCollection, LocDB irLocDB, ImperatorDefines defines) {
Id = id;
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/Imperator/Armies/UnitCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace ImperatorToCK3.Imperator.Armies;

public sealed class UnitCollection : IdObjectCollection<ulong, Unit> {
internal sealed class UnitCollection : IdObjectCollection<ulong, Unit> {
public IdObjectCollection<ulong, Subunit> Subunits { get; } = new();

public void LoadSubunits(BufferedReader subunitsReader) {
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/Imperator/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public partial class World {
public IReadOnlyCollection<War> Wars { get; private set; } = Array.Empty<War>();
public IReadOnlyCollection<Dependency> Dependencies { get; private set; } = Array.Empty<Dependency>();
public Jobs.JobsDB JobsDB { get; private set; } = new();
public UnitCollection Units { get; } = [];
internal UnitCollection Units { get; } = [];
public CulturesDB CulturesDB { get; } = [];
public ReligionCollection Religions { get; private set; }
private GenesDB genesDB = new();
Expand Down
8 changes: 3 additions & 5 deletions ImperatorToCK3/Mappers/UnitType/UnitTypeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace ImperatorToCK3.Mappers.UnitType;

public sealed class UnitTypeMapper {
internal sealed class UnitTypeMapper {
private readonly Dictionary<string, string?> unitTypeMap = []; // imperator -> ck3

public UnitTypeMapper(string mappingsFilePath) {
Expand All @@ -30,7 +30,7 @@ public UnitTypeMapper(string mappingsFilePath) {
return unitTypeMap.GetValueOrDefault(imperatorUnitType, defaultValue: null);
}

public IDictionary<string, int> GetMenPerCK3UnitType(IDictionary<string, int> menPerImperatorUnitType) {
public Dictionary<string, int> GetMenPerCK3UnitType(IDictionary<string, int> menPerImperatorUnitType) {
var toReturn = new Dictionary<string, int>();

foreach (var (imperatorType, imperatorMen) in menPerImperatorUnitType) {
Expand All @@ -39,10 +39,8 @@ public IDictionary<string, int> GetMenPerCK3UnitType(IDictionary<string, int> me
continue;
}

if (toReturn.ContainsKey(ck3Type)) {
if (!toReturn.TryAdd(ck3Type, imperatorMen)) {
toReturn[ck3Type] += imperatorMen;
} else {
toReturn[ck3Type] = imperatorMen;
}
}

Expand Down

0 comments on commit ebe8f0e

Please sign in to comment.