Skip to content

Commit

Permalink
Bookmark map with player titles displayed (#324) #minor
Browse files Browse the repository at this point in the history
* DrawBookmarkMap test

* Prepare BookmarkOutputter for displaying player countries

* Draw bookmark map with player titles displayed

* PR tweaks

* Fix regression

* Make countries on map semi-transparent

* Determine province neighbors from provinces.png

* Determine colorable impassables

* Color some impassables

* Create realm highlight file

* Minor optimisation

* Update title_map.txt

* Calculate position for players on bookmark screen

* Change provincePositionsPath

* Update commonItems.NET

* Calculate position of character on bookmark screen

* Separate file for ProvincePosition

* Separate files for classes

* ReSharper tweaks for BookmarkOutputter

* ID -> Id

* ProvinceDefinitionTests

* TestFiles, ProvinceDefinitionsTests

* Create ProvincePositionTests.cs

* MapDataTests

* Tweaks for Codacy

* Add vassals' counties to bookmark map

* Actually do what the previous commit was supposed to

* !!!

* Check nonImpassableNeighborProvs for emptiness

* Change thrown exception type

* Change impassable coloring algorithm

* Test tweaks

* Make GetProvincesInCountry a Title method

* Load MapData in CK3 World

* Cleanup

* Fix memory leak by using ImageSharp

* Remove old rakaly files
  • Loading branch information
IhateTrains authored Oct 3, 2021
1 parent d25d6a6 commit 4b93e67
Show file tree
Hide file tree
Showing 47 changed files with 75,648 additions and 167 deletions.
48 changes: 48 additions & 0 deletions ImperatorToCK3.UnitTests/CK3/Map/MapDataTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using ImperatorToCK3.CK3.Map;
using System;
using System.Collections.Generic;
using System.IO;
using Xunit;

namespace ImperatorToCK3.UnitTests.CK3.Map {
[Collection("MapTests")]
[CollectionDefinition("MapTests", DisableParallelization = true)]
public class MapDataTests {
private const string testCK3Path = "TestFiles/MapData/CK3_1_province_map";
[Fact]
public void NeighborsDictDefaultsToEmpty() {
var data = new MapData(testCK3Path);

Assert.Empty(data.NeighborsDict);
}
[Fact]
public void NeighborProvincesCanBeDetermined() {
const string testCK3Path2 = "TestFiles/MapData/CK3_all_prov_defs";
const ulong byzantionId = 496;

var data = new MapData(testCK3Path2);
Assert.True(data.ProvinceDefinitions.ProvinceToColorDict.ContainsKey(byzantionId));
Assert.True(data.NeighborsDict.ContainsKey(byzantionId));

var byzantionNeighborProvs = data.NeighborsDict[byzantionId];
var expectedByzantionNeighborProvs = new HashSet<ulong> {
3761, // Selymbria
8668, // sea_bosporus
947 // sea_marmara
// There is also a dark grey circle in the middle of Byzantion,
// but the color is not found in definition.csv, so there's no ID to add to neighbors.
};
Assert.True(byzantionNeighborProvs.SetEquals(expectedByzantionNeighborProvs));
}

[Fact]
public void ProvinceNotFoundForColorIsLogged() {
var output = new StringWriter();
Console.SetOut(output);

const string testCK3Path2 = "TestFiles/MapData/CK3_all_prov_defs";
_ = new MapData(testCK3Path2);
Assert.Contains("Province not found for color Rgb24(30, 30, 30)", output.ToString());
}
}
}
57 changes: 57 additions & 0 deletions ImperatorToCK3.UnitTests/CK3/Map/ProvinceDefinitionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using ImperatorToCK3.CK3.Map;
using SixLabors.ImageSharp.PixelFormats;
using System;
using Xunit;

namespace ImperatorToCK3.UnitTests.CK3.Map {
[Collection("MapTests")]
[CollectionDefinition("MapTests", DisableParallelization = true)]
public class ProvinceDefinitionsTests {
private const string testCK3Path = "TestFiles/CK3";
[Fact]
public void DictionariesDefaultToEmpty() {
var provDefs = new ProvinceDefinitions(testCK3Path);
Assert.Collection(provDefs.ColorToProvinceDict,
pair1 => {
(Rgb24 key, ulong value) = pair1;
Assert.Equal(new Rgb24(42, 3, 128), key);
Assert.Equal((ulong)1, value);
},
pair2 => {
(Rgb24 key, ulong value) = pair2;
Assert.Equal(new Rgb24(84, 6, 1), key);
Assert.Equal((ulong)2, value);
},
pair3 => {
(Rgb24 key, ulong value) = pair3;
Assert.Equal(new Rgb24(126, 9, 129), key);
Assert.Equal((ulong)3, value);
}
);
Assert.Collection(provDefs.ProvinceToColorDict,
pair1 => {
(ulong key, Rgb24 value) = pair1;
Assert.Equal((ulong)1, key);
Assert.Equal(new Rgb24(42, 3, 128), value);
},
pair2 => {
(ulong key, Rgb24 value) = pair2;
Assert.Equal((ulong)2, key);
Assert.Equal(new Rgb24(84, 6, 1), value);
},
pair3 => {
(ulong key, Rgb24 value) = pair3;
Assert.Equal((ulong)3, key);
Assert.Equal(new Rgb24(126, 9, 129), value);
}
);
}

[Fact]
public void ExceptionIsThrownOnUnparseableLine() {
const string ck3Path = "TestFiles/corruptedCK3";
// this definition.csv has a line with quoted province id
Assert.Throws<FormatException>(() => _ = new ProvinceDefinitions(ck3Path));
}
}
}
24 changes: 24 additions & 0 deletions ImperatorToCK3.UnitTests/CK3/Map/ProvincePositionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using commonItems;
using ImperatorToCK3.CK3.Map;
using Xunit;

namespace ImperatorToCK3.UnitTests.CK3.Map {
[Collection("MapTests")]
[CollectionDefinition("MapTests", DisableParallelization = true)]
public class ProvincePositionTests {
[Fact]
public void PositionCanBeParsed() {
const string blob = "{" +
"id = 5 " +
"position ={ 271.722198 0.000000 3950.798096 } " +
"rotation ={ -0.000000 - 0.960029 - 0.000000 0.279900 } " +
"scale ={ 1.000000 1.000000 1.000000 } " +
"}";
var reader = new BufferedReader(blob);
var pos = ProvincePosition.Parse(reader);
Assert.Equal((ulong)5, pos.Id);
Assert.Equal(271.722198, pos.X);
Assert.Equal(3950.798096, pos.Y);
}
}
}
2 changes: 2 additions & 0 deletions ImperatorToCK3.UnitTests/Imperator/Families/FamiliesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Xunit;

namespace ImperatorToCK3.UnitTests.Imperator.Families {
[Collection("Sequential")]
[CollectionDefinition("Sequential", DisableParallelization = true)]
public class FamiliesTests {
[Fact]
public void FamiliesDefaultToEmpty() {
Expand Down
73 changes: 40 additions & 33 deletions ImperatorToCK3.UnitTests/ImperatorToCK3.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,104 +29,111 @@

<ItemGroup>
<None Update="TestFiles\CK3ProvincesHistoryFile.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\CK3_province_mappings.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\CoatsOfArms.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\configurables\definite_form_names.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\configurables\governorMappings.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\configurables\nickname_map.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\configurables\succession_law_map.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\configurables\title_map.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\configurables\trait_map.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\mod\brokenmod.mod">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\mod\missingmod.mod">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\mod\packedmod.mod">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\mod\packedmod.zip">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\mod\themod.mod">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\mod\themod\README.md">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\regions\CK3RegionMapperTests\CorrectParentLocationsReported.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\regions\CK3RegionMapperTests\empty.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\regions\CK3RegionMapperTests\LoadingBrokenCountyWillThrowException.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\regions\CK3RegionMapperTests\LoadingBrokenDuchyWillThrowException.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\regions\CK3RegionMapperTests\LoadingBrokenRegionWillThrowException.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\regions\CK3RegionMapperTests\LocationNameValidationWorks.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\regions\CK3RegionMapperTests\LocationServicesCorrectlyFail.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\regions\CK3RegionMapperTests\LocationServicesFailForNonsense.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\regions\CK3RegionMapperTests\LocationServicesSucceedsForCountyField.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\regions\CK3RegionMapperTests\LocationServicesSucceedsForProvinceField.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\regions\CK3RegionMapperTests\LocationServicesWork.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\regions\CK3RegionMapperTests\WrongParentLocationsReturnNull.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\regions\CultureMappingTests\empty.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\regions\CultureMappingTests\MatchOnRegion.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\regions\CultureMappingTests\MatchOnRegionFailsForWrongRegion.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\regions\island_regions.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\regions\regions.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="TestFiles\title_history\TitlesHistory.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<TestFiles Include="TestFiles/**/*.*" />
</ItemGroup>

<Target Name="CopyCustomContent" AfterTargets="Build">
<Copy SourceFiles="@(TestFiles)" DestinationFolder="$(OutDir)\TestFiles\%(RecursiveDir)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" Retries="3" RetryDelayMilliseconds="300" />
</Target>
</Project>
Loading

0 comments on commit 4b93e67

Please sign in to comment.