From b662c10513b746f98c6de7e61936a5e18cbdd77d Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Mon, 7 Aug 2023 14:29:58 +0200 Subject: [PATCH] Fix BBVariant inspector oddities --- blackboard/bb_param/bb_param.cpp | 23 +++++++++++++++++------ blackboard/bb_param/bb_param.h | 5 +++++ blackboard/bb_param/bb_variant.cpp | 16 ++++++++++++---- blackboard/bb_param/bb_variant.h | 4 ++-- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/blackboard/bb_param/bb_param.cpp b/blackboard/bb_param/bb_param.cpp index 3e65ee3..2ed1929 100644 --- a/blackboard/bb_param/bb_param.cpp +++ b/blackboard/bb_param/bb_param.cpp @@ -29,10 +29,6 @@ void BBParam::set_value_source(ValueSource p_value) { } Variant BBParam::get_saved_value() { - if (saved_value.get_type() != get_type()) { - Callable::CallError err; - Variant::construct(get_type(), saved_value, nullptr, 0, err); - } return saved_value; } @@ -50,7 +46,21 @@ void BBParam::set_variable(const String &p_value) { String BBParam::to_string() { if (value_source == SAVED_VALUE) { - return String(saved_value); + String s = saved_value.stringify(); + switch (get_type()) { + case Variant::STRING: { + s = s.c_escape().quote(); + } break; + case Variant::STRING_NAME: { + s = "&" + s.c_escape().quote(); + } break; + case Variant::NODE_PATH: { + s = "^" + s.c_escape().quote(); + } break; + default: { + } break; + } + return s; } else { return LimboUtility::get_singleton()->decorate_var(variable); } @@ -95,5 +105,6 @@ void BBParam::_bind_methods() { BBParam::BBParam() { value_source = SAVED_VALUE; variable = ""; - saved_value = Variant(); + + _assign_default_value(); } diff --git a/blackboard/bb_param/bb_param.h b/blackboard/bb_param/bb_param.h index 343eb20..4a74e2d 100644 --- a/blackboard/bb_param/bb_param.h +++ b/blackboard/bb_param/bb_param.h @@ -43,6 +43,11 @@ protected: virtual Variant::Type get_type() const { return Variant::NIL; } + _FORCE_INLINE_ void _assign_default_value() { + Callable::CallError err; + Variant::construct(get_type(), saved_value, nullptr, 0, err); + } + void _get_property_list(List *p_list) const; public: diff --git a/blackboard/bb_param/bb_variant.cpp b/blackboard/bb_param/bb_variant.cpp index d27e727..2e92dc6 100644 --- a/blackboard/bb_param/bb_variant.cpp +++ b/blackboard/bb_param/bb_variant.cpp @@ -14,9 +14,18 @@ #include "core/variant/variant.h" void BBVariant::set_type(Variant::Type p_type) { - type = p_type; - notify_property_list_changed(); - emit_changed(); + if (type != p_type) { + type = p_type; + if (get_saved_value().get_type() != p_type) { + _assign_default_value(); + } + emit_changed(); + notify_property_list_changed(); + } +} + +Variant::Type BBVariant::get_type() const { + return type; } void BBVariant::_bind_methods() { @@ -33,5 +42,4 @@ void BBVariant::_bind_methods() { } BBVariant::BBVariant() { - type = Variant::NIL; } diff --git a/blackboard/bb_param/bb_variant.h b/blackboard/bb_param/bb_variant.h index f806233..d8664bd 100644 --- a/blackboard/bb_param/bb_variant.h +++ b/blackboard/bb_param/bb_variant.h @@ -20,12 +20,12 @@ class BBVariant : public BBParam { GDCLASS(BBVariant, BBParam); private: - Variant::Type type; + Variant::Type type = Variant::NIL; protected: static void _bind_methods(); - virtual Variant::Type get_type() const override { return type; } + virtual Variant::Type get_type() const override; void set_type(Variant::Type p_type); public: