Ejemplo n.º 1
0
                protected override bool TryGetValue(MyIniValue storage, out Dictionary <string, Vector3D> value)
                {
                    value = new Dictionary <string, Vector3D>();
                    List <string> lines = new List <string>();

                    storage.GetLines(lines);
                    foreach (string l in lines)
                    {
                        if (string.IsNullOrWhiteSpace(l))
                        {
                            continue;
                        }
                        string [] configValues = l.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        if (configValues.Length != 4)
                        {
                            return(false);
                        }
                        Vector3D offset = new Vector3D();
                        if (!double.TryParse(configValues [1], out offset.X))
                        {
                            return(false);
                        }
                        if (!double.TryParse(configValues [2], out offset.Y))
                        {
                            return(false);
                        }
                        if (!double.TryParse(configValues [3], out offset.Z))
                        {
                            return(false);
                        }
                        value[configValues [0]] = offset;
                    }
                    return(value.Count > 0);
                }
Ejemplo n.º 2
0
        /// <summary>Returns the value requested and throws if it does not exist.</summary>
        /// <param name="ini">This</param>
        /// <param name="section">Name of the section</param>
        /// <param name="key">Key</param>
        /// <returns>The value corresponding to the key in the section</returns>
        public static MyIniValue GetThrow(this MyIni ini, string section, string key)
        {
            MyIniValue res = ini.Get(section, key);

            if (res.IsEmpty)
            {
                throw new InvalidOperationException($"Need key '{key}' in section '{section}' in custom data");
            }
            return(res);
        }
Ejemplo n.º 3
0
            protected override bool TryGetValue(MyIniValue storage, out T value)
            {
                value = default(T);
                string temp;

                if (!storage.TryGetString(out temp))
                {
                    return(false);
                }
                return(Enum.TryParse <T>(temp, out value));
            }
Ejemplo n.º 4
0
        private bool getOrAddIniInt(string section, string key, ref int val, string description = "\n")
        {
            MyIniValue iniVal = param_ini.Get(section, key);

            if (iniVal.IsEmpty)
            {
                param_ini.Set(section, key, val);
                param_ini.SetComment(section, key, description);
                return(true);
            }
            val = iniVal.ToInt32();
            return(false);
        }
Ejemplo n.º 5
0
            protected override bool TryGetValue(MyIniValue storage, out Vector3D value)
            {
                value = new Vector3D();
                string temp;

                if (!storage.TryGetString(out temp))
                {
                    return(false);
                }
                string [] args = temp.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (args.Length != 3)
                {
                    return(false);
                }
                if (!double.TryParse(args [0], out value.X))
                {
                    return(false);
                }
                if (!double.TryParse(args [1], out value.Y))
                {
                    return(false);
                }
                return(double.TryParse(args [2], out value.Z));
            }
Ejemplo n.º 6
0
 protected override bool TryGetValue(MyIniValue storage, out bool value)
 {
     return(storage.TryGetBoolean(out value));
 }
Ejemplo n.º 7
0
 protected abstract bool TryGetValue(MyIniValue storage, out T value);
Ejemplo n.º 8
0
 protected override bool TryGetValue(MyIniValue storage, out double value)
 {
     return(storage.TryGetDouble(out value));
 }
Ejemplo n.º 9
0
 protected override bool TryGetValue(MyIniValue storage, out int value)
 {
     return(storage.TryGetInt32(out value));
 }
Ejemplo n.º 10
0
 protected override bool TryGetValue(MyIniValue storage, out string value)
 {
     return(storage.TryGetString(out value));
 }