diff --git a/bb_param/bb_param.cpp b/bb_param/bb_param.cpp index 53cf273..1fbc32e 100644 --- a/bb_param/bb_param.cpp +++ b/bb_param/bb_param.cpp @@ -15,6 +15,14 @@ void BBParam::set_value_source(ValueSource p_value) { emit_changed(); } +Variant BBParam::get_saved_value() { + if (saved_value.get_type() != get_type()) { + Variant::CallError err; + saved_value = Variant::construct(get_type(), nullptr, 0, err); + } + return saved_value; +} + void BBParam::set_saved_value(Variant p_value) { saved_value = p_value; _update_name(); diff --git a/bb_param/bb_param.h b/bb_param/bb_param.h index 16bd16a..cecd96b 100644 --- a/bb_param/bb_param.h +++ b/bb_param/bb_param.h @@ -40,7 +40,7 @@ public: ValueSource get_value_source() const { return value_source; } void set_saved_value(Variant p_value); - Variant get_saved_value() const { return saved_value; } + Variant get_saved_value(); void set_variable(const String &p_value); String get_variable() const { return variable; } diff --git a/bb_param/bb_variant.cpp b/bb_param/bb_variant.cpp new file mode 100644 index 0000000..e9ca51d --- /dev/null +++ b/bb_param/bb_variant.cpp @@ -0,0 +1,28 @@ +/* bb_variant.cpp */ + +#include "bb_variant.h" +#include "core/object.h" +#include "core/variant.h" + +void BBVariant::set_type(Variant::Type p_type) { + type = p_type; + property_list_changed_notify(); + emit_changed(); +} + +void BBVariant::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_type", "p_type"), &BBVariant::set_type); + + String vtypes; + for (int i = 0; i < Variant::VARIANT_MAX; i++) { + if (i > 0) { + vtypes += ","; + } + vtypes += Variant::get_type_name(Variant::Type(i)); + } + ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, vtypes), "set_type", "get_type"); +} + +BBVariant::BBVariant() { + type = Variant::NIL; +} diff --git a/bb_param/bb_variant.h b/bb_param/bb_variant.h new file mode 100644 index 0000000..45fe747 --- /dev/null +++ b/bb_param/bb_variant.h @@ -0,0 +1,26 @@ +/* bb_variant.h */ + +#ifndef BB_VARIANT_H +#define BB_VARIANT_H + +#include "bb_param.h" +#include "core/object.h" +#include "core/variant.h" + +class BBVariant : public BBParam { + GDCLASS(BBVariant, BBParam); + +private: + Variant::Type type; + +protected: + static void _bind_methods(); + + virtual Variant::Type get_type() const { return type; } + void set_type(Variant::Type p_type); + +public: + BBVariant(); +}; + +#endif // BB_VARIANT \ No newline at end of file diff --git a/register_types.cpp b/register_types.cpp index b206474..498c021 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -25,6 +25,7 @@ #include "bb_param/bb_string_array.h" #include "bb_param/bb_transform.h" #include "bb_param/bb_transform2d.h" +#include "bb_param/bb_variant.h" #include "bb_param/bb_vector2.h" #include "bb_param/bb_vector2_array.h" #include "bb_param/bb_vector3.h" @@ -147,6 +148,7 @@ void register_limboai_types() { ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); _limbo_utility = memnew(LimboUtility); ClassDB::register_class();