61 lines
1.4 KiB
C#
61 lines
1.4 KiB
C#
using Godot;
|
|
using System.Collections.Generic;
|
|
|
|
public abstract class ProgramNode
|
|
{
|
|
public ProgramNode nextNode;
|
|
public ProgramNode NegativeNode;
|
|
public string DisplayText;
|
|
public string TooltipText;
|
|
public string lastExecutionMessage;
|
|
|
|
public abstract NodeResult Execute(Robot robot, double delta);
|
|
public abstract ProgramNode Duplicate();
|
|
public abstract string Save();
|
|
|
|
public virtual void SetNextNode(
|
|
List<Godot.Collections.Dictionary> connections,
|
|
Dictionary<StringName, ProgramNode> availableNodes
|
|
)
|
|
{
|
|
nextNode = null;
|
|
|
|
if (connections.Count <= 0) return;
|
|
|
|
nextNode = GetConnectedNode(connections[0], availableNodes);
|
|
}
|
|
|
|
protected void SetBranchNodes(
|
|
List<Godot.Collections.Dictionary> connections,
|
|
Dictionary<StringName, ProgramNode> availableNodes
|
|
)
|
|
{
|
|
nextNode = null;
|
|
NegativeNode = null;
|
|
|
|
foreach (Godot.Collections.Dictionary connection in connections)
|
|
{
|
|
ProgramNode connectedNode = GetConnectedNode(connection, availableNodes);
|
|
if ((int)connection["from_port"] == 0)
|
|
{
|
|
nextNode = connectedNode;
|
|
}
|
|
else
|
|
{
|
|
NegativeNode = connectedNode;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected ProgramNode GetConnectedNode(
|
|
Godot.Collections.Dictionary connection,
|
|
Dictionary<StringName, ProgramNode> availableNodes
|
|
)
|
|
{
|
|
StringName nodeName = connection["to_node"].AsStringName();
|
|
if (!availableNodes.ContainsKey(nodeName)) return null;
|
|
|
|
return availableNodes[nodeName];
|
|
}
|
|
}
|