ProjectDDD/Assets/_DDD/_Scripts/GameUi/RestaurantManagementUi/ItemUi/ItemViewModel.cs
2025-08-04 08:09:01 +09:00

117 lines
3.9 KiB
C#

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<RecipeDataSo>().GetDataById(Id).RecipeType : RecipeType.None;
public Sprite ItemSprite
{
get
{
if (ItemType == ItemType.Recipe)
{
DataManager.Instance.GetDataSo<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.GetDataSo<FoodDataSo>().GetDataById(GetRecipeResultKey).CookwareKey;
break;
case RecipeType.DrinkRecipe:
cookwareSpriteKey = DataManager.Instance.GetDataSo<DrinkDataSo>().GetDataById(GetRecipeResultKey).CookwareKey;
break;
}
return DataManager.Instance.GetSprite(cookwareSpriteKey);
}
}
public string GetRecipeResultKey
{
get
{
if (ItemType != ItemType.Recipe) return null;
return DataManager.Instance.GetDataSo<RecipeDataSo>().GetDataById(Id).RecipeResult;
}
}
public List<TasteData> GetTasteDatas
{
get
{
switch (RecipeType)
{
case RecipeType.FoodRecipe:
return DataManager.Instance.GetDataSo<FoodDataSo>().GetDataById(GetRecipeResultKey).GetTasteDatas();
case RecipeType.DrinkRecipe:
return DataManager.Instance.GetDataSo<DrinkDataSo>().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<FoodDataSo>().GetDataById(resultKey);
craftableCount = foodData.GetCraftableCount();
}
else if (RecipeType == RecipeType.DrinkRecipe)
{
var drinkData = DataManager.Instance.GetDataSo<DrinkDataSo>().GetDataById(resultKey);
craftableCount = drinkData.GetCraftableCount();
}
Count = craftableCount;
}
else
{
Count = InventoryManager.Instance.GetItemCount(Id);
}
}
}
}