Skip to content

For Developers

Caeden117 edited this page Jun 2, 2019 · 34 revisions

Have you ever wanted to add a counter of your own to Counters+, but you want it to also be its own standalone mod? Counters+ has a solution that allows you to easily implement any Counter of choice into the Counters+ system, allowing people to easily reposition them as if it was part of Counters+.

Custom Counter System

The Custom Counter system is a way to store a reference to a GameObject in the Counters+ config, along with basic credits and other settings information, to allow a user to easily reconfigure the positioning of a counter as if it was part of Counters+.

Beginnings

To begin adding your counter to the Counters+ system, begin by adding Counters+ as a reference to your project, and check if Counters+ is installed (Preferably, in the Init or OnApplicationStart function of your Plugin.cs class.

using IPA.Loader; //Add References from Beat Saber_Data/Managed
public class Plugin : IBeatSaberPlugin {
     public void Init(){
          if (PluginManager.GetPlugin("Counters+")) {
               AddCustomCounter();
          }
     }
     //...
}

Adding A Custom Counter

Next, reference the CountersPlus.Custom namespace (using CountersPlus.Custom;), and create a CustomCounter object.

  • SectionName is used as an identifier in the Counters+ config. Make sure it is unique!
  • Name is the display name to be displayed in the Counters+ Settings Menu.
  • BSIPAMod/Mod are references to the plugin that created it. Use one or the other depending on if your plugin is a BSIPA plugin (Inherits IBeatSaberPlugin), or an IPA Reloaded plugin (Inherits IPlugin).
  • Counter is the name of the GameObject that contains your Counter. Make sure any and all TextMeshPro objects you have are either attached to this GameObject, or are attached to Children of this GameObject. You can only have 1 GameObject per Custom Counter!

Finally, you can call CustomCounterCreator.Create() to create your Custom Counter.

using IPA.Loader;
using CountersPlus.Custom;
public class Plugin : IBeatSaberPlugin {
     //...
     private void AddCustomCounter() {
          CustomCounter counter = new CustomCounter {
               SectionName = "testCounter",
               Name = "Test",
               BSIPAMod = this,
               Counter = "testCounterGameObject",
          };
          CustomCounterCreator.Create(counter);
     }
}

And that's it! If it has not yet been created, Counters+ will append the custom counter to its CountersPlus.ini file, and will go off of that from now on. Your Counter can now be subject to the same base configuration settings as every counter!

Custom Counter Defaults

Currently, the default settings for every custom counter is Below Combo, with a Distance of 2. If you instead want your Counter to appear someplace else, Counters+ has a way for you to attach defaults with your custom counter.

Simply create a CustomConfigModel object (with the name as the parameter), edit your default settings, and then input those defaults along with the counter in CustomCounterCreator.Create()

using IPA.Loader;
using CountersPlus.Custom;
public class Plugin : IBeatSaberPlugin {
     //...
     private void AddCustomCounter() {
          //...
          CustomConfigModel defaults = new CustomConfigModel(counter.Name) {
               Enabled = true,
               Position = CountersPlus.Config.ICounterPositions.AboveCombo,
               Index = 0,
          };
          CustomCounterCreator.Create(counter, defaults);
     }
}

When your Custom Counter is created for the first time, Counters+ will use your CustomConfigModel as defaults when saving to config.

Restricting Positions

Perhaps, maybe your counter is too wide to fit above/below the Combo and Multiplier. Maybe you want the users to only place it above or below the highway and track?

Counters+ also has a way for you to restrict where the user can position your counter. Just supply different ICounterPositions objects in CustomCounterCreator.Create(), and those will be the only options available to the user when editing your counter.

using IPA.Loader;
using CountersPlus.Custom;
using CountersPlus.Config; //ICounterPositions is in here.
public class Plugin : IBeatSaberPlugin {
     //...
     private void AddCustomCounter() {
          //...
          CustomCounterCreator.Create(counter, defaults, ICounterPositions.AboveHighway, ICounterPositions.BelowEnergy);
     }
}

...It really is as simple as that! If you do not input any restricted positions, the counter will instead be able to use all 6.

What's the Point?

The main reason for the Custom Counter system is to prevent mods from having to depend on Counters+ in order to function. Custom Counters is more of a bonus if the user also happens to have Counters+ installed.

Clone this wiki locally