Skip to content

Commit

Permalink
Fix exception if the special_headgear_blindfold gene is not found (#…
Browse files Browse the repository at this point in the history
…2397) #patch

Sentry event ID: 2454b92b077e42088ba9b3e3e777f5b3

Issue seems to occur when EPE is included in the CK3 mods.
  • Loading branch information
IhateTrains authored Jan 5, 2025
1 parent ebce0a8 commit 61b1b8d
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions ImperatorToCK3/CK3/Characters/DNAFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ internal DNA GenerateDNA(Imperator.Characters.Character irCharacter, PortraitDat
}

// Convert eye accessories.
const string blindfoldGeneId = "special_headgear_blindfold";
const string blindfoldTemplateId = "blindfold";
var irEyeAccessoryGeneTemplateName = irPortraitData.AccessoryGenesDict["eye_accessory"].GeneTemplate;
switch (irEyeAccessoryGeneTemplateName) {
case "normal_eyes":
Expand All @@ -171,11 +173,18 @@ internal DNA GenerateDNA(Imperator.Characters.Character irCharacter, PortraitDat

break;
case "blindfold_1": // TODO: check if this is correctly added to portrait modifiers if needed

Check warning on line 175 in ImperatorToCK3/CK3/Characters/DNAFactory.cs

View workflow job for this annotation

GitHub Actions / Upload development build (linux-x64)

TODO check if this is correctly added to portrait modifiers if needed (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 175 in ImperatorToCK3/CK3/Characters/DNAFactory.cs

View workflow job for this annotation

GitHub Actions / add_release_archive (linux-x64)

TODO check if this is correctly added to portrait modifiers if needed (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 175 in ImperatorToCK3/CK3/Characters/DNAFactory.cs

View workflow job for this annotation

GitHub Actions / add_release_archive (osx-arm64)

TODO check if this is correctly added to portrait modifiers if needed (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 175 in ImperatorToCK3/CK3/Characters/DNAFactory.cs

View workflow job for this annotation

GitHub Actions / add_release_archive (win-x64)

TODO check if this is correctly added to portrait modifiers if needed (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 175 in ImperatorToCK3/CK3/Characters/DNAFactory.cs

View workflow job for this annotation

GitHub Actions / Upload development build (win-x64)

TODO check if this is correctly added to portrait modifiers if needed (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)
var blindfoldTemplate = ck3GenesDB.SpecialAccessoryGenes["special_headgear_blindfold"]
.GeneTemplates["blindfold"];
if (!ck3GenesDB.SpecialAccessoryGenes.TryGetValue(blindfoldGeneId, out var blindfoldGene)) {
Logger.Warn($"{blindfoldGeneId} not found in CK3 special accessory genes!");
break;
}
if (!blindfoldGene.GeneTemplates.TryGetValue(blindfoldTemplateId, out var blindfoldTemplate)) {
Logger.Warn($"{blindfoldTemplateId} not found in CK3 special accessory genes!");
break;
}

if (blindfoldTemplate.AgeSexWeightBlocks.TryGetValue(irCharacter.AgeSex, out WeightBlock? blindfoldWeightBlock)) {
var blindfoldObjectName = blindfoldWeightBlock.GetMatchingObject(1) ?? blindfoldWeightBlock.ObjectNames.Last();
accessoryDNAValues["special_headgear_blindfold"] = new(blindfoldTemplate.Id, blindfoldObjectName, blindfoldWeightBlock);
accessoryDNAValues[blindfoldGeneId] = new(blindfoldTemplate.Id, blindfoldObjectName, blindfoldWeightBlock);
}

break;
Expand Down Expand Up @@ -206,12 +215,14 @@ internal DNA GenerateDNA(Imperator.Characters.Character irCharacter, PortraitDat
var blindEyesObjectName = blindEyesWeighBlock.GetMatchingObject(1) ?? blindEyesWeighBlock.ObjectNames.Last();
accessoryDNAValues["eye_accessory"] = new(blindEyesTemplate.Id, blindEyesObjectName, blindEyesWeighBlock); // TODO: check if this is correctly added to portrait modifiers if needed

Check warning on line 216 in ImperatorToCK3/CK3/Characters/DNAFactory.cs

View workflow job for this annotation

GitHub Actions / Upload development build (linux-x64)

TODO check if this is correctly added to portrait modifiers if needed (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 216 in ImperatorToCK3/CK3/Characters/DNAFactory.cs

View workflow job for this annotation

GitHub Actions / add_release_archive (linux-x64)

TODO check if this is correctly added to portrait modifiers if needed (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 216 in ImperatorToCK3/CK3/Characters/DNAFactory.cs

View workflow job for this annotation

GitHub Actions / add_release_archive (osx-arm64)

TODO check if this is correctly added to portrait modifiers if needed (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 216 in ImperatorToCK3/CK3/Characters/DNAFactory.cs

View workflow job for this annotation

GitHub Actions / add_release_archive (win-x64)

TODO check if this is correctly added to portrait modifiers if needed (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 216 in ImperatorToCK3/CK3/Characters/DNAFactory.cs

View workflow job for this annotation

GitHub Actions / Upload development build (win-x64)

TODO check if this is correctly added to portrait modifiers if needed (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)
}

var blindfoldTemplate = ck3GenesDB.SpecialAccessoryGenes["special_headgear_blindfold"]
.GeneTemplates["blindfold"];
if (blindfoldTemplate.AgeSexWeightBlocks.TryGetValue(irCharacter.AgeSex, out WeightBlock? blindfoldWeighBlock)) {

if (!ck3GenesDB.SpecialAccessoryGenes.TryGetValue(blindfoldGeneId, out var blindfoldGene)) {
Logger.Warn($"{blindfoldGeneId} not found in CK3 special accessory genes!");
} else if (!blindfoldGene.GeneTemplates.TryGetValue(blindfoldTemplateId, out var blindfoldTemplate)) {
Logger.Warn($"{blindfoldTemplateId} not found in CK3 special accessory genes!");
} else if (blindfoldTemplate.AgeSexWeightBlocks.TryGetValue(irCharacter.AgeSex, out WeightBlock? blindfoldWeighBlock)) {
var blindfoldObjectName = blindfoldWeighBlock.GetMatchingObject(1) ?? blindfoldWeighBlock.ObjectNames.Last();
accessoryDNAValues["special_headgear_blindfold"] = new(blindfoldTemplate.Id, blindfoldObjectName, blindfoldWeighBlock); // TODO: check if this is correctly added to portrait modifiers if needed
accessoryDNAValues[blindfoldGeneId] = new(blindfoldTemplate.Id, blindfoldObjectName, blindfoldWeighBlock); // TODO: check if this is correctly added to portrait modifiers if needed

Check warning on line 225 in ImperatorToCK3/CK3/Characters/DNAFactory.cs

View workflow job for this annotation

GitHub Actions / Upload development build (linux-x64)

TODO check if this is correctly added to portrait modifiers if needed (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 225 in ImperatorToCK3/CK3/Characters/DNAFactory.cs

View workflow job for this annotation

GitHub Actions / add_release_archive (linux-x64)

TODO check if this is correctly added to portrait modifiers if needed (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 225 in ImperatorToCK3/CK3/Characters/DNAFactory.cs

View workflow job for this annotation

GitHub Actions / add_release_archive (osx-arm64)

TODO check if this is correctly added to portrait modifiers if needed (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 225 in ImperatorToCK3/CK3/Characters/DNAFactory.cs

View workflow job for this annotation

GitHub Actions / add_release_archive (win-x64)

TODO check if this is correctly added to portrait modifiers if needed (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 225 in ImperatorToCK3/CK3/Characters/DNAFactory.cs

View workflow job for this annotation

GitHub Actions / Upload development build (win-x64)

TODO check if this is correctly added to portrait modifiers if needed (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)
}
} else if (irCharacter.Traits.Contains("one_eyed")) {
var eyePatchTemplate = ck3GenesDB.SpecialAccessoryGenes["special_headgear_eye_patch"]
Expand Down

0 comments on commit 61b1b8d

Please sign in to comment.