diff --git a/Assets/Scripts/Inventory/Inventory.cs b/Assets/Scripts/Inventory/Inventory.cs index 87f482f..cccbeb9 100644 --- a/Assets/Scripts/Inventory/Inventory.cs +++ b/Assets/Scripts/Inventory/Inventory.cs @@ -23,31 +23,23 @@ public class Inventory : MonoBehaviour public delegate void OnItemChanged(); - public OnItemChanged onItemChangedCallback; // + public OnItemChanged onItemChangedCallback; + + [SerializeField] + int numberOfSlots = 20; [SerializeField] List inventory = new List(); public List getInventory { get => inventory;} - public void createEmptyInventory(int numberOfSlots, int maxSpaceOfSlots = 10) - { - // Initializes the inventory with a specific number of slots and slotsize. - // !!!Has to be called bevore adding any items!!! - // Example createEmptyInventory(5, 10) : 5 Slots with space for 10 items each - for (int i = 0; i < numberOfSlots; i++) - { - inventory.Add(new Slot(maxSpaceOfSlots)); - } - if (onItemChangedCallback != null) - onItemChangedCallback.Invoke(); - } + public void addInventorySlots(int numberOfSlots, int maxSpaceOfSlots = 10) { // Adds a specific number of slots and slotsize to the inventory. // Example addInventorySlots(5, 10) : Adds 5 Slots with space for 10 items each for (int i = 0; i < numberOfSlots; i++) { - inventory.Add(new Slot(maxSpaceOfSlots)); + inventory.Add(new Slot()); } if (onItemChangedCallback != null) onItemChangedCallback.Invoke(); @@ -142,4 +134,30 @@ public class Inventory : MonoBehaviour return false; } } + + /* + public int addItem(Item itemType, int count = 1) + { + foreach (Slot slot in inventory) + { + if (slot.ItemType.Equals(itemType)) + { + slot. + } + } + }*/ + + + void Start() + { + // Init Inventory + for (int i = 0; i < numberOfSlots; i++) + { + inventory.Add(new Slot()); + } + if (onItemChangedCallback != null) + onItemChangedCallback.Invoke(); + + } + } diff --git a/Assets/Scripts/Inventory/Slot.cs b/Assets/Scripts/Inventory/Slot.cs index 2a5fe68..af51f81 100644 --- a/Assets/Scripts/Inventory/Slot.cs +++ b/Assets/Scripts/Inventory/Slot.cs @@ -18,15 +18,12 @@ public class Slot /// Item item; - int maxItems = 1; int count = 0; public Item ItemType { get => item; set => item = value; } public int Count { get => count; set => count = value; } - public int MaxItems { get => maxItems; set => maxItems = value; } - public Slot(int maxItems = 1) + public Slot() { item = null; - this.maxItems = maxItems; } public void addItem(int count = 1) { @@ -45,7 +42,7 @@ public class Slot } public Slot copy() { - Slot slot = new Slot(maxItems); + Slot slot = new Slot(); slot.count = count; slot.ItemType = ItemType;