State after inventory clip (farming mechanic still WIP)
This commit is contained in:
@@ -10,8 +10,6 @@ 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;
|
||||
@@ -22,14 +20,10 @@ public partial class Player2D : CharacterBody2D
|
||||
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;
|
||||
InventoryManager.Instance.playerInventory.InventoryContentsChanged += HandleNewItemInInventory;
|
||||
}
|
||||
|
||||
private void HandleNewItemInInventory()
|
||||
@@ -37,31 +31,7 @@ public partial class Player2D : CharacterBody2D
|
||||
// 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)
|
||||
{
|
||||
|
||||
@@ -31,21 +31,13 @@ public partial class FarmingControls2D : Node2D
|
||||
bool activate;
|
||||
|
||||
//if our hands are empty, activate
|
||||
if (_toolId == -1)
|
||||
if (toolId == -1)
|
||||
{
|
||||
activate = true;
|
||||
activate = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if we're already carrying a tool, deactivate or fail return
|
||||
if (_toolId == toolId)
|
||||
{
|
||||
activate = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
activate = true;
|
||||
}
|
||||
|
||||
_toolId = activate ? toolId : -1;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
@@ -7,12 +8,44 @@ public partial class VesnaBehaviour2D : Node
|
||||
[ExportGroup("Farming")]
|
||||
[Export] private FieldService2D _fieldParent;
|
||||
[Export] private FarmingControls2D _farmingControls;
|
||||
[Export] private ItemResource _hoe;
|
||||
[Export] private ItemResource _wateringCan;
|
||||
|
||||
[Signal] public delegate void PickedUpToolEventHandler(bool success, int toolId);
|
||||
|
||||
private InventoryManager _inventoryManager;
|
||||
private InventoryInstance _inventoryInstance;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_farmingControls.FieldService = _fieldParent;
|
||||
_inventoryManager = InventoryManager.Instance;
|
||||
_inventoryInstance = _inventoryManager.playerInventory;
|
||||
_inventoryManager.SlotIndexChanged += HandleInventorySelectedSlotIndexChanged;
|
||||
}
|
||||
|
||||
private void HandleInventorySelectedSlotIndexChanged(int newIndex)
|
||||
{
|
||||
InventorySlot currentSlot = InventoryManager.Instance.GetCurrentSelectedSlot();
|
||||
ItemInstance? currentItem = currentSlot.itemInstance;
|
||||
|
||||
if (currentItem == null)
|
||||
return;
|
||||
|
||||
if (currentItem.blueprint == _hoe)
|
||||
{
|
||||
ActivateTool(0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentItem.blueprint == _wateringCan)
|
||||
{
|
||||
ActivateTool(1);
|
||||
return;
|
||||
}
|
||||
|
||||
ActivateTool(-1);
|
||||
|
||||
}
|
||||
|
||||
#region Farming
|
||||
|
||||
Reference in New Issue
Block a user