From cab087d6f9767c2c0d5cf96b1eb35f78d83e5768 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 4 Mar 2024 21:29:34 -0500 Subject: [PATCH] Fix dialogue replacement overwriting character names --- NewHorizons/Builder/Props/DialogueBuilder.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/NewHorizons/Builder/Props/DialogueBuilder.cs b/NewHorizons/Builder/Props/DialogueBuilder.cs index 54eab78a..7f4d2d58 100644 --- a/NewHorizons/Builder/Props/DialogueBuilder.cs +++ b/NewHorizons/Builder/Props/DialogueBuilder.cs @@ -68,8 +68,6 @@ namespace NewHorizons.Builder.Props private static CharacterDialogueTree AddToExistingDialogue(DialogueInfo info, string xml) { - AddTranslation(xml); - var existingDialogue = SearchUtilities.Find(info.pathToExistingDialogue)?.GetComponent(); if (existingDialogue == null) @@ -125,6 +123,9 @@ namespace NewHorizons.Builder.Props existingDialogue.SetTextXml(newTextAsset); + var characterName = existingDialogueTree.SelectSingleNode("NameField").InnerText; + AddTranslation(xml, characterName); + return existingDialogue; } @@ -374,14 +375,20 @@ namespace NewHorizons.Builder.Props } } - private static void AddTranslation(string xml) + private static void AddTranslation(string xml, string characterName = null) { var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(xml); var xmlNode = xmlDocument.SelectSingleNode("DialogueTree"); var xmlNodeList = xmlNode.SelectNodes("DialogueNode"); - string characterName = xmlNode.SelectSingleNode("NameField").InnerText; - TranslationHandler.AddDialogue(characterName); + + // When adding dialogue to existing stuff, we have to pass in the character name + // Otherwise we translate it if its from a new dialogue object + if (characterName == null) + { + characterName = xmlNode.SelectSingleNode("NameField").InnerText; + TranslationHandler.AddDialogue(characterName); + } foreach (object obj in xmlNodeList) {