summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-09-19 20:07:41 +0200
committerGitHub <noreply@github.com>2019-09-19 20:07:41 +0200
commit093c1c1a6944715ffa3dafd55f6cff21b925de24 (patch)
tree652c2690336e915032f30469875466abea050272
parentfc9985b770f28626ade78e189408571bbfabf1a6 (diff)
parentd53ddc5baa29a4fdcdcd56c772d1430747661229 (diff)
Merge pull request #31985 from nekomatata/fix-builtin-script-resource
Fixed resource loading when editing built-in script from resource
-rw-r--r--editor/plugins/script_editor_plugin.cpp43
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));
}