[+] Change in-game settings

This commit is contained in:
Azalea
2024-03-19 19:58:00 -04:00
parent 6f34c21d94
commit 906199a517
7 changed files with 110 additions and 74 deletions

View File

@@ -47,7 +47,13 @@ annotation class SettingField(val name: Str, val desc: Str)
// Reflection
@Suppress("UNCHECKED_CAST")
fun <T : Any> KClass<T>.vars() = memberProperties.mapNotNull { it as? KMutableProperty1<T, Any> }
@Suppress("UNCHECKED_CAST")
fun <C, T: Any> KMutableProperty1<C, T>.setCast(obj: C, value: String) = set(obj, when (returnType.classifier) {
String::class -> value
Int::class -> value.toInt()
Boolean::class -> value.toBoolean()
else -> 400 - "Invalid field type $returnType"
} as T)
// Make it easier to throw a ResponseStatusException
operator fun HttpStatus.invoke(message: String? = null): Nothing = throw ApiException(value(), message ?: this.reasonPhrase)