@@ -384,13 +384,19 @@ static func _generate_method(cls_name: StringName, method: Dictionary) -> String
384384 for default_value in default_args :
385385 if default_value == null :
386386 default_value = "default"
387+ # handle enums
387388 elif default_value is int and arg_types [i ] != "int" :
388389 default_value = ("(%s )" % arg_types [i ]) + str (default_value )
389- elif default_value is String :
390- default_value = '"%s "' % default_value
391- elif default_value is StringName :
390+ # C# requires the "f" suffix for float literals
391+ elif default_value is float and arg_types [i ] == "float" :
392+ default_value = "%s f" % default_value
393+ # NOTE: don't move this branch below the String one, since most of the
394+ # time when arg_types[i] == StringName, default_value is String
395+ elif default_value is StringName or arg_types [i ] == "Godot.StringName" :
392396 implementation .append ('%s ??= "%s ";' % [arg_names [i ], default_value ])
393397 default_value = "null"
398+ elif default_value is String :
399+ default_value = '"%s "' % default_value
394400 elif default_value is Array :
395401 assert (default_value .is_empty (), "Populated Array not supported yet! " + str (default_value )) # TODO: support populated array as default value
396402 implementation .append ("%s ??= new();" % arg_names [i ])
@@ -399,6 +405,36 @@ static func _generate_method(cls_name: StringName, method: Dictionary) -> String
399405 assert (default_value .is_empty (), "Populated Dictionary not supported yet! " + str (default_value )) # TODO: support populated dictionary as default value
400406 implementation .append ("%s ??= new();" % arg_names [i ])
401407 default_value = "null"
408+ elif (
409+ default_value is Vector2 or default_value is Vector3 or default_value is Vector4
410+ or default_value is Color
411+ ):
412+ args [i ] = args [i ].replace (arg_types [i ], arg_types [i ] + "?" )
413+ var impl = "%s ??= new%s ;" % [arg_names [i ], default_value ]
414+ if not OS .has_feature ("double" ):
415+ impl = impl .replace ("," , "f," ).replace (")" , "f)" )
416+ implementation .append (impl )
417+ default_value = "null"
418+ elif (
419+ default_value is PackedByteArray
420+ or default_value is PackedInt32Array or default_value is PackedInt64Array
421+ or default_value is PackedFloat32Array or default_value is PackedFloat64Array
422+ or default_value is PackedVector2Array or default_value is PackedVector3Array or default_value is PackedVector4Array
423+ or default_value is PackedColorArray
424+ ):
425+ assert (default_value .is_empty (), "Populated Packed Array not supported yet! " + str (default_value ))
426+ implementation .append ("%s ??= System.Array.Empty<%s >();" % [arg_names [i ], arg_types [i ].replace ("[]" , "" )])
427+ default_value = "null"
428+ elif default_value is Transform2D :
429+ assert (default_value == Transform2D .IDENTITY , "Only identity Transform2D is supported as default value" )
430+ args [i ] = args [i ].replace (arg_types [i ], arg_types [i ] + "?" )
431+ implementation .append ("%s ??= Godot.Transform2D.Identity;" % arg_names [i ])
432+ default_value = "null"
433+ elif default_value is Transform3D :
434+ assert (default_value == Transform3D .IDENTITY , "Only identity Transform3D is supported as default value" )
435+ args [i ] = args [i ].replace (arg_types [i ], arg_types [i ] + "?" )
436+ implementation .append ("%s ??= Godot.Transform3D.Identity;" % arg_names [i ])
437+ default_value = "null"
402438 args [i ] += " = " + str (default_value )
403439 i += 1
404440
0 commit comments