WIP moving seed to plant matching into separate system, making fields independent of specific plants.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
@@ -13,7 +14,9 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
[Export] private Texture2D Tilled;
|
||||
[Export] private Texture2D Watered;
|
||||
[Export] public FieldState FieldState = FieldState.Tilled;
|
||||
[Export] private InteractionArea2D _growingCollider;
|
||||
[Export] public InteractionArea2D PlantingInteraction;
|
||||
[Export] public Node PlantingPlaceholder;
|
||||
|
||||
|
||||
public Vector2 FieldPosition;
|
||||
|
||||
@@ -31,19 +34,21 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
{
|
||||
case FieldState.Empty:
|
||||
FieldState = FieldState.Empty;
|
||||
PlantingInteraction.IsActive = false;
|
||||
break;
|
||||
case FieldState.Tilled:
|
||||
FieldState = FieldState.Tilled;
|
||||
_fieldSprite.Texture = Tilled;
|
||||
_growingCollider.Visible = false;
|
||||
PlantingInteraction.IsActive = false;
|
||||
break;
|
||||
case FieldState.Watered:
|
||||
FieldState = FieldState.Watered;
|
||||
_fieldSprite.Texture = Watered;
|
||||
_growingCollider.Visible = true;
|
||||
PlantingInteraction.IsActive = true;
|
||||
break;
|
||||
case FieldState.Planted:
|
||||
FieldState = FieldState.Planted;
|
||||
PlantingInteraction.IsActive = false;
|
||||
break;
|
||||
default:
|
||||
FieldState = FieldState.NotFound;
|
||||
@@ -62,19 +67,37 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
/// </summary>
|
||||
public void Farm()
|
||||
{
|
||||
switch (FieldState)
|
||||
if (FieldState == FieldState.Watered)
|
||||
{
|
||||
case FieldState.Empty:
|
||||
_fieldSprite.Texture = Tilled;
|
||||
FieldState = FieldState.Tilled;
|
||||
break;
|
||||
case FieldState.Watered:
|
||||
FieldState = FieldState.Planted;
|
||||
break;
|
||||
case FieldState.Planted:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if (TryPlant())
|
||||
{
|
||||
UpdateFieldState(FieldState.Planted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryPlant()
|
||||
{
|
||||
bool success = false;
|
||||
int currentSlotIndex = InventoryManager.Instance.CurrentSelectedSlotIndex;
|
||||
ItemInstance? item = InventoryManager.Instance.playerInventory.Slots[currentSlotIndex].itemInstance;
|
||||
|
||||
if (item == null)
|
||||
return success;
|
||||
|
||||
PackedScene? plantPrefab = SeedRepository.Instance.GetPlant(item.blueprint);
|
||||
|
||||
if (plantPrefab != null)
|
||||
{
|
||||
Node plantInstance = plantPrefab.Instantiate();
|
||||
if (plantInstance is Node2D plant2d)
|
||||
{
|
||||
PlantingPlaceholder.AddChild(plant2d);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user