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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +1,60 @@
|
||||
using System.Diagnostics;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
public enum FieldState
|
||||
namespace Babushka.scripts.CSharp.Common.Farming
|
||||
{
|
||||
Empty = 0,
|
||||
Tilled = 1,
|
||||
Planted = 2,
|
||||
Watered = 3,
|
||||
NotFound = 99
|
||||
public enum FieldState
|
||||
{
|
||||
Empty = 0,
|
||||
Tilled = 1,
|
||||
Planted = 2,
|
||||
Watered = 3,
|
||||
NotFound = 99
|
||||
}
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FieldBehaviour : Sprite3D
|
||||
{
|
||||
[Export] private Texture2D Tilled;
|
||||
[Export] private Texture2D Watered;
|
||||
[Export] public FieldState FieldState = FieldState.Empty;
|
||||
|
||||
public Vector2 FieldPosition;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Texture = Tilled;
|
||||
base._Ready();
|
||||
}
|
||||
|
||||
public void Water()
|
||||
{
|
||||
FieldState = FieldState.Watered;
|
||||
Texture = Watered;
|
||||
Debug.Print($"Current Texture: {Texture.ResourceName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the player enters the field'S interaction area and presses <E>.
|
||||
/// </summary>
|
||||
public void Farm()
|
||||
{
|
||||
switch (FieldState)
|
||||
{
|
||||
case FieldState.Empty:
|
||||
Texture = Tilled;
|
||||
FieldState = FieldState.Tilled;
|
||||
break;
|
||||
case FieldState.Tilled:
|
||||
FieldState = FieldState.Planted;
|
||||
break;
|
||||
case FieldState.Planted:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial class FieldBehaviour : Sprite3D
|
||||
{
|
||||
[Export] private Texture2D Tilled;
|
||||
[Export] private Texture2D Watered;
|
||||
[Export] public FieldState FieldState = FieldState.Empty;
|
||||
|
||||
public Vector2 FieldPosition;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Texture = Tilled;
|
||||
base._Ready();
|
||||
}
|
||||
|
||||
public void Water()
|
||||
{
|
||||
FieldState = FieldState.Watered;
|
||||
Texture = Watered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the player enters the field'S interaction area and presses <E>.
|
||||
/// </summary>
|
||||
public void Farm()
|
||||
{
|
||||
switch (FieldState)
|
||||
{
|
||||
case FieldState.Empty:
|
||||
Texture = Tilled;
|
||||
FieldState = FieldState.Tilled;
|
||||
break;
|
||||
case FieldState.Tilled:
|
||||
FieldState = FieldState.Planted;
|
||||
break;
|
||||
case FieldState.Planted:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,9 @@ public partial class FieldService : Node3D
|
||||
if (!fields.ContainsKey(key))
|
||||
{
|
||||
fields.Add(key, field);
|
||||
Debug.Print("Added entry: " + key);
|
||||
return true;
|
||||
}
|
||||
Debug.Print("Added entry: " + key);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -25,8 +25,12 @@ public partial class FieldService : Node3D
|
||||
public FieldBehaviour Get(Vector2I key)
|
||||
{
|
||||
Debug.Print($"Getting field at {key}. Found: {fields.ContainsKey(key)}.");
|
||||
if(fields.TryGetValue(key, out FieldBehaviour field))
|
||||
if (fields.TryGetValue(key, out FieldBehaviour field))
|
||||
{
|
||||
Debug.Print($"Getting field at {key}, field: {field.Name}.");
|
||||
return field;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
uid://b7vlkecrn0t5c
|
||||
Reference in New Issue
Block a user