diff options
author | George Marques <george@gmarqu.es> | 2021-03-18 10:17:42 -0300 |
---|---|---|
committer | George Marques <george@gmarqu.es> | 2021-03-30 08:29:38 -0300 |
commit | 2b9be53243e868a03894ffe8637c9983e7f0255f (patch) | |
tree | 5bf1be7e481fe0a575fc68ec25295d706fb3630b | |
parent | 160c26049566a8f392420d459d8a738e8e3b753d (diff) |
GDScript: Implement export of typed arrays
-rw-r--r-- | modules/gdscript/gdscript_parser.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 3bdbdcddcd..695154e9a9 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -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)) { |