|
|
|
|
@ -4,10 +4,12 @@ using Godot;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Babushka.scripts.CSharp.Common.Savegame;
|
|
|
|
|
using Babushka.scripts.CSharp.GameEntity.LoadSave;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Inventory;
|
|
|
|
|
|
|
|
|
|
public partial class InventoryInstance
|
|
|
|
|
public partial class InventoryInstance : IJsonSerializable
|
|
|
|
|
{
|
|
|
|
|
private readonly List<InventorySlot> _slots;
|
|
|
|
|
public IReadOnlyList<InventorySlot> Slots => _slots;
|
|
|
|
|
@ -193,4 +195,27 @@ public partial class InventoryInstance
|
|
|
|
|
{
|
|
|
|
|
return items.All(HasItems);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadFromJson(JObject json)
|
|
|
|
|
{
|
|
|
|
|
var itemsArray = (JArray?)json["items"];
|
|
|
|
|
if (itemsArray == null) return;
|
|
|
|
|
|
|
|
|
|
foreach (var (itemToken, slot) in itemsArray.Zip(_slots))
|
|
|
|
|
{
|
|
|
|
|
var itemObj = (JObject?)itemToken;
|
|
|
|
|
if (itemObj == null) continue;
|
|
|
|
|
slot.LoadFromJson(itemObj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InventoryContentsChanged?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JObject SaveToJson()
|
|
|
|
|
{
|
|
|
|
|
return new JObject
|
|
|
|
|
{
|
|
|
|
|
["items"] = new JArray(_slots.Select(s => s.SaveToJson()))
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|