GDScript: Implement export of typed arrays

This commit is contained in:
George Marques 2021-03-18 10:17:42 -03:00
parent 160c260495
commit 2b9be53243
No known key found for this signature in database
GPG key ID: 046BD46A3201E43D

View file

@ -3224,7 +3224,7 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node
variable->export_info.hint_string = hint_string;
// This is called after tne analyzer is done finding the type, so this should be set here.
const DataType &export_type = variable->get_datatype();
DataType export_type = variable->get_datatype();
if (p_annotation->name == "@export") {
if (variable->datatype_specifier == nullptr && variable->initializer == nullptr) {
@ -3232,6 +3232,13 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node
return false;
}
bool is_array = false;
if (export_type.builtin_type == Variant::ARRAY && export_type.has_container_element_type()) {
export_type = export_type.get_container_element_type(); // Use inner type for.
is_array = true;
}
if (export_type.is_variant() || export_type.has_no_type()) {
push_error(R"(Cannot use simple "@export" annotation because the type of the initialized value can't be inferred.)", p_annotation);
return false;
@ -3250,6 +3257,7 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node
variable->export_info.hint_string = get_real_class_name(export_type.native_type);
} else {
push_error(R"(Export type can only be built-in, a resource, or an enum.)", variable);
return false;
}
break;
case GDScriptParser::DataType::ENUM: {
@ -3274,6 +3282,16 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node
push_error(R"(Export type can only be built-in, a resource, or an enum.)", variable);
break;
}
if (is_array) {
String hint_prefix = itos(variable->export_info.type);
if (variable->export_info.hint) {
hint_prefix += "/" + itos(variable->export_info.hint);
}
variable->export_info.hint = PROPERTY_HINT_TYPE_STRING;
variable->export_info.hint_string = hint_prefix + ":" + variable->export_info.hint_string;
variable->export_info.type = Variant::ARRAY;
}
} else {
// Validate variable type with export.
if (!export_type.is_variant() && (export_type.kind != DataType::BUILTIN || export_type.builtin_type != t_type)) {