Added item stacking
This commit is contained in:
@@ -6,7 +6,7 @@ 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()
|
||||
@@ -23,11 +23,13 @@ public partial class InventoryManager : Node
|
||||
public InventoryActionResult CreateItem(
|
||||
ItemResource itemBlueprint,
|
||||
InventoryInstance inventory,
|
||||
int amount = 1,
|
||||
int inventorySlot = -1)
|
||||
{
|
||||
var newItem = new ItemInstance { blueprint = itemBlueprint };
|
||||
var addResult = inventory.AddItem(newItem, inventorySlot);
|
||||
return addResult;
|
||||
var newItem = new ItemInstance { blueprint = itemBlueprint, amount = amount };
|
||||
return inventorySlot < 0
|
||||
? inventory.AddItem(newItem)
|
||||
: inventory.AddItemToSlot(newItem, inventorySlot);
|
||||
}
|
||||
|
||||
public InventoryActionResult MoveItem(
|
||||
@@ -39,10 +41,11 @@ public partial class InventoryManager : Node
|
||||
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;
|
||||
var addResult = destinationInventory.AddItemToSlot(item!, destinationSlot);
|
||||
if (addResult == InventoryActionResult.Success) return InventoryActionResult.Success;
|
||||
|
||||
sourceInventory.AddItem(item!, sourceSlot); // can not fail ... in theory
|
||||
// if adding in the destination failed, re-add the item into the source
|
||||
sourceInventory.AddItemToSlot(item!, sourceSlot); // can not fail ... in theory
|
||||
return addResult;
|
||||
}
|
||||
|
||||
@@ -60,8 +63,9 @@ public partial class InventoryManager : Node
|
||||
{
|
||||
return inventory.RemoveItem(inventorySlot);
|
||||
}
|
||||
|
||||
public InventoryActionResult CollectItem(ItemInstance itemInstance)
|
||||
{
|
||||
return playerInventory.AddItem(itemInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user