From d54ac732ae6643a817ea84d8adc7dd01490220e7 Mon Sep 17 00:00:00 2001 From: George Marques Date: Tue, 13 Feb 2018 11:59:56 -0200 Subject: [PATCH] Expose priority and order for custom import plugins (cherry picked from commit c68948fdfaf154acc00b9b92f44875d8518957c4) --- doc/classes/EditorImportPlugin.xml | 14 ++++++++++++++ editor/import/editor_import_plugin.cpp | 16 ++++++++++++++++ editor/import/editor_import_plugin.h | 2 ++ 3 files changed, 32 insertions(+) diff --git a/doc/classes/EditorImportPlugin.xml b/doc/classes/EditorImportPlugin.xml index 07d6f92274b..85f3d80607b 100644 --- a/doc/classes/EditorImportPlugin.xml +++ b/doc/classes/EditorImportPlugin.xml @@ -64,6 +64,13 @@ Get the options and default values for the preset at this index. Returns an Array of Dictionaries with the following keys: "name", "default_value", "property_hint" (optional), "hint_string" (optional), "usage" (optional). + + + + + Get 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. + + @@ -97,6 +104,13 @@ Get the name of the options preset at this index. + + + + + Get the priority of this plugin for the recognized extension. Higher priority plugins will be preferred. Default value is 1.0. + + diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp index 07c77a9df03..3f5dc7c9f40 100644 --- a/editor/import/editor_import_plugin.cpp +++ b/editor/import/editor_import_plugin.cpp @@ -72,6 +72,20 @@ String EditorImportPlugin::get_resource_type() const { return get_script_instance()->call("get_resource_type"); } +float EditorImportPlugin::get_priority() const { + if (!(get_script_instance() && get_script_instance()->has_method("get_priority"))) { + return EditorImportPlugin::get_priority(); + } + return get_script_instance()->call("get_priority"); +} + +int EditorImportPlugin::get_import_order() const { + if (!(get_script_instance() && get_script_instance()->has_method("get_import_order"))) { + return EditorImportPlugin::get_import_order(); + } + return get_script_instance()->call("get_import_order"); +} + void EditorImportPlugin::get_import_options(List *r_options, int p_preset) const { ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("get_import_options"))); @@ -148,6 +162,8 @@ void EditorImportPlugin::_bind_methods() { ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::ARRAY, "get_import_options", PropertyInfo(Variant::INT, "preset"))); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_save_extension")); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_resource_type")); + ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::REAL, "get_priority")); + ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::INT, "get_import_order")); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "get_option_visibility", PropertyInfo(Variant::STRING, "option"), PropertyInfo(Variant::DICTIONARY, "options"))); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::INT, "import", PropertyInfo(Variant::STRING, "source_file"), PropertyInfo(Variant::STRING, "save_path"), PropertyInfo(Variant::DICTIONARY, "options"), PropertyInfo(Variant::ARRAY, "r_platform_variants"), PropertyInfo(Variant::ARRAY, "r_gen_files"))); } diff --git a/editor/import/editor_import_plugin.h b/editor/import/editor_import_plugin.h index 61a0a944f5a..92d83158ef9 100644 --- a/editor/import/editor_import_plugin.h +++ b/editor/import/editor_import_plugin.h @@ -47,6 +47,8 @@ public: virtual int get_preset_count() const; virtual String get_save_extension() const; virtual String get_resource_type() const; + virtual float get_priority() const; + virtual int get_import_order() const; virtual void get_import_options(List *r_options, int p_preset) const; virtual bool get_option_visibility(const String &p_option, const Map &p_options) const; virtual Error import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files);