diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/Setting.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/Setting.kt index 153d78982..923a4d890 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/Setting.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/Setting.kt @@ -13,6 +13,7 @@ package net.mamoe.mirai.console.setting import net.mamoe.mirai.console.setting.internal.cast import net.mamoe.mirai.console.setting.internal.valueFromKTypeImpl +import net.mamoe.mirai.console.setting.internal.valueImpl import net.mamoe.mirai.utils.MiraiExperimentalAPI import kotlin.internal.LowPriorityInOverloadResolution import kotlin.reflect.KProperty @@ -54,7 +55,7 @@ internal abstract class SettingImpl { // TODO: 2020/6/19 CODEGEN -fun Setting.value(value: Int): IntValue = TODO("codegen") +fun Setting.value(default: Int): IntValue = valueImpl(default) //// endregion Setting.value primitives CODEGEN //// diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/ValueDeclarationsImpl.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/CompositeValueImpl.kt similarity index 87% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/ValueDeclarationsImpl.kt rename to backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/CompositeValueImpl.kt index c4726e915..1b611fe9d 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/ValueDeclarationsImpl.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/CompositeValueImpl.kt @@ -13,25 +13,6 @@ package net.mamoe.mirai.console.setting.internal import net.mamoe.mirai.console.setting.* -internal abstract class IntValueImpl : IntValue { - constructor() - constructor(default: Int) { - _value = default - } - - private var _value: Int? = null - - override var value: Int - get() = _value ?: throw IllegalStateException("IntValue should be initialized before get.") - set(v) { - if (v != this._value) { - this._value = v - onChanged() - } - } - - protected abstract fun onChanged() -} // type inference bug internal fun Setting.createCompositeSetValueImpl(tToValue: (T) -> Value): CompositeSetValueImpl { diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/ValueCreatorsImpl.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/Setting.value composite impl.kt similarity index 100% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/ValueCreatorsImpl.kt rename to backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/Setting.value composite impl.kt diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/_PrimitiveValueDeclareations.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/_PrimitiveValueDeclareations.kt new file mode 100644 index 000000000..650200b97 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/_PrimitiveValueDeclareations.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +package net.mamoe.mirai.console.setting.internal + +import net.mamoe.mirai.console.setting.IntValue + + +//// region PrimitiveValues CODEGEN //// + +// TODO: 2020/6/21 CODEGEN + +internal abstract class IntValueImpl : IntValue { + constructor() + constructor(default: Int) { + _value = default + } + + private var _value: Int? = null + + override var value: Int + get() = _value ?: throw IllegalStateException("IntValue should be initialized before get.") + set(v) { + if (v != this._value) { + this._value = v + onChanged() + } + } + + protected abstract fun onChanged() +} + +//// endregion PrimitiveValues CODEGEN //// diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/_Setting.value.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/_Setting.value.kt new file mode 100644 index 000000000..76e8e5331 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/_Setting.value.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +package net.mamoe.mirai.console.setting.internal + +import net.mamoe.mirai.console.setting.IntValue +import net.mamoe.mirai.console.setting.Setting + + +//// region Setting.value primitives impl CODEGEN //// + +// TODO: 2020/6/21 CODEGEN + +internal fun Setting.valueImpl(default: Int): IntValue = object : IntValueImpl(default) { + override fun onChanged() = this@valueImpl.onValueChanged(this) +} + +//// endregion Setting.value primitives impl CODEGEN //// diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/internal.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/serializerUtil.kt similarity index 100% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/internal.kt rename to backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/serializerUtil.kt