Ejemplo n.º 1
0
 public RecoloringData(string data)
 {
     if (data.Contains(","))//CSV value, parse from floats
     {
         string[] values = data.Split(',');
         int      len    = values.Length;
         if (len < 3)
         {
             MonoBehaviour.print("ERROR: Not enough data in: " + data + " to construct color values.");
             values = new string[] { "255", "255", "255", "0", "0" };
         }
         string redString   = values[0];
         string greenString = values[1];
         string blueString  = values[2];
         string specString  = len > 3 ? values[3] : "0";
         string metalString = len > 4 ? values[4] : "0";
         float  r           = Utils.safeParseFloat(redString);
         float  g           = Utils.safeParseFloat(greenString);
         float  b           = Utils.safeParseFloat(blueString);
         color    = new Color(r, g, b);
         specular = Utils.safeParseFloat(specString);
         metallic = Utils.safeParseFloat(metalString);
     }
     else //preset color, load from string value
     {
         RecoloringDataPreset preset = PresetColor.getColor(data);
         color    = preset.color;
         specular = preset.specular;
         metallic = preset.metallic;
     }
 }
Ejemplo n.º 2
0
        internal static void loadColors()
        {
            colorList.Clear();
            presetColors.Clear();
            ConfigNode[] colorNodes = GameDatabase.Instance.GetConfigNodes("KSP_COLOR_PRESET");
            int          len        = colorNodes.Length;

            for (int i = 0; i < len; i++)
            {
                RecoloringDataPreset data = new RecoloringDataPreset(colorNodes[i]);
                if (!presetColors.ContainsKey(data.name))
                {
                    presetColors.Add(data.name, data);
                    colorList.Add(data);
                    loadPresetIntoGroup(data, "FULL");
                }
            }
            ConfigNode[] groupNodes = GameDatabase.Instance.GetConfigNodes("PRESET_COLOR_GROUP");
            len = groupNodes.Length;
            for (int i = 0; i < len; i++)
            {
                string   name       = groupNodes[i].GetStringValue("name");
                string[] colorNames = groupNodes[i].GetStringValues("color");
                for (int k = 0; k < colorNames.Length; k++)
                {
                    RecoloringDataPreset data;
                    if (presetColors.TryGetValue(colorNames[k], out data))
                    {
                        loadPresetIntoGroup(data, name);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Load a recoloring data instance from an input CSV string.  This method attempts intelligent parsing based on the values provided.
        /// If the value contains commas and periods, attempt to parse as floating point.  If the value contains commas only, attempt to parse
        /// as bytes.  If the value contains neither period nor comma, attempt to parse as a 'presetColor' name.
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static RecoloringData ParseColorsBlockEntry(string data)
        {
            Color color;
            float specular, metallic, detail;

            detail = 1;
            if (data.Contains(","))//CSV value, parse from floats
            {
                string[] values = data.Split(',');
                int      len    = values.Length;
                if (len < 3)
                {
                    Log.error("ERROR: Not enough data in: " + data + " to construct color values.");
                    color    = Color.white;
                    specular = 0;
                    metallic = 0;
                }
                else if (data.Contains("."))
                {
                    string rgb          = values[0] + "," + values[1] + "," + values[2] + ",1.0";
                    string specString   = len > 3 ? values[3] : "0";
                    string metalString  = len > 4 ? values[4] : "0";
                    string detailString = len > 5 ? values[5] : "1";
                    color    = Utils.parseColor(rgb);
                    specular = Utils.safeParseFloat(specString);
                    metallic = Utils.safeParseFloat(metalString);
                    detail   = Utils.safeParseFloat(detailString);
                }
                else
                {
                    string rgb          = values[0] + "," + values[1] + "," + values[2] + ",255";
                    string specString   = len > 3 ? values[3] : "0";
                    string metalString  = len > 4 ? values[4] : "0";
                    string detailString = len > 5 ? values[5] : "255";
                    color    = Utils.parseColor(rgb);
                    specular = Utils.safeParseInt(specString) / 255f;
                    metallic = Utils.safeParseInt(metalString) / 255f;
                    detail   = Utils.safeParseInt(detailString) / 255f;
                }
            }
            else //preset color, load from string value
            {
                RecoloringDataPreset preset = PresetColor.getColor(data);
                color    = preset.color;
                specular = preset.specular;
                metallic = preset.metallic;
                detail   = 1;
            }
            return(new RecoloringData(color, specular, metallic, detail));
        }
Ejemplo n.º 4
0
        internal static void loadPresetIntoGroup(RecoloringDataPreset preset, string group)
        {
            RecoloringDataPresetGroup colors;

            if (!presetGroups.TryGetValue(group, out colors))
            {
                colors = new RecoloringDataPresetGroup(group);
                presetGroups.Add(group, colors);
                presetGroupList.Add(colors);
            }
            if (!colors.colors.Contains(preset))
            {
                colors.colors.Add(preset);
            }
        }
Ejemplo n.º 5
0
        internal static void loadColors()
        {
            colorList.Clear();
            presetColors.Clear();
            ConfigNode[] colorNodes = GameDatabase.Instance.GetConfigNodes("KSP_COLOR_PRESET");
            int          len        = colorNodes.Length;

            for (int i = 0; i < len; i++)
            {
                RecoloringDataPreset data = new RecoloringDataPreset(colorNodes[i]);
                if (!presetColors.ContainsKey(data.name))
                {
                    presetColors.Add(data.name, data);
                    colorList.Add(data);
                }
            }
        }