Esempio n. 1
0
File: Obj.cs Progetto: zy1911/JxqyHD
 public void Save(KeyDataCollection keyDataCollection)
 {
     keyDataCollection.AddKey("ObjName", _objName);
     AddKey(keyDataCollection, "Kind", _kind);
     AddKey(keyDataCollection, "Dir", _dir);
     keyDataCollection.AddKey("MapX", MapX.ToString());
     keyDataCollection.AddKey("MapY", MapY.ToString());
     AddKey(keyDataCollection, "Damage", _damage);
     AddKey(keyDataCollection, "Frame", CurrentFrameIndex - FrameBegin);
     AddKey(keyDataCollection, "Height", _height);
     AddKey(keyDataCollection, "Lum", _lum);
     AddKey(keyDataCollection, "ObjFile", _objFileName);
     AddKey(keyDataCollection, "OffX", _offX);
     AddKey(keyDataCollection, "OffY", _offY);
     if (_scriptFile != null)
     {
         AddKey(keyDataCollection, "ScriptFile", _scriptFile);
     }
     if (_timerScriptFile != null)
     {
         AddKey(keyDataCollection, "TimerScriptFile", _timerScriptFile);
     }
     if (_wavFileSoundEffect != null)
     {
         AddKey(keyDataCollection, "WavFile", _wavFileName);
     }
     if (_timerScriptInterval != Globals.DefaultNpcObjTimeScriptInterval)
     {
         AddKey(keyDataCollection, "TimerScriptInterval", _timerScriptInterval);
     }
 }
