From e75ebffb70f53426e4d8cafad7a2ff608602fda7 Mon Sep 17 00:00:00 2001 From: David Snopek Date: Tue, 16 May 2023 20:59:54 -0500 Subject: [PATCH] Add support for adding/removing editor plugins --- binding_generator.py | 18 ++++++++++++++++++ gdextension/gdextension_interface.h | 20 ++++++++++++++++++++ include/godot_cpp/godot.hpp | 2 ++ src/godot.cpp | 4 ++++ 4 files changed, 44 insertions(+) diff --git a/binding_generator.py b/binding_generator.py index 30def353..315cc8ff 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -1376,6 +1376,24 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us result.append("};") result.append("") + if class_name == "EditorPlugin": + result.append("class EditorPlugins {") + result.append("public:") + result.append("") + + result.append("\ttemplate ") + result.append("\tstatic void add_by_type() {") + result.append("\t\tinternal::gdextension_interface_editor_add_plugin(T::get_class_static()._native_ptr());") + result.append("\t}") + + result.append("\ttemplate ") + result.append("\tstatic void remove_by_type() {") + result.append("\t\tinternal::gdextension_interface_editor_remove_plugin(T::get_class_static()._native_ptr());") + result.append("\t}") + + result.append("};") + result.append("") + result.append("} // namespace godot") result.append("") diff --git a/gdextension/gdextension_interface.h b/gdextension/gdextension_interface.h index 44cea710..23717eb7 100644 --- a/gdextension/gdextension_interface.h +++ b/gdextension/gdextension_interface.h @@ -2106,6 +2106,26 @@ typedef void (*GDExtensionInterfaceClassdbUnregisterExtensionClass)(GDExtensionC */ typedef void (*GDExtensionInterfaceGetLibraryPath)(GDExtensionClassLibraryPtr p_library, GDExtensionStringPtr r_path); +/** + * @name editor_add_plugin + * + * Adds an editor plugin. + * + * It's safe to call during initialization. + * + * @param p_class_name A pointer to a StringName with the name of a class (descending from EditorPlugin) which is already registered with ClassDB. + */ +typedef void (*GDExtensionInterfaceEditorAddPlugin)(GDExtensionConstStringNamePtr p_class_name); + +/** + * @name editor_remove_plugin + * + * Removes an editor plugin. + * + * @param p_class_name A pointer to a StringName with the name of a class that was previously added as an editor plugin. + */ +typedef void (*GDExtensionInterfaceEditorRemovePlugin)(GDExtensionConstStringNamePtr p_class_name); + #ifdef __cplusplus } #endif diff --git a/include/godot_cpp/godot.hpp b/include/godot_cpp/godot.hpp index 20e94008..4f9a75bf 100644 --- a/include/godot_cpp/godot.hpp +++ b/include/godot_cpp/godot.hpp @@ -177,6 +177,8 @@ extern "C" GDExtensionInterfaceClassdbRegisterExtensionClassPropertySubgroup gde extern "C" GDExtensionInterfaceClassdbRegisterExtensionClassSignal gdextension_interface_classdb_register_extension_class_signal; extern "C" GDExtensionInterfaceClassdbUnregisterExtensionClass gdextension_interface_classdb_unregister_extension_class; extern "C" GDExtensionInterfaceGetLibraryPath gdextension_interface_get_library_path; +extern "C" GDExtensionInterfaceEditorAddPlugin gdextension_interface_editor_add_plugin; +extern "C" GDExtensionInterfaceEditorRemovePlugin gdextension_interface_editor_remove_plugin; } // namespace internal diff --git a/src/godot.cpp b/src/godot.cpp index 25828a79..b95f1b81 100644 --- a/src/godot.cpp +++ b/src/godot.cpp @@ -181,6 +181,8 @@ GDExtensionInterfaceClassdbRegisterExtensionClassPropertySubgroup gdextension_in GDExtensionInterfaceClassdbRegisterExtensionClassSignal gdextension_interface_classdb_register_extension_class_signal = nullptr; GDExtensionInterfaceClassdbUnregisterExtensionClass gdextension_interface_classdb_unregister_extension_class = nullptr; GDExtensionInterfaceGetLibraryPath gdextension_interface_get_library_path = nullptr; +GDExtensionInterfaceEditorAddPlugin gdextension_interface_editor_add_plugin = nullptr; +GDExtensionInterfaceEditorRemovePlugin gdextension_interface_editor_remove_plugin = nullptr; } // namespace internal @@ -360,6 +362,8 @@ GDExtensionBool GDExtensionBinding::init(GDExtensionInterfaceGetProcAddress p_ge LOAD_PROC_ADDRESS(classdb_register_extension_class_signal, GDExtensionInterfaceClassdbRegisterExtensionClassSignal); LOAD_PROC_ADDRESS(classdb_unregister_extension_class, GDExtensionInterfaceClassdbUnregisterExtensionClass); LOAD_PROC_ADDRESS(get_library_path, GDExtensionInterfaceGetLibraryPath); + LOAD_PROC_ADDRESS(editor_add_plugin, GDExtensionInterfaceEditorAddPlugin); + LOAD_PROC_ADDRESS(editor_remove_plugin, GDExtensionInterfaceEditorRemovePlugin); // Load the Godot version. internal::gdextension_interface_get_godot_version(&internal::godot_version);