Make RGBAColorTypeAdapter accept hex strings as input
This commit is contained in:
parent
16ccb84d3b
commit
032f32626e
@ -1,5 +1,6 @@
|
|||||||
package ru.dbotthepony.kstarbound.json.factory
|
package ru.dbotthepony.kstarbound.json.factory
|
||||||
|
|
||||||
|
import com.google.gson.JsonSyntaxException
|
||||||
import com.google.gson.TypeAdapter
|
import com.google.gson.TypeAdapter
|
||||||
import com.google.gson.stream.JsonReader
|
import com.google.gson.stream.JsonReader
|
||||||
import com.google.gson.stream.JsonToken
|
import com.google.gson.stream.JsonToken
|
||||||
@ -29,6 +30,12 @@ object RGBAColorTypeAdapter : TypeAdapter<RGBAColor>() {
|
|||||||
if (`in`.consumeNull())
|
if (`in`.consumeNull())
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
if (`in`.peek() == JsonToken.STRING) {
|
||||||
|
val str = `in`.nextString()
|
||||||
|
val color = RGBAColor.fromHexStringRGB(str) ?: throw JsonSyntaxException("Not a valid hex color: $str")
|
||||||
|
return color
|
||||||
|
}
|
||||||
|
|
||||||
`in`.beginArray()
|
`in`.beginArray()
|
||||||
|
|
||||||
val red = `in`.nextInt()
|
val red = `in`.nextInt()
|
||||||
|
Loading…
Reference in New Issue
Block a user