diff --git a/editor/script/script_text_editor.cpp b/editor/script/script_text_editor.cpp index 7f1e3f2fdae..35caec6cb68 100644 --- a/editor/script/script_text_editor.cpp +++ b/editor/script/script_text_editor.cpp @@ -38,10 +38,13 @@ #include "editor/debugger/editor_debugger_node.h" #include "editor/doc/editor_help.h" #include "editor/docks/filesystem_dock.h" +#include "editor/editor_interface.h" #include "editor/editor_node.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_toaster.h" #include "editor/inspector/editor_context_menu_plugin.h" +#include "editor/inspector/editor_inspector.h" +#include "editor/inspector/multi_node_edit.h" #include "editor/settings/editor_command_palette.h" #include "editor/settings/editor_settings.h" #include "editor/themes/editor_scale.h" @@ -145,6 +148,10 @@ void ScriptTextEditor::apply_code() { } script->set_source_code(code_editor->get_text_editor()->get_text()); script->update_exports(); + if (!pending_dragged_exports.is_empty()) { + _assign_dragged_export_variables(); + } + code_editor->get_text_editor()->get_syntax_highlighter()->update_cache(); } @@ -868,6 +875,10 @@ void ScriptTextEditor::_validate_script() { _update_errors(); _update_background_color(); + if (!pending_dragged_exports.is_empty()) { + _assign_dragged_export_variables(); + } + emit_signal(SNAME("name_changed")); emit_signal(SNAME("edited_script_changed")); } @@ -2198,7 +2209,7 @@ static String _quote_drop_data(const String &str) { return escaped.quote(using_single_quotes ? "'" : "\""); } -static String _get_dropped_resource_line(const Ref &p_resource, bool p_create_field, bool p_allow_uid) { +static String _get_dropped_resource_as_member(const Ref &p_resource, bool p_create_field, bool p_allow_uid) { String path = p_resource->get_path(); if (p_allow_uid) { ResourceUID::ID id = ResourceLoader::get_resource_uid(path); @@ -2225,6 +2236,30 @@ static String _get_dropped_resource_line(const Ref &p_resource, bool p return vformat("const %s = preload(%s)", variable_name, _quote_drop_data(path)); } +String ScriptTextEditor::_get_dropped_resource_as_exported_member(const Ref &p_resource, const Vector &p_script_instance_obj_ids) { + String variable_name = p_resource->get_name(); + if (variable_name.is_empty()) { + variable_name = p_resource->get_path().get_file().get_basename(); + } + + variable_name = variable_name.to_snake_case().validate_unicode_identifier(); + for (ObjectID obj_id : p_script_instance_obj_ids) { + pending_dragged_exports.push_back(DraggedExport{ obj_id, variable_name, p_resource }); + } + + StringName class_name = p_resource->get_class(); + Ref