GDScript: Implement export of typed arrays
This commit is contained in:
parent
160c260495
commit
2b9be53243
1 changed files with 19 additions and 1 deletions
|
@ -3224,7 +3224,7 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node
|
||||||
variable->export_info.hint_string = hint_string;
|
variable->export_info.hint_string = hint_string;
|
||||||
|
|
||||||
// This is called after tne analyzer is done finding the type, so this should be set here.
|
// 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 (p_annotation->name == "@export") {
|
||||||
if (variable->datatype_specifier == nullptr && variable->initializer == nullptr) {
|
if (variable->datatype_specifier == nullptr && variable->initializer == nullptr) {
|
||||||
|
@ -3232,6 +3232,13 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node
|
||||||
return false;
|
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()) {
|
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);
|
push_error(R"(Cannot use simple "@export" annotation because the type of the initialized value can't be inferred.)", p_annotation);
|
||||||
return false;
|
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);
|
variable->export_info.hint_string = get_real_class_name(export_type.native_type);
|
||||||
} else {
|
} else {
|
||||||
push_error(R"(Export type can only be built-in, a resource, or an enum.)", variable);
|
push_error(R"(Export type can only be built-in, a resource, or an enum.)", variable);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GDScriptParser::DataType::ENUM: {
|
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);
|
push_error(R"(Export type can only be built-in, a resource, or an enum.)", variable);
|
||||||
break;
|
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 {
|
} else {
|
||||||
// Validate variable type with export.
|
// Validate variable type with export.
|
||||||
if (!export_type.is_variant() && (export_type.kind != DataType::BUILTIN || export_type.builtin_type != t_type)) {
|
if (!export_type.is_variant() && (export_type.kind != DataType::BUILTIN || export_type.builtin_type != t_type)) {
|
||||||
|
|
Loading…
Reference in a new issue