|
|
|
|
@ -3,9 +3,7 @@ using System;
|
|
|
|
|
using Godot;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Babushka.scripts.CSharp.Common.Farming;
|
|
|
|
|
using Babushka.scripts.CSharp.Common.Savegame;
|
|
|
|
|
using Godot.Collections;
|
|
|
|
|
|
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Inventory;
|
|
|
|
|
|
|
|
|
|
@ -48,6 +46,19 @@ public partial class InventoryInstance : Node
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void _EnterTree()
|
|
|
|
|
{
|
|
|
|
|
LoadFromSaveData();
|
|
|
|
|
InventoryContentsChanged += UpdateSaveData;
|
|
|
|
|
SlotAmountChanged += UpdateSaveData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void _ExitTree()
|
|
|
|
|
{
|
|
|
|
|
InventoryContentsChanged -= UpdateSaveData;
|
|
|
|
|
SlotAmountChanged -= UpdateSaveData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public InventoryActionResult AddItem(ItemInstance newItem)
|
|
|
|
|
{
|
|
|
|
|
var result = AddItemAndStackRecursive(newItem, 0);
|
|
|
|
|
@ -201,9 +212,14 @@ public partial class InventoryInstance : Node
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < _slots.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (save.TryGetValue(i.ToString(), out Variant inventoryItem))
|
|
|
|
|
if (save.TryGetValue(i.ToString(), out Variant inventoryItemData))
|
|
|
|
|
{
|
|
|
|
|
// todo: we have the resource paths and amounts, but how do we get to ItemResources and ItemInstances?
|
|
|
|
|
string[] savePayload = inventoryItemData.AsStringArray();
|
|
|
|
|
ItemResource resource = ResourceLoader.Load<ItemResource>(savePayload[0]);
|
|
|
|
|
int _amount = int.Parse(savePayload[1]);
|
|
|
|
|
|
|
|
|
|
ItemInstance instance = new ItemInstance { blueprint = resource, amount = _amount };
|
|
|
|
|
AddItem(instance);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|