Allow exporting variables of type Variant

This commit is contained in:
kobewi 2024-03-24 21:36:35 +01:00
parent 96cdbbe5bd
commit 012d47b089
5 changed files with 127 additions and 12 deletions

View file

@ -4533,14 +4533,9 @@ bool GDScriptParser::export_annotations(AnnotationNode *p_annotation, Node *p_ta
return false;
}
if (export_type.is_variant() || export_type.has_no_type()) {
if (is_dict) {
// Dictionary allowed to have a variant key/value.
export_type.kind = GDScriptParser::DataType::BUILTIN;
} else {
push_error(R"(Cannot use simple "@export" annotation because the type of the initialized value can't be inferred.)", p_annotation);
return false;
}
if (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;
}
switch (export_type.kind) {
@ -4591,6 +4586,12 @@ bool GDScriptParser::export_annotations(AnnotationNode *p_annotation, Node *p_ta
variable->export_info.class_name = String(export_type.native_type).replace("::", ".");
}
} break;
case GDScriptParser::DataType::VARIANT: {
if (export_type.is_variant()) {
variable->export_info.type = Variant::NIL;
variable->export_info.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
}
} break;
default:
push_error(R"(Export type can only be built-in, a resource, a node, or an enum.)", p_annotation);
return false;