Fix missing resource properties being dropped on save
(cherry picked from commit 87cce795d3ff0d6172427f86d9d56eaedcc9d328)
This commit is contained in:
parent
72cff2ed59
commit
2e7d923382
|
@ -74,6 +74,10 @@ bool MissingResource::is_recording_properties() const {
|
||||||
return recording_properties;
|
return recording_properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String MissingResource::get_save_class() const {
|
||||||
|
return original_class;
|
||||||
|
}
|
||||||
|
|
||||||
void MissingResource::_bind_methods() {
|
void MissingResource::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("set_original_class", "name"), &MissingResource::set_original_class);
|
ClassDB::bind_method(D_METHOD("set_original_class", "name"), &MissingResource::set_original_class);
|
||||||
ClassDB::bind_method(D_METHOD("get_original_class"), &MissingResource::get_original_class);
|
ClassDB::bind_method(D_METHOD("get_original_class"), &MissingResource::get_original_class);
|
||||||
|
|
|
@ -57,6 +57,8 @@ public:
|
||||||
void set_recording_properties(bool p_enable);
|
void set_recording_properties(bool p_enable);
|
||||||
bool is_recording_properties() const;
|
bool is_recording_properties() const;
|
||||||
|
|
||||||
|
virtual String get_save_class() const override;
|
||||||
|
|
||||||
MissingResource();
|
MissingResource();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -833,7 +833,7 @@ Error ResourceLoaderBinary::load() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool set_valid = true;
|
bool set_valid = true;
|
||||||
if (value.get_type() == Variant::OBJECT && missing_resource != nullptr) {
|
if (value.get_type() == Variant::OBJECT && missing_resource == nullptr && ResourceLoader::is_creating_missing_resources_if_class_unavailable_enabled()) {
|
||||||
// If the property being set is a missing resource (and the parent is not),
|
// If the property being set is a missing resource (and the parent is not),
|
||||||
// then setting it will most likely not work.
|
// then setting it will most likely not work.
|
||||||
// Instead, save it as metadata.
|
// Instead, save it as metadata.
|
||||||
|
@ -2220,10 +2220,10 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const Ref<Re
|
||||||
|
|
||||||
List<ResourceData> resources;
|
List<ResourceData> resources;
|
||||||
|
|
||||||
Dictionary missing_resource_properties = p_resource->get_meta(META_MISSING_RESOURCES, Dictionary());
|
|
||||||
|
|
||||||
{
|
{
|
||||||
for (const Ref<Resource> &E : saved_resources) {
|
for (const Ref<Resource> &E : saved_resources) {
|
||||||
|
Dictionary missing_resource_properties = E->get_meta(META_MISSING_RESOURCES, Dictionary());
|
||||||
|
|
||||||
ResourceData &rd = resources.push_back(ResourceData())->get();
|
ResourceData &rd = resources.push_back(ResourceData())->get();
|
||||||
rd.type = _resource_get_class(E);
|
rd.type = _resource_get_class(E);
|
||||||
|
|
||||||
|
@ -2238,7 +2238,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const Ref<Re
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((F.usage & PROPERTY_USAGE_STORAGE)) {
|
if ((F.usage & PROPERTY_USAGE_STORAGE) || missing_resource_properties.has(F.name)) {
|
||||||
Property p;
|
Property p;
|
||||||
p.name_idx = get_string_index(F.name);
|
p.name_idx = get_string_index(F.name);
|
||||||
|
|
||||||
|
@ -2253,7 +2253,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const Ref<Re
|
||||||
p.value = E->get(F.name);
|
p.value = E->get(F.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.pi.type == Variant::OBJECT && missing_resource_properties.has(F.name)) {
|
if (F.type == Variant::OBJECT && missing_resource_properties.has(F.name)) {
|
||||||
// Was this missing resource overridden? If so do not save the old value.
|
// Was this missing resource overridden? If so do not save the old value.
|
||||||
Ref<Resource> res = p.value;
|
Ref<Resource> res = p.value;
|
||||||
if (res.is_null()) {
|
if (res.is_null()) {
|
||||||
|
|
|
@ -786,7 +786,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Has
|
||||||
Dictionary missing_resource_properties = p_node->get_meta(META_MISSING_RESOURCES, Dictionary());
|
Dictionary missing_resource_properties = p_node->get_meta(META_MISSING_RESOURCES, Dictionary());
|
||||||
|
|
||||||
for (const PropertyInfo &E : plist) {
|
for (const PropertyInfo &E : plist) {
|
||||||
if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
|
if (!(E.usage & PROPERTY_USAGE_STORAGE) && !(missing_resource_properties.has(E.name))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -600,7 +600,7 @@ Error ResourceLoaderText::load() {
|
||||||
if (do_assign) {
|
if (do_assign) {
|
||||||
bool set_valid = true;
|
bool set_valid = true;
|
||||||
|
|
||||||
if (value.get_type() == Variant::OBJECT && missing_resource != nullptr) {
|
if (value.get_type() == Variant::OBJECT && missing_resource == nullptr && ResourceLoader::is_creating_missing_resources_if_class_unavailable_enabled()) {
|
||||||
// If the property being set is a missing resource (and the parent is not),
|
// If the property being set is a missing resource (and the parent is not),
|
||||||
// then setting it will most likely not work.
|
// then setting it will most likely not work.
|
||||||
// Instead, save it as metadata.
|
// Instead, save it as metadata.
|
||||||
|
@ -725,7 +725,9 @@ Error ResourceLoaderText::load() {
|
||||||
if (error) {
|
if (error) {
|
||||||
if (error != ERR_FILE_EOF) {
|
if (error != ERR_FILE_EOF) {
|
||||||
_printerr();
|
_printerr();
|
||||||
} else {
|
return error;
|
||||||
|
}
|
||||||
|
// EOF, Done parsing
|
||||||
error = OK;
|
error = OK;
|
||||||
if (cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
|
if (cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
|
||||||
if (!ResourceCache::has(res_path)) {
|
if (!ResourceCache::has(res_path)) {
|
||||||
|
@ -735,14 +737,13 @@ Error ResourceLoaderText::load() {
|
||||||
} else {
|
} else {
|
||||||
resource->set_path_cache(res_path);
|
resource->set_path_cache(res_path);
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!assign.is_empty()) {
|
if (!assign.is_empty()) {
|
||||||
bool set_valid = true;
|
bool set_valid = true;
|
||||||
|
|
||||||
if (value.get_type() == Variant::OBJECT && missing_resource != nullptr) {
|
if (value.get_type() == Variant::OBJECT && ResourceLoader::is_creating_missing_resources_if_class_unavailable_enabled() && missing_resource == nullptr) {
|
||||||
// If the property being set is a missing resource (and the parent is not),
|
// If the property being set is a missing resource (and the parent is not),
|
||||||
// then setting it will most likely not work.
|
// then setting it will most likely not work.
|
||||||
// Instead, save it as metadata.
|
// Instead, save it as metadata.
|
||||||
|
@ -1914,7 +1915,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const Ref<Reso
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PE->get().usage & PROPERTY_USAGE_STORAGE) {
|
if (PE->get().usage & PROPERTY_USAGE_STORAGE || missing_resource_properties.has(PE->get().name)) {
|
||||||
String name = PE->get().name;
|
String name = PE->get().name;
|
||||||
Variant value;
|
Variant value;
|
||||||
if (PE->get().usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT) {
|
if (PE->get().usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT) {
|
||||||
|
|
Loading…
Reference in New Issue