Files

50 lines
1.2 KiB
C#
Raw Permalink Normal View History

2025-04-14 16:49:29 +02:00
using Godot;
namespace Babushka.scripts.CSharp.Common.Inventory;
public partial class ItemOnGround : Node3D
{
private ItemInstance _itemInstance;
2025-04-14 17:36:29 +02:00
[Export]
private bool _infiniteSupply = false;
private Label3D _itemLabel => GetNode<Label3D>("ItemLabel");
private Label3D _pickupErrorLabel => GetNode<Label3D>("PickupErrorLabel");
2025-04-14 16:49:29 +02:00
public ItemInstance itemInstance
{
get => _itemInstance;
set
{
_itemInstance = value;
UpdateVisuals();
}
}
public void TryPickUp()
{
GD.Print("Trying to pick up item");
2025-04-17 16:10:12 +02:00
var result = InventoryManager.Instance.CollectItem(itemInstance.Clone());
2025-04-14 16:49:29 +02:00
if (result == InventoryActionResult.Success)
{
2025-04-14 17:36:29 +02:00
if (!_infiniteSupply)
{
QueueFree();
}
2025-04-14 16:49:29 +02:00
}
else
{
2025-04-14 17:36:29 +02:00
_pickupErrorLabel.Text = "Inventory Full";
var tween = GetTree().CreateTween();
tween.TweenInterval(2);
tween.TweenCallback(Callable.From(() => _pickupErrorLabel.Text = ""));
2025-04-14 16:49:29 +02:00
}
}
public void UpdateVisuals()
{
2025-04-14 17:36:29 +02:00
_itemLabel.Text = itemInstance.blueprint?.name ?? "Error Item";
2025-04-14 16:49:29 +02:00
}
}