Пример #1
0
        public static void SaveConfig(string filename)
        {
            try
            {
                SectionDataCollection sections = new SectionDataCollection();
                sections.AddSection("Game");
                sections.AddSection("Flooding");
                sections.AddSection("Solver");
                IniData data = new IniData(sections);

                data["Game"]["full_life"]             = ToString(full_life);
                data["Game"]["invul_frames"]          = ToString(invul_frames);
                data["Game"]["bonus_required"]        = ToString(bonus_required);
                data["Game"]["enable_moving_objects"] = ToString(enable_moving_objects);

                data["Flooding"]["ground_speed"] = ToString(ground_speed);
                data["Flooding"]["damageless_healzone_bonus"]             = ToString(damageless_healzone_bonus);
                data["Flooding"]["damageless_back_before_healzone_malus"] = ToString(damageless_back_before_healzone_malus);
                data["Flooding"]["back_before_bonus_malus"] = ToString(back_before_bonus_malus);
                data["Flooding"]["allow_wall_clip"]         = ToString(allow_wall_clip);
                data["Flooding"]["wall_speed"]               = ToString(wall_speed);
                data["Flooding"]["wall_bonus_per_invul"]     = ToString(wall_bonus_per_invul);
                data["Flooding"]["wall_bonus_required_cost"] = ToString(wall_bonus_required_cost);
                data["Flooding"]["wall_clip_malus"]          = ToString(wall_clip_malus);
                data["Flooding"]["wall_clip_malus_dist"]     = ToString(wall_clip_malus_dist);
                data["Flooding"]["restrict_complete_wall_clip_when_one_heart"] = ToString(restrict_complete_wall_clip_when_one_heart);
                data["Flooding"]["nb_additional_cost_maps"]         = ToString(nb_additional_cost_maps);
                data["Flooding"]["complete_wall_clip_max_dist"]     = ToString(complete_wall_clip_max_dist);
                data["Flooding"]["complete_wall_clip_duration"]     = ToString(complete_wall_clip_duration);
                data["Flooding"]["cwc_max_dist_zero_in_legal_zone"] = ToString(cwc_max_dist_zero_in_legal_zone);

                data["Solver"]["pos_reduction"]                                 = ToString(pos_reduction);
                data["Solver"]["bump_reduction"]                                = ToString(bump_reduction);
                data["Solver"]["healzone_pos_reduction"]                        = ToString(healzone_pos_reduction);
                data["Solver"]["healzone_bump_reduction"]                       = ToString(healzone_bump_reduction);
                data["Solver"]["additional_reduction_in_wall"]                  = ToString(additional_reduction_in_wall);
                data["Solver"]["additional_reduction_dist_multiplier"]          = ToString(additional_reduction_dist_multiplier);
                data["Solver"]["max_additional_reduction"]                      = ToString(max_additional_reduction);
                data["Solver"]["healzone_additional_reduction_dist_multiplier"] = ToString(healzone_additional_reduction_dist_multiplier);
                data["Solver"]["healzone_max_additional_reduction"]             = ToString(healzone_max_additional_reduction);
                data["Solver"]["rot_precision"]                                 = ToString(rot_precision);
                data["Solver"]["rot_rate_precision"]                            = ToString(rot_rate_precision);
                data["Solver"]["healzone_rot_precision"]                        = ToString(healzone_rot_precision);
                data["Solver"]["healzone_rot_rate_precision"]                   = ToString(healzone_rot_rate_precision);
                data["Solver"]["frame_nb_precision"]                            = ToString(frame_nb_precision);
                data["Solver"]["healzone_frame_nb_precision"]                   = ToString(healzone_frame_nb_precision);
                data["Solver"]["invul_precision"]                               = ToString(invul_precision);
                data["Solver"]["cost_multiplier"]                               = ToString(cost_multiplier);
                data["Solver"]["min_ab_speed"] = ToString(min_ab_speed);
                data["Solver"]["allow_state_visit_with_less_life"] = ToString(allow_state_visit_with_less_life);
                data["Solver"]["nb_iterations_before_ui_update"]   = ToString(nb_iterations_before_ui_update);

                FileIniDataParser parser = new FileIniDataParser();
                parser.WriteFile(filename, data);
            }
            catch { }
        }
Пример #2
0
    static void Write(Transform[] childArray)
    {
        CreateConfigDirectory();

        //初始化INIParser
        FileIniDataParser parser = new FileIniDataParser();

        parser.Parser.Configuration.AllowDuplicateKeys     = true;
        parser.Parser.Configuration.OverrideDuplicateKeys  = true;
        parser.Parser.Configuration.AllowDuplicateSections = true;

        IniData iniData = parser.ReadFile(_nodeconfigFile);
        SectionDataCollection sectionCollection = new SectionDataCollection();

        iniData.Sections = sectionCollection;
        int count = 0;

        for (int i = 0; i < childArray.Length; i++)
        {
            Transform child = childArray[i];
            if (child.tag == "pw")
            {
                sectionCollection.AddSection(child.name);
                iniData[child.name]["ID"]      = count.ToString();
                iniData[child.name]["Info"]    = "请录入信息_" + count;
                iniData[child.name]["HasSale"] = "0";
                iniData[child.name]["Value"]   = "v";
                count++;
            }
        }

        parser.WriteFile(_nodeconfigFile, iniData);
    }
        public void check_adding_sections_to_collection()
        {
            var col = new SectionDataCollection();

            var exampleSection = new SectionData("section1");
            exampleSection.Keys.AddKey("examplekey");
            exampleSection.Keys["examplekey"] = "examplevalue";

            col.Add(exampleSection);

            Assert.That(col["section1"], Is.Not.Null);

            // Add sections directly to the collection
            Assert.That(col.AddSection("section2"), Is.True);
            Assert.That(col.AddSection("section2"), Is.False);

            Assert.That(col["section2"], Is.Not.Null);
        }
Пример #4
0
        public void check_adding_sections_to_collection()
        {
            var col = new SectionDataCollection();

            var exampleSection = new SectionData("section1");

            exampleSection.Keys.AddKey("examplekey");
            exampleSection.Keys["examplekey"] = "examplevalue";

            col.Add(exampleSection);

            Assert.That(col["section1"], Is.Not.Null);

            // Add sections directly to the collection
            Assert.That(col.AddSection("section2"), Is.True);
            Assert.That(col.AddSection("section2"), Is.False);

            Assert.That(col["section2"], Is.Not.Null);
        }
Пример #5
0
        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_deep_clone()
        {
            var ori = new SectionDataCollection();
            ori.AddSection("section1");
            ori["section1"]["key1"] = "value1";

            var copy = (SectionDataCollection)ori.Clone();
            copy["section1"]["key1"] = "value2";

            Assert.That(ori["section1"]["key1"], Is.EqualTo("value1"));
        }
        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);
        }
Пример #8
0
        public void check_deep_clone()
        {
            var ori = new SectionDataCollection();

            ori.AddSection("section1");
            ori["section1"]["key1"] = "value1";

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

            copy["section1"]["key1"] = "value2";

            Assert.That(ori["section1"]["key1"], Is.EqualTo("value1"));
        }
Пример #9
0
        public static void SetLocalScreenMode(string config3DPath)
        {
            //初始化INIParser
            var parser = new FileIniDataParser();

            parser.Parser.Configuration.AllowDuplicateKeys     = true;
            parser.Parser.Configuration.OverrideDuplicateKeys  = true;
            parser.Parser.Configuration.AllowDuplicateSections = true;

            //如果没有ini路径。默认打开3D。
            FileInfo ini = new FileInfo(config3DPath);

            if (!ini.Exists)
            {
                if (!Directory.Exists(ini.Directory.FullName))
                {
                    Directory.CreateDirectory(ini.Directory.FullName);
                }
                var file = File.Create(config3DPath);
                file.Close();
                SectionDataCollection sec = new SectionDataCollection();
                IniData iniData           = new IniData(sec);
                sec.AddSection("Screen");
                sec.AddSection("ScreenDimensional");
                sec.AddSection("ScreenMode");
                sec.AddSection("CanUseAR");
                iniData["Screen"].AddKey("IsScreen", "True");
                iniData["ProjectionMode"].AddKey("Mode", "VR-2D");
                //iniData["ScreenDimensional"].AddKey("Dimensional", "2D");
                //iniData["ScreenMode"].AddKey("ScreenMode", "VR");
                iniData["CanUseAR"].AddKey("AR", "True");
                iniData["Display"].AddKey("Name", "");
                iniData["VersionNo"].AddKey("CurVersion", "1.0");


                parser.WriteFile(config3DPath, iniData);

                UISetting.isScreen              = true;
                UISetting.isNoneProjection      = false;
                UISetting.lastIsNoneProjection  = false;
                UISetting.screenDimensional     = UISetting.ScreenDimensional.TwoDimensional;
                UISetting.lastScreenDimensional = UISetting.ScreenDimensional.TwoDimensional;
                UISetting.screenmode            = UISetting.ScreenMode.VR;
                UISetting.lastScreenmode        = UISetting.ScreenMode.VR;

                UISetting.curScreenmode = ScreenManger.DualScreenMode.VR_2D;
                liu.GlobalConfig.Instance.displayName = "";
                liu.GlobalConfig.Instance.versionNO   = "1.0";
            }
            else
            {
                IniData iniData        = parser.ReadFile(ini.FullName);
                string  isOpen         = iniData["Screen"]["IsScreen"];
                string  projectionMode = iniData["ProjectionMode"]["Mode"];
                //string cDimensional = iniData["ScreenDimensional"]["Dimensional"];
                //string cScreenMode = iniData["ScreenMode"]["ScreenMode"];
                string cAR          = iniData["CanUseAR"]["AR"];
                string displayName  = iniData["Display"]["Name"];
                string curVersionNo = iniData["VersionNo"]["CurVersion"];

                bool isScreen = isOpen == "True" ? true : false;


                //isScreen = screenNum > 1 ? isScreen : false;

                //var dimensional = cDimensional == "2D" ? UISetting.ScreenDimensional.TwoDimensional : UISetting.ScreenDimensional.ThreeDimensional;
                //var screenMode = cScreenMode == "VR" ? UISetting.ScreenMode.VR : UISetting.ScreenMode.AR;
                var arFunc = cAR == "True" ? true : false;
                switch (projectionMode)
                {
                case "None":
                    UISetting.isNoneProjection  = true;
                    UISetting.screenDimensional = UISetting.ScreenDimensional.None;
                    UISetting.screenmode        = UISetting.ScreenMode.None;
                    break;

                case "VR-2D":
                    UISetting.isNoneProjection  = false;
                    UISetting.screenDimensional = UISetting.ScreenDimensional.TwoDimensional;
                    UISetting.screenmode        = UISetting.ScreenMode.VR;
                    break;

                case "VR-3D":
                    UISetting.isNoneProjection  = false;
                    UISetting.screenDimensional = UISetting.ScreenDimensional.ThreeDimensional;
                    UISetting.screenmode        = UISetting.ScreenMode.VR;
                    break;

                case "AR":
                    UISetting.isNoneProjection  = false;
                    UISetting.screenDimensional = UISetting.ScreenDimensional.TwoDimensional;
                    UISetting.screenmode        = UISetting.ScreenMode.AR;
                    break;

                default:
                    break;
                }

                UISetting.isScreen = isScreen;

                //UISetting.screenmode = UISetting.ScreenMode.VR;
                liu.GlobalConfig.canUseCameraAR       = arFunc;
                liu.GlobalConfig.Instance.displayName = displayName;
                liu.GlobalConfig.Instance.versionNO   = curVersionNo;

                UISetting.lastIsNoneProjection  = UISetting.isNoneProjection;
                UISetting.lastScreenDimensional = UISetting.screenDimensional;
                UISetting.lastScreenmode        = UISetting.screenmode;
            }
        }
        /// <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);
                }
            }
        }