mirror of
https://github.com/godotengine/godot.git
synced 2024-11-10 22:23:07 +00:00
Make most resources (save for packedscenes and scripts) reload if they change on disk. Closes #4059.
This commit is contained in:
parent
88e28af5e3
commit
efdcf205d2
@ -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));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
||||
|
@ -196,6 +196,7 @@ class PackedScene : public Resource {
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool editor_can_reload_from_file() { return false; } // this is handled by editor better
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
|
@ -187,6 +187,8 @@ RID Sample::get_rid() const {
|
||||
return sample;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Sample::_bind_methods(){
|
||||
|
||||
|
||||
|
@ -75,6 +75,7 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
|
||||
void create(Format p_format, bool p_stereo, int p_length);
|
||||
|
||||
Format get_format() const;
|
||||
|
@ -98,10 +98,6 @@ Texture::Texture() {
|
||||
|
||||
|
||||
|
||||
bool ImageTexture::can_reload_from_file() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImageTexture::reload_from_file() {
|
||||
|
||||
|
@ -103,7 +103,6 @@ private:
|
||||
float lossy_storage_quality;
|
||||
|
||||
protected:
|
||||
virtual bool can_reload_from_file();
|
||||
virtual void reload_from_file();
|
||||
|
||||
bool _set(const StringName& p_name, const Variant& p_value);
|
||||
|
@ -2804,10 +2804,12 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) {
|
||||
|
||||
List<Ref<Resource> > cached;
|
||||
ResourceCache::get_cached_resources(&cached);
|
||||
|
||||
//this should probably be done in a thread..
|
||||
for(List<Ref<Resource> >::Element *E=cached.front();E;E=E->next()) {
|
||||
|
||||
if (!E->get()->can_reload_from_file())
|
||||
if (!E->get()->editor_can_reload_from_file())
|
||||
continue;
|
||||
if (!E->get()->get_path().is_resource_file() && !E->get()->get_path().is_abs_path())
|
||||
continue;
|
||||
if (!FileAccess::exists(E->get()->get_path()))
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user