mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Allow adding an xml to an existing dialogue that had a null asset (#868)
## Bug fixes - If `pathToExistingDialogue` points to a dialogue object that has a null asset, it will now set its asset to yours instead of erroring. - We now search in the body for `pathToExistingDialogue`. You no longer have to put the root object at the beginning of the path.
This commit is contained in:
commit
df7cbae490
@ -35,7 +35,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return (AddToExistingDialogue(info, xml), null);
|
return (AddToExistingDialogue(go, info, xml, dialogueName), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,9 +70,11 @@ namespace NewHorizons.Builder.Props
|
|||||||
return (dialogue, remoteTrigger);
|
return (dialogue, remoteTrigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CharacterDialogueTree AddToExistingDialogue(DialogueInfo info, string xml)
|
private static CharacterDialogueTree AddToExistingDialogue(GameObject go, DialogueInfo info, string xml, string dialogueName)
|
||||||
{
|
{
|
||||||
var existingDialogue = SearchUtilities.Find(info.pathToExistingDialogue)?.GetComponent<CharacterDialogueTree>();
|
var dialogueObject = go.FindChild(info.pathToExistingDialogue);
|
||||||
|
if (dialogueObject == null) dialogueObject = SearchUtilities.Find(info.pathToExistingDialogue);
|
||||||
|
var existingDialogue = dialogueObject != null ? dialogueObject.GetComponent<CharacterDialogueTree>() : null;
|
||||||
|
|
||||||
if (existingDialogue == null)
|
if (existingDialogue == null)
|
||||||
{
|
{
|
||||||
@ -80,7 +82,29 @@ namespace NewHorizons.Builder.Props
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var existingText = existingDialogue._xmlCharacterDialogueAsset.text;
|
var existingAsset = existingDialogue._xmlCharacterDialogueAsset;
|
||||||
|
if (existingAsset == null)
|
||||||
|
{
|
||||||
|
var dialogueDoc = new XmlDocument();
|
||||||
|
dialogueDoc.LoadXml(xml);
|
||||||
|
var xmlNode = dialogueDoc.SelectSingleNode("DialogueTree");
|
||||||
|
AddTranslation(xmlNode);
|
||||||
|
|
||||||
|
xml = xmlNode.OuterXml;
|
||||||
|
|
||||||
|
var text = new TextAsset(xml)
|
||||||
|
{
|
||||||
|
// Text assets need a name to be used with VoiceMod
|
||||||
|
name = dialogueName
|
||||||
|
};
|
||||||
|
existingDialogue.SetTextXml(text);
|
||||||
|
|
||||||
|
FixDialogueNextFrame(existingDialogue);
|
||||||
|
|
||||||
|
return existingDialogue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var existingText = existingAsset.text;
|
||||||
|
|
||||||
var existingDialogueDoc = new XmlDocument();
|
var existingDialogueDoc = new XmlDocument();
|
||||||
existingDialogueDoc.LoadXml(existingText);
|
existingDialogueDoc.LoadXml(existingText);
|
||||||
@ -517,14 +541,16 @@ namespace NewHorizons.Builder.Props
|
|||||||
|
|
||||||
public static void HandleUnityCreatedDialogue(CharacterDialogueTree dialogue)
|
public static void HandleUnityCreatedDialogue(CharacterDialogueTree dialogue)
|
||||||
{
|
{
|
||||||
var text = dialogue._xmlCharacterDialogueAsset.text;
|
var asset = dialogue._xmlCharacterDialogueAsset;
|
||||||
|
if (asset == null) return;
|
||||||
|
var text = asset.text;
|
||||||
var dialogueDoc = new XmlDocument();
|
var dialogueDoc = new XmlDocument();
|
||||||
dialogueDoc.LoadXml(text);
|
dialogueDoc.LoadXml(text);
|
||||||
var xmlNode = dialogueDoc.SelectSingleNode("DialogueTree");
|
var xmlNode = dialogueDoc.SelectSingleNode("DialogueTree");
|
||||||
AddTranslation(xmlNode, null);
|
AddTranslation(xmlNode, null);
|
||||||
var newTextAsset = new TextAsset(dialogueDoc.OuterXml)
|
var newTextAsset = new TextAsset(dialogueDoc.OuterXml)
|
||||||
{
|
{
|
||||||
name = dialogue._xmlCharacterDialogueAsset.name
|
name = asset.name
|
||||||
};
|
};
|
||||||
dialogue.SetTextXml(newTextAsset);
|
dialogue.SetTextXml(newTextAsset);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user