(WIP) Switch from previous DSL System (UI order based) to a new DSL System (node connection based) still in Progress.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class ForNode : ProgramNode
|
||||
{
|
||||
@@ -34,4 +35,27 @@ public class ForNode : ProgramNode
|
||||
{
|
||||
return $"Name: {DisplayText}, AmountExecuted: {amountExecuted}, Amount: {amount}";
|
||||
}
|
||||
|
||||
public override void SetNextNode(
|
||||
List<Godot.Collections.Dictionary> connections,
|
||||
Dictionary<StringName, ProgramNode> availableNodes
|
||||
)
|
||||
{
|
||||
nextNode = null;
|
||||
NegativeNode = null;
|
||||
|
||||
foreach (Godot.Collections.Dictionary connection in connections)
|
||||
{
|
||||
int port = (int)connection["from_port"];
|
||||
ProgramNode connectedNode = GetConnectedNode(connection, availableNodes);
|
||||
if (port == 0)
|
||||
{
|
||||
nextNode = connectedNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
NegativeNode = connectedNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class IfNode : ProgramNode
|
||||
{
|
||||
@@ -56,4 +57,27 @@ public class IfNode : ProgramNode
|
||||
{
|
||||
return $"Name: {DisplayText}, Item: {(selectedItem == null ? "Empty" : selectedItem.data.Id)}, Comparator: {comparator}, Amount: {amount}";
|
||||
}
|
||||
|
||||
public override void SetNextNode(
|
||||
List<Godot.Collections.Dictionary> connections,
|
||||
Dictionary<StringName, ProgramNode> availableNodes
|
||||
)
|
||||
{
|
||||
nextNode = null;
|
||||
NegativeNode = null;
|
||||
|
||||
foreach (Godot.Collections.Dictionary connection in connections)
|
||||
{
|
||||
int port = (int)connection["from_port"];
|
||||
ProgramNode connectedNode = GetConnectedNode(connection, availableNodes);
|
||||
if (port == 0)
|
||||
{
|
||||
nextNode = connectedNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
NegativeNode = connectedNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ public class MoveNode : ProgramNode
|
||||
pathPoints.Remove(pathPoints[0]);
|
||||
if (pathPoints.Count <= 0)
|
||||
{
|
||||
pathPoints = null;
|
||||
lastExecutionMessage = "";
|
||||
return NodeResult.SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,37 @@
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public abstract class ProgramNode
|
||||
{
|
||||
public ProgramNode nextNode;
|
||||
public ProgramNode previousNode;
|
||||
public ProgramNode NegativeNode;
|
||||
public string DisplayText;
|
||||
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 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];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
public class StartNode : ProgramNode
|
||||
{
|
||||
public StartNode()
|
||||
{
|
||||
DisplayText = "Start";
|
||||
}
|
||||
|
||||
public override NodeResult Execute(Robot robot, double delta)
|
||||
{
|
||||
return NodeResult.SUCCESS;
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
StartNode duplicate = new StartNode();
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://d3kyu2j3nxjsh
|
||||
@@ -1,4 +1,5 @@
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class WhileNode : ProgramNode
|
||||
{
|
||||
@@ -57,4 +58,27 @@ public class WhileNode : ProgramNode
|
||||
{
|
||||
return $"Name: {DisplayText}, Item: {(selectedItem == null ? "Empty" : selectedItem.data.Id)}, Comparator: {comparator}, Amount: {amount}";
|
||||
}
|
||||
|
||||
public override void SetNextNode(
|
||||
List<Godot.Collections.Dictionary> connections,
|
||||
Dictionary<StringName, ProgramNode> availableNodes
|
||||
)
|
||||
{
|
||||
nextNode = null;
|
||||
NegativeNode = null;
|
||||
|
||||
foreach (Godot.Collections.Dictionary connection in connections)
|
||||
{
|
||||
int port = (int)connection["from_port"];
|
||||
ProgramNode connectedNode = GetConnectedNode(connection, availableNodes);
|
||||
if (port == 0)
|
||||
{
|
||||
nextNode = connectedNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
NegativeNode = connectedNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user