using System; using System.Collections.Generic; using ColdMint.scripts.utils; using Godot; namespace ColdMint.scripts.item; public static class ItemTypeManager { // Register items statically here static ItemTypeManager() { } private static Dictionary Registry { get; } = []; private static Texture2D DefaultTexture { get; } = new PlaceholderTexture2D(); /// /// Register a item type. /// Return false if the item id already exist. /// /// Whether the registration was successful. public static bool Register(ItemType itemType) => Registry.TryAdd(itemType.Id, itemType); /// /// Creates a new instance of the item registered to the given id. /// Returns null when the id is not registered. /// public static IItem_New? NewItem(string id) => Registry.TryGetValue(id, out var itemType) ? itemType.NewItemFunc() : null; /// /// Get the translated default name of the item type for the given id /// /// /// Translated default name of the item id if it exists. Else, return the id itself /// public static string DefaultNameOf(string id) => TranslationServerUtils.Translate($"item_{id}") ?? id; /// /// Get the translated default description of the item type for the given id /// /// /// Translated default description of the item id if it exists. Else, return null /// public static string? DefaultDescriptionOf(string id) => TranslationServerUtils.Translate($"item_{id}_desc"); /// /// Get the default icon of the item type for the given id /// /// /// Translated default icon of the item id if it exists. Else, return a placeholder /// public static Texture2D DefaultIconOf(string id) => Registry.TryGetValue(id, out var itemType) ? itemType.Icon ?? DefaultTexture : DefaultTexture; public static int MaxStackQuantityOf(string id) => Registry.TryGetValue(id, out var itemType) ? itemType.MaxStackQuantity : 0; }