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.
Babushka/scripts/CSharp/GameEntity/Entities/VesnaEntity.cs

51 lines
1.5 KiB

using System;
using Babushka.scripts.CSharp.Common.Farming;
using Babushka.scripts.CSharp.Common.Inventory;
using Babushka.scripts.CSharp.GameEntity.Management;
using Godot;
using Newtonsoft.Json.Linq;
namespace Babushka.scripts.CSharp.GameEntity.Entities;
public class VesnaEntity : PositionalEntity
{
public override string EntityType => OWN_TYPE_NAME;
public const string OWN_TYPE_NAME = "VesnaEntity";
public readonly InventoryInstance inventory = new (37);
public event Action<int>? SlotIndexChanged;
private int _currentSelectedSlotIndex;
public int CurrentSelectedSlotIndex
{
get => _currentSelectedSlotIndex;
set
{
if (value >= 0 && value <= 8)
{
_currentSelectedSlotIndex = value;
SlotIndexChanged?.Invoke(_currentSelectedSlotIndex);
}
}
}
public override void InstantiateEntityNode(Node2D parent)
{
var node = (VesnaBehaviour2D) EntityManager.Instance.NodeCreator.InstantiateNode(OWN_TYPE_NAME);
node.player2d.Initialize(this);
parent.AddChild(node);
}
public override void SaveEntity(JObject json)
{
base.SaveEntity(json);
json["slot"] = CurrentSelectedSlotIndex;
json["inventory"] = inventory.SaveToJson();
}
public override void LoadEntity(JObject json)
{
base.LoadEntity(json);
CurrentSelectedSlotIndex = json.Value<int>("slot");
inventory.LoadFromJson(json.Value<JObject>("inventory")!);
}
}