Merge pull request #31985 from nekomatata/fix-builtin-script-resource

Fixed resource loading when editing built-in script from resource
This commit is contained in:
Rémi Verschelde 2019-09-19 20:07:41 +02:00 committed by GitHub
commit 093c1c1a69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 // if it's a path then it's most likely a deleted file not help
} else if (path.find("::") != -1) { } else if (path.find("::") != -1) {
// built-in script // built-in script
String scene_path = path.get_slice("::", 0); String res_path = path.get_slice("::", 0);
if (!EditorNode::get_singleton()->is_scene_open(scene_path)) { if (ResourceLoader::get_resource_type(res_path) == "PackedScene") {
EditorNode::get_singleton()->load_scene(scene_path); 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); Ref<Script> script = ResourceLoader::load(path);
if (script.is_valid()) { if (script.is_valid()) {
@ -1028,12 +1032,16 @@ void ScriptEditor::_menu_option(int p_option) {
if (extensions.find(path.get_extension()) || built_in) { if (extensions.find(path.get_extension()) || built_in) {
if (built_in) { if (built_in) {
String scene_path = path.get_slice("::", 0); String res_path = path.get_slice("::", 0);
if (!EditorNode::get_singleton()->is_scene_open(scene_path)) { if (ResourceLoader::get_resource_type(res_path) == "PackedScene") {
EditorNode::get_singleton()->load_scene(scene_path); if (!EditorNode::get_singleton()->is_scene_open(res_path)) {
script_editor->call_deferred("_menu_option", p_option); EditorNode::get_singleton()->load_scene(res_path);
previous_scripts.push_back(path); //repeat the operation script_editor->call_deferred("_menu_option", p_option);
return; 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)) { if (Object::cast_to<Script>(p_object)) {
Script *p_script = 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); String res_path = p_script->get_path().get_slice("::", 0);
if (_is_built_in_script(p_script) && !EditorNode::get_singleton()->is_scene_open(scene_path)) { if (_is_built_in_script(p_script)) {
EditorNode::get_singleton()->load_scene(scene_path); if (ResourceLoader::get_resource_type(res_path) == "PackedScene") {
if (!EditorNode::get_singleton()->is_scene_open(res_path)) {
script_editor->call_deferred("edit", p_script); EditorNode::get_singleton()->load_scene(res_path);
} else { }
script_editor->edit(p_script); } else {
EditorNode::get_singleton()->load_resource(res_path);
}
} }
script_editor->edit(p_script);
} else if (Object::cast_to<TextFile>(p_object)) { } else if (Object::cast_to<TextFile>(p_object)) {
script_editor->edit(Object::cast_to<TextFile>(p_object)); script_editor->edit(Object::cast_to<TextFile>(p_object));
} }