Fixed tomato farming again

This commit is contained in:
2025-08-17 21:57:57 +02:00
parent ce2d7eb773
commit 7fd26ffed3
11 changed files with 40 additions and 51 deletions
@@ -15,7 +15,7 @@ public partial class FieldBehaviour2D : Sprite2D
[Export] private Texture2D Watered;
[Export] public FieldState FieldState = FieldState.Tilled;
[Export] public InteractionArea2D PlantingInteraction;
[Export] public Node PlantingPlaceholder;
[Export] public Node2D PlantingPlaceholder;
public Vector2 FieldPosition;
@@ -48,6 +48,7 @@ public partial class FieldBehaviour2D : Sprite2D
break;
case FieldState.Planted:
FieldState = FieldState.Planted;
_fieldSprite.Texture = Tilled;
PlantingInteraction.IsActive = false;
break;
default:
@@ -82,10 +83,10 @@ public partial class FieldBehaviour2D : Sprite2D
int currentSlotIndex = InventoryManager.Instance.CurrentSelectedSlotIndex;
ItemInstance? item = InventoryManager.Instance.playerInventory.Slots[currentSlotIndex].itemInstance;
if (item == null)
if (item == null || PlantingPlaceholder.GetChildCount() > 0)
return success;
PackedScene? plantPrefab = SeedRepository.Instance.GetPlant(item.blueprint);
PackedScene? plantPrefab = item.blueprint.itemPrefab;
if (plantPrefab != null)
{
@@ -93,6 +94,15 @@ public partial class FieldBehaviour2D : Sprite2D
if (plantInstance is Node2D plant2d)
{
PlantingPlaceholder.AddChild(plant2d);
plant2d.GlobalPosition = PlantingPlaceholder.GlobalPosition;
PlantBehaviour2D? plantBehaviour = plant2d as PlantBehaviour2D;
if (plantBehaviour != null)
{
plantBehaviour.Field = this;
plantBehaviour.Grow();
}
success = true;
}
}