properly save external resources, fixes #1924

added API to get scancode names to OS
This commit is contained in:
Juan Linietsky 2015-05-17 13:11:55 -03:00
parent 0faaa729e7
commit e72717e373
5 changed files with 84 additions and 34 deletions

View file

@ -5,7 +5,7 @@
#include "io/base64.h"
#include "core/globals.h"
#include "io/file_access_encrypted.h"
#include "os/keyboard.h"
_ResourceLoader *_ResourceLoader::singleton=NULL;
Ref<ResourceInteractiveLoader> _ResourceLoader::load_interactive(const String& p_path,const String& p_type_hint) {
@ -694,6 +694,20 @@ String _OS::get_custom_level() const {
return OS::get_singleton()->get_custom_level();
}
String _OS::get_scancode_string(uint32_t p_code) const {
return keycode_get_string(p_code);
}
bool _OS::is_scancode_unicode(uint32_t p_unicode) const {
return keycode_has_unicode(p_unicode);
}
int _OS::find_scancode_from_string(const String& p_code) const {
return find_keycode(p_code);
}
_OS *_OS::singleton=NULL;
void _OS::_bind_methods() {
@ -810,6 +824,9 @@ void _OS::_bind_methods() {
ObjectTypeDB::bind_method(_MD("native_video_stop"),&_OS::native_video_stop);
ObjectTypeDB::bind_method(_MD("native_video_pause"),&_OS::native_video_pause);
ObjectTypeDB::bind_method(_MD("get_scancode_string","code"),&_OS::get_scancode_string);
ObjectTypeDB::bind_method(_MD("is_scancode_unicode","code"),&_OS::is_scancode_unicode);
ObjectTypeDB::bind_method(_MD("find_scancode_from_string","string"),&_OS::find_scancode_from_string);
ObjectTypeDB::bind_method(_MD("set_use_file_access_save_and_swap","enabled"),&_OS::set_use_file_access_save_and_swap);

View file

@ -178,6 +178,11 @@ public:
String get_unique_ID() const;
String get_scancode_string(uint32_t p_code) const;
bool is_scancode_unicode(uint32_t p_unicode) const;
int find_scancode_from_string(const String& p_code) const;
/*
struct Date {

View file

@ -343,6 +343,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
#endif
if (!valid) {
#ifdef DEBUG_ENABLED
if (ret.get_type()==Variant::STRING) {
//return a string when invalid with the error
err_text=ret;
@ -350,7 +352,9 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
} else {
err_text="Invalid operands '"+Variant::get_type_name(a->get_type())+"' and '"+Variant::get_type_name(b->get_type())+"' in operator '"+Variant::get_operator_name(op)+"'.";
}
#endif
break;
}
#ifdef DEBUG_ENABLED
*dst=ret;

View file

@ -610,7 +610,42 @@ static Error _fix_imported_scene_paths(Node* node, Node* root, String save_path)
};
bool EditorNode::_find_and_save_edited_subresources(Object *obj,Set<RES>& processed,int32_t flags) {
bool EditorNode::_find_and_save_resource(RES res,Map<RES,bool>& processed,int32_t flags) {
if (res.is_null())
return false;
if (processed.has(res)) {
return processed[res];
}
bool changed = res->is_edited();
res->set_edited(false);
bool subchanged = _find_and_save_edited_subresources(res.ptr(),processed,flags);
// print_line("checking if edited: "+res->get_type()+" :: "+res->get_name()+" :: "+res->get_path()+" :: "+itos(changed)+" :: SR "+itos(subchanged));
if (res->get_path().is_resource_file()) {
if (changed || subchanged) {
//save
print_line("Also saving modified external resource: "+res->get_path());
Error err = ResourceSaver::save(res->get_path(),res,flags);
}
processed[res]=false; //because it's a file
return false;
} else {
processed[res]=changed;
return changed;
}
}
bool EditorNode::_find_and_save_edited_subresources(Object *obj,Map<RES,bool>& processed,int32_t flags) {
bool ret_changed=false;
List<PropertyInfo> pi;
@ -620,57 +655,45 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj,Set<RES>& proces
if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
continue;
switch(E->get().type) {
case Variant::OBJECT: {
RES res = obj->get(E->get().name);
if (res.is_null() || processed.has(res))
break;
processed.insert(res);
bool changed = res->is_edited();
res->set_edited(false);
bool subchanged = _find_and_save_edited_subresources(res.ptr(),processed,flags);
if (res->get_path().is_resource_file()) {
if (changed || subchanged) {
//save
print_line("Also saving modified external resource: "+res->get_path());
Error err = ResourceSaver::save(res->get_path(),res,flags);
}
} else {
if (_find_and_save_resource(res,processed,flags))
ret_changed=true;
}
} break;
case Variant::ARRAY: {
/*Array varray=p_variant;
Array varray= obj->get(E->get().name);
int len=varray.size();
for(int i=0;i<len;i++) {
Variant v=varray.get(i);
_find_resources(v);
}*/
RES res=v;
if (_find_and_save_resource(res,processed,flags))
ret_changed=true;
//_find_resources(v);
}
} break;
case Variant::DICTIONARY: {
/*
Dictionary d=p_variant;
Dictionary d=obj->get(E->get().name);;
List<Variant> keys;
d.get_key_list(&keys);
for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
Variant v = d[E->get()];
_find_resources(v);
} */
RES res=v;
if (_find_and_save_resource(res,processed,flags))
ret_changed=true;
}
} break;
default: {}
}
@ -681,7 +704,7 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj,Set<RES>& proces
}
void EditorNode::_save_edited_subresources(Node* scene,Set<RES>& processed,int32_t flags) {
void EditorNode::_save_edited_subresources(Node* scene,Map<RES,bool>& processed,int32_t flags) {
_find_and_save_edited_subresources(scene,processed,flags);
@ -741,7 +764,7 @@ void EditorNode::_save_scene(String p_file) {
err = ResourceSaver::save(p_file,sdata,flg);
Set<RES> processed;
Map<RES,bool> processed;
_save_edited_subresources(scene,processed,flg);
editor_data.save_editor_external_data();
if (err==OK) {

View file

@ -390,8 +390,9 @@ class EditorNode : public Node {
void _cleanup_scene();
bool _find_and_save_edited_subresources(Object *obj,Set<RES>& processed,int32_t flags);
void _save_edited_subresources(Node* scene,Set<RES>& processed,int32_t flags);
bool _find_and_save_resource(RES p_res,Map<RES,bool>& processed,int32_t flags);
bool _find_and_save_edited_subresources(Object *obj,Map<RES,bool>& processed,int32_t flags);
void _save_edited_subresources(Node* scene,Map<RES,bool>& processed,int32_t flags);
struct ExportDefer {