summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-02-01 09:45:45 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-02-01 09:46:36 -0300
commit2cd2ca7bbc892eccc635b1c4aea80c956c9b92dc (patch)
tree0a212bf8786c53ec7b054757071dc2430667d3a1 /core/io
parent36b6ba8e94d9afcb06aa2579bf627651f7ebfea0 (diff)
Lot of work in new importer, importing textures now works.
Diffstat (limited to 'core/io')
-rw-r--r--core/io/config_file.cpp5
-rw-r--r--core/io/config_file.h2
-rw-r--r--core/io/resource_import.cpp87
-rw-r--r--core/io/resource_import.h40
-rw-r--r--core/io/resource_loader.h2
5 files changed, 123 insertions, 13 deletions
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp
index a9de740806..b944906e78 100644
--- a/core/io/config_file.cpp
+++ b/core/io/config_file.cpp
@@ -119,7 +119,10 @@ void ConfigFile::get_section_keys(const String& p_section,List<String> *r_keys)
}
+void ConfigFile::erase_section(const String& p_section) {
+ values.erase(p_section);
+}
Error ConfigFile::save(const String& p_path){
@@ -215,6 +218,8 @@ void ConfigFile::_bind_methods(){
ClassDB::bind_method(_MD("get_sections"),&ConfigFile::_get_sections);
ClassDB::bind_method(_MD("get_section_keys","section"),&ConfigFile::_get_section_keys);
+ ClassDB::bind_method(_MD("erase_section","section"),&ConfigFile::erase_section);
+
ClassDB::bind_method(_MD("load:Error","path"),&ConfigFile::load);
ClassDB::bind_method(_MD("save:Error","path"),&ConfigFile::save);
diff --git a/core/io/config_file.h b/core/io/config_file.h
index 397342f90f..c9c4a9fbc0 100644
--- a/core/io/config_file.h
+++ b/core/io/config_file.h
@@ -54,6 +54,8 @@ public:
void get_sections(List<String> *r_sections) const;
void get_section_keys(const String& p_section,List<String> *r_keys) const;
+ void erase_section(const String& p_section);
+
Error save(const String& p_path);
Error load(const String& p_path);
diff --git a/core/io/resource_import.cpp b/core/io/resource_import.cpp
index 92b5d1de40..18fd8d25e7 100644
--- a/core/io/resource_import.cpp
+++ b/core/io/resource_import.cpp
@@ -30,7 +30,7 @@ Error ResourceFormatImporter::_get_path_and_type(const String& p_path, PathAndTy
return OK;
}
else if (err!=OK) {
- ERR_PRINTS("ResourceFormatImporter::load - "+p_path+":"+itos(lines)+" error: "+error_text);
+ ERR_PRINTS("ResourceFormatImporter::load - "+p_path+".import:"+itos(lines)+" error: "+error_text);
memdelete(f);
return err;
}
@@ -71,12 +71,20 @@ RES ResourceFormatImporter::load(const String &p_path,const String& p_original_p
}
- return ResourceLoader::load(pat.path,pat.type,false,r_error);
+ RES res = ResourceLoader::load(pat.path,pat.type,false,r_error);
+
+#ifdef TOOLS_ENABLED
+ res->set_import_last_modified_time( res->get_last_modified_time() ); //pass this, if used
+ res->set_import_path(pat.path);
+#endif
+
+ return res;
}
void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extensions) const{
+ print_line("getting exts from: "+itos(importers.size()));
Set<String> found;
for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
@@ -84,6 +92,7 @@ void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extension
E->get()->get_recognized_extensions(&local_exts);
for (List<String>::Element *F=local_exts.front();F;F=F->next()) {
if (!found.has(F->get())) {
+ print_line("adding ext "+String(F->get()));
p_extensions->push_back(F->get());
found.insert(F->get());
}
@@ -93,10 +102,14 @@ void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extension
void ResourceFormatImporter::get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const{
+ if (p_type=="") {
+ return get_recognized_extensions(p_extensions);
+ }
+
Set<String> found;
for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
- if (!ClassDB::is_parent_class(p_type,E->get()->get_resource_type()))
+ if (!ClassDB::is_parent_class(E->get()->get_resource_type(),p_type))
continue;
List<String> local_exts;
@@ -112,13 +125,21 @@ void ResourceFormatImporter::get_recognized_extensions_for_type(const String& p_
bool ResourceFormatImporter::recognize_path(const String& p_path,const String& p_for_type) const{
- return (p_path.get_extension().to_lower()=="import");
+ return FileAccess::exists(p_path+".import");
+
+}
+
+bool ResourceFormatImporter::can_be_imported(const String& p_path) const {
+
+ return ResourceFormatLoader::recognize_path(p_path);
}
+
bool ResourceFormatImporter::handles_type(const String& p_type) const {
for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
- if (ClassDB::is_parent_class(p_type,E->get()->get_resource_type()))
+ print_line("handles "+p_type+" base is "+E->get()->get_resource_type());
+ if (ClassDB::is_parent_class(E->get()->get_resource_type(),p_type))
return true;
}
@@ -152,3 +173,59 @@ void ResourceFormatImporter::get_dependencies(const String& p_path,List<String>
return ResourceLoader::get_dependencies(pat.path,p_dependencies,p_add_types);
}
+Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String& p_name) {
+
+ for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
+ if (E->get()->get_importer_name()==p_name) {
+ return E->get();
+ }
+ }
+
+ return Ref<ResourceImporter>();
+}
+
+
+void ResourceFormatImporter::get_importers_for_extension(const String& p_extension,List<Ref<ResourceImporter> > *r_importers) {
+
+ for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
+ List<String> local_exts;
+ E->get()->get_recognized_extensions(&local_exts);
+ for (List<String>::Element *F=local_exts.front();F;F=F->next()) {
+ if (p_extension.to_lower()==F->get()) {
+ r_importers->push_back(E->get());
+ }
+ }
+ }
+}
+
+Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const String& p_extension) {
+
+
+ Ref<ResourceImporter> importer;
+ float priority=0;
+
+ for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
+
+ List<String> local_exts;
+ E->get()->get_recognized_extensions(&local_exts);
+ for (List<String>::Element *F=local_exts.front();F;F=F->next()) {
+ if (p_extension.to_lower()==F->get() && E->get()->get_priority() > priority) {
+ importer=E->get();
+ priority=E->get()->get_priority();
+ }
+ }
+ }
+
+ return importer;
+}
+
+String ResourceFormatImporter::get_import_base_path(const String& p_for_file) const {
+
+ return "res://.import/"+p_for_file.get_file()+"-"+p_for_file.md5_text();
+}
+
+ResourceFormatImporter *ResourceFormatImporter::singleton=NULL;
+
+ResourceFormatImporter::ResourceFormatImporter() {
+ singleton=this;
+}
diff --git a/core/io/resource_import.h b/core/io/resource_import.h
index d4b80030b2..d54308b6ed 100644
--- a/core/io/resource_import.h
+++ b/core/io/resource_import.h
@@ -15,35 +15,61 @@ class ResourceFormatImporter : public ResourceFormatLoader {
Error _get_path_and_type(const String& p_path,PathAndType & r_path_and_type) const;
+ static ResourceFormatImporter *singleton;
+
Set< Ref<ResourceImporter> > importers;
public:
+ static ResourceFormatImporter *get_singleton() { return singleton; }
virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const;
- bool recognize_path(const String& p_path,const String& p_for_type=String()) const;
- virtual bool handles_type(const String& p_type) const=0;
- virtual String get_resource_type(const String &p_path) const=0;
+ 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 void get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types=false);
+ virtual bool can_be_imported(const String& p_path) const;
+
+
+ void add_importer(const Ref<ResourceImporter>& p_importer) { importers.insert(p_importer); }
+ Ref<ResourceImporter> get_importer_by_name(const String& p_name);
+ Ref<ResourceImporter> get_importer_by_extension(const String& p_extension);
+ void get_importers_for_extension(const String& p_extension,List<Ref<ResourceImporter> > *r_importers);
+
+ String get_import_base_path(const String& p_for_file) const;
+ ResourceFormatImporter();
};
-class ResourceImporter {
+class ResourceImporter : public Reference {
+
+ GDCLASS(ResourceImporter,Reference)
public:
- virtual String get_name() const=0;
+ virtual String get_importer_name() const=0;
virtual String get_visible_name() const=0;
virtual void get_recognized_extensions(List<String> *p_extensions) const=0;
+ virtual String get_save_extension() const=0;
virtual String get_resource_type() const=0;
+ virtual float get_priority() const { return 1.0; }
struct ImportOption {
PropertyInfo option;
Variant default_value;
+
+ ImportOption(const PropertyInfo& p_info,const Variant& p_default) { option=p_info; default_value=p_default; }
+ ImportOption() {}
};
- virtual void get_import_options(List<ImportOption> *r_options)=0;
- virtual RES import(const String& p_path,const Map<StringName,Variant>& p_options)=0;
+ virtual int get_preset_count() const { return 0; }
+ virtual String get_preset_name(int p_idx) const { return String(); }
+
+ virtual void get_import_options(List<ImportOption> *r_options,int p_preset=0) const=0;
+ virtual bool get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const=0;
+
+
+ virtual Error import(const String& p_source_file,const String& p_save_path,const Map<StringName,Variant>& p_options,List<String>* r_platform_variants)=0;
};
diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h
index 05a4d98d83..f464415e12 100644
--- a/core/io/resource_loader.h
+++ b/core/io/resource_loader.h
@@ -61,7 +61,7 @@ public:
virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
virtual void get_recognized_extensions(List<String> *p_extensions) const=0;
virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const;
- bool recognize_path(const String& p_path,const String& p_for_type=String()) const;
+ virtual bool recognize_path(const String& p_path,const String& p_for_type=String()) const;
virtual bool handles_type(const String& p_type) const=0;
virtual String get_resource_type(const String &p_path) const=0;
virtual void get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types=false);