using System.Linq; using Robust.Shared.Prototypes; namespace Content.Shared.Kitchen { public sealed class RecipeManager { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; public List Recipes { get; private set; } = new(); public void Initialize() { Recipes = new List(); foreach (var item in _prototypeManager.EnumeratePrototypes()) { Recipes.Add(item); } Recipes.Sort(new RecipeComparer()); } /// /// Check if a prototype ids appears in any of the recipes that exist. /// public bool SolidAppears(string solidId) { return Recipes.Any(recipe => recipe.IngredientsSolids.ContainsKey(solidId)); } private sealed class RecipeComparer : Comparer { public override int Compare(FoodRecipePrototype? x, FoodRecipePrototype? y) { if (x == null || y == null) { return 0; } var nx = x.IngredientCount(); var ny = y.IngredientCount(); return -nx.CompareTo(ny); } } } }