Implemented field creation and wateringcan fill up animation

This commit is contained in:
2025-05-24 21:47:25 +02:00
parent b917fb5fbd
commit a477f9ef4f
7 changed files with 40 additions and 121 deletions
@@ -8,7 +8,7 @@ public partial class InteractionArea2D : Node2D
[Export] private Label _label;
[Export] private SpriteSwitcher2D _sprites; // TODO: remove
[Export] private bool _showLabel = true;
[Export] private int _id; // TODO: remove
[Export] private int _id = -1; // TODO: remove
[Signal] public delegate void InteractedToolEventHandler(int id); // TODO: remove
[Signal] public delegate void InteractedEventHandler();
@@ -15,9 +15,7 @@ public partial class Player2D : CharacterBody2D
private int _toolID = -1;
private string _toolString;
private bool anyActionPressed;
private bool _wateringInProgress;
private bool _pickupAnimationInProgress;
private bool _farmingAnimationInProgress;
private bool _canHandleInput = true;
private Vector2 _lastDirection = Vector2.Zero;
private InventoryManager _inventoryManager;
@@ -36,8 +34,8 @@ public partial class Player2D : CharacterBody2D
public override void _Process(double delta)
{
anyActionPressed = false;
if (_pickupAnimationInProgress || _wateringInProgress || _farmingAnimationInProgress)
if (!_canHandleInput)
return;
if (Input.IsActionPressed("move_right"))
@@ -135,47 +133,46 @@ public partial class Player2D : CharacterBody2D
/// </summary>
public void PlayWateringAnimation()
{
if (_toolID == 1 && !_wateringInProgress)
if (_toolID == 1 && _canHandleInput)
{
_sprite.Animation = "diagonal wateringcan";
_sprite.Play();
_wateringInProgress = true;
Task.Run(DelayedWateringCanReset);
_canHandleInput = false;
Task.Run(DelayedInputHandlerReset);
}
}
private async Task DelayedWateringCanReset()
private async Task DelayedInputHandlerReset()
{
await Task.Delay(1000);
_wateringInProgress = false;
_canHandleInput = true;
}
public void PlayPickUpAnimation()
{
_sprite.Animation = "side pickup";
_sprite.Play();
_pickupAnimationInProgress = true;
Task.Run(DelayedPickUpReset);
}
private async Task DelayedPickUpReset()
{
await Task.Delay(1000);
_pickupAnimationInProgress = false;
_canHandleInput = false;
Task.Run(DelayedInputHandlerReset);
}
public void PlayFarmingAnimation()
{
_sprite.Animation = "diagonal farming";
_sprite.Play();
_farmingAnimationInProgress = true;
Task.Run(DelayedFarmingReset);
_canHandleInput = false;
Task.Run(DelayedInputHandlerReset);
}
private async Task DelayedFarmingReset()
public void PlayWateringCanFillupAnimation()
{
await Task.Delay(1000);
_farmingAnimationInProgress = false;
_sprite.Animation = "back interact";
_sprite.Play();
_canHandleInput = false;
_lastDirection = Vector2.Up;
Task.Run(DelayedInputHandlerReset);
}
}
@@ -1,3 +1,4 @@
using Babushka.scripts.CSharp.Common.CharacterControls;
using Babushka.scripts.CSharp.Common.Inventory;
using Godot;
@@ -8,6 +9,7 @@ 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;
@@ -61,6 +63,7 @@ public partial class VesnaBehaviour2D : Node
if (toolId == 1)
{
_farmingControls.FillWateringCan(true);
_player2d.PlayWateringCanFillupAnimation();
}
}
@@ -15,8 +15,11 @@ public partial class InventoryManager : Node
get => _currentSelectedSlotIndex;
set
{
_currentSelectedSlotIndex = value;
EmitSignalSlotIndexChanged(_currentSelectedSlotIndex);
if (value >= 0 && value <= 8)
{
_currentSelectedSlotIndex = value;
EmitSignalSlotIndexChanged(_currentSelectedSlotIndex);
}
}
}
@@ -23,8 +23,6 @@ public partial class ItemOnGround : Node3D
public void TryPickUp()
{
GD.Print("Trying to pick up item");
var result = InventoryManager.Instance.CollectItem(itemInstance.Clone());
if (result == InventoryActionResult.Success)
{