Moved the player inventory and selected slot to VesnaEntity
This commit is contained in:
@@ -3,6 +3,8 @@ using Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
using Babushka.scripts.CSharp.Common.DayAndNight;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.Common.Savegame;
|
||||
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||
using Babushka.scripts.CSharp.GameEntity.Management;
|
||||
using Babushka.scripts.CSharp.Low_Code.Events;
|
||||
using Babushka.scripts.CSharp.Low_Code.Variables;
|
||||
using Godot;
|
||||
@@ -178,8 +180,8 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
||||
private bool TryPlant()
|
||||
{
|
||||
bool success = false;
|
||||
int currentSlotIndex = InventoryManager.Instance.CurrentSelectedSlotIndex;
|
||||
ItemInstance? item = InventoryManager.Instance.playerInventory.Slots[currentSlotIndex].itemInstance;
|
||||
int currentSlotIndex = EntityManager.Instance.GetUniqueEntity<VesnaEntity>().CurrentSelectedSlotIndex;
|
||||
ItemInstance? item = EntityManager.Instance.GetUniqueEntity<VesnaEntity>().inventory.Slots[currentSlotIndex].itemInstance;
|
||||
|
||||
if (item == null || PlantingPlaceholder.GetChildCount() > 0 || item.amount == 0)
|
||||
return success;
|
||||
@@ -189,7 +191,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
||||
if (!string.IsNullOrEmpty(plantPrefabPath))
|
||||
{
|
||||
PlantPrefab(plantPrefabPath);
|
||||
InventoryManager.Instance.playerInventory.RemoveItem(currentSlotIndex);
|
||||
EntityManager.Instance.GetUniqueEntity<VesnaEntity>().inventory.RemoveItem(currentSlotIndex);
|
||||
success = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ using Babushka.scripts.CSharp.Common.Animation;
|
||||
using Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.Common.Services;
|
||||
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||
using Babushka.scripts.CSharp.GameEntity.Management;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
@@ -20,34 +22,32 @@ public partial class VesnaBehaviour2D : Node2D // EntityNode
|
||||
|
||||
[Signal] public delegate void InventorySelectionChangedEventHandler(int toolId);
|
||||
|
||||
private InventoryManager _inventoryManager;
|
||||
private InventoryInstance _inventoryInstance;
|
||||
//private InventoryManager _inventoryManager;
|
||||
private VesnaEntity _vesnaEntity;
|
||||
private InventoryInstance _playerInventory;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_inventoryManager = InventoryManager.Instance;
|
||||
_inventoryInstance = _inventoryManager.playerInventory;
|
||||
_inventoryManager.SlotIndexChanged += HandleInventorySelectedSlotIndexChanged;
|
||||
_vesnaEntity = EntityManager.Instance.GetUniqueEntity<VesnaEntity>();
|
||||
_playerInventory = _vesnaEntity.inventory;
|
||||
_vesnaEntity.SlotIndexChanged += HandleInventorySelectedSlotIndexChanged;
|
||||
_playerInventory.InventoryContentsChanged += UpdateToolInHand;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
_inventoryManager.SlotIndexChanged -= HandleInventorySelectedSlotIndexChanged;
|
||||
_vesnaEntity.SlotIndexChanged -= HandleInventorySelectedSlotIndexChanged;
|
||||
_playerInventory.InventoryContentsChanged -= UpdateToolInHand;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when picking up an item.
|
||||
/// Makes sure that item animations are also updated when they are occupying a currently empty spot.
|
||||
/// </summary>
|
||||
//public void HandlePickUp()
|
||||
//{
|
||||
// //Calls the same event handler as the inventory to ensure the currently selected item is updated in the animation.
|
||||
// HandleInventorySelectedSlotIndexChanged(0);
|
||||
//}
|
||||
|
||||
private void HandleInventorySelectedSlotIndexChanged(int newIndex = 0)
|
||||
private void HandleInventorySelectedSlotIndexChanged(int _ = 0)
|
||||
{
|
||||
InventorySlot currentSlot = InventoryManager.Instance.GetCurrentSelectedSlot();
|
||||
UpdateToolInHand();
|
||||
}
|
||||
|
||||
private void UpdateToolInHand()
|
||||
{
|
||||
InventorySlot currentSlot = _playerInventory.Slots[_vesnaEntity.CurrentSelectedSlotIndex];
|
||||
ItemInstance? currentItem = currentSlot.itemInstance;
|
||||
|
||||
int toolId = -1;
|
||||
|
||||
Reference in New Issue
Block a user