diff --git a/src/main/kotlin/io/arkosammy12/monkeyconfig/builders/ConfigElementBuilder.kt b/src/main/kotlin/io/arkosammy12/monkeyconfig/builders/ConfigElementBuilder.kt index b8c209a..778e6e5 100644 --- a/src/main/kotlin/io/arkosammy12/monkeyconfig/builders/ConfigElementBuilder.kt +++ b/src/main/kotlin/io/arkosammy12/monkeyconfig/builders/ConfigElementBuilder.kt @@ -2,6 +2,7 @@ package io.arkosammy12.monkeyconfig.builders import io.arkosammy12.monkeyconfig.base.ConfigElement import io.arkosammy12.monkeyconfig.util.ElementPath +import org.slf4j.Logger sealed class ConfigElementBuilder>( val name: String, @@ -9,6 +10,8 @@ sealed class ConfigElementBuilder Unit)? = null diff --git a/src/main/kotlin/io/arkosammy12/monkeyconfig/builders/ConfigManagerBuilder.kt b/src/main/kotlin/io/arkosammy12/monkeyconfig/builders/ConfigManagerBuilder.kt index 7e45839..b0c7b45 100644 --- a/src/main/kotlin/io/arkosammy12/monkeyconfig/builders/ConfigManagerBuilder.kt +++ b/src/main/kotlin/io/arkosammy12/monkeyconfig/builders/ConfigManagerBuilder.kt @@ -39,6 +39,7 @@ open class ConfigManagerBuilder( val path = ElementPath(settingName) val settingBuilder: T = builderInstanceProvider(settingName, defaultValue, path) builder(settingBuilder) + settingBuilder.logger = this.logger this.internalConfigElementBuilders.add(settingBuilder) return path } @@ -67,12 +68,14 @@ open class ConfigManagerBuilder( fun section(sectionName: String, builderInstanceProvider: (String, ConfigManagerBuilder) -> SectionBuilder = ::SectionBuilder, builder: SectionBuilder.() -> Unit) { val sectionBuilder: SectionBuilder = builderInstanceProvider(sectionName, this) builder(sectionBuilder) + sectionBuilder.logger = this.logger this.internalConfigElementBuilders.add(sectionBuilder) } fun , T : MapSectionBuilder> mapSection(sectionName: String, builderInstanceProvider: (String) -> T, builder: T.() -> Unit): ElementPath { val mapSectionBuilder = builderInstanceProvider(sectionName) builder(mapSectionBuilder) + mapSectionBuilder.logger = this.logger this.internalConfigElementBuilders.add(mapSectionBuilder) return mapSectionBuilder.path } @@ -82,7 +85,6 @@ open class ConfigManagerBuilder( } -// TODO: Add some way to add the file extension or atleast warn the user to use the correct file extension in the file path @JvmOverloads fun > configManager(fileName: String, fileFormat: T, filePath: Path, builderInstanceProvider: (String, T, Path) -> ConfigManagerBuilder = ::ConfigManagerBuilder, builder: ConfigManagerBuilder.() -> Unit): ConfigManager { if (fileName.contains(".")) { diff --git a/src/main/kotlin/io/arkosammy12/monkeyconfig/builders/MapSectionBuilder.kt b/src/main/kotlin/io/arkosammy12/monkeyconfig/builders/MapSectionBuilder.kt index cee96cb..dcdfaad 100644 --- a/src/main/kotlin/io/arkosammy12/monkeyconfig/builders/MapSectionBuilder.kt +++ b/src/main/kotlin/io/arkosammy12/monkeyconfig/builders/MapSectionBuilder.kt @@ -19,6 +19,10 @@ open class MapSectionBuilder>( internal val defaultEntries: MutableMap = mutableMapOf() + init { + this.logger = parent?.logger + } + fun addDefaultEntry(entry: Pair) { val key: String = entry.first val value: V = entry.second diff --git a/src/main/kotlin/io/arkosammy12/monkeyconfig/builders/SectionBuilder.kt b/src/main/kotlin/io/arkosammy12/monkeyconfig/builders/SectionBuilder.kt index 31be788..4d9b380 100644 --- a/src/main/kotlin/io/arkosammy12/monkeyconfig/builders/SectionBuilder.kt +++ b/src/main/kotlin/io/arkosammy12/monkeyconfig/builders/SectionBuilder.kt @@ -24,10 +24,15 @@ open class SectionBuilder( override var implementation: (SectionBuilder) -> Section = ::DefaultSection + init { + this.logger = parent?.logger + } + fun , I : Setting, T : SettingBuilder> setting(settingName: String, defaultValue: V, builderInstanceProvider: (String, V, ElementPath) -> T, builder: T.() -> Unit): ElementPath { val path: ElementPath = this.path.withAppendedNode(settingName) val settingBuilder = builderInstanceProvider(settingName, defaultValue, path) builder(settingBuilder) + settingBuilder.logger = this.logger this.internalConfigElementBuilders.add(settingBuilder) return path } @@ -56,12 +61,14 @@ open class SectionBuilder( fun section(sectionName: String, builderInstanceProvider: (String, ConfigManagerBuilder, SectionBuilder?) -> SectionBuilder = ::SectionBuilder, builder: SectionBuilder.() -> Unit) { val sectionBuilder: SectionBuilder = builderInstanceProvider(sectionName, this.manager, this) builder(sectionBuilder) + sectionBuilder.logger = this.logger this.internalConfigElementBuilders.add(sectionBuilder) } fun , T : MapSectionBuilder> mapSection(sectionName: String, builderInstanceProvider: (String, SectionBuilder) -> T, builder: T.() -> Unit): ElementPath { val mapSectionBuilder = builderInstanceProvider(sectionName, this) builder(mapSectionBuilder) + mapSectionBuilder.logger = this.logger this.internalConfigElementBuilders.add(mapSectionBuilder) return mapSectionBuilder.path } diff --git a/src/main/kotlin/io/arkosammy12/monkeyconfig/sections/AbstractSection.kt b/src/main/kotlin/io/arkosammy12/monkeyconfig/sections/AbstractSection.kt index 4e0e244..27fed73 100644 --- a/src/main/kotlin/io/arkosammy12/monkeyconfig/sections/AbstractSection.kt +++ b/src/main/kotlin/io/arkosammy12/monkeyconfig/sections/AbstractSection.kt @@ -5,6 +5,7 @@ import io.arkosammy12.monkeyconfig.base.sections import io.arkosammy12.monkeyconfig.base.settings import io.arkosammy12.monkeyconfig.builders.SectionBuilder import io.arkosammy12.monkeyconfig.util.ElementPath +import org.slf4j.Logger abstract class AbstractSection( sectionBuilder: SectionBuilder, @@ -26,6 +27,8 @@ abstract class AbstractSection( protected val onSavedFunction: ((Section) -> Unit)? = sectionBuilder.onSaved + protected val logger: Logger? = sectionBuilder.logger + override val isInitialized: Boolean get() = this.internalIsInitialized diff --git a/src/main/kotlin/io/arkosammy12/monkeyconfig/sections/DefaultSection.kt b/src/main/kotlin/io/arkosammy12/monkeyconfig/sections/DefaultSection.kt index 158626b..76542ae 100644 --- a/src/main/kotlin/io/arkosammy12/monkeyconfig/sections/DefaultSection.kt +++ b/src/main/kotlin/io/arkosammy12/monkeyconfig/sections/DefaultSection.kt @@ -20,10 +20,6 @@ class DefaultSection( } this.configElements = configElements.toList() - - // TODO: Make sure there are no accidental duplicates - //sectionBuilder.internalSettingBuilders.clear() - //sectionBuilder.subSections.clear() } diff --git a/src/main/kotlin/io/arkosammy12/monkeyconfig/sections/maps/AbstractMapSection.kt b/src/main/kotlin/io/arkosammy12/monkeyconfig/sections/maps/AbstractMapSection.kt index 121b0c1..323b2b9 100644 --- a/src/main/kotlin/io/arkosammy12/monkeyconfig/sections/maps/AbstractMapSection.kt +++ b/src/main/kotlin/io/arkosammy12/monkeyconfig/sections/maps/AbstractMapSection.kt @@ -10,6 +10,7 @@ import io.arkosammy12.monkeyconfig.types.ListType import io.arkosammy12.monkeyconfig.types.SerializableType import io.arkosammy12.monkeyconfig.types.toSerializedType import io.arkosammy12.monkeyconfig.util.ElementPath +import org.slf4j.Logger abstract class AbstractMapSection>( mapSectionBuilder: MapSectionBuilder @@ -46,6 +47,8 @@ abstract class AbstractMapSection>( protected val onSavedFunction: ((MapSection) -> Unit)? = mapSectionBuilder.onSaved + protected val logger: Logger? = mapSectionBuilder.logger + init { val mapEntries: MutableList> = mutableListOf() val defaultMapEntries: MutableList> = mutableListOf() @@ -113,9 +116,9 @@ abstract class AbstractMapSection>( } } - override fun updateValue(fileConfig: FileConfig) { + override fun updateValue(fileConfig: FileConfig) { val config: Config = fileConfig.get(this.path.string) ?: run { - // TODO: LOG + this.logger?.error("Found no Section with name ${this.name} to load values from!") return } val tempEntries: MutableList> = mutableListOf() @@ -124,7 +127,7 @@ abstract class AbstractMapSection>( val serializedEntryValue: SerializableType<*> = toSerializedType(rawEntryValue) val newMapEntry: Setting? = this.getEntryFromSerialized(ElementPath(*this.path.asArray, entry.key), serializedEntryValue) if (newMapEntry == null) { - // TODO: LOG + this.logger?.error("Unable to read value of entry ${entry.key}, from MapSection ${this.name}! This entry will be skipped.") continue } tempEntries.add(newMapEntry) diff --git a/src/main/kotlin/io/arkosammy12/monkeyconfig/settings/AbstractSetting.kt b/src/main/kotlin/io/arkosammy12/monkeyconfig/settings/AbstractSetting.kt index 9caf5a8..556b738 100644 --- a/src/main/kotlin/io/arkosammy12/monkeyconfig/settings/AbstractSetting.kt +++ b/src/main/kotlin/io/arkosammy12/monkeyconfig/settings/AbstractSetting.kt @@ -4,6 +4,7 @@ import io.arkosammy12.monkeyconfig.base.Setting import io.arkosammy12.monkeyconfig.builders.SettingBuilder import io.arkosammy12.monkeyconfig.types.SerializableType import io.arkosammy12.monkeyconfig.util.ElementPath +import org.slf4j.Logger abstract class AbstractSetting, I : AbstractSetting>( settingBuilder: SettingBuilder @@ -21,6 +22,8 @@ abstract class AbstractSetting, I : AbstractSet protected val onUpdatedFunction: ((I) -> Unit)? = settingBuilder.onUpdated + protected val logger: Logger? = settingBuilder.logger + override fun toString(): String = "${this::class.simpleName}{name=$name, path=$path, value=$value, comment=$comment}" diff --git a/src/main/kotlin/io/arkosammy12/monkeyconfig/values/NumberSettingValue.kt b/src/main/kotlin/io/arkosammy12/monkeyconfig/values/NumberSettingValue.kt index c7f1493..989d0e4 100644 --- a/src/main/kotlin/io/arkosammy12/monkeyconfig/values/NumberSettingValue.kt +++ b/src/main/kotlin/io/arkosammy12/monkeyconfig/values/NumberSettingValue.kt @@ -3,24 +3,26 @@ package io.arkosammy12.monkeyconfig.values import io.arkosammy12.monkeyconfig.types.NumberType +import org.slf4j.Logger -class NumberSettingValue( +class NumberSettingValue @JvmOverloads constructor( default: T, raw: T = default, val minValue: T?, val maxValue: T?, + logger: Logger? = null, serializer: (T) -> NumberType, deserializer: (NumberType) -> T -) : SettingValue>(default, raw, serializer, deserializer) { +) : SettingValue>(default, raw, logger, serializer, deserializer) { override var raw: T set(value) { if (minValue != null && value < this.minValue) { - // TODO: LOG + this.logger?.error("Value $value is below the minimum value for $this") return } if (this.maxValue != null && value > this.maxValue) { - // TODO: LOG + this.logger?.error("Value $value is above the maximum value for $this") return } super.raw = value diff --git a/src/main/kotlin/io/arkosammy12/monkeyconfig/values/SettingValue.kt b/src/main/kotlin/io/arkosammy12/monkeyconfig/values/SettingValue.kt index d0fd27b..e4a05ad 100644 --- a/src/main/kotlin/io/arkosammy12/monkeyconfig/values/SettingValue.kt +++ b/src/main/kotlin/io/arkosammy12/monkeyconfig/values/SettingValue.kt @@ -1,10 +1,12 @@ package io.arkosammy12.monkeyconfig.values import io.arkosammy12.monkeyconfig.types.SerializableType +import org.slf4j.Logger -open class SettingValue>( +open class SettingValue> @JvmOverloads constructor( val default: V, open var raw: V = default, + protected val logger: Logger? = null, private val serializer: (V) -> S, private val deserializer: (S) -> V ) { diff --git a/src/test/kotlin/io/arkosammy12/monkeyconfig/Main.kt b/src/test/kotlin/io/arkosammy12/monkeyconfig/Main.kt index 416194d..dceb213 100644 --- a/src/test/kotlin/io/arkosammy12/monkeyconfig/Main.kt +++ b/src/test/kotlin/io/arkosammy12/monkeyconfig/Main.kt @@ -29,7 +29,7 @@ object Main { comment = "Test comment" minValue = 0 maxValue = 10 - implementation = { builder -> TestNumberSetting(builder) } + implementation = ::TestNumberSetting } section("testSubsection") { comment = "Test comment"