From 71723f74b70cbfaf9e02e8d18011de0e8884f335 Mon Sep 17 00:00:00 2001
From: Jojo-1000 <33495614+Jojo-1000@users.noreply.github.com>
Date: Fri, 28 Mar 2025 22:35:45 +0100
Subject: [PATCH] Mark necessary EditorImportPlugin functions as required
---
doc/classes/EditorImportPlugin.xml | 20 ++---
editor/import/editor_import_plugin.cpp | 104 ++++++++++---------------
editor/import/editor_import_plugin.h | 16 ++--
3 files changed, 61 insertions(+), 79 deletions(-)
diff --git a/doc/classes/EditorImportPlugin.xml b/doc/classes/EditorImportPlugin.xml
index a16207cf290..07b7363245f 100644
--- a/doc/classes/EditorImportPlugin.xml
+++ b/doc/classes/EditorImportPlugin.xml
@@ -124,17 +124,18 @@
Tells whether this importer can be run in parallel on threads, or, on the contrary, it's only safe for the editor to call it from the main thread, for one file at a time.
- If this method is not overridden, it will return [code]false[/code] by default.
If this importer's implementation is thread-safe and can be run in parallel, override this with [code]true[/code] to optimize for concurrency.
+ If not overridden, returns [code]false[/code].
Gets the format version of this importer. Increment this version when making incompatible changes to the format of the imported resources.
+ If not overridden, the format version is [code]0[/code].
-
+
@@ -148,7 +149,7 @@
Gets the order of this importer to be run when importing resources. Importers with [i]lower[/i] import orders will be called first, and higher values will be called later. Use this to ensure the importer runs after the dependencies are already imported. The default import order is [code]0[/code] unless overridden by a specific importer. See [enum ResourceImporter.ImportOrder] for some predefined values.
-
+
Gets the unique name of the importer.
@@ -189,9 +190,10 @@
Gets the number of initial presets defined by the plugin. Use [method _get_import_options] to get the default options for the preset and [method _get_preset_name] to get the name of the preset.
+ By default, there are no presets.
-
+
@@ -204,31 +206,31 @@
Gets the priority of this plugin for the recognized extension. Higher priority plugins will be preferred. The default priority is [code]1.0[/code].
-
+
Gets the list of file extensions to associate with this loader (case-insensitive). e.g. [code]["obj"][/code].
-
+
Gets the Godot resource type associated with this loader. e.g. [code]"Mesh"[/code] or [code]"Animation"[/code].
-
+
Gets the extension used to save this resource in the [code].godot/imported[/code] directory (see [member ProjectSettings.application/config/use_hidden_project_data_directory]).
-
+
Gets the name to display in the import window. You should choose this name as a continuation to "Import as", e.g. "Import as Special Mesh".
-
+
diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp
index 56fcb4902be..eac364d270c 100644
--- a/editor/import/editor_import_plugin.cpp
+++ b/editor/import/editor_import_plugin.cpp
@@ -35,38 +35,28 @@
String EditorImportPlugin::get_importer_name() const {
String ret;
- if (GDVIRTUAL_CALL(_get_importer_name, ret)) {
- return ret;
- }
- ERR_FAIL_V_MSG(String(), "Unimplemented _get_importer_name in add-on.");
+ GDVIRTUAL_CALL(_get_importer_name, ret);
+ return ret;
}
String EditorImportPlugin::get_visible_name() const {
String ret;
- if (GDVIRTUAL_CALL(_get_visible_name, ret)) {
- return ret;
- }
- ERR_FAIL_V_MSG(String(), "Unimplemented _get_visible_name in add-on.");
+ GDVIRTUAL_CALL(_get_visible_name, ret);
+ return ret;
}
void EditorImportPlugin::get_recognized_extensions(List *p_extensions) const {
Vector extensions;
-
- if (GDVIRTUAL_CALL(_get_recognized_extensions, extensions)) {
- for (int i = 0; i < extensions.size(); i++) {
- p_extensions->push_back(extensions[i]);
- }
- return;
+ GDVIRTUAL_CALL(_get_recognized_extensions, extensions);
+ for (int i = 0; i < extensions.size(); i++) {
+ p_extensions->push_back(extensions[i]);
}
- ERR_FAIL_MSG("Unimplemented _get_recognized_extensions in add-on.");
}
String EditorImportPlugin::get_preset_name(int p_idx) const {
String ret;
- if (GDVIRTUAL_CALL(_get_preset_name, p_idx, ret)) {
- return ret;
- }
- ERR_FAIL_V_MSG(itos(p_idx), "Unimplemented _get_preset_name in add-on.");
+ GDVIRTUAL_CALL(_get_preset_name, p_idx, ret);
+ return ret;
}
int EditorImportPlugin::get_preset_count() const {
@@ -79,18 +69,14 @@ int EditorImportPlugin::get_preset_count() const {
String EditorImportPlugin::get_save_extension() const {
String ret;
- if (GDVIRTUAL_CALL(_get_save_extension, ret)) {
- return ret;
- }
- ERR_FAIL_V_MSG(String(), "Unimplemented _get_save_extension in add-on.");
+ GDVIRTUAL_CALL(_get_save_extension, ret);
+ return ret;
}
String EditorImportPlugin::get_resource_type() const {
String ret;
- if (GDVIRTUAL_CALL(_get_resource_type, ret)) {
- return ret;
- }
- ERR_FAIL_V_MSG(String(), "Unimplemented _get_resource_type in add-on.");
+ GDVIRTUAL_CALL(_get_resource_type, ret);
+ return ret;
}
float EditorImportPlugin::get_priority() const {
@@ -120,35 +106,31 @@ int EditorImportPlugin::get_format_version() const {
void EditorImportPlugin::get_import_options(const String &p_path, List *r_options, int p_preset) const {
Array needed = { "name", "default_value" };
TypedArray options;
- if (GDVIRTUAL_CALL(_get_import_options, p_path, p_preset, options)) {
- for (int i = 0; i < options.size(); i++) {
- Dictionary d = options[i];
- ERR_FAIL_COND(!d.has_all(needed));
- String name = d["name"];
- Variant default_value = d["default_value"];
+ GDVIRTUAL_CALL(_get_import_options, p_path, p_preset, options);
+ for (int i = 0; i < options.size(); i++) {
+ Dictionary d = options[i];
+ ERR_FAIL_COND(!d.has_all(needed));
+ String name = d["name"];
+ Variant default_value = d["default_value"];
- PropertyHint hint = PROPERTY_HINT_NONE;
- if (d.has("property_hint")) {
- hint = (PropertyHint)d["property_hint"].operator int64_t();
- }
-
- String hint_string;
- if (d.has("hint_string")) {
- hint_string = d["hint_string"];
- }
-
- uint32_t usage = PROPERTY_USAGE_DEFAULT;
- if (d.has("usage")) {
- usage = d["usage"];
- }
-
- ImportOption option(PropertyInfo(default_value.get_type(), name, hint, hint_string, usage), default_value);
- r_options->push_back(option);
+ PropertyHint hint = PROPERTY_HINT_NONE;
+ if (d.has("property_hint")) {
+ hint = (PropertyHint)d["property_hint"].operator int64_t();
}
- return;
- }
- ERR_FAIL_MSG("Unimplemented _get_import_options in add-on.");
+ String hint_string;
+ if (d.has("hint_string")) {
+ hint_string = d["hint_string"];
+ }
+
+ uint32_t usage = PROPERTY_USAGE_DEFAULT;
+ if (d.has("usage")) {
+ usage = d["usage"];
+ }
+
+ ImportOption option(PropertyInfo(default_value.get_type(), name, hint, hint_string, usage), default_value);
+ r_options->push_back(option);
+ }
}
bool EditorImportPlugin::get_option_visibility(const String &p_path, const String &p_option, const HashMap &p_options) const {
@@ -176,16 +158,14 @@ Error EditorImportPlugin::import(ResourceUID::ID p_source_id, const String &p_so
}
Error err = OK;
- if (GDVIRTUAL_CALL(_import, p_source_file, p_save_path, options, platform_variants, gen_files, err)) {
- for (int i = 0; i < platform_variants.size(); i++) {
- r_platform_variants->push_back(platform_variants[i]);
- }
- for (int i = 0; i < gen_files.size(); i++) {
- r_gen_files->push_back(gen_files[i]);
- }
- return err;
+ GDVIRTUAL_CALL(_import, p_source_file, p_save_path, options, platform_variants, gen_files, err);
+ for (int i = 0; i < platform_variants.size(); i++) {
+ r_platform_variants->push_back(platform_variants[i]);
}
- ERR_FAIL_V_MSG(ERR_METHOD_NOT_FOUND, "Unimplemented _import in add-on.");
+ for (int i = 0; i < gen_files.size(); i++) {
+ r_gen_files->push_back(gen_files[i]);
+ }
+ return err;
}
bool EditorImportPlugin::can_import_threaded() const {
diff --git a/editor/import/editor_import_plugin.h b/editor/import/editor_import_plugin.h
index 46f18942019..c4a060ae135 100644
--- a/editor/import/editor_import_plugin.h
+++ b/editor/import/editor_import_plugin.h
@@ -39,19 +39,19 @@ class EditorImportPlugin : public ResourceImporter {
protected:
static void _bind_methods();
- GDVIRTUAL0RC(String, _get_importer_name)
- GDVIRTUAL0RC(String, _get_visible_name)
+ GDVIRTUAL0RC_REQUIRED(String, _get_importer_name)
+ GDVIRTUAL0RC_REQUIRED(String, _get_visible_name)
GDVIRTUAL0RC(int, _get_preset_count)
- GDVIRTUAL1RC(String, _get_preset_name, int)
- GDVIRTUAL0RC(Vector, _get_recognized_extensions)
- GDVIRTUAL2RC(TypedArray, _get_import_options, String, int)
- GDVIRTUAL0RC(String, _get_save_extension)
- GDVIRTUAL0RC(String, _get_resource_type)
+ GDVIRTUAL1RC_REQUIRED(String, _get_preset_name, int)
+ GDVIRTUAL0RC_REQUIRED(Vector, _get_recognized_extensions)
+ GDVIRTUAL2RC_REQUIRED(TypedArray, _get_import_options, String, int)
+ GDVIRTUAL0RC_REQUIRED(String, _get_save_extension)
+ GDVIRTUAL0RC_REQUIRED(String, _get_resource_type)
GDVIRTUAL0RC(float, _get_priority)
GDVIRTUAL0RC(int, _get_import_order)
GDVIRTUAL0RC(int, _get_format_version)
GDVIRTUAL3RC(bool, _get_option_visibility, String, StringName, Dictionary)
- GDVIRTUAL5RC(Error, _import, String, String, Dictionary, TypedArray, TypedArray)
+ GDVIRTUAL5RC_REQUIRED(Error, _import, String, String, Dictionary, TypedArray, TypedArray)
GDVIRTUAL0RC(bool, _can_import_threaded)
Error _append_import_external_resource(const String &p_file, const Dictionary &p_custom_options = Dictionary(), const String &p_custom_importer = String(), Variant p_generator_parameters = Variant());