Config & Translation
Creating a Config & Translation with Synapse3
Config
Creating a Config with Neuron is really easy. First you have to create a new Type which will be your Config that inherits from Syml.IDocumentSection
and give it the the Attribute Syml.DocumentSectionAttribute
as well as Automatic
Now can you add various Properties (or fields) to your Type
Neuron will now detect your config and will on start of your Plugin serialize this class with the default values (for AmountOfX in this case 5) and add it inside the plugins.syml
(modules.syml
if you are creating a Module) file or deserialize the values of the config if the section of your config was found.
The now loaded Config will be binded then to the kernel to ensure that every time you request the Config the proper instances will be returned. Synapse.Get<MyConfig>()
Configs will be also updated every time they are loaded so if you update your plugin all new Configs will be added with the default values while the original config values are not touched and configs that were removed will be removed from the Configs as well.
What is about reloading Configs?
The Reload Event is not a direct feature of Neuron but one of Synapse, so Synapse will call the reload method of the Neuron Config Module upon raising of the Event.
This will unbind the old config and start the process again so that a new reloaded instances of the Config will be binded to the kernel.
This however means if you want to store your Configs somewhere and not use Synapse.Get<> every time you have to reload this field every time the Reload Event is fired. How you can automate this can you see here
Be careful not to use any special symbols when choosing a Name for your Config Section.
Try to use only default letters since otherwise SYML could deny the reading of the configs and throws an Error
Translation
In order to create a Translation you have to create a new Type that inherits from Translations<TYourOwnType>
and add the Automatic Attribute to it
Now can you add various Properties (or fields) to your Type
If you don't use English as default Language, you have to override Default Language
As you can see you are not only limited to using strings but every object that can be serialized inside your configs which can be used for example to set up different broadcast times for different languages
The Translation will be binded and reloaded automatic by Neuron/Synapse so you can just use Synapse.Get<MyTranslation>
in order to get the current Translation, however this will just return the default Translation so in order to get the proper Translation have you to use the Extension method Get() this would look like this
Synapse.Get<MyTranslation>().Get();
This will always return the current Translation (so you don't have to worry about reloading your instance like the config) defined inside the Synapse.syml config.
If you want to get the proper translation for a Player can you just use the Get method with the Player as argument
Synapse.Get<MyTranslation>().Get(player);
How to add Properties/Fields that should not be serialized?
Syml uses in the background Yaml so you can just place YamlIgnore on top of the field/property and it will be ignored
What can I use as Config?
Syml supports every basic c# type (like string, int, float, double, array (list)) as well as types that are simple enough to be serialized, so you can create sub configs within your config
SerializedObjects
Since it is very tedious to create a new Type every time you want to store a Position Rotation or something else exist there a couple of predefined Types that can be casted to the proper Type that you actually want to store these are
Last updated