using Babushka.scripts.CSharp.GameEntity.LoadSave; using Godot; using Newtonsoft.Json.Linq; namespace Babushka.scripts.CSharp.Common.Inventory; // Do not instantiate this resource // But it has to be a resource because Godot [GlobalClass] public partial class ItemInstance : Resource, IJsonSerializable { [Export] public ItemResource blueprint; [Export] public int amount = 1; public ItemInstance Clone() { return new ItemInstance { blueprint = blueprint, amount = amount }; } public void LoadFromJson(JObject json) { var blueprintPath = json.GetStringValue("blueprint"); blueprint = GD.Load(blueprintPath); amount = json.GetIntValue("amount"); } public JObject SaveToJson() { return new( new JProperty("blueprint", blueprint.ResourcePath), new JProperty("amount", amount)); } }