Browse Source

Merge pull request #104084 from dsnopek/classdb-correctly-register-editor-classes

Register editor classes normally, rather than via `ClassDB::set_current_api()`
Rémi Verschelde 5 months ago
parent
commit
eabd877873

+ 0 - 5
modules/fbx/register_types.cpp

@@ -61,10 +61,6 @@ void initialize_fbx_module(ModuleInitializationLevel p_level) {
 
 
 #ifdef TOOLS_ENABLED
 #ifdef TOOLS_ENABLED
 	if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
 	if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
-		// Editor-specific API.
-		ClassDB::APIType prev_api = ClassDB::get_current_api();
-		ClassDB::set_current_api(ClassDB::API_EDITOR);
-
 		GDREGISTER_CLASS(EditorSceneFormatImporterUFBX);
 		GDREGISTER_CLASS(EditorSceneFormatImporterUFBX);
 
 
 		GLOBAL_DEF_RST_BASIC("filesystem/import/fbx2gltf/enabled", true);
 		GLOBAL_DEF_RST_BASIC("filesystem/import/fbx2gltf/enabled", true);
@@ -72,7 +68,6 @@ void initialize_fbx_module(ModuleInitializationLevel p_level) {
 		GLOBAL_DEF_RST("filesystem/import/fbx2gltf/enabled.android", false);
 		GLOBAL_DEF_RST("filesystem/import/fbx2gltf/enabled.android", false);
 		GLOBAL_DEF_RST("filesystem/import/fbx2gltf/enabled.web", false);
 		GLOBAL_DEF_RST("filesystem/import/fbx2gltf/enabled.web", false);
 
 
-		ClassDB::set_current_api(prev_api);
 		EditorNode::add_init_callback(_editor_init);
 		EditorNode::add_init_callback(_editor_init);
 	}
 	}
 #endif // TOOLS_ENABLED
 #endif // TOOLS_ENABLED

+ 0 - 5
modules/gdscript/register_types.cpp

@@ -162,12 +162,7 @@ void initialize_gdscript_module(ModuleInitializationLevel p_level) {
 		gdscript_translation_parser_plugin.instantiate();
 		gdscript_translation_parser_plugin.instantiate();
 		EditorTranslationParser::get_singleton()->add_parser(gdscript_translation_parser_plugin, EditorTranslationParser::STANDARD);
 		EditorTranslationParser::get_singleton()->add_parser(gdscript_translation_parser_plugin, EditorTranslationParser::STANDARD);
 	} else if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
 	} else if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
-		ClassDB::APIType prev_api = ClassDB::get_current_api();
-		ClassDB::set_current_api(ClassDB::API_EDITOR);
-
 		GDREGISTER_CLASS(GDScriptSyntaxHighlighter);
 		GDREGISTER_CLASS(GDScriptSyntaxHighlighter);
-
-		ClassDB::set_current_api(prev_api);
 	}
 	}
 #endif // TOOLS_ENABLED
 #endif // TOOLS_ENABLED
 }
 }

+ 0 - 6
modules/gltf/register_types.cpp

@@ -135,10 +135,6 @@ void initialize_gltf_module(ModuleInitializationLevel p_level) {
 
 
 #ifdef TOOLS_ENABLED
 #ifdef TOOLS_ENABLED
 	if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
 	if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
-		// Editor-specific API.
-		ClassDB::APIType prev_api = ClassDB::get_current_api();
-		ClassDB::set_current_api(ClassDB::API_EDITOR);
-
 		GDREGISTER_CLASS(EditorSceneFormatImporterGLTF);
 		GDREGISTER_CLASS(EditorSceneFormatImporterGLTF);
 		EditorPlugins::add_by_type<SceneExporterGLTFPlugin>();
 		EditorPlugins::add_by_type<SceneExporterGLTFPlugin>();
 
 
@@ -149,10 +145,8 @@ void initialize_gltf_module(ModuleInitializationLevel p_level) {
 		GLOBAL_DEF_RST("filesystem/import/blender/enabled.android", false);
 		GLOBAL_DEF_RST("filesystem/import/blender/enabled.android", false);
 		GLOBAL_DEF_RST("filesystem/import/blender/enabled.web", false);
 		GLOBAL_DEF_RST("filesystem/import/blender/enabled.web", false);
 
 
-		ClassDB::set_current_api(prev_api);
 		EditorNode::add_init_callback(_editor_init);
 		EditorNode::add_init_callback(_editor_init);
 	}
 	}
-
 #endif // TOOLS_ENABLED
 #endif // TOOLS_ENABLED
 }
 }
 
 

+ 13 - 22
modules/minimp3/register_types.cpp

@@ -33,39 +33,30 @@
 #include "audio_stream_mp3.h"
 #include "audio_stream_mp3.h"
 
 
 #ifdef TOOLS_ENABLED
 #ifdef TOOLS_ENABLED
+#include "core/config/engine.h"
+#include "editor/editor_node.h"
 #include "resource_importer_mp3.h"
 #include "resource_importer_mp3.h"
