summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-01-23 21:42:15 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-01-23 21:42:15 -0300
commita74138a0dc5862d2c26eb78a141ba3c3f9d01c6d (patch)
treeb813df7f8b217100fcf71dcf06eec58fe2b7354e /scene/resources
parent6c27df8df609337867c108c5adb66174393e190b (diff)
-Some changes to how scenes and scripts are overriden in scene instance and inheritance
-Fixes #3127 and also properly fixes #2958
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/packed_scene.cpp36
1 files changed, 31 insertions, 5 deletions
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index 57d2a8d890..43196a43d4 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -33,7 +33,7 @@
#include "scene/gui/control.h"
#include "scene/2d/node_2d.h"
#include "scene/main/instance_placeholder.h"
-
+#include "core/core_string_names.h"
#define PACK_VERSION 2
bool SceneState::can_instance() const {
@@ -99,6 +99,7 @@ Node *SceneState::instance(bool p_gen_edit_state) const {
Node *node=NULL;
+
if (i==0 && base_scene_idx>=0) {
//scene inheritance on root node
//print_line("scene inherit");
@@ -193,7 +194,26 @@ Node *SceneState::instance(bool p_gen_edit_state) const {
ERR_FAIL_INDEX_V( nprops[j].name, sname_count, NULL );
ERR_FAIL_INDEX_V( nprops[j].value, prop_count, NULL );
- node->set(snames[ nprops[j].name ],props[ nprops[j].value ],&valid);
+ if (snames[ nprops[j].name ]==CoreStringNames::get_singleton()->_script) {
+ //work around to avoid old script variables from disappearing, should be the proper fix to:
+ //https://github.com/godotengine/godot/issues/2958
+
+ //store old state
+ List<Pair<StringName,Variant> > old_state;
+ if (node->get_script_instance()) {
+ node->get_script_instance()->get_property_state(old_state);
+ }
+
+ node->set(snames[ nprops[j].name ],props[ nprops[j].value ],&valid);
+
+ //restore old state for new script, if exists
+ for (List<Pair<StringName,Variant> >::Element *E=old_state.front();E;E=E->next()) {
+ node->set(E->get().first,E->get().second);
+ }
+ } else {
+
+ node->set(snames[ nprops[j].name ],props[ nprops[j].value ],&valid);
+ }
}
}
@@ -460,6 +480,7 @@ Error SceneState::_parse_node(Node *p_owner,Node *p_node,int p_parent_idx, Map<S
List<PropertyInfo> plist;
p_node->get_property_list(&plist);
+ bool saved_script=false;
for (List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {
@@ -508,8 +529,10 @@ Error SceneState::_parse_node(Node *p_owner,Node *p_node,int p_parent_idx, Map<S
break;
}
}
-
- if (exists && p_node->get_script_instance()) {
+#if 0
+// this workaround ended up causing problems:
+https://github.com/godotengine/godot/issues/3127
+ if (saved_script && exists && p_node->get_script_instance()) {
//if this is an overriden value by another script, save it anyway
//as the script change will erase it
//https://github.com/godotengine/godot/issues/2958
@@ -522,7 +545,7 @@ Error SceneState::_parse_node(Node *p_owner,Node *p_node,int p_parent_idx, Map<S
}
}
-
+#endif
if (exists && bool(Variant::evaluate(Variant::OP_EQUAL,value,original))) {
//exists and did not change
continue;
@@ -543,6 +566,9 @@ Error SceneState::_parse_node(Node *p_owner,Node *p_node,int p_parent_idx, Map<S
}
}
+ if (name=="script/script")
+ saved_script=true;
+
NodeData::Property prop;
prop.name=_nm_get_string( name,name_map);
prop.value=_vm_get_variant( value, variant_map);