parent
ee897db52b
commit
f3ed5e0ad0
@ -0,0 +1,50 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
public partial class ItemOnGround2D : Node
|
||||
{
|
||||
private ItemInstance _itemInstance;
|
||||
|
||||
[Export]
|
||||
private bool _infiniteSupply = false;
|
||||
|
||||
private Label _itemLabel => GetNode<Label>("ItemLabel");
|
||||
private Label _pickupErrorLabel => GetNode<Label>("PickupErrorLabel");
|
||||
|
||||
public ItemInstance itemInstance
|
||||
{
|
||||
get => _itemInstance;
|
||||
set
|
||||
{
|
||||
_itemInstance = value;
|
||||
UpdateVisuals();
|
||||
}
|
||||
}
|
||||
|
||||
public void TryPickUp()
|
||||
{
|
||||
GD.Print("Trying to pick up item");
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
uid://btusf04xnywhm
|
||||
@ -0,0 +1,16 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
public partial class ItemOnGroundSpawnWith2D : Node
|
||||
{
|
||||
[Export] private ItemResource? _blueprint = null;
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
if(_blueprint == null) return;
|
||||
|
||||
var parent = GetParent<ItemOnGround2D>();
|
||||
parent.itemInstance = new ItemInstance { blueprint = _blueprint };
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
uid://bdsel2amlbnuq
|
||||
Loading…
Reference in new issue