コード例 #1
0
        public static void LoadCounters()
        {
            Plugin.Log("Loading Counters...");
            LoadCounter <MissedConfigModel, MissedCounter>("Missed", settings.missedConfig);
            LoadCounter <NoteConfigModel, AccuracyCounter>("Notes", settings.noteConfig);
            LoadCounter <ScoreConfigModel, ScoreCounter>("Score", settings.scoreConfig);
            LoadCounter <ProgressConfigModel, ProgressCounter>("Progress", settings.progressConfig);
            LoadCounter <SpeedConfigModel, SpeedCounter>("Speed", settings.speedConfig);
            LoadCounter <CutConfigModel, CutCounter>("Cut", settings.cutConfig);
            FileIniDataParser parser = new FileIniDataParser();
            IniData           data   = parser.ReadFile(Environment.CurrentDirectory.Replace('\\', '/') + "/UserData/CountersPlus.ini");

            foreach (SectionData section in data.Sections)
            {
                if (section.Keys.Any((KeyData x) => x.KeyName == "SectionName"))
                {
                    if (!PluginManager.Plugins.Any((IPlugin x) => x.Name == section.Keys["ModCreator"]))
                    {
                        return;
                    }
                    CustomConfigModel potential = new CustomConfigModel(section.SectionName);
                    LoadCounter <CustomConfigModel, CustomCounterHook>(section.Keys["SectionName"], potential);
                }
            }
        }
コード例 #2
0
 public static void LoadCounters()
 {
     Plugin.Log("Loading Counters...");
     LoadCounter <MissedConfigModel, MissedCounter>("Missed", settings.missedConfig);
     LoadCounter <AccuracyConfigModel, AccuracyCounter>("Notes", settings.accuracyConfig);
     LoadCounter <ScoreConfigModel, ScoreCounter>("Score", settings.scoreConfig);
     LoadCounter <ProgressConfigModel, ProgressCounter>("Progress", settings.progressConfig);
     LoadCounter <SpeedConfigModel, SpeedCounter>("Speed", settings.speedConfig);
     LoadCounter <CutConfigModel, CutCounter>("Cut", settings.cutConfig);
     if (Directory.Exists(Environment.CurrentDirectory.Replace('\\', '/') + $"/UserData/Custom Counters"))
     {
         foreach (string file in Directory.EnumerateFiles(Environment.CurrentDirectory.Replace('\\', '/') + $"/UserData/Custom Counters/"))
         {
             try
             {
                 CustomConfigModel counter = JsonConvert.DeserializeObject <CustomConfigModel>(File.ReadAllText(file));
                 if (PluginManager.Plugins.Where((IPlugin x) => x.Name == counter.ModCreator).Count() == 0)
                 {
                     Plugin.Log("Custom Counter cannot find the plugin it originated from. Ignoring...");
                 }
                 //else if (PluginManager.Plugins.Where((IPlugin x) => x.Name == "Counters+").Count() == 0)
                 //Plugin.Log("Who thought it was a good idea to say Counters+ created a custom counter? :pepeThinking:");
                 else
                 {
                     LoadCounter <CustomConfigModel, CustomCounterHook>(counter.JSONName, counter);
                 }
             }catch { Plugin.Log("Error loading Custom Counter. Ignoring..."); }
         }
     }
     if (settings.RNG)
     {
         new GameObject("Counters+ | Randomizer").AddComponent <RandomizePositions>();
     }
 }
コード例 #3
0
        void Awake()
        {
            Name = name.Split('|').Last().Substring(1).Split(' ').First();
            if (!Directory.Exists(Environment.CurrentDirectory.Replace('\\', '/') + $"/UserData/Custom Counters"))
            {
                Plugin.Log($"Custom Counter ({Name}) could not find its attached config model. Destroying...");
                Destroy(this);
            }
            else
            {
                foreach (string file in Directory.EnumerateFiles(Environment.CurrentDirectory.Replace('\\', '/') + $"/UserData/Custom Counters"))
                {
                    CustomConfigModel potential = JsonConvert.DeserializeObject <CustomConfigModel>(File.ReadAllText(file));
                    if (potential.JSONName == Name)
                    {
                        settings = potential;
                    }
                }
            }

            if (settings == null)
            {
                Plugin.Log($"Custom Counter ({Name}) could not find its attached config model. Destroying...");
                Destroy(this);
            }
            StartCoroutine(GetRequired());
        }
コード例 #4
0
 public void saveCustom(CustomConfigModel model)
 {
     using (StreamWriter file = File.CreateText(Environment.CurrentDirectory.Replace('\\', '/') + $"/UserData/Custom Counters/{model.JSONName}.json"))
     {
         JsonSerializer serializer = new JsonSerializer();
         serializer.Serialize(file, model);
     }
 }
コード例 #5
0
 void Start()
 {
     Name = name.Split('|').Last().Substring(1).Split(' ').First();
     foreach(CustomConfigModel potential in ConfigLoader.LoadCustomCounters())
         if (potential.SectionName == Name) settings = potential;
     if (settings == null)
     {
         Plugin.Log($"Custom Counter ({Name}) could not find its attached config model. Destroying...", LogInfo.Notice);
         Destroy(this);
     }
     StartCoroutine(GetRequired());
 }
コード例 #6
0
        /// <summary>
        /// Grabs a list of all Custom Counter references in CountersPlus.ini, if their mod is loaded by BSIPA.
        /// </summary>
        public static List <CustomConfigModel> LoadCustomCounters()
        {
            List <CustomConfigModel> counters = new List <CustomConfigModel>();
            FileIniDataParser        parser   = new FileIniDataParser();
            IniData data = parser.ReadFile(Path.Combine(UnityGame.UserDataPath, "CountersPlus.ini"));

            foreach (SectionData section in data.Sections)
            {
                if (!TypesUtility.GetListOfType <ConfigModel>().Any(y => y.DisplayName == section.SectionName))
                {
                    CustomConfigModel unloadedModel = new CustomConfigModel(section.SectionName);
                    CustomConfigModel loadedModel   = DeserializeFromConfig(unloadedModel, section.SectionName);
                    counters.Add(loadedModel);
                }
            }
            return(counters);
        }
コード例 #7
0
ファイル: Config.cs プロジェクト: Jackzmc/CountersPlus
        /// <summary>
        /// Grabs a list of all Custom Counter references in CountersPlus.ini, if their mod is loaded by BSIPA.
        /// </summary>
        public static List <CustomConfigModel> LoadCustomCounters()
        {
            List <CustomConfigModel> counters = new List <CustomConfigModel>();
            FileIniDataParser        parser   = new FileIniDataParser();
            IniData data = parser.ReadFile(Path.Combine(BeatSaber.UserDataPath, "CountersPlus.ini"));

            foreach (SectionData section in data.Sections)
            {
                if (section.Keys.Any((KeyData x) => x.KeyName == "SectionName") &&
                    PluginUtility.IsPluginPresent(section.Keys["ModCreator"]))
                {
                    CustomConfigModel unloadedModel = new CustomConfigModel(section.SectionName);
                    CustomConfigModel loadedModel   = DeserializeFromConfig(unloadedModel, section.SectionName) as CustomConfigModel;
                    counters.Add(loadedModel);
                }
            }
            return(counters);
        }
コード例 #8
0
        protected override void DidActivate(bool firstActivation, ActivationType type)
        {
            try
            {
                if (firstActivation)
                {
                    Instance     = this;
                    cellInstance = Resources.FindObjectsOfTypeAll <LevelListTableCell>().First((LevelListTableCell x) => x.name == "LevelListTableCell");
                    base.DidActivate(firstActivation, type);

                    foreach (var kvp in AdvancedCounterSettings.counterUIItems)
                    {
                        counterInfos.Add(CreateFromModel(kvp.Key));
                    }
                    FileIniDataParser parser = new FileIniDataParser();
                    IniData           data   = parser.ReadFile(Path.Combine(BeatSaber.UserDataPath, "CountersPlus.ini"));
                    foreach (SectionData section in data.Sections)
                    {
                        if (section.Keys.Any((KeyData x) => x.KeyName == "SectionName") &&
                            PluginUtility.IsPluginPresent(section.Keys["ModCreator"]))
                        {
                            CustomConfigModel potential = new CustomConfigModel(section.SectionName);
                            potential = ConfigLoader.DeserializeFromConfig(potential, section.SectionName) as CustomConfigModel;

                            counterInfos.Add(new SettingsInfo()
                            {
                                Name        = potential.DisplayName,
                                Description = $"A custom counter added by {potential.ModCreator}!",
                                Model       = potential,
                                IsCustom    = true,
                            });
                        }
                    }
                    _customListTableView.didSelectCellWithIdxEvent += OnCellSelect;
                    _customListTableView.ReloadData();
                    _customListTableView.SelectCellWithIdx(0, false);
                }
            }
            catch (Exception e) {
                Plugin.Log(e.Message + e.StackTrace, Plugin.LogInfo.Fatal, "Check dependencies. If issue persists, re-install Counters+. If issue still persists, create an issue on the Counters+ GitHub.");
            }
        }
コード例 #9
0
        private void AddCustomCounter()
        {
            Logger.Log("Creating Custom Counter");
            CustomCounter counter = new CustomCounter
            {
                SectionName = "deviationCounter",
                Name        = "Deviation Counter",
                BSIPAMod    = this,
                Counter     = "Deviation Counter",
            };

            CustomConfigModel defaults = new CustomConfigModel(counter.Name)
            {
                Enabled  = true,
                Position = CountersPlus.Config.ICounterPositions.BelowCombo,
                Distance = 1
            };

            CustomCounterCreator.Create(counter, defaults);
        }
コード例 #10
0
ファイル: Plugin.cs プロジェクト: Caeden117/NotesLeftCounter
        void AddCustomCounter()
        {
            Log("Creating Custom Counter");
            CustomCounter counter = new CustomCounter
            {
                SectionName = "notesLeftCounter",     //Name in config system. Also used as an identifier. Don't plan on changing this.
                Name        = "Notes Left",           //Display name that will appear in the SettingsUI.
                Mod         = (IPA.Old.IPlugin) this, //IPA Plugin. Will show up in Credits in the SettingsUI.
                Counter     = "NotesLeftCounter",     //Name of the GameObject that holds your Counter component. Used to hook into the Counters+ system.
            };

            CustomConfigModel defaults = new CustomConfigModel(counter.Name)
            {
                Enabled  = true,
                Position = CountersPlus.Config.ICounterPositions.AboveHighway,
                Index    = 0,
            };

            CustomCounterCreator.Create(counter, defaults); //Using no ICounterPositions for params defaults to it being able to use all 6.
        }
コード例 #11
0
        void Awake()
        {
            Name = name.Split('|').Last().Substring(1).Split(' ').First();
            FileIniDataParser parser = new FileIniDataParser();
            IniData           data   = parser.ReadFile(Environment.CurrentDirectory.Replace('\\', '/') + "/UserData/CountersPlus.ini");

            foreach (SectionData section in data.Sections)
            {
                if (section.Keys.Any((KeyData x) => x.KeyName == "SectionName"))
                {
                    CustomConfigModel potential = new CustomConfigModel(section.SectionName);
                    if (potential.SectionName == Name)
                    {
                        settings = potential;
                    }
                }
            }
            if (settings == null)
            {
                Plugin.Log($"Custom Counter ({Name}) could not find its attached config model. Destroying...");
                Destroy(this);
            }
            StartCoroutine(GetRequired());
        }
コード例 #12
0
        internal static void CreateSettingsUI()
        {
            if (Directory.Exists(Environment.CurrentDirectory.Replace('\\', '/') + $"/UserData/Custom Counters"))
            {
                foreach (string file in Directory.EnumerateFiles(Environment.CurrentDirectory.Replace('\\', '/') + $"/UserData/Custom Counters"))
                {
                    try
                    {
                        CustomConfigModel potential = JsonConvert.DeserializeObject <CustomConfigModel>(File.ReadAllText(file));
                        if (loadedCustoms.Where((CustomConfigModel x) => x.JSONName == potential.JSONName).Count() != 0)
                        {
                            continue;
                        }
                        customCounterUIItems.Add(potential, (SubMenu v) =>
                        {
                            var delete       = v.AddBool("Delete?", "Deletes the Custom Counter from the system when you apply settings.\n<color=#FF0000>Relaunching the credited mod will regenerate the file.</color>\nAnother way to remove the effects of a Custom Counter is by simply disabling it.");
                            delete.GetValue += delegate { return(false); };
                            delete.SetValue += delegate(bool c)
                            {
                                if (c)
                                {
                                    File.Delete(file);
                                }
                                CountersController.settings.saveCustom(potential);
                            };
                            var credits             = v.AddListSetting <ModeViewController>("Credits", $"Created by: {potential.ModCreator}");
                            credits.values          = creditSetting;
                            credits.GetValue        = () => creditSetting.First();
                            credits.GetTextForValue = (value) => "Hover";
                            credits.SetValue        = c => { };
                        });
                        loadedCustoms.Add(potential);
                    }catch (Exception e) { Plugin.Log("Error loading Custom Counter. Ignoring..."); Plugin.Log(e.ToString()); }
                }
            }

            //Main
            var mainSub     = SettingsUI.CreateSubMenu("Counters+ | Main");
            var mainEnabled = mainSub.AddBool("Enabled", "Toggles the plugin on or off.");

            mainEnabled.GetValue += delegate { return(CountersController.settings.Enabled); };
            mainEnabled.SetValue += delegate(bool value) {
                CountersController.settings.Enabled = value;
                Plugin.FlagConfigForReload(true);
            };

            if (!CountersController.settings.Enabled)
            {
                return;
            }

            var mainRNG = mainSub.AddBool("Random Counter Properties", "Add some RNG to the position and settings of some Counters.\n<color=#FF0000>This will essentially have counters float around the play space every 10 seconds, and can be distracting in play.</color>");

            mainRNG.GetValue += delegate { return(CountersController.settings.RNG); };
            mainRNG.SetValue += delegate(bool value) {
                CountersController.settings.RNG = value;
            };

            var mainMenus = mainSub.AddBool("Disable Menus", "Removes clutter by removing all other Counters+ submenus while keeping Counters+ enabled.");

            mainMenus.GetValue += delegate { return(CountersController.settings.DisableMenus); };
            mainMenus.SetValue += delegate(bool value) {
                CountersController.settings.DisableMenus = value;
            };

            if (CountersController.settings.DisableMenus)
            {
                return;
            }

            foreach (var kvp in counterUIItems)
            {
                kvp.Value(createBase(kvp.Key.DisplayName, kvp.Key));
            }
            foreach (var kvp in customCounterUIItems)
            {
                kvp.Value(createBase(kvp.Key.DisplayName, kvp.Key, kvp.Key.RestrictedPositions));
            }
        }
コード例 #13
0
 // Is this too much? Probably.
 private void BindCustomCounter(CustomCounter counter, CustomConfigModel settings)
 {
     Container.Bind <ConfigModel>().WithId(counter.Name).To <CustomConfigModel>().FromInstance(settings).AsCached();
     Container.Bind <ConfigModel>().To <CustomConfigModel>().FromInstance(settings).AsCached();
     Container.BindInterfacesAndSelfTo <CustomConfigModel>().FromInstance(settings).WhenInjectedInto(counter.CounterType);
 }
コード例 #14
0
        internal static void CreateSettingsUI()
        {
            FileIniDataParser parser = new FileIniDataParser();
            IniData           data   = parser.ReadFile(Environment.CurrentDirectory.Replace('\\', '/') + "/UserData/CountersPlus.ini");

            foreach (SectionData section in data.Sections)
            {
                if (section.Keys.Any((KeyData x) => x.KeyName == "SectionName"))
                {
                    Plugin.Log(section.SectionName);
                    CustomConfigModel potential = new CustomConfigModel(section.SectionName);
                    if (!PluginManager.Plugins.Any((IPlugin x) => x.Name == section.Keys["ModCreator"]))
                    {
                        continue;
                    }
                    customCounterUIItems.Add(potential, (SubMenu v) =>
                    {
                        var delete       = v.AddBool("Delete?", "Deletes the Custom Counter from the system when you apply settings.\n<color=#FF0000>Relaunching the credited mod will regenerate the file.</color>\nAnother way to remove the effects of a Custom Counter is by simply disabling it.");
                        delete.GetValue += delegate { return(false); };
                        delete.SetValue += delegate(bool c)
                        {
                            if (c)
                            {
                                data.Sections.RemoveSection(section.SectionName);
                            }
                        };
                        var credits             = v.AddListSetting <ModeViewController>("Credits", $"Created by: {potential.ModCreator}");
                        credits.values          = creditSetting;
                        credits.GetValue        = () => creditSetting.First();
                        credits.GetTextForValue = (value) => "Hover";
                        credits.SetValue        = c => { };
                    });
                    loadedCustoms.Add(potential);
                }
            }

            //Main
            var mainSub     = SettingsUI.CreateSubMenu("Counters+ | Main");
            var mainEnabled = mainSub.AddBool("Enabled", "Toggles the plugin on or off.");

            mainEnabled.GetValue += delegate { return(CountersController.settings.Enabled); };
            mainEnabled.SetValue += delegate(bool value) {
                CountersController.settings.Enabled = value;
            };

            if (!CountersController.settings.Enabled)
            {
                return;
            }

            var mainMenus = mainSub.AddBool("Disable Menus", "Removes clutter by removing all other Counters+ submenus while keeping Counters+ enabled.");

            mainMenus.GetValue += delegate { return(CountersController.settings.DisableMenus); };
            mainMenus.SetValue += delegate(bool value) {
                CountersController.settings.DisableMenus = value;
            };


            float[] offsetValues = new float[] { 0, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1 };
            var     comboOffset  = mainSub.AddList("Combo Offset", offsetValues, "Before Index is taken into account, how far should counters be from the Combo counter.");

            comboOffset.GetValue        += delegate { return(CountersController.settings.ComboOffset); };
            comboOffset.SetValue        += delegate(float f) { CountersController.settings.ComboOffset = f; };
            comboOffset.GetTextForValue += delegate(float f) { return(f.ToString()); };

            var multiplierOffset = mainSub.AddList("Multiplier Offset", offsetValues, "Before Index is taken into account, how far should counters be from the Multiplier counter.");

            multiplierOffset.GetValue        += delegate { return(CountersController.settings.MultiplierOffset); };
            multiplierOffset.SetValue        += delegate(float f) { CountersController.settings.MultiplierOffset = f; };
            multiplierOffset.GetTextForValue += delegate(float f) { return(f.ToString()); };

            if (CountersController.settings.DisableMenus)
            {
                return;
            }

            foreach (var kvp in counterUIItems)
            {
                try
                {
                    kvp.Value(createBase(kvp.Key.DisplayName, kvp.Key));
                }
                catch { }
            }
            foreach (var kvp in customCounterUIItems)
            {
                try
                {
                    kvp.Value(createBase(kvp.Key.DisplayName, kvp.Key, kvp.Key.RestrictedPositions));
                }
                catch (Exception e) { Plugin.Log(e.ToString()); }
            }
        }