Esempio n. 2
0
 public void Save(KeyDataCollection keyDataCollection)
 {
     foreach (var p in this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
     {
         if (p.Name == "FileName")
         {
             continue;
         }
         if (p.PropertyType == typeof(AttrInt))
         {
             if (p.Name == "Cost")
             {
                 keyDataCollection.AddKey("Cost", _cost.GetString());
             }
             else if (p.Name == "SellPrice")
             {
                 keyDataCollection.AddKey("SellPrice", _sellPrice.GetString());
             }
             else
             {
                 var v = (AttrInt)p.GetValue(this, null);
                 keyDataCollection.AddKey(p.Name, v.GetString());
             }
         }
         else if (p.PropertyType == typeof(Asf))
         {
             var v = (Asf)p.GetValue(this, null);
             if (v != null)
             {
                 keyDataCollection.AddKey(p.Name, v.FileName);
             }
         }
         else if (p.PropertyType == typeof(string))
         {
             var v = (string)p.GetValue(this, null);
             if (!string.IsNullOrEmpty(v))
             {
                 keyDataCollection.AddKey(p.Name, v);
             }
         }
         else if (p.PropertyType == typeof(Magic))
         {
             var v = (Magic)p.GetValue(this, null);
             if (v != null)
             {
                 keyDataCollection.AddKey(p.Name, v.FileName);
             }
         }
         else if (p.PropertyType == typeof(GoodKind))
         {
             var v = (GoodKind)p.GetValue(this, null);
             keyDataCollection.AddKey(p.Name, ((int)v).ToString());
         }
         else if (p.PropertyType == typeof(EquipPosition))
         {
             var v = (EquipPosition)p.GetValue(this, null);
             keyDataCollection.AddKey(p.Name, v.ToString());
         }
     }
 }
Esempio n. 3
0
        private void AddCustomExecutable(string title, string binary, string arguments = "",
                                         string workingDirectory = "", string toolbar = "false", string ownicon = "false")
        {
            IniData           iniFile           = organizerIniData;
            KeyDataCollection customExecutables = iniFile["customExecutables"];

            if (INIHasExecutable(customExecutables, title))
            {
                return;
            }
            string nextId = (Int16.Parse(customExecutables["size"]) + 1).ToString();

            customExecutables.AddKey(nextId + "\\title", title);
            customExecutables.AddKey(nextId + "\\toolbar", toolbar);
            customExecutables.AddKey(nextId + "\\ownicon", ownicon);
            binary = binary.Replace("\\", "/");
            customExecutables.AddKey(nextId + "\\binary", binary);
            customExecutables.AddKey(nextId + "\\arguments", arguments);
            workingDirectory = workingDirectory.Replace("\\", "/");
            customExecutables.AddKey(nextId + "\\workingDirectory", workingDirectory);
            customExecutables.AddKey(nextId + "\\steamAppID", "");
            customExecutables.AddKey(nextId + "\\hide", "false");
            customExecutables["size"] = nextId;
            WriteINIFile(iniFile);
        }
Esempio n. 4
0
        public void AddKey(string filename, string section, string key, string value)
        {
            if (!File.Exists(filename))
            {
                File.WriteAllText(filename, string.Empty);
            }

            IniData iniData = IniParser.ReadFile(filename);

            if (!iniData.Sections.ContainsSection(section))
            {
                iniData.Sections.AddSection(section);
            }

            KeyDataCollection autorunSection = iniData.Sections[section];

            if (!autorunSection.ContainsKey(key))
            {
                autorunSection.AddKey(key);
            }

            autorunSection.GetKeyData(key).Value = value;

            IniParser.WriteFile(filename, iniData);
        }
Esempio n. 5
0
        /// <summary>
        ///     Adds a key to a concrete <see cref="KeyDataCollection"/> instance, checking
        ///     if duplicate keys are allowed in the configuration
        /// </summary>
        /// <param name="key">
        ///     Key name
        /// </param>
        /// <param name="value">
        ///     Key's value
        /// </param>
        /// <param name="keyDataCollection">
        ///     <see cref="KeyData"/> collection where the key should be inserted
        /// </param>
        /// <param name="sectionName">
        ///     Name of the section where the <see cref="KeyDataCollection"/> is contained.
        ///     Used only for logging purposes.
        /// </param>
        private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
        {
            // Check for duplicated keys
            if (keyDataCollection.ContainsKey(key))
            {
                // We already have a key with the same name defined in the current section

                if (!Configuration.AllowDuplicateKeys)
                {
                    throw new ParsingException(string.Format("Duplicated key '{0}' found in section '{1}", key, sectionName));
                }
                else if (Configuration.OverrideDuplicateKeys)
                {
                    keyDataCollection[key] = value;
                }
            }
            else
            {
                // Save the keys
                keyDataCollection.AddKey(key, value);
            }

            keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp;
            _currentCommentListTemp.Clear();
        }
Esempio n. 6
0
        public static void SaveParallelScript(KeyDataCollection keyDataCollection)
        {
            var i = 0;

            foreach (var parallelScriptItem in _parallelListDelayed)
            {
                keyDataCollection.AddKey(i.ToString(),
                                         parallelScriptItem.FilePath + ":" + (int)parallelScriptItem.WaitMilliseconds);
                i++;
            }

            foreach (var parallelScriptItem in _parallelListImmediately)
            {
                keyDataCollection.AddKey(i.ToString(),
                                         parallelScriptItem.FilePath + ":0");
                i++;
            }
        }
        public void test()
        {
            var col = new KeyDataCollection();
            col.AddKey("key1");

            Assert.That(col["key1"], Is.Empty);


            col.AddKey("key2", "value2");

            Assert.That(col["key2"], Is.EqualTo("value2"));

            var keyData = new KeyData("key3");
            keyData.Value = "value3";
            col.AddKey(keyData);

            Assert.That(col["key3"], Is.EqualTo("value3"));
        }
Esempio n. 8
0
        public void check_merge_keys()
        {
            var keys1 = new KeyDataCollection();
            keys1.AddKey( "key1", "value1");
            keys1.AddKey( "key2", "value2");
            keys1.AddKey( "key3", "value3");

            var keys2 = new KeyDataCollection();
            keys2.AddKey("key1", "value11");
            keys2.AddKey("key4", "value4");

            keys1.Merge(keys2);

            Assert.That(keys1["key1"], Is.EqualTo("value11"));
            Assert.That(keys1["key2"], Is.EqualTo("value2"));
            Assert.That(keys1["key3"], Is.EqualTo("value3"));
            Assert.That(keys1["key4"], Is.EqualTo("value4"));
        }
Esempio n. 9
0
 public static string GetString(this KeyDataCollection settings, string keyName, string defaultVal = "")
 {
     if (!settings.ContainsKey(keyName))
     {
         settings.AddKey(CreateKeyData(keyName, defaultVal));
         Write();
     }
     return(settings[keyName]);
 }
Esempio n. 10
0
        public void test()
        {
            var col = new KeyDataCollection();

            col.AddKey("key1");

            Assert.That(col["key1"], Is.Empty);


            col.AddKey("key2", "value2");

            Assert.That(col["key2"], Is.EqualTo("value2"));

            var keyData = new KeyData("key3");

            keyData.Value = "value3";
            col.AddKey(keyData);

            Assert.That(col["key3"], Is.EqualTo("value3"));
        }
Esempio n. 11
0
        private void AppendIni(KeyDataCollection context, string key, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return;
            }
            var data = new KeyData(key);

            data.Value = value;
            context.AddKey(data);
        }
