From f669ebeeaf75a00b4c66dc92f62bd5030cb11660 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 26 Feb 2019 18:43:37 -0300 Subject: -Properly handle missing ETC support on export -Added ability for resource importers to save metadata -Added ability for resource importers to validate depending on project settings --- core/io/resource_importer.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++ core/io/resource_importer.h | 17 ++++++++++++++-- 2 files changed, 62 insertions(+), 2 deletions(-) (limited to 'core/io') diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index 9327e000f5..ef834921b6 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -32,6 +32,9 @@ #include "core/os/os.h" #include "core/variant_parser.h" +bool ResourceFormatImporter::SortImporterByName::operator() ( const Ref& p_a,const Ref& p_b) const { + return p_a->get_importer_name() < p_b->get_importer_name(); +} Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndType &r_path_and_type, bool *r_valid) const { @@ -90,6 +93,8 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy r_path_and_type.type = value; } else if (assign == "importer") { r_path_and_type.importer = value; + } else if (assign == "metadata") { + r_path_and_type.metadata = value; } else if (assign == "valid") { if (r_valid) { *r_valid = value; @@ -304,6 +309,19 @@ String ResourceFormatImporter::get_resource_type(const String &p_path) const { return pat.type; } +Variant ResourceFormatImporter::get_resource_metadata(const String &p_path) const { + PathAndType pat; + Error err = _get_path_and_type(p_path, pat); + + if (err != OK) { + + return Variant(); + } + + return pat.metadata; +} + + void ResourceFormatImporter::get_dependencies(const String &p_path, List *p_dependencies, bool p_add_types) { PathAndType pat; @@ -366,6 +384,35 @@ String ResourceFormatImporter::get_import_base_path(const String &p_for_file) co return "res://.import/" + p_for_file.get_file() + "-" + p_for_file.md5_text(); } +bool ResourceFormatImporter::are_import_settings_valid(const String &p_path) const { + + bool valid = true; + PathAndType pat; + _get_path_and_type(p_path, pat, &valid); + + if (!valid) { + return false; + } + + for(int i=0;iget_importer_name() == pat.importer) { + if (!importers[i]->are_import_settings_valid(p_path)) { //importer thinks this is not valid + return false; + } + } + } + + return true; +} + + String ResourceFormatImporter::get_import_settings_hash() const { + String hash; + for(int i=0;iget_importer_name()+":"+importers[i]->get_import_settings_string(); + } + return hash.md5_text(); +} + ResourceFormatImporter *ResourceFormatImporter::singleton = NULL; ResourceFormatImporter::ResourceFormatImporter() { diff --git a/core/io/resource_importer.h b/core/io/resource_importer.h index 32c39a8085..0ae6bf9090 100644 --- a/core/io/resource_importer.h +++ b/core/io/resource_importer.h @@ -43,12 +43,18 @@ class ResourceFormatImporter : public ResourceFormatLoader { String path; String type; String importer; + Variant metadata; }; Error _get_path_and_type(const String &p_path, PathAndType &r_path_and_type, bool *r_valid = NULL) const; static ResourceFormatImporter *singleton; + //need them to stay in order to compute the settings hash + struct SortImporterByName { + bool operator() ( const Ref& p_a,const Ref& p_b) const; + }; + Vector > importers; public: @@ -59,6 +65,7 @@ public: virtual bool recognize_path(const String &p_path, const String &p_for_type = String()) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; + virtual Variant get_resource_metadata(const String &p_path) const; virtual bool is_import_valid(const String &p_path) const; virtual void get_dependencies(const String &p_path, List *p_dependencies, bool p_add_types = false); @@ -68,12 +75,15 @@ public: String get_internal_resource_path(const String &p_path) const; void get_internal_resource_path_list(const String &p_path, List *r_paths); - void add_importer(const Ref &p_importer) { importers.push_back(p_importer); } + void add_importer(const Ref &p_importer) { importers.push_back(p_importer); importers.sort_custom();} void remove_importer(const Ref &p_importer) { importers.erase(p_importer); } Ref get_importer_by_name(const String &p_name) const; Ref get_importer_by_extension(const String &p_extension) const; void get_importers_for_extension(const String &p_extension, List > *r_importers); + bool are_import_settings_valid(const String &p_path) const; + String get_import_settings_hash() const; + String get_import_base_path(const String &p_for_file) const; ResourceFormatImporter(); }; @@ -107,7 +117,10 @@ public: virtual void get_import_options(List *r_options, int p_preset = 0) const = 0; virtual bool get_option_visibility(const String &p_option, const Map &p_options) const = 0; - 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 = NULL) = 0; + 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 = NULL, Variant *r_metadata=NULL) = 0; + virtual bool are_import_settings_valid(const String &p_path) const { return true; } + virtual String get_import_settings_string() const { return String(); } + }; #endif // RESOURCE_IMPORTER_H -- cgit v1.2.3