# HG changeset patch # User Jason Maltzen # Date 2018-05-21 20:05:00 # Node ID 66a2d6c441ac65c593b399edb0167f415f72acc4 # Parent b12642d19557e5c6a1241c2c0a5b60721fcfffaa Add a debug log to paint recipe generation diff --git a/RecipeGenerator.cs b/RecipeGenerator.cs --- a/RecipeGenerator.cs +++ b/RecipeGenerator.cs @@ -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; diff --git a/UI/RecipeGeneratorView.cs b/UI/RecipeGeneratorView.cs --- a/UI/RecipeGeneratorView.cs +++ b/UI/RecipeGeneratorView.cs @@ -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);