Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix synchronization of global class name #92303

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 31 additions & 26 deletions editor/editor_autoload_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ void EditorAutoloadSettings::_notification(int p_what) {
file_dialog->add_filter("*." + E);
}

for (const AutoloadInfo &info : autoload_cache) {
if (info.node && info.in_editor) {
callable_mp((Node *)get_tree()->get_root(), &Node::add_child).call_deferred(info.node, false, Node::INTERNAL_MODE_DISABLED);
}
}
browse_button->set_icon(get_editor_theme_icon(SNAME("Folder")));
} break;

Expand Down Expand Up @@ -419,6 +414,8 @@ Node *EditorAutoloadSettings::_create_autoload(const String &p_path) {

Ref<Script> scr = res;
if (scr.is_valid()) {
ERR_FAIL_COND_V_MSG(!scr->is_valid(), nullptr, vformat("Failed to create an autoload, script '%s' is not compiling.", p_path));
AThousandShips marked this conversation as resolved.
Show resolved Hide resolved

StringName ibt = scr->get_instance_base_type();
bool valid_type = ClassDB::is_parent_class(ibt, "Node");
ERR_FAIL_COND_V_MSG(!valid_type, nullptr, vformat("Failed to create an autoload, script '%s' does not inherit from 'Node'.", p_path));
Expand All @@ -436,6 +433,35 @@ Node *EditorAutoloadSettings::_create_autoload(const String &p_path) {
return n;
}

void EditorAutoloadSettings::init_autoloads() {
for (AutoloadInfo &info : autoload_cache) {
info.node = _create_autoload(info.path);

if (info.node) {
Ref<Script> scr = info.node->get_script();
info.in_editor = scr.is_valid() && scr->is_tool();
info.node->set_name(info.name);
}

if (info.is_singleton) {
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
ScriptServer::get_language(i)->add_named_global_constant(info.name, info.node);
}
}

if (!info.is_singleton && !info.in_editor && info.node != nullptr) {
memdelete(info.node);
info.node = nullptr;
}
}

for (const AutoloadInfo &info : autoload_cache) {
if (info.node && info.in_editor) {
callable_mp((Node *)get_tree()->get_root(), &Node::add_child).call_deferred(info.node, false, Node::INTERNAL_MODE_DISABLED);
}
}
adamscott marked this conversation as resolved.
Show resolved Hide resolved
}

void EditorAutoloadSettings::update_autoload() {
if (updating_autoload) {
return;
Expand Down Expand Up @@ -857,27 +883,6 @@ EditorAutoloadSettings::EditorAutoloadSettings() {
autoload_cache.push_back(info);
}

for (AutoloadInfo &info : autoload_cache) {
info.node = _create_autoload(info.path);

if (info.node) {
Ref<Script> scr = info.node->get_script();
info.in_editor = scr.is_valid() && scr->is_tool();
info.node->set_name(info.name);
}

if (info.is_singleton) {
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
ScriptServer::get_language(i)->add_named_global_constant(info.name, info.node);
}
}

if (!info.is_singleton && !info.in_editor && info.node != nullptr) {
memdelete(info.node);
info.node = nullptr;
}
}

HBoxContainer *hbc = memnew(HBoxContainer);
add_child(hbc);

Expand Down
1 change: 1 addition & 0 deletions editor/editor_autoload_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class EditorAutoloadSettings : public VBoxContainer {
static void _bind_methods();

public:
void init_autoloads();
void update_autoload();
bool autoload_add(const String &p_name, const String &p_path);
void autoload_remove(const String &p_name);
Expand Down
Loading
Loading