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.
87 lines
2.3 KiB
87 lines
2.3 KiB
using Babushka.scripts.CSharp.Common.CharacterControls;
|
|
using Babushka.scripts.CSharp.Common.Inventory;
|
|
using Godot;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Farming;
|
|
|
|
public partial class VesnaBehaviour2D : Node
|
|
{
|
|
[ExportGroup("Farming")]
|
|
[Export] private FieldService2D _fieldParent;
|
|
[Export] private FarmingControls2D _farmingControls;
|
|
[Export] private Player2D _player2d;
|
|
[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
|
|
|
|
public void ActivateTool(int toolId)
|
|
{
|
|
bool activated = _farmingControls.TryActivateTool(toolId);
|
|
EmitSignal(SignalName.PickedUpTool, activated, toolId);
|
|
}
|
|
|
|
public void TryFillWateringCan(int toolId)
|
|
{
|
|
if (toolId == 1)
|
|
{
|
|
_farmingControls.FillWateringCan(true);
|
|
_player2d.PlayWateringCanFillupAnimation();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Enables the character movement in the Player2D script.
|
|
/// </summary>
|
|
public void EnableMovement()
|
|
{
|
|
_player2d.InputEnabled = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Disables the character movement in the Player2D script.
|
|
/// </summary>
|
|
public void DisableMovement()
|
|
{
|
|
_player2d.InputEnabled = false;
|
|
}
|
|
} |