Added new nodes to DSL for a wider variety of commands and scripts.
This commit is contained in:
@@ -2,5 +2,6 @@ public enum NodeResult
|
||||
{
|
||||
SUCCESS,
|
||||
FAILURE,
|
||||
RUNNING
|
||||
RUNNING,
|
||||
CONDITIONFALSE
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class CraftNode : ProgramNode
|
||||
{
|
||||
HBoxContainer valueContainer = display.GetNode<HBoxContainer>("./EditorDisplay/HBoxContainer/");
|
||||
OptionButton items = valueContainer.GetNode<OptionButton>("./Item");
|
||||
string readableItem = items.GetItemText(items.GetSelectedId());
|
||||
string readableItem = items.GetItemText(items.GetSelectedId()).Split(":")[0];
|
||||
if (GameData.availableItems.ContainsKey(ItemData.GetIndex(readableItem)))
|
||||
{
|
||||
selectedItem = new Item { data = GameData.availableItems[ItemData.GetIndex(readableItem)] };
|
||||
@@ -79,7 +79,7 @@ public class CraftNode : ProgramNode
|
||||
{
|
||||
for (int i = 0; i < options.ItemCount; i++)
|
||||
{
|
||||
if (ItemData.GetIndex(options.GetItemText(i)) == selectedItem.data.Id)
|
||||
if (ItemData.GetIndex(options.GetItemText(i).Split(":")[0]) == selectedItem.data.Id)
|
||||
{
|
||||
options.Select(i);
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using Godot;
|
||||
|
||||
public class ElseNode : ProgramNode
|
||||
{
|
||||
public ElseNode()
|
||||
{
|
||||
DisplayText = "Else";
|
||||
}
|
||||
public override NodeResult Execute(Robot robot, double delta)
|
||||
{
|
||||
return NodeResult.SUCCESS;
|
||||
}
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
ElseNode duplicate = new ElseNode();
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dxpf6nsijqq1d
|
||||
@@ -0,0 +1,48 @@
|
||||
using Godot;
|
||||
|
||||
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 void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
HBoxContainer valueContainer = display.GetNode<HBoxContainer>("./EditorDisplay/HBoxContainer/");
|
||||
amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
ForNode duplicate = new ForNode()
|
||||
{
|
||||
amount = amount,
|
||||
amountExecuted = 0
|
||||
};
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}, AmountExecuted: {amountExecuted}, Amount: {amount}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://s1gp2fdow25r
|
||||
@@ -30,6 +30,10 @@ public class HarvestNode : ProgramNode
|
||||
lastExecutionMessage = "Not enough space";
|
||||
return NodeResult.FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NodeResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
return NodeResult.RUNNING;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
using Godot;
|
||||
|
||||
public class IfNode : ProgramNode
|
||||
{
|
||||
public Item selectedItem;
|
||||
public int amount;
|
||||
public string comparator;
|
||||
public IfNode()
|
||||
{
|
||||
DisplayText = "If";
|
||||
}
|
||||
public override NodeResult Execute(Robot robot, double delta)
|
||||
{
|
||||
if (selectedItem == null)
|
||||
{
|
||||
lastExecutionMessage = "No Item selected";
|
||||
return NodeResult.FAILURE;
|
||||
}
|
||||
|
||||
bool isConditionFulfilled = DetermineCondition();
|
||||
return isConditionFulfilled? NodeResult.SUCCESS : NodeResult.CONDITIONFALSE;
|
||||
}
|
||||
|
||||
private bool DetermineCondition()
|
||||
{
|
||||
int inventoryAmount = GameData.inventory.GetItemAmount(selectedItem.data.Id);
|
||||
switch (comparator)
|
||||
{
|
||||
case "is bigger than":
|
||||
return inventoryAmount > amount;
|
||||
case "is less than":
|
||||
return inventoryAmount < amount;
|
||||
case "is not":
|
||||
return inventoryAmount != amount;
|
||||
case "is less than or equal to":
|
||||
return inventoryAmount <= amount;
|
||||
case "is bigger than or equal to":
|
||||
return inventoryAmount >= amount;
|
||||
default:
|
||||
return inventoryAmount == amount;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
HBoxContainer valueContainer = display.GetNode<HBoxContainer>("./EditorDisplay/HBoxContainer/");
|
||||
OptionButton items = valueContainer.GetNode<OptionButton>("./Item");
|
||||
string readableItem = items.GetItemText(items.GetSelectedId()).Split(":")[0];
|
||||
if (GameData.availableItems.ContainsKey(ItemData.GetIndex(readableItem)))
|
||||
{
|
||||
selectedItem = new Item { data = GameData.availableItems[ItemData.GetIndex(readableItem)] };
|
||||
}
|
||||
amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
|
||||
|
||||
OptionButton comparators = valueContainer.GetNode<OptionButton>("./Comparator");
|
||||
comparator = comparators.GetItemText(comparators.GetSelectedId());
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
IfNode duplicate = new IfNode()
|
||||
{
|
||||
selectedItem = selectedItem,
|
||||
amount = amount,
|
||||
comparator = comparator
|
||||
};
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
OptionButton options = display.GetNode<OptionButton>("./EditorDisplay/HBoxContainer/Item");
|
||||
options.AddItem("Select item...");
|
||||
foreach (ItemData item in GameData.availableItems.Values)
|
||||
{
|
||||
if (GameData.availableResearch[item.Research].state != ResearchState.RESEARCHED) continue;
|
||||
options.AddItem(item.GetReadableName());
|
||||
}
|
||||
|
||||
if (selectedItem != null)
|
||||
{
|
||||
for (int i = 0; i < options.ItemCount; i++)
|
||||
{
|
||||
if (ItemData.GetIndex(options.GetItemText(i).Split(":")[0]) == selectedItem.data.Id)
|
||||
{
|
||||
options.Select(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OptionButton comparators = display.GetNode<OptionButton>("./EditorDisplay/HBoxContainer/Comparator");
|
||||
|
||||
if (comparator != null)
|
||||
{
|
||||
for (int i = 0; i < comparators.ItemCount; i++)
|
||||
{
|
||||
if (comparators.GetItemText(i) == comparator)
|
||||
{
|
||||
comparators.Select(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}, Item: {(selectedItem == null ? "Empty" : selectedItem.data.Id)}, Comparator: {comparator}, Amount: {amount}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cosidbtpmcj16
|
||||
@@ -3,6 +3,7 @@ using Godot;
|
||||
public abstract class ProgramNode
|
||||
{
|
||||
public ProgramNode nextNode;
|
||||
public ProgramNode previousNode;
|
||||
public string DisplayText;
|
||||
public string lastExecutionMessage;
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using Godot;
|
||||
|
||||
public class UntilNode : ProgramNode
|
||||
{
|
||||
public UntilNode()
|
||||
{
|
||||
DisplayText = "Until";
|
||||
}
|
||||
public override NodeResult Execute(Robot robot, double delta)
|
||||
{
|
||||
return NodeResult.SUCCESS;
|
||||
}
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
UntilNode duplicate = new UntilNode();
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cq0j38wd84pc7
|
||||
@@ -0,0 +1,113 @@
|
||||
using Godot;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
bool isConditionFulfilled = DetermineCondition();
|
||||
return isConditionFulfilled? NodeResult.SUCCESS : NodeResult.CONDITIONFALSE;
|
||||
}
|
||||
|
||||
private bool DetermineCondition()
|
||||
{
|
||||
int inventoryAmount = GameData.inventory.GetItemAmount(selectedItem.data.Id);
|
||||
switch (comparator)
|
||||
{
|
||||
case "is bigger than":
|
||||
return inventoryAmount > amount;
|
||||
case "is less than":
|
||||
return inventoryAmount < amount;
|
||||
case "is not":
|
||||
return inventoryAmount != amount;
|
||||
case "is less than or equal to":
|
||||
return inventoryAmount <= amount;
|
||||
case "is bigger than or equal to":
|
||||
return inventoryAmount >= amount;
|
||||
default:
|
||||
return inventoryAmount == amount;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
HBoxContainer valueContainer = display.GetNode<HBoxContainer>("./EditorDisplay/HBoxContainer/");
|
||||
OptionButton items = valueContainer.GetNode<OptionButton>("./Item");
|
||||
|
||||
string readableItem = items.GetItemText(items.GetSelectedId()).Split(":")[0];
|
||||
if (GameData.availableItems.ContainsKey(ItemData.GetIndex(readableItem)))
|
||||
{
|
||||
selectedItem = new Item { data = GameData.availableItems[ItemData.GetIndex(readableItem)] };
|
||||
}
|
||||
amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
|
||||
|
||||
OptionButton comparators = valueContainer.GetNode<OptionButton>("./Comparator");
|
||||
comparator = comparators.GetItemText(comparators.GetSelectedId());
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
WhileNode duplicate = new WhileNode()
|
||||
{
|
||||
selectedItem = selectedItem,
|
||||
amount = amount,
|
||||
comparator = comparator
|
||||
};
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
OptionButton options = display.GetNode<OptionButton>("./EditorDisplay/HBoxContainer/Item");
|
||||
options.AddItem("Select item...");
|
||||
foreach (ItemData item in GameData.availableItems.Values)
|
||||
{
|
||||
if (GameData.availableResearch[item.Research].state != ResearchState.RESEARCHED) continue;
|
||||
options.AddItem(item.GetReadableName());
|
||||
}
|
||||
|
||||
if (selectedItem != null)
|
||||
{
|
||||
for (int i = 0; i < options.ItemCount; i++)
|
||||
{
|
||||
if (ItemData.GetIndex(options.GetItemText(i).Split(":")[0]) == selectedItem.data.Id)
|
||||
{
|
||||
options.Select(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OptionButton comparators = display.GetNode<OptionButton>("./EditorDisplay/HBoxContainer/Comparator");
|
||||
|
||||
if (comparator != null)
|
||||
{
|
||||
for (int i = 0; i < comparators.ItemCount; i++)
|
||||
{
|
||||
if (comparators.GetItemText(i) == comparator)
|
||||
{
|
||||
comparators.Select(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}, Item: {(selectedItem == null ? "Empty" : selectedItem.data.Id)}, Comparator: {comparator}, Amount: {amount}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://hmecauiiaggc
|
||||
Reference in New Issue
Block a user