Esempio n. 1
0
        public EngineOptions Clone()
        {
            EngineOptions clone = new EngineOptions();

            foreach (EngineOption eo in this)
            {
                if (eo is BooleanEngineOption)
                {
                    clone._options[eo.Key] = new BooleanEngineOption()
                    {
                        Key          = eo.Key,
                        Value        = ((BooleanEngineOption)eo).Value,
                        DefaultValue = ((BooleanEngineOption)eo).DefaultValue,
                    };
                }
                else if (eo is IntegerEngineOption)
                {
                    clone._options[eo.Key] = new IntegerEngineOption()
                    {
                        Key          = eo.Key,
                        Value        = ((IntegerEngineOption)eo).Value,
                        DefaultValue = ((IntegerEngineOption)eo).DefaultValue,
                        MinValue     = ((IntegerEngineOption)eo).MinValue,
                        MaxValue     = ((IntegerEngineOption)eo).MaxValue,
                    };
                }
                else if (eo is DoubleEngineOption)
                {
                    clone._options[eo.Key] = new DoubleEngineOption()
                    {
                        Key          = eo.Key,
                        Value        = ((DoubleEngineOption)eo).Value,
                        DefaultValue = ((DoubleEngineOption)eo).DefaultValue,
                        MinValue     = ((DoubleEngineOption)eo).MinValue,
                        MaxValue     = ((DoubleEngineOption)eo).MaxValue,
                    };
                }
                else if (eo is EnumEngineOption)
                {
                    EnumEngineOption eeo = new EnumEngineOption()
                    {
                        Key          = eo.Key,
                        Value        = ((EnumEngineOption)eo).Value,
                        DefaultValue = ((EnumEngineOption)eo).DefaultValue,
                    };
                    string[] values = new string[((EnumEngineOption)eo).Values.Length];
                    Array.Copy(((EnumEngineOption)eo).Values, values, values.Length);
                    eeo.Values = values;

                    clone._options[eo.Key] = eeo;
                }
            }

            return(clone);
        }
Esempio n. 2
0
        public void ParseEngineOptionLines(string [] optionLines)
        {
            foreach (string optionLine in optionLines)
            {
                try
                {
                    string[] split = optionLine.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                    string key          = split[0];
                    string type         = split[1];
                    string value        = split[2];
                    string defaultValue = split[3];

                    EngineOption eo;

                    switch (type)
                    {
                    case "bool":
                        BooleanEngineOption beo = new BooleanEngineOption();
                        beo.Value        = bool.Parse(value);
                        beo.DefaultValue = bool.Parse(defaultValue);
                        eo = beo;
                        break;

                    case "int":
                        IntegerEngineOption ieo = new IntegerEngineOption();
                        ieo.Value        = int.Parse(value);
                        ieo.DefaultValue = int.Parse(defaultValue);
                        if (split.Length >= 6)
                        {
                            ieo.MinValue = int.Parse(split[4]);
                            ieo.MaxValue = int.Parse(split[5]);
                        }
                        eo = ieo;
                        break;

                    case "double":
                        DoubleEngineOption deo = new DoubleEngineOption();
                        deo.Value        = double.Parse(value);
                        deo.DefaultValue = double.Parse(defaultValue);
                        if (split.Length >= 6)
                        {
                            deo.MinValue = double.Parse(split[4]);
                            deo.MaxValue = double.Parse(split[5]);
                        }
                        eo = deo;
                        break;

                    case "enum":
                        EnumEngineOption eeo = new EnumEngineOption();
                        eeo.Value        = value;
                        eeo.DefaultValue = defaultValue;
                        eeo.Values       = new string[split.Length - 4];
                        Array.Copy(split, 4, eeo.Values, 0, eeo.Values.Length);
                        eo = eeo;
                        break;

                    default:
                        throw new Exception(string.Format("Unknown type \"{0}\"", type));
                    }

                    eo.Key = key;

                    _options[key] = eo;
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("Unable to parse option line {0}", optionLine), ex);
                }
            }
        }