From cb3aa0b1b08b90ed35b5628bd1847c5bd12a8c78 Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 11 Aug 2021 20:33:41 +0200 Subject: [PATCH] Now the editor can properly handle without a restart when an already existing PropData gets re-serialized with the scene conversion tool. --- editor/prop_editor_plugin.cpp | 15 ++++++++++----- props/prop_data.cpp | 16 ++++++++++++++++ props/prop_data.h | 3 ++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/editor/prop_editor_plugin.cpp b/editor/prop_editor_plugin.cpp index 7f5871b..4254558 100644 --- a/editor/prop_editor_plugin.cpp +++ b/editor/prop_editor_plugin.cpp @@ -65,15 +65,20 @@ void PropEditorPlugin::convert_scene(Node *root, const String &path) { ResourceLoader l; if (l.exists(path)) { - Ref res = l.load(path); + Ref 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(); + } else { + ResourceSaver s; + s.save(path, data); } - - ResourceSaver s; - s.save(path, data); } void PropEditorPlugin::_quick_convert_button_pressed() { diff --git a/props/prop_data.cpp b/props/prop_data.cpp index b9ccde7..151efa3 100644 --- a/props/prop_data.cpp +++ b/props/prop_data.cpp @@ -112,6 +112,20 @@ void PropData::add_textures_into(Ref texture_packer) { } #endif +void PropData::copy_from(const Ref &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() { _id = 0; _snap_to_mesh = false; @@ -144,4 +158,6 @@ void PropData::_bind_methods() { #if TEXTURE_PACKER_PRESENT ClassDB::bind_method(D_METHOD("add_textures_into", "texture_packer"), &PropData::add_textures_into); #endif + + ClassDB::bind_method(D_METHOD("copy_from", "prop_data"), &PropData::copy_from); } diff --git a/props/prop_data.h b/props/prop_data.h index 24479d2..b0dd9bb 100644 --- a/props/prop_data.h +++ b/props/prop_data.h @@ -42,7 +42,6 @@ SOFTWARE. #include "prop_data_entry.h" - #if TEXTURE_PACKER_PRESENT #include "../../texture_packer/texture_packer.h" #endif @@ -74,6 +73,8 @@ public: void add_textures_into(Ref texture_packer); #endif + void copy_from(const Ref &prop_data); + PropData(); ~PropData();