State after inventory clip (farming mechanic still WIP)

This commit is contained in:
2025-05-21 00:13:58 +02:00
parent 83f4144b43
commit 708aa8cca4
4 changed files with 73 additions and 53 deletions
@@ -31,21 +31,13 @@ public partial class FarmingControls2D : Node2D
bool activate;
//if our hands are empty, activate
if (_toolId == -1)
if (toolId == -1)
{
activate = true;
activate = false;
}
else
{
//if we're already carrying a tool, deactivate or fail return
if (_toolId == toolId)
{
activate = false;
}
else
{
return false;
}
activate = true;
}
_toolId = activate ? toolId : -1;
@@ -1,3 +1,4 @@
using Babushka.scripts.CSharp.Common.Inventory;
using Godot;
namespace Babushka.scripts.CSharp.Common.Farming;
@@ -7,12 +8,44 @@ public partial class VesnaBehaviour2D : Node
[ExportGroup("Farming")]
[Export] private FieldService2D _fieldParent;
[Export] private FarmingControls2D _farmingControls;
[Export] private ItemResource _hoe;
[Export] private ItemResource _wateringCan;
[Signal] public delegate void PickedUpToolEventHandler(bool success, int toolId);
private InventoryManager _inventoryManager;
private InventoryInstance _inventoryInstance;
public override void _Ready()
{
_farmingControls.FieldService = _fieldParent;
_inventoryManager = InventoryManager.Instance;
_inventoryInstance = _inventoryManager.playerInventory;
_inventoryManager.SlotIndexChanged += HandleInventorySelectedSlotIndexChanged;
}
private void HandleInventorySelectedSlotIndexChanged(int newIndex)
{
InventorySlot currentSlot = InventoryManager.Instance.GetCurrentSelectedSlot();
ItemInstance? currentItem = currentSlot.itemInstance;
if (currentItem == null)
return;
if (currentItem.blueprint == _hoe)
{
ActivateTool(0);
return;
}
if (currentItem.blueprint == _wateringCan)
{
ActivateTool(1);
return;
}
ActivateTool(-1);
}
#region Farming