Merge pull request #983 from rburing/variant_to_from_objectid
Add conversions between `Variant` and `ObjectID`pull/1000/head
commit
0dfe0d0166
|
@ -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;
|
||||
|
|
|
@ -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<Object *>(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());
|
||||
|
|
Loading…
Reference in New Issue