diff options
author | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2019-09-04 20:00:09 +0200 |
---|---|---|
committer | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2019-09-07 16:54:01 +0200 |
commit | d53ddc5baa29a4fdcdcd56c772d1430747661229 (patch) | |
tree | 678f25c651b3dc46a1c088c91ebe98b4beac9466 | |
parent | d1a062662fb1da17cb9aec92e8b218929cb26fd6 (diff) |
Fixed resource loading when editing built-in script from resource
Fixes #27380
-rw-r--r-- | editor/plugins/script_editor_plugin.cpp | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 8b6bab374c..f79c9d5062 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -538,9 +538,13 @@ void ScriptEditor::_open_recent_script(int p_idx) { // if it's a path then it's most likely a deleted file not help } else if (path.find("::") != -1) { // built-in script - String scene_path = path.get_slice("::", 0); - if (!EditorNode::get_singleton()->is_scene_open(scene_path)) { - EditorNode::get_singleton()->load_scene(scene_path); + String res_path = path.get_slice("::", 0); + if (ResourceLoader::get_resource_type(res_path) == "PackedScene") { + if (!EditorNode::get_singleton()->is_scene_open(res_path)) { + EditorNode::get_singleton()->load_scene(res_path); + } + } else { + EditorNode::get_singleton()->load_resource(res_path); } Ref<Script> script = ResourceLoader::load(path); if (script.is_valid()) { @@ -1028,12 +1032,16 @@ void ScriptEditor::_menu_option(int p_option) { if (extensions.find(path.get_extension()) || built_in) { if (built_in) { - String scene_path = path.get_slice("::", 0); - if (!EditorNode::get_singleton()->is_scene_open(scene_path)) { - EditorNode::get_singleton()->load_scene(scene_path); - script_editor->call_deferred("_menu_option", p_option); - previous_scripts.push_back(path); //repeat the operation - return; + String res_path = path.get_slice("::", 0); + if (ResourceLoader::get_resource_type(res_path) == "PackedScene") { + if (!EditorNode::get_singleton()->is_scene_open(res_path)) { + EditorNode::get_singleton()->load_scene(res_path); + script_editor->call_deferred("_menu_option", p_option); + previous_scripts.push_back(path); //repeat the operation + return; + } + } else { + EditorNode::get_singleton()->load_resource(res_path); } } @@ -3463,15 +3471,18 @@ void ScriptEditorPlugin::edit(Object *p_object) { if (Object::cast_to<Script>(p_object)) { Script *p_script = Object::cast_to<Script>(p_object); - String scene_path = p_script->get_path().get_slice("::", 0); - - if (_is_built_in_script(p_script) && !EditorNode::get_singleton()->is_scene_open(scene_path)) { - EditorNode::get_singleton()->load_scene(scene_path); + String res_path = p_script->get_path().get_slice("::", 0); - script_editor->call_deferred("edit", p_script); - } else { - script_editor->edit(p_script); + if (_is_built_in_script(p_script)) { + if (ResourceLoader::get_resource_type(res_path) == "PackedScene") { + if (!EditorNode::get_singleton()->is_scene_open(res_path)) { + EditorNode::get_singleton()->load_scene(res_path); + } + } else { + EditorNode::get_singleton()->load_resource(res_path); + } } + script_editor->edit(p_script); } else if (Object::cast_to<TextFile>(p_object)) { script_editor->edit(Object::cast_to<TextFile>(p_object)); } |