Skip to content

Commit 2041444

Browse files
authored
Change vararg conversion to buffer (#613)
1 parent b8b5a13 commit 2041444

File tree

1 file changed

+42
-44
lines changed
  • kt/godot-library/src/main/kotlin/godot/core

1 file changed

+42
-44
lines changed

kt/godot-library/src/main/kotlin/godot/core/Variant.kt

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
11
package godot.core
22

33
import godot.Object
4-
import godot.core.VariantType.*
54
import godot.core.VariantType.AABB
5+
import godot.core.VariantType.ANY
6+
import godot.core.VariantType.ARRAY
7+
import godot.core.VariantType.BASIS
8+
import godot.core.VariantType.BOOL
9+
import godot.core.VariantType.CALLABLE
10+
import godot.core.VariantType.COLOR
11+
import godot.core.VariantType.DICTIONARY
12+
import godot.core.VariantType.DOUBLE
13+
import godot.core.VariantType.JVM_BYTE
14+
import godot.core.VariantType.JVM_FLOAT
15+
import godot.core.VariantType.JVM_INT
16+
import godot.core.VariantType.LONG
17+
import godot.core.VariantType.NIL
18+
import godot.core.VariantType.NODE_PATH
19+
import godot.core.VariantType.PACKED_BYTE_ARRAY
20+
import godot.core.VariantType.PACKED_COLOR_ARRAY
21+
import godot.core.VariantType.PACKED_FLOAT_32_ARRAY
22+
import godot.core.VariantType.PACKED_FLOAT_64_ARRAY
23+
import godot.core.VariantType.PACKED_INT_32_ARRAY
24+
import godot.core.VariantType.PACKED_INT_64_ARRAY
25+
import godot.core.VariantType.PACKED_STRING_ARRAY
26+
import godot.core.VariantType.PACKED_VECTOR2_ARRAY
27+
import godot.core.VariantType.PACKED_VECTOR3_ARRAY
28+
import godot.core.VariantType.PLANE
29+
import godot.core.VariantType.PROJECTION
30+
import godot.core.VariantType.QUATERNION
31+
import godot.core.VariantType.RECT2
32+
import godot.core.VariantType.RECT2I
33+
import godot.core.VariantType.SIGNAL
34+
import godot.core.VariantType.STRING
35+
import godot.core.VariantType.STRING_NAME
36+
import godot.core.VariantType.TRANSFORM2D
37+
import godot.core.VariantType.TRANSFORM3D
38+
import godot.core.VariantType.VECTOR2
39+
import godot.core.VariantType.VECTOR2I
40+
import godot.core.VariantType.VECTOR3
41+
import godot.core.VariantType.VECTOR3I
42+
import godot.core.VariantType.VECTOR4
43+
import godot.core.VariantType.VECTOR4I
44+
import godot.core.VariantType._RID
645
import godot.core.memory.MemoryManager
746
import godot.signals.Signal
847
import godot.util.toRealT
@@ -683,49 +722,8 @@ enum class VariantType(
683722
entries[expectedType].toKotlinWithoutNullCheck(buffer, expectedType)
684723
},
685724
{ buffer: ByteBuffer, any: Any ->
686-
when (any) {
687-
is Unit -> NIL.toGodotWithoutNullCheck(buffer, any)
688-
is Byte -> JVM_BYTE.toGodotWithoutNullCheck(buffer, any)
689-
is Boolean -> BOOL.toGodotWithoutNullCheck(buffer, any)
690-
is Int -> JVM_INT.toGodotWithoutNullCheck(buffer, any)
691-
is Long -> LONG.toGodotWithoutNullCheck(buffer, any)
692-
is Float -> JVM_FLOAT.toGodotWithoutNullCheck(buffer, any)
693-
is Double -> DOUBLE.toGodotWithoutNullCheck(buffer, any)
694-
is String -> STRING.toGodotWithoutNullCheck(buffer, any)
695-
is Vector2 -> VECTOR2.toGodotWithoutNullCheck(buffer, any)
696-
is Vector2i -> VECTOR2I.toGodotWithoutNullCheck(buffer, any)
697-
is Rect2 -> RECT2.toGodotWithoutNullCheck(buffer, any)
698-
is Rect2i -> RECT2I.toGodotWithoutNullCheck(buffer, any)
699-
is Vector3 -> VECTOR3.toGodotWithoutNullCheck(buffer, any)
700-
is Vector3i -> VECTOR3I.toGodotWithoutNullCheck(buffer, any)
701-
is Transform2D -> TRANSFORM2D.toGodotWithoutNullCheck(buffer, any)
702-
is Vector4 -> VECTOR4.toGodotWithoutNullCheck(buffer, any)
703-
is Vector4i -> VECTOR4I.toGodotWithoutNullCheck(buffer, any)
704-
is Plane -> PLANE.toGodotWithoutNullCheck(buffer, any)
705-
is Quaternion -> QUATERNION.toGodotWithoutNullCheck(buffer, any)
706-
is godot.core.AABB -> AABB.toGodotWithoutNullCheck(buffer, any)
707-
is Basis -> BASIS.toGodotWithoutNullCheck(buffer, any)
708-
is Transform3D -> TRANSFORM3D.toGodotWithoutNullCheck(buffer, any)
709-
is Color -> COLOR.toGodotWithoutNullCheck(buffer, any)
710-
is StringName -> STRING_NAME.toGodotWithoutNullCheck(buffer, any)
711-
is NodePath -> NODE_PATH.toGodotWithoutNullCheck(buffer, any)
712-
is RID -> _RID.toGodotWithoutNullCheck(buffer, any)
713-
is VariantArray<*> -> ARRAY.toGodotWithoutNullCheck(buffer, any)
714-
is Callable -> CALLABLE.toGodotWithoutNullCheck(buffer, any)
715-
is Signal -> SIGNAL.toGodotWithoutNullCheck(buffer, any)
716-
is Dictionary<*, *> -> DICTIONARY.toGodotWithoutNullCheck(buffer, any)
717-
is PackedByteArray -> PACKED_BYTE_ARRAY.toGodotWithoutNullCheck(buffer, any)
718-
is PackedInt32Array -> PACKED_INT_32_ARRAY.toGodotWithoutNullCheck(buffer, any)
719-
is PackedInt64Array -> PACKED_INT_64_ARRAY.toGodotWithoutNullCheck(buffer, any)
720-
is PackedFloat32Array -> PACKED_FLOAT_32_ARRAY.toGodotWithoutNullCheck(buffer, any)
721-
is PackedFloat64Array -> PACKED_FLOAT_64_ARRAY.toGodotWithoutNullCheck(buffer, any)
722-
is PackedStringArray -> PACKED_STRING_ARRAY.toGodotWithoutNullCheck(buffer, any)
723-
is PackedVector2Array -> PACKED_VECTOR2_ARRAY.toGodotWithoutNullCheck(buffer, any)
724-
is PackedVector3Array -> PACKED_VECTOR3_ARRAY.toGodotWithoutNullCheck(buffer, any)
725-
is PackedColorArray -> PACKED_COLOR_ARRAY.toGodotWithoutNullCheck(buffer, any)
726-
is KtObject -> OBJECT.toGodotWithoutNullCheck(buffer, any)
727-
else -> throw UnsupportedOperationException("Can't convert type ${any::class} to Variant")
728-
}
725+
val type = variantMapper[any::class] ?: throw UnsupportedOperationException("Can't convert type ${any::class} to Variant")
726+
type.toGodotWithoutNullCheck(buffer, any)
729727
}
730728
);
731729

0 commit comments

Comments
 (0)