1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-12 13:20:55 +00:00

Merge pull request #31401 from aaronfranke/no-init-scripts

Allow plugins to not have an init script
This commit is contained in:
Rémi Verschelde
2019-08-17 22:09:17 +02:00
committed by GitHub

View File

@@ -2921,32 +2921,36 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled,
return; return;
} }
String path = cf->get_value("plugin", "script"); String script_path = cf->get_value("plugin", "script");
path = String("res://addons").plus_file(p_addon).plus_file(path); Ref<Script> script; // We need to save it for creating "ep" below.
Ref<Script> script = ResourceLoader::load(path); // Only try to load the script if it has a name. Else, the plugin has no init script.
if (script_path.length() > 0) {
script_path = String("res://addons").plus_file(p_addon).plus_file(script_path);
script = ResourceLoader::load(script_path);
if (script.is_null()) { if (script.is_null()) {
show_warning(vformat(TTR("Unable to load addon script from path: '%s'."), path)); show_warning(vformat(TTR("Unable to load addon script from path: '%s'."), script_path));
return; return;
} }
//errors in the script cause the base_type to be "" // Errors in the script cause the base_type to be an empty string.
if (String(script->get_instance_base_type()) == "") { if (String(script->get_instance_base_type()) == "") {
show_warning(vformat(TTR("Unable to load addon script from path: '%s' There seems to be an error in the code, please check the syntax."), path)); show_warning(vformat(TTR("Unable to load addon script from path: '%s' There seems to be an error in the code, please check the syntax."), script_path));
return; return;
} }
//could check inheritance.. // Plugin init scripts must inherit from EditorPlugin and be tools.
if (String(script->get_instance_base_type()) != "EditorPlugin") { if (String(script->get_instance_base_type()) != "EditorPlugin") {
show_warning(vformat(TTR("Unable to load addon script from path: '%s' Base type is not EditorPlugin."), path)); show_warning(vformat(TTR("Unable to load addon script from path: '%s' Base type is not EditorPlugin."), script_path));
return; return;
} }
if (!script->is_tool()) { if (!script->is_tool()) {
show_warning(vformat(TTR("Unable to load addon script from path: '%s' Script is not in tool mode."), path)); show_warning(vformat(TTR("Unable to load addon script from path: '%s' Script is not in tool mode."), script_path));
return; return;
} }
}
EditorPlugin *ep = memnew(EditorPlugin); EditorPlugin *ep = memnew(EditorPlugin);
ep->set_script(script.get_ref_ptr()); ep->set_script(script.get_ref_ptr());