Changeset - 66a2d6c441ac
[Not reviewed]
default
0 2 0
Jason Maltzen (jmaltzen) - 6 years ago 2018-05-21 20:05:00
jason.maltzen@unsanctioned.net
Add a debug log to paint recipe generation
2 files changed with 35 insertions and 24 deletions:
0 comments (0 inline, 0 general)
RecipeGenerator.cs
Show inline comments
...
 
@@ -583,16 +583,17 @@ namespace DesertPaintLab
 
                        {
 
                            recipes[colorName].CopyFrom(recipe);
 
                            recipeCosts[colorName] = recipe.Cost;
 
                            log?.WriteLine("New recipe (cost {0}): {1}", recipe.Cost, recipe);
 
                            if (NewRecipe != null)
 
                            {
 
                                NewRecipeEventArgs args = new NewRecipeEventArgs(colorName, recipe);
 
                                NewRecipe(this, args);
 
                            }
 
                        }
 
                        else
 
                        {
 
                            Console.WriteLine("Ignoring recipe - existing cost is cheaper.");
 
                        }
 
                        //else
 
                        //{
 
                        //    Console.WriteLine("Ignoring recipe - existing cost is cheaper.");
 
                        //}
 
                    }
 
                    else
 
                    {
...
 
@@ -609,14 +610,14 @@ namespace DesertPaintLab
 
            }
 
            else
 
            {
 
                string msg = String.Format("Recipe is invalid ({0} ingredients)\n", recipe.Ingredients.Count);
 
                foreach (PaintRecipe.RecipeIngredient ingr in recipe.Ingredients)
 
                {
 
                    msg += String.Format("    -> {0} {1}", ingr.quantity, ingr.name);
 
                }
 
                lock (workerLock) {
 
                    Console.WriteLine(msg);
 
                }
 
                //string msg = String.Format("Recipe is invalid ({0} ingredients)\n", recipe.Ingredients.Count);
 
                //foreach (PaintRecipe.RecipeIngredient ingr in recipe.Ingredients)
 
                //{
 
                //    msg += String.Format("    -> {0} {1}", ingr.quantity, ingr.name);
 
                //}
 
                //lock (workerLock) {
 
                //    Console.WriteLine(msg);
 
                //}
 
            }
 
        }
 

	
...
 
@@ -717,7 +718,7 @@ namespace DesertPaintLab
 
                    node.InitForQuantity(newQuantity);
 
                    if (node.CurrentTargetQuantity <= node.UsedQuantity)
 
                    {
 
                        if (log != null) { lock(log) { log.WriteLine("Update quantity to {0}", node.CurrentTargetQuantity); } }
 
                        //if (log != null) { lock(log) { log.WriteLine("Update quantity to {0}", node.CurrentTargetQuantity); } }
 
                        return true;
 
                    }
 
                }
...
 
@@ -766,7 +767,7 @@ namespace DesertPaintLab
 
                                    {
 
                                        // just popped the last reagent at the top level
 
                                        ++currentDepth;
 
                                        if (log != null) { lock(log) { log.WriteLine("Increased depth to {0}/{1}", currentDepth, node.MaxReagents); } }
 
                                        //if (log != null) { lock(log) { log.WriteLine("Increased depth to {0}/{1}", currentDepth, node.MaxReagents); } }
 
                                    }
 
                                }
 
                            }
...
 
@@ -778,7 +779,7 @@ namespace DesertPaintLab
 
                                {
 
                                    // just popped the last reagent at the top level
 
                                    ++currentDepth;
 
                                    if (log != null) { lock(log) { log.WriteLine("Increased depth to {0}/{1} [pop last reagent at top level]", currentDepth, node.MaxReagents); } }
 
                                    //if (log != null) { lock(log) { log.WriteLine("Increased depth to {0}/{1} [pop last reagent at top level]", currentDepth, node.MaxReagents); } }
 
                                }
 
                            }
 
                        }
...
 
@@ -790,7 +791,7 @@ namespace DesertPaintLab
 
                            {
 
                                if (! node.AddNextReagent())
 
                                {
 
                                    if (log != null) { lock(log) { log.WriteLine("Failed to reagent {0}/{1}", node.ReagentCount+1, currentDepth); } }
 
                                    //if (log != null) { lock(log) { log.WriteLine("Failed to add reagent {0}/{1}", node.ReagentCount+1, currentDepth); } }
 
                                    recipeFound = false;
 
                                }
 
                            }
...
 
@@ -805,7 +806,7 @@ namespace DesertPaintLab
 
                else
 
                {
 
                    ++currentDepth;
 
                    if (log != null) { lock(log) { log.WriteLine("Increased depth to {0}/{1} [no recipe]", currentDepth, node.MaxReagents); } }
 
                    //if (log != null) { lock(log) { log.WriteLine("Increased depth to {0}/{1} [no recipe]", currentDepth, node.MaxReagents); } }
 
                }
 
            } while (currentDepth <= maxReagents);
 
            if (recipeFound)
...
 
@@ -822,12 +823,12 @@ namespace DesertPaintLab
 
                    node.TestRecipe.AddReagent(node.Reagent(i).Name, node.CurrentWeights[i]);
 
                }
 
                if (log != null) { 
 
                    string combo = "";
 
                    foreach (PaintRecipe.RecipeIngredient ingr in node.TestRecipe.Ingredients)
 
                    {
 
                        combo += " " + ingr.name;
 
                    }
 
                    lock(log) { log.WriteLine("New ingredients: " + combo); }
 
                    //string combo = "";
 
                    //foreach (PaintRecipe.RecipeIngredient ingr in node.TestRecipe.Ingredients)
 
                    //{
 
                    //    combo += " " + ingr.name;
 
                    //}
 
                    //lock(log) { log.WriteLine("New ingredients: " + combo); }
 
                }
 
            }
 

	
...
 
@@ -857,7 +858,7 @@ namespace DesertPaintLab
 
            if (remainingWeight < MinConcentration)
 
            {
 
                // not possible to make a valid recipe
 
                Console.WriteLine("Insufficient remaining weight");
 
                //Console.WriteLine("Insufficient remaining weight");
 
                return false;
 
            }
 
            //uint remainingReagents = (uint)node.Reagents.Count - node.CatalystCount;
UI/RecipeGeneratorView.cs
Show inline comments
...
 
@@ -241,6 +241,16 @@ namespace DesertPaintLab
 
                generator.Progress += OnProgress;
 
                generator.Finished += OnFinished;
 
                generator.NewRecipe += OnNewRecipe;
 

	
 
                bool enableDebugMenu = false;
 
                DesertPaintLab.AppSettings.Get("EnableDebugMenu", out enableDebugMenu);
 
                bool logGenerator = false;
 
                DesertPaintLab.AppSettings.Get("GeneratorLog", out logGenerator);
 
                if (enableDebugMenu && logGenerator)
 
                {
 
                    string logDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
 
                    generator.Log = System.IO.Path.Combine(logDir, "dpl_generator.txt");
 
                }
 
            }
 
            generator.InitRecipes(profile.Recipes);
 

	
0 comments (0 inline, 0 general)