diff --git a/SCsub b/SCsub index 8651eaf..66a7e5c 100644 --- a/SCsub +++ b/SCsub @@ -9,3 +9,4 @@ env.add_source_files(env.modules_sources, "bt/actions/*.cpp") env.add_source_files(env.modules_sources, "bt/decorators/*.cpp") env.add_source_files(env.modules_sources, "bt/conditions/*.cpp") env.add_source_files(env.modules_sources, "editor/*.cpp") +env.add_source_files(env.modules_sources, "bb_param/*.cpp") diff --git a/bb_param/bb_aabb.h b/bb_param/bb_aabb.h new file mode 100644 index 0000000..4e8dbf4 --- /dev/null +++ b/bb_param/bb_aabb.h @@ -0,0 +1,16 @@ +/* bb_aabb.h */ + +#ifndef BB_AABB_H +#define BB_AABB_H + +#include "bb_param.h" +#include "core/object.h" + +class BBAabb : public BBParam { + GDCLASS(BBAabb, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::AABB; } +}; + +#endif // BB_AABB_H \ No newline at end of file diff --git a/bb_param/bb_array.h b/bb_param/bb_array.h new file mode 100644 index 0000000..61acb88 --- /dev/null +++ b/bb_param/bb_array.h @@ -0,0 +1,16 @@ +/* bb_array.h */ + +#ifndef BB_ARRAY_H +#define BB_ARRAY_H + +#include "bb_param.h" +#include "core/object.h" + +class BBArray : public BBParam { + GDCLASS(BBArray, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::ARRAY; } +}; + +#endif // BB_ARRAY_H \ No newline at end of file diff --git a/bb_param/bb_basis.h b/bb_param/bb_basis.h new file mode 100644 index 0000000..235be0e --- /dev/null +++ b/bb_param/bb_basis.h @@ -0,0 +1,16 @@ +/* bb_basis.h */ + +#ifndef BB_BASIS_H +#define BB_BASIS_H + +#include "bb_param.h" +#include "core/object.h" + +class BBBasis : public BBParam { + GDCLASS(BBBasis, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::BASIS; } +}; + +#endif // BB_BASIS_H \ No newline at end of file diff --git a/bb_param/bb_bool.h b/bb_param/bb_bool.h new file mode 100644 index 0000000..46e45c9 --- /dev/null +++ b/bb_param/bb_bool.h @@ -0,0 +1,16 @@ +/* bb_bool.h */ + +#ifndef BB_BOOL_H +#define BB_BOOL_H + +#include "bb_param.h" +#include "core/object.h" + +class BBBool : public BBParam { + GDCLASS(BBBool, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::BOOL; } +}; + +#endif // BB_BOOL_H \ No newline at end of file diff --git a/bb_param/bb_byte_array.h b/bb_param/bb_byte_array.h new file mode 100644 index 0000000..2d1d104 --- /dev/null +++ b/bb_param/bb_byte_array.h @@ -0,0 +1,16 @@ +/* bb_byte_array.h */ + +#ifndef BB_BYTE_ARRAY_H +#define BB_BYTE_ARRAY_H + +#include "bb_param.h" +#include "core/object.h" + +class BBByteArray : public BBParam { + GDCLASS(BBByteArray, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::POOL_BYTE_ARRAY; } +}; + +#endif // BB_BYTE_ARRAY_H \ No newline at end of file diff --git a/bb_param/bb_color.h b/bb_param/bb_color.h new file mode 100644 index 0000000..2d4a3cf --- /dev/null +++ b/bb_param/bb_color.h @@ -0,0 +1,16 @@ +/* bb_color.h */ + +#ifndef BB_COLOR_H +#define BB_COLOR_H + +#include "bb_param.h" +#include "core/object.h" + +class BBColor : public BBParam { + GDCLASS(BBColor, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::COLOR; } +}; + +#endif // BB_COLOR_H \ No newline at end of file diff --git a/bb_param/bb_color_array.h b/bb_param/bb_color_array.h new file mode 100644 index 0000000..47c9b78 --- /dev/null +++ b/bb_param/bb_color_array.h @@ -0,0 +1,16 @@ +/* bb_color_array.h */ + +#ifndef BB_COLOR_ARRAY_H +#define BB_COLOR_ARRAY_H + +#include "bb_param.h" +#include "core/object.h" + +class BBColorArray : public BBParam { + GDCLASS(BBColorArray, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::POOL_COLOR_ARRAY; } +}; + +#endif // BB_COLOR_ARRAY_H \ No newline at end of file diff --git a/bb_param/bb_dictionary.h b/bb_param/bb_dictionary.h new file mode 100644 index 0000000..12b9939 --- /dev/null +++ b/bb_param/bb_dictionary.h @@ -0,0 +1,16 @@ +/* bb_dictionary.h */ + +#ifndef BB_DICTIONARY_H +#define BB_DICTIONARY_H + +#include "bb_param.h" +#include "core/object.h" + +class BBDictionary : public BBParam { + GDCLASS(BBDictionary, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::DICTIONARY; } +}; + +#endif // BB_DICTIONARY_H \ No newline at end of file diff --git a/bb_param/bb_float.h b/bb_param/bb_float.h new file mode 100644 index 0000000..28f6842 --- /dev/null +++ b/bb_param/bb_float.h @@ -0,0 +1,16 @@ +/* bb_float.h */ + +#ifndef BB_FLOAT_H +#define BB_FLOAT_H + +#include "bb_param.h" +#include "core/object.h" + +class BBFloat : public BBParam { + GDCLASS(BBFloat, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::REAL; } +}; + +#endif // BB_FLOAT_H \ No newline at end of file diff --git a/bb_param/bb_int.h b/bb_param/bb_int.h new file mode 100644 index 0000000..8e0529e --- /dev/null +++ b/bb_param/bb_int.h @@ -0,0 +1,16 @@ +/* bb_int.h */ + +#ifndef BB_INT_H +#define BB_INT_H + +#include "bb_param.h" +#include "core/object.h" + +class BBInt : public BBParam { + GDCLASS(BBInt, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::INT; } +}; + +#endif // BB_INT_H \ No newline at end of file diff --git a/bb_param/bb_int_array.h b/bb_param/bb_int_array.h new file mode 100644 index 0000000..ccb41c0 --- /dev/null +++ b/bb_param/bb_int_array.h @@ -0,0 +1,16 @@ +/* bb_int_array.h */ + +#ifndef BB_INT_ARRAY_H +#define BB_INT_ARRAY_H + +#include "bb_param.h" +#include "core/object.h" + +class BBIntArray : public BBParam { + GDCLASS(BBIntArray, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::POOL_INT_ARRAY; } +}; + +#endif // BB_INT_ARRAY_H \ No newline at end of file diff --git a/bb_param/bb_node.cpp b/bb_param/bb_node.cpp new file mode 100644 index 0000000..113e2f9 --- /dev/null +++ b/bb_param/bb_node.cpp @@ -0,0 +1,32 @@ +/* bb_node.cpp */ + +#include "bb_node.h" +#include "core/error_macros.h" +#include "core/variant.h" +#include "scene/main/node.h" + +Variant BBNode::get_value(Object *p_agent, const Ref &p_blackboard, const Variant &p_default) { + ERR_FAIL_COND_V(p_agent == nullptr, Variant()); + ERR_FAIL_COND_V(!p_blackboard.is_valid(), Variant()); + + Variant val; + if (get_value_source() == SAVED_VALUE) { + val = get_saved_value(); + } else { + val = p_blackboard->get_var(get_variable(), p_default); + } + + if (val.get_type() == Variant::NODE_PATH) { + Node *agent = Object::cast_to(p_agent); + ERR_FAIL_COND_V_MSG(agent == nullptr, Variant(), "BBNode: p_agent must be a Node."); + return agent->get_node(val); + } else { + Node *node = val; + if (unlikely(node == nullptr && val.get_type() != Variant::NIL)) { + WARN_PRINT("BBNode: Unexpected variant type of a blackboard variable."); + return p_default; + } else { + return node; + } + } +} diff --git a/bb_param/bb_node.h b/bb_param/bb_node.h new file mode 100644 index 0000000..cf8ae19 --- /dev/null +++ b/bb_param/bb_node.h @@ -0,0 +1,19 @@ +/* bb_node.h */ + +#ifndef BB_NODE_H +#define BB_NODE_H + +#include "bb_param.h" +#include "core/object.h" + +class BBNode : public BBParam { + GDCLASS(BBNode, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::NODE_PATH; } + +public: + virtual Variant get_value(Object *p_agent, const Ref &p_blackboard, const Variant &p_default = Variant()); +}; + +#endif // BB_NODE_H \ No newline at end of file diff --git a/bb_param/bb_param.cpp b/bb_param/bb_param.cpp new file mode 100644 index 0000000..a2f7a23 --- /dev/null +++ b/bb_param/bb_param.cpp @@ -0,0 +1,51 @@ +/* bb_param.cpp */ + +#include "bb_param.h" +#include "core/class_db.h" +#include "core/error_macros.h" +#include "core/object.h" +#include "core/variant.h" + +VARIANT_ENUM_CAST(BBParam::ValueSource); + +Variant BBParam::get_value(Object *p_agent, const Ref &p_blackboard, const Variant &p_default) { + ERR_FAIL_COND_V(p_blackboard.is_valid(), p_default); + + if (value_source == SAVED_VALUE) { + return saved_value; + } else { + return p_blackboard->get_var(variable, p_default); + } +} + +void BBParam::_get_property_list(List *p_list) const { + if (value_source == ValueSource::SAVED_VALUE) { + p_list->push_back(PropertyInfo(get_type(), "saved_value")); + } else { + p_list->push_back(PropertyInfo(Variant::STRING, "variable")); + } +} + +void BBParam::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_value_source", "p_value_source"), &BBParam::set_value_source); + ClassDB::bind_method(D_METHOD("get_value_source"), &BBParam::get_value_source); + ClassDB::bind_method(D_METHOD("set_saved_value", "p_value"), &BBParam::set_saved_value); + ClassDB::bind_method(D_METHOD("get_saved_value"), &BBParam::get_saved_value); + ClassDB::bind_method(D_METHOD("set_variable", "p_variable_name"), &BBParam::set_variable); + ClassDB::bind_method(D_METHOD("get_variable"), &BBParam::get_variable); + ClassDB::bind_method(D_METHOD("get_type"), &BBParam::get_type); + ClassDB::bind_method(D_METHOD("get_value"), &BBParam::get_value); + + ADD_PROPERTY(PropertyInfo(Variant::INT, "value_source", PROPERTY_HINT_ENUM, "Saved Value, Blackboard Var"), "set_value_source", "get_value_source"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "variable", PROPERTY_HINT_NONE, "", 0), "set_variable", "get_variable"); + ADD_PROPERTY(PropertyInfo(Variant::NIL, "saved_value", PROPERTY_HINT_NONE, "", 0), "set_saved_value", "get_saved_value"); + + BIND_ENUM_CONSTANT(SAVED_VALUE); + BIND_ENUM_CONSTANT(BLACKBOARD_VAR); +} + +BBParam::BBParam() { + value_source = SAVED_VALUE; + variable = ""; + saved_value = Variant(); +} diff --git a/bb_param/bb_param.h b/bb_param/bb_param.h new file mode 100644 index 0000000..cbe2241 --- /dev/null +++ b/bb_param/bb_param.h @@ -0,0 +1,57 @@ +/* bb_param.h */ + +#ifndef BB_PARAM_H +#define BB_PARAM_H + +#include "core/object.h" +#include "core/resource.h" +#include "core/variant.h" +#include "modules/limboai/blackboard.h" + +class BBParam : public Resource { + GDCLASS(BBParam, Resource); + +public: + enum ValueSource : unsigned int { + SAVED_VALUE, + BLACKBOARD_VAR + }; + +private: + ValueSource value_source; + Variant saved_value; + String variable; + +protected: + static void _bind_methods(); + + virtual Variant::Type get_type() const { return Variant::NIL; } + + void _get_property_list(List *p_list) const; + +public: + void set_value_source(ValueSource p_value) { + value_source = p_value; + property_list_changed_notify(); + emit_changed(); + } + ValueSource get_value_source() const { return value_source; } + + void set_saved_value(Variant p_value) { + saved_value = p_value; + emit_changed(); + } + Variant get_saved_value() const { return saved_value; } + + void set_variable(const String &p_value) { + variable = p_value; + emit_changed(); + } + String get_variable() const { return variable; } + + virtual Variant get_value(Object *p_agent, const Ref &p_blackboard, const Variant &p_default = Variant()); + + BBParam(); +}; + +#endif // BB_PARAM_H \ No newline at end of file diff --git a/bb_param/bb_plane.h b/bb_param/bb_plane.h new file mode 100644 index 0000000..dd8d9cd --- /dev/null +++ b/bb_param/bb_plane.h @@ -0,0 +1,16 @@ +/* bb_plane.h */ + +#ifndef BB_PLANE_H +#define BB_PLANE_H + +#include "bb_param.h" +#include "core/object.h" + +class BBPlane : public BBParam { + GDCLASS(BBPlane, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::PLANE; } +}; + +#endif // BB_PLANE_H \ No newline at end of file diff --git a/bb_param/bb_quat.h b/bb_param/bb_quat.h new file mode 100644 index 0000000..6d18164 --- /dev/null +++ b/bb_param/bb_quat.h @@ -0,0 +1,16 @@ +/* bb_quat.h */ + +#ifndef BB_QUAT_H +#define BB_QUAT_H + +#include "bb_param.h" +#include "core/object.h" + +class BBQuat : public BBParam { + GDCLASS(BBQuat, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::QUAT; } +}; + +#endif // BB_QUAT_H \ No newline at end of file diff --git a/bb_param/bb_real_array.h b/bb_param/bb_real_array.h new file mode 100644 index 0000000..81147a6 --- /dev/null +++ b/bb_param/bb_real_array.h @@ -0,0 +1,16 @@ +/* bb_real_array.h */ + +#ifndef BB_REAL_ARRAY_H +#define BB_REAL_ARRAY_H + +#include "bb_param.h" +#include "core/object.h" + +class BBRealArray : public BBParam { + GDCLASS(BBRealArray, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::POOL_REAL_ARRAY; } +}; + +#endif // BB_REAL_ARRAY_H \ No newline at end of file diff --git a/bb_param/bb_rect2.h b/bb_param/bb_rect2.h new file mode 100644 index 0000000..4fa8d40 --- /dev/null +++ b/bb_param/bb_rect2.h @@ -0,0 +1,16 @@ +/* bb_rect2.h */ + +#ifndef BB_RECT2_H +#define BB_RECT2_H + +#include "bb_param.h" +#include "core/object.h" + +class BBRect2 : public BBParam { + GDCLASS(BBRect2, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::RECT2; } +}; + +#endif // BB_RECT2_H \ No newline at end of file diff --git a/bb_param/bb_string.h b/bb_param/bb_string.h new file mode 100644 index 0000000..249fe83 --- /dev/null +++ b/bb_param/bb_string.h @@ -0,0 +1,16 @@ +/* bb_string.h */ + +#ifndef BB_STRING_H +#define BB_STRING_H + +#include "bb_param.h" +#include "core/object.h" + +class BBString : public BBParam { + GDCLASS(BBString, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::STRING; } +}; + +#endif // BB_STRING_H \ No newline at end of file diff --git a/bb_param/bb_string_array.h b/bb_param/bb_string_array.h new file mode 100644 index 0000000..985ddff --- /dev/null +++ b/bb_param/bb_string_array.h @@ -0,0 +1,16 @@ +/* bb_string_array.h */ + +#ifndef BB_STRING_ARRAY_H +#define BB_STRING_ARRAY_H + +#include "bb_param.h" +#include "core/object.h" + +class BBStringArray : public BBParam { + GDCLASS(BBStringArray, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::POOL_STRING_ARRAY; } +}; + +#endif // BB_STRING_ARRAY_H \ No newline at end of file diff --git a/bb_param/bb_transform.h b/bb_param/bb_transform.h new file mode 100644 index 0000000..4080277 --- /dev/null +++ b/bb_param/bb_transform.h @@ -0,0 +1,16 @@ +/* bb_transform.h */ + +#ifndef BB_TRANSFORM_H +#define BB_TRANSFORM_H + +#include "bb_param.h" +#include "core/object.h" + +class BBTransform : public BBParam { + GDCLASS(BBTransform, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::TRANSFORM; } +}; + +#endif // BB_TRANSFORM_H \ No newline at end of file diff --git a/bb_param/bb_transform2d.h b/bb_param/bb_transform2d.h new file mode 100644 index 0000000..fcfa3b7 --- /dev/null +++ b/bb_param/bb_transform2d.h @@ -0,0 +1,16 @@ +/* bb_transform2d.h */ + +#ifndef BB_TRANSFORM2D_H +#define BB_TRANSFORM2D_H + +#include "bb_param.h" +#include "core/object.h" + +class BBTransform2D : public BBParam { + GDCLASS(BBTransform2D, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::TRANSFORM2D; } +}; + +#endif // BB_TRANSFORM2D_H \ No newline at end of file diff --git a/bb_param/bb_vector2.h b/bb_param/bb_vector2.h new file mode 100644 index 0000000..cf16a5d --- /dev/null +++ b/bb_param/bb_vector2.h @@ -0,0 +1,16 @@ +/* bb_vector2.h */ + +#ifndef BB_VECTOR2_H +#define BB_VECTOR2_H + +#include "bb_param.h" +#include "core/object.h" + +class BBVector2 : public BBParam { + GDCLASS(BBVector2, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::VECTOR2; } +}; + +#endif // BB_VECTOR2_H \ No newline at end of file diff --git a/bb_param/bb_vector2_array.h b/bb_param/bb_vector2_array.h new file mode 100644 index 0000000..b8e8f5e --- /dev/null +++ b/bb_param/bb_vector2_array.h @@ -0,0 +1,16 @@ +/* bb_vector2_array.h */ + +#ifndef BB_VECTOR2_ARRAY_H +#define BB_VECTOR2_ARRAY_H + +#include "bb_param.h" +#include "core/object.h" + +class BBVector2Array : public BBParam { + GDCLASS(BBVector2Array, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::POOL_VECTOR2_ARRAY; } +}; + +#endif // BB_VECTOR2_ARRAY_H \ No newline at end of file diff --git a/bb_param/bb_vector3.h b/bb_param/bb_vector3.h new file mode 100644 index 0000000..dfb91c0 --- /dev/null +++ b/bb_param/bb_vector3.h @@ -0,0 +1,16 @@ +/* bb_vector3.h */ + +#ifndef BB_VECTOR3_H +#define BB_VECTOR3_H + +#include "bb_param.h" +#include "core/object.h" + +class BBVector3 : public BBParam { + GDCLASS(BBVector3, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::VECTOR3; } +}; + +#endif // BB_VECTOR3_H \ No newline at end of file diff --git a/bb_param/bb_vector3_array.h b/bb_param/bb_vector3_array.h new file mode 100644 index 0000000..e5c2143 --- /dev/null +++ b/bb_param/bb_vector3_array.h @@ -0,0 +1,16 @@ +/* bb_vector3_array.h */ + +#ifndef BB_VECTOR3_ARRAY_H +#define BB_VECTOR3_ARRAY_H + +#include "bb_param.h" +#include "core/object.h" + +class BBVector3Array : public BBParam { + GDCLASS(BBVector3Array, BBParam); + +protected: + virtual Variant::Type get_type() const { return Variant::POOL_VECTOR3_ARRAY; } +}; + +#endif // BB_VECTOR3_ARRAY_H \ No newline at end of file diff --git a/register_types.cpp b/register_types.cpp index d7ae6e9..dd15970 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -4,6 +4,30 @@ #include "core/class_db.h" +#include "bb_param/bb_aabb.h" +#include "bb_param/bb_array.h" +#include "bb_param/bb_basis.h" +#include "bb_param/bb_bool.h" +#include "bb_param/bb_byte_array.h" +#include "bb_param/bb_color.h" +#include "bb_param/bb_color_array.h" +#include "bb_param/bb_dictionary.h" +#include "bb_param/bb_float.h" +#include "bb_param/bb_int.h" +#include "bb_param/bb_int_array.h" +#include "bb_param/bb_param.h" +#include "bb_param/bb_plane.h" +#include "bb_param/bb_quat.h" +#include "bb_param/bb_real_array.h" +#include "bb_param/bb_rect2.h" +#include "bb_param/bb_string.h" +#include "bb_param/bb_string_array.h" +#include "bb_param/bb_transform.h" +#include "bb_param/bb_transform2d.h" +#include "bb_param/bb_vector2.h" +#include "bb_param/bb_vector2_array.h" +#include "bb_param/bb_vector3.h" +#include "bb_param/bb_vector3_array.h" #include "blackboard.h" #include "bt/actions/bt_action.h" #include "bt/actions/bt_console_print.h" @@ -97,6 +121,31 @@ void register_limboai_types() { ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + _limbo_utility = memnew(LimboUtility); ClassDB::register_class();