Merge pull request #49702 from aaronfranke/3.x-cs-bindings

[3.x] Fix C# bindings generator for default value types
This commit is contained in:
Rémi Verschelde 2021-06-18 11:22:03 +02:00 committed by GitHub
commit 160514724e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2564,28 +2564,37 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
}
break;
case Variant::REAL:
#ifndef REAL_T_IS_DOUBLE
r_iarg.default_argument += "f";
#endif
if (r_iarg.type.cname == "float") {
r_iarg.default_argument += "f";
}
break;
case Variant::STRING:
case Variant::NODE_PATH:
r_iarg.default_argument = "\"" + r_iarg.default_argument + "\"";
break;
case Variant::TRANSFORM:
if (p_val.operator Transform() == Transform())
r_iarg.default_argument.clear();
r_iarg.default_argument = "new %s(" + r_iarg.default_argument + ")";
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.def_param_mode = ArgumentInterface::NULLABLE_VAL;
break;
case Variant::PLANE:
case Variant::AABB:
case Variant::COLOR:
r_iarg.default_argument = "new Color(1, 1, 1, 1)";
} 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.def_param_mode = ArgumentInterface::NULLABLE_VAL;
break;
} 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.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;
case Variant::COLOR: {
if (r_iarg.default_argument == "1,1,1,1") {
r_iarg.default_argument = "1, 1, 1, 1";
}
r_iarg.default_argument = "new Color(" + r_iarg.default_argument + ")";
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;
case Variant::VECTOR2:
case Variant::RECT2:
case Variant::VECTOR3:
r_iarg.default_argument = "new %s" + r_iarg.default_argument;
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
@ -2620,14 +2629,46 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
r_iarg.default_argument = "new %s {}";
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_REF;
break;
case Variant::TRANSFORM2D:
case Variant::BASIS:
case Variant::QUAT:
r_iarg.default_argument = Variant::get_type_name(p_val.get_type()) + ".Identity";
case Variant::TRANSFORM2D: {
Transform2D transform = p_val.operator Transform2D();
if (transform == Transform2D()) {
r_iarg.default_argument = "Transform2D.Identity";
} else {
r_iarg.default_argument = "new Transform2D(new Vector2" + transform.elements[0].operator String() + ", new Vector2" + transform.elements[1].operator String() + ", new Vector2" + transform.elements[2].operator String() + ")";
}
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;
case Variant::TRANSFORM: {
Transform transform = p_val.operator Transform();
if (transform == Transform()) {
r_iarg.default_argument = "Transform.Identity";
} else {
Basis basis = transform.basis;
r_iarg.default_argument = "new Transform(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.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;
case Variant::BASIS: {
Basis basis = p_val.operator Basis();
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.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;
case Variant::QUAT: {
Quat quat = p_val.operator Quat();
if (quat == Quat()) {
r_iarg.default_argument = "Quat.Identity";
} else {
r_iarg.default_argument = "new Quat" + quat.operator String();
}
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;
default:
CRASH_NOW_MSG("Unexpected Variant type: " + itos(p_val.get_type()));
break;
default: {
}
}
if (r_iarg.def_param_mode == ArgumentInterface::CONSTANT && r_iarg.type.cname == name_cache.type_Variant && r_iarg.default_argument != "null")