public ARKColors(List <List <object> > colorDefinitions, List <List <object> > colorDefinitions2 = null) { colorsByHash = new Dictionary <int, ARKColor>(); colorsByName = new Dictionary <string, ARKColor>(); colorsList = new List <ARKColor>() { new ARKColor() }; if (colorDefinitions == null) { return; } ParseColors(colorDefinitions, 1); if (colorDefinitions2 != null) { ParseColors(colorDefinitions2, 201); // dye colors can appear as color mutation, they start with id 201 } void ParseColors(List <List <object> > colorDefs, int idStart) { foreach (List <object> cd in colorDefs) { var t = cd[0].GetType(); var tt = cd[1].GetType(); if (cd.Count == 2 && cd[0] is string colorName && cd[1] is Newtonsoft.Json.Linq.JArray colorValues) { ARKColor ac = new ARKColor(colorName, new double[] { (double)colorValues[0], (double)colorValues[1], (double)colorValues[2], (double)colorValues[3], }) { id = idStart }; if (!colorsByHash.ContainsKey(ac.hash)) { colorsByHash.Add(ac.hash, ac); } if (!colorsByName.ContainsKey(ac.name)) { colorsByName.Add(ac.name, ac); } colorsList.Add(ac); } idStart++; } } colorsById = colorsList.ToDictionary(c => c.id, c => c); }
/// <summary> /// Returns the ARKColor that is closest to the given argb (sRGB) values. /// </summary> /// <param name="r"></param> /// <param name="g"></param> /// <param name="b"></param> /// <param name="a"></param> /// <returns></returns> public ARKColor ClosestColor(double r, double g, double b, double a) { int hash = ARKColor.ColorHashCode(r, g, b, a); ARKColor ac = ByHash(hash); if (ac.id != 0) { return(ac); } return(ClosestColorFromRGB(r, g, b, a)); }
public ARKColor ClosestColor(double r, double g, double b) { int hash = ARKColor.ColorHashCode(r, g, b); ARKColor ac = ByHash(hash); if (ac.name != "unknown") { return(ac); } return(ClosestColorFromRGB(r, g, b)); }
/// <summary> /// Sets the ARKColor objects /// </summary> internal void Initialize(ARKColors arkColors) { naturalColors = new List <ARKColor>(); if (colors == null) { return; } foreach (var c in colors) { ARKColor cl = arkColors.ByName(c); if (cl.hash != 0 && !naturalColors.Contains(cl)) { naturalColors.Add(cl); } } }
public ARKColors(List <List <object> > colorDefinitions) { colorsByHash = new Dictionary <int, ARKColor>(); colorsByName = new Dictionary <string, ARKColor>(); colorsList = new List <ARKColor>() { new ARKColor() }; if (colorDefinitions == null) { return; } int id = 1; foreach (List <object> cd in colorDefinitions) { var t = cd[0].GetType(); var tt = cd[1].GetType(); if (cd.Count == 2 && cd[0] is string colorName && cd[1] is Newtonsoft.Json.Linq.JArray colorValues) { ARKColor ac = new ARKColor(colorName, new double[] { (double)colorValues[0], (double)colorValues[1], (double)colorValues[2], (double)colorValues[3], }) { id = id++ }; if (!colorsByHash.ContainsKey(ac.hash)) { colorsByHash.Add(ac.hash, ac); } if (!colorsByName.ContainsKey(ac.name)) { colorsByName.Add(ac.name, ac); } colorsList.Add(ac); } } }
public ARKColors(List <List <object> > colorDefinitions) { colorsByHash = new Dictionary <int, ARKColor>(); colorsByName = new Dictionary <string, ARKColor>(); colorsList = new List <ARKColor>() { new ARKColor() }; if (colorDefinitions == null) { return; } int id = 1; foreach (List <object> cd in colorDefinitions) { if (cd.Count < 2 || cd[0].GetType() != typeof(string) || cd[1].GetType() != typeof(object[])) { continue; } ARKColor ac = new ARKColor(cd[0] as string, cd[1] as object[]) { id = id++ }; if (!colorsByHash.ContainsKey(ac.hash)) { colorsByHash.Add(ac.hash, ac); } if (!colorsByName.ContainsKey(ac.name)) { colorsByName.Add(ac.name, ac); } colorsList.Add(ac); } }