Skip to content

Commit

Permalink
Use Meziantou.Analyzer to enforce good practices (#1462)
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains authored Aug 6, 2023
1 parent e72e326 commit fd1aa7e
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ public void ImperatorCountriesGoldCanBeDistributedAmongRulerAndVassals() {
);
var governorship1 = new Governorship(governorshipReader1, imperatorWorld.Countries, imperatorWorld.ImperatorRegionMapper);
var governorship2 = new Governorship(governorshipReader2, imperatorWorld.Countries, imperatorWorld.ImperatorRegionMapper);
imperatorWorld.Jobs.Governorships.Add(governorship1);
imperatorWorld.Jobs.Governorships.Add(governorship2);
imperatorWorld.JobsDB.Governorships.Add(governorship1);
imperatorWorld.JobsDB.Governorships.Add(governorship2);

var titles = new Title.LandedTitles();
titles.LoadTitles(new BufferedReader(@"
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 @@ -251,7 +251,7 @@ public void GovernorshipsCanBeRecognizedAsCountyLevel() {
"governorship = \"galatia_region\""
);
var governorship1 = new Governorship(reader, imperatorWorld.Countries, impRegionMapper);
imperatorWorld.Jobs.Governorships.Add(governorship1);
imperatorWorld.JobsDB.Governorships.Add(governorship1);
var titles = new Title.LandedTitles();
titles.LoadTitles(new BufferedReader(
"c_county1 = { b_barony1={province=1} } " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void WarWithNoDefendersIsSkipped() {
3 = { previous=no defender=1 }
}
""");
var diplomacy = new ImperatorToCK3.Imperator.Diplomacy.Diplomacy(reader);
var diplomacy = new ImperatorToCK3.Imperator.Diplomacy.DiplomacyDB(reader);

Assert.Empty(diplomacy.Wars);
var logStr = output.ToString();
Expand Down
6 changes: 3 additions & 3 deletions ImperatorToCK3.UnitTests/Imperator/Jobs/JobsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public JobsTests() {
}
[Fact]
public void GovernorshipsDefaultToEmpty() {
var jobs = new ImperatorToCK3.Imperator.Jobs.Jobs();
var jobs = new ImperatorToCK3.Imperator.Jobs.JobsDB();
Assert.Empty(jobs.Governorships);
}
[Fact]
public void GovernorshipsCanBeRead() {
var reader = new BufferedReader(
"province_job={who=1 governorship=galatia_region} province_job={who=2 governorship=galatia_region}"
);
var jobs = new ImperatorToCK3.Imperator.Jobs.Jobs(reader, countryCollection, irRegionMapper);
var jobs = new ImperatorToCK3.Imperator.Jobs.JobsDB(reader, countryCollection, irRegionMapper);
Assert.Collection(jobs.Governorships,
item1 => Assert.Equal((ulong)1, item1.Country.Id),
item2 => Assert.Equal((ulong)2, item2.Country.Id)
Expand All @@ -50,7 +50,7 @@ public void IgnoredTokensAreLogged() {
var reader = new BufferedReader(
"useless_job = {}"
);
_ = new ImperatorToCK3.Imperator.Jobs.Jobs(reader, countryCollection, irRegionMapper);
_ = new ImperatorToCK3.Imperator.Jobs.JobsDB(reader, countryCollection, irRegionMapper);

Assert.Contains("Ignored Jobs tokens: useless_job", output.ToString());
}
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3.UnitTests/Mappers/TagTitle/MappingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void GovernorshipToDeJureDuchyMappingFailsIfDuchyIsNot60PercentControlled
var irGovernorship = new Governorship(governorshipReader, irCountries, irRegionMapper);
Assert.Equal(irRegionId, irGovernorship.Region.Id);
Assert.Equal(irCountryId, irGovernorship.Country.Id);
var jobs = new Jobs();
var jobs = new JobsDB();
jobs.Governorships.Add(irGovernorship);

const string duchyId = "d_galatia";
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 @@ -353,7 +353,7 @@ List<Governorship> countryLevelGovernorships
) {
Logger.Info("Importing Imperator Governorships...");

var governorships = irWorld.Jobs.Governorships;
var governorships = irWorld.JobsDB.Governorships;
var governorshipsPerRegion = governorships.GroupBy(g => g.Region.Id)
.ToDictionary(g => g.Key, g => g.Count());

Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public World(Imperator.World impWorld, Configuration config) {
);

// Give counties to rulers and governors.
OverwriteCountiesHistory(impWorld.Jobs.Governorships, countyLevelGovernorships, impWorld.Characters, impWorld.Provinces, CorrectedDate);
OverwriteCountiesHistory(impWorld.JobsDB.Governorships, countyLevelGovernorships, impWorld.Characters, impWorld.Provinces, CorrectedDate);
// Import holding owners as barons and counts.
LandedTitles.ImportImperatorHoldings(Provinces, impWorld.Characters, CorrectedDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

namespace ImperatorToCK3.Imperator.Diplomacy;

public class Diplomacy {
public List<War> Wars { get; } = new();
public Diplomacy(BufferedReader reader) {
public class DiplomacyDB {
public IList<War> Wars { get; } = new List<War>();
public DiplomacyDB(BufferedReader reader) {
var parser = new Parser();
parser.RegisterKeyword("database", databaseReader => {
var databaseParser = new Parser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

namespace ImperatorToCK3.Imperator.Jobs;

public class Jobs {
public List<Governorship> Governorships { get; } = new();
public class JobsDB {
public IList<Governorship> Governorships { get; } = new List<Governorship>();

public Jobs() { }
public Jobs(BufferedReader jobsReader, CountryCollection countries, ImperatorRegionMapper irRegionMapper) {
public JobsDB() { }
public JobsDB(BufferedReader jobsReader, CountryCollection countries, ImperatorRegionMapper irRegionMapper) {
var ignoredTokens = new IgnoredKeywordsSet();
var parser = new Parser();
parser.RegisterKeyword("province_job", reader => {
Expand Down
10 changes: 5 additions & 5 deletions ImperatorToCK3/Imperator/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public class World : Parser {
public AreaCollection Areas { get; } = new();
public ImperatorRegionMapper ImperatorRegionMapper { get; }
public StateCollection States { get; } = new();
public List<War> Wars { get; private set; } = new();
public Jobs.Jobs Jobs { get; private set; } = new();
public IList<War> Wars { get; private set; } = new List<War>();
public Jobs.JobsDB JobsDB { get; private set; } = new();
public UnitCollection Units { get; } = new();
public CulturesDB CulturesDB { get; } = new();
public ReligionCollection Religions { get; private set; }
Expand Down Expand Up @@ -193,14 +193,14 @@ public World(Configuration config, ConverterVersion converterVersion): this(conf
});
RegisterKeyword("diplomacy", reader => {
Logger.Info("Loading diplomacy...");
var diplomacy = new Diplomacy.Diplomacy(reader);
var diplomacy = new Diplomacy.DiplomacyDB(reader);
Wars = diplomacy.Wars;
Logger.IncrementProgress();
});
RegisterKeyword("jobs", reader => {
Logger.Info("Loading Jobs...");
Jobs = new Jobs.Jobs(reader, Countries, ImperatorRegionMapper);
Logger.Info($"Loaded {Jobs.Governorships.Capacity} governorships.");
JobsDB = new Jobs.JobsDB(reader, Countries, ImperatorRegionMapper);
Logger.Info($"Loaded {JobsDB.Governorships.Count} governorships.");
Logger.IncrementProgress();
});
RegisterKeyword("deity_manager", reader => {
Expand Down
5 changes: 4 additions & 1 deletion ImperatorToCK3/ImperatorToCK3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\Debug\ImperatorToCK3\</OutputPath>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -30,6 +29,10 @@
<PackageReference Include="CsvHelper" Version="30.0.1" />
<PackageReference Include="Fmod5Sharp" Version="3.0.1" />
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="13.2.0" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.80">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NAudio" Version="2.1.0" />
<PackageReference Include="NAudio.Vorbis" Version="1.5.0" />
<PackageReference Include="PGCG.commonItems" Version="8.2.0" />
Expand Down

0 comments on commit fd1aa7e

Please sign in to comment.