You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.6 KiB
57 lines
1.6 KiB
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;
|
|
}
|
|
} |