1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

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.
This commit is contained in:
Rémi Verschelde
2022-01-18 11:31:15 +01:00
parent 045648d091
commit 8898d6dadc
12 changed files with 25 additions and 33 deletions

View File

@@ -1649,12 +1649,13 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
dict.get_key_list(&keys); dict.get_key_list(&keys);
keys.sort(); 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"); p_store_string_func(p_store_string_ud, "{\n");
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { for (List<Variant>::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); 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, ": "); 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); write(dict[E->get()], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, recursion_count);

View File

@@ -62,8 +62,7 @@
<argument index="0" name="primitive" type="int" enum="Mesh.PrimitiveType" /> <argument index="0" name="primitive" type="int" enum="Mesh.PrimitiveType" />
<argument index="1" name="arrays" type="Array" /> <argument index="1" name="arrays" type="Array" />
<argument index="2" name="blend_shapes" type="Array" default="[]" /> <argument index="2" name="blend_shapes" type="Array" default="[]" />
<argument index="3" name="lods" type="Dictionary" default="{ <argument index="3" name="lods" type="Dictionary" default="{}" />
}" />
<argument index="4" name="compress_flags" type="int" default="0" /> <argument index="4" name="compress_flags" type="int" default="0" />
<description> <description>
Creates a new surface. Creates a new surface.

View File

@@ -23,8 +23,7 @@
<argument index="0" name="primitive" type="int" enum="Mesh.PrimitiveType" /> <argument index="0" name="primitive" type="int" enum="Mesh.PrimitiveType" />
<argument index="1" name="arrays" type="Array" /> <argument index="1" name="arrays" type="Array" />
<argument index="2" name="blend_shapes" type="Array" default="[]" /> <argument index="2" name="blend_shapes" type="Array" default="[]" />
<argument index="3" name="lods" type="Dictionary" default="{ <argument index="3" name="lods" type="Dictionary" default="{}" />
}" />
<argument index="4" name="material" type="Material" default="null" /> <argument index="4" name="material" type="Material" default="null" />
<argument index="5" name="name" type="String" default="&quot;&quot;" /> <argument index="5" name="name" type="String" default="&quot;&quot;" />
<argument index="6" name="flags" type="int" default="0" /> <argument index="6" name="flags" type="int" default="0" />

View File

@@ -1838,8 +1838,7 @@
<argument index="1" name="primitive" type="int" enum="RenderingServer.PrimitiveType" /> <argument index="1" name="primitive" type="int" enum="RenderingServer.PrimitiveType" />
<argument index="2" name="arrays" type="Array" /> <argument index="2" name="arrays" type="Array" />
<argument index="3" name="blend_shapes" type="Array" default="[]" /> <argument index="3" name="blend_shapes" type="Array" default="[]" />
<argument index="4" name="lods" type="Dictionary" default="{ <argument index="4" name="lods" type="Dictionary" default="{}" />
}" />
<argument index="5" name="compress_format" type="int" default="0" /> <argument index="5" name="compress_format" type="int" default="0" />
<description> <description>
</description> </description>

View File

@@ -24,8 +24,7 @@
<argument index="0" name="text" type="String" /> <argument index="0" name="text" type="String" />
<argument index="1" name="fonts" type="Font" /> <argument index="1" name="fonts" type="Font" />
<argument index="2" name="size" type="int" /> <argument index="2" name="size" type="int" />
<argument index="3" name="opentype_features" type="Dictionary" default="{ <argument index="3" name="opentype_features" type="Dictionary" default="{}" />
}" />
<argument index="4" name="language" type="String" default="&quot;&quot;" /> <argument index="4" name="language" type="String" default="&quot;&quot;" />
<description> <description>
Adds text span and font to draw it. Adds text span and font to draw it.

View File

