-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle missing areas when loading states (#1504
- Loading branch information
1 parent
e91befd
commit 18941f6
Showing
6 changed files
with
83 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,58 @@ | ||
using commonItems; | ||
using commonItems.Collections; | ||
using ImperatorToCK3.CommonUtils; | ||
using ImperatorToCK3.Imperator.Countries; | ||
using ImperatorToCK3.Imperator.Geography; | ||
|
||
namespace ImperatorToCK3.Imperator.States; | ||
|
||
public class StateCollection : IdObjectCollection<ulong, State> { | ||
public void LoadStates(BufferedReader statesDbReader, IdObjectCollection<string, Area> areas, CountryCollection countries) { | ||
stateDataParser.RegisterKeyword("capital", reader => stateData.CapitalProvinceId = reader.GetULong()); | ||
stateDataParser.RegisterKeyword("area", reader => { | ||
var areaId = reader.GetString(); | ||
if (!areas.TryGetValue(areaId, out var area)) { | ||
Logger.Warn($"Unrecognized area found when loading states: {areaId}"); | ||
return; | ||
} | ||
stateData.Area = area; | ||
}); | ||
stateDataParser.RegisterKeyword("country", reader => { | ||
var countryId = reader.GetULong(); | ||
if (!countries.TryGetValue(countryId, out var country)) { | ||
Logger.Warn($"Unrecognized country found when loading states: {countryId}"); | ||
return; | ||
} | ||
stateData.Country = country; | ||
}); | ||
stateDataParser.IgnoreAndStoreUnregisteredItems(IgnoredStateKeywords); | ||
|
||
var parser = new Parser(); | ||
parser.RegisterRegex(CommonRegexes.Integer, (reader, stateIdStr) => { | ||
var strOfItem = reader.GetStringOfItem(); | ||
if (!strOfItem.IsArrayOrObject()) { | ||
return; | ||
} | ||
var stateReader = new BufferedReader(strOfItem.ToString()); | ||
AddOrReplace(new State(ulong.Parse(stateIdStr), stateReader, areas, countries)); | ||
var stateId = ulong.Parse(stateIdStr); | ||
stateData = new StateData(); | ||
stateDataParser.ParseStream(new BufferedReader(strOfItem.ToString())); | ||
if (stateData.Area is null) { | ||
Logger.Warn($"State {stateId} has no area defined!"); | ||
return; | ||
} | ||
if (stateData.Country is null) { | ||
Logger.Warn($"State {stateId} has no country defined!"); | ||
return; | ||
} | ||
AddOrReplace(new State(stateId, stateData)); | ||
}); | ||
parser.IgnoreAndLogUnregisteredItems(); | ||
parser.ParseStream(statesDbReader); | ||
} | ||
|
||
private StateData stateData = new(); | ||
private readonly Parser stateDataParser = new(); | ||
|
||
public static IgnoredKeywordsSet IgnoredStateKeywords { get; } = new(); | ||
} |
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,10 @@ | ||
using ImperatorToCK3.Imperator.Countries; | ||
using ImperatorToCK3.Imperator.Geography; | ||
|
||
namespace ImperatorToCK3.Imperator.States; | ||
|
||
public record StateData { | ||
public ulong CapitalProvinceId { get; set; } | ||
public Area? Area { get; set; } | ||
public Country? Country { get; set; } | ||
} |
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