From 2ba64a57c5b561e39fd26f1c48465b08c0edf222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Marsero?= Date: Mon, 10 Feb 2025 19:44:36 -0500 Subject: [PATCH] Fix Global Class names cache not saved with upgrade to 4.4. Co-authored-by: Hilderin <81109165+Hilderin@users.noreply.github.com> --- editor/editor_data.cpp | 33 ++++++++++++++++----------------- editor/editor_data.h | 2 +- editor/editor_file_system.cpp | 17 ++++++++++------- editor/editor_file_system.h | 2 +- editor/editor_node.cpp | 28 ++++++++++++++++++---------- editor/editor_node.h | 2 ++ editor/filesystem_dock.cpp | 6 ++---- 7 files changed, 50 insertions(+), 40 deletions(-) diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index aec082791ef..d06472e3ce1 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -1046,24 +1046,23 @@ void EditorData::script_class_set_name(const String &p_path, const StringName &p _script_class_file_to_path[p_path] = p_class; } -void EditorData::script_class_save_icon_paths() { - Array script_classes = ProjectSettings::get_singleton()->get_global_class_list(); - - Dictionary d; - for (const KeyValue &E : _script_class_icon_paths) { - if (ScriptServer::is_global_class(E.key)) { - d[E.key] = E.value; - } +void EditorData::script_class_save_global_classes() { + List global_classes; + ScriptServer::get_global_class_list(&global_classes); + Array array_classes; + for (const StringName &class_name : global_classes) { + Dictionary d; + String *icon = _script_class_icon_paths.getptr(class_name); + d["class"] = class_name; + d["language"] = ScriptServer::get_global_class_language(class_name); + d["path"] = ScriptServer::get_global_class_path(class_name); + d["base"] = ScriptServer::get_global_class_base(class_name); + d["icon"] = icon ? *icon : String(); + d["is_abstract"] = ScriptServer::is_global_class_abstract(class_name); + d["is_tool"] = ScriptServer::is_global_class_tool(class_name); + array_classes.push_back(d); } - - for (int i = 0; i < script_classes.size(); i++) { - Dictionary d2 = script_classes[i]; - if (!d2.has("class")) { - continue; - } - d2["icon"] = d.get(d2["class"], ""); - } - ProjectSettings::get_singleton()->store_global_class_list(script_classes); + ProjectSettings::get_singleton()->store_global_class_list(array_classes); } void EditorData::script_class_load_icon_paths() { diff --git a/editor/editor_data.h b/editor/editor_data.h index 943c661b6b2..bc5a8daed81 100644 --- a/editor/editor_data.h +++ b/editor/editor_data.h @@ -251,7 +251,7 @@ public: String script_class_get_icon_path(const String &p_class, bool *r_valid = nullptr) const; void script_class_set_icon_path(const String &p_class, const String &p_icon_path); void script_class_clear_icon_paths() { _script_class_icon_paths.clear(); } - void script_class_save_icon_paths(); + void script_class_save_global_classes(); void script_class_load_icon_paths(); Ref extension_class_get_icon(const String &p_class) const; diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index d5c39bd4ef2..e78f77b5bf1 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -319,7 +319,12 @@ void EditorFileSystem::_first_scan_filesystem() { _first_scan_process_scripts(first_scan_root_dir, gdextension_extensions, existing_class_names, extensions); // Removing invalid global class to prevent having invalid paths in ScriptServer. - _remove_invalid_global_class_names(existing_class_names); + bool save_scripts = _remove_invalid_global_class_names(existing_class_names); + + // If a global class is found or removed, we sync global_script_class_cache.cfg with the ScriptServer + if (!existing_class_names.is_empty() || save_scripts) { + EditorNode::get_editor_data().script_class_save_global_classes(); + } // Processing extensions to add new extensions or remove invalid ones. // Important to do it in the first scan so custom types, new class names, custom importers, etc... @@ -1618,7 +1623,7 @@ void EditorFileSystem::_thread_func_sources(void *_userdata) { efs->scanning_changes_done.set(); } -void EditorFileSystem::_remove_invalid_global_class_names(const HashSet &p_existing_class_names) { +bool EditorFileSystem::_remove_invalid_global_class_names(const HashSet &p_existing_class_names) { List global_classes; bool must_save = false; ScriptServer::get_global_class_list(&global_classes); @@ -1628,9 +1633,7 @@ void EditorFileSystem::_remove_invalid_global_class_names(const HashSet must_save = true; } } - if (must_save) { - ScriptServer::save_global_classes(); - } + return must_save; } String EditorFileSystem::_get_file_by_class_name(EditorFileSystemDirectory *p_dir, const String &p_class_name, EditorFileSystemDirectory::FileInfo *&r_file_info) { @@ -2043,6 +2046,7 @@ EditorFileSystem::ScriptClassInfo EditorFileSystem::_get_global_script_class(con for (int i = 0; i < ScriptServer::get_language_count(); i++) { if (ScriptServer::get_language(i)->handles_global_class_type(p_type)) { info.name = ScriptServer::get_language(i)->get_global_class_name(p_path, &info.extends, &info.icon_path, &info.is_abstract, &info.is_tool); + break; } } return info; @@ -2130,8 +2134,7 @@ void EditorFileSystem::_update_script_classes() { update_script_paths.clear(); } - ScriptServer::save_global_classes(); - EditorNode::get_editor_data().script_class_save_icon_paths(); + EditorNode::get_editor_data().script_class_save_global_classes(); emit_signal("script_classes_updated"); diff --git a/editor/editor_file_system.h b/editor/editor_file_system.h index 82ae983d413..2e483a54257 100644 --- a/editor/editor_file_system.h +++ b/editor/editor_file_system.h @@ -374,7 +374,7 @@ class EditorFileSystem : public Node { void _update_file_icon_path(EditorFileSystemDirectory::FileInfo *file_info); void _update_files_icon_path(EditorFileSystemDirectory *edp = nullptr); - void _remove_invalid_global_class_names(const HashSet &p_existing_class_names); + bool _remove_invalid_global_class_names(const HashSet &p_existing_class_names); String _get_file_by_class_name(EditorFileSystemDirectory *p_dir, const String &p_class_name, EditorFileSystemDirectory::FileInfo *&r_file_info); void _register_global_class_script(const String &p_search_path, const String &p_target_path, const ScriptClassInfoUpdate &p_script_update); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index a733e1ce4e1..84a4b42f536 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -649,17 +649,11 @@ void EditorNode::_notification(int p_what) { OS::get_singleton()->benchmark_begin_measure("Editor", "First Scan"); - if (run_surface_upgrade_tool) { - run_surface_upgrade_tool = false; - SurfaceUpgradeTool::get_singleton()->connect("upgrade_finished", callable_mp(EditorFileSystem::get_singleton(), &EditorFileSystem::scan), CONNECT_ONE_SHOT); - SurfaceUpgradeTool::get_singleton()->finish_upgrade(); - } else if (run_uid_upgrade_tool) { - run_uid_upgrade_tool = false; - UIDUpgradeTool::get_singleton()->connect("upgrade_finished", callable_mp(EditorFileSystem::get_singleton(), &EditorFileSystem::scan), CONNECT_ONE_SHOT); - UIDUpgradeTool::get_singleton()->finish_upgrade(); - } else { - EditorFileSystem::get_singleton()->scan(); + if (run_surface_upgrade_tool || run_uid_upgrade_tool) { + EditorFileSystem::get_singleton()->connect("filesystem_changed", callable_mp(this, &EditorNode::_execute_upgrades), CONNECT_ONE_SHOT); } + + EditorFileSystem::get_singleton()->scan(); } } break; @@ -901,6 +895,20 @@ void EditorNode::_update_update_spinner() { OS::get_singleton()->set_low_processor_usage_mode(!update_continuously); } +void EditorNode::_execute_upgrades() { + if (run_surface_upgrade_tool) { + run_surface_upgrade_tool = false; + // Execute another scan to reimport the modified files. + SurfaceUpgradeTool::get_singleton()->connect("upgrade_finished", callable_mp(EditorFileSystem::get_singleton(), &EditorFileSystem::scan), CONNECT_ONE_SHOT); + SurfaceUpgradeTool::get_singleton()->finish_upgrade(); + } else if (run_uid_upgrade_tool) { + run_uid_upgrade_tool = false; + // Execute another scan to reimport the modified files. + UIDUpgradeTool::get_singleton()->connect("upgrade_finished", callable_mp(EditorFileSystem::get_singleton(), &EditorFileSystem::scan), CONNECT_ONE_SHOT); + UIDUpgradeTool::get_singleton()->finish_upgrade(); + } +} + void EditorNode::init_plugins() { _initializing_plugins = true; Vector addons; diff --git a/editor/editor_node.h b/editor/editor_node.h index 8e77a34e012..3ace2e868c5 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -675,6 +675,8 @@ private: void _progress_dialog_visibility_changed(); void _load_error_dialog_visibility_changed(); + void _execute_upgrades(); + protected: friend class FileSystemDock; diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 4d14bd7e3d1..4fafdefbb59 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1573,8 +1573,7 @@ void FileSystemDock::_update_resource_paths_after_move(const HashMapemit_signal(SNAME("script_classes_updated")); } @@ -1708,8 +1707,7 @@ void FileSystemDock::_resource_removed(const Ref &p_resource) { const Ref