Files
Babushka/scripts/CSharp/Common/Farming/FarmingControls2D.cs
T

76 lines
1.9 KiB
C#
Raw Normal View History

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
{
[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
[Export] private float _wateringCanParticlesVerticalOffset = 50f;
[Export] private Vector2I _fieldOffsetVector = new Vector2I(735, 651);
[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-05-12 00:16:13 +02:00
#region Tools
/// <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
{
bool activate;
//if our hands are empty, activate
if (toolId == -1)
{
activate = false;
}
else
{
activate = true;
}
_toolId = activate ? toolId : -1;
WateringCanState.SetActive(_toolId == WateringCanState.WATERING_CAN_ID);
return activate;
2025-05-12 00:16:13 +02:00
}
#endregion
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();
Vector2I mousePositionInteger = (Vector2I) mousePosition;
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
#region WATERING
2025-07-05 17:34:03 +02:00
public void FillWateringCan()
2025-05-18 11:44:33 +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
#endregion
2025-05-12 00:16:13 +02:00
}