|
|
|
|
@ -1,8 +1,10 @@
|
|
|
|
|
using Babushka.scripts.CSharp.Common.Savegame;
|
|
|
|
|
using Godot;
|
|
|
|
|
using Godot.Collections;
|
|
|
|
|
|
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Inventory;
|
|
|
|
|
|
|
|
|
|
public partial class ItemOnGround2D : Node
|
|
|
|
|
public partial class ItemOnGround2D : Node, ISaveable
|
|
|
|
|
{
|
|
|
|
|
private ItemInstance _itemInstance;
|
|
|
|
|
|
|
|
|
|
@ -30,6 +32,7 @@ public partial class ItemOnGround2D : Node
|
|
|
|
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
|
{
|
|
|
|
|
LoadFromSaveData();
|
|
|
|
|
UpdateVisuals();
|
|
|
|
|
_pickupErrorLabel.Text = "";
|
|
|
|
|
}
|
|
|
|
|
@ -43,24 +46,34 @@ public partial class ItemOnGround2D : Node
|
|
|
|
|
EmitSignal(SignalName.SuccessfulPickUp);
|
|
|
|
|
if (result == InventoryActionResult.Success)
|
|
|
|
|
{
|
|
|
|
|
if (!_infiniteSupply)
|
|
|
|
|
{
|
|
|
|
|
pickUpCounter++;
|
|
|
|
|
if (pickUpCounter >= _finiteSupply)
|
|
|
|
|
{
|
|
|
|
|
QueueFree();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Pickup();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_pickupErrorLabel.Text = "Inventory Full";
|
|
|
|
|
var tween = GetTree().CreateTween();
|
|
|
|
|
tween.TweenInterval(2);
|
|
|
|
|
tween.TweenCallback(Callable.From(() => _pickupErrorLabel.Text = ""));
|
|
|
|
|
FailToPickup();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Pickup()
|
|
|
|
|
{
|
|
|
|
|
if (!_infiniteSupply)
|
|
|
|
|
{
|
|
|
|
|
pickUpCounter++;
|
|
|
|
|
if (pickUpCounter >= _finiteSupply)
|
|
|
|
|
{
|
|
|
|
|
QueueFree();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FailToPickup()
|
|
|
|
|
{
|
|
|
|
|
_pickupErrorLabel.Text = "Inventory Full";
|
|
|
|
|
var tween = GetTree().CreateTween();
|
|
|
|
|
tween.TweenInterval(2);
|
|
|
|
|
tween.TweenCallback(Callable.From(() => _pickupErrorLabel.Text = ""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateVisuals()
|
|
|
|
|
{
|
|
|
|
|
if (!IsActive)
|
|
|
|
|
@ -76,4 +89,40 @@ public partial class ItemOnGround2D : Node
|
|
|
|
|
_itemLabel.Text = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateSaveData()
|
|
|
|
|
{
|
|
|
|
|
// do nothing?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadFromSaveData()
|
|
|
|
|
{
|
|
|
|
|
if (_infiniteSupply)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ItemResource itemResource = itemInstance.blueprint;
|
|
|
|
|
Dictionary<string, Variant> savegameData = SavegameService.GetSaveData(InventoryInstance.ID);
|
|
|
|
|
if (savegameData.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var kvp in savegameData)
|
|
|
|
|
{
|
|
|
|
|
// if it's a unique item, then it can only exist once in the world (either as a pickup OR in the inventory)
|
|
|
|
|
if (itemInstance.blueprint.isUnique)
|
|
|
|
|
{
|
|
|
|
|
//comparing resource path to identify the item
|
|
|
|
|
string[] valuePair = kvp.Value.AsStringArray();
|
|
|
|
|
if (valuePair[0] == itemResource.ResourcePath)
|
|
|
|
|
{
|
|
|
|
|
int amountInInventory = int.Parse(valuePair[1]);
|
|
|
|
|
// comparing amount to see if it's all in the inventory now.
|
|
|
|
|
if (amountInInventory > 0)
|
|
|
|
|
{
|
|
|
|
|
Pickup();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|