You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
945 B
37 lines
945 B
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<ItemResource>(blueprintPath);
|
|
amount = json.GetIntValue("amount");
|
|
}
|
|
|
|
public JObject SaveToJson()
|
|
{
|
|
return new(
|
|
new JProperty("blueprint", blueprint.ResourcePath),
|
|
new JProperty("amount", amount));
|
|
}
|
|
} |