Changeset - 1846a628223c
[Not reviewed]
default
0 1 0
Jason Maltzen (jmaltzen) - 9 years ago 2016-01-15 17:23:21
jason.maltzen@unsanctioned.net
Use luminance value to determine whether exported wiki color text should be white-on-color instead of default black-on-color
1 file changed with 13 insertions and 1 deletions:
0 comments (0 inline, 0 general)
PlayerProfile.cs
Show inline comments
...
 
@@ -417,75 +417,87 @@ namespace DesertPaintLab
 
                string recipeFile = System.IO.Path.Combine(directory, "dp_recipes.txt");
 
                using (StreamWriter writer = new StreamWriter(recipeFile, false))
 
                {
 
                    foreach (KeyValuePair<string, PaintRecipe> pair in recipes)
 
                    {
 
                        writer.WriteLine("--- Recipe: {0}", pair.Key);
 
                        foreach (PaintRecipe.RecipeIngredient ingredient in pair.Value.Ingredients)
 
                        {
 
                            writer.WriteLine("{0,-14} | {1}", ingredient.name, ingredient.quantity);
 
                        }
 
                    }
 
                }
 
            }
 
        }
 

 
        public void ExportWikiRecipes(string file)
 
        {
 
            StreamWriter writer = new StreamWriter(file);
 
            ExportWikiFormat(writer);
 
        }
 
		
 
        public void ExportWikiFormat(TextWriter writer)
 
        {
 
            PaintRecipe recipe;
 
            List<KeyValuePair<string, string>> missing = new List<KeyValuePair<string, string>>();
 
            using (writer)
 
            {
 
                writer.WriteLine("{| class='wikitable sortable' border=\"1\" style=\"background-color:#DEB887;\"");
 
                writer.WriteLine("! Color !! Recipe !! Verified");    
 
                foreach (PaintColor color in Palette.Colors)
 
                {
 
                    writer.WriteLine("|-");
 
                    string colorLine = "| ";
 
                    colorLine += "style=\"font-weight: bold; background-color: #" + color.Red.ToString("X2") + color.Green.ToString("X2") + color.Blue.ToString("X2") + ";";
 
                    if (color.Red < 128 && color.Green < 128 && color.Blue < 128)
 
                    float rPortion = color.Red / 255.0f;
 
                    float gPortion = color.Green / 255.0f;
 
                    float bPortion = color.Blue / 255.0f;
 
                    float maxColor = Math.Max(rPortion, Math.Max(gPortion, bPortion));
 
                    float minColor = Math.Min(rPortion, Math.Min(gPortion, bPortion));
 
                    float luminance = (maxColor - minColor) * 0.5f;
 
                    if (luminance < 0.5f)
 
                    {
 
                        // dark color gets light text
 
                        colorLine += " color: #FFFFFF;";
 
                    }
 
                    colorLine += "\" | " + color.Name + " || ";
 
                    if (recipes.TryGetValue(color.Name, out recipe))
 
                    {
 
                        foreach (PaintRecipe.RecipeIngredient ingredient in recipe.Ingredients)
 
                        {
 
                            colorLine += " " + ingredient.ToString();
 
                        }
 
                    } 
 
                    else
 
                    {
 
                        // no recipe
 
                    }
 
                    colorLine += " || ";
 
                    
 
                    if (recipe.CheckMissingReactions(ref missing) == false)
 
                    {
 
                        colorLine += "Y";
 
                    }
 
                    writer.WriteLine(colorLine);
 
                }
 
                writer.WriteLine("|}");
 
            }
 
        }
 
        
 
		public Reaction FindReaction(Reagent reagent1, Reagent reagent2)
 
		{
 
            return reactions.Find(reagent1, reagent2);
 
		}
 
		
 
		public void SetReaction(Reagent reagent1, Reagent reagent2, Reaction reaction)
 
		{
 
            reactions.Set(reagent1, reagent2, reaction);
 
		}
 

 
        public void SetRecipe(PaintRecipe recipe)
 
        {
 
            string colorName = Palette.FindNearest(recipe.ReactedColor);
 
            recipes[colorName].CopyFrom(recipe);
 
        }
 
	}
 
}
 

0 comments (0 inline, 0 general)