Implemented first version of an interactable area that reacts to inventory selection

This commit is contained in:
2025-08-17 23:49:04 +02:00
parent 3913143892
commit 6ae877f2ab
4 changed files with 83 additions and 1 deletions
@@ -0,0 +1,57 @@
using Babushka.scripts.CSharp.Common.CharacterControls;
using Babushka.scripts.CSharp.Common.Inventory;
using Godot;
using Godot.Collections;
namespace Babushka.scripts.CSharp.Common.Items;
public partial class InventoryDependentInteractable : Node2D
{
[Export] private InteractionArea2D _interactionArea;
[Export] private Array<ItemResource> _itemsToReactTo;
[Export] private bool _activateOnItem = true;
private InventoryManager _inventoryManager;
private InventoryInstance _inventoryInstance;
public override void _Ready()
{
_inventoryManager = InventoryManager.Instance;
_inventoryInstance = _inventoryManager.playerInventory;
_inventoryManager.SlotIndexChanged += HandleInventorySelectedSlotIndexChanged;
}
private void HandleInventorySelectedSlotIndexChanged(int newIndex)
{
int currentSlotIndex = InventoryManager.Instance.CurrentSelectedSlotIndex;
ItemInstance? item = InventoryManager.Instance.playerInventory.Slots[currentSlotIndex].itemInstance;
if (item != null)
{
if (_activateOnItem)
{
_interactionArea.IsActive = Match(item.blueprint);
}
else
{
_interactionArea.IsActive = !Match(item.blueprint);
}
}
}
private bool Match(ItemResource inventoryItem)
{
bool matched = false;
foreach (ItemResource item in _itemsToReactTo)
{
if (inventoryItem == item)
{
matched = true;
}
}
return matched;
}
}
@@ -0,0 +1 @@
uid://doxr432r22dd0