Changeset - 0b17df70395d
[Not reviewed]
Merge default
0 1 0
Jason Maltzen (jmaltzen) - 7 years ago 2018-05-18 01:25:48
jason.maltzen@unsanctioned.net
Merge
1 file changed with 57 insertions and 8 deletions:
0 comments (0 inline, 0 general)
PlayerProfile.cs
Show inline comments
...
 
@@ -495,57 +495,106 @@ namespace DesertPaintLab
 
		
 
        public void ExportWikiRibbons(string file)
 
        {
 
            StreamWriter writer = new StreamWriter(file);
 
            ExportWikiFormat(writer, this.ribbonRecipes);
 
        }
 
        
 
        public void ExportWikiRecipes(TextWriter writer)
 
        {
 
            ExportWikiFormat(writer, this.recipes);
 
        }
 
        
 
        public void ExportWikiRibbons(TextWriter writer)
 
        {
 
            ExportWikiFormat(writer, this.ribbonRecipes);
 
        }
 
        
 

	
 
        static public PaintColor RgbToHsv(PaintColor color)
 
        {
 
            float h = 0;
 
            float s = 0;
 
            float r = color.Red / 255.0f;
 
            float g = color.Green / 255.0f;
 
            float b = color.Blue / 255.0f;
 
            float cmax = Math.Max(Math.Max(r, g), b);
 
            float cmin = Math.Min(Math.Min(r, g), b);
 
            float cd = cmax - cmin;
 
            if (cd == 0)
 
            {
 
                h = 0;
 
            }
 
            else if (cmax == r)
 
            {
 
                h = (((g - b) / cd) % 6) / 6f;
 
            }
 
            else if (cmax == g)
 
            {
 
                h = (((b - r) / cd) + 2) / 6f;
 
            }
 
            else
 
            {
 
                h = (((r - g) / cd) + 4) / 6f;
 
            }
 

	
 
            if (cmax == 0)
 
            {
 
                s = 0;
 
            }
 
            else
 
            {
 
                s = cd / cmax;
 
            }
 

	
 
            if (h < 0)
 
            {
 
                h = 1 + h;
 
            }
 

	
 
            if (h >= 1)
 
            {
 
                h = 0;
 
            }
 

	
 

	
 
            return new PaintColor((byte)(h * 255), (byte)(s * 255), (byte)(cmax * 255));
 
        }
 

	
 
        public void ExportWikiFormat(TextWriter writer, SortedDictionary<string, PaintRecipe> recipeDict)
 
        {
 
            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 !! Missing Reactions? || 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") + ";";
 
                    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)
 
                    PaintColor hsvColor = RgbToHsv(color);
 
                    if (hsvColor.Blue < 200) // value
 
                    {
 
                        // dark color gets light text
 
                        colorLine += " color: #FFFFFF;";
 
                    }
 
                    else
 
                    {
 
                        colorLine += "color: #000000;";
 
                    }
 
                    colorLine += "\" | " + color.Name + " || ";
 
                    if (recipeDict.TryGetValue(color.Name, out recipe))
 
                    {
 
                        foreach (PaintRecipe.RecipeIngredient ingredient in recipe.Ingredients)
 
                        {
 
                            colorLine += " " + ingredient.ToString();
 
                        }
 
                    } 
 
                    else
 
                    {
 
                        // no recipe
 
                    }
 
                    colorLine += " || ";
 
                    
 
                    if (recipe.CheckMissingReactions(ref missing) == true)
 
                    {
0 comments (0 inline, 0 general)