RecipeManager.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Linq;
  2. using Robust.Shared.Prototypes;
  3. namespace Content.Shared.Kitchen
  4. {
  5. public sealed class RecipeManager
  6. {
  7. [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
  8. public List<FoodRecipePrototype> Recipes { get; private set; } = new();
  9. public void Initialize()
  10. {
  11. Recipes = new List<FoodRecipePrototype>();
  12. foreach (var item in _prototypeManager.EnumeratePrototypes<FoodRecipePrototype>())
  13. {
  14. if (!item.SecretRecipe)
  15. Recipes.Add(item);
  16. }
  17. Recipes.Sort(new RecipeComparer());
  18. }
  19. /// <summary>
  20. /// Check if a prototype ids appears in any of the recipes that exist.
  21. /// </summary>
  22. public bool SolidAppears(string solidId)
  23. {
  24. return Recipes.Any(recipe => recipe.IngredientsSolids.ContainsKey(solidId));
  25. }
  26. private sealed class RecipeComparer : Comparer<FoodRecipePrototype>
  27. {
  28. public override int Compare(FoodRecipePrototype? x, FoodRecipePrototype? y)
  29. {
  30. if (x == null || y == null)
  31. {
  32. return 0;
  33. }
  34. var nx = x.IngredientCount();
  35. var ny = y.IngredientCount();
  36. return -nx.CompareTo(ny);
  37. }
  38. }
  39. }
  40. }