2025-11-05 16:48:45 +01:00
|
|
|
using Babushka.scripts.CSharp.Low_Code.Variables;
|
2025-05-12 00:16:13 +02:00
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Farming;
|
|
|
|
|
|
|
|
|
|
[GlobalClass]
|
|
|
|
|
public partial class FarmingControls2D : Node2D
|
|
|
|
|
{
|
2025-11-05 16:48:45 +01:00
|
|
|
[Export] private VariableResource _sceneKeyProvider;
|
2025-05-12 00:16:13 +02:00
|
|
|
[Export] private Node2D _movingPlayer;
|
|
|
|
|
[Export] private Camera2D _camera;
|
2025-11-11 15:51:15 +01:00
|
|
|
|
2025-07-05 22:54:52 +02:00
|
|
|
[Export] private float _wateringCanParticlesVerticalOffset = 50f;
|
2025-11-05 19:25:46 +01:00
|
|
|
[Export] private Vector2I _fieldOffsetVector = new Vector2I(735, 651);
|
2025-11-11 12:15:30 +01:00
|
|
|
[Export] private Node2D _fieldParent;
|
2025-05-12 00:16:13 +02:00
|
|
|
|
2025-05-16 23:16:27 +02:00
|
|
|
private int _toolId = -1;
|
2025-05-18 11:44:33 +02:00
|
|
|
private bool _wateringCanFilled = false;
|
2025-05-12 00:16:13 +02:00
|
|
|
|
2025-11-05 19:25:46 +01:00
|
|
|
|
2025-05-12 00:16:13 +02:00
|
|
|
#region Tools
|
2025-05-17 16:38:32 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// If no tool has been set, then set the current tool to the incoming tool id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="toolId">The id of the tool to activate if possible</param>
|
|
|
|
|
/// <returns>If the tool in question was activated.</returns>
|
|
|
|
|
public bool TryActivateTool(int toolId)
|
2025-05-12 00:16:13 +02:00
|
|
|
{
|
2025-05-17 16:38:32 +02:00
|
|
|
bool activate;
|
|
|
|
|
|
|
|
|
|
//if our hands are empty, activate
|
2025-05-21 00:13:58 +02:00
|
|
|
if (toolId == -1)
|
2025-05-17 16:38:32 +02:00
|
|
|
{
|
2025-05-21 00:13:58 +02:00
|
|
|
activate = false;
|
2025-05-17 16:38:32 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-05-21 00:13:58 +02:00
|
|
|
activate = true;
|
2025-05-17 16:38:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_toolId = activate ? toolId : -1;
|
2025-07-05 22:54:52 +02:00
|
|
|
|
|
|
|
|
WateringCanState.SetActive(_toolId == WateringCanState.WATERING_CAN_ID);
|
|
|
|
|
|
2025-05-17 16:38:32 +02:00
|
|
|
return activate;
|
2025-05-12 00:16:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2025-11-18 17:17:42 +01:00
|
|
|
|
2025-07-06 10:57:38 +02:00
|
|
|
|
|
|
|
|
private Vector2I GetAdjustedMousePosition()
|
2025-05-12 00:16:13 +02:00
|
|
|
{
|
2025-05-17 17:40:15 +02:00
|
|
|
Vector2 mousePosition = _camera.GetGlobalMousePosition();
|
2025-05-17 18:23:35 +02:00
|
|
|
Vector2I mousePositionInteger = (Vector2I) mousePosition;
|
2025-11-05 19:25:46 +01:00
|
|
|
Vector2I adjustedPosition = AdjustValue(mousePositionInteger, _fieldOffsetVector);
|
2025-07-06 10:57:38 +02:00
|
|
|
return adjustedPosition;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 18:18:05 +01:00
|
|
|
private Vector2I AdjustValue(Vector2I input, Vector2I step)
|
2025-07-06 10:57:38 +02:00
|
|
|
{
|
2025-11-07 18:18:05 +01:00
|
|
|
return input.Snapped(step);
|
|
|
|
|
}
|
2025-05-18 11:44:33 +02:00
|
|
|
|
2025-07-05 22:54:52 +02:00
|
|
|
#region WATERING
|
2025-07-05 17:34:03 +02:00
|
|
|
public void FillWateringCan()
|
2025-05-18 11:44:33 +02:00
|
|
|
{
|
2025-07-05 22:54:52 +02:00
|
|
|
if (_toolId == WateringCanState.WATERING_CAN_ID)
|
2025-05-18 11:44:33 +02:00
|
|
|
{
|
2025-07-05 17:34:03 +02:00
|
|
|
WateringCanState.Fill();
|
2025-05-18 11:44:33 +02:00
|
|
|
}
|
|
|
|
|
}
|
2025-05-12 00:16:13 +02:00
|
|
|
|
2025-07-05 22:54:52 +02:00
|
|
|
#endregion
|
|
|
|
|
|
2025-05-12 00:16:13 +02:00
|
|
|
}
|