-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace ImperatorToCK3.CK3.Cultures; | ||
namespace ImperatorToCK3.CK3.Cultures; | ||
|
||
public class CultureCollection : IdObjectCollection<string, Culture> { | ||
public CultureCollection(ColorFactory colorFactory, PillarCollection pillarCollection, ICollection<string> ck3ModFlags) { | ||
|
@@ -64,10 +64,10 @@ private void InitCultureDataParser(ColorFactory colorFactory, ICollection<string | |
}); | ||
cultureDataParser.IgnoreAndLogUnregisteredItems(); | ||
} | ||
|
||
private void LoadInvalidatingCultureIds(ICollection<string> ck3ModFlags, BufferedReader reader) { | ||
var cultureIdsPerModFlagParser = new Parser(); | ||
|
||
if (ck3ModFlags.Count == 0) { | ||
cultureIdsPerModFlagParser.RegisterKeyword("vanilla", modCultureIdsReader => { | ||
cultureData.InvalidatingCultureIds = modCultureIdsReader.GetStrings(); | ||
|
@@ -79,37 +79,37 @@ private void LoadInvalidatingCultureIds(ICollection<string> ck3ModFlags, Buffere | |
}); | ||
} | ||
} | ||
|
||
// Ignore culture IDs from mods that haven't been selected. | ||
cultureIdsPerModFlagParser.IgnoreAndStoreUnregisteredItems(ignoredModFlags); | ||
cultureIdsPerModFlagParser.ParseStream(reader); | ||
} | ||
|
||
public void LoadCultures(ModFilesystem ck3ModFS) { | ||
Logger.Info("Loading cultures..."); | ||
|
||
var parser = new Parser(); | ||
parser.RegisterRegex(CommonRegexes.String, (reader, cultureId) => LoadCulture(cultureId, reader)); | ||
parser.IgnoreAndLogUnregisteredItems(); | ||
parser.ParseGameFolder("common/culture/cultures", ck3ModFS, "txt", true, logFilePaths: true); | ||
parser.ParseGameFolder("common/culture/cultures", ck3ModFS, "txt", recursive: true, logFilePaths: true); | ||
|
||
ReplaceInvalidatedParents(); | ||
} | ||
|
||
public void LoadConverterCultures(string converterCulturesPath) { | ||
Logger.Info("Loading converter cultures..."); | ||
|
||
var parser = new Parser(); | ||
parser.RegisterRegex(CommonRegexes.String, (reader, cultureId) => LoadCulture(cultureId, reader)); | ||
parser.IgnoreAndLogUnregisteredItems(); | ||
parser.ParseFile(converterCulturesPath); | ||
|
||
ReplaceInvalidatedParents(); | ||
} | ||
|
||
private void LoadCulture(string cultureId, BufferedReader cultureReader) { | ||
cultureData = new CultureData(); | ||
|
||
cultureDataParser.ParseStream(cultureReader); | ||
|
||
if (cultureData.InvalidatingCultureIds.Any()) { | ||
|
@@ -154,18 +154,18 @@ private void ReplaceInvalidatedParents() { | |
|
||
public void LoadNameLists(ModFilesystem ck3ModFS) { | ||
Logger.Info("Loading name lists..."); | ||
|
||
var parser = new Parser(); | ||
parser.RegisterRegex(CommonRegexes.String, (reader, nameListId) => { | ||
NameListCollection.AddOrReplace(new NameList(nameListId, reader)); | ||
}); | ||
parser.IgnoreAndLogUnregisteredItems(); | ||
parser.ParseGameFolder("common/culture/name_lists", ck3ModFS, "txt", recursive: true, logFilePaths: true); | ||
} | ||
|
||
public void LoadInnovationIds(ModFilesystem ck3ModFS) { | ||
Logger.Info("Loading CK3 innovation IDs..."); | ||
|
||
var parser = new Parser(); | ||
parser.RegisterRegex(CommonRegexes.String, (reader, innovationId) => { | ||
InnovationIds.Add(innovationId); | ||
|
@@ -181,7 +181,7 @@ public void LoadInnovationIds(ModFilesystem ck3ModFS) { | |
if (country.CountryType == CountryType.real) { | ||
Logger.Warn($"Failed to get primary or monarch culture for Imperator country {country.Tag}!"); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
|
@@ -190,25 +190,25 @@ public void LoadInnovationIds(ModFilesystem ck3ModFS) { | |
if (irProvinceId.HasValue) { | ||
ck3ProvinceId = provinceMapper.GetCK3ProvinceNumbers(irProvinceId.Value).FirstOrDefault(); | ||
} | ||
|
||
return cultureMapper.Match(irCulture, ck3ProvinceId, irProvinceId, country.HistoricalTag); | ||
} | ||
|
||
public void ImportTechnology(CountryCollection countries, CultureMapper cultureMapper, ProvinceMapper provinceMapper, InventionsDB inventionsDB, LocDB irLocDB) { // TODO: add tests for this | ||
Check warning on line 197 in ImperatorToCK3/CK3/Cultures/CultureCollection.cs GitHub Actions / build (self-hosted, windows)
Check warning on line 197 in ImperatorToCK3/CK3/Cultures/CultureCollection.cs GitHub Actions / build (self-hosted, linux)
Check warning on line 197 in ImperatorToCK3/CK3/Cultures/CultureCollection.cs GitHub Actions / build (macos-14)
Check warning on line 197 in ImperatorToCK3/CK3/Cultures/CultureCollection.cs GitHub Actions / test_and_check_coverage
Check warning on line 197 in ImperatorToCK3/CK3/Cultures/CultureCollection.cs GitHub Actions / test (macos-14)
Check warning on line 197 in ImperatorToCK3/CK3/Cultures/CultureCollection.cs GitHub Actions / test (self-hosted, windows)
|
||
Logger.Info("Converting Imperator inventions to CK3 innovations..."); | ||
|
||
var innovationMapper = new InnovationMapper(); | ||
innovationMapper.LoadLinksAndBonuses("configurables/inventions_to_innovations_map.txt"); | ||
innovationMapper.LogUnmappedInventions(inventionsDB, irLocDB); | ||
innovationMapper.RemoveMappingsWithInvalidInnovations(InnovationIds); | ||
|
||
// Group I:R countries by corresponding CK3 culture. | ||
var countriesByCulture = countries.Select(c => new { | ||
Country = c, CK3CultureId = GetCK3CultureIdForImperatorCountry(c, cultureMapper, provinceMapper), | ||
}) | ||
.Where(c => c.CK3CultureId is not null) | ||
.GroupBy(c => c.CK3CultureId); | ||
|
||
foreach (var grouping in countriesByCulture) { | ||
if (!TryGetValue(grouping.Key!, out var culture)) { | ||
Logger.Warn($"Can't import technology for culture {grouping.Key}: culture not found in CK3 cultures!"); | ||
|
@@ -223,11 +223,11 @@ public void LoadInnovationIds(ModFilesystem ck3ModFS) { | |
} | ||
|
||
private readonly IDictionary<string, string> cultureReplacements = new Dictionary<string, string>(); // replaced culture -> replacing culture | ||
|
||
protected readonly PillarCollection PillarCollection; | ||
protected readonly IdObjectCollection<string, NameList> NameListCollection = new(); | ||
protected readonly IdObjectCollection<string, NameList> NameListCollection = []; | ||
protected readonly HashSet<string> InnovationIds = []; | ||
|
||
private CultureData cultureData = new(); | ||
private readonly Parser cultureDataParser = new(); | ||
private readonly IgnoredKeywordsSet ignoredModFlags = []; | ||
|