Reworked farming tools pickup animations
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
@@ -9,6 +10,8 @@ public partial class Player2D : CharacterBody2D
|
||||
[Export] private float _speed = 100f;
|
||||
[Export] private AnimatedSprite2D _sprite;
|
||||
[Export] private SceneTree.GroupCallFlags _fieldFlags;
|
||||
[Export] private ItemResource _hoe;
|
||||
[Export] private ItemResource _wateringCan;
|
||||
|
||||
// -1 means no tool.
|
||||
private int _toolID = -1;
|
||||
@@ -18,7 +21,48 @@ public partial class Player2D : CharacterBody2D
|
||||
private bool _pickupAnimationInProgress;
|
||||
private bool _farmingAnimationInProgress;
|
||||
private Vector2 _lastDirection = Vector2.Zero;
|
||||
|
||||
private InventoryManager _inventoryManager;
|
||||
private InventoryInstance _inventoryInstance;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_inventoryManager = InventoryManager.Instance;
|
||||
_inventoryInstance = _inventoryManager.playerInventory;
|
||||
_inventoryManager.SlotIndexChanged += HandleInventorySelectedSlotIndexChanged;
|
||||
_inventoryInstance.InventoryContentsChanged += HandleNewItemInInventory;
|
||||
}
|
||||
|
||||
private void HandleNewItemInInventory()
|
||||
{
|
||||
// for future Kathi: this does not, in fact, check if an item has been added only, but triggers on every content change!
|
||||
PlayPickUpAnimation();
|
||||
}
|
||||
|
||||
private void HandleInventorySelectedSlotIndexChanged(int newIndex)
|
||||
{
|
||||
InventorySlot currentSlot = InventoryManager.Instance.GetCurrentSelectedSlot();
|
||||
ItemInstance? currentItem = currentSlot.itemInstance;
|
||||
|
||||
if (currentItem == null)
|
||||
return;
|
||||
|
||||
if (currentItem.blueprint == _hoe)
|
||||
{
|
||||
ActivateTool(true, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentItem.blueprint == _wateringCan)
|
||||
{
|
||||
ActivateTool(true, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
ActivateTool(false, 0);
|
||||
ActivateTool(false, 1);
|
||||
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
anyActionPressed = false;
|
||||
@@ -99,7 +143,6 @@ public partial class Player2D : CharacterBody2D
|
||||
if (success)
|
||||
{
|
||||
_toolID = id;
|
||||
PlayPickUpAnimation();
|
||||
}
|
||||
else _toolID = -1;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ public partial class InventoryManager : Node
|
||||
[Signal]
|
||||
public delegate void SlotIndexChangedEventHandler(int newIndex);
|
||||
|
||||
|
||||
public static InventoryManager Instance { get; private set; } = null!;
|
||||
public int CurrentSelectedSlotIndex
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user