diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-01-18 11:31:15 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-01-18 11:31:21 +0100 |
commit | 8898d6dadc64d3c87d998c57ef0a6eab99698566 (patch) | |
tree | c8f736fdab327ccc6e0236944290c6453406242e /core | |
parent | 045648d09166377500630c606a447857cd841fc0 (diff) |
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.
Diffstat (limited to 'core')
-rw-r--r-- | core/variant/variant_parser.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp index 571181f665..57875bf50f 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<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); 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); |