diff --git a/gradle.properties b/gradle.properties index 0e3fcfb..24212a0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ kotlin.code.style=official specifyKotlinAsDependency=false projectGroup=ru.dbotthepony.kommons -projectVersion=2.9.22 +projectVersion=2.9.23 guavaDepVersion=33.0.0 gsonDepVersion=2.8.9 diff --git a/gson-linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/gson/Vector3dTypeAdapter.kt b/gson-linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/gson/Vector3dTypeAdapter.kt new file mode 100644 index 0000000..91d4b4b --- /dev/null +++ b/gson-linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/gson/Vector3dTypeAdapter.kt @@ -0,0 +1,28 @@ +package ru.dbotthepony.kommons.gson + +import com.google.gson.TypeAdapter +import com.google.gson.stream.JsonReader +import com.google.gson.stream.JsonWriter +import ru.dbotthepony.kommons.vector.Vector3d + +object Vector3dTypeAdapter : TypeAdapter() { + override fun write(out: JsonWriter, value: Vector3d) { + `out`.beginArray() + `out`.value(value.x) + `out`.value(value.y) + `out`.value(value.z) + `out`.endArray() + } + + override fun read(`in`: JsonReader): Vector3d { + `in`.beginArray() + + val x = `in`.nextDouble() + val y = `in`.nextDouble() + val z = `in`.nextDouble() + + `in`.endArray() + + return Vector3d(x, y, z) + } +} diff --git a/gson-linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/gson/Vector3fTypeAdapter.kt b/gson-linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/gson/Vector3fTypeAdapter.kt new file mode 100644 index 0000000..6e750a2 --- /dev/null +++ b/gson-linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/gson/Vector3fTypeAdapter.kt @@ -0,0 +1,28 @@ +package ru.dbotthepony.kommons.gson + +import com.google.gson.TypeAdapter +import com.google.gson.stream.JsonReader +import com.google.gson.stream.JsonWriter +import ru.dbotthepony.kommons.vector.Vector3f + +object Vector3fTypeAdapter : TypeAdapter() { + override fun write(out: JsonWriter, value: Vector3f) { + `out`.beginArray() + `out`.value(value.x) + `out`.value(value.y) + `out`.value(value.z) + `out`.endArray() + } + + override fun read(`in`: JsonReader): Vector3f { + `in`.beginArray() + + val x = `in`.nextDouble().toFloat() + val y = `in`.nextDouble().toFloat() + val z = `in`.nextDouble().toFloat() + + `in`.endArray() + + return Vector3f(x, y, z) + } +} \ No newline at end of file diff --git a/gson-linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/gson/Vector3iTypeAdapter.kt b/gson-linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/gson/Vector3iTypeAdapter.kt new file mode 100644 index 0000000..fb82323 --- /dev/null +++ b/gson-linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/gson/Vector3iTypeAdapter.kt @@ -0,0 +1,28 @@ +package ru.dbotthepony.kommons.gson + +import com.google.gson.TypeAdapter +import com.google.gson.stream.JsonReader +import com.google.gson.stream.JsonWriter +import ru.dbotthepony.kommons.vector.Vector3i + +object Vector3iTypeAdapter : TypeAdapter() { + override fun write(out: JsonWriter, value: Vector3i) { + `out`.beginArray() + `out`.value(value.x) + `out`.value(value.y) + `out`.value(value.z) + `out`.endArray() + } + + override fun read(`in`: JsonReader): Vector3i { + `in`.beginArray() + + val x = `in`.nextInt() + val y = `in`.nextInt() + val z = `in`.nextInt() + + `in`.endArray() + + return Vector3i(x, y, z) + } +} \ No newline at end of file diff --git a/gson-linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/gson/Vector4fTypeAdapter.kt b/gson-linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/gson/Vector4fTypeAdapter.kt new file mode 100644 index 0000000..9a4cab1 --- /dev/null +++ b/gson-linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/gson/Vector4fTypeAdapter.kt @@ -0,0 +1,30 @@ +package ru.dbotthepony.kommons.gson + +import com.google.gson.TypeAdapter +import com.google.gson.stream.JsonReader +import com.google.gson.stream.JsonWriter +import ru.dbotthepony.kommons.vector.Vector4f + +object Vector4fTypeAdapter : TypeAdapter() { + override fun write(out: JsonWriter, value: Vector4f) { + `out`.beginArray() + `out`.value(value.x) + `out`.value(value.y) + `out`.value(value.z) + `out`.value(value.w) + `out`.endArray() + } + + override fun read(`in`: JsonReader): Vector4f { + `in`.beginArray() + + val x = `in`.nextDouble().toFloat() + val y = `in`.nextDouble().toFloat() + val z = `in`.nextDouble().toFloat() + val w = `in`.nextDouble().toFloat() + + `in`.endArray() + + return Vector4f(x, y, z, w) + } +}