2021-07-17 02:37:09 +02:00
|
|
|
|
using System.Collections.Generic;
|
2020-04-30 18:08:51 -05:00
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Shared.Kitchen
|
|
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class RecipeManager
|
2020-04-30 18:08:51 -05:00
|
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
|
|
|
2021-02-27 04:12:09 +01:00
|
|
|
|
public List<FoodRecipePrototype> Recipes { get; private set; } = new();
|
2020-04-30 18:08:51 -05:00
|
|
|
|
|
|
|
|
|
|
public void Initialize()
|
|
|
|
|
|
{
|
2020-04-30 23:07:27 -05:00
|
|
|
|
Recipes = new List<FoodRecipePrototype>();
|
|
|
|
|
|
foreach (var item in _prototypeManager.EnumeratePrototypes<FoodRecipePrototype>())
|
2020-04-30 18:08:51 -05:00
|
|
|
|
{
|
|
|
|
|
|
Recipes.Add(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Recipes.Sort(new RecipeComparer());
|
|
|
|
|
|
}
|
2020-06-05 11:46:34 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Check if a prototype ids appears in any of the recipes that exist.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="solidIds"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public bool SolidAppears(string solidId)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach(var recipe in Recipes)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(recipe.IngredientsSolids.ContainsKey(solidId))
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-16 00:23:23 -07:00
|
|
|
|
private sealed class RecipeComparer : Comparer<FoodRecipePrototype>
|
2020-04-30 18:08:51 -05:00
|
|
|
|
{
|
2021-02-27 04:12:09 +01:00
|
|
|
|
public override int Compare(FoodRecipePrototype? x, FoodRecipePrototype? y)
|
2020-04-30 18:08:51 -05:00
|
|
|
|
{
|
|
|
|
|
|
if (x == null || y == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2020-06-05 11:46:34 -05:00
|
|
|
|
|
2020-05-04 13:54:54 -04:00
|
|
|
|
return -x.IngredientsReagents.Count.CompareTo(y.IngredientsReagents.Count);
|
2020-04-30 18:08:51 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|