Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions addons/dialogue_trees/scripts/core/DialogueGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -239,7 +244,7 @@ void AddDialogueNode(Node node, int index)

dialogueNode.GraphReady();
dialogueNode.Selected = true;
}
}

_arrangingNodes = true;
ArrangeGraph(true);
Expand All @@ -249,13 +254,17 @@ void AddDialogueNode(Node node, int index)

///<summary>Unloads the given DialogueTreeData and removes all loadedNodes, this is intended only for use with UndoRedo.</summary>
public void UnloadTree(DialogueTreeData treeData, Array<Node> 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;
Expand All @@ -276,6 +285,10 @@ public void ClearTree()

foreach(Node node in GetChildren())
{
if (node.Name.Equals(_connectionLayer))
{
continue;
}
RemoveChild(node);
node.QueueFree();
}
Expand Down