Added settings to allow levels with other versions.

This commit is contained in:
2026-03-26 14:48:18 +08:00
parent e0e7de73a1
commit e8713c08c7
2 changed files with 44 additions and 9 deletions
@@ -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
@@ -2,9 +2,11 @@
package cn.rdlevel.rdkt.core.settings 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.annotations.RDKTInternalAPI
import cn.rdlevel.rdkt.core.serialization.MutableStringListSerializedInString 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.CURRENT_LEVEL_VERSION
import cn.rdlevel.rdkt.core.settings.LevelSettings.Companion.allowOldLevels
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlin.jvm.JvmName import kotlin.jvm.JvmName
import kotlin.random.Random 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]. * The version of the level. Currently, it is set to [67][CURRENT_LEVEL_VERSION].
* *
* This library currently does not support levels with other versions. * 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.
* If you want to use levels with other versions, please use the level editor to convert them to a supported version. * 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 public var version: Int = CURRENT_LEVEL_VERSION
set(value) { set(value) {
require(value == CURRENT_LEVEL_VERSION) { if (!allowOldLevels) {
""" require(value == CURRENT_LEVEL_VERSION) {
Levels with version $value is not supported. """
Currently, the supported level version is $CURRENT_LEVEL_VERSION. Levels with version $value is not supported.
If you want to use levels with other versions, please use the level editor to convert them to a supported version. Currently, the supported level version is $CURRENT_LEVEL_VERSION.
""".trimIndent() 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 field = value
} }
@@ -198,6 +207,13 @@ public class LevelSettings {
* The current level version the level editor is using. * The current level version the level editor is using.
*/ */
public const val CURRENT_LEVEL_VERSION: Int = 67 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
} }
} }