-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
185 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package dev.s7a.ktconfig.model | ||
|
||
import dev.s7a.ktconfig.KtConfigSerializer | ||
import dev.s7a.ktconfig.UseSerializer | ||
import kotlin.reflect.typeOf | ||
|
||
/** | ||
* Two-dimensional integer vector. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
@UseSerializer(IntVector2.Serializer::class) | ||
data class IntVector2(val x: Int, val y: Int) { | ||
/** | ||
* Serializer of [IntVector2] separated by commas. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
object Serializer : KtConfigSerializer<String, IntVector2> { | ||
override val type = typeOf<String>() | ||
|
||
override fun deserialize(value: String): IntVector2? { | ||
return runCatching { | ||
value.split(',').let { | ||
if (it.size != 2) return null | ||
val x = it[0].trim().toInt() | ||
val y = it[1].trim().toInt() | ||
IntVector2(x, y) | ||
} | ||
}.getOrNull() | ||
} | ||
|
||
override fun serialize(value: IntVector2): String { | ||
return "${value.x}, ${value.y}" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package dev.s7a.ktconfig.model | ||
|
||
import dev.s7a.ktconfig.KtConfigSerializer | ||
import dev.s7a.ktconfig.UseSerializer | ||
import kotlin.reflect.typeOf | ||
|
||
/** | ||
* Three-dimensional integer vector. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
@UseSerializer(IntVector3.Serializer::class) | ||
data class IntVector3(val x: Int, val y: Int, val z: Int) { | ||
/** | ||
* Serializer of [IntVector3] separated by commas. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
object Serializer : KtConfigSerializer<String, IntVector3> { | ||
override val type = typeOf<String>() | ||
|
||
override fun deserialize(value: String): IntVector3? { | ||
return runCatching { | ||
value.split(',').let { | ||
if (it.size != 3) return null | ||
val x = it[0].trim().toInt() | ||
val y = it[1].trim().toInt() | ||
val z = it[2].trim().toInt() | ||
IntVector3(x, y, z) | ||
} | ||
}.getOrNull() | ||
} | ||
|
||
override fun serialize(value: IntVector3): String { | ||
return "${value.x}, ${value.y}, ${value.z}" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package dev.s7a.ktconfig.model | ||
|
||
import dev.s7a.ktconfig.KtConfigSerializer | ||
import dev.s7a.ktconfig.UseSerializer | ||
import kotlin.reflect.typeOf | ||
|
||
/** | ||
* Two-dimensional vector. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
@UseSerializer(Vector2.Serializer::class) | ||
data class Vector2(val x: Double, val y: Double) { | ||
/** | ||
* Serializer of [Vector2] separated by commas. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
object Serializer : KtConfigSerializer<String, Vector2> { | ||
override val type = typeOf<String>() | ||
|
||
override fun deserialize(value: String): Vector2? { | ||
return runCatching { | ||
value.split(',').let { | ||
if (it.size != 2) return null | ||
val x = it[0].trim().toDouble() | ||
val y = it[1].trim().toDouble() | ||
Vector2(x, y) | ||
} | ||
}.getOrNull() | ||
} | ||
|
||
override fun serialize(value: Vector2): String { | ||
return "${value.x}, ${value.y}" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package dev.s7a.ktconfig.model | ||
|
||
import dev.s7a.ktconfig.KtConfigSerializer | ||
import dev.s7a.ktconfig.UseSerializer | ||
import kotlin.reflect.typeOf | ||
|
||
/** | ||
* Three-dimensional vector. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
@UseSerializer(Vector3.Serializer::class) | ||
data class Vector3(val x: Double, val y: Double, val z: Double) { | ||
/** | ||
* Serializer of [Vector3] separated by commas. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
object Serializer : KtConfigSerializer<String, Vector3> { | ||
override val type = typeOf<String>() | ||
|
||
override fun deserialize(value: String): Vector3? { | ||
return runCatching { | ||
value.split(',').let { | ||
if (it.size != 3) return null | ||
val x = it[0].trim().toDouble() | ||
val y = it[1].trim().toDouble() | ||
val z = it[2].trim().toDouble() | ||
Vector3(x, y, z) | ||
} | ||
}.getOrNull() | ||
} | ||
|
||
override fun serialize(value: Vector3): String { | ||
return "${value.x}, ${value.y}, ${value.z}" | ||
} | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
src/main/kotlin/dev/s7a/ktconfig/serializer/VectorString.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters