Moved Bar slot selection handling to inventory manager
This commit is contained in:
@@ -1,13 +1,27 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
public partial class InventoryManager : Node
|
||||
{
|
||||
public static InventoryManager Instance { get; private set; }
|
||||
[Signal]
|
||||
public delegate void SlotIndexChangedEventHandler(int newIndex);
|
||||
|
||||
public static InventoryManager Instance { get; private set; } = null!;
|
||||
public int CurrentSelectedSlotIndex
|
||||
{
|
||||
get => _currentSelectedSlotIndex;
|
||||
set
|
||||
{
|
||||
_currentSelectedSlotIndex = value;
|
||||
EmitSignalSlotIndexChanged(_currentSelectedSlotIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public InventoryInstance playerInventory;
|
||||
public InventoryInstance playerInventory = new InventoryInstance();
|
||||
|
||||
private int _currentSelectedSlotIndex = 0;
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
@@ -16,7 +30,6 @@ public partial class InventoryManager : Node
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
playerInventory = new InventoryInstance();
|
||||
playerInventory.SlotAmount = 37;
|
||||
}
|
||||
|
||||
@@ -68,4 +81,14 @@ public partial class InventoryManager : Node
|
||||
{
|
||||
return playerInventory.AddItem(itemInstance);
|
||||
}
|
||||
}
|
||||
|
||||
public InventorySlot GetCurrentSelectedSlot()
|
||||
{
|
||||
if (CurrentSelectedSlotIndex < 0 || CurrentSelectedSlotIndex > 8)
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(CurrentSelectedSlotIndex),
|
||||
"currentInventoryBarIndex must be between 0 and 8 (inclusively)");
|
||||
|
||||
return playerInventory.Slots[CurrentSelectedSlotIndex];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user