Skip to content

Commit

Permalink
Further fixes to global script class parsing
Browse files Browse the repository at this point in the history
Bugs were introduced on first parse by godotengine#71628

This should fix everything remaining. No errors of any type were observed.
  • Loading branch information
reduz committed Jan 19, 2023
1 parent cd0a9cc commit c0a81b1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
36 changes: 29 additions & 7 deletions editor/editor_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ void EditorFileSystem::scan() {
new_filesystem = nullptr;
_update_scan_actions();
scanning = false;
_update_pending_script_classes();
emit_signal(SNAME("filesystem_changed"));
emit_signal(SNAME("sources_changed"), sources_changed.size() > 0);
first_scan = false;
Expand Down Expand Up @@ -923,6 +924,10 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, Ref<DirAc
fi->modified_time = mt;
fi->import_modified_time = 0;
fi->import_valid = true;

if (ClassDB::is_parent_class(fi->type, SNAME("Script"))) {
_queue_update_script_class(path);
}
}
}

Expand Down Expand Up @@ -1174,7 +1179,9 @@ void EditorFileSystem::scan_changes() {
sp.low = 0;
scan_total = 0;
_scan_fs_changes(filesystem, sp);
if (_update_scan_actions()) {
bool changed = _update_scan_actions();
_update_pending_script_classes();
if (changed) {
emit_signal(SNAME("filesystem_changed"));
}
}
Expand Down Expand Up @@ -1223,7 +1230,9 @@ void EditorFileSystem::_notification(int p_what) {
set_process(false);

thread_sources.wait_to_finish();
if (_update_scan_actions()) {
bool changed = _update_scan_actions();
_update_pending_script_classes();
if (changed) {
emit_signal(SNAME("filesystem_changed"));
}
emit_signal(SNAME("sources_changed"), sources_changed.size() > 0);
Expand All @@ -1239,6 +1248,7 @@ void EditorFileSystem::_notification(int p_what) {
new_filesystem = nullptr;
thread.wait_to_finish();
_update_scan_actions();
_update_pending_script_classes();
emit_signal(SNAME("filesystem_changed"));
emit_signal(SNAME("sources_changed"), sources_changed.size() > 0);
first_scan = false;
Expand Down Expand Up @@ -1508,11 +1518,20 @@ void EditorFileSystem::_update_script_classes() {
lang = ScriptServer::get_language(j)->get_name();
}
}
if (lang.is_empty()) {
continue; // No lang found that can handle this global class
}

ScriptServer::add_global_class(efd->files[index]->script_class_name, efd->files[index]->script_class_extends, lang, path);
EditorNode::get_editor_data().script_class_set_icon_path(efd->files[index]->script_class_name, efd->files[index]->script_class_icon_path);
EditorNode::get_editor_data().script_class_set_name(efd->files[index]->file, efd->files[index]->script_class_name);
}
}

// Parse documentation second, as it requires the class names to be correct and registered
for (const String &path : update_script_paths) {
int index = -1;
EditorFileSystemDirectory *efd = find_file(path, &index);

for (int i = 0; i < ScriptServer::get_language_count(); i++) {
ScriptLanguage *lang = ScriptServer::get_language(i);
Expand Down Expand Up @@ -1545,14 +1564,16 @@ void EditorFileSystem::_update_script_classes() {
ResourceSaver::add_custom_savers();
}

void EditorFileSystem::_update_pending_script_classes() {
if (!update_script_paths.is_empty()) {
_update_script_classes();
}
}

void EditorFileSystem::_queue_update_script_class(const String &p_path) {
update_script_mutex.lock();
bool call_update = update_script_paths.is_empty();
update_script_paths.insert(p_path);
update_script_mutex.unlock();
if (call_update) {
call_deferred(SNAME("_update_script_classes"));
}
}

void EditorFileSystem::update_file(const String &p_file) {
Expand Down Expand Up @@ -1582,6 +1603,7 @@ void EditorFileSystem::update_file(const String &p_file) {
fs->files.remove_at(cpos);
}

_update_pending_script_classes();
call_deferred(SNAME("emit_signal"), "filesystem_changed"); //update later
return;
}
Expand Down Expand Up @@ -1646,6 +1668,7 @@ void EditorFileSystem::update_file(const String &p_file) {
_queue_update_script_class(p_file);
}

_update_pending_script_classes();
call_deferred(SNAME("emit_signal"), "filesystem_changed"); //update later
}

Expand Down Expand Up @@ -2428,7 +2451,6 @@ void EditorFileSystem::_bind_methods() {
ClassDB::bind_method(D_METHOD("update_file", "path"), &EditorFileSystem::update_file);
ClassDB::bind_method(D_METHOD("get_filesystem_path", "path"), &EditorFileSystem::get_filesystem_path);
ClassDB::bind_method(D_METHOD("get_file_type", "path"), &EditorFileSystem::get_file_type);
ClassDB::bind_method(D_METHOD("_update_script_classes"), &EditorFileSystem::_update_script_classes);
ClassDB::bind_method(D_METHOD("reimport_files", "files"), &EditorFileSystem::reimport_files);

ADD_SIGNAL(MethodInfo("filesystem_changed"));
Expand Down
1 change: 1 addition & 0 deletions editor/editor_file_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ class EditorFileSystem : public Node {
HashSet<String> update_script_paths;
void _queue_update_script_class(const String &p_path);
void _update_script_classes();
void _update_pending_script_classes();

String _get_global_script_class(const String &p_type, const String &p_path, String *r_extends, String *r_icon_path) const;

Expand Down

0 comments on commit c0a81b1

Please sign in to comment.