using System.Collections.Generic; using UnityEngine; namespace DDD { public class ItemViewModel { public string Id; public ItemType ItemType; public int Count; public RecipeType RecipeType => ItemType == ItemType.Recipe ? DataManager.Instance.RecipeDataSo.GetDataById(Id).RecipeType : RecipeType.None; public Sprite ItemSprite { get { if (ItemType == ItemType.Recipe) { DataManager.Instance.RecipeDataSo.TryGetDataById(Id, out var recipe); return DataManager.Instance.GetSprite(recipe.RecipeResult); } return DataManager.Instance.GetSprite(Id); } } public Sprite GetCookwareSprite { get { if (ItemType != ItemType.Recipe) return null; string cookwareSpriteKey = null; switch (RecipeType) { case RecipeType.FoodRecipe: cookwareSpriteKey = DataManager.Instance.FoodDataSo.GetDataById(GetRecipeResultKey).CookwareType.ToString(); break; case RecipeType.DrinkRecipe: cookwareSpriteKey = DataManager.Instance.DrinkDataSo.GetDataById(GetRecipeResultKey).CookwareType.ToString(); break; } return DataManager.Instance.GetSprite(cookwareSpriteKey); } } public string GetRecipeResultKey { get { if (ItemType != ItemType.Recipe) return null; return DataManager.Instance.RecipeDataSo.GetDataById(Id).RecipeResult; } } public List GetTasteDatas { get { switch (RecipeType) { case RecipeType.FoodRecipe: return DataManager.Instance.FoodDataSo.GetDataById(GetRecipeResultKey).GetTasteDatas(); case RecipeType.DrinkRecipe: return DataManager.Instance.DrinkDataSo.GetDataById(GetRecipeResultKey).GetTasteDatas(); } return null; } } public void UpdateCount() { if (ItemType == ItemType.Recipe) { int craftableCount = 0; string resultKey = GetRecipeResultKey; if (RecipeType == RecipeType.FoodRecipe) { var foodData = DataManager.Instance.FoodDataSo.GetDataById(resultKey); craftableCount = foodData.GetCraftableCount(); } else if (RecipeType == RecipeType.DrinkRecipe) { var drinkData = DataManager.Instance.DrinkDataSo.GetDataById(resultKey); craftableCount = drinkData.GetCraftableCount(); } Count = craftableCount; } else if (ItemType == ItemType.Ingredient) { Count = InventoryManager.Instance.GetItemCount(Id); } } } }