| 5973 | } |
| 5974 | |
| 5975 | void EditorNode::run_editor_script(const Ref<Script> &p_script) { |
| 5976 | Error err = p_script->reload(true); // Always hard reload the script before running. |
| 5977 | if (err != OK || !p_script->is_valid()) { |
| 5978 | EditorToaster::get_singleton()->popup_str(TTR("Cannot run the script because it contains errors, check the output log."), EditorToaster::SEVERITY_WARNING); |
| 5979 | return; |
| 5980 | } |
| 5981 | |
| 5982 | // Perform additional checks on the script to evaluate if it's runnable. |
| 5983 | |
| 5984 | bool is_runnable = true; |
| 5985 | if (!ClassDB::is_parent_class(p_script->get_instance_base_type(), "EditorScript")) { |
| 5986 | is_runnable = false; |
| 5987 | |
| 5988 | EditorToaster::get_singleton()->popup_str(TTR("Cannot run the script because it doesn't extend EditorScript."), EditorToaster::SEVERITY_WARNING); |
| 5989 | } |
| 5990 | if (!p_script->is_tool()) { |
| 5991 | is_runnable = false; |
| 5992 | |
| 5993 | if (p_script->get_class() == "GDScript") { |
| 5994 | EditorToaster::get_singleton()->popup_str(TTR("Cannot run the script because it's not a tool script (add the @tool annotation at the top)."), EditorToaster::SEVERITY_WARNING); |
| 5995 | } else if (p_script->get_class() == "CSharpScript") { |
| 5996 | EditorToaster::get_singleton()->popup_str(TTR("Cannot run the script because it's not a tool script (add the [Tool] attribute above the class definition)."), EditorToaster::SEVERITY_WARNING); |
| 5997 | } else { |
| 5998 | EditorToaster::get_singleton()->popup_str(TTR("Cannot run the script because it's not a tool script."), EditorToaster::SEVERITY_WARNING); |
| 5999 | } |
| 6000 | } |
| 6001 | if (!is_runnable) { |
| 6002 | return; |
| 6003 | } |
| 6004 | |
| 6005 | Ref<EditorScript> es = memnew(EditorScript); |
| 6006 | es->set_script(p_script); |
| 6007 | es->run(); |
| 6008 | } |
| 6009 | |
| 6010 | void EditorNode::_immediate_dialog_confirmed() { |
| 6011 | immediate_dialog_confirmed = true; |
no test coverage detected