Files
crystall-punk-14/Content.Shared/Kitchen/RecipeManager.cs

47 lines
1.4 KiB
C#
Raw Permalink Normal View History

using System.Linq;
using Robust.Shared.Prototypes;
2020-04-30 18:08:51 -05:00
namespace Content.Shared.Kitchen
{
public sealed class RecipeManager
2020-04-30 18:08:51 -05:00
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
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
{
if (!item.SecretRecipe)
Recipes.Add(item);
2020-04-30 18:08:51 -05:00
}
Recipes.Sort(new RecipeComparer());
}
/// <summary>
/// Check if a prototype ids appears in any of the recipes that exist.
/// </summary>
public bool SolidAppears(string solidId)
{
return Recipes.Any(recipe => recipe.IngredientsSolids.ContainsKey(solidId));
}
private sealed class RecipeComparer : Comparer<FoodRecipePrototype>
2020-04-30 18:08:51 -05:00
{
public override int Compare(FoodRecipePrototype? x, FoodRecipePrototype? y)
2020-04-30 18:08:51 -05:00
{
if (x == null || y == null)
{
return 0;
}
var nx = x.IngredientCount();
var ny = y.IngredientCount();
return -nx.CompareTo(ny);
2020-04-30 18:08:51 -05:00
}
}
}
}