diff --git a/scripts/CSharp/Common/Farming/FarmingControls2D.cs b/scripts/CSharp/Common/Farming/FarmingControls2D.cs index f7b1952..ee9dc3e 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls2D.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls2D.cs @@ -67,8 +67,10 @@ public partial class FarmingControls2D : Node2D public override void _Input(InputEvent @event) { Vector2 mousePosition = _camera.GetGlobalMousePosition(); - - Vector2I adjustedPosition = new Vector2I(AdjustValue(mousePosition.X), AdjustValue(mousePosition.Y)); + Vector2I mousePositionInteger = (Vector2I) mousePosition; + GD.Print(mousePosition); + Vector2I adjustedPosition = AdjustValue(mousePositionInteger, new Vector2I(735, 651)); + GD.Print(adjustedPosition); if (@event.IsActionPressed("click") && _toolId == 0) { @@ -94,15 +96,11 @@ public partial class FarmingControls2D : Node2D { if(FieldParent == null || _fieldPrefab == null) return; - - bool fieldAllowed = FieldParent.FieldAllowed(); - GD.Print($"Field allowed at {fieldPosition}: {fieldAllowed}"); + // only try to instantiate a field if you're in the allowed area - if (!fieldAllowed) + if (!FieldParent.FieldAllowed()) return; - - // only instantiate a field if there isn't one already. if(FieldParent.Get(fieldPosition) == null) { @@ -123,6 +121,14 @@ public partial class FarmingControls2D : Node2D private int AdjustValue(float value) { - return (int) Mathf.Floor(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); } } \ No newline at end of file