summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-06-27 13:17:20 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-06-27 13:17:20 -0300
commitefdcf205d2b428580ee9b4a50572649bc06b4276 (patch)
tree3d091cf77bd4033436a0d33314c021efbe6e4239 /core
parent88e28af5e360d826ee0e83944dff0003375e3daf (diff)
Make most resources (save for packedscenes and scripts) reload if they change on disk. Closes #4059.
Diffstat (limited to 'core')
-rw-r--r--core/resource.cpp28
-rw-r--r--core/resource.h2
-rw-r--r--core/script_language.h1
3 files changed, 27 insertions, 4 deletions
diff --git a/core/resource.cpp b/core/resource.cpp
index 97dee3e1d7..b80ec7012d 100644
--- a/core/resource.cpp
+++ b/core/resource.cpp
@@ -30,7 +30,7 @@
#include "core_string_names.h"
#include <stdio.h>
#include "os/file_access.h"
-
+#include "io/resource_loader.h"
void ResourceImportMetadata::set_editor(const String& p_editor) {
@@ -218,14 +218,36 @@ String Resource::get_name() const {
return name;
}
-bool Resource::can_reload_from_file() {
+bool Resource::editor_can_reload_from_file() {
- return false;
+ return true; //by default yes
}
void Resource::reload_from_file() {
+ String path=get_path();
+ if (!path.is_resource_file())
+ return;
+
+ Ref<Resource> s = ResourceLoader::load(path,get_type(),true);
+
+ if (!s.is_valid())
+ return;
+
+ List<PropertyInfo> pi;
+ s->get_property_list(&pi);
+
+ for (List<PropertyInfo>::Element *E=pi.front();E;E=E->next()) {
+
+ if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
+ continue;
+ if (E->get().name=="resource/path")
+ continue; //do not change path
+
+ set(E->get().name,s->get(E->get().name));
+
+ }
}
diff --git a/core/resource.h b/core/resource.h
index 958414f62b..0673a4e89d 100644
--- a/core/resource.h
+++ b/core/resource.h
@@ -121,7 +121,7 @@ protected:
void _take_over_path(const String& p_path);
public:
- virtual bool can_reload_from_file();
+ virtual bool editor_can_reload_from_file();
virtual void reload_from_file();
void register_owner(Object *p_owner);
diff --git a/core/script_language.h b/core/script_language.h
index 51fb351fde..6d75b83aaf 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -78,6 +78,7 @@ class Script : public Resource {
protected:
+ virtual bool editor_can_reload_from_file() { return false; } // this is handled by editor better
void _notification( int p_what);
static void _bind_methods();