Now the editor can properly handle without a restart when an already existing PropData gets re-serialized with the scene conversion tool.

This commit is contained in:
Relintai 2021-08-11 20:33:41 +02:00
parent 1d4e05b5a1
commit cb3aa0b1b0
3 changed files with 28 additions and 6 deletions

View File

@ -65,15 +65,20 @@ void PropEditorPlugin::convert_scene(Node *root, const String &path) {
ResourceLoader l; ResourceLoader l;
if (l.exists(path)) { if (l.exists(path)) {
Ref<Resource> res = l.load(path); Ref<PropData> res = l.load(path, "PropData");
ERR_FAIL_COND((res.is_valid() && res->get_class() != "PropData")); ERR_FAIL_COND(!res.is_valid());
res->copy_from(data);
ResourceSaver s;
s.save(path, res);
res.unref(); res.unref();
} else {
ResourceSaver s;
s.save(path, data);
} }
ResourceSaver s;
s.save(path, data);
} }
void PropEditorPlugin::_quick_convert_button_pressed() { void PropEditorPlugin::_quick_convert_button_pressed() {

View File

@ -112,6 +112,20 @@ void PropData::add_textures_into(Ref<TexturePacker> texture_packer) {
} }
#endif #endif
void PropData::copy_from(const Ref<PropData> &prop_data) {
_id = prop_data->_id;
_snap_to_mesh = prop_data->_snap_to_mesh;
_snap_axis = prop_data->_snap_axis;
_props.clear();
for (int i = 0; i < prop_data->_props.size(); ++i) {
_props.push_back(prop_data->_props[i]);
}
emit_changed();
}
PropData::PropData() { PropData::PropData() {
_id = 0; _id = 0;
_snap_to_mesh = false; _snap_to_mesh = false;
@ -144,4 +158,6 @@ void PropData::_bind_methods() {
#if TEXTURE_PACKER_PRESENT #if TEXTURE_PACKER_PRESENT
ClassDB::bind_method(D_METHOD("add_textures_into", "texture_packer"), &PropData::add_textures_into); ClassDB::bind_method(D_METHOD("add_textures_into", "texture_packer"), &PropData::add_textures_into);
#endif #endif
ClassDB::bind_method(D_METHOD("copy_from", "prop_data"), &PropData::copy_from);
} }

View File

@ -42,7 +42,6 @@ SOFTWARE.
#include "prop_data_entry.h" #include "prop_data_entry.h"
#if TEXTURE_PACKER_PRESENT #if TEXTURE_PACKER_PRESENT
#include "../../texture_packer/texture_packer.h" #include "../../texture_packer/texture_packer.h"
#endif #endif
@ -74,6 +73,8 @@ public:
void add_textures_into(Ref<TexturePacker> texture_packer); void add_textures_into(Ref<TexturePacker> texture_packer);
#endif #endif
void copy_from(const Ref<PropData> &prop_data);
PropData(); PropData();
~PropData(); ~PropData();