using Babushka.scripts.CSharp.Common.CharacterControls; using Babushka.scripts.CSharp.Common.Inventory; using Babushka.scripts.CSharp.GameEntity.Entities; using Babushka.scripts.CSharp.GameEntity.Management; using Godot; using Godot.Collections; namespace Babushka.scripts.CSharp.Common.Items; public partial class InventoryDependentInteractable : Node2D { [Export] private InteractionArea2D _interactionArea; [Export] private Array _itemsToReactTo; [Export] private bool _activateOnItem = true; private VesnaEntity _vesnaEntity; private InventoryInstance _playerInventory; public override void _Ready() { _vesnaEntity = EntityManager.Instance.GetUniqueEntity(); _playerInventory = _vesnaEntity.inventory; _vesnaEntity.SlotIndexChanged += HandleInventorySelectedSlotIndexChanged; } private void HandleInventorySelectedSlotIndexChanged(int newIndex) { int currentSlotIndex = _vesnaEntity.CurrentSelectedSlotIndex; ItemInstance? item = _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; } }