Esempio n. 12
0
        /// <summary>
        ///     Adds a key to a concrete <see cref="KeyDataCollection" instance, checking
        ///     if duplicate keys are allowed in the configuration
        /// </summary>
        /// <param name="key">
        ///     Key name
        /// </param>
        /// <param name="value">
        ///     Key's value
        /// </param>
        /// <param name="keyDataCollection">
        ///     <see cref="KeyData" collection where the key should be inserted
        /// </param>
        /// <param name="sectionName">
        ///     Name of the section where the <see cref="KeyDataCollection" is contained.
        ///     Used only for logging purposes.
        /// </param>
        private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
        {
            // Check for duplicated keys
            if (keyDataCollection.ContainsKey(key))
                HandleDuplicatedKeyInCollection(key, value, keyDataCollection, sectionName);
            else
                keyDataCollection.AddKey(key, value);

            keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp;
            _currentCommentListTemp.Clear();
        }
Esempio n. 13
0
        public void check_merge_keys()
        {
            var keys1 = new KeyDataCollection();

            keys1.AddKey("key1", "value1");
            keys1.AddKey("key2", "value2");
            keys1.AddKey("key3", "value3");

            var keys2 = new KeyDataCollection();

            keys2.AddKey("key1", "value11");
            keys2.AddKey("key4", "value4");

            keys1.Merge(keys2);

            Assert.That(keys1["key1"], Is.EqualTo("value11"));
            Assert.That(keys1["key2"], Is.EqualTo("value2"));
            Assert.That(keys1["key3"], Is.EqualTo("value3"));
            Assert.That(keys1["key4"], Is.EqualTo("value4"));
        }
Esempio n. 14
0
        public void check_deep_clone()
        {
            var ori = new KeyDataCollection();

            ori.AddKey("key1", "value1");

            var copy = (KeyDataCollection)ori.Clone();

            copy["key1"] = "Value2";

            Assert.That(ori["key1"], Is.EqualTo("value1"));
        }
Esempio n. 15
0
        private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
        {
            bool flag = keyDataCollection.ContainsKey(key);

            if (flag)
            {
                this.HandleDuplicatedKeyInCollection(key, value, keyDataCollection, sectionName);
            }
            else
            {
                keyDataCollection.AddKey(key, value);
            }
            keyDataCollection.GetKeyData(key).Comments = this._currentCommentListTemp;
            this._currentCommentListTemp.Clear();
        }
Esempio n. 16
0
        public static KeyDataCollection RocketLauncherCliToIni(string cliParams)
        {
            var cliParamsArr = cliParams.Replace("--", "-").Split('-').Select(_ => _.Trim()).Where(_ => !string.IsNullOrWhiteSpace(_));

            var gameCliIni = new KeyDataCollection();

            foreach (var param in cliParamsArr)
            {
                if (!param.Contains(" "))
                {
                    gameCliIni.AddKey(param, "true");
                }
                else
                {
                    var keyData = param.Split(' ');
                    var key     = keyData[0];
                    var data    = keyData[1];

                    gameCliIni.AddKey(key, data);
                }
            }

            return(gameCliIni);
        }
Esempio n. 17
0
        public static bool GetBool(this KeyDataCollection settings, string keyName, bool defaultVal = false)
        {
            if (!settings.ContainsKey(keyName))
            {
                settings.AddKey(CreateKeyData(keyName, defaultVal.ToString()));
                Write();
            }
            bool successful = StrToBool(settings[keyName], out bool result, defaultVal);

            if (!successful)
            {
                Logger.Warning($"Unable to parse {keyName} with value {settings[keyName]} as a boolean, using default value of {defaultVal} instead.");
            }
            return(result);
        }
