# HG changeset patch # User Jason Maltzen # Date 2021-09-09 23:59:27 # Node ID a930076422652e083c5d7ddac36137ba772e3562 # Parent a8c7548cacbbe4a8c7934f40223b564473201de6 Add a utility on a paint recipe to find the list of missing reaction pairs for that recipe diff --git a/Models/PaintRecipe.cs b/Models/PaintRecipe.cs --- a/Models/PaintRecipe.cs +++ b/Models/PaintRecipe.cs @@ -176,8 +176,8 @@ namespace DesertPaintCodex.Models Debug.Assert(reactions != null); // track visited reagents so the reaction is only applied once - HashSet reagentSet = new(); - List prevReagents = new(); + HashSet reagentSet = new(); + List prevReagents = new(); foreach (ReagentQuantity ingredient in _recipe) { @@ -360,5 +360,41 @@ namespace DesertPaintCodex.Models return false; } + + public List<(string, string)> MissingReactionPairs() + { + ReactionSet? reactions = ProfileManager.CurrentProfile?.Reactions; + Debug.Assert(reactions != null); + + HashSet reagentSet = new(); + List prevReagents = new(); + + List<(string, string)> missingReactionPairs = new List<(string, string)>(16); + + foreach (ReagentQuantity ingredient in _recipe) + { + if (reagentSet.Count > 4) return missingReactionPairs; // no more reactions + + string reagentName = ingredient.Name; + if (string.IsNullOrEmpty(reagentName)) continue; + if (reagentSet.Contains(reagentName)) continue; + reagentSet.Add(reagentName); + + Reagent reagent = ReagentService.GetReagent(reagentName); + + // Find reactions. + foreach (Reagent prevReagent in prevReagents) + { + Reaction? reaction = reactions.Find(prevReagent, reagent); + if (reaction == null) + { + missingReactionPairs.Add((prevReagent.Name, reagentName)); + } + } + prevReagents.Add(reagent); + } + + return missingReactionPairs; + } } }