Пример #1
0
        public static Matrix4x4 ParseMatrix4x4(string matrixString)
        {
            string[] array = matrixString.Split(new char[]
            {
                ','
            });
            if (array.Length < 16)
            {
                Debug.LogWarning("WARNING: Matrix4x4 entry is not formatted properly! Proper format for Matrix4x4 is 16 csv floats (m00,m01,m02,m03,m10,m11..m33)");
                return(Matrix4x4.Identity);
            }
            Matrix4x4 matrix = Matrix4x4.Identity;

            matrix.m00 = KPUtil.ParseDouble(array[0]);
            matrix.m01 = KPUtil.ParseDouble(array[1]);
            matrix.m02 = KPUtil.ParseDouble(array[2]);
            matrix.m03 = KPUtil.ParseDouble(array[3]);
            matrix.m10 = KPUtil.ParseDouble(array[4]);
            matrix.m11 = KPUtil.ParseDouble(array[5]);
            matrix.m12 = KPUtil.ParseDouble(array[6]);
            matrix.m13 = KPUtil.ParseDouble(array[7]);
            matrix.m20 = KPUtil.ParseDouble(array[8]);
            matrix.m21 = KPUtil.ParseDouble(array[9]);
            matrix.m22 = KPUtil.ParseDouble(array[10]);
            matrix.m23 = KPUtil.ParseDouble(array[11]);
            matrix.m30 = KPUtil.ParseDouble(array[12]);
            matrix.m31 = KPUtil.ParseDouble(array[13]);
            matrix.m32 = KPUtil.ParseDouble(array[14]);
            matrix.m33 = KPUtil.ParseDouble(array[15]);
            return(matrix);
        }
Пример #2
0
 public void Save(ConfigNode node)
 {
     node.AddValue("nodeName", this.name);
     node.AddValue("anyToUnlock", this.anyToUnlock);
     node.AddValue("icon", this.iconRef);
     node.AddValue("pos", KPUtil.WriteVector(this._pos));
     node.AddValue("scale", this.scale);
 }
Пример #3
0
 public static Quaternion ParseQuaternion(string quaternionString)
 {
     string[] array = quaternionString.Split(new char[]
     {
         ','
     });
     if (array.Length < 4)
     {
         Debug.LogWarning("WARNING: Quaternion entry is not formatted properly! Proper format for Quaternion is x,y,z,w");
         return(Quaternion.Identity);
     }
     return(new Quaternion(KPUtil.ParseDouble(array[0]), KPUtil.ParseDouble(array[1]), KPUtil.ParseDouble(array[2]), KPUtil.ParseDouble(array[3])));
 }
Пример #4
0
 public static Vector4 ParseVector4(string vectorString)
 {
     string[] array = vectorString.Split(new char[]
     {
         ','
     });
     if (array.Length < 4)
     {
         Debug.LogWarning("WARNING: Vector4 entry is not formatted properly! Proper format for Vector4 is x,y,z,w");
         return(Vector4.Zero);
     }
     return(new Vector4(KPUtil.ParseDouble(array[0]), KPUtil.ParseDouble(array[1]), KPUtil.ParseDouble(array[2]), KPUtil.ParseDouble(array[3])));
 }
Пример #5
0
 public static Color ParseColor(string colorString)
 {
     string[] array = colorString.Split(new char[]
     {
         ','
     });
     if (array.Length < 3)
     {
         Debug.LogWarning("WARNING: Color entry is not formatted properly! Proper format for Colors is r,g,b{,a}");
         return(Color.White);
     }
     if (array.Length > 3)
     {
         return(new Color(KPUtil.ParseDouble(array[0]), KPUtil.ParseDouble(array[1]), KPUtil.ParseDouble(array[2]), KPUtil.ParseDouble(array[3])));
     }
     return(new Color(KPUtil.ParseDouble(array[0]), KPUtil.ParseDouble(array[1]), KPUtil.ParseDouble(array[2])));
 }
Пример #6
0
 public void Load(ConfigNode node)
 {
     if (node.HasValue("id"))
     {
         this.id = node.GetValue("id");
     }
     if (node.HasValue("title"))
     {
         this.title = node.GetValue("title");
     }
     if (node.HasValue("description"))
     {
         this.description = node.GetValue("description");
     }
     if (node.HasValue("nodeName"))
     {
         this.name = node.GetValue("nodeName");
     }
     if (node.HasValue("cost"))
     {
         this.scienceCost = KPUtil.ParseInt(node.GetValue("cost"));
     }
     if (node.HasValue("hideEmpty"))
     {
         this.hideEmpty = bool.Parse(node.GetValue("hideEmpty"));
     }
     if (node.HasValue("anyToUnlock"))
     {
         this.anyToUnlock = bool.Parse(node.GetValue("anyToUnlock"));
     }
     if (node.HasValue("pos"))
     {
         this._pos = KPUtil.ParseVector3(node.GetValue("pos"));
     }
     if (node.HasValue("icon"))
     {
         this.iconRef = node.GetValue("icon");
     }
     if (node.HasValue("scale"))
     {
         this.scale = KPUtil.ParseDouble(node.GetValue("scale"));
     }
 }
