diff --git a/include/godot_cpp/variant/variant.hpp b/include/godot_cpp/variant/variant.hpp index 2aa54a28..b131d749 100644 --- a/include/godot_cpp/variant/variant.hpp +++ b/include/godot_cpp/variant/variant.hpp @@ -42,6 +42,8 @@ namespace godot { +class ObjectID; + class Variant { uint8_t opaque[GODOT_CPP_VARIANT_SIZE]{ 0 }; @@ -187,6 +189,7 @@ public: Variant(const StringName &v); Variant(const NodePath &v); Variant(const godot::RID &v); + Variant(const ObjectID &v); Variant(const Object *v); Variant(const Callable &v); Variant(const Signal &v); @@ -230,6 +233,7 @@ public: operator StringName() const; operator NodePath() const; operator godot::RID() const; + operator ObjectID() const; operator Object *() const; operator Callable() const; operator Signal() const; diff --git a/src/variant/variant.cpp b/src/variant/variant.cpp index 7fa8c24c..4026637c 100644 --- a/src/variant/variant.cpp +++ b/src/variant/variant.cpp @@ -191,6 +191,10 @@ Variant::Variant(const Object *v) { } } +Variant::Variant(const ObjectID &p_id) : + Variant(p_id.operator uint64_t()) { +} + Variant::Variant(const Callable &v) { from_type_constructor[CALLABLE](_native_ptr(), v._native_ptr()); } @@ -410,6 +414,21 @@ Variant::operator Object *() const { return reinterpret_cast(internal::gde_interface->object_get_instance_binding(obj, internal::token, &Object::___binding_callbacks)); } +Variant::operator ObjectID() const { + if (get_type() == Type::INT) { + return ObjectID(operator uint64_t()); + } else if (get_type() == Type::OBJECT) { + Object *obj = operator Object *(); + if (obj != nullptr) { + return ObjectID(obj->get_instance_id()); + } else { + return ObjectID(); + } + } else { + return ObjectID(); + } +} + Variant::operator Callable() const { Callable result; to_type_constructor[CALLABLE](result._native_ptr(), _native_ptr());