1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-20 14:45:44 +00:00

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1319,7 +1319,7 @@ void godotsharp_object_to_string(Object *p_ptr, godot_string *r_str) {
#endif #endif
// Can't call 'Object::to_string()' here, as that can end up calling 'ToString' again resulting in an endless circular loop. // 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, 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 #ifdef __cplusplus