Skip to content

Commit

Permalink
Fix multiple errors reported by ck3-tiger for a conversion to TFE (#2204
Browse files Browse the repository at this point in the history
) #patch
  • Loading branch information
IhateTrains authored Sep 17, 2024
1 parent 5de3a02 commit a0ca406
Show file tree
Hide file tree
Showing 47 changed files with 1,566 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class CK3CharacterBuilder {
private TraitMapper traitMapper = new("TestFiles/configurables/trait_map.txt", CK3ModFS);
private NicknameMapper nicknameMapper = new("TestFiles/configurables/nickname_map.txt");
private LocDB irLocDB = new("english");
private CK3LocDB ck3LocDB = new(CK3ModFS);
private CK3LocDB ck3LocDB = new(CK3ModFS, Array.Empty<string>());
private ProvinceMapper provinceMapper = new();
private DeathReasonMapper deathReasonMapper = new();

Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3.UnitTests/CK3/Dynasties/DynastyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Character Build() {
traitMapper,
nicknameMapper,
locDB,
new CK3LocDB(ck3ModFS),
new CK3LocDB(ck3ModFS, config.GetActiveCK3ModFlags()),
irMapData,
provinceMapper,
deathReasonMapper,
Expand Down
22 changes: 16 additions & 6 deletions ImperatorToCK3/CK3/CK3LocDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@
using ImperatorToCK3.CK3.Localization;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace ImperatorToCK3.CK3;

public class CK3LocDB : ConcurrentIdObjectCollection<string, CK3LocBlock> {
public CK3LocDB() { }

public CK3LocDB(ModFilesystem ck3ModFS) {
LoadLocFromModFS(ck3ModFS);
public CK3LocDB(ModFilesystem ck3ModFS, IEnumerable<string> activeModFlags) {
LoadLocFromModFS(ck3ModFS, activeModFlags);
}

public void LoadLocFromModFS(ModFilesystem ck3ModFS) {
public void LoadLocFromModFS(ModFilesystem ck3ModFS, IEnumerable<string> activeModFlags) {
// Read loc from CK3 and selected CK3 mods.
var modFSLocDB = new LocDB(ConverterGlobals.PrimaryLanguage, ConverterGlobals.SecondaryLanguages);
modFSLocDB.ScrapeLocalizations(ck3ModFS);
ImportLocFromLocDB(modFSLocDB);

// Read loc from ImperatorToCK3 congifurables.
// It will only be outputted for keys localized in neither ModFSLocDB nor ConverterGeneratedLocDB.
LoadOptionalLoc();
LoadOptionalLoc(activeModFlags);
}

private void ImportLocFromLocDB(LocDB locDB) {
Expand All @@ -38,15 +39,24 @@ private void ImportLocFromLocDB(LocDB locDB) {
}
}

private void LoadOptionalLoc() {
private void LoadOptionalLoc(IEnumerable<string> activeModFlags) {
const string optionalLocDir = "configurables/localization";
if (!Directory.Exists(optionalLocDir)) {
Logger.Warn("Optional loc directory not found, skipping optional loc loading.");
return;
}

string baseLocDir = Path.Combine(optionalLocDir, "base");
var optionalLocFilePaths = Directory.GetFiles(baseLocDir, "*.yml", SearchOption.AllDirectories);
foreach (var modFlag in activeModFlags) {
string modLocDir = Path.Combine(optionalLocDir, modFlag);
if (!Directory.Exists(modLocDir)) {
continue;
}
optionalLocFilePaths = optionalLocFilePaths.Concat(Directory.GetFiles(modLocDir, "*.yml", SearchOption.AllDirectories)).ToArray();
}

var optionalConverterLocDB = new LocDB(ConverterGlobals.PrimaryLanguage, ConverterGlobals.SecondaryLanguages);
var optionalLocFilePaths = Directory.GetFiles(optionalLocDir, "*.yml", SearchOption.AllDirectories);
foreach (var outputtedLocFilePath in optionalLocFilePaths) {
optionalConverterLocDB.ScrapeFile(outputtedLocFilePath);
}
Expand Down
20 changes: 20 additions & 0 deletions ImperatorToCK3/CK3/Cultures/CultureCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
namespace ImperatorToCK3.CK3.Cultures;

public class CultureCollection : IdObjectCollection<string, Culture> {
public readonly Dictionary<string, StringOfItem> CultureCreationNames = [];

public CultureCollection(ColorFactory colorFactory, PillarCollection pillarCollection, OrderedDictionary<string, bool> ck3ModFlags) {
this.PillarCollection = pillarCollection;
InitCultureDataParser(colorFactory, ck3ModFlags);
Expand Down Expand Up @@ -243,6 +245,24 @@ public void LoadInnovationIds(ModFilesystem ck3ModFS) {
}
}

public void LoadConverterCultureCreationNames(bool tfeEnabled) {
Logger.Info("Loading converter's culture creation names...");

var parser = new Parser();
parser.RegisterRegex(CommonRegexes.String, (reader, cultureId) => {
CultureCreationNames[cultureId] = new StringOfItem(reader);
});
parser.IgnoreAndLogUnregisteredItems();
parser.ParseFile("configurables/culture/culture_creation_names.txt");

if (tfeEnabled) {
// If TFE is enabled, remove creation names that depend on carthaginian culture existing.
CultureCreationNames.Remove("pmpese");
CultureCreationNames.Remove("taliaite");
CultureCreationNames.Remove("carchidonian");
}
}

private readonly IDictionary<string, string> cultureReplacements = new Dictionary<string, string>(); // replaced culture -> replacing culture

protected readonly PillarCollection PillarCollection;
Expand Down
12 changes: 11 additions & 1 deletion ImperatorToCK3/CK3/Titles/Title.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,17 @@ private void RegisterKeys(Parser parser) {
}
});
parser.RegisterKeyword("capital", reader => CapitalCountyId = reader.GetString());
parser.RegisterKeyword("ai_primary_priority", reader => AIPrimaryPriority = reader.GetStringOfItem());
parser.RegisterKeyword("ai_primary_priority", reader => {
var stringOfItem = reader.GetStringOfItem();
// Drop ai_primary_priority blocks that contain references to specific dynasties or characters.
var str = stringOfItem.ToString();
if (str.Contains("dynasty:") || str.Contains("character:")) {
return;
}
AIPrimaryPriority = stringOfItem;
});
parser.RegisterKeyword("ignore_titularity_for_title_weighting", reader => IgnoreTitularityForTitleWeighting = reader.GetBool());
parser.RegisterKeyword("can_create", reader => CanCreate = reader.GetStringOfItem());
parser.RegisterKeyword("can_create_on_partition", reader => CanCreateOnPartition = reader.GetStringOfItem());
Expand Down
3 changes: 2 additions & 1 deletion ImperatorToCK3/CK3/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public World(Imperator.World impWorld, Configuration config, Thread? irCoaExtrac
// Now that we have the mod filesystem, we can initialize the localization database.
Parallel.Invoke(
() => {
LocDB.LoadLocFromModFS(ModFS);
LocDB.LoadLocFromModFS(ModFS, config.GetActiveCK3ModFlags());
Logger.IncrementProgress();
},
() => ScriptValues.LoadScriptValues(ModFS),
Expand Down Expand Up @@ -133,6 +133,7 @@ public World(Imperator.World impWorld, Configuration config, Thread? irCoaExtrac
Cultures.LoadInnovationIds(ModFS);
Cultures.LoadCultures(ModFS);
Cultures.LoadConverterCultures("configurables/converter_cultures.txt");
Cultures.LoadConverterCultureCreationNames(config.FallenEagleEnabled);
Logger.IncrementProgress();
},
() => LoadMenAtArmsTypes(ModFS, ScriptValues), // depends on ScriptValues
Expand Down
4 changes: 4 additions & 0 deletions ImperatorToCK3/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,8 @@ public OrderedDictionary<string, bool> GetCK3ModFlags() {
flags["vanilla"] = flags.Count(f => f.Value) == 0;
return flags;
}

public IEnumerable<string> GetActiveCK3ModFlags() {
return GetCK3ModFlags().Where(f => f.Value).Select(f => f.Key);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
crimean_gothic = { # https://en.wikipedia.org/wiki/Crimean_Goths
crimean_gothic = { # https://en.wikipedia.org/wiki/Crimean_Goths
trigger = {
capital_county = {
title:d_crimea = {
Expand Down Expand Up @@ -198,3 +198,71 @@ hyperborean = {
}
}
}


## Hybrid

gothogreek = { # https://en.wikipedia.org/wiki/Gothograecia
trigger = {
OR = {
AND = {
scope:culture = {
OR = {
this = culture:gothic
any_parent_culture_or_above = { this = culture:gothic }
}
}
scope:other_culture = { has_cultural_pillar = language_greek }
}
AND = {
scope:culture = { has_cultural_pillar = language_greek }
scope:other_culture = {
OR = {
this = culture:gothic
any_parent_culture_or_above = { this = culture:gothic }
}
}
}
}
any_sub_realm_county = {
OR = {
culture = scope:culture
culture = scope:other_culture
}
}
}
hybrid = yes
}

carchidonian = { # before Royal Court a pre-defined fictional culture by Iohannes
name = carchidonian
trigger = {
OR = {
AND = {
scope:culture = {
OR = {
this = culture:carthaginian
any_parent_culture_or_above = { this = culture:carthaginian }
}
}
scope:other_culture = { has_cultural_pillar = language_greek }
}
AND = {
scope:culture = { has_cultural_pillar = language_greek }
scope:other_culture = {
OR = {
this = culture:carthaginian
any_parent_culture_or_above = { this = culture:carthaginian }
}
}
}
}
any_sub_realm_county = {
OR = {
culture = scope:culture
culture = scope:other_culture
}
}
}
hybrid = yes
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# For example, Charlemagne was born after I:R start, so the "carolingian" seed doesn't make sense.
# Comments are allowed and start with a hash (#) character.

# Vanilla seeds
king_arthur
carolingian
el_cid
Expand Down Expand Up @@ -31,4 +32,9 @@ ragnarr
shibi_chakravarti
afrasiyab
descendants_of_brahman
menelik_i
menelik_i

# TFE seeds
TFE_ashina_she_wolf
beowulf
haftvad
Loading

0 comments on commit a0ca406

Please sign in to comment.