Skip to content
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

Tweaks suggested by Meziantou.Analyzer #1466

Merged
merged 2 commits into from
Aug 7, 2023
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
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Provinces/ProvinceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void LoadPrehistory() {
}

private static Imperator.Provinces.Province? DeterminePrimarySourceProvince(
List<ulong> impProvinceNumbers,
IEnumerable<ulong> impProvinceNumbers,
Imperator.World irWorld
) {
// determine ownership by province development.
Expand Down
7 changes: 4 additions & 3 deletions ImperatorToCK3/CK3/Religions/ReligionCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
namespace ImperatorToCK3.CK3.Religions;

public class ReligionCollection : IdObjectCollection<string, Religion> {
public Dictionary<string, OrderedSet<string>> ReplaceableHolySitesByFaith { get; } = new();
private readonly Dictionary<string, OrderedSet<string>> replaceableHolySitesByFaith = new();
public IReadOnlyDictionary<string, OrderedSet<string>> ReplaceableHolySitesByFaith => replaceableHolySitesByFaith;
public IdObjectCollection<string, HolySite> HolySites { get; } = new();
public IdObjectCollection<string, DoctrineCategory> DoctrineCategories { get; } = new();

Expand Down Expand Up @@ -82,9 +83,9 @@ public void LoadReplaceableHolySites(string filePath) {

var valueStr = value.ToString();
if (value.IsArrayOrObject()) {
ReplaceableHolySitesByFaith[faithId] = new OrderedSet<string>(new BufferedReader(valueStr).GetStrings());
replaceableHolySitesByFaith[faithId] = new OrderedSet<string>(new BufferedReader(valueStr).GetStrings());
} else if (valueStr == "all") {
ReplaceableHolySitesByFaith[faithId] = new OrderedSet<string>(faith.HolySiteIds);
replaceableHolySitesByFaith[faithId] = new OrderedSet<string>(faith.HolySiteIds);
} else {
Logger.Warn($"Unexpected value: {valueStr}");
}
Expand Down
4 changes: 2 additions & 2 deletions ImperatorToCK3/CK3/Titles/Title.cs
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,9 @@ public Dictionary<string, Title> GetDeFactoVassalsAndBelow(Date date, string ran
[SerializedName("always_follows_primary_heir")] public bool? AlwaysFollowsPrimaryHeir { get; set; }
[SerializedName("de_jure_drift_disabled")] public bool? DeJureDriftDisabled { get; set; }
[SerializedName("can_be_named_after_dynasty")] public bool? CanBeNamedAfterDynasty { get; set; }
[SerializedName("male_names")] public List<string>? MaleNames { get; private set; }
[SerializedName("male_names")] public IList<string>? MaleNames { get; private set; }
// <culture, loc key>
[SerializedName("cultural_names")] public Dictionary<string, string>? CulturalNames { get; private set; }
[SerializedName("cultural_names")] public IDictionary<string, string>? CulturalNames { get; private set; }

public int? GetOwnOrInheritedDevelopmentLevel(Date date) {
var ownDev = GetDevelopmentLevel(date);
Expand Down
4 changes: 2 additions & 2 deletions ImperatorToCK3/CK3/Wars/War.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class War {
public Date EndDate { get; }
public OrderedSet<string> TargetedTitles { get; } = new();
public string? CasusBelli { get; }
public List<string> Attackers { get; } = new();
public List<string> Defenders { get; } = new();
public IList<string> Attackers { get; } = new List<string>();
public IList<string> Defenders { get; } = new List<string>();
public string Claimant { get; }

public War(Imperator.Diplomacy.War irWar, Mappers.War.WarMapper warMapper, ProvinceMapper provinceMapper, Imperator.Countries.CountryCollection impCountries, StateCollection irStates, ProvinceCollection ck3Provinces, Title.LandedTitles titles, Date ck3BookmarkDate) {
Expand Down
4 changes: 2 additions & 2 deletions ImperatorToCK3/Imperator/Diplomacy/War.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace ImperatorToCK3.Imperator.Diplomacy;
public class War {
public Date StartDate { get; private set; } = new(1, 1, 1);
public bool Previous { get; private set; }
public List<ulong> AttackerCountryIds { get; } = new();
public List<ulong> DefenderCountryIds { get; } = new();
public IList<ulong> AttackerCountryIds { get; } = new List<ulong>();
public IList<ulong> DefenderCountryIds { get; } = new List<ulong>();
public string? WarGoal { get; private set; }
public ulong? TargetedStateId { get; private set; }

Expand Down
6 changes: 3 additions & 3 deletions ImperatorToCK3/Imperator/Provinces/Province.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class Province : IIdentifiable<ulong> {
public State? State { get; private set; } = null;
public Country? OwnerCountry { get; set; }
public ulong Controller { get; set; } = 0;
public Dictionary<ulong, Pop> Pops { get; set; } = new();
public IDictionary<ulong, Pop> Pops { get; } = new Dictionary<ulong, Pop>();
public ProvinceRank ProvinceRank { get; set; } = ProvinceRank.settlement;
public bool Fort { get; set; } = false;
public bool IsHolySite => HolySiteId is not null;
Expand All @@ -43,10 +43,10 @@ public int GetPopCount() {
}

// Returns a count of linked pops
public int LinkPops(PopCollection pops) {
public int LinkPops(PopCollection popCollection) {
int counter = 0;
foreach (var popId in parsedPopIds) {
if (pops.TryGetValue(popId, out var popToLink)) {
if (popCollection.TryGetValue(popId, out var popToLink)) {
Pops.Add(popId, popToLink);
++counter;
} else {
Expand Down
8 changes: 4 additions & 4 deletions ImperatorToCK3/Mappers/Province/ProvinceMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace ImperatorToCK3.Mappers.Province;

public class ProvinceMapper {
private readonly Dictionary<ulong, List<ulong>> imperatorToCK3ProvinceMap = new();
private readonly Dictionary<ulong, List<ulong>> ck3ToImperatorProvinceMap = new();
private readonly Dictionary<ulong, IList<ulong>> imperatorToCK3ProvinceMap = new();
private readonly Dictionary<ulong, IList<ulong>> ck3ToImperatorProvinceMap = new();

public void LoadMappings(string mappingsPath, string mappingsVersionName) {
Logger.Info("Loading province mappings...");
Expand Down Expand Up @@ -49,14 +49,14 @@ private void CreateMappings(ProvinceMappingsVersion mappingsVersion) {
}
}

public List<ulong> GetImperatorProvinceNumbers(ulong ck3ProvinceNumber) {
public IList<ulong> GetImperatorProvinceNumbers(ulong ck3ProvinceNumber) {
if (ck3ToImperatorProvinceMap.TryGetValue(ck3ProvinceNumber, out var impProvs)) {
return impProvs;
}
return new List<ulong>();
}

public List<ulong> GetCK3ProvinceNumbers(ulong impProvinceNumber) {
public IList<ulong> GetCK3ProvinceNumbers(ulong impProvinceNumber) {
if (imperatorToCK3ProvinceMap.TryGetValue(impProvinceNumber, out var ck3Provs)) {
return ck3Provs;
}
Expand Down
4 changes: 2 additions & 2 deletions ImperatorToCK3/Mappers/Province/ProvinceMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
namespace ImperatorToCK3.Mappers.Province;

public class ProvinceMapping {
public List<ulong> CK3Provinces { get; } = new();
public List<ulong> ImperatorProvinces { get; } = new();
public IList<ulong> CK3Provinces { get; } = new List<ulong>();
public IList<ulong> ImperatorProvinces { get; } = new List<ulong>();

private static readonly Parser parser = new();
private static ProvinceMapping tempMapping = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace ImperatorToCK3.Mappers.Province;

public class ProvinceMappingsVersion {
public List<ProvinceMapping> Mappings { get; } = new();
public IList<ProvinceMapping> Mappings { get; } = new List<ProvinceMapping>();
public ProvinceMappingsVersion() { }
public ProvinceMappingsVersion(BufferedReader reader) {
var referencedImperatorProvs = new HashSet<ulong>();
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/Mappers/Trait/TraitMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace ImperatorToCK3.Mappers.Trait;

public class TraitMapper {
protected Dictionary<string, string> ImperatorToCK3TraitMap = new();
protected IDictionary<string, string> ImperatorToCK3TraitMap = new Dictionary<string, string>();
protected IdObjectCollection<string, CK3.Characters.Trait> CK3Traits = new();

public TraitMapper() { }
Expand Down
4 changes: 2 additions & 2 deletions ImperatorToCK3/Outputter/WarsOutputter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace ImperatorToCK3.Outputter;

public static class WarsOutputter {
public static void OutputWars(string outputModName, List<War> wars) {
public static void OutputWars(string outputModName, IList<War> wars) {
Logger.Info("Writing wars...");
// dumping all into one file
var path = Path.Combine("output",outputModName, "history/wars/fromImperator.txt");
Expand All @@ -23,7 +23,7 @@ private static void OutputWar(TextWriter output, War war) {

output.WriteLine($"\tstart_date = {war.StartDate}");
output.WriteLine($"\tend_date = {war.EndDate}");
output.WriteLine($"\ttargeted_titles={{ {string.Join(" ", war.TargetedTitles)} }}");
output.WriteLine($"\ttargeted_titles={{ {string.Join(' ', war.TargetedTitles)} }}");
if (war.CasusBelli is not null) {
output.WriteLine($"\tcasus_belli = {war.CasusBelli}");
}
Expand Down
Loading