Added complete crafting to the game. Next step would be research and buildings. Updated DSL with Setup to work with dynamic loading.
This commit is contained in:
@@ -12,14 +12,9 @@ public partial class NodeDisplay : PanelContainer
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public void SetupUIElement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
node.Setup(this);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
|
||||
@@ -2,31 +2,74 @@ using Godot;
|
||||
|
||||
public class CraftNode : ProgramNode
|
||||
{
|
||||
Item selectedItem;
|
||||
int amount;
|
||||
public CraftNode()
|
||||
{
|
||||
DisplayText = "Craft";
|
||||
}
|
||||
public override NodeResult Execute(Robot robot, double delta)
|
||||
{
|
||||
GD.Print("Craft");
|
||||
if (nextNode != null)
|
||||
if (selectedItem == null)
|
||||
{
|
||||
return nextNode.Execute(robot, delta);
|
||||
lastExecutionMessage = "No Item selected";
|
||||
return NodeResult.FAILURE;
|
||||
}
|
||||
else
|
||||
if (amount <= 0)
|
||||
{
|
||||
return NodeResult.SUCCESS;
|
||||
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;
|
||||
}
|
||||
|
||||
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 ProgramNode Duplicate()
|
||||
{
|
||||
CraftNode duplicate = new CraftNode();
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,4 +87,9 @@ public class ExploreNode : ProgramNode
|
||||
{
|
||||
//Currently does nothing
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
//Currently does nothing
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public class HarvestNode : ProgramNode
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
//
|
||||
//Currently does nothing
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
@@ -44,4 +44,9 @@ public class HarvestNode : ProgramNode
|
||||
HarvestNode duplicate = new HarvestNode();
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
//Currently does nothing
|
||||
}
|
||||
}
|
||||
@@ -72,4 +72,9 @@ public class MoveNode : ProgramNode
|
||||
};
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
//Currently does nothing
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ public abstract class ProgramNode
|
||||
public string DisplayText;
|
||||
public string lastExecutionMessage;
|
||||
|
||||
public abstract void Setup(NodeDisplay display);
|
||||
public abstract NodeResult Execute(Robot robot, double delta);
|
||||
public abstract void ReadParameters(NodeDisplay display);
|
||||
public abstract ProgramNode Duplicate();
|
||||
|
||||
Reference in New Issue
Block a user