basic harvesting implemented
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;
|
||||
@@ -15,6 +16,7 @@ public partial class PlantBehaviour2D : Node2D
|
||||
[Export] private Sprite2D[] _readyPlants;
|
||||
[Export] private PlantState _state = PlantState.None;
|
||||
[Export] private FieldBehaviour2D _field;
|
||||
[Export] private ItemOnGround2D _harvestablePlant;
|
||||
|
||||
private Sprite2D _currentPlantSprite = null;
|
||||
|
||||
@@ -52,6 +54,7 @@ public partial class PlantBehaviour2D : Node2D
|
||||
_state = PlantState.Ready;
|
||||
_currentPlantSprite.Visible = false;
|
||||
_currentPlantSprite = GetRandomSprite(_readyPlants);
|
||||
_harvestablePlant.IsActive = true;
|
||||
_currentPlantSprite.Visible = true;
|
||||
break;
|
||||
case PlantState.Ready:
|
||||
|
||||
@@ -5,9 +5,12 @@ namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
public partial class ItemOnGround2D : Node
|
||||
{
|
||||
private ItemInstance _itemInstance;
|
||||
|
||||
[Export] private bool _infiniteSupply = false;
|
||||
[Export] private int _finiteSupply = 1;
|
||||
[Export] public bool IsActive = true;
|
||||
|
||||
[Export]
|
||||
private bool _infiniteSupply = false;
|
||||
private int pickUpCounter = 0;
|
||||
|
||||
private Label _itemLabel => GetNode<Label>("ItemLabel");
|
||||
private Label _pickupErrorLabel => GetNode<Label>("PickupErrorLabel");
|
||||
@@ -31,14 +34,19 @@ public partial class ItemOnGround2D : Node
|
||||
|
||||
public void TryPickUp()
|
||||
{
|
||||
GD.Print("Trying to pick up item");
|
||||
|
||||
if (!IsActive)
|
||||
return;
|
||||
|
||||
var result = InventoryManager.Instance.CollectItem(itemInstance.Clone());
|
||||
if (result == InventoryActionResult.Success)
|
||||
{
|
||||
if (!_infiniteSupply)
|
||||
{
|
||||
QueueFree();
|
||||
pickUpCounter++;
|
||||
if (pickUpCounter >= _finiteSupply)
|
||||
{
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -52,6 +60,9 @@ public partial class ItemOnGround2D : Node
|
||||
|
||||
public void UpdateVisuals()
|
||||
{
|
||||
if (!IsActive)
|
||||
return;
|
||||
|
||||
_iconSprite.Texture = itemInstance?.blueprint?.icon;
|
||||
if (_iconSprite.Texture == null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user