From af3f83407f0e26c72476e8cac6b82ed6a7f772b9 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Fri, 23 Jul 2021 12:10:32 +0200 Subject: [PATCH] Expose an ImportOrder enum in ResourceImporter This avoids using magic numbers in code. (cherry picked from commit 7f83977f37f5f13024bee4f29ead87a992a072b6) --- core/io/resource_importer.cpp | 5 +++++ core/io/resource_importer.h | 12 +++++++++++- doc/classes/EditorImportPlugin.xml | 2 +- doc/classes/ResourceImporter.xml | 9 +++++++++ editor/import/resource_importer_scene.h | 3 ++- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index ccd7e286186..2511c89678f 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -420,3 +420,8 @@ ResourceFormatImporter *ResourceFormatImporter::singleton = nullptr; ResourceFormatImporter::ResourceFormatImporter() { singleton = this; } + +void ResourceImporter::_bind_methods() { + BIND_ENUM_CONSTANT(IMPORT_ORDER_DEFAULT); + BIND_ENUM_CONSTANT(IMPORT_ORDER_SCENE); +} diff --git a/core/io/resource_importer.h b/core/io/resource_importer.h index 6d03529d477..13b00dfa534 100644 --- a/core/io/resource_importer.h +++ b/core/io/resource_importer.h @@ -95,6 +95,9 @@ public: class ResourceImporter : public Reference { GDCLASS(ResourceImporter, Reference); +protected: + static void _bind_methods(); + public: virtual String get_importer_name() const = 0; virtual String get_visible_name() const = 0; @@ -102,7 +105,7 @@ public: virtual String get_save_extension() const = 0; virtual String get_resource_type() const = 0; virtual float get_priority() const { return 1.0; } - virtual int get_import_order() const { return 0; } + virtual int get_import_order() const { return IMPORT_ORDER_DEFAULT; } struct ImportOption { PropertyInfo option; @@ -115,6 +118,11 @@ public: ImportOption() {} }; + enum ImportOrder { + IMPORT_ORDER_DEFAULT = 0, + IMPORT_ORDER_SCENE = 100, + }; + virtual int get_preset_count() const { return 0; } virtual String get_preset_name(int p_idx) const { return String(); } @@ -129,4 +137,6 @@ public: virtual String get_import_settings_string() const { return String(); } }; +VARIANT_ENUM_CAST(ResourceImporter::ImportOrder); + #endif // RESOURCE_IMPORTER_H diff --git a/doc/classes/EditorImportPlugin.xml b/doc/classes/EditorImportPlugin.xml index 1acd0c41c75..c639397b65f 100644 --- a/doc/classes/EditorImportPlugin.xml +++ b/doc/classes/EditorImportPlugin.xml @@ -64,7 +64,7 @@ - Gets the order of this importer to be run when importing resources. Higher values will be called later. Use this to ensure the importer runs after the dependencies are already imported. + 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. diff --git a/doc/classes/ResourceImporter.xml b/doc/classes/ResourceImporter.xml index e2fccd90af0..40b883312a8 100644 --- a/doc/classes/ResourceImporter.xml +++ b/doc/classes/ResourceImporter.xml @@ -1,13 +1,22 @@ + Base class for the implementation of core resource importers. + This is the base class for the resource importers implemented in core. To implement your own resource importers using editor plugins, see [EditorImportPlugin]. + https://docs.godotengine.org/en/stable/tutorials/plugins/editor/import_plugins.html + + The default import order. + + + The import order for scenes, which ensures scenes are imported [i]after[/i] all other core resources such as textures. Custom importers should generally have an import order lower than [code]100[/code] to avoid issues when importing scenes that rely on custom resources. + diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h index fbc43546eac..a03fdefc58c 100644 --- a/editor/import/resource_importer_scene.h +++ b/editor/import/resource_importer_scene.h @@ -140,7 +140,8 @@ public: virtual void get_import_options(List *r_options, int p_preset = 0) const; virtual bool get_option_visibility(const String &p_option, const Map &p_options) const; - virtual int get_import_order() const { return 100; } //after everything + // Import scenes *after* everything else (such as textures). + virtual int get_import_order() const { return ResourceImporter::IMPORT_ORDER_SCENE; } void _find_meshes(Node *p_node, Map, Transform> &meshes);