WIP reworking the field behaviour to implement watering. Broken state.
This commit is contained in:
@@ -6,8 +6,10 @@ namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
public partial class VesnaBehaviour : Node
|
||||
{
|
||||
[ExportGroup("Farming")]
|
||||
[Export] private Node _fieldParent;
|
||||
[Export] private FieldService _fieldParent;
|
||||
[Export] private FarmingControls _farmingControls;
|
||||
|
||||
[Signal] public delegate void ToolPickupEventHandler(bool success);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -18,7 +20,26 @@ public partial class VesnaBehaviour : Node
|
||||
|
||||
public void ActivateHoe(bool activate)
|
||||
{
|
||||
_farmingControls.ActivateHoe(activate);
|
||||
ActivateTool(activate, 0);
|
||||
}
|
||||
|
||||
public void ActivateWateringCan(bool activate)
|
||||
{
|
||||
ActivateTool(activate, 1);
|
||||
}
|
||||
|
||||
private void ActivateTool(bool activate , int toolId)
|
||||
{
|
||||
bool success = false;
|
||||
if (toolId == 0)
|
||||
{
|
||||
success = _farmingControls.ActivateHoe(activate);
|
||||
}
|
||||
else if (toolId == 1)
|
||||
{
|
||||
success = _farmingControls.ActivateWateringCan(activate);
|
||||
}
|
||||
EmitSignal(SignalName.ToolPickup, success);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -7,18 +7,38 @@ namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
public partial class FarmingControls : Node3D
|
||||
{
|
||||
[Export] private Sprite3D _hoeSprite;
|
||||
[Export] private Sprite3D _wateringCanSprite;
|
||||
[Export] private PackedScene _fieldPrefab;
|
||||
[Export] private Node3D _movingPlayer;
|
||||
|
||||
public Node FieldParent;
|
||||
public FieldService FieldParent;
|
||||
|
||||
private bool _hoeInHand = false;
|
||||
private Dictionary<KeyValuePair<int, int>, bool> _spawnedFields = new Dictionary<KeyValuePair<int, int>, bool>();
|
||||
public void ActivateHoe(bool activate)
|
||||
private bool _waterCanInHand = false;
|
||||
|
||||
#region Tools
|
||||
|
||||
public bool ActivateHoe(bool activate)
|
||||
{
|
||||
_hoeSprite.Visible = !activate;
|
||||
_hoeInHand = !activate;
|
||||
bool success = ActivateTool(activate, _hoeSprite);
|
||||
_hoeInHand = success;
|
||||
return success;
|
||||
}
|
||||
|
||||
public bool ActivateWateringCan(bool activate)
|
||||
{
|
||||
bool success = ActivateTool(activate, _wateringCanSprite);
|
||||
_waterCanInHand = success;
|
||||
return success;
|
||||
}
|
||||
|
||||
private bool ActivateTool(bool activate, Sprite3D tool)
|
||||
{
|
||||
tool.Visible = !activate;
|
||||
return !activate;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
@@ -26,6 +46,16 @@ public partial class FarmingControls : Node3D
|
||||
{
|
||||
MakeField();
|
||||
}
|
||||
|
||||
if (@event.IsActionPressed("click") && _waterCanInHand)
|
||||
{
|
||||
WaterTheField();
|
||||
}
|
||||
}
|
||||
|
||||
private void WaterTheField()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void MakeField()
|
||||
@@ -38,9 +68,13 @@ public partial class FarmingControls : Node3D
|
||||
if (fieldInstance is Node3D field3d)
|
||||
{
|
||||
Vector3 playerPos = _movingPlayer.GlobalPosition;
|
||||
field3d.Position = new Vector3(AdjustValue(playerPos.X), 0.1f, AdjustValue(playerPos.Z));
|
||||
playerPos = new Vector3(AdjustValue(playerPos.X), 0.1f, AdjustValue(playerPos.Z));
|
||||
field3d.Position = playerPos;
|
||||
Vector2I intPosition = new Vector2I((int) playerPos.X, (int) playerPos.Z);
|
||||
FieldParent.AddEntry(intPosition, FieldState.Tilled);
|
||||
}
|
||||
|
||||
|
||||
FieldParent.AddChild(fieldInstance);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,14 +13,22 @@ public enum FieldState
|
||||
public partial class FieldBehaviour : Sprite3D
|
||||
{
|
||||
[Export] private Texture2D Tilled;
|
||||
[Export] private Texture3D Watered;
|
||||
[Export] private Texture2D Watered;
|
||||
[Export] private 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>.
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FieldService : Node3D
|
||||
{
|
||||
[Export] private Dictionary<Vector2I, FieldState> fields = new Dictionary<Vector2I, FieldState>();
|
||||
|
||||
//Create
|
||||
|
||||
public void AddEntry(Vector2I key, FieldState state)
|
||||
{
|
||||
fields.Add(key, state);
|
||||
}
|
||||
|
||||
// Read
|
||||
|
||||
public FieldState Get(Vector2I key)
|
||||
{
|
||||
return fields[key];
|
||||
}
|
||||
|
||||
//Update
|
||||
public void UpdateEntry(Vector2I fieldPosition, FieldState state)
|
||||
{
|
||||
if (fields.ContainsKey(fieldPosition))
|
||||
{
|
||||
fields[fieldPosition] = state;
|
||||
}
|
||||
else
|
||||
{
|
||||
AddEntry(fieldPosition, state);
|
||||
}
|
||||
}
|
||||
|
||||
//Delete
|
||||
|
||||
public void RemoveEntry(Vector2I fieldPosition)
|
||||
{
|
||||
if (fields.ContainsKey(fieldPosition))
|
||||
{
|
||||
fields.Remove(fieldPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user