Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 23 additions & 37 deletions Content.Shared/Kitchen/RecipeManager.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,32 @@
using System.Linq;
using System.Linq;
using Robust.Shared.Prototypes;

namespace Content.Shared.Kitchen
{
public sealed class RecipeManager
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
namespace Content.Shared.Kitchen;

public List<FoodRecipePrototype> Recipes { get; private set; } = new();
public sealed class RecipeManager
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;

public void Initialize()
{
Recipes = new List<FoodRecipePrototype>();
foreach (var item in _prototypeManager.EnumeratePrototypes<FoodRecipePrototype>())
{
if (!item.SecretRecipe)
Recipes.Add(item);
}
public List<FoodRecipePrototype> Recipes { get; private set; } = new();

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));
}
public void Initialize()
{
ReloadRecipes();
_prototypeManager.PrototypesReloaded += OnPrototypesReloaded;
}

private sealed class RecipeComparer : Comparer<FoodRecipePrototype>
{
public override int Compare(FoodRecipePrototype? x, FoodRecipePrototype? y)
{
if (x == null || y == null)
{
return 0;
}
private void OnPrototypesReloaded(PrototypesReloadedEventArgs args)
{
if (args.WasModified<FoodRecipePrototype>())
ReloadRecipes();
}

var nx = x.IngredientCount();
var ny = y.IngredientCount();
return -nx.CompareTo(ny);
}
}
private void ReloadRecipes()
{
Recipes = _prototypeManager
.EnumeratePrototypes<FoodRecipePrototype>()
.Where(x => !x.SecretRecipe)
.OrderByDescending(x => x.IngredientCount())
.ToList();
}
}
Loading