Added inventory display and item display.

This commit is contained in:
=
2026-05-05 20:44:06 +02:00
parent abeb8c0902
commit ffe1077abc
14 changed files with 184 additions and 11 deletions
+7 -7
View File
@@ -3,25 +3,25 @@ using Godot;
public class Inventory
{
public List<Item> inventory = new();
public List<Item> items = new();
public int maxInventorySize = 8;
public bool AddItem(Item item, int amount)
{
Item inventoryItem = inventory.Find(x => x.data.Id == item.data.Id && x.currentAmount + amount <= x.data.StackSize);
Item inventoryItem = items.Find(x => x.data.Id == item.data.Id && x.currentAmount + amount <= x.data.StackSize);
if (inventoryItem != null)
{
GD.Print(inventory.IndexOf(inventoryItem) + ": " + inventoryItem.currentAmount);
GD.Print(items.IndexOf(inventoryItem) + ": " + inventoryItem.currentAmount);
inventoryItem.currentAmount += amount;
return true;
}
else
{
if (inventory.Count < maxInventorySize)
if (items.Count < maxInventorySize)
{
inventory.Add(item);
inventory[inventory.Count - 1].currentAmount += amount;
items.Add(item);
items[items.Count - 1].currentAmount += amount;
return true;
}
}
@@ -34,7 +34,7 @@ public class Inventory
Item item;
foreach(Ingredient ingredient in neededIngredients)
{
item = inventory.Find(x => x.data.Id == ingredient.item && x.currentAmount >= ingredient.amount * amount);
item = items.Find(x => x.data.Id == ingredient.item && x.currentAmount >= ingredient.amount * amount);
if (item == null)
{
canCraft = false;