Fix dialogue replacement overwriting character names

This commit is contained in:
Nick 2024-03-04 21:29:34 -05:00
parent e1411db3af
commit cab087d6f9

View File

@ -68,8 +68,6 @@ namespace NewHorizons.Builder.Props
private static CharacterDialogueTree AddToExistingDialogue(DialogueInfo info, string xml) private static CharacterDialogueTree AddToExistingDialogue(DialogueInfo info, string xml)
{ {
AddTranslation(xml);
var existingDialogue = SearchUtilities.Find(info.pathToExistingDialogue)?.GetComponent<CharacterDialogueTree>(); var existingDialogue = SearchUtilities.Find(info.pathToExistingDialogue)?.GetComponent<CharacterDialogueTree>();
if (existingDialogue == null) if (existingDialogue == null)
@ -125,6 +123,9 @@ namespace NewHorizons.Builder.Props
existingDialogue.SetTextXml(newTextAsset); existingDialogue.SetTextXml(newTextAsset);
var characterName = existingDialogueTree.SelectSingleNode("NameField").InnerText;
AddTranslation(xml, characterName);
return existingDialogue; 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(); var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xml); xmlDocument.LoadXml(xml);
var xmlNode = xmlDocument.SelectSingleNode("DialogueTree"); var xmlNode = xmlDocument.SelectSingleNode("DialogueTree");
var xmlNodeList = xmlNode.SelectNodes("DialogueNode"); var xmlNodeList = xmlNode.SelectNodes("DialogueNode");
string characterName = xmlNode.SelectSingleNode("NameField").InnerText;
// 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); TranslationHandler.AddDialogue(characterName);
}
foreach (object obj in xmlNodeList) foreach (object obj in xmlNodeList)
{ {