Esempio n. 18
0
    /// <summary>
    /// Method to prevent leaking KeyDataCollection to calling code
    /// </summary>
    /// <returns>The dictionary converted from a KeyDataCollection.</returns>
    /// <param name="keyDataCollection">Key data collection.</param>
    private KeyDataCollection DictionaryToKeyDataCollection(IDictionary <string, string> data)
    {
        if (data == null)
        {
            return(null);
        }

        KeyDataCollection result = new KeyDataCollection();

        foreach (KeyValuePair <string, string> kvp in data)
        {
            result.AddKey(kvp.Key, kvp.Value);
        }

        return(result);
    }
Esempio n. 19
0
        /// <summary>
        ///     Adds a key to a concrete <see cref="KeyDataCollection"/> instance, checking
        ///     if duplicate keys are allowed in the configuration
        /// </summary>
        /// <param name="key">
        ///     Key name
        /// </param>
        /// <param name="value">
        ///     Key's value
        /// </param>
        /// <param name="keyDataCollection">
        ///     <see cref="KeyData"/> collection where the key should be inserted
        /// </param>
        /// <param name="sectionName">
        ///     Name of the section where the <see cref="KeyDataCollection"/> is contained.
        ///     Used only for logging purposes.
        /// </param>
        private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
        {
            // Check for duplicated keys
            if (keyDataCollection.ContainsKey(key))
            {
                // We already have a key with the same name defined in the current section
                HandleDuplicatedKeyInCollection(key, value, keyDataCollection, sectionName);
            }
            else
            {
                // Save the keys
                keyDataCollection.AddKey(key, value);
            }

            keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp;
            _currentCommentListTemp.Clear();
        }
Esempio n. 20
0
        public static int GetInt(this KeyDataCollection settings, string keyName, int defaultVal = 0)
        {
            if (!settings.ContainsKey(keyName))
            {
                settings.AddKey(CreateKeyData(keyName, defaultVal.ToString()));
                Write();
            }
            int  val        = defaultVal;
            bool successful = int.TryParse(settings[keyName], out val);

            if (!successful)
            {
                Logger.Warning($"Unable to parse {keyName} with value {settings[keyName]} as an integer, using default value of {defaultVal} instead.");
                val = defaultVal;
            }
            return(val);
        }
Esempio n. 21
0
 public void WriteIniData(KeyDataCollection keys)
 {
     foreach (var element in elementDict)
     {
         var keyData = new KeyData(element.Key);
         keyData.Value = element.Value.Options.Parser.EncodeObject(element.Value.GetValue <object>());
         var commentList = new List <string>();
         commentList.Add(element.Value.Options.Parser.GetUsageString());
         if (element.Value.Options.Comment != null)
         {
             commentList.Add(element.Value.Options.Comment);
         }
         keyData.Comments = commentList;
         if (!keys.AddKey(keyData))
         {
             Debug.LogWarning($"Key {element.Key} already present in section!");
         }
     }
 }
Esempio n. 22
0
 protected void AddKey(KeyDataCollection keyDataCollection, string key, string value)
 {
     keyDataCollection.AddKey(key, value);
 }
Esempio n. 23
0
 protected void AddKey(KeyDataCollection keyDataCollection, string key, int value)
 {
     keyDataCollection.AddKey(key, value.ToString());
 }
Esempio n. 24
0
        /// <summary>
        ///     Adds a key to a concrete <see cref="KeyDataCollection"/> instance, checking
        ///     if duplicate keys are allowed in the configuration
        /// </summary>
        /// <param name="key">
        ///     Key name
        /// </param>
        /// <param name="value">
        ///     Key's value
        /// </param>
        /// <param name="keyDataCollection">
        ///     <see cref="KeyData"/> collection where the key should be inserted
        /// </param>
        /// <param name="sectionName">
        ///     Name of the section where the <see cref="KeyDataCollection"/> is contained. 
        ///     Used only for logging purposes.
        /// </param>
        private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
        {
            // Check for duplicated keys
            if (keyDataCollection.ContainsKey(key))
            {
                // We already have a key with the same name defined in the current section
                HandleDuplicatedKeyInCollection(key, value, keyDataCollection, sectionName);
            }
            else
            {
                // Save the keys
                keyDataCollection.AddKey(key, value);
            }

            keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp;
            _currentCommentListTemp.Clear();
        }
