From f8afe6b94a6b0ef151edf81aaf72787106e97126 Mon Sep 17 00:00:00 2001
From: Meythulhu <108483531+Meythulhu@users.noreply.github.com>
Date: Thu, 29 Aug 2024 21:13:08 -0700
Subject: [PATCH] Filter out _connection_layer, fix connection node indexing
being offset by _connection_layer on load
---
.../scripts/core/DialogueGraph.cs | 33 +++++++++++++------
1 file changed, 23 insertions(+), 10 deletions(-)
diff --git a/addons/dialogue_trees/scripts/core/DialogueGraph.cs b/addons/dialogue_trees/scripts/core/DialogueGraph.cs
index 04528ed..965fe2c 100644
--- a/addons/dialogue_trees/scripts/core/DialogueGraph.cs
+++ b/addons/dialogue_trees/scripts/core/DialogueGraph.cs
@@ -19,6 +19,7 @@ private const string
_fromPort = "from_port",
_toNode = "to_node",
_toPort = "to_port";
+ private static readonly StringName _connectionLayer = "_connection_layer";
public EditorUndoRedoManager UndoRedo;
public DialogueTreesPlugin Plugin;
@@ -216,14 +217,18 @@ void AddDialogueNode(Node node, int index)
loadedNodes.Add(node);
}
-
- for(int x = 0; x < treeData.GetConnectionsCount(); x++)
+
+ var children = GetChildren()
+ .Where(c => !c.Name.Equals(_connectionLayer))
+ .ToList();
+ var count = treeData.GetConnectionsCount();
+ for(int x = 0; x < count; x++)
{
DialogueTreeData.Connection con = treeData.GetConnection(x);
- Node fromNode = GetChild(con.FromNode);
- Node toNode = GetChild(con.ToNode);
-
+ Node fromNode = children.ElementAt(con.FromNode);
+ Node toNode = children.ElementAt(con.ToNode);
+
if(fromNode is not DialogueNode || toNode is not DialogueNode)
continue;
@@ -239,7 +244,7 @@ void AddDialogueNode(Node node, int index)
dialogueNode.GraphReady();
dialogueNode.Selected = true;
- }
+ }
_arrangingNodes = true;
ArrangeGraph(true);
@@ -249,13 +254,17 @@ void AddDialogueNode(Node node, int index)
///Unloads the given DialogueTreeData and removes all loadedNodes, this is intended only for use with UndoRedo.
public void UnloadTree(DialogueTreeData treeData, Array loadedNodes)
- {
- for(int x = 0; x < treeData.GetConnectionsCount(); x++)
+ {
+ var children = GetChildren()
+ .Where(c => !c.Name.Equals(_connectionLayer))
+ .ToList();
+ var count = treeData.GetConnectionsCount();
+ for(int x = 0; x < count; x++)
{
DialogueTreeData.Connection con = treeData.GetConnection(x);
- Node fromNode = GetChild(con.FromNode);
- Node toNode = GetChild(con.ToNode);
+ Node fromNode = children.ElementAt(con.FromNode);
+ Node toNode = children.ElementAt(con.ToNode);
if(fromNode is not DialogueNode || toNode is not DialogueNode)
continue;
@@ -276,6 +285,10 @@ public void ClearTree()
foreach(Node node in GetChildren())
{
+ if (node.Name.Equals(_connectionLayer))
+ {
+ continue;
+ }
RemoveChild(node);
node.QueueFree();
}