Skip to content

Commit

Permalink
fixed color import.
Browse files Browse the repository at this point in the history
  • Loading branch information
cadaei committed Nov 17, 2019
1 parent 1faa63f commit c4d5592
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
26 changes: 11 additions & 15 deletions ARKBreedingStats/species/ARKColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,25 @@ public ARKColor()
arkRgb = new double[] { 0, 0, 0 };
}

public ARKColor(string name, object[] colorObjectValues)
public ARKColor(string name, double[] colorValues)
{
this.name = name;
if (colorObjectValues?.Length > 3)
if (colorValues.Length > 3)
{
decimal[] decimalValues = new decimal[colorObjectValues.Length];
colorObjectValues.CopyTo(decimalValues, 0);
var doubleValues = Array.ConvertAll<decimal, double>(decimalValues, d => (double)d);

color = Color.FromArgb(LinearColorComponentToColorComponentClamped(doubleValues[0]),
LinearColorComponentToColorComponentClamped(doubleValues[1]),
LinearColorComponentToColorComponentClamped(doubleValues[2]));
color = Color.FromArgb(LinearColorComponentToColorComponentClamped(colorValues[0]),
LinearColorComponentToColorComponentClamped(colorValues[1]),
LinearColorComponentToColorComponentClamped(colorValues[2]));
// TODO support HDR color part

hash = ColorHashCode(
doubleValues[0],
doubleValues[1],
doubleValues[2]
colorValues[0],
colorValues[1],
colorValues[2]
);

arkRgb = new double[] {doubleValues[0],
doubleValues[1],
doubleValues[2]};
arkRgb = new double[] {colorValues[0],
colorValues[1],
colorValues[2]};
}
else
{
Expand Down
30 changes: 21 additions & 9 deletions ARKBreedingStats/species/ARKColors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,28 @@ public ARKColors(List<List<object>> colorDefinitions)

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);
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);
}
}
}

Expand Down

0 comments on commit c4d5592

Please sign in to comment.