🐛 field creation at the same spot no longer possible, also watering works now.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Babushka.scripts.CSharp.Low_Code.Variables;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
@@ -6,14 +7,13 @@ namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
[GlobalClass]
|
||||
public partial class FarmingControls2D : Node2D
|
||||
{
|
||||
[Export] private PackedScene _fieldPrefab;
|
||||
[Export] private VariableResource _sceneKeyProvider;
|
||||
[Export] private PackedScene? _fieldPrefab = null!;
|
||||
[Export] private Node2D _movingPlayer;
|
||||
[Export] private Camera2D _camera;
|
||||
[Export] private CpuParticles2D _wateringParticles;
|
||||
[Export] private float _wateringCanParticlesVerticalOffset = 50f;
|
||||
|
||||
public FieldService2D FieldService;
|
||||
|
||||
private int _toolId = -1;
|
||||
private bool _wateringCanFilled = false;
|
||||
|
||||
@@ -116,7 +116,7 @@ public partial class FarmingControls2D : Node2D
|
||||
|
||||
private void WaterTheField(Vector2I fieldPosition)
|
||||
{
|
||||
FieldBehaviour2D field = FieldService.Get(fieldPosition);
|
||||
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!");
|
||||
@@ -135,25 +135,30 @@ public partial class FarmingControls2D : Node2D
|
||||
#region FIELD CREATION
|
||||
private void MakeField(Vector2I fieldPosition)
|
||||
{
|
||||
if(FieldService == null || _fieldPrefab == null)
|
||||
if(_fieldPrefab == null)
|
||||
return;
|
||||
|
||||
// only instantiate a field if there isn't one already.
|
||||
if(FieldService.Get(fieldPosition) == null)
|
||||
if(FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), fieldPosition) == null)
|
||||
{
|
||||
GD.Print($"FarmingControls: Creating a field at {fieldPosition}");
|
||||
Node fieldInstance = _fieldPrefab.Instantiate();
|
||||
if (fieldInstance is Node2D field2d)
|
||||
{
|
||||
// add dictionary entry for the field
|
||||
Array<Node> fields = field2d.FindChildren("*", nameof(FieldBehaviour2D));
|
||||
if (fields.Count > 0)
|
||||
FieldService.TryAddEntry(fieldPosition, fields[0] as FieldBehaviour2D);
|
||||
FieldService.Instance.TryAddEntry(_sceneKeyProvider.Payload.AsString(), fieldPosition, fields[0] as FieldBehaviour2D);
|
||||
|
||||
// reposition and reparent the instance
|
||||
field2d.Position = new Vector2(fieldPosition.X, fieldPosition.Y);;
|
||||
FieldService.AddChild(fieldInstance);
|
||||
FieldService.Instance.AddChild(fieldInstance);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.Print($"FarmingControls: Could not create a field at {fieldPosition}.");
|
||||
}
|
||||
}
|
||||
|
||||
private int AdjustValue(float value)
|
||||
|
||||
Reference in New Issue
Block a user