Setting up multiple configs for a single mod #394
Replies: 3 comments 4 replies
-
Gimme a moment to get back upstairs, this should normally be fairly trivial, unless I did something silly in the template. |
Beta Was this translation helpful? Give feedback.
-
public class Config : Configurable<Config>
{
[DisplayName("Int")]
[Description("This is an int.")]
public int Integer { get; set; }
}
public class Config2 : Configurable<Config2>
{
[DisplayName("Float")]
[Description("This is a float.")]
public float Float { get; set; }
}
/// <summary>
/// Allows you to override certain aspects of the configuration creation process (e.g. create multiple configurations).
/// Override elements in <see cref="ConfiguratorMixinBase"/> for finer control.
/// </summary>
public class ConfiguratorMixin : ConfiguratorMixinBase
{
public override IUpdatableConfigurable[] MakeConfigurations(string configFolder)
{
// You can add any Configurable here.
return new IUpdatableConfigurable[]
{
Configurable<Config>.FromFile(Path.Combine(configFolder, "Config.json"), "First Config"),
Configurable<Config2>.FromFile(Path.Combine(configFolder, "Config2.json"), "Second Config")
};
}
} Here's a minimal example of the desired functionality. |
Beta Was this translation helpful? Give feedback.
-
You will need to edit Normally // Your config file is in Config.json.
// Need a different name, format or more configurations? Modify the `Configurator`.
// If you do not want a config, remove Configuration folder and Config class.
var configurator = new Configurator(_modLoader.GetModConfigDirectory(_modConfig.ModId));
_configuration = configurator.GetConfiguration<Config>(0);
_configuration.ConfigurationUpdated += OnConfigurationUpdated; You could get the second config via As an alternate solution to two configs, it's also possible to group configs. Source code:
Creating a class |
Beta Was this translation helpful? Give feedback.
-
Hello, I've been working on trying to set up a mod with multiple config files to reduce the clutter in the config menu. However It's been pretty slow going and I was hoping to get some pointers in the right direction. I'm pretty new to C# (started learning it specifically for Reloaded-II) so hopefully my questions aren't too ignorant.
I've had no issues with actually generating multiple config files by using an override of MakeConfigurations from the ConfiguratorMixinBase class, but the issue comes when I'm trying to assign different options for each file. I've tried setting up new subclasses of Configurable for each config file's options, but then I run into the issue of the template specifically calling the subclass "Config" of Configurable, and can't cast between subobjects.
So first question I have is do I have to edit the template directly to get multiple configs to work, by including the new subclasses where necessary? I'd really prefer to avoid editing the template but I'm really struggling to find a way around this without diving into it.
Second question would be is there a way to assign multiple config files to the subclass "Config" but have them separate which options they are assigned within "Config". So for example say I want a toggle named "Toggle A" in FirstConfig.json, and I want a toggle named "Toggle B" in SecondConfig.json. Is there a way to have both of those within the "Config : Configurable" subclass while also keeping them restricted to their respective json, or do I have to use different subclasses for this type of functionality?
Really hoping there's a way to do this without editing the template boilerplate. Appreciate any advice or pointers, I tried finding documentation or examples of how to properly utilize ConfiguratorMixinBase to implement multiple configs but really couldn't find anything.
Beta Was this translation helpful? Give feedback.
All reactions