Improve null and object printing to avoid confusion with arrays

- Use different syntax for object printing to avoid confusion with arrays.
- Print null as `<null>` to avoid confusion with a string `"null"`.
- Display `<empty>` in editor resource pickers to avoid confusion
  with array-based properties.
This commit is contained in:
Hugo Locurcio 2022-07-25 00:15:20 +02:00
parent de5f13e935
commit 291d3aaabe
No known key found for this signature in database
GPG Key ID: 39E8F8BE30B0A49C
8 changed files with 13 additions and 13 deletions

View File

@ -811,7 +811,7 @@ String Object::to_string() {
_extension->to_string(_extension_instance, &ret);
return ret;
}
return "[" + get_class() + ":" + itos(get_instance_id()) + "]";
return "<" + get_class() + "#" + itos(get_instance_id()) + ">";
}
void Object::set_script_and_instance(const Variant &p_script, ScriptInstance *p_instance) {

View File

@ -1787,7 +1787,7 @@ String stringify_vector(const T &vec, int recursion_count) {
String Variant::stringify(int recursion_count) const {
switch (type) {
case NIL:
return "null";
return "<null>";
case BOOL:
return _data._bool ? "true" : "false";
case INT:
@ -1904,12 +1904,12 @@ String Variant::stringify(int recursion_count) const {
case OBJECT: {
if (_get_obj().obj) {
if (!_get_obj().id.is_ref_counted() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
return "[Freed Object]";
return "<Freed Object>";
}
return _get_obj().obj->to_string();
} else {
return "[Object:null]";
return "<Object#null>";
}
} break;
@ -1926,7 +1926,7 @@ String Variant::stringify(int recursion_count) const {
return "RID(" + itos(s.get_id()) + ")";
} break;
default: {
return "[" + get_type_name(type) + "]";
return "<" + get_type_name(type) + ">";
}
}

View File

@ -52,7 +52,7 @@ void EditorPropertyNil::update_property() {
EditorPropertyNil::EditorPropertyNil() {
Label *label = memnew(Label);
label->set_text("[null]");
label->set_text("<null>");
add_child(label);
}
@ -1382,7 +1382,7 @@ void EditorPropertyObjectID::update_property() {
edit->set_disabled(false);
edit->set_icon(EditorNode::get_singleton()->get_class_icon(type));
} else {
edit->set_text(TTR("[Empty]"));
edit->set_text(TTR("<empty>"));
edit->set_disabled(true);
edit->set_icon(Ref<Texture2D>());
}

View File

@ -61,7 +61,7 @@ void EditorResourcePicker::_update_resource() {
if (edited_resource == Ref<Resource>()) {
assign_button->set_icon(Ref<Texture2D>());
assign_button->set_text(TTR("[empty]"));
assign_button->set_text(TTR("<empty>"));
assign_button->set_tooltip_text("");
} else {
assign_button->set_icon(EditorNode::get_singleton()->get_object_icon(edited_resource.operator->(), "Object"));
@ -1113,7 +1113,7 @@ void EditorAudioStreamPicker::_update_resource() {
void EditorAudioStreamPicker::_preview_draw() {
Ref<AudioStream> audio_stream = get_edited_resource();
if (!audio_stream.is_valid()) {
get_assign_button()->set_text(TTR("[empty]"));
get_assign_button()->set_text(TTR("<empty>"));
return;
}

View File

@ -1,5 +1,5 @@
GDTEST_OK
null
<null>
0
1
2

View File

@ -1,2 +1,2 @@
GDTEST_OK
123456789101112131415161718192212223242526272829303132333435363738394041424344454647falsetruenull
123456789101112131415161718192212223242526272829303132333435363738394041424344454647falsetrue<null>

View File

@ -1,4 +1,4 @@
GDTEST_OK
null
<null>
true
false

View File

@ -1319,7 +1319,7 @@ void godotsharp_object_to_string(Object *p_ptr, godot_string *r_str) {
#endif
// Can't call 'Object::to_string()' here, as that can end up calling 'ToString' again resulting in an endless circular loop.
memnew_placement(r_str,
String("[" + p_ptr->get_class() + ":" + itos(p_ptr->get_instance_id()) + "]"));
String("<" + p_ptr->get_class() + "#" + itos(p_ptr->get_instance_id()) + ">"));
}
#ifdef __cplusplus