588879951d
Readded node deletion.
70 lines
1.6 KiB
C#
70 lines
1.6 KiB
C#
using Godot;
|
|
using System.Collections.Generic;
|
|
|
|
public class WhileNode : ProgramNode
|
|
{
|
|
public Item selectedItem;
|
|
public int amount;
|
|
public string comparator;
|
|
public WhileNode()
|
|
{
|
|
DisplayText = "While";
|
|
}
|
|
|
|
public override NodeResult Execute(Robot robot, double delta)
|
|
{
|
|
if (selectedItem == null)
|
|
{
|
|
lastExecutionMessage = "No Item selected";
|
|
return NodeResult.FAILURE;
|
|
}
|
|
|
|
if (comparator == null)
|
|
{
|
|
lastExecutionMessage = "No comparator selected";
|
|
return NodeResult.FAILURE;
|
|
}
|
|
|
|
bool isConditionFulfilled = DetermineCondition();
|
|
return isConditionFulfilled ? NodeResult.SUCCESS : NodeResult.CONDITIONFALSE;
|
|
}
|
|
|
|
private bool DetermineCondition()
|
|
{
|
|
int inventoryAmount = GameData.inventory.GetItemAmount(selectedItem.data.Id);
|
|
return comparator switch
|
|
{
|
|
"is bigger than" => inventoryAmount > amount,
|
|
"is less than" => inventoryAmount < amount,
|
|
"is not" => inventoryAmount != amount,
|
|
"is less than or equal to" => inventoryAmount <= amount,
|
|
"is bigger than or equal to" => inventoryAmount >= amount,
|
|
_ => inventoryAmount == amount
|
|
};
|
|
}
|
|
|
|
public override ProgramNode Duplicate()
|
|
{
|
|
WhileNode duplicate = new WhileNode()
|
|
{
|
|
selectedItem = selectedItem,
|
|
amount = amount,
|
|
comparator = comparator
|
|
};
|
|
return duplicate;
|
|
}
|
|
|
|
public override string Save()
|
|
{
|
|
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
|
|
)
|
|
{
|
|
SetBranchNodes(connections, availableNodes);
|
|
}
|
|
}
|