Пример #7
0
        public static RDTechTree Load(string filePath)
        {
            RDTechTree techTree     = new RDTechTree();
            string     fileFullPath = KPUtil.PathCombine(GameDatabase.KSPRootPath, filePath);
            ConfigNode configNode   = ConfigNode.Load(fileFullPath);

            if (configNode != null)
            {
                if (configNode.HasNode("TechTree"))
                {
                    techTree.Load(configNode.GetNode("TechTree"));
                }
            }
            else
            {
                Debug.LogError("[Tech Tree]: file does not exist or has bad nodes.");
            }
            return(techTree);
        }
Пример #8
0
 public static Vector4 ParseVector4(string x, string y, string z, string w)
 {
     return(new Vector4(KPUtil.ParseDouble(x), KPUtil.ParseDouble(y), KPUtil.ParseDouble(z), KPUtil.ParseDouble(w)));
 }
Пример #9
0
 public static Vector3 ParseVector3(string x, string y, string z)
 {
     return(new Vector3(KPUtil.ParseDouble(x), KPUtil.ParseDouble(y), KPUtil.ParseDouble(z)));
 }
Пример #10
0
 public static Vector2 ParseVector2(string x, string y)
 {
     return(new Vector2(KPUtil.ParseDouble(x), KPUtil.ParseDouble(y)));
 }
Пример #11
0
 public static Quaternion ParseQuaternion(string x, string y, string z, string w)
 {
     return(new Quaternion(KPUtil.ParseDouble(x), KPUtil.ParseDouble(y), KPUtil.ParseDouble(z), KPUtil.ParseDouble(w)));
 }
Пример #12
0
        private static object ReadValue(Type fieldType, string value)
        {
            NumberStyles style   = NumberStyles.Number | NumberStyles.AllowDecimalPoint;
            CultureInfo  culture = CultureInfo.InvariantCulture;

            if (fieldType.IsValueType)
            {
                if (fieldType == typeof(bool))
                {
                    bool flag = false;
                    if (bool.TryParse(value, out flag))
                    {
                        return(flag);
                    }
                }
                else if (fieldType == typeof(byte))
                {
                    byte b = 0;
                    if (byte.TryParse(value, style, culture, out b))
                    {
                        return(b);
                    }
                }
                else if (fieldType == typeof(sbyte))
                {
                    sbyte b2 = 0;
                    if (sbyte.TryParse(value, style, culture, out b2))
                    {
                        return(b2);
                    }
                }
                else if (fieldType == typeof(char))
                {
                    char c = '\0';
                    if (char.TryParse(value, out c))
                    {
                        return(c);
                    }
                }
                else if (fieldType == typeof(decimal))
                {
                    decimal num = 0m;
                    if (decimal.TryParse(value, style, culture, out num))
                    {
                        return(num);
                    }
                }
                else if (fieldType == typeof(double))
                {
                    double num2 = 0.0;
                    if (double.TryParse(value, style, culture, out num2))
                    {
                        return(num2);
                    }
                }
                else if (fieldType == typeof(float))
                {
                    float num3 = 0f;
                    if (float.TryParse(value, style, culture, out num3))
                    {
                        return(num3);
                    }
                }
                else if (fieldType == typeof(int))
                {
                    int num4 = 0;
                    if (int.TryParse(value, style, culture, out num4))
                    {
                        return(num4);
                    }
                }
                else if (fieldType == typeof(uint))
                {
                    uint num5 = 0u;
                    if (uint.TryParse(value, style, culture, out num5))
                    {
                        return(num5);
                    }
                }
                else if (fieldType == typeof(long))
                {
                    long num6 = 0L;
                    if (long.TryParse(value, style, culture, out num6))
                    {
                        return(num6);
                    }
                }
                else if (fieldType == typeof(ulong))
                {
                    ulong num7 = 0uL;
                    if (ulong.TryParse(value, style, culture, out num7))
                    {
                        return(num7);
                    }
                }
                else if (fieldType == typeof(short))
                {
                    short num8 = 0;
                    if (short.TryParse(value, style, culture, out num8))
                    {
                        return(num8);
                    }
                }
                else if (fieldType == typeof(ushort))
                {
                    ushort num9 = 0;
                    if (ushort.TryParse(value, style, culture, out num9))
                    {
                        return(num9);
                    }
                }
                else if (fieldType == typeof(Vector2))
                {
                    return(KPUtil.ParseVector2(value));
                }
                else if (fieldType == typeof(Vector3))
                {
                    return(KPUtil.ParseVector3(value));
                }
                else if (fieldType == typeof(Vector4))
                {
                    return(KPUtil.ParseVector4(value));
                }
                else if (fieldType == typeof(Quaternion))
                {
                    return(KPUtil.ParseQuaternion(value));
                }
                else if (fieldType == typeof(Color))
                {
                    return(KPUtil.ParseColor(value));
                }
                else if (fieldType == typeof(Matrix4x4))
                {
                    return(KPUtil.ParseMatrix4x4(value));
                }
                else if (fieldType.IsEnum)
                {
                    return(KPUtil.ParseEnum(fieldType, value));
                }
            }
            else if (fieldType == typeof(string))
            {
                return(value);
            }
            return(null);
        }
Пример #13
0
        public void AddValue(string name, object value)
        {
            ConfigValue v = new ConfigValue(name, ConfigNode.CleanupInput(KPUtil.WriteObject(value)));

            this._values.Add(v);
        }