summaryrefslogtreecommitdiffstats
path: root/modules/mono/editor
diff options
context:
space:
mode:
authorSpartan322 <Megacake1234@gmail.com>2024-11-02 03:14:40 -0400
committerSpartan322 <Megacake1234@gmail.com>2024-11-02 03:22:12 -0400
commita684ee1dec108bb1a050f07ec3dd73fd5ef02dbc (patch)
treee9de2ee4820e24a159d2c06b1ace11f89c4e97c4 /modules/mono/editor
parent3302f803aa4ea09b16a8824ca3bea33f3e2b48ba (diff)
parentc6c464cf9ae56e8b68620af65125dd980d0e8122 (diff)
downloadredot-engine-a684ee1dec108bb1a050f07ec3dd73fd5ef02dbc.tar.gz
Merge commit godotengine/godot@c6c464cf9ae56e8b68620af65125dd980d0e8122
Diffstat (limited to 'modules/mono/editor')
-rw-r--r--modules/mono/editor/bindings_generator.cpp110
1 files changed, 95 insertions, 15 deletions
diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp
index 7b6b5461ab..400ff0a3b8 100644
--- a/modules/mono/editor/bindings_generator.cpp
+++ b/modules/mono/editor/bindings_generator.cpp
@@ -4374,9 +4374,45 @@ bool BindingsGenerator::_populate_object_type_interfaces() {
return true;
}
+static String _get_vector2_cs_ctor_args(const Vector2 &p_vec2) {
+ return String::num_real(p_vec2.x, true) + "f, " +
+ String::num_real(p_vec2.y, true) + "f";
+}
+
+static String _get_vector3_cs_ctor_args(const Vector3 &p_vec3) {
+ return String::num_real(p_vec3.x, true) + "f, " +
+ String::num_real(p_vec3.y, true) + "f, " +
+ String::num_real(p_vec3.z, true) + "f";
+}
+
+static String _get_vector4_cs_ctor_args(const Vector4 &p_vec4) {
+ return String::num_real(p_vec4.x, true) + "f, " +
+ String::num_real(p_vec4.y, true) + "f, " +
+ String::num_real(p_vec4.z, true) + "f, " +
+ String::num_real(p_vec4.w, true) + "f";
+}
+
+static String _get_vector2i_cs_ctor_args(const Vector2i &p_vec2i) {
+ return itos(p_vec2i.x) + ", " + itos(p_vec2i.y);
+}
+
+static String _get_vector3i_cs_ctor_args(const Vector3i &p_vec3i) {
+ return itos(p_vec3i.x) + ", " + itos(p_vec3i.y) + ", " + itos(p_vec3i.z);
+}
+
+static String _get_vector4i_cs_ctor_args(const Vector4i &p_vec4i) {
+ return itos(p_vec4i.x) + ", " + itos(p_vec4i.y) + ", " + itos(p_vec4i.z) + ", " + itos(p_vec4i.w);
+}
+
+static String _get_color_cs_ctor_args(const Color &p_color) {
+ return String::num(p_color.r, 4) + "f, " +
+ String::num(p_color.g, 4) + "f, " +
+ String::num(p_color.b, 4) + "f, " +
+ String::num(p_color.a, 4) + "f";
+}
+
bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, ArgumentInterface &r_iarg) {
r_iarg.def_param_value = p_val;
- r_iarg.default_argument = p_val.operator String();
switch (p_val.get_type()) {
case Variant::NIL:
@@ -4389,10 +4425,14 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
break;
case Variant::INT:
if (r_iarg.type.cname != name_cache.type_int) {
- r_iarg.default_argument = "(%s)(" + r_iarg.default_argument + ")";
+ r_iarg.default_argument = "(%s)(" + p_val.operator String() + ")";
+ } else {
+ r_iarg.default_argument = p_val.operator String();
}
break;
case Variant::FLOAT:
+ r_iarg.default_argument = p_val.operator String();
+
if (r_iarg.type.cname == name_cache.type_float) {
r_iarg.default_argument += "f";
}
@@ -4402,7 +4442,7 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
case Variant::NODE_PATH:
if (r_iarg.type.cname == name_cache.type_StringName || r_iarg.type.cname == name_cache.type_NodePath) {
if (r_iarg.default_argument.length() > 0) {
- r_iarg.default_argument = "(%s)\"" + r_iarg.default_argument + "\"";
+ r_iarg.default_argument = "(%s)\"" + p_val.operator String() + "\"";
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_REF;
} else {
// No need for a special `in` statement to change `null` to `""`. Marshaling takes care of this already.
@@ -4410,40 +4450,62 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
}
} else {
CRASH_COND(r_iarg.type.cname != name_cache.type_String);
- r_iarg.default_argument = "\"" + r_iarg.default_argument + "\"";
+ r_iarg.default_argument = "\"" + p_val.operator String() + "\"";
}
break;
case Variant::PLANE: {
Plane plane = p_val.operator Plane();
- r_iarg.default_argument = "new Plane(new Vector3" + plane.normal.operator String() + ", " + rtos(plane.d) + ")";
+ r_iarg.default_argument = "new Plane(new Vector3(" +
+ _get_vector3_cs_ctor_args(plane.normal) + "), " + rtos(plane.d) + "f)";
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;
case Variant::AABB: {
AABB aabb = p_val.operator ::AABB();
- r_iarg.default_argument = "new Aabb(new Vector3" + aabb.position.operator String() + ", new Vector3" + aabb.size.operator String() + ")";
+ r_iarg.default_argument = "new Aabb(new Vector3(" +
+ _get_vector3_cs_ctor_args(aabb.position) + "), new Vector3(" +
+ _get_vector3_cs_ctor_args(aabb.size) + "))";
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;
case Variant::RECT2: {
Rect2 rect = p_val.operator Rect2();
- r_iarg.default_argument = "new Rect2(new Vector2" + rect.position.operator String() + ", new Vector2" + rect.size.operator String() + ")";
+ r_iarg.default_argument = "new Rect2(new Vector2(" +
+ _get_vector2_cs_ctor_args(rect.position) + "), new Vector2(" +
+ _get_vector2_cs_ctor_args(rect.size) + "))";
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;
case Variant::RECT2I: {
Rect2i rect = p_val.operator Rect2i();
- r_iarg.default_argument = "new Rect2I(new Vector2I" + rect.position.operator String() + ", new Vector2I" + rect.size.operator String() + ")";
+ r_iarg.default_argument = "new Rect2I(new Vector2I(" +
+ _get_vector2i_cs_ctor_args(rect.position) + "), new Vector2I(" +
+ _get_vector2i_cs_ctor_args(rect.size) + "))";
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;
case Variant::COLOR:
+ r_iarg.default_argument = "new Color(" + _get_color_cs_ctor_args(p_val.operator Color()) + ")";
+ r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
+ break;
case Variant::VECTOR2:
+ r_iarg.default_argument = "new Vector2(" + _get_vector2_cs_ctor_args(p_val.operator Vector2()) + ")";
+ r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
+ break;
case Variant::VECTOR2I:
+ r_iarg.default_argument = "new Vector2I(" + _get_vector2i_cs_ctor_args(p_val.operator Vector2i()) + ")";
+ r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
+ break;
case Variant::VECTOR3:
+ r_iarg.default_argument = "new Vector3(" + _get_vector3_cs_ctor_args(p_val.operator Vector3()) + ")";
+ r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
+ break;
case Variant::VECTOR3I:
- r_iarg.default_argument = "new %s" + r_iarg.default_argument;
+ r_iarg.default_argument = "new Vector3I(" + _get_vector3i_cs_ctor_args(p_val.operator Vector3i()) + ")";
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
break;
case Variant::VECTOR4:
+ r_iarg.default_argument = "new Vector4(" + _get_vector4_cs_ctor_args(p_val.operator Vector4()) + ")";
+ r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
+ break;
case Variant::VECTOR4I:
- r_iarg.default_argument = "new %s" + r_iarg.default_argument;
+ r_iarg.default_argument = "new Vector4I(" + _get_vector4i_cs_ctor_args(p_val.operator Vector4i()) + ")";
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
break;
case Variant::OBJECT:
@@ -4493,7 +4555,10 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
if (transform == Transform2D()) {
r_iarg.default_argument = "Transform2D.Identity";
} else {
- r_iarg.default_argument = "new Transform2D(new Vector2" + transform.columns[0].operator String() + ", new Vector2" + transform.columns[1].operator String() + ", new Vector2" + transform.columns[2].operator String() + ")";
+ r_iarg.default_argument = "new Transform2D(new Vector2(" +
+ _get_vector2_cs_ctor_args(transform.columns[0]) + "), new Vector2(" +
+ _get_vector2_cs_ctor_args(transform.columns[1]) + "), new Vector2(" +
+ _get_vector2_cs_ctor_args(transform.columns[2]) + "))";
}
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;
@@ -4503,7 +4568,11 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
r_iarg.default_argument = "Transform3D.Identity";
} else {
Basis basis = transform.basis;
- r_iarg.default_argument = "new Transform3D(new Vector3" + basis.get_column(0).operator String() + ", new Vector3" + basis.get_column(1).operator String() + ", new Vector3" + basis.get_column(2).operator String() + ", new Vector3" + transform.origin.operator String() + ")";
+ r_iarg.default_argument = "new Transform3D(new Vector3(" +
+ _get_vector3_cs_ctor_args(basis.get_column(0)) + "), new Vector3(" +
+ _get_vector3_cs_ctor_args(basis.get_column(1)) + "), new Vector3(" +
+ _get_vector3_cs_ctor_args(basis.get_column(2)) + "), new Vector3(" +
+ _get_vector3_cs_ctor_args(transform.origin) + "))";
}
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;
@@ -4512,7 +4581,11 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
if (projection == Projection()) {
r_iarg.default_argument = "Projection.Identity";
} else {
- r_iarg.default_argument = "new Projection(new Vector4" + projection.columns[0].operator String() + ", new Vector4" + projection.columns[1].operator String() + ", new Vector4" + projection.columns[2].operator String() + ", new Vector4" + projection.columns[3].operator String() + ")";
+ r_iarg.default_argument = "new Projection(new Vector4(" +
+ _get_vector4_cs_ctor_args(projection.columns[0]) + "), new Vector4(" +
+ _get_vector4_cs_ctor_args(projection.columns[1]) + "), new Vector4(" +
+ _get_vector4_cs_ctor_args(projection.columns[2]) + "), new Vector4(" +
+ _get_vector4_cs_ctor_args(projection.columns[3]) + "))";
}
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;
@@ -4521,7 +4594,10 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
if (basis == Basis()) {
r_iarg.default_argument = "Basis.Identity";
} else {
- r_iarg.default_argument = "new Basis(new Vector3" + basis.get_column(0).operator String() + ", new Vector3" + basis.get_column(1).operator String() + ", new Vector3" + basis.get_column(2).operator String() + ")";
+ r_iarg.default_argument = "new Basis(new Vector3(" +
+ _get_vector3_cs_ctor_args(basis.get_column(0)) + "), new Vector3(" +
+ _get_vector3_cs_ctor_args(basis.get_column(1)) + "), new Vector3(" +
+ _get_vector3_cs_ctor_args(basis.get_column(2)) + "))";
}
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;
@@ -4530,7 +4606,11 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
if (quaternion == Quaternion()) {
r_iarg.default_argument = "Quaternion.Identity";
} else {
- r_iarg.default_argument = "new Quaternion" + quaternion.operator String();
+ r_iarg.default_argument = "new Quaternion(" +
+ String::num_real(quaternion.x, false) + "f, " +
+ String::num_real(quaternion.y, false) + "f, " +
+ String::num_real(quaternion.z, false) + "f, " +
+ String::num_real(quaternion.w, false) + "f)";
}
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;