Merge pull request #89324 from KoBeWi/pandora's_can_of_worms

Allow exporting variables of type Variant
This commit is contained in:
Thaddeus Crews 2025-04-28 10:01:33 -05:00
commit c87f23ce7d
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
5 changed files with 127 additions and 12 deletions

View file

@ -4568,14 +4568,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) {
@ -4626,6 +4621,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;