Expose an ImportOrder enum in ResourceImporter

This avoids using magic numbers in code.

(cherry picked from commit 7f83977f37)
This commit is contained in:
Hugo Locurcio 2021-07-23 12:10:32 +02:00 committed by Rémi Verschelde
parent 8ecb5d2047
commit af3f83407f
No known key found for this signature in database
GPG key ID: C3336907360768E1
5 changed files with 28 additions and 3 deletions

View file

@ -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);
}

View file

@ -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

View file

@ -64,7 +64,7 @@
<return type="int">
</return>
<description>
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.
</description>
</method>
<method name="get_importer_name" qualifiers="virtual">

View file

@ -1,13 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="ResourceImporter" inherits="Reference" version="3.4">
<brief_description>
Base class for the implementation of core resource importers.
</brief_description>
<description>
This is the base class for the resource importers implemented in core. To implement your own resource importers using editor plugins, see [EditorImportPlugin].
</description>
<tutorials>
<link title="Import plugins">https://docs.godotengine.org/en/stable/tutorials/plugins/editor/import_plugins.html</link>
</tutorials>
<methods>
</methods>
<constants>
<constant name="IMPORT_ORDER_DEFAULT" value="0" enum="ImportOrder">
The default import order.
</constant>
<constant name="IMPORT_ORDER_SCENE" value="100" enum="ImportOrder">
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.
</constant>
</constants>
</class>

View file

@ -140,7 +140,8 @@ public:
virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const;
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &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<Ref<ArrayMesh>, Transform> &meshes);