ProjectDDD/Assets/_DDD/_Scripts/GameUi/RestaurantManagementUi/ItemUi/ItemViewModel.cs

99 lines
3.2 KiB
C#
Raw Normal View History

2025-07-27 22:55:07 +00:00
using System.Collections.Generic;
2025-07-25 07:58:53 +00:00
using UnityEngine;
namespace DDD
{
public class ItemViewModel
{
public string Id;
public ItemType ItemType;
2025-07-27 19:32:41 +00:00
public int Count;
2025-07-25 07:58:53 +00:00
2025-07-27 19:32:41 +00:00
public RecipeType RecipeType => ItemType == ItemType.Recipe ? DataManager.Instance.RecipeDataSo.GetDataById(Id).RecipeType : RecipeType.None;
2025-07-28 11:33:04 +00:00
public Sprite ItemSprite
2025-07-25 07:58:53 +00:00
{
2025-07-28 11:33:04 +00:00
get
2025-07-27 19:32:41 +00:00
{
2025-07-28 11:33:04 +00:00
if (ItemType == ItemType.Recipe)
2025-07-27 19:32:41 +00:00
{
2025-07-28 11:33:04 +00:00
DataManager.Instance.RecipeDataSo.TryGetDataById(Id, out var recipe);
return DataManager.Instance.GetSprite(recipe.RecipeResult);
2025-07-27 19:32:41 +00:00
}
2025-07-28 11:33:04 +00:00
return DataManager.Instance.GetSprite(Id);
2025-07-27 19:32:41 +00:00
}
2025-07-25 07:58:53 +00:00
}
2025-07-27 22:55:07 +00:00
2025-07-29 15:56:47 +00:00
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);
}
}
2025-07-28 11:33:04 +00:00
public string GetRecipeResultKey
2025-07-27 22:55:07 +00:00
{
get
{
if (ItemType != ItemType.Recipe) return null;
2025-07-28 11:33:04 +00:00
return DataManager.Instance.RecipeDataSo.GetDataById(Id).RecipeResult;
2025-07-27 22:55:07 +00:00
}
}
public List<TasteData> GetTasteDatas
{
get
{
switch (RecipeType)
{
case RecipeType.FoodRecipe:
2025-07-28 11:33:04 +00:00
return DataManager.Instance.FoodDataSo.GetDataById(GetRecipeResultKey).GetTasteDatas();
2025-07-27 22:55:07 +00:00
case RecipeType.DrinkRecipe:
2025-07-28 11:33:04 +00:00
return DataManager.Instance.DrinkDataSo.GetDataById(GetRecipeResultKey).GetTasteDatas();
2025-07-27 22:55:07 +00:00
}
return null;
}
}
2025-07-29 15:56:47 +00:00
public void UpdateCount()
2025-07-28 11:33:04 +00:00
{
if (ItemType == ItemType.Recipe)
{
int craftableCount = 0;
2025-07-29 15:56:47 +00:00
string resultKey = GetRecipeResultKey;
2025-07-28 11:33:04 +00:00
if (RecipeType == RecipeType.FoodRecipe)
{
2025-07-29 15:56:47 +00:00
var foodData = DataManager.Instance.FoodDataSo.GetDataById(resultKey);
craftableCount = foodData.GetCraftableCount();
2025-07-28 11:33:04 +00:00
}
else if (RecipeType == RecipeType.DrinkRecipe)
{
2025-07-29 15:56:47 +00:00
var drinkData = DataManager.Instance.DrinkDataSo.GetDataById(resultKey);
craftableCount = drinkData.GetCraftableCount();
2025-07-28 11:33:04 +00:00
}
Count = craftableCount;
}
2025-07-29 15:56:47 +00:00
else if (ItemType == ItemType.Ingredient)
2025-07-28 11:33:04 +00:00
{
2025-07-29 15:56:47 +00:00
Count = InventoryManager.Instance.GetItemCount(Id);
2025-07-28 11:33:04 +00:00
}
}
2025-07-25 07:58:53 +00:00
}
}