From 8898d6dadc64d3c87d998c57ef0a6eab99698566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Tue, 18 Jan 2022 11:31:15 +0100 Subject: [PATCH] Dictionary: Serialize empty dict as `{}` instead of `{\n}` Also make sure to always convert multiline dictionaries to a single line for its EditorHelp representation, as multiline values break formatting. --- core/variant/variant_parser.cpp | 9 +++++---- doc/classes/ArrayMesh.xml | 3 +-- doc/classes/CodeEdit.xml | 2 +- doc/classes/Image.xml | 2 +- doc/classes/ImporterMesh.xml | 5 ++--- doc/classes/PackedScene.xml | 2 +- doc/classes/RenderingServer.xml | 3 +-- doc/classes/TextLine.xml | 3 +-- doc/classes/TextParagraph.xml | 6 ++---- doc/classes/TextServer.xml | 3 +-- editor/doc_tools.cpp | 14 +++++++------- .../webrtc/doc_classes/WebRTCPeerConnection.xml | 6 ++---- 12 files changed, 25 insertions(+), 33 deletions(-) diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp index 571181f6652..57875bf50fb 100644 --- a/core/variant/variant_parser.cpp +++ b/core/variant/variant_parser.cpp @@ -1649,12 +1649,13 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str dict.get_key_list(&keys); keys.sort(); + if (keys.is_empty()) { // Avoid unnecessary line break. + p_store_string_func(p_store_string_ud, "{}"); + break; + } + p_store_string_func(p_store_string_ud, "{\n"); for (List::Element *E = keys.front(); E; E = E->next()) { - /* - if (!_check_type(dict[E->get()])) - continue; - */ write(E->get(), p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, recursion_count); p_store_string_func(p_store_string_ud, ": "); write(dict[E->get()], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, recursion_count); diff --git a/doc/classes/ArrayMesh.xml b/doc/classes/ArrayMesh.xml index c986947dfb3..fa980d9f759 100644 --- a/doc/classes/ArrayMesh.xml +++ b/doc/classes/ArrayMesh.xml @@ -62,8 +62,7 @@ - + Creates a new surface. diff --git a/doc/classes/CodeEdit.xml b/doc/classes/CodeEdit.xml index 697b0443f12..4a9d79978ca 100644 --- a/doc/classes/CodeEdit.xml +++ b/doc/classes/CodeEdit.xml @@ -442,7 +442,7 @@ Highlight mismatching brace pairs. - + Sets the brace pairs to be autocompleted. diff --git a/doc/classes/Image.xml b/doc/classes/Image.xml index e7bb1b98256..60d4b664d2e 100644 --- a/doc/classes/Image.xml +++ b/doc/classes/Image.xml @@ -452,7 +452,7 @@ - + Holds all the image's color data in a given format. See [enum Format] constants. diff --git a/doc/classes/ImporterMesh.xml b/doc/classes/ImporterMesh.xml index ab344f908c6..4c323156c9c 100644 --- a/doc/classes/ImporterMesh.xml +++ b/doc/classes/ImporterMesh.xml @@ -23,8 +23,7 @@ - + @@ -178,7 +177,7 @@ - + diff --git a/doc/classes/PackedScene.xml b/doc/classes/PackedScene.xml index d3a770b35bc..4bba6563bb6 100644 --- a/doc/classes/PackedScene.xml +++ b/doc/classes/PackedScene.xml @@ -104,7 +104,7 @@ - + A dictionary representation of the scene contents. Available keys include "rnames" and "variants" for resources, "node_count", "nodes", "node_paths" for nodes, "editable_instances" for base scene children overrides, "conn_count" and "conns" for signal connections, and "version" for the format style of the PackedScene. diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index 5127455b4d8..b91f3595f1c 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -1838,8 +1838,7 @@ - + diff --git a/doc/classes/TextLine.xml b/doc/classes/TextLine.xml index 1eaccf46043..bf1abf86aed 100644 --- a/doc/classes/TextLine.xml +++ b/doc/classes/TextLine.xml @@ -24,8 +24,7 @@ - + Adds text span and font to draw it. diff --git a/doc/classes/TextParagraph.xml b/doc/classes/TextParagraph.xml index ff193a0e4b3..3d3c0dd6ff6 100644 --- a/doc/classes/TextParagraph.xml +++ b/doc/classes/TextParagraph.xml @@ -24,8 +24,7 @@ - + Adds text span and font to draw it. @@ -259,8 +258,7 @@ - + Sets drop cap, overrides previously set drop cap. Drop cap (dropped capital) is a decorative element at the beginning of a paragraph that is larger than the rest of the text. diff --git a/doc/classes/TextServer.xml b/doc/classes/TextServer.xml index 5be6113ddac..61024ef0c87 100644 --- a/doc/classes/TextServer.xml +++ b/doc/classes/TextServer.xml @@ -913,8 +913,7 @@ - + Adds text span and font to draw it to the text buffer. diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index a71e16b66ca..6804ec32ac3 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -410,7 +410,7 @@ void DocTools::generate(bool p_basic_types) { //used to track uninitialized values using valgrind //print_line("getting default value for " + String(name) + "." + String(E.name)); if (default_value_valid && default_value.get_type() != Variant::OBJECT) { - prop.default_value = default_value.get_construct_string().replace("\n", ""); + prop.default_value = default_value.get_construct_string().replace("\n", " "); } StringName setter = ClassDB::get_property_setter(name, E.name); @@ -522,7 +522,7 @@ void DocTools::generate(bool p_basic_types) { int darg_idx = i - (E.arguments.size() - E.default_arguments.size()); if (darg_idx >= 0) { Variant default_arg = E.default_arguments[darg_idx]; - argument.default_value = default_arg.get_construct_string(); + argument.default_value = default_arg.get_construct_string().replace("\n", " "); } method.arguments.push_back(argument); @@ -585,7 +585,7 @@ void DocTools::generate(bool p_basic_types) { tid.name = E; tid.type = "Color"; tid.data_type = "color"; - tid.default_value = Variant(Theme::get_default()->get_color(E, cname)).get_construct_string(); + tid.default_value = Variant(Theme::get_default()->get_color(E, cname)).get_construct_string().replace("\n", " "); c.theme_properties.push_back(tid); } @@ -757,7 +757,7 @@ void DocTools::generate(bool p_basic_types) { int darg_idx = mi.default_arguments.size() - mi.arguments.size() + j; if (darg_idx >= 0) { Variant default_arg = mi.default_arguments[darg_idx]; - ad.default_value = default_arg.get_construct_string(); + ad.default_value = default_arg.get_construct_string().replace("\n", " "); } method.arguments.push_back(ad); @@ -801,7 +801,7 @@ void DocTools::generate(bool p_basic_types) { DocData::PropertyDoc property; property.name = pi.name; property.type = Variant::get_type_name(pi.type); - property.default_value = v.get(pi.name).get_construct_string(); + property.default_value = v.get(pi.name).get_construct_string().replace("\n", " "); c.properties.push_back(property); } @@ -813,7 +813,7 @@ void DocTools::generate(bool p_basic_types) { DocData::ConstantDoc constant; constant.name = E; Variant value = Variant::get_constant_value(Variant::Type(i), E); - constant.value = value.get_type() == Variant::INT ? itos(value) : value.get_construct_string(); + constant.value = value.get_type() == Variant::INT ? itos(value) : value.get_construct_string().replace("\n", " "); constant.is_value_valid = true; c.constants.push_back(constant); } @@ -930,7 +930,7 @@ void DocTools::generate(bool p_basic_types) { int darg_idx = j - (mi.arguments.size() - mi.default_arguments.size()); if (darg_idx >= 0) { Variant default_arg = mi.default_arguments[darg_idx]; - ad.default_value = default_arg.get_construct_string(); + ad.default_value = default_arg.get_construct_string().replace("\n", " "); } md.arguments.push_back(ad); diff --git a/modules/webrtc/doc_classes/WebRTCPeerConnection.xml b/modules/webrtc/doc_classes/WebRTCPeerConnection.xml index 618fe141376..2f2c2c379dc 100644 --- a/modules/webrtc/doc_classes/WebRTCPeerConnection.xml +++ b/modules/webrtc/doc_classes/WebRTCPeerConnection.xml @@ -33,8 +33,7 @@ - + Returns a new [WebRTCDataChannel] (or [code]null[/code] on failure) with given [code]label[/code] and optionally configured via the [code]options[/code] dictionary. This method can only be called when the connection is in state [constant STATE_NEW]. There are two ways to create a working data channel: either call [method create_data_channel] on only one of the peer and listen to [signal data_channel_received] on the other, or call [method create_data_channel] on both peers, with the same values, and the [code]negotiated[/code] option set to [code]true[/code]. @@ -70,8 +69,7 @@ - + Re-initialize this peer connection, closing any previously active connection, and going back to state [constant STATE_NEW]. A dictionary of [code]options[/code] can be passed to configure the peer connection. Valid [code]options[/code] are: