-
Notifications
You must be signed in to change notification settings - Fork 4
Configuration system
Orion uses Configurate library and HOCON for configurations.
Configuration files are in /modconfigs/<modname>.cfg
. Right now only one configuration file is supported, I think that it'll be sufficient for now as this modding platform isn't quite popular
Orion uses ObjectConfigurationLoader to map and serialize config from/to configuration file conveniently.
Instance of ObjectConfigurationLoader is injected to your plugin using Guice, you just have to add @Inject private ObjectConfigurationLoader<YourConfigClass> config
to your class.
Own configuration class can be specified in OrionMod annotation.
Configuration file base node is got from lowered case class name, unless you add ConfigurationBaseNode annotation, which will override that.
Mod class:
@OrionMod(id = "foo", configurationClass = FooConfig.class)
public final class Foo {
@Inject
private ObjectConfigurationLoader<FooConfig> configurationLoader;
@Inject
private Logger logger;
@Subscribe
public void on(ModConstructEvent e) throws Exception {
// Load & save to load configuration and then populate configuration file with new nodes (if not present in file)
configurationLoader.load();
configurationLoader.save();
// Log message
logger.info(configurationLoader.getConfiguration().logMessage);
}
}
Configuration class:
@ConfigSerializable
@ConfigurationBaseNode("foo") // Optional
public final class FooConfig {
@Setting(value = "log-message", comment = "Message to log into console on mod construct")
public String logMessage = "Orion rocks!";
}
And resulting configuration file:
foo {
# Message to log into console on mod construct
log-message="Orion rocks!"
}