Files
RuinAdventurer/Scripts/DSL/Nodes/ForNode.cs
T

62 lines
1.2 KiB
C#

using Godot;
using System.Collections.Generic;
public class ForNode : ProgramNode
{
public int amountExecuted;
public int amount;
public ForNode()
{
DisplayText = "For";
}
public override NodeResult Execute(Robot robot, double delta)
{
bool isConditionFulfilled = DetermineCondition();
amountExecuted++;
return isConditionFulfilled? NodeResult.SUCCESS : NodeResult.CONDITIONFALSE;
}
private bool DetermineCondition()
{
return amountExecuted < amount;
}
public override ProgramNode Duplicate()
{
ForNode duplicate = new ForNode()
{
amount = amount,
amountExecuted = 0
};
return duplicate;
}
public override string Save()
{
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;
}
}
}
}