84 lines
3.4 KiB
C#
84 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace DDD
|
|
{
|
|
public static class ItemViewModelFactory
|
|
{
|
|
public static List<ItemViewModel> CreateRestaurantManagementInventoryItem(Func<ItemData, bool> predicate)
|
|
{
|
|
var result = new List<ItemViewModel>();
|
|
var recipeDataMap = DataManager.Instance.RecipeDataSo.GetDataList().ToDictionary(r => r.Id, r => r);
|
|
var foodDataMap = DataManager.Instance.FoodDataSo.GetDataList().ToDictionary(f => f.Id, f => f);
|
|
var drinkDataMap = DataManager.Instance.DrinkDataSo.GetDataList().ToDictionary(d => d.Id, d => d);
|
|
var ingredientDataMap = DataManager.Instance.IngredientDataSo.GetDataList().ToDictionary(i => i.Id, i => i);
|
|
|
|
foreach (var kvp in InventoryManager.Instance.InventoryItems)
|
|
{
|
|
var id = kvp.Key;
|
|
var item = InventoryManager.Instance.GetItemDataByIdOrNull(id);
|
|
if (item == null || !predicate(item)) continue;
|
|
|
|
var model = new ItemViewModel
|
|
{
|
|
Id = item.Id,
|
|
ItemType = item.ItemType,
|
|
Icon = DataManager.Instance.GetSprite(id),
|
|
Count = item.ItemType switch
|
|
{
|
|
ItemType.Recipe => CalculateCraftableCount(item.Id),
|
|
ItemType.Ingredient => InventoryManager.Instance.GetItemCount(id),
|
|
_ => null
|
|
}
|
|
};
|
|
|
|
if (recipeDataMap.TryGetValue(item.Id, out var recipe))
|
|
{
|
|
var itemKey = recipe.ItemKey;
|
|
|
|
switch (recipe.RecipeType)
|
|
{
|
|
case RecipeType.FoodRecipe:
|
|
if (foodDataMap.TryGetValue(itemKey, out var food))
|
|
{
|
|
model.NameKey = food.NameKey;
|
|
model.DescriptionKey = food.DescriptionKey;
|
|
}
|
|
break;
|
|
case RecipeType.DrinkRecipe:
|
|
if (drinkDataMap.TryGetValue(itemKey, out var drink))
|
|
{
|
|
model.NameKey = drink.NameKey;
|
|
model.DescriptionKey = drink.DescriptionKey;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
else if (ingredientDataMap.TryGetValue(item.Id, out var ingredient))
|
|
{
|
|
model.NameKey = ingredient.NameKey;
|
|
model.DescriptionKey = ingredient.DescriptionKey;
|
|
}
|
|
|
|
result.Add(model);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private static int CalculateCraftableCount(string recipeId)
|
|
{
|
|
if (!DataManager.Instance.RecipeDataSo.TryGetDataById(recipeId, out var recipe)) return 0;
|
|
|
|
string itemKey = recipe.ItemKey;
|
|
|
|
return recipe.RecipeType switch
|
|
{
|
|
RecipeType.FoodRecipe => DataManager.Instance.FoodDataSo.TryGetDataById(itemKey, out var food) ? food.GetCraftableCount() : 0,
|
|
RecipeType.DrinkRecipe => DataManager.Instance.DrinkDataSo.TryGetDataById(itemKey, out var drink) ? drink.GetCraftableCount() : 0,
|
|
_ => 0
|
|
};
|
|
}
|
|
}
|
|
} |