mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Clean up some code to avoid making a billion XmlDocuments
This commit is contained in:
parent
700baec85a
commit
a7bbbc1bd1
@ -156,7 +156,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
// If they're adding dialogue we have to manually register the xml text
|
// If they're adding dialogue we have to manually register the xml text
|
||||||
if (isFromAssetBundle && component is CharacterDialogueTree dialogue)
|
if (isFromAssetBundle && component is CharacterDialogueTree dialogue)
|
||||||
{
|
{
|
||||||
DialogueBuilder.AddTranslation(dialogue._xmlCharacterDialogueAsset.text, null);
|
DialogueBuilder.HandleUnityCreatedDialogue(dialogue);
|
||||||
}
|
}
|
||||||
|
|
||||||
FixComponent(component, go, detail.ignoreSun);
|
FixComponent(component, go, detail.ignoreSun);
|
||||||
|
|||||||
@ -5,7 +5,9 @@ using NewHorizons.Utility;
|
|||||||
using NewHorizons.Utility.OuterWilds;
|
using NewHorizons.Utility.OuterWilds;
|
||||||
using NewHorizons.Utility.OWML;
|
using NewHorizons.Utility.OWML;
|
||||||
using OWML.Common;
|
using OWML.Common;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data.SqlTypes;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
@ -130,20 +132,11 @@ namespace NewHorizons.Builder.Props
|
|||||||
|
|
||||||
// Chracter name is required for adding translations, something to do with how OW prefixes its dialogue
|
// Chracter name is required for adding translations, something to do with how OW prefixes its dialogue
|
||||||
var characterName = existingDialogueTree.SelectSingleNode("NameField").InnerText;
|
var characterName = existingDialogueTree.SelectSingleNode("NameField").InnerText;
|
||||||
AddTranslation(xml, characterName);
|
AddTranslation(additionalDialogueDoc.GetChildNode("DialogueTree"), characterName);
|
||||||
|
|
||||||
return existingDialogue;
|
return existingDialogue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string DoDialogueOptionsListReplacement(string xmlString)
|
|
||||||
{
|
|
||||||
var dialogueDoc = new XmlDocument();
|
|
||||||
dialogueDoc.LoadXml(xmlString);
|
|
||||||
var xmlNode = dialogueDoc.SelectSingleNode("DialogueTree");
|
|
||||||
DoDialogueOptionsListReplacement(xmlNode);
|
|
||||||
return xmlNode.OuterXml;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void DoDialogueOptionsListReplacement(XmlNode dialogueTree)
|
private static void DoDialogueOptionsListReplacement(XmlNode dialogueTree)
|
||||||
{
|
{
|
||||||
var optionsListsByName = new Dictionary<string, XmlNode>();
|
var optionsListsByName = new Dictionary<string, XmlNode>();
|
||||||
@ -235,7 +228,12 @@ namespace NewHorizons.Builder.Props
|
|||||||
|
|
||||||
var dialogueTree = conversationZone.AddComponent<NHCharacterDialogueTree>();
|
var dialogueTree = conversationZone.AddComponent<NHCharacterDialogueTree>();
|
||||||
|
|
||||||
xml = DoDialogueOptionsListReplacement(xml);
|
var dialogueDoc = new XmlDocument();
|
||||||
|
dialogueDoc.LoadXml(xml);
|
||||||
|
var xmlNode = dialogueDoc.SelectSingleNode("DialogueTree");
|
||||||
|
DoDialogueOptionsListReplacement(xmlNode);
|
||||||
|
AddTranslation(xmlNode);
|
||||||
|
xml = xmlNode.OuterXml;
|
||||||
|
|
||||||
var text = new TextAsset(xml)
|
var text = new TextAsset(xml)
|
||||||
{
|
{
|
||||||
@ -243,7 +241,6 @@ namespace NewHorizons.Builder.Props
|
|||||||
name = dialogueName
|
name = dialogueName
|
||||||
};
|
};
|
||||||
dialogueTree.SetTextXml(text);
|
dialogueTree.SetTextXml(text);
|
||||||
AddTranslation(xml);
|
|
||||||
|
|
||||||
switch (info.flashlightToggle)
|
switch (info.flashlightToggle)
|
||||||
{
|
{
|
||||||
@ -428,11 +425,17 @@ namespace NewHorizons.Builder.Props
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Obsolete("Pass in the DialogueTree XmlNode instead, this is still here because Pikpik was using it in EOTP")]
|
||||||
public static void AddTranslation(string xml, string characterName = null)
|
public 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");
|
||||||
|
AddTranslation(xmlNode, characterName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddTranslation(XmlNode xmlNode, string characterName = null)
|
||||||
|
{
|
||||||
var xmlNodeList = xmlNode.SelectNodes("DialogueNode");
|
var xmlNodeList = xmlNode.SelectNodes("DialogueNode");
|
||||||
|
|
||||||
// When adding dialogue to existing stuff, we have to pass in the character name
|
// When adding dialogue to existing stuff, we have to pass in the character name
|
||||||
@ -467,5 +470,20 @@ namespace NewHorizons.Builder.Props
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void HandleUnityCreatedDialogue(CharacterDialogueTree dialogue)
|
||||||
|
{
|
||||||
|
var text = dialogue._xmlCharacterDialogueAsset.text;
|
||||||
|
var dialogueDoc = new XmlDocument();
|
||||||
|
dialogueDoc.LoadXml(text);
|
||||||
|
var xmlNode = dialogueDoc.SelectSingleNode("DialogueTree");
|
||||||
|
AddTranslation(xmlNode, null);
|
||||||
|
DoDialogueOptionsListReplacement(xmlNode);
|
||||||
|
var newTextAsset = new TextAsset(dialogueDoc.OuterXml)
|
||||||
|
{
|
||||||
|
name = dialogue._xmlCharacterDialogueAsset.name
|
||||||
|
};
|
||||||
|
dialogue.SetTextXml(newTextAsset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user