Add BBVariant

This commit is contained in:
Serhii Snitsaruk 2022-10-25 22:01:00 +02:00
parent 7ec38e0988
commit c73562a86e
5 changed files with 65 additions and 1 deletions

View File

@ -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();

View File

@ -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; }

28
bb_param/bb_variant.cpp Normal file
View File

@ -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;
}

26
bb_param/bb_variant.h Normal file
View File

@ -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

View File

@ -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<BBStringArray>();
ClassDB::register_class<BBVector2Array>();
ClassDB::register_class<BBVector3Array>();
ClassDB::register_class<BBVariant>();
_limbo_utility = memnew(LimboUtility);
ClassDB::register_class<LimboUtility>();