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.
68 lines
1.9 KiB
68 lines
1.9 KiB
#nullable enable
|
|
using Godot;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Inventory;
|
|
|
|
public partial class InventoryManager : Node
|
|
{
|
|
public static InventoryManager Instance { get; private set; }
|
|
|
|
public InventoryInstance playerInventory;
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
public override void _Ready()
|
|
{
|
|
playerInventory = new InventoryInstance();
|
|
playerInventory.SlotAmount = 30;
|
|
}
|
|
|
|
public InventoryActionResult CreateItem(
|
|
ItemResource itemBlueprint,
|
|
InventoryInstance inventory,
|
|
int inventorySlot = -1)
|
|
{
|
|
var newItem = new ItemInstance { blueprint = itemBlueprint };
|
|
var addResult = inventory.AddItem(newItem, inventorySlot);
|
|
return addResult;
|
|
}
|
|
|
|
public InventoryActionResult MoveItem(
|
|
InventoryInstance sourceInventory,
|
|
int sourceSlot,
|
|
InventoryInstance destinationInventory,
|
|
int destinationSlot)
|
|
{
|
|
var remResult = sourceInventory.RemoveItem(sourceSlot, out var item);
|
|
if (remResult != InventoryActionResult.Success) return remResult;
|
|
|
|
var addResult = destinationInventory.AddItem(item!, destinationSlot);
|
|
if(addResult == InventoryActionResult.Success) return InventoryActionResult.Success;
|
|
|
|
sourceInventory.AddItem(item!, sourceSlot); // can not fail ... in theory
|
|
return addResult;
|
|
}
|
|
|
|
public InventoryActionResult RemoveItem(
|
|
InventoryInstance inventory,
|
|
int inventorySlot,
|
|
out ItemInstance? itemInstance)
|
|
{
|
|
return inventory.RemoveItem(inventorySlot, out itemInstance);
|
|
}
|
|
|
|
public InventoryActionResult RemoveItem(
|
|
InventoryInstance inventory,
|
|
int inventorySlot)
|
|
{
|
|
return inventory.RemoveItem(inventorySlot);
|
|
}
|
|
public InventoryActionResult CollectItem(ItemInstance itemInstance)
|
|
{
|
|
return playerInventory.AddItem(itemInstance);
|
|
}
|
|
}
|