✨ added InventoryListener and made field interaction area activate only when the right item (seed) is in the inventory
parent
c52bfc8017
commit
6e833a0735
@ -0,0 +1,48 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
public partial class InventoryListener : Node
|
||||
{
|
||||
[Export] private ItemResource[] _itemResourcesToListenFor;
|
||||
|
||||
[Signal] public delegate void ItemInstanceActivatedEventHandler(bool activated);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
InventoryManager.Instance.playerInventory.InventoryContentsChanged += HandleNewItemInInventory;
|
||||
InventoryManager.Instance.SlotIndexChanged += HandleNewItemInInventory;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
InventoryManager.Instance.playerInventory.InventoryContentsChanged -= HandleNewItemInInventory;
|
||||
InventoryManager.Instance.SlotIndexChanged -= HandleNewItemInInventory;
|
||||
}
|
||||
|
||||
private void HandleNewItemInInventory(int newIndex)
|
||||
{
|
||||
HandleNewItemInInventory();
|
||||
}
|
||||
|
||||
private void HandleNewItemInInventory()
|
||||
{
|
||||
int currentSlotIndex = InventoryManager.Instance.CurrentSelectedSlotIndex;
|
||||
ItemInstance? instance = InventoryManager.Instance.playerInventory.Slots[currentSlotIndex].itemInstance;
|
||||
if (instance != null)
|
||||
{
|
||||
ItemResource? item = instance.blueprint;
|
||||
|
||||
foreach (var res in _itemResourcesToListenFor)
|
||||
{
|
||||
if (item == res)
|
||||
{
|
||||
EmitSignal(SignalName.ItemInstanceActivated, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EmitSignal(SignalName.ItemInstanceActivated, false);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
uid://3t0af586fimq
|
||||
Loading…
Reference in new issue