Fix wrong json conversion from numbers again

This commit is contained in:
DBotThePony 2024-04-22 21:43:01 +07:00
parent 3bb7e50315
commit 7270b1b47b
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -15,12 +15,14 @@ import org.classdump.luna.impl.NonsuspendableFunctionException
import org.classdump.luna.runtime.AbstractFunction3
import org.classdump.luna.runtime.ExecutionContext
import ru.dbotthepony.kommons.gson.set
import ru.dbotthepony.kommons.io.writeSignedVarLong
import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.kstarbound.math.AABB
import ru.dbotthepony.kommons.util.IStruct2d
import ru.dbotthepony.kommons.util.IStruct2i
import ru.dbotthepony.kommons.util.IStruct3i
import ru.dbotthepony.kommons.util.IStruct4i
import ru.dbotthepony.kstarbound.json.BinaryJsonReader
import ru.dbotthepony.kstarbound.math.vector.Vector2d
import ru.dbotthepony.kstarbound.math.vector.Vector2f
import ru.dbotthepony.kstarbound.math.vector.Vector2i
@ -187,7 +189,21 @@ fun TableFactory.from(value: JsonElement?): Any? {
when (value) {
is JsonPrimitive -> {
if (value.isNumber) {
return value.asNumber
return when (val v = value.asNumber) {
is Float, is Double -> value.asDouble
is Int, is Long -> value.asLong
else -> {
// hi com.google.gson.internal.LazilyParsedNumber
val doubleBits by lazy { v.toDouble() }
if (v.toString().contains('.') || doubleBits % 1.0 != 0.0) {
v.toDouble()
} else {
v.toLong()
}
}
}
} else if (value.isString) {
return ByteString.of(value.asString)
} else if (value.isBoolean) {