-
-
Notifications
You must be signed in to change notification settings - Fork 120
Setting up multiple configs for a single mod #394
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.
All reactions
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.
All reactions
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.
Hopefully that helps. See next post for more info.
All reactions
You will need to edit Startup.cs to obtain the second config at runtime after you do that.
Normally Startup.cs has this
// 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 configurator.GetConfiguration<Config2>(1); in this case.
As an alternate solution to two configs, it's also possible to group configs.
Source code:
[DisplayName("Default Settings")]
[Description("The regular settings from the Sonic Heroes launcher.")]
public DefaultSettings DefaultSettings { get; set; } = new DefaultSettings();
Creating a class DefaultSettings and putting it in the main Config.cs will create a new group.
You may find this easier than having 2 config files strictly speaking.
All reactions
Thank you very much for the quick response!
"As an alternate solution to two configs, it's also possible to group configs."
I am doing this already since I'm dealing with a lot of options, but I wanted to further reduce clutter by separating some between config files. To help explain what I'm trying to do I should probably explain what the configs are for. One set of configs is for choosing between versions of effects for weapons in the game (terminus or ascension effects), while the other set of configs is for changing how those effects behave in game (disabled, enabled, only on during combat, etc). So at first I thought ok I'll just put these in order with one of those options for each weapon named and the other option would have an empty name but appear below the former in the menu. However as seen below that didn't work out because the options get scrambled for some reason, and I couldn't find a way to force them to load in the correct order without making it extremely ugly:
With 21 characters in the game, almost all have 2 or more weapons that this mod would control, it would quickly become too cluttered if I split the 2 categories of options into separate groupings instead of keeping it as 1 grouping per character. So I had the idea to split them between config files to keep it clean. If you know a way to force options to appear in a specific order without something like putting a number in front of the name that could definitely be a solid alternative for me.
"You will need to edit Startup.cs to obtain the second config at runtime after you do that."
Was a bit worried this would be the case, wanted to try and avoid directly editing anything in the template if possible. I'll give it a shot though and hopefully I'll be able to get it to work!
All reactions
Yeah, there currently isn't a way to define an order, unfortunately.
And most likely won't be, unless someone makes a PR for it, as I'm working on R2's successor, so I'm only fixing bugs in R2 as they show up.
But hey, hopefully that helps you out 👍
All reactions
Got it to work after messing around in Startup.cs and implementing some overrides for ModContext and ModBase, thank you very much for pointing me in the right direction!
All reactions
No worries, make sure to have a bit of fun :P