-#endif
 
 
-#ifdef TOOLS_ENABLED
-#include "core/config/engine.h"
+static void _editor_init() {
+	Ref<ResourceImporterMP3> mp3_import;
+	mp3_import.instantiate();
+	ResourceFormatImporter::get_singleton()->add_importer(mp3_import);
+}
 #endif
 #endif
 
 
 void initialize_minimp3_module(ModuleInitializationLevel p_level) {
 void initialize_minimp3_module(ModuleInitializationLevel p_level) {
-	if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
-		return;
+	if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) {
+		GDREGISTER_CLASS(AudioStreamMP3);
 	}
 	}
 
 
 #ifdef TOOLS_ENABLED
 #ifdef TOOLS_ENABLED
-	if (Engine::get_singleton()->is_editor_hint()) {
-		Ref<ResourceImporterMP3> mp3_import;
-		mp3_import.instantiate();
-		ResourceFormatImporter::get_singleton()->add_importer(mp3_import);
-	}
+	if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
+		GDREGISTER_CLASS(ResourceImporterMP3);
 
 
-	ClassDB::APIType prev_api = ClassDB::get_current_api();
-	ClassDB::set_current_api(ClassDB::API_EDITOR);
-
-	// Required to document import options in the class reference.
-	GDREGISTER_CLASS(ResourceImporterMP3);
-
-	ClassDB::set_current_api(prev_api);
+		EditorNode::add_init_callback(_editor_init);
+	}
 #endif
 #endif
-
-	GDREGISTER_CLASS(AudioStreamMP3);
 }
 }
 
 
 void uninitialize_minimp3_module(ModuleInitializationLevel p_level) {
 void uninitialize_minimp3_module(ModuleInitializationLevel p_level) {
-	if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
-		return;
-	}
 }
 }

+ 3 - 7
modules/openxr/register_types.cpp

@@ -225,21 +225,17 @@ void initialize_openxr_module(ModuleInitializationLevel p_level) {
 				openxr_interface->initialize();
 				openxr_interface->initialize();
 			}
 			}
 		}
 		}
+	}
 
 
 #ifdef TOOLS_ENABLED
 #ifdef TOOLS_ENABLED
-		// Register as "editor", not "core".
-		ClassDB::APIType prev_api = ClassDB::get_current_api();
-		ClassDB::set_current_api(ClassDB::API_EDITOR);
-
+	if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
 		GDREGISTER_ABSTRACT_CLASS(OpenXRInteractionProfileEditorBase);
 		GDREGISTER_ABSTRACT_CLASS(OpenXRInteractionProfileEditorBase);
 		GDREGISTER_CLASS(OpenXRInteractionProfileEditor);
 		GDREGISTER_CLASS(OpenXRInteractionProfileEditor);
 		GDREGISTER_CLASS(OpenXRBindingModifierEditor);
 		GDREGISTER_CLASS(OpenXRBindingModifierEditor);
 
 
-		ClassDB::set_current_api(prev_api);
-
 		EditorNode::add_init_callback(_editor_init);
 		EditorNode::add_init_callback(_editor_init);
-#endif
 	}
 	}
+#endif
 }
 }
 
 
 void uninitialize_openxr_module(ModuleInitializationLevel p_level) {
 void uninitialize_openxr_module(ModuleInitializationLevel p_level) {

+ 14 - 20
modules/vorbis/register_types.cpp

@@ -33,36 +33,30 @@
 #include "audio_stream_ogg_vorbis.h"
 #include "audio_stream_ogg_vorbis.h"
 
 
 #ifdef TOOLS_ENABLED
 #ifdef TOOLS_ENABLED
+#include "editor/editor_node.h"
 #include "resource_importer_ogg_vorbis.h"
 #include "resource_importer_ogg_vorbis.h"
+
+static void _editor_init() {
+	Ref<ResourceImporterOggVorbis> ogg_vorbis_importer;
+	ogg_vorbis_importer.instantiate();
+	ResourceFormatImporter::get_singleton()->add_importer(ogg_vorbis_importer);
+}
 #endif
 #endif
 
 
 void initialize_vorbis_module(ModuleInitializationLevel p_level) {
 void initialize_vorbis_module(ModuleInitializationLevel p_level) {
-	if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
-		return;
+	if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) {
+		GDREGISTER_CLASS(AudioStreamOggVorbis);
+		GDREGISTER_CLASS(AudioStreamPlaybackOggVorbis);
 	}
 	}
 
 
 #ifdef TOOLS_ENABLED
 #ifdef TOOLS_ENABLED
-	if (Engine::get_singleton()->is_editor_hint()) {
-		Ref<ResourceImporterOggVorbis> ogg_vorbis_importer;
-		ogg_vorbis_importer.instantiate();
-		ResourceFormatImporter::get_singleton()->add_importer(ogg_vorbis_importer);
-	}
-
-	ClassDB::APIType prev_api = ClassDB::get_current_api();
-	ClassDB::set_current_api(ClassDB::API_EDITOR);
+	if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
+		GDREGISTER_CLASS(ResourceImporterOggVorbis);
 
 
-	// Required to document import options in the class reference.
-	GDREGISTER_CLASS(ResourceImporterOggVorbis);
-
-	ClassDB::set_current_api(prev_api);
+		EditorNode::add_init_callback(_editor_init);
+	}
 #endif
 #endif
-
-	GDREGISTER_CLASS(AudioStreamOggVorbis);
-	GDREGISTER_CLASS(AudioStreamPlaybackOggVorbis);
 }
 }
 
 
 void uninitialize_vorbis_module(ModuleInitializationLevel p_level) {
 void uninitialize_vorbis_module(ModuleInitializationLevel p_level) {
-	if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
-		return;
-	}
 }
 }