public void check_section_data_operations() { string strSectionTest = "MySection"; string strComment = "comment"; List <string> commentListTest = new List <string>(new string[] { "testComment 1", "testComment 2" }); //Creation SectionDataCollection sdc = new SectionDataCollection(); Assert.That(sdc, Is.Empty); //Add sectoin sdc.AddSection(strSectionTest); sdc.AddSection(strSectionTest); Assert.That(sdc.Count, Is.EqualTo(1)); //Check access Assert.That(sdc.GetSectionData(strSectionTest), Is.Not.Null); Assert.That(sdc.GetSectionData(strSectionTest).LeadingComments, Is.Empty); Assert.That(sdc.GetSectionData(strSectionTest).Keys.Count, Is.EqualTo(0)); //Check add coments sdc.GetSectionData(strSectionTest).LeadingComments.Add(strComment); Assert.That(sdc.GetSectionData(strSectionTest).LeadingComments.Count, Is.EqualTo(1)); sdc.GetSectionData(strSectionTest).LeadingComments.Clear(); sdc.GetSectionData(strSectionTest).LeadingComments.AddRange(commentListTest); Assert.That(sdc.GetSectionData(strSectionTest).LeadingComments.Count, Is.EqualTo(commentListTest.Count)); //Remove section sdc.RemoveSection("asdf"); Assert.That(sdc.Count, Is.EqualTo(1)); sdc.RemoveSection(strSectionTest); Assert.That(sdc.Count, Is.EqualTo(0)); //Check access Assert.That(sdc[strSectionTest], Is.Null); }
public void check_section_data_operations() { string strSectionTest = "MySection"; string strComment = "comment"; List<string> commentListTest = new List<string>(new string[] { "testComment 1", "testComment 2" }); //Creation SectionDataCollection sdc = new SectionDataCollection(); Assert.That(sdc, Is.Empty); //Add sectoin sdc.AddSection(strSectionTest); sdc.AddSection(strSectionTest); Assert.That(sdc.Count, Is.EqualTo(1)); //Check access Assert.That(sdc.GetSectionData(strSectionTest), Is.Not.Null); Assert.That(sdc.GetSectionData(strSectionTest).LeadingComments, Is.Empty); Assert.That(sdc.GetSectionData(strSectionTest).Keys.Count, Is.EqualTo(0)); //Check add coments sdc.GetSectionData(strSectionTest).LeadingComments.Add(strComment); Assert.That(sdc.GetSectionData(strSectionTest).LeadingComments.Count, Is.EqualTo(1)); sdc.GetSectionData(strSectionTest).LeadingComments.Clear(); sdc.GetSectionData(strSectionTest).LeadingComments.AddRange(commentListTest); Assert.That(sdc.GetSectionData(strSectionTest).LeadingComments.Count, Is.EqualTo(commentListTest.Count)); //Remove section sdc.RemoveSection("asdf"); Assert.That(sdc.Count, Is.EqualTo(1)); sdc.RemoveSection(strSectionTest); Assert.That(sdc.Count, Is.EqualTo(0)); //Check access Assert.That(sdc[strSectionTest], Is.Null); }
/// <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); } } }
public static string GetValFromCfg(SectionDataCollection col, string sect, string key) { return(col.GetSectionData(sect).Keys.GetKeyData(key).Value.Trim(PackRes_Def.trim)); }