From 1f46626c1d98f37b1fdb65abf6f4dea271494689 Mon Sep 17 00:00:00 2001
From: miepzerino <o.skotnik@gmail.com>
Date: Tue, 01 Apr 2025 15:53:40 +0000
Subject: [PATCH] fixed ruletileset

---
 Assets/Scripts/Inventory/ItemDatabase.cs |   75 +++++++++++++++++++++++++++++++++++++
 1 files changed, 75 insertions(+), 0 deletions(-)

diff --git a/Assets/Scripts/Inventory/ItemDatabase.cs b/Assets/Scripts/Inventory/ItemDatabase.cs
new file mode 100644
index 0000000..c0a0067
--- /dev/null
+++ b/Assets/Scripts/Inventory/ItemDatabase.cs
@@ -0,0 +1,75 @@
+using System.Collections.Generic;
+using UnityEngine;
+
+public class ItemDatabase : MonoBehaviour
+{
+    public static ItemDatabase Instance { get; private set; }
+
+    [SerializeField]
+    private List<Item> items = new List<Item>();
+
+    private Dictionary<string, Item> itemDictionary = new Dictionary<string, Item>();
+    private Dictionary<int, Item> itemIdDictionary = new Dictionary<int, Item>();
+
+    private void Awake()
+    {
+        if (Instance == null)
+        {
+            Instance = this;
+            InitializeItemDictionary();
+        }
+        else
+        {
+            Destroy(gameObject);
+        }
+    }
+
+    private void InitializeItemDictionary()
+    {
+        itemDictionary.Clear();
+        itemIdDictionary.Clear();
+
+        foreach (Item item in items)
+        {
+            if (!itemDictionary.ContainsKey(item.itemName))
+            {
+                itemDictionary.Add(item.itemName, item);
+            }
+            else
+            {
+                Debug.LogError($"Duplicate item name found in ItemDatabase: {item.itemName}");
+            }
+
+            if (!itemIdDictionary.ContainsKey(item.itemId))
+            {
+                itemIdDictionary.Add(item.itemId, item);
+            }
+            else
+            {
+                Debug.LogError($"Duplicate item ID found in ItemDatabase: {item.itemId}");
+            }
+        }
+    }
+
+    public Item GetItem(string itemName)
+    {
+        if (itemDictionary.TryGetValue(itemName, out Item item))
+        {
+            return item;
+        }
+
+        Debug.LogWarning($"Item not found in database: {itemName}");
+        return null;
+    }
+
+    public Item GetItem(int itemId)
+    {
+        if (itemIdDictionary.TryGetValue(itemId, out Item item))
+        {
+            return item;
+        }
+
+        Debug.LogWarning($"Item not found in database: ID {itemId}");
+        return null;
+    }
+}

--
Gitblit v1.9.3