Skip to content

Commit

Permalink
Merge branch 'master' into invictus-compatch
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains committed Aug 8, 2023
2 parents ee2e131 + a9dc2a5 commit 4581a70
Show file tree
Hide file tree
Showing 31 changed files with 94 additions and 87 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/build_dev_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
expire-in: 0


upload_dev_build_artifact:
name: Upload development build
needs: remove_old_artifacts
Expand Down Expand Up @@ -44,10 +43,6 @@ jobs:
uses: actions/setup-dotnet@v3
with:
global-json-file: Fronter.NET/global.json
env:
BACKBLAZE_KEY_ID: ${{ secrets.BACKBLAZE_KEY_ID }}
BACKBLAZE_APPLICATION_KEY: ${{ secrets.BACKBLAZE_APPLICATION_KEY }}
BACKBLAZE_BUCKET_ID: ${{ secrets.BACKBLAZE_BUCKET_ID }}
- name: "Replace frontend background image"
run: |
rm Fronter.NET/Fronter.NET/Assets/Images/background.png
Expand All @@ -57,6 +52,10 @@ jobs:
with:
fronter_dir: 'Fronter.NET'
release_dir: 'Publish'
env:
BACKBLAZE_KEY_ID: ${{ secrets.BACKBLAZE_KEY_ID }}
BACKBLAZE_APPLICATION_KEY: ${{ secrets.BACKBLAZE_APPLICATION_KEY }}
BACKBLAZE_BUCKET_ID: ${{ secrets.BACKBLAZE_BUCKET_ID }}
- name: Setup Dotnet for use with actions
uses: actions/setup-dotnet@v3
with:
Expand Down
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
25 changes: 16 additions & 9 deletions ImperatorToCK3.UnitTests/Mappers/Region/CK3RegionMapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using commonItems.Mods;
using ImperatorToCK3.CK3.Titles;
using ImperatorToCK3.Mappers.Region;
using System;
using System.Collections.Generic;
using System.IO;
using Xunit;
Expand Down Expand Up @@ -38,9 +39,11 @@ public void LoadingBrokenRegionWillThrowException() {
const string ck3Path = "TestFiles/regions/CK3RegionMapperTests/LoadingBrokenRegionWillThrowException";
var ck3Root = Path.Combine(ck3Path, "game");
var ck3ModFS = new ModFilesystem(ck3Root, new List<Mod>());
void action() => mapper.LoadRegions(ck3ModFS, landedTitles);
KeyNotFoundException exception = Assert.Throws<KeyNotFoundException>(action);
Assert.Equal("Region's test_region2 region test_region does not exist!", exception.Message);

var output = new StringWriter();
Console.SetOut(output);
mapper.LoadRegions(ck3ModFS, landedTitles);
Assert.Contains("Region's test_region2 region test_region does not exist!", output.ToString());
}
[Fact]
public void LoadingBrokenDuchyWillThrowException() {
Expand All @@ -53,9 +56,11 @@ public void LoadingBrokenDuchyWillThrowException() {
const string ck3Path = "TestFiles/regions/CK3RegionMapperTests/LoadingBrokenDuchyWillThrowException";
var ck3Root = Path.Combine(ck3Path, "game");
var ck3ModFS = new ModFilesystem(ck3Root, new List<Mod>());
void action() => mapper.LoadRegions(ck3ModFS, landedTitles);
KeyNotFoundException exception = Assert.Throws<KeyNotFoundException>(action);
Assert.Equal("Region's test_region duchy d_aquitane does not exist!", exception.Message);

var output = new StringWriter();
Console.SetOut(output);
mapper.LoadRegions(ck3ModFS, landedTitles);
Assert.Contains("Region's test_region duchy d_aquitane does not exist!", output.ToString());
}
[Fact]
public void LoadingBrokenCountyWillThrowException() {
Expand All @@ -68,9 +73,11 @@ public void LoadingBrokenCountyWillThrowException() {
const string ck3Path = "TestFiles/regions/CK3RegionMapperTests/LoadingBrokenCountyWillThrowException";
var ck3Root = Path.Combine(ck3Path, "game");
var ck3ModFS = new ModFilesystem(ck3Root, new List<Mod>());
void Action() => mapper.LoadRegions(ck3ModFS, landedTitles);
KeyNotFoundException exception = Assert.Throws<KeyNotFoundException>(Action);
Assert.Equal("Region's test_region county c_mers does not exist!", exception.Message);

var output = new StringWriter();
Console.SetOut(output);
mapper.LoadRegions(ck3ModFS, landedTitles);
Assert.Contains("Region's test_region county c_mers does not exist!", output.ToString());
}

[Fact]
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/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
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
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
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
26 changes: 9 additions & 17 deletions ImperatorToCK3/Imperator/Countries/Country.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,17 @@ public SortedSet<string> GetLaws() {
_ => monarchyLaws,
};
}
public int TerritoriesCount => ownedProvinces.Count;
public CountryRank Rank {
get {
var provCount = ownedProvinces.Count;
if (provCount == 0) {
return CountryRank.migrantHorde;
}
if (provCount == 1) {
return CountryRank.cityState;
}
if (provCount <= 24) {
return CountryRank.localPower;
}
if (provCount <= 99) {
return CountryRank.regionalPower;
}
if (provCount <= 499) {
return CountryRank.majorPower;
}
return CountryRank.greatPower;
return TerritoriesCount switch {
0 => CountryRank.migrantHorde,
1 => CountryRank.cityState,
<= 24 => CountryRank.localPower,
<= 99 => CountryRank.regionalPower,
<= 499 => CountryRank.majorPower,
_ => CountryRank.greatPower
};
}
}
public void RegisterProvince(Province province) {
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
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
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
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
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
7 changes: 5 additions & 2 deletions 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,9 +29,13 @@
<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" />
<PackageReference Include="PGCG.commonItems" Version="8.3.0" />
<PackageReference Include="PGCG.commonItems.SourceGenerators" Version="1.0.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.1" />
</ItemGroup>
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
Loading

0 comments on commit 4581a70

Please sign in to comment.