diff options
Diffstat (limited to 'core/variant')
-rw-r--r-- | core/variant/array.cpp | 14 | ||||
-rw-r--r-- | core/variant/callable_bind.cpp | 4 | ||||
-rw-r--r-- | core/variant/container_type_validate.h | 10 | ||||
-rw-r--r-- | core/variant/variant.cpp | 16 | ||||
-rw-r--r-- | core/variant/variant.h | 3 | ||||
-rw-r--r-- | core/variant/variant_construct.cpp | 2 | ||||
-rw-r--r-- | core/variant/variant_op.cpp | 2 | ||||
-rw-r--r-- | core/variant/variant_setget.cpp | 4 | ||||
-rw-r--r-- | core/variant/variant_utility.cpp | 2 |
9 files changed, 29 insertions, 28 deletions
diff --git a/core/variant/array.cpp b/core/variant/array.cpp index 3e62d3dffa..f7a86b8fa3 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -385,7 +385,7 @@ int Array::find_custom(const Callable &p_callable, int p_from) const { Callable::CallError ce; p_callable.callp(argptrs, 1, res, ce); if (unlikely(ce.error != Callable::CallError::CALL_OK)) { - ERR_FAIL_V_MSG(ret, "Error calling method from 'find_custom': " + Variant::get_callable_error_text(p_callable, argptrs, 1, ce)); + ERR_FAIL_V_MSG(ret, vformat("Error calling method from 'find_custom': %s.", Variant::get_callable_error_text(p_callable, argptrs, 1, ce))); } ERR_FAIL_COND_V_MSG(res.get_type() != Variant::Type::BOOL, ret, "Error on method from 'find_custom': Return type of callable must be boolean."); @@ -445,7 +445,7 @@ int Array::rfind_custom(const Callable &p_callable, int p_from) const { Callable::CallError ce; p_callable.callp(argptrs, 1, res, ce); if (unlikely(ce.error != Callable::CallError::CALL_OK)) { - ERR_FAIL_V_MSG(-1, "Error calling method from 'rfind_custom': " + Variant::get_callable_error_text(p_callable, argptrs, 1, ce)); + ERR_FAIL_V_MSG(-1, vformat("Error calling method from 'rfind_custom': %s.", Variant::get_callable_error_text(p_callable, argptrs, 1, ce))); } ERR_FAIL_COND_V_MSG(res.get_type() != Variant::Type::BOOL, -1, "Error on method from 'rfind_custom': Return type of callable must be boolean."); @@ -574,7 +574,7 @@ Array Array::filter(const Callable &p_callable) const { Callable::CallError ce; p_callable.callp(argptrs, 1, result, ce); if (ce.error != Callable::CallError::CALL_OK) { - ERR_FAIL_V_MSG(Array(), "Error calling method from 'filter': " + Variant::get_callable_error_text(p_callable, argptrs, 1, ce)); + ERR_FAIL_V_MSG(Array(), vformat("Error calling method from 'filter': %s.", Variant::get_callable_error_text(p_callable, argptrs, 1, ce))); } if (result.operator bool()) { @@ -600,7 +600,7 @@ Array Array::map(const Callable &p_callable) const { Callable::CallError ce; p_callable.callp(argptrs, 1, result, ce); if (ce.error != Callable::CallError::CALL_OK) { - ERR_FAIL_V_MSG(Array(), "Error calling method from 'map': " + Variant::get_callable_error_text(p_callable, argptrs, 1, ce)); + ERR_FAIL_V_MSG(Array(), vformat("Error calling method from 'map': %s.", Variant::get_callable_error_text(p_callable, argptrs, 1, ce))); } new_arr[i] = result; @@ -626,7 +626,7 @@ Variant Array::reduce(const Callable &p_callable, const Variant &p_accum) const Callable::CallError ce; p_callable.callp(argptrs, 2, result, ce); if (ce.error != Callable::CallError::CALL_OK) { - ERR_FAIL_V_MSG(Variant(), "Error calling method from 'reduce': " + Variant::get_callable_error_text(p_callable, argptrs, 2, ce)); + ERR_FAIL_V_MSG(Variant(), vformat("Error calling method from 'reduce': %s.", Variant::get_callable_error_text(p_callable, argptrs, 2, ce))); } ret = result; } @@ -643,7 +643,7 @@ bool Array::any(const Callable &p_callable) const { Callable::CallError ce; p_callable.callp(argptrs, 1, result, ce); if (ce.error != Callable::CallError::CALL_OK) { - ERR_FAIL_V_MSG(false, "Error calling method from 'any': " + Variant::get_callable_error_text(p_callable, argptrs, 1, ce)); + ERR_FAIL_V_MSG(false, vformat("Error calling method from 'any': %s.", Variant::get_callable_error_text(p_callable, argptrs, 1, ce))); } if (result.operator bool()) { @@ -665,7 +665,7 @@ bool Array::all(const Callable &p_callable) const { Callable::CallError ce; p_callable.callp(argptrs, 1, result, ce); if (ce.error != Callable::CallError::CALL_OK) { - ERR_FAIL_V_MSG(false, "Error calling method from 'all': " + Variant::get_callable_error_text(p_callable, argptrs, 1, ce)); + ERR_FAIL_V_MSG(false, vformat("Error calling method from 'all': %s.", Variant::get_callable_error_text(p_callable, argptrs, 1, ce))); } if (!(result.operator bool())) { diff --git a/core/variant/callable_bind.cpp b/core/variant/callable_bind.cpp index d82aa3583d..afb889551e 100644 --- a/core/variant/callable_bind.cpp +++ b/core/variant/callable_bind.cpp @@ -43,7 +43,7 @@ bool CallableCustomBind::_equal_func(const CallableCustom *p_a, const CallableCu const CallableCustomBind *a = static_cast<const CallableCustomBind *>(p_a); const CallableCustomBind *b = static_cast<const CallableCustomBind *>(p_b); - if (!(a->callable != b->callable)) { + if (a->callable != b->callable) { return false; } @@ -185,7 +185,7 @@ bool CallableCustomUnbind::_equal_func(const CallableCustom *p_a, const Callable const CallableCustomUnbind *a = static_cast<const CallableCustomUnbind *>(p_a); const CallableCustomUnbind *b = static_cast<const CallableCustomUnbind *>(p_b); - if (!(a->callable != b->callable)) { + if (a->callable != b->callable) { return false; } diff --git a/core/variant/container_type_validate.h b/core/variant/container_type_validate.h index 0a23c69cb4..8971fadf73 100644 --- a/core/variant/container_type_validate.h +++ b/core/variant/container_type_validate.h @@ -94,7 +94,7 @@ struct ContainerTypeValidate { return true; } - ERR_FAIL_V_MSG(false, "Attempted to " + String(p_operation) + " a variable of type '" + Variant::get_type_name(inout_variant.get_type()) + "' into a " + where + " of type '" + Variant::get_type_name(type) + "'."); + ERR_FAIL_V_MSG(false, vformat("Attempted to %s a variable of type '%s' into a %s of type '%s'.", String(p_operation), Variant::get_type_name(inout_variant.get_type()), where, Variant::get_type_name(type))); } if (type != Variant::OBJECT) { @@ -113,7 +113,7 @@ struct ContainerTypeValidate { return true; // This is fine, it's null. } Object *object = ObjectDB::get_instance(object_id); - ERR_FAIL_NULL_V_MSG(object, false, "Attempted to " + String(p_operation) + " an invalid (previously freed?) object instance into a '" + String(where) + "."); + ERR_FAIL_NULL_V_MSG(object, false, vformat("Attempted to %s an invalid (previously freed?) object instance into a '%s'.", String(p_operation), String(where))); #else Object *object = p_variant; if (object == nullptr) { @@ -126,7 +126,7 @@ struct ContainerTypeValidate { StringName obj_class = object->get_class_name(); if (obj_class != class_name) { - ERR_FAIL_COND_V_MSG(!ClassDB::is_parent_class(object->get_class_name(), class_name), false, "Attempted to " + String(p_operation) + " an object of type '" + object->get_class() + "' into a " + where + ", which does not inherit from '" + String(class_name) + "'."); + ERR_FAIL_COND_V_MSG(!ClassDB::is_parent_class(object->get_class_name(), class_name), false, vformat("Attempted to %s an object of type '%s' into a %s, which does not inherit from '%s'.", String(p_operation), object->get_class(), where, String(class_name))); } if (script.is_null()) { @@ -136,8 +136,8 @@ struct ContainerTypeValidate { Ref<Script> other_script = object->get_script(); // Check base script.. - ERR_FAIL_COND_V_MSG(other_script.is_null(), false, "Attempted to " + String(p_operation) + " an object into a " + String(where) + ", that does not inherit from '" + String(script->get_class_name()) + "'."); - ERR_FAIL_COND_V_MSG(!other_script->inherits_script(script), false, "Attempted to " + String(p_operation) + " an object into a " + String(where) + ", that does not inherit from '" + String(script->get_class_name()) + "'."); + ERR_FAIL_COND_V_MSG(other_script.is_null(), false, vformat("Attempted to %s an object into a %s, that does not inherit from '%s'.", String(p_operation), String(where), String(script->get_class_name()))); + ERR_FAIL_COND_V_MSG(!other_script->inherits_script(script), false, vformat("Attempted to %s an object into a %s, that does not inherit from '%s'.", String(p_operation), String(where), String(script->get_class_name()))); return true; } diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index e2865a06be..54936eb8a2 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -951,7 +951,7 @@ bool Variant::is_zero() const { return *reinterpret_cast<const ::RID *>(_data._mem) == ::RID(); } case OBJECT: { - return _get_obj().obj == nullptr; + return get_validated_object() == nullptr; } case CALLABLE: { return reinterpret_cast<const Callable *>(_data._mem)->is_null(); @@ -1736,7 +1736,7 @@ String Variant::stringify(int recursion_count) const { case INT: return itos(_data._int); case FLOAT: - return rtos(_data._float); + return String::num_real(_data._float, true); case STRING: return *reinterpret_cast<const String *>(_data._mem); case VECTOR2: @@ -2719,8 +2719,7 @@ Variant::Variant(const Vector<Plane> &p_array) : } } -Variant::Variant(const Vector<Face3> &p_face_array) : - type(NIL) { +Variant::Variant(const Vector<Face3> &p_face_array) { PackedVector3Array vertices; int face_count = p_face_array.size(); vertices.resize(face_count * 3); @@ -2739,8 +2738,7 @@ Variant::Variant(const Vector<Face3> &p_face_array) : *this = vertices; } -Variant::Variant(const Vector<Variant> &p_array) : - type(NIL) { +Variant::Variant(const Vector<Variant> &p_array) { Array arr; arr.resize(p_array.size()); for (int i = 0; i < p_array.size(); i++) { @@ -2749,8 +2747,7 @@ Variant::Variant(const Vector<Variant> &p_array) : *this = arr; } -Variant::Variant(const Vector<StringName> &p_array) : - type(NIL) { +Variant::Variant(const Vector<StringName> &p_array) { PackedStringArray v; int len = p_array.size(); v.resize(len); @@ -2908,8 +2905,7 @@ Variant::Variant(const IPAddress &p_address) : memnew_placement(_data._mem, String(p_address)); } -Variant::Variant(const Variant &p_variant) : - type(NIL) { +Variant::Variant(const Variant &p_variant) { reference(p_variant); } diff --git a/core/variant/variant.h b/core/variant/variant.h index 3b1924e8ea..9702c67a37 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -814,8 +814,7 @@ public: static void unregister_types(); Variant(const Variant &p_variant); - _FORCE_INLINE_ Variant() : - type(NIL) {} + _FORCE_INLINE_ Variant() {} _FORCE_INLINE_ ~Variant() { clear(); } diff --git a/core/variant/variant_construct.cpp b/core/variant/variant_construct.cpp index 6c37d5e4b7..9706457549 100644 --- a/core/variant/variant_construct.cpp +++ b/core/variant/variant_construct.cpp @@ -43,7 +43,7 @@ static LocalVector<VariantConstructData> construct_data[Variant::VARIANT_MAX]; template <typename T> static void add_constructor(const Vector<String> &arg_names) { - ERR_FAIL_COND_MSG(arg_names.size() != T::get_argument_count(), "Argument names size mismatch for " + Variant::get_type_name(T::get_base_type()) + "."); + ERR_FAIL_COND_MSG(arg_names.size() != T::get_argument_count(), vformat("Argument names size mismatch for '%s'.", Variant::get_type_name(T::get_base_type()))); VariantConstructData cd; cd.construct = T::construct; diff --git a/core/variant/variant_op.cpp b/core/variant/variant_op.cpp index d2c1cde970..ce27fbdf67 100644 --- a/core/variant/variant_op.cpp +++ b/core/variant/variant_op.cpp @@ -980,6 +980,7 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorInDictionaryHas<Color>>(Variant::OP_IN, Variant::COLOR, Variant::DICTIONARY); register_op<OperatorEvaluatorInDictionaryHas<StringName>>(Variant::OP_IN, Variant::STRING_NAME, Variant::DICTIONARY); register_op<OperatorEvaluatorInDictionaryHas<NodePath>>(Variant::OP_IN, Variant::NODE_PATH, Variant::DICTIONARY); + register_op<OperatorEvaluatorInDictionaryHas<::RID>>(Variant::OP_IN, Variant::RID, Variant::DICTIONARY); register_op<OperatorEvaluatorInDictionaryHasObject>(Variant::OP_IN, Variant::OBJECT, Variant::DICTIONARY); register_op<OperatorEvaluatorInDictionaryHas<Callable>>(Variant::OP_IN, Variant::CALLABLE, Variant::DICTIONARY); register_op<OperatorEvaluatorInDictionaryHas<Signal>>(Variant::OP_IN, Variant::SIGNAL, Variant::DICTIONARY); @@ -1021,6 +1022,7 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorInArrayFind<Color, Array>>(Variant::OP_IN, Variant::COLOR, Variant::ARRAY); register_op<OperatorEvaluatorInArrayFind<StringName, Array>>(Variant::OP_IN, Variant::STRING_NAME, Variant::ARRAY); register_op<OperatorEvaluatorInArrayFind<NodePath, Array>>(Variant::OP_IN, Variant::NODE_PATH, Variant::ARRAY); + register_op<OperatorEvaluatorInArrayFind<::RID, Array>>(Variant::OP_IN, Variant::RID, Variant::ARRAY); register_op<OperatorEvaluatorInArrayFindObject>(Variant::OP_IN, Variant::OBJECT, Variant::ARRAY); register_op<OperatorEvaluatorInArrayFind<Callable, Array>>(Variant::OP_IN, Variant::CALLABLE, Variant::ARRAY); register_op<OperatorEvaluatorInArrayFind<Signal, Array>>(Variant::OP_IN, Variant::SIGNAL, Variant::ARRAY); diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp index 1652f81d99..560067fc08 100644 --- a/core/variant/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -141,6 +141,10 @@ void register_named_setters_getters() { REGISTER_MEMBER(Color, h); REGISTER_MEMBER(Color, s); REGISTER_MEMBER(Color, v); + + REGISTER_MEMBER(Color, ok_hsl_h); + REGISTER_MEMBER(Color, ok_hsl_s); + REGISTER_MEMBER(Color, ok_hsl_l); } void unregister_named_setters_getters() { diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index 384fe6c4a6..50932afbb6 100644 --- a/core/variant/variant_utility.cpp +++ b/core/variant/variant_utility.cpp @@ -1671,7 +1671,7 @@ static void register_utility_function(const String &p_name, const Vector<String> bfi.argnames = argnames; bfi.argcount = T::get_argument_count(); if (!bfi.is_vararg) { - ERR_FAIL_COND_MSG(argnames.size() != bfi.argcount, "wrong number of arguments binding utility function: " + name); + ERR_FAIL_COND_MSG(argnames.size() != bfi.argcount, vformat("Wrong number of arguments binding utility function: '%s'.", name)); } bfi.get_arg_type = T::get_argument_type; bfi.return_type = T::get_return_type(); |