MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / set_addon_plugin_enabled

Method set_addon_plugin_enabled

editor/editor_node.cpp:4007–4096  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4005}
4006
4007void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed) {
4008 String addon_path = p_addon;
4009
4010 if (!addon_path.begins_with("res://")) {
4011 addon_path = "res://addons/" + addon_path + "/plugin.cfg";
4012 }
4013
4014 ERR_FAIL_COND(p_enabled && addon_name_to_plugin.has(addon_path));
4015 ERR_FAIL_COND(!p_enabled && !addon_name_to_plugin.has(addon_path));
4016
4017 if (!p_enabled) {
4018 EditorPlugin *addon = addon_name_to_plugin[addon_path];
4019 remove_editor_plugin(addon, p_config_changed);
4020 memdelete(addon);
4021 addon_name_to_plugin.erase(addon_path);
4022 _update_addon_config();
4023 return;
4024 }
4025
4026 Ref<ConfigFile> cf;
4027 cf.instantiate();
4028 if (!DirAccess::exists(addon_path.get_base_dir())) {
4029 _remove_plugin_from_enabled(addon_path);
4030 WARN_PRINT("Addon '" + addon_path + "' failed to load. No directory found. Removing from enabled plugins.");
4031 return;
4032 }
4033 Error err = cf->load(addon_path);
4034 if (err != OK) {
4035 show_warning(vformat(TTR("Unable to enable addon plugin at: '%s' parsing of config failed."), addon_path));
4036 return;
4037 }
4038
4039 String plugin_version;
4040 if (cf->has_section_key("plugin", "version")) {
4041 plugin_version = cf->get_value("plugin", "version");
4042 }
4043
4044 if (!cf->has_section_key("plugin", "script")) {
4045 show_warning(vformat(TTR("Unable to find script field for addon plugin at: '%s'."), addon_path));
4046 return;
4047 }
4048
4049 String script_path = cf->get_value("plugin", "script");
4050 Ref<Script> scr; // We need to save it for creating "ep" below.
4051
4052 // Only try to load the script if it has a name. Else, the plugin has no init script.
4053 if (script_path.length() > 0) {
4054 script_path = addon_path.get_base_dir().path_join(script_path);
4055 // We should not use the cached version on startup to prevent a script reload
4056 // if it is already loaded and potentially running from autoloads. See GH-100750.
4057 scr = ResourceLoader::load(script_path, "Script", EditorFileSystem::get_singleton()->doing_first_scan() ? ResourceFormatLoader::CACHE_MODE_REUSE : ResourceFormatLoader::CACHE_MODE_IGNORE);
4058
4059 if (scr.is_null()) {
4060 show_warning(vformat(TTR("Unable to load addon script from path: '%s'."), script_path));
4061 return;
4062 }
4063
4064 // Errors in the script cause the base_type to be an empty StringName.

Callers 2

set_plugin_enabledMethod · 0.80

Calls 15

memdeleteFunction · 0.85
vformatFunction · 0.85
TTRFunction · 0.85
begins_withMethod · 0.80
get_base_dirMethod · 0.80
has_section_keyMethod · 0.80
path_joinMethod · 0.80
doing_first_scanMethod · 0.80
set_plugin_versionMethod · 0.80
StringNameClass · 0.50
hasMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected