示例#1
0
        /// <summary>
        /// Adds an outside MonoBehaviour into the Counters+ system.
        /// <param name="model"/>The CustomCounter object.</param>
        /// <param name="defaults">Default configuration options for your custom counter.</param>
        /// <param name="restrictedPositions">Restrict your Custom Counter to any of these positions. Inputting no parameters would allow the Counter to use all that are available.</param>
        /// </summary>
        public static void Create <T>(T model, CustomConfigModel defaults = null, params ICounterPositions[] restrictedPositions) where T : CustomCounter
        {
            string modCreator = "";

            if (model.Mod != null)
            {
                modCreator = model.Mod.Name;
            }

            if (model.BSIPAMod != null)
            {
                PluginLoader.PluginMetadata pluginMetadata = PluginUtility.GetPluginMetadata(model.BSIPAMod);
                if (pluginMetadata != null)
                {
                    modCreator = pluginMetadata.Name;
                }
            }

            Plugin.Log($"Custom Counter ({model.Name}) added!", Plugin.LogInfo.Notice);

            foreach (CustomConfigModel potential in ConfigLoader.LoadCustomCounters())
            {
                if (potential.DisplayName == model.Name)
                {
                    if (potential.IsNew)
                    {
                        potential.IsNew = false;
                        potential.Save();
                    }
                    return;
                }
            }

            CustomConfigModel counter = new CustomConfigModel(model.Name)
            {
                DisplayName         = model.Name,
                SectionName         = model.SectionName,
                Enabled             = (defaults == null ? true : defaults.Enabled),
                Position            = (defaults == null ? ICounterPositions.BelowCombo : defaults.Position),
                Distance            = (defaults == null ? 2 : defaults.Distance),
                Counter             = model.Counter,
                ModCreator          = modCreator,
                IsNew               = true,
                RestrictedPositions = (restrictedPositions?.Count() == 0 || restrictedPositions == null) ? new ICounterPositions[] { } : restrictedPositions, //Thanks Viscoci for this
            };

            if (string.IsNullOrEmpty(counter.SectionName) || string.IsNullOrEmpty(counter.DisplayName))
            {
                throw new CustomCounterException("Custom Counter properties invalid. Please make sure SectionName and DisplayName are properly assigned.");
            }

            counter.Save();
        }
示例#2
0
        private static void Create <T>(T model, CustomConfigModel defaults, Assembly callingAssembly, params ICounterPositions[] restrictedPositions) where T : CustomCounter
        {
            string modCreator = "";

            if (model.Mod != null)
            {
                modCreator = model.Mod.Name;
            }

            if (model.BSIPAMod != null)
            {
                modCreator = model.BSIPAMod.Name;
            }
            model.ModName = modCreator;

            Plugin.Log($"Custom Counter ({model.Name}) added!", LogInfo.Notice);

            if (!string.IsNullOrEmpty(model.Icon_ResourceName))
            {
                model.LoadedIcon = UIUtilities.LoadSpriteRaw(UIUtilities.GetResource(callingAssembly, model.Icon_ResourceName));
            }

            List <CustomConfigModel> existingModels = ConfigLoader.LoadCustomCounters();

            if (restrictedPositions != null && restrictedPositions.Count() >= 1)
            {
                model.RestrictedPositions = restrictedPositions;
            }
            if (existingModels.Any(x => x.DisplayName == model.SectionName))
            {
                model.ConfigModel = existingModels.First(x => x.DisplayName == model.SectionName);
            }
            else //This is a new counter!
            {
                if (defaults is null)
                {
                    defaults          = new CustomConfigModel(model);
                    defaults.Enabled  = true;
                    defaults.Position = ICounterPositions.BelowCombo;
                    defaults.Distance = 2;
                }
                model.ConfigModel = defaults;
                model.IsNew       = true;
                defaults.Save();
            }
            model.ConfigModel.CustomCounter = model;
            LoadedCustomCounters.Add(model);
        }
示例#3
0
 internal static void add(CustomConfigModel counter)
 {
     if (!Directory.Exists(Environment.CurrentDirectory.Replace('\\', '/') + $"/UserData/Custom Counters"))
     {
         Directory.CreateDirectory(Environment.CurrentDirectory.Replace('\\', '/') + $"/UserData/Custom Counters");
     }
     using (StreamWriter file = File.CreateText(Environment.CurrentDirectory.Replace('\\', '/') + $"/UserData/Custom Counters/{counter.JSONName}.json"))
     {
         JsonSerializer serializer = new JsonSerializer();
         JsonConvert.DefaultSettings = new Func <JsonSerializerSettings>(() => {
             JsonSerializerSettings settings = new JsonSerializerSettings();
             settings.Formatting             = Formatting.Indented;
             return(settings);
         });
         serializer.Serialize(file, counter);
     }
     Plugin.Log("Custom Counter successfully added!");
 }
示例#4
0
 internal static Task EnsureSettingsExist(CustomConfigModel counter)
 {
     return(Task.Run(() =>
     {
         while (true)
         {
             try
             {
                 if (CountersController.settings != null)
                 {
                     add(counter);
                     break;
                 }
             }
             catch (Exception e) { Plugin.Log(e.ToString()); }
             Thread.Sleep(10);
         }
     }));
 }
