|
5 | 5 | ## |
6 | 6 | ## Use the "Project -> Tools -> Generate C# GDExtension Bindings" menu item to |
7 | 7 | ## generate C# bindings from GDExtension. |
8 | | -## |
9 | | -## TODO: support constant integers that are not part of any enum |
10 | 8 | @tool |
11 | 9 | extends EditorPlugin |
12 | 10 |
|
@@ -101,6 +99,21 @@ func generate_csharp_script(cls_name: StringName): |
101 | 99 | var enums = PackedStringArray() |
102 | 100 | for enum_name in ClassDB.class_get_enum_list(cls_name, true): |
103 | 101 | enums.append(_generate_enum(cls_name, enum_name)) |
| 102 | + |
| 103 | + # INTEGER CONSTANTS |
| 104 | + var integer_constants = PackedStringArray() |
| 105 | + for constant_name in ClassDB.class_get_integer_constant_list(cls_name, true): |
| 106 | + if not ClassDB.class_get_integer_constant_enum(cls_name, constant_name, true).is_empty(): |
| 107 | + continue |
| 108 | + integer_constants.append(_generate_integer_constant(cls_name, constant_name)) |
| 109 | + |
| 110 | + var inherited_integer_constants = PackedStringArray() |
| 111 | + if not parent_class_is_extension: |
| 112 | + for inherited_class in _get_parent_classes(cls_name): |
| 113 | + for constant_name in ClassDB.class_get_integer_constant_list(inherited_class, true): |
| 114 | + if not ClassDB.class_get_integer_constant_enum(cls_name, constant_name, true).is_empty(): |
| 115 | + continue |
| 116 | + inherited_integer_constants.append(_generate_integer_constant(inherited_class, constant_name)) |
104 | 117 |
|
105 | 118 | # PROPERTIES |
106 | 119 | var properties = PackedStringArray() |
@@ -161,6 +174,14 @@ func generate_csharp_script(cls_name: StringName): |
161 | 174 | regions.append("#region Enums") |
162 | 175 | regions.append("\n\n".join(enums)) |
163 | 176 | regions.append("#endregion") |
| 177 | + if not integer_constants.is_empty(): |
| 178 | + regions.append("#region Integer Constants") |
| 179 | + regions.append("\n\n".join(integer_constants)) |
| 180 | + regions.append("#endregion") |
| 181 | + if not inherited_integer_constants.is_empty(): |
| 182 | + regions.append("#region Inherited Integer Constants") |
| 183 | + regions.append("\n\n".join(inherited_integer_constants)) |
| 184 | + regions.append("#endregion") |
164 | 185 | if not properties.is_empty(): |
165 | 186 | regions.append("#region Properties") |
166 | 187 | regions.append("\n\n".join(properties)) |
@@ -249,6 +270,13 @@ static func _generate_enum(cls_name: StringName, enum_name: StringName) -> Strin |
249 | 270 | }).strip_edges() |
250 | 271 |
|
251 | 272 |
|
| 273 | +static func _generate_integer_constant(cls_name: StringName, constant_name: StringName) -> String: |
| 274 | + return "public const long {csharp_constant_name} = {constant_value}L;".format({ |
| 275 | + csharp_constant_name = constant_name.to_pascal_case(), |
| 276 | + constant_value = ClassDB.class_get_integer_constant(cls_name, constant_name), |
| 277 | + }) |
| 278 | + |
| 279 | + |
252 | 280 | static func _generate_property(cls_name: StringName, property: Dictionary) -> String: |
253 | 281 | var property_name = property["name"] |
254 | 282 | var csharp_property_name = property_name.to_pascal_case() |
|
0 commit comments