-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Purge unneeded dynasty houses from CK3 (#1969)
- Loading branch information
1 parent
95b77af
commit a2e0703
Showing
21 changed files
with
172 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using commonItems; | ||
using commonItems.Collections; | ||
using commonItems.Serialization; | ||
using commonItems.SourceGenerators; | ||
|
||
namespace ImperatorToCK3.CK3.Dynasties; | ||
|
||
[SerializationByProperties] | ||
public partial class House : IPDXSerializable, IIdentifiable<string> { | ||
[NonSerialized] public string Id { get; } | ||
|
||
[SerializedName("prefix")] public string? Prefix { get; private set; } | ||
[SerializedName("name")] public string? Name { get; private set; } | ||
[SerializedName("dynasty")] public string? DynastyId { get; private set; } | ||
[SerializedName("motto")] public string? Motto { get; private set; } | ||
[SerializedName("forced_coa_religiongroup")] public string? ForcedCoaReligionGroup { get; private set; } | ||
|
||
public House(string id, BufferedReader houseReader) { | ||
Id = id; | ||
|
||
var parser = new Parser(); | ||
parser.RegisterKeyword("prefix", reader => Prefix = reader.GetString()); | ||
parser.RegisterKeyword("name", reader => Name = reader.GetString()); | ||
parser.RegisterKeyword("dynasty", reader => DynastyId = reader.GetString()); | ||
parser.RegisterKeyword("motto", reader => Motto = reader.GetString()); | ||
parser.RegisterKeyword("forced_coa_religiongroup", reader => ForcedCoaReligionGroup = reader.GetString()); | ||
parser.IgnoreAndLogUnregisteredItems(); | ||
parser.ParseStream(houseReader); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using commonItems; | ||
using commonItems.Collections; | ||
using commonItems.Mods; | ||
using ImperatorToCK3.CK3.Characters; | ||
using System.Linq; | ||
|
||
namespace ImperatorToCK3.CK3.Dynasties; | ||
|
||
public class HouseCollection : IdObjectCollection<string, House> { | ||
public void LoadCK3Houses(ModFilesystem ck3ModFS) { | ||
Logger.Info("Loading dynasty houses from CK3..."); | ||
|
||
var parser = new Parser(); | ||
parser.RegisterRegex(CommonRegexes.String, (reader, houseId) => { | ||
var house = new House(houseId, reader); | ||
AddOrReplace(house); | ||
}); | ||
parser.IgnoreAndLogUnregisteredItems(); | ||
parser.ParseGameFolder("common/dynasty_houses", ck3ModFS, "txt", recursive: true, parallel: true); | ||
} | ||
|
||
public void PurgeUnneededHouses(CharacterCollection ck3Characters, Date date) { | ||
Logger.Info("Purging unneeded dynasty houses..."); | ||
|
||
var houseIdsToKeep = ck3Characters | ||
.Select(c => c.GetDynastyHouseId(date)) | ||
.Where(id => id is not null) | ||
.Distinct() | ||
.Cast<string>() | ||
.ToHashSet(); | ||
|
||
int removedCount = 0; | ||
foreach (var house in this.ToList()) { | ||
if (houseIdsToKeep.Contains(house.Id)) { | ||
continue; | ||
} | ||
|
||
Remove(house.Id); | ||
++removedCount; | ||
} | ||
Logger.Info($"Purged {removedCount} unneeded dynasty houses."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.