diff options
author | Paweł Fertyk <pfertyk@pfertyk.me> | 2022-06-08 19:22:30 +0200 |
---|---|---|
committer | Paweł Fertyk <pfertyk@pfertyk.me> | 2022-06-09 18:42:32 +0200 |
commit | 725eb629b350ab443a9bc3f2e713d75ec56170d6 (patch) | |
tree | 8dce3023f3e5331ef8362dae1f253087a17c6c77 /editor | |
parent | 532e253a7c0544bfb4866fb00129cfa1d39fcd62 (diff) |
Allow plugin name in `is_plugin_enabled`
Fixes #61604.
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_node.cpp | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index c59c7de603..e6ed28367d 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -3306,33 +3306,39 @@ void EditorNode::_update_addon_config() { } void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed) { - ERR_FAIL_COND(p_enabled && addon_name_to_plugin.has(p_addon)); - ERR_FAIL_COND(!p_enabled && !addon_name_to_plugin.has(p_addon)); + String addon_path = p_addon; + + if (!addon_path.begins_with("res://")) { + addon_path = "res://addons/" + addon_path + "/plugin.cfg"; + } + + ERR_FAIL_COND(p_enabled && addon_name_to_plugin.has(addon_path)); + ERR_FAIL_COND(!p_enabled && !addon_name_to_plugin.has(addon_path)); if (!p_enabled) { - EditorPlugin *addon = addon_name_to_plugin[p_addon]; + EditorPlugin *addon = addon_name_to_plugin[addon_path]; remove_editor_plugin(addon, p_config_changed); memdelete(addon); - addon_name_to_plugin.erase(p_addon); + addon_name_to_plugin.erase(addon_path); _update_addon_config(); return; } Ref<ConfigFile> cf; cf.instantiate(); - if (!DirAccess::exists(p_addon.get_base_dir())) { - _remove_plugin_from_enabled(p_addon); - WARN_PRINT("Addon '" + p_addon + "' failed to load. No directory found. Removing from enabled plugins."); + if (!DirAccess::exists(addon_path.get_base_dir())) { + _remove_plugin_from_enabled(addon_path); + WARN_PRINT("Addon '" + addon_path + "' failed to load. No directory found. Removing from enabled plugins."); return; } - Error err = cf->load(p_addon); + Error err = cf->load(addon_path); if (err != OK) { - show_warning(vformat(TTR("Unable to enable addon plugin at: '%s' parsing of config failed."), p_addon)); + show_warning(vformat(TTR("Unable to enable addon plugin at: '%s' parsing of config failed."), addon_path)); return; } if (!cf->has_section_key("plugin", "script")) { - show_warning(vformat(TTR("Unable to find script field for addon plugin at: '%s'."), p_addon)); + show_warning(vformat(TTR("Unable to find script field for addon plugin at: '%s'."), addon_path)); return; } @@ -3341,7 +3347,7 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, // 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 = p_addon.get_base_dir().plus_file(script_path); + script_path = addon_path.get_base_dir().plus_file(script_path); script = ResourceLoader::load(script_path); if (script.is_null()) { @@ -3351,8 +3357,8 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, // Errors in the script cause the base_type to be an empty StringName. if (script->get_instance_base_type() == StringName()) { - show_warning(vformat(TTR("Unable to load addon script from path: '%s'. This might be due to a code error in that script.\nDisabling the addon at '%s' to prevent further errors."), script_path, p_addon)); - _remove_plugin_from_enabled(p_addon); + show_warning(vformat(TTR("Unable to load addon script from path: '%s'. This might be due to a code error in that script.\nDisabling the addon at '%s' to prevent further errors."), script_path, addon_path)); + _remove_plugin_from_enabled(addon_path); return; } @@ -3370,14 +3376,18 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, EditorPlugin *ep = memnew(EditorPlugin); ep->set_script(script); - addon_name_to_plugin[p_addon] = ep; + addon_name_to_plugin[addon_path] = ep; add_editor_plugin(ep, p_config_changed); _update_addon_config(); } bool EditorNode::is_addon_plugin_enabled(const String &p_addon) const { - return addon_name_to_plugin.has(p_addon); + if (p_addon.begins_with("res://")) { + return addon_name_to_plugin.has(p_addon); + } + + return addon_name_to_plugin.has("res://addons/" + p_addon + "/plugin.cfg"); } void EditorNode::_remove_edited_scene(bool p_change_tab) { |