🐛 fixed never more than 10 fields bug
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Babushka.scripts.CSharp.Low_Code.Variables;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
@@ -17,7 +18,7 @@ public partial class FarmingControls2D : Node2D
|
||||
|
||||
private int _toolId = -1;
|
||||
private bool _wateringCanFilled = false;
|
||||
|
||||
private bool _canCreateFields = false;
|
||||
|
||||
[Signal] public delegate void WateringFieldEventHandler();
|
||||
|
||||
@@ -60,14 +61,12 @@ public partial class FarmingControls2D : Node2D
|
||||
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)
|
||||
if (_canCreateFields && _toolId == 0)
|
||||
{
|
||||
GD.Print("Trying to create a field.");
|
||||
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
||||
MakeField(adjustedPosition);
|
||||
}
|
||||
@@ -82,43 +81,19 @@ public partial class FarmingControls2D : Node2D
|
||||
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)
|
||||
private Vector2I AdjustValue(Vector2I input, Vector2I step)
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
return input.Snapped(step);
|
||||
}
|
||||
|
||||
public void CanCreateFields()
|
||||
{
|
||||
_canCreateFields = true;
|
||||
}
|
||||
|
||||
if (!inputEvent.IsActionPressed("click"))
|
||||
return;
|
||||
|
||||
if (inputEvent is InputEventMouseButton inputEventMouseButton)
|
||||
{
|
||||
if (!inputEventMouseButton.Pressed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_toolId == 0)
|
||||
{
|
||||
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
||||
MakeField(adjustedPosition);
|
||||
}
|
||||
*/
|
||||
public void CannotCreateFields()
|
||||
{
|
||||
_canCreateFields = false;
|
||||
}
|
||||
|
||||
#region WATERING
|
||||
@@ -135,14 +110,12 @@ public partial class FarmingControls2D : Node2D
|
||||
FieldBehaviour2D? field = FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), fieldPosition);
|
||||
if (field == null || field.FieldState == FieldState.Watered)
|
||||
{
|
||||
GD.Print($"The field at position {fieldPosition} is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
field.Water();
|
||||
_wateringParticles.GlobalPosition = new Vector2(field.GlobalPosition.X, field.GlobalPosition.Y + _wateringCanParticlesVerticalOffset);
|
||||
WateringCanState.Water();
|
||||
GD.Print($"Watered the field at {fieldPosition}.");
|
||||
EmitSignal(SignalName.WateringField);
|
||||
}
|
||||
|
||||
@@ -163,20 +136,20 @@ public partial class FarmingControls2D : Node2D
|
||||
// add dictionary entry for the field
|
||||
Array<Node> fields = field2d.FindChildren("*", nameof(FieldBehaviour2D));
|
||||
if (fields.Count > 0)
|
||||
{
|
||||
FieldService.Instance.TryAddEntry(_sceneKeyProvider.Payload.AsString(), fieldPosition, fields[0] as FieldBehaviour2D);
|
||||
}
|
||||
|
||||
// reposition and reparent the instance
|
||||
field2d.Position = new Vector2(fieldPosition.X, fieldPosition.Y);;
|
||||
field2d.Position = new Vector2(fieldPosition.X, fieldPosition.Y);
|
||||
|
||||
FieldService.Instance.AddChild(fieldInstance);
|
||||
EmitSignal(SignalName.FieldCreated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2I AdjustValue(Vector2I input, Vector2I step)
|
||||
{
|
||||
return input.Snapped(step);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user