Basic watering functionality implemented
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
@@ -55,7 +58,13 @@ public partial class FarmingControls : Node3D
|
||||
|
||||
private void WaterTheField()
|
||||
{
|
||||
Vector2I currentPos = new Vector2I(AdjustValue(_movingPlayer.GlobalPosition.X), AdjustValue(_movingPlayer.GlobalPosition.Z));
|
||||
FieldBehaviour field = FieldParent.Get(currentPos);
|
||||
if (field == null)
|
||||
return;
|
||||
|
||||
field.Water();
|
||||
Debug.Print("Watered the field.");
|
||||
}
|
||||
|
||||
private void MakeField()
|
||||
@@ -75,7 +84,9 @@ public partial class FarmingControls : Node3D
|
||||
if (fieldInstance is Node3D field3d)
|
||||
{
|
||||
// add dictionary entry for the field
|
||||
FieldParent.TryAddEntry(intPosition, field3d as FieldBehaviour);
|
||||
Array<Node> fields = field3d.FindChildren("*", nameof(FieldBehaviour));
|
||||
if (fields.Count > 0)
|
||||
FieldParent.TryAddEntry(intPosition, fields[0] as FieldBehaviour);
|
||||
|
||||
// reposition and reparent the instance
|
||||
field3d.Position = playerPos;
|
||||
@@ -84,9 +95,9 @@ public partial class FarmingControls : Node3D
|
||||
}
|
||||
}
|
||||
|
||||
private float AdjustValue(float value)
|
||||
private int AdjustValue(float value)
|
||||
{
|
||||
return Mathf.Floor(value);
|
||||
return (int) Mathf.Floor(value);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user