-
-
Notifications
You must be signed in to change notification settings - Fork 287
Support enums in arrays, with correct export hints #353
Description
The relevant type string hint is generated here:
gdext/godot-core/src/builtin/array.rs
Line 645 in 3ab6b2a
| format!("{}:{}", sys::VariantType::Array as i32, T::type_string()) |
Example code:
...
pub struct Textbox {
...
#[export]
font_types: Array<FontType>,
...
}
...vs.
extends Control
enum Foo {
Bar = 0,
Baz = 1,
Qux = 2,
}
@export
var lol: Array[Foo] = []When inspected via
func _ready():
for prop in get_property_list():
if prop.name == "lol":
print(prop)
var mt = Textbox.new()
for prop in mt.get_property_list():
if prop.name == "font_types":
print(prop)the following output is obtained:
{ "name": "lol", "class_name": &"", "type": 28, "hint": 23, "hint_string": "2/2:Bar:0,Baz:1,Qux:2", "usage": 4102 }
{ "name": "font_types", "class_name": &"Textbox", "type": 28, "hint": 23, "hint_string": "Generic33x8:0,Greek33x3:1,Cyrillic33x4:2,Compact6x6:3", "usage": 6 }
Note the missing "2/2:" prefix. After some digging around, the first 2 apparently stands for VariantType::Int, the second 2 stands for PROPERTY_HINT_ENUM, though I am not 100% sure of this.
Note that the gdext version does not work in the editor, it simply shows up as unspecified ints, while the gdscript variant shows the enum labels.
Note that I implement TypeStringHint for FontType with what is essentially the "hint_string" from the output. From my understanding, there should still be a prefix added to the hint from the line referenced above, but it appears to not be added.