Skip to content

Commit

Permalink
Merge pull request #91 from crashkonijn/fix/various-editor-bugs
Browse files Browse the repository at this point in the history
Fix/various editor bugs
  • Loading branch information
crashkonijn authored Oct 16, 2023
2 parents 2d068ed + 7499088 commit 49be2e4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
7 changes: 7 additions & 0 deletions Package/Documentation/General/WorldState.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Package/Editor/CrashKonijn.Goap.Editor/Classes/DebugGraph.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Graph = CrashKonijn.Goap.Editor.Classes.Models.Graph;
using Node = CrashKonijn.Goap.Editor.Classes.Models.Node;

Expand All @@ -25,11 +27,14 @@ public Nodes GetGraph(Node entryNode)

private void StoreNode(int depth, Node node, Nodes nodes)
{
if (nodes.Contains(node))
return;

nodes.Add(depth, node);

foreach (var connection in node.Conditions.SelectMany(condition => condition.Connections))
{
this.StoreNode(depth + 1, this.GetNode(connection), nodes);
this.StoreNode(depth + 1, this.GetNode(connection), nodes);
}
}

Expand Down
7 changes: 6 additions & 1 deletion Package/Editor/CrashKonijn.Goap.Editor/Classes/Nodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public int GetMaxWidth()

public void Add(int depth, Node node)
{
if (this.AllNodes.Values.Any(x => x.Node == node))
if (this.Contains(node))
return;

var newNode = new RenderNode(node);
Expand All @@ -47,5 +47,10 @@ public void Add(int depth, Node node)

this.MaxWidth = this.GetMaxWidth();
}

public bool Contains(Node node)
{
return this.AllNodes.Values.Any(x => x.Node == node);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using CrashKonijn.Goap.Behaviours;
using CrashKonijn.Goap.Editor.Classes;
Expand Down Expand Up @@ -173,7 +174,17 @@ private void RenderAgents()
itemsSource = this.agents
};

list.SetSelectionWithoutNotify(new []{ this.agents.IndexOf(this.agent) });
if (this.agent == null && this.agents.Count > 0)
{
list.SetSelectionWithoutNotify(new[] { 0 });
this.AgentChanged(this.agents[0]);
}

if (this.agent != null)
{
list.SetSelectionWithoutNotify(new []{ this.agents.IndexOf(this.agent) });
this.AgentChanged(this.agent);
}

#if UNITY_2021_1 || UNITY_2021_2 || UNITY_2021_3
list.schedule.Execute(() =>
Expand All @@ -188,26 +199,29 @@ private void RenderAgents()

var agent = this.agents[index];

if (agent == null)
return;

if (agent == this.agent)
return;

this.agent = agent;
this.goapSet = this.agent.GoapSet;
this.RenderGraph();
this.AgentChanged(agent);
}).Every(33);
#elif UNITY_2022_1_OR_NEWER
list.selectionChanged += _ =>
{
this.agent = this.agents[list.selectedIndex];
this.goapSet = this.agent.GoapSet;
this.RenderGraph();
this.AgentChanged(this.agents[list.selectedIndex]);
};
#endif
this.leftPanel.Add(list);
}

private void AgentChanged(AgentBehaviour agent)
{
if (agent == null)
return;

if (agent == this.agent)
return;

this.agent = agent;
this.goapSet = this.agent.GoapSet;
this.RenderGraph();
}

private void RenderGraph()
{
Expand Down

0 comments on commit 49be2e4

Please sign in to comment.