Added ability to delete nodes from editor, added complete node load and save for the DSL
This commit is contained in:
@@ -1,75 +1,92 @@
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
|
||||
public class CraftNode : ProgramNode
|
||||
{
|
||||
Item selectedItem;
|
||||
int amount;
|
||||
public CraftNode()
|
||||
{
|
||||
DisplayText = "Craft";
|
||||
}
|
||||
public override NodeResult Execute(Robot robot, double delta)
|
||||
{
|
||||
if (selectedItem == null)
|
||||
{
|
||||
lastExecutionMessage = "No Item selected";
|
||||
return NodeResult.FAILURE;
|
||||
}
|
||||
if (amount <= 0)
|
||||
{
|
||||
lastExecutionMessage = "Amount has to be atleast 1";
|
||||
return NodeResult.FAILURE;
|
||||
}
|
||||
if (!GameData.inventory.CanCraft(selectedItem.data.Inputs, amount))
|
||||
{
|
||||
lastExecutionMessage = "Not enough items to craft this";
|
||||
return NodeResult.FAILURE;
|
||||
}
|
||||
public Item selectedItem;
|
||||
public int amount;
|
||||
public CraftNode()
|
||||
{
|
||||
DisplayText = "Craft";
|
||||
}
|
||||
public override NodeResult Execute(Robot robot, double delta)
|
||||
{
|
||||
if (selectedItem == null)
|
||||
{
|
||||
lastExecutionMessage = "No Item selected";
|
||||
return NodeResult.FAILURE;
|
||||
}
|
||||
if (amount <= 0)
|
||||
{
|
||||
lastExecutionMessage = "Amount has to be atleast 1";
|
||||
return NodeResult.FAILURE;
|
||||
}
|
||||
if (!GameData.inventory.CanCraft(selectedItem.data.Inputs, amount))
|
||||
{
|
||||
lastExecutionMessage = "Not enough items to craft this";
|
||||
return NodeResult.FAILURE;
|
||||
}
|
||||
|
||||
switch (selectedItem.Craft(amount, delta))
|
||||
{
|
||||
case CraftingResult.FAILED:
|
||||
lastExecutionMessage = "Not enough space to add item to inventory";
|
||||
return NodeResult.FAILURE;
|
||||
case CraftingResult.FINISHED:
|
||||
return NodeResult.SUCCESS;
|
||||
}
|
||||
|
||||
return NodeResult.RUNNING;
|
||||
}
|
||||
switch (selectedItem.Craft(amount, delta))
|
||||
{
|
||||
case CraftingResult.FAILED:
|
||||
lastExecutionMessage = "Not enough space to add item to inventory";
|
||||
return NodeResult.FAILURE;
|
||||
case CraftingResult.FINISHED:
|
||||
return NodeResult.SUCCESS;
|
||||
}
|
||||
|
||||
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());
|
||||
if (GameData.availableItems.ContainsKey(ItemData.GetIndex(readableItem)))
|
||||
{
|
||||
selectedItem = new Item { data = GameData.availableItems[ItemData.GetIndex(readableItem)]};
|
||||
}
|
||||
amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
|
||||
}
|
||||
return NodeResult.RUNNING;
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
CraftNode duplicate = new CraftNode()
|
||||
{
|
||||
selectedItem = selectedItem,
|
||||
amount = amount
|
||||
};
|
||||
return duplicate;
|
||||
}
|
||||
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());
|
||||
if (GameData.availableItems.ContainsKey(ItemData.GetIndex(readableItem)))
|
||||
{
|
||||
selectedItem = new Item { data = GameData.availableItems[ItemData.GetIndex(readableItem)] };
|
||||
}
|
||||
amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
|
||||
}
|
||||
|
||||
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 (item.Inputs.Count > 0)
|
||||
{
|
||||
options.AddItem(item.GetReadableName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
CraftNode duplicate = new CraftNode()
|
||||
{
|
||||
selectedItem = selectedItem,
|
||||
amount = amount
|
||||
};
|
||||
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 (item.Inputs.Count > 0)
|
||||
{
|
||||
options.AddItem(item.GetReadableName());
|
||||
}
|
||||
}
|
||||
if (selectedItem != null)
|
||||
{
|
||||
for (int i = 0; i < options.ItemCount; i++)
|
||||
{
|
||||
if (ItemData.GetIndex(options.GetItemText(i)) == selectedItem.data.Id)
|
||||
{
|
||||
options.Select(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}, Item: {(selectedItem == null ? "Empty" : selectedItem.data.Id)}, Amount: {amount}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,4 +92,9 @@ public class ExploreNode : ProgramNode
|
||||
{
|
||||
//Currently does nothing
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}";
|
||||
}
|
||||
}
|
||||
@@ -49,4 +49,9 @@ public class HarvestNode : ProgramNode
|
||||
{
|
||||
//Currently does nothing
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}";
|
||||
}
|
||||
}
|
||||
@@ -77,4 +77,9 @@ public class MoveNode : ProgramNode
|
||||
{
|
||||
//Currently does nothing
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}, Position: ({targetPosition.X}|{targetPosition.Y}|{targetPosition.Z})";
|
||||
}
|
||||
}
|
||||
@@ -10,4 +10,5 @@ public abstract class ProgramNode
|
||||
public abstract NodeResult Execute(Robot robot, double delta);
|
||||
public abstract void ReadParameters(NodeDisplay display);
|
||||
public abstract ProgramNode Duplicate();
|
||||
public abstract string Save();
|
||||
}
|
||||
Reference in New Issue
Block a user