You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
using Godot;
|
|
namespace Babushka.scripts.CSharp.Common.Inventory;
|
|
|
|
public partial class ItemOnGround : Node3D
|
|
{
|
|
private ItemInstance _itemInstance;
|
|
|
|
[Export]
|
|
private bool _infiniteSupply = false;
|
|
|
|
private Label3D _itemLabel => GetNode<Label3D>("ItemLabel");
|
|
private Label3D _pickupErrorLabel => GetNode<Label3D>("PickupErrorLabel");
|
|
|
|
public ItemInstance itemInstance
|
|
{
|
|
get => _itemInstance;
|
|
set
|
|
{
|
|
_itemInstance = value;
|
|
UpdateVisuals();
|
|
}
|
|
}
|
|
|
|
public void TryPickUp()
|
|
{
|
|
var result = InventoryManager.Instance.CollectItem(itemInstance.Clone());
|
|
if (result == InventoryActionResult.Success)
|
|
{
|
|
if (!_infiniteSupply)
|
|
{
|
|
QueueFree();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_pickupErrorLabel.Text = "Inventory Full";
|
|
var tween = GetTree().CreateTween();
|
|
tween.TweenInterval(2);
|
|
tween.TweenCallback(Callable.From(() => _pickupErrorLabel.Text = ""));
|
|
}
|
|
}
|
|
|
|
public void UpdateVisuals()
|
|
{
|
|
_itemLabel.Text = itemInstance.blueprint?.name ?? "Error Item";
|
|
}
|
|
}
|