-
-
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.
Support has_ck3_dlc parameter in succession law mappings
- Loading branch information
1 parent
b713452
commit e75daa8
Showing
5 changed files
with
81 additions
and
33 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
30 changes: 28 additions & 2 deletions
30
ImperatorToCK3/Mappers/SuccessionLaw/SuccessionLawMapping.cs
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 |
---|---|---|
@@ -1,16 +1,42 @@ | ||
using commonItems; | ||
using commonItems.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace ImperatorToCK3.Mappers.SuccessionLaw; | ||
|
||
internal sealed class SuccessionLawMapping { | ||
public string ImperatorLaw { get; set; } = ""; | ||
public SortedSet<string> CK3SuccessionLaws { get; } = new(); | ||
private string ImperatorLaw { get; set; } = ""; | ||
private OrderedSet<string> CK3SuccessionLaws { get; } = []; | ||
private HashSet<string> RequiredCK3Dlcs { get; } = []; | ||
|
||
public SuccessionLawMapping(BufferedReader mappingReader) { | ||
var parser = new Parser(); | ||
parser.RegisterKeyword("ir", reader => ImperatorLaw = reader.GetString()); | ||
parser.RegisterKeyword("ck3", reader => CK3SuccessionLaws.Add(reader.GetString())); | ||
parser.RegisterKeyword("has_ck3_dlc", reader => RequiredCK3Dlcs.Add(reader.GetString())); | ||
parser.RegisterRegex(CommonRegexes.Catchall, ParserHelpers.IgnoreAndLogItem); | ||
parser.ParseStream(mappingReader); | ||
|
||
|
||
if (CK3SuccessionLaws.Count == 0) { | ||
Logger.Warn("SuccessionLawMapper: link with no CK3 successions laws"); | ||
} | ||
} | ||
|
||
internal OrderedSet<string>? Match(string irLaw, IReadOnlyCollection<string> enabledCK3Dlcs) { | ||
if (irLaw != ImperatorLaw) { | ||
return null; | ||
} | ||
|
||
if (RequiredCK3Dlcs.Count != 0) { | ||
if (enabledCK3Dlcs.Count == 0) { | ||
return null; | ||
} | ||
if (!RequiredCK3Dlcs.IsSubsetOf(enabledCK3Dlcs)) { | ||
return null; | ||
} | ||
} | ||
|
||
return new(CK3SuccessionLaws); | ||
} | ||
} |