using Cysharp.Threading.Tasks; using UnityEngine; namespace BulletHellTemplate { /// /// Handles saving and loading inventory-related data locally (such as item upgrade levels), /// and optionally syncing specific items to the backend. /// public class InventorySave : MonoBehaviour { public static InventorySave Singleton; private void Awake() { if (Singleton == null) { Singleton = this; } else { Destroy(gameObject); } } /// /// Attempts to change the upgrade level of a purchased item. /// The backend validates the operation; on success the change is cached locally. /// public static async UniTask UpgradeItemAsync(string uniqueItemGuid, InventoryItem inventorySO) { return await BackendManager.Service.UpgradeInventoryItemAsync(uniqueItemGuid,inventorySO); } /// /// Gets the item upgrade level from local data, returns 0 if not found. /// /// GUID of the purchased item. /// The upgrade level, or 0 if not found. public static int GetItemUpgradeLevel(string uniqueItemGuid) { return PlayerSave.GetItemUpgradeLevel(uniqueItemGuid); } /// /// Equips an item (assigns a GUID) in the given character's slot, saving to Firestore if needed. /// If uniqueItemGuid is empty, it means unequip and calls RemoveCharacterItemAsync. /// public static async UniTask SetEquippedItemForSlotAsync(int characterId, string slotName, string uniqueItemGuid) { RequestResult res = await BackendManager.Service.SetCharacterItemAsync(characterId, slotName, uniqueItemGuid); return res; } /// /// Returns the unique item GUID equipped in a specific slot for a given character, /// or empty string if none is equipped. /// public static string GetEquippedItemForSlot(int characterId, string slotName) { return PlayerSave.GetCharacterSlotItem(characterId, slotName) ?? ""; } /// /// Deletes a purchased inventory item everywhere (backend first, then local cache). /// public static async UniTask DeletePurchasedItemAsync(string uniqueItemGuid) { RequestResult res = await BackendManager.Service .DeletePurchasedInventoryItemAsync(uniqueItemGuid); if (res.Success) { UIInventoryMenu.Singleton?.UpdateInventoryUI(); } return res; } } }