Merge pull request #67055 from GuilhermeGSousa/custom-node-export

Added custom node export
This commit is contained in:
Rémi Verschelde 2022-10-31 11:11:07 +01:00
commit f4f98c4ecb
No known key found for this signature in database
GPG key ID: C3336907360768E1
5 changed files with 39 additions and 8 deletions

View file

@ -4392,6 +4392,27 @@ Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p
return nullptr;
}
bool EditorNode::is_object_of_custom_type(const Object *p_object, const StringName &p_class) {
ERR_FAIL_COND_V(!p_object, false);
Ref<Script> scr = p_object->get_script();
if (scr.is_null() && Object::cast_to<Script>(p_object)) {
scr = p_object;
}
if (scr.is_valid()) {
Ref<Script> base_script = scr;
while (base_script.is_valid()) {
StringName name = EditorNode::get_editor_data().script_class_get_name(base_script->get_path());
if (name == p_class) {
return true;
}
base_script = base_script->get_base_script();
}
}
return false;
}
void EditorNode::progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel) {
if (singleton->cmdline_export_mode) {
print_line(p_task + ": begin: " + p_label + " steps: " + itos(p_steps));

View file

@ -827,6 +827,8 @@ public:
Ref<Texture2D> get_object_icon(const Object *p_object, const String &p_fallback = "Object");
Ref<Texture2D> get_class_icon(const String &p_class, const String &p_fallback = "Object") const;
bool is_object_of_custom_type(const Object *p_object, const StringName &p_class);
void show_accept(const String &p_text, const String &p_title);
void show_save_accept(const String &p_text, const String &p_title);
void show_warning(const String &p_text, const String &p_title = TTR("Warning!"));

View file

@ -3699,7 +3699,8 @@ bool EditorPropertyNodePath::is_drop_valid(const Dictionary &p_drag_data) const
}
for (const StringName &E : valid_types) {
if (dropped_node->is_class(E)) {
if (dropped_node->is_class(E) ||
EditorNode::get_singleton()->is_object_of_custom_type(dropped_node, E)) {
return true;
}
}

View file

@ -483,8 +483,9 @@ void SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
if (valid_types.size()) {
bool valid = false;
for (int i = 0; i < valid_types.size(); i++) {
if (p_node->is_class(valid_types[i])) {
for (const StringName &E : valid_types) {
if (p_node->is_class(E) ||
EditorNode::get_singleton()->is_object_of_custom_type(p_node, E)) {
valid = true;
break;
}

View file

@ -3765,13 +3765,19 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node
break;
case GDScriptParser::DataType::CLASS:
// Can assume type is a global GDScript class.
if (!ClassDB::is_parent_class(export_type.native_type, SNAME("Resource"))) {
push_error(R"(Exported script type must extend Resource.)");
if (ClassDB::is_parent_class(export_type.native_type, SNAME("Resource"))) {
variable->export_info.type = Variant::OBJECT;
variable->export_info.hint = PROPERTY_HINT_RESOURCE_TYPE;
variable->export_info.hint_string = export_type.class_type->identifier->name;
} else if (ClassDB::is_parent_class(export_type.native_type, SNAME("Node"))) {
variable->export_info.type = Variant::OBJECT;
variable->export_info.hint = PROPERTY_HINT_NODE_TYPE;
variable->export_info.hint_string = export_type.class_type->identifier->name;
} else {
push_error(R"(Export type can only be built-in, a resource, a node or an enum.)", variable);
return false;
}
variable->export_info.type = Variant::OBJECT;
variable->export_info.hint = PROPERTY_HINT_RESOURCE_TYPE;
variable->export_info.hint_string = export_type.class_type->identifier->name;
break;
case GDScriptParser::DataType::SCRIPT: {
StringName class_name;