Improve variable synchronization between base and derived blackboard plans
When variable is altered in the base plan, values should properly sync to the derived plans if those vars are not altered in the derived plan. Editor QoL improvement.
This commit is contained in:
parent
98a685b592
commit
95c2496adf
|
@ -22,6 +22,7 @@ void BBVariable::unref() {
|
||||||
|
|
||||||
void BBVariable::set_value(const Variant &p_value) {
|
void BBVariable::set_value(const Variant &p_value) {
|
||||||
data->value = p_value; // Setting value even when bound as a fallback in case the binding fails.
|
data->value = p_value; // Setting value even when bound as a fallback in case the binding fails.
|
||||||
|
data->value_changed = true;
|
||||||
|
|
||||||
if (is_bound()) {
|
if (is_bound()) {
|
||||||
Object *obj = ObjectDB::get_instance(ObjectID(data->bound_object));
|
Object *obj = ObjectDB::get_instance(ObjectID(data->bound_object));
|
||||||
|
@ -83,6 +84,9 @@ BBVariable BBVariable::duplicate() const {
|
||||||
var.data->hint_string = data->hint_string;
|
var.data->hint_string = data->hint_string;
|
||||||
var.data->type = data->type;
|
var.data->type = data->type;
|
||||||
var.data->value = data->value;
|
var.data->value = data->value;
|
||||||
|
var.data->binding_path = data->binding_path;
|
||||||
|
var.data->bound_object = data->bound_object;
|
||||||
|
var.data->bound_property = data->bound_property;
|
||||||
return var;
|
return var;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,11 +139,11 @@ bool BBVariable::operator==(const BBVariable &p_var) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->value != p_var.data->value) {
|
if (data->hint_string != p_var.data->hint_string) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->hint_string != p_var.data->hint_string) {
|
if (get_value() != p_var.get_value()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,9 @@ using namespace godot;
|
||||||
class BBVariable {
|
class BBVariable {
|
||||||
private:
|
private:
|
||||||
struct Data {
|
struct Data {
|
||||||
|
// Is used to decide if the value needs to be synced in a derived plan.
|
||||||
|
bool value_changed = false;
|
||||||
|
|
||||||
SafeRefCount refcount;
|
SafeRefCount refcount;
|
||||||
Variant value;
|
Variant value;
|
||||||
Variant::Type type = Variant::NIL;
|
Variant::Type type = Variant::NIL;
|
||||||
|
@ -53,6 +56,9 @@ public:
|
||||||
|
|
||||||
BBVariable duplicate() const;
|
BBVariable duplicate() const;
|
||||||
|
|
||||||
|
_FORCE_INLINE_ bool is_value_changed() const { return data->value_changed; }
|
||||||
|
_FORCE_INLINE_ void reset_value_changed() { data->value_changed = false; }
|
||||||
|
|
||||||
bool is_same_prop_info(const BBVariable &p_other) const;
|
bool is_same_prop_info(const BBVariable &p_other) const;
|
||||||
void copy_prop_info(const BBVariable &p_other);
|
void copy_prop_info(const BBVariable &p_other);
|
||||||
|
|
||||||
|
@ -62,7 +68,7 @@ public:
|
||||||
bool has_binding() { return data->binding_path.is_empty(); }
|
bool has_binding() { return data->binding_path.is_empty(); }
|
||||||
|
|
||||||
// * Runtime binding methods
|
// * Runtime binding methods
|
||||||
bool is_bound() const { return data->bound_object != 0; }
|
_FORCE_INLINE_ bool is_bound() const { return data->bound_object != 0; }
|
||||||
void bind(Object *p_object, const StringName &p_property);
|
void bind(Object *p_object, const StringName &p_property);
|
||||||
void unbind();
|
void unbind();
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,10 @@ bool BlackboardPlan::_set(const StringName &p_name, const Variant &p_value) {
|
||||||
// * Editor
|
// * Editor
|
||||||
if (var_map.has(prop_name)) {
|
if (var_map.has(prop_name)) {
|
||||||
var_map[prop_name].set_value(p_value);
|
var_map[prop_name].set_value(p_value);
|
||||||
|
if (base.is_valid() && p_value == base->get_var(prop_name).get_value()) {
|
||||||
|
// When user pressed reset property button in inspector...
|
||||||
|
var_map[prop_name].reset_value_changed();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,8 +238,11 @@ void BlackboardPlan::sync_with_base_plan() {
|
||||||
var.copy_prop_info(base_var);
|
var.copy_prop_info(base_var);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
if (var.get_value().get_type() != base_var.get_type()) {
|
if ((!var.is_value_changed() && var.get_value() != base_var.get_value()) ||
|
||||||
|
(var.get_value().get_type() != base_var.get_type())) {
|
||||||
|
// Reset value according to base plan.
|
||||||
var.set_value(base_var.get_value());
|
var.set_value(base_var.get_value());
|
||||||
|
var.reset_value_changed();
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue