Fixed tomato farming again
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Babushka.scripts.CSharp.Common.Animation;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Godot;
|
||||
|
||||
@@ -24,6 +25,15 @@ public partial class PlantBehaviour2D : Node2D
|
||||
private string _magicWordDialogicEventName = "MagicWord";
|
||||
private Sprite2D _currentPlantSprite = null;
|
||||
private bool _magicWordSaid = false;
|
||||
|
||||
/// <summary>
|
||||
/// public accessor for the field reference
|
||||
/// </summary>
|
||||
public FieldBehaviour2D Field
|
||||
{
|
||||
get => _field;
|
||||
set => _field = value;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -34,7 +44,7 @@ public partial class PlantBehaviour2D : Node2D
|
||||
if (_field.FieldState != FieldState.Watered || _magicWordSaid != _magicWordNeeded)
|
||||
return;
|
||||
|
||||
//GetTree().CallGroup("PlantGrowing", PlayerMovement.MethodName.PlayFarmingAnimation);
|
||||
GetTree().CallGroup("PlantGrowing", VesnaAnimations.MethodName.PlayFarmingAnimation);
|
||||
// todo:
|
||||
// find out why the last plant stage is being skipped the second time around
|
||||
switch (_state)
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
public partial class SeedRepository : Node
|
||||
{
|
||||
public static SeedRepository Instance { get; private set; } = null!;
|
||||
|
||||
// todo: Find out how to not use PackedScene here because it does not inherit from Node
|
||||
[Export] private Dictionary<ItemResource, PackedScene> seedToPlantRepository;
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public PackedScene? GetPlant(ItemResource resource)
|
||||
{
|
||||
if (seedToPlantRepository.ContainsKey(resource))
|
||||
{
|
||||
return seedToPlantRepository[resource];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://coqch6yjvjuc0
|
||||
@@ -15,11 +15,15 @@ public partial class ItemResource : Resource
|
||||
|
||||
[Export]
|
||||
public int maxStack;
|
||||
|
||||
[Export]
|
||||
public PackedScene? itemPrefab;
|
||||
|
||||
public ItemResource()
|
||||
{
|
||||
name = "";
|
||||
color = Colors.Red;
|
||||
maxStack = 1;
|
||||
itemPrefab = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user