Fixed field creation bug

This commit is contained in:
2025-07-06 10:57:38 +02:00
parent a54003c658
commit 09ef508f49
5 changed files with 70 additions and 36 deletions
@@ -52,23 +52,64 @@ public partial class FarmingControls2D : Node2D
public override void _Input(InputEvent @event)
{
Vector2 mousePosition = _camera.GetGlobalMousePosition();
Vector2I mousePositionInteger = (Vector2I) mousePosition;
Vector2I adjustedPosition = AdjustValue(mousePositionInteger, new Vector2I(735, 651));
if (@event.IsActionPressed("click") && _toolId == 0)
{
MakeField(adjustedPosition);
}
if (@event.IsActionPressed("click")
&& _toolId == WateringCanState.WATERING_CAN_ID
&& WateringCanState.GetFillState() > 0)
{
Vector2I adjustedPosition = GetAdjustedMousePosition();
WaterTheField(adjustedPosition);
}
}
private Vector2I GetAdjustedMousePosition()
{
Vector2 mousePosition = _camera.GetGlobalMousePosition();
Vector2I mousePositionInteger = (Vector2I) mousePosition;
Vector2I adjustedPosition = AdjustValue(mousePositionInteger, new Vector2I(735, 651));
return adjustedPosition;
}
/// <summary>
/// Called by the allowed farming area collision area 2d.
/// </summary>
/// <param name="node"></param>
/// <param name="inputEvent"></param>
/// <param name="shapeIndex"></param>
public void InputEventPressedOn(Node node, InputEvent inputEvent, int shapeIndex)
{
if (!inputEvent.IsPressed())
{
GD.Print("Input Event is not pressed." );
return;
}
if (!inputEvent.IsActionPressed("click"))
return;
if (inputEvent is InputEventMouseButton inputEventMouseButton)
{
GD.Print("Input Event is InputEventMouseButton." );
if (!inputEventMouseButton.Pressed)
{
GD.Print("Input Event Mouse Button is not pressed." );
return;
}
}
else
{
GD.Print("Other Input Event registered." );
return;
}
GD.Print("Current tool id: " + _toolId );
if (_toolId == 0)
{
GD.Print("Trying to create field." );
Vector2I adjustedPosition = GetAdjustedMousePosition();
MakeField(adjustedPosition);
}
}
#region WATERING
public void FillWateringCan()
{
@@ -98,10 +139,6 @@ public partial class FarmingControls2D : Node2D
if(FieldService == null || _fieldPrefab == null)
return;
// only try to instantiate a field if you're in the allowed area
if (!FieldService.FieldAllowed())
return;
// only instantiate a field if there isn't one already.
if(FieldService.Get(fieldPosition) == null)
{