示例#5
0
        /// <summary>
        /// Adds an outside MonoBehaviour into the Counters+ system. If it already exists in the system, it will be ignored.
        /// <param name="model"/>The CustomCounter object.</param>
        /// <param name="restrictedPositions">Restrict your Custom Counter to any of these positions.</param>
        /// </summary>
        public static void CreateCustomCounter <T>(T model, params ICounterPositions[] restrictedPositions) where T : CustomCounter
        {
            FileIniDataParser parser = new FileIniDataParser();
            IniData           data   = parser.ReadFile(Environment.CurrentDirectory.Replace('\\', '/') + "/UserData/CountersPlus.ini");
            Scene             scene  = SceneManager.GetActiveScene();

            foreach (SectionData section in data.Sections)
            {
                if (section.Keys.Any((KeyData x) => x.KeyName == "SectionName"))
                {
                    if (section.SectionName == model.Name)
                    {
                        return;
                    }
                }
            }
            if (scene.name == "" || scene.name == "Init" || scene.name == "EmptyTransition" || scene.name == "HealthWarning")
            {
                CustomConfigModel counter = new CustomConfigModel(model.Name)
                {
                    DisplayName         = model.Name,
                    SectionName         = model.JSONName,
                    Enabled             = true,
                    Position            = ICounterPositions.BelowCombo,
                    Index               = 2,
                    Counter             = model.Counter,
                    ModCreator          = model.Mod.Name,
                    RestrictedPositions = (restrictedPositions.Count() == 0 || restrictedPositions == null) ? new ICounterPositions[] { } : restrictedPositions, //Thanks Viscoci for this
                };
                if (string.IsNullOrEmpty(counter.SectionName) || string.IsNullOrEmpty(counter.DisplayName))
                {
                    throw new CustomCounterException("Custom Counter properties invalid. Please make sure JSONName and DisplayName are properly assigned.");
                }
                Plugin.Log("Custom Counter added!");
            }
            else
            {
                throw new CustomCounterException("It is too late to add Custom Counters. Please add Custom Counters at launch.");
            }
        }
示例#6
0
        /// <summary>
        /// Adds an outside MonoBehaviour into the Counters+ system. If it already exists in the system, it will be ignored.
        /// <param name="model"/>The CustomCounter object.</param>
        /// <param name="restrictedPositions">Restrict your Custom Counter to any of these positions.</param>
        /// </summary>
        public static void CreateCustomCounter <T>(T model, params ICounterPositions[] restrictedPositions) where T : CustomCounter
        {
            try
            {
                if (File.Exists(Environment.CurrentDirectory.Replace('\\', '/') + $"/UserData/Custom Counters/{model.JSONName}.json"))
                {
                    Plugin.Log("Attempted custom counter already exists in the system. Ignoring...", Plugin.LogInfo.Warning);
                    return;
                }
            }
            catch { }
            Scene scene = SceneManager.GetActiveScene();

            if (scene.name == "" || scene.name == "Init" || scene.name == "EmptyTransition" || scene.name == "HealthWarning")
            {
                CustomConfigModel counter = new CustomConfigModel
                {
                    JSONName            = model.JSONName,
                    DisplayName         = model.Name,
                    Enabled             = true,
                    Position            = ICounterPositions.BelowCombo,
                    Index               = 2,
                    Counter             = model.Counter,
                    ModCreator          = model.Mod.Name,
                    RestrictedPositions = (restrictedPositions.Count() == 0 || restrictedPositions == null) ? new ICounterPositions[] { } : restrictedPositions, //Thanks Viscoci for this
                };
                if (string.IsNullOrEmpty(counter.JSONName) || string.IsNullOrEmpty(counter.DisplayName))
                {
                    throw new CustomCounterException("Custom Counter properties invalid. Please make sure JSONName and DisplayName are properly assigned.");
                }
                EnsureSettingsExist(counter);
            }
            else
            {
                throw new CustomCounterException("It is too late to add Custom Counters. Please add Custom Counters at launch.");
            }
        }
示例#7
0
 /// <summary>
 /// Adds an outside MonoBehaviour into the Counters+ system.
 /// <param name="model"/>The CustomCounter object.</param>
 /// <param name="restrictedPositions">Restrict your Custom Counter to any of these positions. Inputting no parameters would allow the Counter to use all that are available.</param>
 /// </summary>
 public static void Create <T>(T model, CustomConfigModel defaults = null) where T : CustomCounter
 {
     Create(model, defaults, null);
 }
示例#8
0
 /// <summary>
 /// Adds an outside MonoBehaviour into the Counters+ system.
 /// <param name="model"/>The CustomCounter object.
 /// <param name="defaults">Default configuration options for your custom counter.</param>
 /// <param name="restrictedPositions">Restrict your Custom Counter to any of these positions. Inputting no parameters would allow the Counter to use all that are available.</param>
 /// </summary>
 public static void Create <T>(T model, CustomConfigModel defaults = null, params ICounterPositions[] restrictedPositions) where T : CustomCounter
 {
     Create(model, defaults, Assembly.GetCallingAssembly(), restrictedPositions);
 }
示例#9
0
 /// <summary>
 /// Adds an outside MonoBehaviour into the Counters+ system.
 /// <param name="model"/>The CustomCounter object.
 /// <param name="defaults"/>A <see cref="CustomConfigModel"/> that contains your default settings.
 /// </summary>
 public static void Create <T>(T model, CustomConfigModel defaults = null) where T : CustomCounter
 {
     Create(model, defaults, Assembly.GetCallingAssembly(), null);
 }