|
|
|
|
@ -13,6 +13,7 @@ public partial class FarmingControls2D : Node2D
|
|
|
|
|
[Export] private Camera2D _camera;
|
|
|
|
|
[Export] private CpuParticles2D _wateringParticles;
|
|
|
|
|
[Export] private float _wateringCanParticlesVerticalOffset = 50f;
|
|
|
|
|
[Export] private Vector2I _fieldOffsetVector = new Vector2I(735, 651);
|
|
|
|
|
|
|
|
|
|
private int _toolId = -1;
|
|
|
|
|
private bool _wateringCanFilled = false;
|
|
|
|
|
@ -20,6 +21,8 @@ public partial class FarmingControls2D : Node2D
|
|
|
|
|
|
|
|
|
|
[Signal] public delegate void WateringFieldEventHandler();
|
|
|
|
|
|
|
|
|
|
[Signal] public delegate void FieldCreatedEventHandler();
|
|
|
|
|
|
|
|
|
|
#region Tools
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
@ -52,13 +55,22 @@ public partial class FarmingControls2D : Node2D
|
|
|
|
|
|
|
|
|
|
public override void _Input(InputEvent @event)
|
|
|
|
|
{
|
|
|
|
|
if (@event.IsActionPressed("click")
|
|
|
|
|
&& _toolId == WateringCanState.WATERING_CAN_ID
|
|
|
|
|
&& WateringCanState.GetFillState() > 0)
|
|
|
|
|
if (@event.IsActionPressed("click"))
|
|
|
|
|
{
|
|
|
|
|
GD.Print("Trying to use the watering can.");
|
|
|
|
|
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
|
|
|
|
WaterTheField(adjustedPosition);
|
|
|
|
|
if (_toolId == WateringCanState.WATERING_CAN_ID
|
|
|
|
|
&& WateringCanState.GetFillState() > 0)
|
|
|
|
|
{
|
|
|
|
|
GD.Print("Trying to use the watering can.");
|
|
|
|
|
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
|
|
|
|
WaterTheField(adjustedPosition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_toolId == 0)
|
|
|
|
|
{
|
|
|
|
|
GD.Print("Trying to create a field.");
|
|
|
|
|
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
|
|
|
|
MakeField(adjustedPosition);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -66,7 +78,7 @@ public partial class FarmingControls2D : Node2D
|
|
|
|
|
{
|
|
|
|
|
Vector2 mousePosition = _camera.GetGlobalMousePosition();
|
|
|
|
|
Vector2I mousePositionInteger = (Vector2I) mousePosition;
|
|
|
|
|
Vector2I adjustedPosition = AdjustValue(mousePositionInteger, new Vector2I(735, 651));
|
|
|
|
|
Vector2I adjustedPosition = AdjustValue(mousePositionInteger, _fieldOffsetVector);
|
|
|
|
|
return adjustedPosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -78,6 +90,9 @@ public partial class FarmingControls2D : Node2D
|
|
|
|
|
/// <param name="shapeIndex"></param>
|
|
|
|
|
public void InputEventPressedOn(Node node, InputEvent inputEvent, int shapeIndex)
|
|
|
|
|
{
|
|
|
|
|
// Bug is here: Whenever I use the collider to limit the farming area, Godot crashes after 10 fields.
|
|
|
|
|
/*
|
|
|
|
|
GD.Print($"Input event registered on {node.Name} as {inputEvent.GetType().Name}.");
|
|
|
|
|
if (!inputEvent.IsPressed())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
@ -103,6 +118,7 @@ public partial class FarmingControls2D : Node2D
|
|
|
|
|
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
|
|
|
|
MakeField(adjustedPosition);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region WATERING
|
|
|
|
|
@ -152,18 +168,11 @@ public partial class FarmingControls2D : Node2D
|
|
|
|
|
// reposition and reparent the instance
|
|
|
|
|
field2d.Position = new Vector2(fieldPosition.X, fieldPosition.Y);;
|
|
|
|
|
FieldService.Instance.AddChild(fieldInstance);
|
|
|
|
|
EmitSignal(SignalName.FieldCreated);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int AdjustValue(float value)
|
|
|
|
|
{
|
|
|
|
|
float adjustedValue = value / 500;
|
|
|
|
|
adjustedValue = Mathf.RoundToInt(adjustedValue);
|
|
|
|
|
adjustedValue *= 500;
|
|
|
|
|
return (int)adjustedValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Vector2I AdjustValue(Vector2I input, Vector2I step)
|
|
|
|
|
{
|
|
|
|
|
return input.Snapped(step);
|
|
|
|
|
|