Esempio n. 25
0
        /// <summary>
        ///     Adds a key to a concrete <see cref="KeyDataCollection"/> instance, checking
        ///     if duplicate keys are allowed in the configuration
        /// </summary>
        /// <param name="key">
        ///     Key name
        /// </param>
        /// <param name="value">
        ///     Key's value
        /// </param>
        /// <param name="keyDataCollection">
        ///     <see cref="KeyData"/> collection where the key should be inserted
        /// </param>
        /// <param name="sectionName">
        ///     Name of the section where the <see cref="KeyDataCollection"/> is contained. 
        ///     Used only for logging purposes.
        /// </param>
        private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
        {
            // Check for duplicated keys
            if (keyDataCollection.ContainsKey(key))
            {
                // We already have a key with the same name defined in the current section

                if (!Configuration.AllowDuplicateKeys)
                {
                    throw new ParsingException(string.Format("Duplicated key '{0}' found in section '{1}", key, sectionName));
                }
                else if(Configuration.OverrideDuplicateKeys)
                {
                    keyDataCollection[key] = value;
                }
            }
            else
            {
                // Save the keys
                keyDataCollection.AddKey(key, value);
            }

            keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp;
            _currentCommentListTemp.Clear();
        }
        /// <summary>
        /// Load settings from IniData.
        /// </summary>
        private void LoadSettings()
        {
            foreach (var section in config.VisibleSections)
            {
                // Add section title to window
                AddSectionTitle(section.name);
                MovePosition(spacing);

                // Get section from collection
                SectionDataCollection sectionDataCollection = data.Sections;
                if (!sectionDataCollection.ContainsSection(section.name))
                {
                    sectionDataCollection.AddSection(section.name);
                }
                SectionData sectionData = sectionDataCollection.GetSectionData(section.name);

                foreach (var key in section.keys)
                {
                    // Get key from collection
                    KeyDataCollection keyDataCollection = sectionData.Keys;
                    if (!keyDataCollection.ContainsKey(key.name))
                    {
                        keyDataCollection.AddKey(key.name);
                    }
                    KeyData keyData = keyDataCollection.GetKeyData(key.name);

                    // Add key to window with corrispective control
                    TextLabel settingName = AddKeyName(key.name);
                    settingName.ToolTip     = defaultToolTip;
                    settingName.ToolTipText = key.description;

                    switch (key.type)
                    {
                    case ModSettingsKey.KeyType.Toggle:
                        bool toggle;
                        AddCheckBox(bool.TryParse(keyData.Value, out toggle) ? toggle : key.toggle.value);
                        break;

                    case ModSettingsKey.KeyType.MultipleChoice:
                        int selected;
                        if (!int.TryParse(keyData.Value, out selected))
                        {
                            selected = key.multipleChoice.selected;
                        }
                        var multipleChoice = GetSlider();
                        multipleChoice.SetIndicator(key.multipleChoice.choices, selected);
                        SetSliderIndicator(multipleChoice);
                        break;

                    case ModSettingsKey.KeyType.Slider:
                        var sliderKey = key.slider;
                        int startValue;
                        if (!int.TryParse(keyData.Value, out startValue))
                        {
                            startValue = key.slider.value;
                        }
                        var slider = GetSlider();
                        slider.SetIndicator(sliderKey.min, sliderKey.max, startValue);
                        SetSliderIndicator(slider);
                        break;

                    case ModSettingsKey.KeyType.FloatSlider:
                        var   floatSliderKey = key.floatSlider;
                        float floatStartValue;
                        if (!float.TryParse(keyData.Value, out floatStartValue))
                        {
                            floatStartValue = key.floatSlider.value;
                        }
                        var floatSlider = GetSlider();
                        floatSlider.SetIndicator(floatSliderKey.min, floatSliderKey.max, floatStartValue);
                        SetSliderIndicator(floatSlider);
                        break;

                    case ModSettingsKey.KeyType.Tuple:
                        var tuple = AddTuple(keyData.Value);
                        tuple.First.Numeric = tuple.Second.Numeric = true;
                        break;

                    case ModSettingsKey.KeyType.FloatTuple:
                        AddTuple(keyData.Value);     // TextBox.Numeric doesn't allow dot
                        break;

                    case ModSettingsKey.KeyType.Text:
                        TextBox textBox = GetTextbox(95, 40, keyData.Value);
                        modTextBoxes.Add(textBox);
                        break;

                    case ModSettingsKey.KeyType.Color:
                        AddColorPicker(keyData.Value, key);
                        break;
                    }

                    MovePosition(spacing);
                }
            }
        }