|
|
|
@ -67,8 +67,10 @@ public partial class FarmingControls2D : Node2D
|
|
|
|
public override void _Input(InputEvent @event)
|
|
|
|
public override void _Input(InputEvent @event)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Vector2 mousePosition = _camera.GetGlobalMousePosition();
|
|
|
|
Vector2 mousePosition = _camera.GetGlobalMousePosition();
|
|
|
|
|
|
|
|
Vector2I mousePositionInteger = (Vector2I) mousePosition;
|
|
|
|
Vector2I adjustedPosition = new Vector2I(AdjustValue(mousePosition.X), AdjustValue(mousePosition.Y));
|
|
|
|
GD.Print(mousePosition);
|
|
|
|
|
|
|
|
Vector2I adjustedPosition = AdjustValue(mousePositionInteger, new Vector2I(735, 651));
|
|
|
|
|
|
|
|
GD.Print(adjustedPosition);
|
|
|
|
|
|
|
|
|
|
|
|
if (@event.IsActionPressed("click") && _toolId == 0)
|
|
|
|
if (@event.IsActionPressed("click") && _toolId == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -94,15 +96,11 @@ public partial class FarmingControls2D : Node2D
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(FieldParent == null || _fieldPrefab == null)
|
|
|
|
if(FieldParent == null || _fieldPrefab == null)
|
|
|
|
return;
|
|
|
|
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
|
|
|
|
// only try to instantiate a field if you're in the allowed area
|
|
|
|
if (!fieldAllowed)
|
|
|
|
if (!FieldParent.FieldAllowed())
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// only instantiate a field if there isn't one already.
|
|
|
|
// only instantiate a field if there isn't one already.
|
|
|
|
if(FieldParent.Get(fieldPosition) == null)
|
|
|
|
if(FieldParent.Get(fieldPosition) == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -123,6 +121,14 @@ public partial class FarmingControls2D : Node2D
|
|
|
|
|
|
|
|
|
|
|
|
private int AdjustValue(float value)
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|