Files
tbd-station-14/Content.Shared/Kitchen/RecipeManager.cs
Kevin Zheng c723d54a51 Chef update (#11189)
* Sort recipes based on total ingredient count

Fix the recipe sort function so that recipes with more ingredients are
matched first. This fixes vegetable pizzas and allows more complex
recipes in the future.

* Chef update

* Pet linter
2022-09-10 20:47:37 -05:00

55 lines
1.5 KiB
C#

using Robust.Shared.Prototypes;
namespace Content.Shared.Kitchen
{
public sealed class RecipeManager
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public List<FoodRecipePrototype> Recipes { get; private set; } = new();
public void Initialize()
{
Recipes = new List<FoodRecipePrototype>();
foreach (var item in _prototypeManager.EnumeratePrototypes<FoodRecipePrototype>())
{
Recipes.Add(item);
}
Recipes.Sort(new RecipeComparer());
}
/// <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;
}
private sealed class RecipeComparer : Comparer<FoodRecipePrototype>
{
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);
}
}
}
}