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.
76 lines
1.9 KiB
76 lines
1.9 KiB
using Babushka.scripts.CSharp.Low_Code.Variables;
|
|
using Godot;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Farming;
|
|
|
|
[GlobalClass]
|
|
public partial class FarmingControls2D : Node2D
|
|
{
|
|
[Export] private VariableResource _sceneKeyProvider;
|
|
[Export] private Node2D _movingPlayer;
|
|
[Export] private Camera2D _camera;
|
|
|
|
[Export] private float _wateringCanParticlesVerticalOffset = 50f;
|
|
[Export] private Vector2I _fieldOffsetVector = new Vector2I(735, 651);
|
|
[Export] private Node2D _fieldParent;
|
|
|
|
private int _toolId = -1;
|
|
private bool _wateringCanFilled = false;
|
|
|
|
|
|
#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)
|
|
{
|
|
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;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
private Vector2I GetAdjustedMousePosition()
|
|
{
|
|
Vector2 mousePosition = _camera.GetGlobalMousePosition();
|
|
Vector2I mousePositionInteger = (Vector2I) mousePosition;
|
|
Vector2I adjustedPosition = AdjustValue(mousePositionInteger, _fieldOffsetVector);
|
|
return adjustedPosition;
|
|
}
|
|
|
|
private Vector2I AdjustValue(Vector2I input, Vector2I step)
|
|
{
|
|
return input.Snapped(step);
|
|
}
|
|
|
|
#region WATERING
|
|
public void FillWateringCan()
|
|
{
|
|
if (_toolId == WateringCanState.WATERING_CAN_ID)
|
|
{
|
|
WateringCanState.Fill();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
} |