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 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); } 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.GetDataSo().GetDataById(GetRecipeResultKey).CookwareKey; break; case RecipeType.DrinkRecipe: cookwareSpriteKey = DataManager.Instance.GetDataSo().GetDataById(GetRecipeResultKey).CookwareKey; break; } return DataManager.Instance.GetSprite(cookwareSpriteKey); } } public string GetRecipeResultKey { get { if (ItemType != ItemType.Recipe) return null; return DataManager.Instance.GetDataSo().GetDataById(Id).RecipeResult; } } 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); } } } }