using System; using System.Collections.Generic; using UnityEngine; namespace DDD { [Serializable] public class ItemViewModel { [field: SerializeField] public string Id { get; private set; } [field: SerializeField] public ItemType ItemType { get; private set; } [field: SerializeField] public int Count { get; private set; } public ItemViewModel(string id, ItemType itemType, int count) { Id = id; ItemType = itemType; Count = count; } public ItemViewModel(string id, ItemType itemType) { Id = id; ItemType = itemType; Count = 0; } public bool HasItem => Count > 0; public string DisplayName => LocalizationManager.Instance.GetName(Id); public RecipeType RecipeType => ItemType == ItemType.Recipe ? DataManager.Instance.GetDataSo().GetDataById(Id).RecipeType : RecipeType.None; public Sprite ItemSprite { get { if (ItemType == ItemType.Recipe) { DataManager.Instance.GetDataSo().TryGetDataById(Id, out var recipe); return DataManager.Instance.GetSprite(recipe.RecipeResult); } if (DataManager.Instance.GetDataSo().ContainsData(Id)) { return DataManager.Instance.GetIcon(Id); } return DataManager.Instance.GetSprite(Id); } } public string GetRecipeResultKey { get { if (ItemType != ItemType.Recipe) return null; return DataManager.Instance.GetDataSo().GetDataById(Id).RecipeResult; } } public Sprite GetCookwareIcon { get { var resultKey = GetRecipeResultKey; if (resultKey == null) return null; string cookwareKey = null; if (RecipeType == RecipeType.FoodRecipe) { cookwareKey = DataManager.Instance.GetDataSo().GetDataById(resultKey).CookwareKey; } else if (RecipeType == RecipeType.DrinkRecipe) { cookwareKey = DataManager.Instance.GetDataSo().GetDataById(resultKey).CookwareKey; } return DataManager.Instance.GetIcon(cookwareKey); } } public List GetTasteDatas { get { switch (RecipeType) { case RecipeType.FoodRecipe: return DataManager.Instance.GetDataSo().GetDataById(GetRecipeResultKey).GetTasteDatas(); case RecipeType.DrinkRecipe: return DataManager.Instance.GetDataSo().GetDataById(GetRecipeResultKey).GetTasteDatas(); } return null; } } public void SetCount(int count) => Count = count; public void UpdateCount() { if (ItemType == ItemType.Recipe) { int craftableCount = 0; string resultKey = GetRecipeResultKey; if (RecipeType == RecipeType.FoodRecipe) { var foodData = DataManager.Instance.GetDataSo().GetDataById(resultKey); craftableCount = foodData.GetCraftableCount(); } else if (RecipeType == RecipeType.DrinkRecipe) { var drinkData = DataManager.Instance.GetDataSo().GetDataById(resultKey); craftableCount = drinkData.GetCraftableCount(); } Count = craftableCount; } else { Count = InventoryManager.Instance.GetItemCount(Id); } } } }