2023-01-19 03:56:45 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Robust.Shared.Prototypes;
|
2020-04-30 18:08:51 -05:00
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2024-09-02 09:49:00 -04:00
|
|
|
|
if (!item.SecretRecipe)
|
|
|
|
|
|
Recipes.Add(item);
|
2020-04-30 18:08:51 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
|
public bool SolidAppears(string solidId)
|
|
|
|
|
|
{
|
2023-01-19 03:56:45 +01:00
|
|
|
|
return Recipes.Any(recipe => recipe.IngredientsSolids.ContainsKey(solidId));
|
2020-06-05 11:46:34 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-09-10 18:47:37 -07:00
|
|
|
|
var nx = x.IngredientCount();
|
|
|
|
|
|
var ny = y.IngredientCount();
|
|
|
|
|
|
return -nx.CompareTo(ny);
|
2020-04-30 18:08:51 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|