99 lines
3.3 KiB
C#
99 lines
3.3 KiB
C#
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.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 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 if (ItemType == ItemType.Ingredient)
|
|
{
|
|
Count = InventoryManager.Instance.GetItemCount(Id);
|
|
}
|
|
}
|
|
}
|
|
} |