Improved config DSL

This commit is contained in:
Auxilor
2022-04-25 20:02:28 +01:00
parent c9a9d86160
commit c1fe633e72

View File

@@ -7,7 +7,7 @@ import com.willfp.eco.core.config.interfaces.Config
/**
* Helper class to create configs with a kotlin DSL.
*/
class DSLConfig internal constructor() : BuildableConfig() {
class DSLConfig internal constructor(type: ConfigType) : TransientConfig(emptyMap(), type) {
infix fun String.to(value: Any?) =
set(this, value)
}
@@ -19,4 +19,26 @@ class DSLConfig internal constructor() : BuildableConfig() {
* @return The config.
*/
fun config(builder: DSLConfig.() -> Unit): Config =
DSLConfig().apply(builder)
DSLConfig(ConfigType.YAML).apply(builder)
/**
* Helper function to create configs with a kotlin DSL.
*
* @param type The config type.
* @param builder The builder.
* @return The config.
*/
fun config(type: ConfigType, builder: DSLConfig.() -> Unit): Config =
DSLConfig(type).apply(builder)
/**
* Helper function to create configs with a kotlin DSL.
*
* Inherits the config type of the sub-builder.
*
* @param builder The builder.
* @return The config.
*/
fun DSLConfig.config(builder: DSLConfig.() -> Unit): Config =
DSLConfig(this.type).apply(builder)