Changeset - d6859ea7177f
[Not reviewed]
default
0 1 0
Jason Maltzen - 3 years ago 2021-09-10 00:02:16
jason@hiddenachievement.com
Add some sanity checks on min/max concentration and min/max reagents in recipe generation. Also, clear out the search queue when generation has finished so the queue isn't loaded next time. This fixes the start/resume button state when entering the recipe generator after a prior run had finished.
1 file changed with 12 insertions and 0 deletions:
0 comments (0 inline, 0 general)
Services/RecipeGenerator.cs
Show inline comments
...
 
@@ -181,16 +181,22 @@ namespace DesertPaintCodex.Services
 

	
 
            MinConcentration = minConcentration;
 
            MaxConcentration = maxConcentration;
 
            MinReagents = minReagents;
 
            MaxReagents = maxReagents;
 
            FullQuantity = fullQuantity;
 
            FullQuantityDepth = fullQuantityDepth;
 

	
 
            // Sanity check
 
            if (MinConcentration < 10) MinConcentration = 10;
 
            if (MaxConcentration < MinConcentration) MaxConcentration = MinConcentration;
 
            if (MinReagents < 1) MinReagents = 1;
 
            if (MaxReagents < MinReagents) MaxReagents = MinReagents;
 

	
 
            // first, sort reagents by cost.
 
            InitSortedReagents();
 

	
 
            _totalReagents = (uint)_costSortedReagents.Count;
 

	
 
            // Pre-populate recipes list with:
 
            // 1) 1-ingredient recipes @ min concentration for all enabled ingredients with a count >= min concentration
 
            // 2) any previously-generated recipes
...
 
@@ -516,16 +522,22 @@ namespace DesertPaintCodex.Services
 
                //generatorThreads.Remove(Thread.CurrentThread);
 

	
 
                done = (_runningThreads == 0);
 
            }
 

	
 
            if (!done) return;
 
            
 
            _running       = false;
 
            if (!_requestCancel && !_searchQueue.IsEmpty)
 
            {
 
                Debug.WriteLine($"Recipe generation complete, but search queue isn't empty {_searchQueue.Count}.");
 
                WriteLog($"Recipe generation complete, but search queue isn't empty {_searchQueue.Count}.");
 
                _searchQueue.Clear();
 
            }
 
            _requestCancel = false;
 
            Finished?.Invoke(this, EventArgs.Empty);
 
        }
 

	
 
        // Add the cheapest recipe to the recipe list
 
        // returns the discarded recipe from the pair (or null if no original recipe to replace)
 
        private void AddCheapestRecipe(PaintRecipe recipe)
 
        {
0 comments (0 inline, 0 general)