@@ -24,8 +24,7 @@
<argument index="0" name="text" type="String" /> <argument index="0" name="text" type="String" />
<argument index="1" name="fonts" type="Font" /> <argument index="1" name="fonts" type="Font" />
<argument index="2" name="size" type="int" /> <argument index="2" name="size" type="int" />
<argument index="3" name="opentype_features" type="Dictionary" default="{ <argument index="3" name="opentype_features" type="Dictionary" default="{}" />
}" />
<argument index="4" name="language" type="String" default="&quot;&quot;" /> <argument index="4" name="language" type="String" default="&quot;&quot;" />
<description> <description>
Adds text span and font to draw it. Adds text span and font to draw it.
@@ -259,8 +258,7 @@
<argument index="1" name="fonts" type="Font" /> <argument index="1" name="fonts" type="Font" />
<argument index="2" name="size" type="int" /> <argument index="2" name="size" type="int" />
<argument index="3" name="dropcap_margins" type="Rect2" default="Rect2(0, 0, 0, 0)" /> <argument index="3" name="dropcap_margins" type="Rect2" default="Rect2(0, 0, 0, 0)" />
<argument index="4" name="opentype_features" type="Dictionary" default="{ <argument index="4" name="opentype_features" type="Dictionary" default="{}" />
}" />
<argument index="5" name="language" type="String" default="&quot;&quot;" /> <argument index="5" name="language" type="String" default="&quot;&quot;" />
<description> <description>
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. 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.

View File

@@ -913,8 +913,7 @@
<argument index="1" name="text" type="String" /> <argument index="1" name="text" type="String" />
<argument index="2" name="fonts" type="Array" /> <argument index="2" name="fonts" type="Array" />
<argument index="3" name="size" type="int" /> <argument index="3" name="size" type="int" />
<argument index="4" name="opentype_features" type="Dictionary" default="{ <argument index="4" name="opentype_features" type="Dictionary" default="{}" />
}" />
<argument index="5" name="language" type="String" default="&quot;&quot;" /> <argument index="5" name="language" type="String" default="&quot;&quot;" />
<description> <description>
Adds text span and font to draw it to the text buffer. Adds text span and font to draw it to the text buffer.

View File

@@ -522,7 +522,7 @@ void DocTools::generate(bool p_basic_types) {
int darg_idx = i - (E.arguments.size() - E.default_arguments.size()); int darg_idx = i - (E.arguments.size() - E.default_arguments.size());
if (darg_idx >= 0) { if (darg_idx >= 0) {
Variant default_arg = E.default_arguments[darg_idx]; 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); method.arguments.push_back(argument);
@@ -585,7 +585,7 @@ void DocTools::generate(bool p_basic_types) {
tid.name = E; tid.name = E;
tid.type = "Color"; tid.type = "Color";
tid.data_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); 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; int darg_idx = mi.default_arguments.size() - mi.arguments.size() + j;
if (darg_idx >= 0) { if (darg_idx >= 0) {
Variant default_arg = mi.default_arguments[darg_idx]; 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); method.arguments.push_back(ad);
@@ -801,7 +801,7 @@ void DocTools::generate(bool p_basic_types) {
DocData::PropertyDoc property; DocData::PropertyDoc property;
property.name = pi.name; property.name = pi.name;
property.type = Variant::get_type_name(pi.type); 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); c.properties.push_back(property);
} }
@@ -813,7 +813,7 @@ void DocTools::generate(bool p_basic_types) {
DocData::ConstantDoc constant; DocData::ConstantDoc constant;
constant.name = E; constant.name = E;
Variant value = Variant::get_constant_value(Variant::Type(i), 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; constant.is_value_valid = true;
c.constants.push_back(constant); 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()); int darg_idx = j - (mi.arguments.size() - mi.default_arguments.size());
if (darg_idx >= 0) { if (darg_idx >= 0) {
Variant default_arg = mi.default_arguments[darg_idx]; 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); md.arguments.push_back(ad);

View File

@@ -33,8 +33,7 @@
<method name="create_data_channel"> <method name="create_data_channel">
<return type="WebRTCDataChannel" /> <return type="WebRTCDataChannel" />
<argument index="0" name="label" type="String" /> <argument index="0" name="label" type="String" />
<argument index="1" name="options" type="Dictionary" default="{ <argument index="1" name="options" type="Dictionary" default="{}" />
}" />
<description> <description>
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]. 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]. 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 @@
</method> </method>
<method name="initialize"> <method name="initialize">
<return type="int" enum="Error" /> <return type="int" enum="Error" />
<argument index="0" name="configuration" type="Dictionary" default="{ <argument index="0" name="configuration" type="Dictionary" default="{}" />
}" />
<description> <description>
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. 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: Valid [code]options[/code] are: