-
-
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.
Merge branch 'master' into empire-gore-tweak
- Loading branch information
Showing
8 changed files
with
95 additions
and
40 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
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