diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/bind/core_bind.cpp | 5 | ||||
-rw-r--r-- | core/bind/core_bind.h | 1 | ||||
-rw-r--r-- | core/io/resource_format_binary.cpp | 97 | ||||
-rw-r--r-- | core/io/resource_format_binary.h | 1 | ||||
-rw-r--r-- | core/io/resource_import.cpp | 154 | ||||
-rw-r--r-- | core/io/resource_import.h | 50 | ||||
-rw-r--r-- | core/io/resource_loader.cpp | 145 | ||||
-rw-r--r-- | core/io/resource_loader.h | 9 | ||||
-rw-r--r-- | core/path_remap.cpp | 182 | ||||
-rw-r--r-- | core/path_remap.h | 35 | ||||
-rw-r--r-- | core/register_core_types.cpp | 2 | ||||
-rw-r--r-- | core/resource.cpp | 130 | ||||
-rw-r--r-- | core/resource.h | 46 |
13 files changed, 230 insertions, 627 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 80adafe092..5dbcfc86bc 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -106,17 +106,12 @@ bool _ResourceLoader::has(const String &p_path) { return ResourceCache::has(local_path); }; -Ref<ResourceImportMetadata> _ResourceLoader::load_import_metadata(const String& p_path) { - - return ResourceLoader::load_import_metadata(p_path); -} void _ResourceLoader::_bind_methods() { ClassDB::bind_method(_MD("load_interactive:ResourceInteractiveLoader","path","type_hint"),&_ResourceLoader::load_interactive,DEFVAL("")); ClassDB::bind_method(_MD("load:Resource","path","type_hint", "p_no_cache"),&_ResourceLoader::load,DEFVAL(""), DEFVAL(false)); - ClassDB::bind_method(_MD("load_import_metadata:ResourceImportMetadata","path"),&_ResourceLoader::load_import_metadata); ClassDB::bind_method(_MD("get_recognized_extensions_for_type","type"),&_ResourceLoader::get_recognized_extensions_for_type); ClassDB::bind_method(_MD("set_abort_on_missing_resources","abort"),&_ResourceLoader::set_abort_on_missing_resources); ClassDB::bind_method(_MD("get_dependencies","path"),&_ResourceLoader::get_dependencies); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 13081fc867..00cbb254d6 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -54,7 +54,6 @@ public: void set_abort_on_missing_resources(bool p_abort); PoolStringArray get_dependencies(const String& p_path); bool has(const String& p_path); - Ref<ResourceImportMetadata> load_import_metadata(const String& p_path); _ResourceLoader(); }; diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 8f8fce0891..c75e476764 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -759,30 +759,7 @@ Error ResourceInteractiveLoaderBinary::poll(){ resource_cache.push_back(res); if (main) { - if (importmd_ofs) { - f->seek(importmd_ofs); - Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); - imd->set_editor(get_unicode_string()); - int sc = f->get_32(); - for(int i=0;i<sc;i++) { - - String src = get_unicode_string(); - String md5 = get_unicode_string(); - imd->add_source(src,md5); - } - int pc = f->get_32(); - - for(int i=0;i<pc;i++) { - - String name = get_unicode_string(); - Variant val; - parse_variant(val); - imd->set_option(name,val); - } - res->set_import_metadata(imd); - - } f->close(); resource=res; error=ERR_FILE_EOF; @@ -849,9 +826,6 @@ void ResourceInteractiveLoaderBinary::get_dependencies(FileAccess *p_f,List<Stri for(int i=0;i<external_resources.size();i++) { String dep=external_resources[i].path; - if (dep.ends_with("*")) { - dep=ResourceLoader::guess_full_filename(dep,external_resources[i].type); - } if (p_add_types && external_resources[i].type!=String()) { dep+="::"+external_resources[i].type; @@ -1104,53 +1078,6 @@ bool ResourceFormatLoaderBinary::handles_type(const String& p_type) const{ return true; //handles all } -Error ResourceFormatLoaderBinary::load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const { - - - FileAccess *f = FileAccess::open(p_path,FileAccess::READ); - if (!f) { - return ERR_FILE_CANT_OPEN; - } - - Ref<ResourceInteractiveLoaderBinary> ria = memnew( ResourceInteractiveLoaderBinary ); - ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path); - ria->res_path=ria->local_path; - //ria->set_local_path( Globals::get_singleton()->localize_path(p_path) ); - ria->recognize(f); - if(ria->error!=OK) - return ERR_FILE_UNRECOGNIZED; - f=ria->f; - uint64_t imp_ofs = f->get_64(); - - if (imp_ofs==0) - return ERR_UNAVAILABLE; - - f->seek(imp_ofs); - Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); - imd->set_editor(ria->get_unicode_string()); - int sc = f->get_32(); - for(int i=0;i<sc;i++) { - - String src = ria->get_unicode_string(); - String md5 = ria->get_unicode_string(); - imd->add_source(src,md5); - } - int pc = f->get_32(); - - for(int i=0;i<pc;i++) { - - String name = ria->get_unicode_string(); - Variant val; - ria->parse_variant(val); - imd->set_option(name,val); - } - - r_var=imd; - - return OK; - -} - void ResourceFormatLoaderBinary::get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types) { @@ -2179,30 +2106,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_ } f->seek_end(); - print_line("SAVING: "+p_path); - if (p_resource->get_import_metadata().is_valid()) { - uint64_t md_pos = f->get_pos(); - Ref<ResourceImportMetadata> imd=p_resource->get_import_metadata(); - save_unicode_string(imd->get_editor()); - f->store_32(imd->get_source_count()); - for(int i=0;i<imd->get_source_count();i++) { - save_unicode_string(imd->get_source_path(i)); - save_unicode_string(imd->get_source_md5(i)); - print_line("SAVE PATH: "+imd->get_source_path(i)); - print_line("SAVE MD5: "+imd->get_source_md5(i)); - } - List<String> options; - imd->get_options(&options); - f->store_32(options.size()); - for(List<String>::Element *E=options.front();E;E=E->next()) { - save_unicode_string(E->get()); - write_variant(imd->get_option(E->get())); - } - - f->seek(md_at); - f->store_64(md_pos); - f->seek_end(); - } f->store_buffer((const uint8_t*)"RSRC",4); //magic at end diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index 611029e792..1dac51cc5c 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -109,7 +109,6 @@ public: 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 Error load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const; virtual Error rename_dependencies(const String &p_path,const Map<String,String>& p_map); diff --git a/core/io/resource_import.cpp b/core/io/resource_import.cpp new file mode 100644 index 0000000000..92b5d1de40 --- /dev/null +++ b/core/io/resource_import.cpp @@ -0,0 +1,154 @@ +#include "resource_import.h" +#include "variant_parser.h" + +Error ResourceFormatImporter::_get_path_and_type(const String& p_path, PathAndType &r_path_and_type) const { + + Error err; + FileAccess *f= FileAccess::open(p_path+".import",FileAccess::READ,&err); + + if (!f) + return err; + + VariantParser::StreamFile stream; + stream.f=f; + + String assign; + Variant value; + VariantParser::Tag next_tag; + + int lines=0; + String error_text; + while(true) { + + assign=Variant(); + next_tag.fields.clear(); + next_tag.name=String(); + + err = VariantParser::parse_tag_assign_eof(&stream,lines,error_text,next_tag,assign,value,NULL,true); + if (err==ERR_FILE_EOF) { + memdelete(f); + return OK; + } + else if (err!=OK) { + ERR_PRINTS("ResourceFormatImporter::load - "+p_path+":"+itos(lines)+" error: "+error_text); + memdelete(f); + return err; + } + + if (assign!=String()) { + if (assign=="path") { + r_path_and_type.path=value; + } else if (assign=="type") { + r_path_and_type.type=value; + } + + } else if (next_tag.name!="remap") { + break; + } + } + + memdelete(f); + + if (r_path_and_type.path==String() || r_path_and_type.type==String()) { + return ERR_FILE_CORRUPT; + } + return OK; + +} + + +RES ResourceFormatImporter::load(const String &p_path,const String& p_original_path,Error *r_error) { + + PathAndType pat; + Error err = _get_path_and_type(p_path,pat); + + if (err!=OK) { + + if (r_error) + *r_error=err; + + return RES(); + } + + + return ResourceLoader::load(pat.path,pat.type,false,r_error); + +} + +void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extensions) const{ + + Set<String> found; + + 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 (!found.has(F->get())) { + p_extensions->push_back(F->get()); + found.insert(F->get()); + } + } + } +} + +void ResourceFormatImporter::get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const{ + + 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())) + continue; + + List<String> local_exts; + E->get()->get_recognized_extensions(&local_exts); + for (List<String>::Element *F=local_exts.front();F;F=F->next()) { + if (!found.has(F->get())) { + p_extensions->push_back(F->get()); + found.insert(F->get()); + } + } + } +} + +bool ResourceFormatImporter::recognize_path(const String& p_path,const String& p_for_type) const{ + + return (p_path.get_extension().to_lower()=="import"); +} + +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())) + return true; + + } + + return true; +} + +String ResourceFormatImporter::get_resource_type(const String &p_path) const { + + PathAndType pat; + Error err = _get_path_and_type(p_path,pat); + + if (err!=OK) { + + return ""; + } + + return pat.type; +} + +void ResourceFormatImporter::get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types){ + + PathAndType pat; + Error err = _get_path_and_type(p_path,pat); + + if (err!=OK) { + + return; + } + + return ResourceLoader::get_dependencies(pat.path,p_dependencies,p_add_types); +} + diff --git a/core/io/resource_import.h b/core/io/resource_import.h new file mode 100644 index 0000000000..d4b80030b2 --- /dev/null +++ b/core/io/resource_import.h @@ -0,0 +1,50 @@ +#ifndef RESOURCE_IMPORT_H +#define RESOURCE_IMPORT_H + + +#include "io/resource_loader.h" +class ResourceImporter; + +class ResourceFormatImporter : public ResourceFormatLoader { + + struct PathAndType { + String path; + String type; + }; + + + Error _get_path_and_type(const String& p_path,PathAndType & r_path_and_type) const; + + Set< Ref<ResourceImporter> > importers; +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; + 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 void get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types=false); + +}; + + +class ResourceImporter { +public: + virtual String get_name() const=0; + virtual String get_visible_name() const=0; + virtual void get_recognized_extensions(List<String> *p_extensions) const=0; + virtual String get_resource_type() const=0; + + struct ImportOption { + PropertyInfo option; + Variant default_value; + }; + + virtual void get_import_options(List<ImportOption> *r_options)=0; + + virtual RES import(const String& p_path,const Map<StringName,Variant>& p_options)=0; + +}; + +#endif // RESOURCE_IMPORT_H diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 354efaa83f..fbf6a2cea2 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -47,21 +47,29 @@ Error ResourceInteractiveLoader::wait() { return err; } +bool ResourceFormatLoader::recognize_path(const String& p_path,const String& p_for_type) const { -bool ResourceFormatLoader::recognize(const String& p_extension) const { + String extension = p_path.get_extension(); List<String> extensions; - get_recognized_extensions(&extensions); + if (p_for_type==String()) { + get_recognized_extensions(&extensions); + } else { + get_recognized_extensions_for_type(p_for_type,&extensions); + } + for (List<String>::Element *E=extensions.front();E;E=E->next()) { - if (E->get().nocasecmp_to(p_extension.get_extension())==0) + if (E->get().nocasecmp_to(extension)==0) return true; } return false; + } + void ResourceFormatLoader::get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const { if (p_type=="" || handles_type(p_type)) @@ -166,7 +174,7 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p else local_path = GlobalConfig::get_singleton()->localize_path(p_path); - local_path=find_complete_path(local_path,p_type_hint); + ERR_FAIL_COND_V(local_path=="",RES()); if (!p_no_cache && ResourceCache::has(local_path)) { @@ -177,22 +185,16 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p return RES( ResourceCache::get(local_path ) ); } - String remapped_path = PathRemap::get_singleton()->get_remap(local_path); - if (OS::get_singleton()->is_stdout_verbose()) - print_line("load resource: "+remapped_path); - - String extension=remapped_path.get_extension(); + print_line("load resource: "+local_path); bool found=false; for (int i=0;i<loader_count;i++) { - if (!loader[i]->recognize(extension)) - continue; - if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) + if (!loader[i]->recognize_path(local_path,p_type_hint)) continue; found=true; - RES res = loader[i]->load(remapped_path,local_path,r_error); + RES res = loader[i]->load(local_path,local_path,r_error); if (res.is_null()) continue; if (!p_no_cache) @@ -201,7 +203,7 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p res->set_edited(false); if (timestamp_on_load) { - uint64_t mt = FileAccess::get_modified_time(remapped_path); + uint64_t mt = FileAccess::get_modified_time(local_path); //printf("mt %s: %lli\n",remapped_path.utf8().get_data(),mt); res->set_last_modified_time(mt); } @@ -220,82 +222,6 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p } -Ref<ResourceImportMetadata> ResourceLoader::load_import_metadata(const String &p_path) { - - - - String local_path; - if (p_path.is_rel_path()) - local_path="res://"+p_path; - else - local_path = GlobalConfig::get_singleton()->localize_path(p_path); - - String extension=p_path.get_extension(); - Ref<ResourceImportMetadata> ret; - - for (int i=0;i<loader_count;i++) { - - if (!loader[i]->recognize(extension)) - continue; - - Error err = loader[i]->load_import_metadata(local_path,ret); - if (err==OK) - break; - } - - - return ret; - -} - - - -String ResourceLoader::find_complete_path(const String& p_path,const String& p_type) { - //this is an old vestige when the engine saved files without extension. - //remains here for compatibility with old projects and only because it - //can be sometimes nice to open files using .* from a script and have it guess - //the right extension. - - String local_path = p_path; - if (local_path.ends_with("*")) { - - //find the extension for resource that ends with * - local_path = local_path.substr(0,local_path.length()-1); - List<String> extensions; - get_recognized_extensions_for_type(p_type,&extensions); - List<String> candidates; - - for(List<String>::Element *E=extensions.front();E;E=E->next()) { - - String path = local_path+E->get(); - - if (PathRemap::get_singleton()->has_remap(path) || FileAccess::exists(path)) { - candidates.push_back(path); - } - - } - - - if (candidates.size()==0) { - return ""; - } else if (candidates.size()==1 || p_type=="") { - return candidates.front()->get(); - } else { - - for(List<String>::Element *E=candidates.front();E;E=E->next()) { - - String rt = get_resource_type(E->get()); - if (ClassDB::is_parent_class(rt,p_type)) { - return E->get(); - } - } - - return ""; - } - } - - return local_path; -} Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_path,const String& p_type_hint,bool p_no_cache,Error *r_error) { @@ -309,7 +235,7 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_ else local_path = GlobalConfig::get_singleton()->localize_path(p_path); - local_path=find_complete_path(local_path,p_type_hint); + ERR_FAIL_COND_V(local_path=="",Ref<ResourceInteractiveLoader>()); @@ -329,19 +255,14 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_ if (OS::get_singleton()->is_stdout_verbose()) print_line("load resource: "); - String remapped_path = PathRemap::get_singleton()->get_remap(local_path); - - String extension=remapped_path.get_extension(); bool found=false; for (int i=0;i<loader_count;i++) { - if (!loader[i]->recognize(extension)) - continue; - if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) + if (!loader[i]->recognize_path(local_path,p_type_hint)) continue; found=true; - Ref<ResourceInteractiveLoader> ril = loader[i]->load_interactive(remapped_path,r_error); + Ref<ResourceInteractiveLoader> ril = loader[i]->load_interactive(local_path,r_error); if (ril.is_null()) continue; if (!p_no_cache) @@ -383,20 +304,16 @@ void ResourceLoader::get_dependencies(const String& p_path, List<String> *p_depe else local_path = GlobalConfig::get_singleton()->localize_path(p_path); - String remapped_path = PathRemap::get_singleton()->get_remap(local_path); - - String extension=remapped_path.get_extension(); - for (int i=0;i<loader_count;i++) { - if (!loader[i]->recognize(extension)) + if (!loader[i]->recognize_path(local_path)) continue; /* if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) continue; */ - loader[i]->get_dependencies(remapped_path,p_dependencies,p_add_types); + loader[i]->get_dependencies(local_path,p_dependencies,p_add_types); } } @@ -410,20 +327,17 @@ Error ResourceLoader::rename_dependencies(const String &p_path,const Map<String, else local_path = GlobalConfig::get_singleton()->localize_path(p_path); - String remapped_path = PathRemap::get_singleton()->get_remap(local_path); - - String extension=remapped_path.get_extension(); for (int i=0;i<loader_count;i++) { - if (!loader[i]->recognize(extension)) + if (!loader[i]->recognize_path(local_path)) continue; /* if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) continue; */ - return loader[i]->rename_dependencies(p_path,p_map); + return loader[i]->rename_dependencies(local_path,p_map); } @@ -432,17 +346,6 @@ Error ResourceLoader::rename_dependencies(const String &p_path,const Map<String, } -String ResourceLoader::guess_full_filename(const String &p_path,const String& p_type) { - - String local_path; - if (p_path.is_rel_path()) - local_path="res://"+p_path; - else - local_path = GlobalConfig::get_singleton()->localize_path(p_path); - - return find_complete_path(local_path,p_type); - -} String ResourceLoader::get_resource_type(const String &p_path) { @@ -452,8 +355,6 @@ String ResourceLoader::get_resource_type(const String &p_path) { else local_path = GlobalConfig::get_singleton()->localize_path(p_path); - String remapped_path = PathRemap::get_singleton()->get_remap(local_path); - String extension=remapped_path.get_extension(); for (int i=0;i<loader_count;i++) { diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index 7979bd02a7..05a4d98d83 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -61,11 +61,10 @@ 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(const String& p_extension) 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 void get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types=false); - virtual Error load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const { return ERR_UNAVAILABLE; } virtual Error rename_dependencies(const String &p_path,const Map<String,String>& p_map) { return OK; } virtual ~ResourceFormatLoader() {} @@ -92,14 +91,12 @@ class ResourceLoader { static DependencyErrorNotify dep_err_notify; static bool abort_on_missing_resource; - static String find_complete_path(const String& p_path,const String& p_type); public: static Ref<ResourceInteractiveLoader> load_interactive(const String &p_path,const String& p_type_hint="",bool p_no_cache=false,Error *r_error=NULL); static RES load(const String &p_path,const String& p_type_hint="",bool p_no_cache=false,Error *r_error=NULL); - static Ref<ResourceImportMetadata> load_import_metadata(const String &p_path); static void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions); static void add_resource_format_loader(ResourceFormatLoader *p_format_loader,bool p_at_front=false); @@ -107,8 +104,6 @@ public: static void get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types=false); static Error rename_dependencies(const String &p_path,const Map<String,String>& p_map); - static String guess_full_filename(const String &p_path,const String& p_type); - static void set_timestamp_on_load(bool p_timestamp) { timestamp_on_load=p_timestamp; } static void notify_load_error(const String& p_err) { if (err_notify) err_notify(err_notify_ud,p_err); } @@ -122,4 +117,6 @@ public: static bool get_abort_on_missing_resources() { return abort_on_missing_resource; } }; + + #endif diff --git a/core/path_remap.cpp b/core/path_remap.cpp index ed77fd8840..bbaba71bba 100644 --- a/core/path_remap.cpp +++ b/core/path_remap.cpp @@ -28,185 +28,3 @@ /*************************************************************************/ #include "path_remap.h" -#include "globals.h" -#include "os/os.h" -#include "translation.h" - -PathRemap* PathRemap::singleton=NULL; - -PathRemap* PathRemap::get_singleton() { - - return singleton; -} - -void PathRemap::add_remap(const String& p_from, const String& p_to,const String& p_locale) { - - if (!remap.has(p_from)) { - remap[p_from]=RemapData(); - } - - if (p_locale==String()) - remap[p_from].always=p_to; - else - remap[p_from].locale[p_locale]=p_to; -} - - -String PathRemap::get_remap(const String& p_from) const { - - const RemapData *ptr=remap.getptr(p_from); - if (!ptr) { - if (OS::get_singleton()->is_stdout_verbose()) - print_line("remap failed: "+p_from); - return p_from; - } else { - - const RemapData *ptr2=NULL; - - String locale = TranslationServer::get_singleton()->get_locale(); - - if (ptr->locale.has(locale)) { - if (OS::get_singleton()->is_stdout_verbose()) - print_line("remap found: "+p_from+" -> "+ptr->locale[locale]); - - ptr2=remap.getptr(ptr->locale[locale]); - - if (ptr2 && ptr2->always!=String()) //may have atlas or export remap too - return ptr2->always; - else - return ptr->locale[locale]; - } - - int p = locale.find("_"); - if (p!=-1) { - locale=locale.substr(0,p); - if (ptr->locale.has(locale)) { - if (OS::get_singleton()->is_stdout_verbose()) - print_line("remap found: "+p_from+" -> "+ptr->locale[locale]); - - ptr2=remap.getptr(ptr->locale[locale]); - - if (ptr2 && ptr2->always!=String()) //may have atlas or export remap too - return ptr2->always; - else - return ptr->locale[locale]; - - } - } - - if (ptr->always!=String()) { - if (OS::get_singleton()->is_stdout_verbose()) { - print_line("remap found: "+p_from+" -> "+ptr->always); - } - return ptr->always; - } - - if (OS::get_singleton()->is_stdout_verbose()) - print_line("remap failed: "+p_from); - - return p_from; - } -} -bool PathRemap::has_remap(const String& p_from) const{ - - return remap.has(p_from); -} - -void PathRemap::erase_remap(const String& p_from){ - - ERR_FAIL_COND(!remap.has(p_from)); - remap.erase(p_from); -} - -void PathRemap::clear_remaps() { - - remap.clear(); -} - -void PathRemap::load_remaps() { - - // default remaps first - PoolVector<String> remaps; - if (GlobalConfig::get_singleton()->has("remap/all")) { - remaps = GlobalConfig::get_singleton()->get("remap/all"); - } - - { - int rlen = remaps.size(); - - ERR_FAIL_COND( rlen%2 ); - PoolVector<String>::Read r = remaps.read(); - for(int i=0;i<rlen/2;i++) { - - String from = r[i*2+0]; - String to = r[i*2+1]; - add_remap(from,to); - } - } - - - // platform remaps second, so override - if (GlobalConfig::get_singleton()->has("remap/"+OS::get_singleton()->get_name())) { - remaps = GlobalConfig::get_singleton()->get("remap/"+OS::get_singleton()->get_name()); - } else { - remaps.resize(0); - } - //remaps = Globals::get_singleton()->get("remap/PSP"); - { - int rlen = remaps.size(); - - ERR_FAIL_COND( rlen%2 ); - PoolVector<String>::Read r = remaps.read(); - for(int i=0;i<rlen/2;i++) { - - String from = r[i*2+0]; - String to = r[i*2+1]; - //print_line("add remap: "+from+" -> "+to); - add_remap(from,to); - } - } - - - //locale based remaps - - if (GlobalConfig::get_singleton()->has("locale/translation_remaps")) { - - Dictionary remaps = GlobalConfig::get_singleton()->get("locale/translation_remaps"); - List<Variant> rk; - remaps.get_key_list(&rk); - for(List<Variant>::Element *E=rk.front();E;E=E->next()) { - - String source = E->get(); - PoolStringArray sa = remaps[E->get()]; - int sas = sa.size(); - PoolStringArray::Read r = sa.read(); - - for(int i=0;i<sas;i++) { - - String s = r[i]; - int qp = s.find_last(":"); - if (qp!=-1) { - String path = s.substr(0,qp); - String locale = s.substr(qp+1,s.length()); - add_remap(source,path,locale); - } - } - } - - } - -} - -void PathRemap::_bind_methods() { - - ClassDB::bind_method(_MD("add_remap","from","to","locale"),&PathRemap::add_remap,DEFVAL(String())); - ClassDB::bind_method(_MD("has_remap","path"),&PathRemap::has_remap); - ClassDB::bind_method(_MD("get_remap","path"),&PathRemap::get_remap); - ClassDB::bind_method(_MD("erase_remap","path"),&PathRemap::erase_remap); - ClassDB::bind_method(_MD("clear_remaps"),&PathRemap::clear_remaps); -} - -PathRemap::PathRemap() { - - singleton=this; -} diff --git a/core/path_remap.h b/core/path_remap.h index a106030f95..966bb10ea5 100644 --- a/core/path_remap.h +++ b/core/path_remap.h @@ -29,39 +29,4 @@ #ifndef PATH_REMAP_H #define PATH_REMAP_H -#include "hash_map.h" -#include "ustring.h" -#include "object.h" - - -class PathRemap : public Object { - - GDCLASS(PathRemap,Object); - - static PathRemap* singleton; - struct RemapData { - String always; - Map<String,String> locale; - }; - - HashMap<String,RemapData> remap; -protected: - - static void _bind_methods(); -public: - - void add_remap(const String& p_from, const String& p_to,const String& p_locale=String()); - bool has_remap(const String& p_from) const; - //_FORCE_INLINE_ String get_remap(const String& p_from) const { const String *ptr=remap.getptr(p_from); if (!ptr) return p_from; else return *ptr; } - String get_remap(const String& p_from) const; - void erase_remap(const String& p_from); - void clear_remaps(); - - void load_remaps(); - - static PathRemap* get_singleton(); - - PathRemap(); -}; - #endif // PATH_REMAP_H diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index 242d36042d..8cbfdf0b01 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -110,7 +110,6 @@ void register_core_types() { ClassDB::register_class<Reference>(); ClassDB::register_class<WeakRef>(); - ClassDB::register_class<ResourceImportMetadata>(); ClassDB::register_class<Resource>(); ClassDB::register_class<FuncRef>(); ClassDB::register_virtual_class<StreamPeer>(); @@ -179,7 +178,6 @@ void register_core_singletons() { GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Geometry",_Geometry::get_singleton()) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("ResourceLoader",_ResourceLoader::get_singleton()) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("ResourceSaver",_ResourceSaver::get_singleton()) ); - GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("PathRemap",PathRemap::get_singleton() ) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("OS",_OS::get_singleton() ) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Engine",_Engine::get_singleton() ) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("ClassDB",_classdb ) ); diff --git a/core/resource.cpp b/core/resource.cpp index 6e8d9a8b17..765000d662 100644 --- a/core/resource.cpp +++ b/core/resource.cpp @@ -35,119 +35,6 @@ #include <stdio.h> -void ResourceImportMetadata::set_editor(const String& p_editor) { - - editor=p_editor; -} - -String ResourceImportMetadata::get_editor() const{ - - return editor; -} - -void ResourceImportMetadata::add_source(const String& p_path,const String& p_md5) { - - Source s; - s.md5=p_md5; - s.path=p_path; - sources.push_back(s); -} - -String ResourceImportMetadata::get_source_path(int p_idx) const{ - ERR_FAIL_INDEX_V(p_idx,sources.size(),String()); - return sources[p_idx].path; -} -String ResourceImportMetadata::get_source_md5(int p_idx) const{ - ERR_FAIL_INDEX_V(p_idx,sources.size(),String()); - return sources[p_idx].md5; -} - -void ResourceImportMetadata::set_source_md5(int p_idx,const String& p_md5) { - - ERR_FAIL_INDEX(p_idx,sources.size()); - sources[p_idx].md5=p_md5; - -} - -void ResourceImportMetadata::remove_source(int p_idx){ - - ERR_FAIL_INDEX(p_idx,sources.size()); - sources.remove(p_idx); - -} - -int ResourceImportMetadata::get_source_count() const { - - return sources.size(); -} -void ResourceImportMetadata::set_option(const String& p_key, const Variant& p_value) { - - if (p_value.get_type()==Variant::NIL) { - options.erase(p_key); - return; - } - - ERR_FAIL_COND(p_value.get_type() == Variant::OBJECT); - ERR_FAIL_COND(p_value.get_type() == Variant::_RID); - - options[p_key]=p_value; - -} - -bool ResourceImportMetadata::has_option(const String& p_key) const { - - return options.has(p_key); -} - -Variant ResourceImportMetadata::get_option(const String& p_key) const { - - ERR_FAIL_COND_V(!options.has(p_key),Variant()); - - return options[p_key]; -} - -void ResourceImportMetadata::get_options(List<String> *r_options) const { - - for(Map<String,Variant>::Element *E=options.front();E;E=E->next()) { - - r_options->push_back(E->key()); - } - -} - -PoolStringArray ResourceImportMetadata::_get_options() const { - - PoolStringArray option_names; - option_names.resize(options.size()); - int i=0; - for(Map<String,Variant>::Element *E=options.front();E;E=E->next()) { - - option_names.set(i++,E->key()); - } - - return option_names; -} - -void ResourceImportMetadata::_bind_methods() { - - ClassDB::bind_method(_MD("set_editor","name"),&ResourceImportMetadata::set_editor); - ClassDB::bind_method(_MD("get_editor"),&ResourceImportMetadata::get_editor); - ClassDB::bind_method(_MD("add_source","path","md5"),&ResourceImportMetadata::add_source, ""); - ClassDB::bind_method(_MD("get_source_path","idx"),&ResourceImportMetadata::get_source_path); - ClassDB::bind_method(_MD("get_source_md5","idx"),&ResourceImportMetadata::get_source_md5); - ClassDB::bind_method(_MD("set_source_md5","idx", "md5"),&ResourceImportMetadata::set_source_md5); - ClassDB::bind_method(_MD("remove_source","idx"),&ResourceImportMetadata::remove_source); - ClassDB::bind_method(_MD("get_source_count"),&ResourceImportMetadata::get_source_count); - ClassDB::bind_method(_MD("set_option","key","value"),&ResourceImportMetadata::set_option); - ClassDB::bind_method(_MD("get_option","key"),&ResourceImportMetadata::get_option); - ClassDB::bind_method(_MD("get_options"),&ResourceImportMetadata::_get_options); -} - -ResourceImportMetadata::ResourceImportMetadata() { - - -} - void Resource::emit_changed() { @@ -381,21 +268,6 @@ void Resource::notify_change_to_owners() { } } -void Resource::set_import_metadata(const Ref<ResourceImportMetadata>& p_metadata) { -#ifdef TOOLS_ENABLED - import_metadata=p_metadata; -#endif -} - -Ref<ResourceImportMetadata> Resource::get_import_metadata() const { - -#ifdef TOOLS_ENABLED - return import_metadata; -#else - return Ref<ResourceImportMetadata>(); -#endif - -} #ifdef TOOLS_ENABLED @@ -461,8 +333,6 @@ void Resource::_bind_methods() { ClassDB::bind_method(_MD("set_name","name"),&Resource::set_name); ClassDB::bind_method(_MD("get_name"),&Resource::get_name); ClassDB::bind_method(_MD("get_rid"),&Resource::get_rid); - ClassDB::bind_method(_MD("set_import_metadata","metadata"),&Resource::set_import_metadata); - ClassDB::bind_method(_MD("get_import_metadata"),&Resource::get_import_metadata); ClassDB::bind_method(_MD("set_local_to_scene","enable"),&Resource::set_local_to_scene); ClassDB::bind_method(_MD("is_local_to_scene"),&Resource::is_local_to_scene); ClassDB::bind_method(_MD("get_local_scene:Node"),&Resource::get_local_scene); diff --git a/core/resource.h b/core/resource.h index 2b071c8e1c..b2873e4866 100644 --- a/core/resource.h +++ b/core/resource.h @@ -46,47 +46,6 @@ virtual String get_base_extension() const { return m_ext; }\ private: -class ResourceImportMetadata : public Reference { - - GDCLASS( ResourceImportMetadata, Reference ); - - struct Source { - String path; - String md5; - }; - - Vector<Source> sources; - String editor; - - Map<String,Variant> options; - - PoolStringArray _get_options() const; - -protected: - - static void _bind_methods(); -public: - - void set_editor(const String& p_editor); - String get_editor() const; - - void add_source(const String& p_path,const String& p_md5=""); - String get_source_path(int p_idx) const; - String get_source_md5(int p_idx) const; - void set_source_md5(int p_idx,const String& p_md5); - void remove_source(int p_idx); - int get_source_count() const; - - void set_option(const String& p_key, const Variant& p_value); - Variant get_option(const String& p_key) const; - bool has_option(const String& p_key) const; - - void get_options(List<String> *r_options) const; - - - ResourceImportMetadata(); -}; - class Resource : public Reference { @@ -106,7 +65,6 @@ friend class ResourceCache; virtual bool _use_builtin_script() const { return true; } #ifdef TOOLS_ENABLED - Ref<ResourceImportMetadata> import_metadata; uint64_t last_modified_time; #endif @@ -147,10 +105,6 @@ public: Ref<Resource> duplicate(bool p_subresources=false); Ref<Resource> duplicate_for_local_scene(Node *p_scene,Map<Ref<Resource>,Ref<Resource> >& remap_cache); - - void set_import_metadata(const Ref<ResourceImportMetadata>& p_metadata); - Ref<ResourceImportMetadata> get_import_metadata() const; - void set_local_to_scene(bool p_enable); bool is_local_to_scene() const; virtual void setup_local_to_scene(); |