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
This commit is contained in:
Kevin Zheng
2022-09-10 18:47:37 -07:00
committed by GitHub
parent 9c5b9f4fec
commit c723d54a51
11 changed files with 780 additions and 175 deletions

View File

@@ -35,5 +35,21 @@ namespace Content.Shared.Kitchen
public IReadOnlyDictionary<string, FixedPoint2> IngredientsReagents => _ingsReagents;
public IReadOnlyDictionary<string, FixedPoint2> IngredientsSolids => _ingsSolids;
/// <summary>
/// Count the number of ingredients in a recipe for sorting the recipe list.
/// This makes sure that where ingredient lists overlap, the more complex
/// recipe is picked first.
/// </summary>
public FixedPoint2 IngredientCount()
{
FixedPoint2 n = 0;
n += _ingsReagents.Count; // number of distinct reagents
foreach (FixedPoint2 i in _ingsSolids.Values) // sum the number of solid ingredients
{
n += i;
}
return n;
}
}
}

View File

@@ -45,7 +45,9 @@ namespace Content.Shared.Kitchen
return 0;
}
return -x.IngredientsReagents.Count.CompareTo(y.IngredientsReagents.Count);
var nx = x.IngredientCount();
var ny = y.IngredientCount();
return -nx.CompareTo(ny);
}
}
}