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

122 lines
4.0 KiB
C#
Raw Normal View History

2025-08-03 23:09:01 +00:00
using System;
2025-07-27 22:55:07 +00:00
using System.Collections.Generic;
2025-07-25 07:58:53 +00:00
using UnityEngine;
namespace DDD
{
2025-08-03 23:09:01 +00:00
[Serializable]
2025-07-25 07:58:53 +00:00
public class ItemViewModel
{
2025-08-03 23:09:01 +00:00
[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;
}
2025-07-25 07:58:53 +00:00
public RecipeType RecipeType => ItemType == ItemType.Recipe ? DataManager.Instance.GetDataSo<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
{
DataManager.Instance.GetDataSo<RecipeDataSo>().TryGetDataById(Id, out var recipe);
2025-07-28 11:33:04 +00:00
return DataManager.Instance.GetSprite(recipe.RecipeResult);
2025-07-27 19:32:41 +00:00
}
2025-08-06 02:45:35 +00:00
if (DataManager.Instance.GetDataSo<CookwareDataSo>().ContainsData(Id))
{
return DataManager.Instance.GetIcon(Id);
}
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.GetDataSo<FoodDataSo>().GetDataById(GetRecipeResultKey).CookwareKey;
2025-07-29 15:56:47 +00:00
break;
case RecipeType.DrinkRecipe:
cookwareSpriteKey = DataManager.Instance.GetDataSo<DrinkDataSo>().GetDataById(GetRecipeResultKey).CookwareKey;
2025-07-29 15:56:47 +00:00
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;
return DataManager.Instance.GetDataSo<RecipeDataSo>().GetDataById(Id).RecipeResult;
2025-07-27 22:55:07 +00:00
}
}
public List<TasteData> GetTasteDatas
{
get
{
switch (RecipeType)
{
case RecipeType.FoodRecipe:
return DataManager.Instance.GetDataSo<FoodDataSo>().GetDataById(GetRecipeResultKey).GetTasteDatas();
2025-07-27 22:55:07 +00:00
case RecipeType.DrinkRecipe:
return DataManager.Instance.GetDataSo<DrinkDataSo>().GetDataById(GetRecipeResultKey).GetTasteDatas();
2025-07-27 22:55:07 +00:00
}
return null;
}
}
2025-07-29 15:56:47 +00:00
2025-08-03 23:09:01 +00:00
public void SetCount(int count) => Count = count;
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)
{
var foodData = DataManager.Instance.GetDataSo<FoodDataSo>().GetDataById(resultKey);
2025-07-29 15:56:47 +00:00
craftableCount = foodData.GetCraftableCount();
2025-07-28 11:33:04 +00:00
}
else if (RecipeType == RecipeType.DrinkRecipe)
{
var drinkData = DataManager.Instance.GetDataSo<DrinkDataSo>().GetDataById(resultKey);
2025-07-29 15:56:47 +00:00
craftableCount = drinkData.GetCraftableCount();
2025-07-28 11:33:04 +00:00
}
Count = craftableCount;
}
2025-08-03 23:09:01 +00:00
else
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
}
}