Moved the player inventory and selected slot to VesnaEntity
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System.Threading.Tasks;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.Common.Services;
|
||||
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||
using Babushka.scripts.CSharp.GameEntity.Management;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Animation;
|
||||
@@ -27,12 +29,12 @@ public partial class VesnaAnimations : Node
|
||||
|
||||
private void SetupSubscriptions()
|
||||
{
|
||||
InventoryManager.Instance.playerInventory.InventoryContentsChanged += HandleNewItemInInventory;
|
||||
EntityManager.Instance.GetUniqueEntity<VesnaEntity>().inventory.InventoryContentsChanged += HandleNewItemInInventory;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
InventoryManager.Instance.playerInventory.InventoryContentsChanged -= HandleNewItemInInventory;
|
||||
EntityManager.Instance.GetUniqueEntity<VesnaEntity>().inventory.InventoryContentsChanged -= HandleNewItemInInventory;
|
||||
}
|
||||
|
||||
private void HandleNewItemInInventory()
|
||||
|
||||
@@ -3,6 +3,8 @@ using Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
using Babushka.scripts.CSharp.Common.DayAndNight;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.Common.Savegame;
|
||||
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||
using Babushka.scripts.CSharp.GameEntity.Management;
|
||||
using Babushka.scripts.CSharp.Low_Code.Events;
|
||||
using Babushka.scripts.CSharp.Low_Code.Variables;
|
||||
using Godot;
|
||||
@@ -178,8 +180,8 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
||||
private bool TryPlant()
|
||||
{
|
||||
bool success = false;
|
||||
int currentSlotIndex = InventoryManager.Instance.CurrentSelectedSlotIndex;
|
||||
ItemInstance? item = InventoryManager.Instance.playerInventory.Slots[currentSlotIndex].itemInstance;
|
||||
int currentSlotIndex = EntityManager.Instance.GetUniqueEntity<VesnaEntity>().CurrentSelectedSlotIndex;
|
||||
ItemInstance? item = EntityManager.Instance.GetUniqueEntity<VesnaEntity>().inventory.Slots[currentSlotIndex].itemInstance;
|
||||
|
||||
if (item == null || PlantingPlaceholder.GetChildCount() > 0 || item.amount == 0)
|
||||
return success;
|
||||
@@ -189,7 +191,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
||||
if (!string.IsNullOrEmpty(plantPrefabPath))
|
||||
{
|
||||
PlantPrefab(plantPrefabPath);
|
||||
InventoryManager.Instance.playerInventory.RemoveItem(currentSlotIndex);
|
||||
EntityManager.Instance.GetUniqueEntity<VesnaEntity>().inventory.RemoveItem(currentSlotIndex);
|
||||
success = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ using Babushka.scripts.CSharp.Common.Animation;
|
||||
using Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.Common.Services;
|
||||
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||
using Babushka.scripts.CSharp.GameEntity.Management;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
@@ -20,34 +22,32 @@ public partial class VesnaBehaviour2D : Node2D // EntityNode
|
||||
|
||||
[Signal] public delegate void InventorySelectionChangedEventHandler(int toolId);
|
||||
|
||||
private InventoryManager _inventoryManager;
|
||||
private InventoryInstance _inventoryInstance;
|
||||
//private InventoryManager _inventoryManager;
|
||||
private VesnaEntity _vesnaEntity;
|
||||
private InventoryInstance _playerInventory;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_inventoryManager = InventoryManager.Instance;
|
||||
_inventoryInstance = _inventoryManager.playerInventory;
|
||||
_inventoryManager.SlotIndexChanged += HandleInventorySelectedSlotIndexChanged;
|
||||
_vesnaEntity = EntityManager.Instance.GetUniqueEntity<VesnaEntity>();
|
||||
_playerInventory = _vesnaEntity.inventory;
|
||||
_vesnaEntity.SlotIndexChanged += HandleInventorySelectedSlotIndexChanged;
|
||||
_playerInventory.InventoryContentsChanged += UpdateToolInHand;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
_inventoryManager.SlotIndexChanged -= HandleInventorySelectedSlotIndexChanged;
|
||||
_vesnaEntity.SlotIndexChanged -= HandleInventorySelectedSlotIndexChanged;
|
||||
_playerInventory.InventoryContentsChanged -= UpdateToolInHand;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when picking up an item.
|
||||
/// Makes sure that item animations are also updated when they are occupying a currently empty spot.
|
||||
/// </summary>
|
||||
//public void HandlePickUp()
|
||||
//{
|
||||
// //Calls the same event handler as the inventory to ensure the currently selected item is updated in the animation.
|
||||
// HandleInventorySelectedSlotIndexChanged(0);
|
||||
//}
|
||||
|
||||
private void HandleInventorySelectedSlotIndexChanged(int newIndex = 0)
|
||||
private void HandleInventorySelectedSlotIndexChanged(int _ = 0)
|
||||
{
|
||||
InventorySlot currentSlot = InventoryManager.Instance.GetCurrentSelectedSlot();
|
||||
UpdateToolInHand();
|
||||
}
|
||||
|
||||
private void UpdateToolInHand()
|
||||
{
|
||||
InventorySlot currentSlot = _playerInventory.Slots[_vesnaEntity.CurrentSelectedSlotIndex];
|
||||
ItemInstance? currentItem = currentSlot.itemInstance;
|
||||
|
||||
int toolId = -1;
|
||||
|
||||
@@ -3,6 +3,8 @@ using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.Common.Util;
|
||||
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||
using Babushka.scripts.CSharp.GameEntity.Management;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Fight.Actions;
|
||||
|
||||
@@ -17,7 +19,7 @@ public class EatBeetrootAction : FighterAction
|
||||
{
|
||||
Debug.Assert(FightWorld.Instance.itemBeetrootToEatForHealth != null,
|
||||
"Item to eat for health has not been set in the FightWorld autoload");
|
||||
return !InventoryManager.Instance.playerInventory!.HasItems(new ItemInstance
|
||||
return !EntityManager.Instance.GetUniqueEntity<VesnaEntity>().inventory.HasItems(new ItemInstance
|
||||
{ blueprint = FightWorld.Instance.itemBeetrootToEatForHealth });
|
||||
}
|
||||
|
||||
@@ -35,7 +37,7 @@ public class EatBeetrootAction : FighterAction
|
||||
{
|
||||
var fighter = HappeningData.fighterTurn.Current;
|
||||
|
||||
var result = InventoryManager.Instance.playerInventory!.TryRemoveAllItems(
|
||||
var result = EntityManager.Instance.GetUniqueEntity<VesnaEntity>().inventory.TryRemoveAllItems(
|
||||
new ItemInstance { blueprint = FightWorld.Instance.itemBeetrootToEatForHealth! });
|
||||
|
||||
if (result != InventoryActionResult.Success)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||
using Babushka.scripts.CSharp.GameEntity.Management;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Fight.UI;
|
||||
@@ -9,7 +11,7 @@ public partial class HealButtonVisual : Button
|
||||
|
||||
public void UpdateText()
|
||||
{
|
||||
var healItemsLeft = InventoryManager.Instance.playerInventory!.TotalItemsOfBlueprint(_healItemBlueprint);
|
||||
var healItemsLeft = EntityManager.Instance.GetUniqueEntity<VesnaEntity>().inventory.TotalItemsOfBlueprint(_healItemBlueprint);
|
||||
Text = $"x{healItemsLeft} - Heal";
|
||||
}
|
||||
}
|
||||
@@ -7,21 +7,16 @@ using Babushka.scripts.CSharp.Common.Savegame;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
public partial class InventoryInstance : Node, ISaveable
|
||||
public partial class InventoryInstance
|
||||
{
|
||||
private List<InventorySlot> _slots = new();
|
||||
private readonly List<InventorySlot> _slots;
|
||||
public IReadOnlyList<InventorySlot> Slots => _slots;
|
||||
|
||||
[Signal]
|
||||
public delegate void SlotAmountChangedEventHandler();
|
||||
|
||||
[Signal]
|
||||
public delegate void InventoryContentsChangedEventHandler();
|
||||
|
||||
public static string ID = "inventoryInstance";
|
||||
public event Action? SlotAmountChanged;
|
||||
public event Action? InventoryContentsChanged;
|
||||
|
||||
/// <summary>
|
||||
/// The total amount of Inventoryslots in the inventory (empty and occupied).
|
||||
/// The total amount of InventorySlots in the inventory (empty and occupied).
|
||||
/// </summary>
|
||||
[Export]
|
||||
public int SlotAmount
|
||||
@@ -41,29 +36,20 @@ public partial class InventoryInstance : Node, ISaveable
|
||||
}
|
||||
}
|
||||
|
||||
EmitSignal(SignalName.SlotAmountChanged);
|
||||
SlotAmountChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public override void _EnterTree()
|
||||
public InventoryInstance(int slotCount)
|
||||
{
|
||||
LoadFromSaveData();
|
||||
InventoryContentsChanged += UpdateSaveData;
|
||||
SlotAmountChanged += UpdateSaveData;
|
||||
SavegameService.OnSaveGameReset += SaveGameReset;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
InventoryContentsChanged -= UpdateSaveData;
|
||||
SlotAmountChanged -= UpdateSaveData;
|
||||
SavegameService.OnSaveGameReset -= SaveGameReset;
|
||||
_slots = new();
|
||||
SlotAmount = slotCount;
|
||||
}
|
||||
|
||||
public InventoryActionResult AddItem(ItemInstance newItem)
|
||||
{
|
||||
var result = AddItemAndStackRecursive(newItem, 0);
|
||||
EmitSignal(SignalName.InventoryContentsChanged);
|
||||
InventoryContentsChanged?.Invoke();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -137,7 +123,7 @@ public partial class InventoryInstance : Node, ISaveable
|
||||
if (itemInstance.amount == 0)
|
||||
_slots[inventorySlot].itemInstance = null;
|
||||
|
||||
EmitSignal(SignalName.InventoryContentsChanged);
|
||||
InventoryContentsChanged?.Invoke();
|
||||
return InventoryActionResult.Success;
|
||||
}
|
||||
|
||||
@@ -174,7 +160,7 @@ public partial class InventoryInstance : Node, ISaveable
|
||||
break;
|
||||
}
|
||||
|
||||
EmitSignal(SignalName.InventoryContentsChanged);
|
||||
InventoryContentsChanged?.Invoke();
|
||||
return InventoryActionResult.Success;
|
||||
}
|
||||
|
||||
@@ -187,7 +173,7 @@ public partial class InventoryInstance : Node, ISaveable
|
||||
return InventoryActionResult.DestinationFull;
|
||||
|
||||
_slots[destinationSlot].itemInstance = itemInstance;
|
||||
EmitSignal(SignalName.InventoryContentsChanged);
|
||||
InventoryContentsChanged?.Invoke();
|
||||
return InventoryActionResult.Success;
|
||||
}
|
||||
|
||||
@@ -207,62 +193,4 @@ public partial class InventoryInstance : Node, ISaveable
|
||||
{
|
||||
return items.All(HasItems);
|
||||
}
|
||||
|
||||
#region SAVE AND LOAD
|
||||
|
||||
public void UpdateSaveData()
|
||||
{
|
||||
var payloadData = new Godot.Collections.Dictionary<string, Variant>();
|
||||
|
||||
for (int i = 0; i < _slots.Count; i++)
|
||||
{
|
||||
if (!_slots[i].IsEmpty())
|
||||
{
|
||||
string key = i.ToString();
|
||||
string[] value = new string[2];
|
||||
value[0] = _slots[i].itemInstance.blueprint.ResourcePath;
|
||||
value[1] = _slots[i].itemInstance.amount.ToString();
|
||||
payloadData.Add(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
SavegameService.AppendDataToSave(ID, payloadData);
|
||||
}
|
||||
|
||||
public void LoadFromSaveData()
|
||||
{
|
||||
var id = ID;
|
||||
|
||||
Godot.Collections.Dictionary<string, Variant> save = SavegameService.GetSaveData(id);
|
||||
|
||||
if (save.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < _slots.Count; i++)
|
||||
{
|
||||
if (save.TryGetValue(i.ToString(), out Variant inventoryItemData))
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when a new save is created.
|
||||
/// Needs to do a runtime check because the InventoryInstance is already in existence at the beginning of the first scene.
|
||||
/// </summary>
|
||||
private void SaveGameReset()
|
||||
{
|
||||
foreach (var slot in _slots)
|
||||
{
|
||||
slot.itemInstance = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||
using Babushka.scripts.CSharp.GameEntity.Management;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
@@ -8,16 +10,25 @@ public partial class InventoryListener : Node
|
||||
|
||||
[Signal] public delegate void ItemInstanceActivatedEventHandler(bool activated);
|
||||
|
||||
private VesnaEntity _vesnaEntity;
|
||||
private InventoryInstance _playerInventory;
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
_vesnaEntity = EntityManager.Instance.GetUniqueEntity<VesnaEntity>();
|
||||
_playerInventory = _vesnaEntity.inventory;
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
InventoryManager.Instance.playerInventory.InventoryContentsChanged += HandleNewItemInInventory;
|
||||
InventoryManager.Instance.SlotIndexChanged += HandleNewItemInInventory;
|
||||
_playerInventory.InventoryContentsChanged += HandleNewItemInInventory;
|
||||
_vesnaEntity.SlotIndexChanged += HandleNewItemInInventory;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
InventoryManager.Instance.playerInventory.InventoryContentsChanged -= HandleNewItemInInventory;
|
||||
InventoryManager.Instance.SlotIndexChanged -= HandleNewItemInInventory;
|
||||
_playerInventory.InventoryContentsChanged -= HandleNewItemInInventory;
|
||||
_vesnaEntity.SlotIndexChanged -= HandleNewItemInInventory;
|
||||
}
|
||||
|
||||
private void HandleNewItemInInventory(int newIndex)
|
||||
@@ -27,8 +38,8 @@ public partial class InventoryListener : Node
|
||||
|
||||
private void HandleNewItemInInventory()
|
||||
{
|
||||
int currentSlotIndex = InventoryManager.Instance.CurrentSelectedSlotIndex;
|
||||
ItemInstance? instance = InventoryManager.Instance.playerInventory.Slots[currentSlotIndex].itemInstance;
|
||||
int currentSlotIndex = _vesnaEntity.CurrentSelectedSlotIndex;
|
||||
ItemInstance? instance = _playerInventory.Slots[currentSlotIndex].itemInstance;
|
||||
if (instance != null)
|
||||
{
|
||||
ItemResource? item = instance.blueprint;
|
||||
|
||||
@@ -5,25 +5,8 @@ namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
public partial class InventoryManager : Node
|
||||
{
|
||||
[Signal]
|
||||
public delegate void SlotIndexChangedEventHandler(int newIndex);
|
||||
|
||||
|
||||
public static InventoryManager Instance { get; private set; } = null!;
|
||||
public int CurrentSelectedSlotIndex
|
||||
{
|
||||
get => _currentSelectedSlotIndex;
|
||||
set
|
||||
{
|
||||
if (value >= 0 && value <= 8)
|
||||
{
|
||||
_currentSelectedSlotIndex = value;
|
||||
EmitSignalSlotIndexChanged(_currentSelectedSlotIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public InventoryInstance? playerInventory;
|
||||
|
||||
private int _currentSelectedSlotIndex = 0;
|
||||
|
||||
@@ -34,9 +17,6 @@ public partial class InventoryManager : Node
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
playerInventory = new InventoryInstance();
|
||||
playerInventory.SlotAmount = 37;
|
||||
AddChild(playerInventory);
|
||||
}
|
||||
|
||||
public InventoryActionResult CreateItem(
|
||||
@@ -82,19 +62,4 @@ public partial class InventoryManager : Node
|
||||
{
|
||||
return inventory.RemoveItem(inventorySlot);
|
||||
}
|
||||
|
||||
public InventoryActionResult CollectItem(ItemInstance itemInstance)
|
||||
{
|
||||
return playerInventory.AddItem(itemInstance);
|
||||
}
|
||||
|
||||
public InventorySlot GetCurrentSelectedSlot()
|
||||
{
|
||||
if (CurrentSelectedSlotIndex < 0 || CurrentSelectedSlotIndex > 8)
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(CurrentSelectedSlotIndex),
|
||||
"currentInventoryBarIndex must be between 0 and 8 (inclusively)");
|
||||
|
||||
return playerInventory.Slots[CurrentSelectedSlotIndex];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Godot;
|
||||
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||
using Babushka.scripts.CSharp.GameEntity.Management;
|
||||
using Godot;
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
public partial class InventoryTestScript : Node
|
||||
@@ -10,7 +12,7 @@ public partial class InventoryTestScript : Node
|
||||
{
|
||||
foreach (var itemResource in _testItemsToCreate)
|
||||
{
|
||||
InventoryManager.Instance.CreateItem(itemResource, InventoryManager.Instance.playerInventory);
|
||||
InventoryManager.Instance.CreateItem(itemResource, EntityManager.Instance.GetUniqueEntity<VesnaEntity>().inventory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||
using Babushka.scripts.CSharp.GameEntity.Management;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
@@ -10,6 +12,7 @@ public partial class InventoryUi : Control
|
||||
[Export] private Control _slotSelect;
|
||||
|
||||
private InventoryInstance _playerInventory;
|
||||
private VesnaEntity _vesnaEntity;
|
||||
private int? _slotOnMouse;
|
||||
private bool _inventoryExtended = false;
|
||||
private Tween? _inventoryExtensionTween;
|
||||
@@ -18,17 +21,18 @@ public partial class InventoryUi : Control
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_playerInventory = InventoryManager.Instance.playerInventory;
|
||||
_vesnaEntity = EntityManager.Instance.GetUniqueEntity<VesnaEntity>();
|
||||
_playerInventory = _vesnaEntity.inventory;
|
||||
//PopulateSlots();
|
||||
SubscribeSlots();
|
||||
SetSlotContent();
|
||||
SetSlotSelectPosition();
|
||||
InventoryManager.Instance.playerInventory.InventoryContentsChanged += SetSlotContent;
|
||||
_playerInventory.InventoryContentsChanged += SetSlotContent;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
InventoryManager.Instance.playerInventory.InventoryContentsChanged -= SetSlotContent;
|
||||
_playerInventory.InventoryContentsChanged -= SetSlotContent;
|
||||
UnsubscribeSlots();
|
||||
}
|
||||
|
||||
@@ -75,7 +79,7 @@ public partial class InventoryUi : Control
|
||||
|
||||
private void SetSlotSelectPosition()
|
||||
{
|
||||
_slotSelect.GlobalPosition = _headerSlots[InventoryManager.Instance.CurrentSelectedSlotIndex].GlobalPosition;
|
||||
_slotSelect.GlobalPosition = _headerSlots[_vesnaEntity.CurrentSelectedSlotIndex].GlobalPosition;
|
||||
}
|
||||
|
||||
private void PopulateSlots()
|
||||
@@ -147,17 +151,17 @@ public partial class InventoryUi : Control
|
||||
|
||||
if (Input.IsActionJustPressed("ui_inventory_disadvance"))
|
||||
{
|
||||
InventoryManager.Instance.CurrentSelectedSlotIndex++;
|
||||
if (InventoryManager.Instance.CurrentSelectedSlotIndex > 8)
|
||||
InventoryManager.Instance.CurrentSelectedSlotIndex = 0;
|
||||
_vesnaEntity.CurrentSelectedSlotIndex++;
|
||||
if (_vesnaEntity.CurrentSelectedSlotIndex > 8)
|
||||
_vesnaEntity.CurrentSelectedSlotIndex = 0;
|
||||
SetSlotSelectPosition();
|
||||
}
|
||||
|
||||
if (Input.IsActionJustPressed("ui_inventory_advance"))
|
||||
{
|
||||
InventoryManager.Instance.CurrentSelectedSlotIndex--;
|
||||
if (InventoryManager.Instance.CurrentSelectedSlotIndex < 0)
|
||||
InventoryManager.Instance.CurrentSelectedSlotIndex = 8;
|
||||
_vesnaEntity.CurrentSelectedSlotIndex--;
|
||||
if (_vesnaEntity.CurrentSelectedSlotIndex < 0)
|
||||
_vesnaEntity.CurrentSelectedSlotIndex = 8;
|
||||
SetSlotSelectPosition();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Babushka.scripts.CSharp.Common.Savegame;
|
||||
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||
using Babushka.scripts.CSharp.GameEntity.Management;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
@@ -44,7 +46,7 @@ public partial class ItemOnGround2D : Node, ISaveable
|
||||
if (!IsActive)
|
||||
return;
|
||||
|
||||
var result = InventoryManager.Instance.CollectItem(itemInstance.Clone());
|
||||
var result = EntityManager.Instance.GetUniqueEntity<VesnaEntity>().inventory.AddItem(itemInstance.Clone());
|
||||
EmitSignal(SignalName.SuccessfulPickUp);
|
||||
if (result == InventoryActionResult.Success)
|
||||
{
|
||||
@@ -111,51 +113,54 @@ public partial class ItemOnGround2D : Node, ISaveable
|
||||
|
||||
public void LoadFromSaveData()
|
||||
{
|
||||
if (!_saveToDisk)
|
||||
return;
|
||||
// WON'T FIX - WILL BE REDONE ANYWAY
|
||||
|
||||
if (_infiniteSupply)
|
||||
return;
|
||||
|
||||
// standard check: how many times has this item been collected?
|
||||
string id = GetMeta("SaveID").AsString();
|
||||
|
||||
Dictionary<string, Variant> save = SavegameService.GetSaveData(id);
|
||||
if (save.Count > 0)
|
||||
{
|
||||
if(save.TryGetValue("pickupCounter", out Variant countVar))
|
||||
{
|
||||
int count = countVar.AsInt32();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
Pickup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if (!_saveToDisk)
|
||||
// return;
|
||||
//
|
||||
//if (_infiniteSupply)
|
||||
// return;
|
||||
//
|
||||
//// standard check: how many times has this item been collected?
|
||||
//string id = GetMeta("SaveID").AsString();
|
||||
//
|
||||
//Dictionary<string, Variant> save = SavegameService.GetSaveData(id);
|
||||
//if (save.Count > 0)
|
||||
//{
|
||||
// if(save.TryGetValue("pickupCounter", out Variant countVar))
|
||||
// {
|
||||
// int count = countVar.AsInt32();
|
||||
// for (int i = 0; i < count; i++)
|
||||
// {
|
||||
// Pickup();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//separate check for unique items: If already in inventory, delete this instance.
|
||||
ItemResource itemResource = itemInstance.blueprint;
|
||||
Dictionary<string, Variant> savegameData = SavegameService.GetSaveData(InventoryInstance.ID);
|
||||
if (savegameData.Count > 0)
|
||||
{
|
||||
foreach (var kvp in savegameData)
|
||||
{
|
||||
// if it's a unique item, then it can only exist once in the world (either as a pickup OR in the inventory)
|
||||
if (itemInstance.blueprint.isUnique)
|
||||
{
|
||||
//comparing resource path to identify the item
|
||||
string[] valuePair = kvp.Value.AsStringArray();
|
||||
if (valuePair[0] == itemResource.ResourcePath)
|
||||
{
|
||||
int amountInInventory = int.Parse(valuePair[1]);
|
||||
// comparing amount to see if it's all in the inventory now.
|
||||
if (amountInInventory > 0)
|
||||
{
|
||||
Pickup();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//ItemResource itemResource = itemInstance.blueprint;
|
||||
//Dictionary<string, Variant> savegameData = SavegameService.GetSaveData(InventoryInstance.ID);
|
||||
//if (savegameData.Count > 0)
|
||||
//{
|
||||
// foreach (var kvp in savegameData)
|
||||
// {
|
||||
// // if it's a unique item, then it can only exist once in the world (either as a pickup OR in the inventory)
|
||||
// if (itemInstance.blueprint.isUnique)
|
||||
// {
|
||||
// //comparing resource path to identify the item
|
||||
// string[] valuePair = kvp.Value.AsStringArray();
|
||||
// if (valuePair[0] == itemResource.ResourcePath)
|
||||
// {
|
||||
// int amountInInventory = int.Parse(valuePair[1]);
|
||||
// // comparing amount to see if it's all in the inventory now.
|
||||
// if (amountInInventory > 0)
|
||||
// {
|
||||
// Pickup();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||
using Babushka.scripts.CSharp.GameEntity.Management;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
@@ -11,20 +13,20 @@ public partial class InventoryDependentInteractable : Node2D
|
||||
[Export] private Array<ItemResource> _itemsToReactTo;
|
||||
[Export] private bool _activateOnItem = true;
|
||||
|
||||
private InventoryManager _inventoryManager;
|
||||
private InventoryInstance _inventoryInstance;
|
||||
private VesnaEntity _vesnaEntity;
|
||||
private InventoryInstance _playerInventory;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_inventoryManager = InventoryManager.Instance;
|
||||
_inventoryInstance = _inventoryManager.playerInventory;
|
||||
_inventoryManager.SlotIndexChanged += HandleInventorySelectedSlotIndexChanged;
|
||||
_vesnaEntity = EntityManager.Instance.GetUniqueEntity<VesnaEntity>();
|
||||
_playerInventory = _vesnaEntity.inventory;
|
||||
_vesnaEntity.SlotIndexChanged += HandleInventorySelectedSlotIndexChanged;
|
||||
}
|
||||
|
||||
private void HandleInventorySelectedSlotIndexChanged(int newIndex)
|
||||
{
|
||||
int currentSlotIndex = InventoryManager.Instance.CurrentSelectedSlotIndex;
|
||||
ItemInstance? item = InventoryManager.Instance.playerInventory.Slots[currentSlotIndex].itemInstance;
|
||||
int currentSlotIndex = _vesnaEntity.CurrentSelectedSlotIndex;
|
||||
ItemInstance? item = _playerInventory.Slots[currentSlotIndex].itemInstance;
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
|
||||
@@ -4,6 +4,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.Common.Quest;
|
||||
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||
using Babushka.scripts.CSharp.GameEntity.Management;
|
||||
|
||||
public partial class DetectInventoryContains : QuestFulfillmentBase
|
||||
{
|
||||
@@ -12,7 +14,7 @@ public partial class DetectInventoryContains : QuestFulfillmentBase
|
||||
public override void _Ready()
|
||||
{
|
||||
QuestManager.Instance!.QuestsChanged += CheckInventory;
|
||||
InventoryManager.Instance.playerInventory.InventoryContentsChanged += CheckInventory;
|
||||
EntityManager.Instance.GetUniqueEntity<VesnaEntity>().inventory.InventoryContentsChanged += CheckInventory;
|
||||
|
||||
CheckInventory();
|
||||
}
|
||||
@@ -20,12 +22,12 @@ public partial class DetectInventoryContains : QuestFulfillmentBase
|
||||
public override void _ExitTree()
|
||||
{
|
||||
QuestManager.Instance!.QuestsChanged -= CheckInventory;
|
||||
InventoryManager.Instance.playerInventory.InventoryContentsChanged -= CheckInventory;
|
||||
EntityManager.Instance.GetUniqueEntity<VesnaEntity>().inventory.InventoryContentsChanged -= CheckInventory;
|
||||
}
|
||||
|
||||
private void CheckInventory()
|
||||
{
|
||||
if (IsQuestActive() && InventoryManager.Instance.playerInventory.HasItems(_itemsToContain))
|
||||
if (IsQuestActive() && EntityManager.Instance.GetUniqueEntity<VesnaEntity>().inventory.HasItems(_itemsToContain))
|
||||
{
|
||||
Fulfill();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Babushka.scripts.CSharp.Common.Farming;
|
||||
using System;
|
||||
using Babushka.scripts.CSharp.Common.Farming;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.GameEntity.Management;
|
||||
using Godot;
|
||||
|
||||
@@ -8,7 +10,23 @@ 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);
|
||||
|
||||
Reference in New Issue
Block a user