From e8713c08c7ff826ffd96656264fdaee46f03f04a Mon Sep 17 00:00:00 2001 From: NoMathExpectation <85624722+NoMathExpectation@users.noreply.github.com> Date: Thu, 26 Mar 2026 14:48:18 +0800 Subject: [PATCH] Added settings to allow levels with other versions. --- .../core/annotations/RDKTExperimentalAPI.kt | 19 +++++++++++ .../rdkt/core/settings/LevelSettings.kt | 34 ++++++++++++++----- 2 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/annotations/RDKTExperimentalAPI.kt diff --git a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/annotations/RDKTExperimentalAPI.kt b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/annotations/RDKTExperimentalAPI.kt new file mode 100644 index 0000000..adc3eac --- /dev/null +++ b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/annotations/RDKTExperimentalAPI.kt @@ -0,0 +1,19 @@ +package cn.rdlevel.rdkt.core.annotations + +/** + * Marks an API as experimental. This means that the API is still in development and may be changed or removed in a future release. + */ +@MustBeDocumented +@Target( + AnnotationTarget.CLASS, + AnnotationTarget.FUNCTION, + AnnotationTarget.PROPERTY, + AnnotationTarget.TYPEALIAS, + AnnotationTarget.CONSTRUCTOR, +) +@Retention(AnnotationRetention.BINARY) +@RequiresOptIn( + "This API is experimental and may be changed or removed in a future release. Use with caution.", + RequiresOptIn.Level.WARNING, +) +public annotation class RDKTExperimentalAPI \ No newline at end of file diff --git a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/settings/LevelSettings.kt b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/settings/LevelSettings.kt index e56b232..cf6b12b 100644 --- a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/settings/LevelSettings.kt +++ b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/settings/LevelSettings.kt @@ -2,9 +2,11 @@ package cn.rdlevel.rdkt.core.settings +import cn.rdlevel.rdkt.core.annotations.RDKTExperimentalAPI import cn.rdlevel.rdkt.core.annotations.RDKTInternalAPI import cn.rdlevel.rdkt.core.serialization.MutableStringListSerializedInString import cn.rdlevel.rdkt.core.settings.LevelSettings.Companion.CURRENT_LEVEL_VERSION +import cn.rdlevel.rdkt.core.settings.LevelSettings.Companion.allowOldLevels import kotlinx.serialization.Serializable import kotlin.jvm.JvmName import kotlin.random.Random @@ -18,19 +20,26 @@ public class LevelSettings { /** * The version of the level. Currently, it is set to [67][CURRENT_LEVEL_VERSION]. * - * This library currently does not support levels with other versions. - * If you want to use levels with other versions, please use the level editor to convert them to a supported version. + * This library currently does not designed to support levels with other versions. It may be not compatible with levels with other versions and may cause unexpected behavior. + * Please consider using the level editor to convert levels with other versions to a supported version before using them with this library. * - * Changing this version number to a not supported one will throw an exception. + * If you still want to use levels with other versions, see [allowOldLevels]. + * + * Changing this version number to a not supported one without setting [allowOldLevels] to true will throw an exception. + * + * @see allowOldLevels */ + @OptIn(RDKTExperimentalAPI::class) public var version: Int = CURRENT_LEVEL_VERSION set(value) { - require(value == CURRENT_LEVEL_VERSION) { - """ - Levels with version $value is not supported. - Currently, the supported level version is $CURRENT_LEVEL_VERSION. - If you want to use levels with other versions, please use the level editor to convert them to a supported version. - """.trimIndent() + if (!allowOldLevels) { + require(value == CURRENT_LEVEL_VERSION) { + """ + Levels with version $value is not supported. + Currently, the supported level version is $CURRENT_LEVEL_VERSION. + If you want to use levels with other versions, please use the level editor to convert them to a supported version, or set allowOldLevels to true (not recommended). + """.trimIndent() + } } field = value } @@ -198,6 +207,13 @@ public class LevelSettings { * The current level version the level editor is using. */ public const val CURRENT_LEVEL_VERSION: Int = 67 + + /** + * Allows using levels with versions other than [CURRENT_LEVEL_VERSION]. + * It is not recommended to use this unless you know what you are doing, as it may cause unexpected behavior and this library may not be compatible with levels with other versions. + */ + @RDKTExperimentalAPI + public var allowOldLevels: Boolean = false } }