Skip to content

Commit

Permalink
Implement mappings loading in ArtifactVisualsMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains committed Oct 26, 2024
1 parent 81a5e71 commit b8d8a98
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
11 changes: 7 additions & 4 deletions ImperatorToCK3/CK3/Characters/CharacterCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ public void ImportArtifacts(
ModifierMapper modifierMapper,
ModifierCollection ck3Modifiers,
LocDB irLocDB,
CK3LocDB ck3LocDB,
Date date
) {
Logger.Info("Importing Imperator artifacts...");
Expand Down Expand Up @@ -750,7 +751,7 @@ Date date
// TODO: try to use create_artifact_sculpture_babr_e_bayan_effect as base

Check warning on line 751 in ImperatorToCK3/CK3/Characters/CharacterCollection.cs

View workflow job for this annotation

GitHub Actions / Upload development build (linux-x64)

TODO try to use create_artifact_sculpture_babr_e_bayan_effect as base (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)
foreach (var irArtifactId in irArtifactIds) {
var irArtifact = treasureManager[irArtifactId];
ImportArtifact(character, irArtifact, modifierMapper, ck3Modifiers, irLocDB, date);
ImportArtifact(character, irArtifact, modifierMapper, ck3Modifiers, irLocDB, ck3LocDB, date);
}


Expand Down Expand Up @@ -784,21 +785,23 @@ Date date
Logger.IncrementProgress();
}

private void ImportArtifact(Character character, Treasure irArtifact, ModifierMapper modifierMapper, ModifierCollection ck3Modifiers, LocDB irLocDB, Date date) {
private void ImportArtifact(Character character, Treasure irArtifact, ModifierMapper modifierMapper, ModifierCollection ck3Modifiers, LocDB irLocDB, CK3LocDB ck3LocDB, Date date) {
var ck3ArtifactName = $"IRToCK3_artifact_{irArtifact.Key}_{irArtifact.Id}";
var irNameLoc = irLocDB.GetLocBlockForKey(irArtifact.Key);
if (irNameLoc is null) {
Logger.Warn($"Can't find name loc for artifact {irArtifact.Key}!");
} else {
character.Localizations.Add(ck3ArtifactName, new LocBlock(ck3ArtifactName, irNameLoc));
var artifactNameLocBlock = ck3LocDB.GetOrCreateLocBlock(ck3ArtifactName);
artifactNameLocBlock.CopyFrom(irNameLoc);
}

var ck3DescKey = $"{ck3ArtifactName}_desc";
var irDescLoc = irLocDB.GetLocBlockForKey(irArtifact.Key + "_desc");
if (irDescLoc is null) {
Logger.Warn($"Can't find description loc for artifact {irArtifact.Key}!");
} else {
character.Localizations.Add(ck3DescKey, new LocBlock(ck3DescKey, irDescLoc));
var descLocBlock = ck3LocDB.GetOrCreateLocBlock(ck3DescKey);
descLocBlock.CopyFrom(irDescLoc);
}

var artifactScope = $"newly_created_artifact_{irArtifact.Id}";
Expand Down
1 change: 1 addition & 0 deletions ImperatorToCK3/CK3/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ public World(Imperator.World impWorld, Configuration config, Thread? irCoaExtrac
modifierMapper,
Modifiers,
impWorld.LocDB,
LocDB,
CorrectedDate
),

Expand Down
36 changes: 29 additions & 7 deletions ImperatorToCK3/Mappers/Artifact/ArtifactVisualsMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,43 @@ public ArtifactVisualsMapper(string mappingsPath) { // TODO: use this somewhere
var parser = new Parser();
RegisterKeys(parser);
parser.ParseFile(mappingsPath);
Logger.Info($"Loaded {impToCK3VisualMap.Count} artifact visuals links.");

Logger.Info($"Loaded {irTreasureToCK3VisualMap.Count} treasure to visual links " +
$"and {irIconToCK3VisualMap.Count} icon to visual links.");
}

private void RegisterKeys(Parser parser) {
parser.RegisterKeyword("link", reader => {
var mapping = new ArtifactVisualsMapping(reader);
if (mapping.Ck3Visual is null) {
parser.RegisterKeyword("link", linkReader => {
string? ck3Visual = null;
var irTreasureIds = new List<string>();
var irIconIds = new List<string>();
var linkParser = new Parser();
linkParser.RegisterKeyword("ck3Visual", reader => {
ck3Visual = reader.GetString();
});
linkParser.RegisterKeyword("irTreasure" , reader => {
irTreasureIds.Add(reader.GetString());
});
linkParser.RegisterKeyword("irIcon" , reader => {
irIconIds.Add(reader.GetString());
});
linkParser.IgnoreAndLogUnregisteredItems();
linkParser.ParseStream(linkReader);
if (ck3Visual is null) {
return;
}
foreach (var impVisual in mapping.ImpVisuals) {
impToCK3VisualMap.Add(impVisual, mapping.Ck3Visual);
foreach (var irTreasureId in irTreasureIds) {
irTreasureToCK3VisualMap.Add(irTreasureId, ck3Visual);
}
foreach (var irIconId in irIconIds) {
irIconToCK3VisualMap.Add(irIconId, ck3Visual);
}
});
}

private readonly Dictionary<string, string> impToCK3VisualMap = new();
private readonly Dictionary<string, string> irTreasureToCK3VisualMap = new();
private readonly Dictionary<string, string> irIconToCK3VisualMap = new();
}

0 comments on commit b8d8a98

Please sign in to comment.