From 7dbb1c0571c0d1fb26c28552b09430807cc4d717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Mon, 16 Jan 2017 18:03:38 +0100 Subject: [PATCH] Improve .tscn VCS Serialize dictionaries adding newlines between key-value pairs Serialize group lists also with newlines in between Serialize string properties escaping only " and \ (needed for a good diff experience with built-in scripts and shaders) Bonus: Make AnimationPlayer serialize its blend times always sorted so their order is predictable in the .tscn file. This PR is back-compat; won't break the load of existing files. --- core/ustring.cpp | 11 ++++++++++- core/ustring.h | 1 + core/variant_parser.cpp | 10 +++++----- scene/animation/animation_player.cpp | 19 +++++++++++-------- scene/animation/animation_player.h | 2 +- scene/resources/scene_format_text.cpp | 10 ++++------ 6 files changed, 32 insertions(+), 21 deletions(-) diff --git a/core/ustring.cpp b/core/ustring.cpp index f9c10615b3..a21d5ec594 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -3286,8 +3286,17 @@ String String::c_escape() const { escaped=escaped.replace("\t","\\t"); escaped=escaped.replace("\v","\\v"); escaped=escaped.replace("\'","\\'"); - escaped=escaped.replace("\"","\\\""); escaped=escaped.replace("\?","\\?"); + escaped=escaped.replace("\"","\\\""); + + return escaped; +} + +String String::c_escape_multiline() const { + + String escaped=*this; + escaped=escaped.replace("\\","\\\\"); + escaped=escaped.replace("\"","\\\""); return escaped; } diff --git a/core/ustring.h b/core/ustring.h index 452f252857..5d2ba3c73b 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -216,6 +216,7 @@ public: String http_escape() const; String http_unescape() const; String c_escape() const; + String c_escape_multiline() const; String c_unescape() const; String json_escape() const; String word_wrap(int p_chars_per_line) const; diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index 5ed2415e36..dc0ba8c3bd 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -1878,7 +1878,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str String str=p_variant; - str="\""+str.c_escape()+"\""; + str="\""+str.c_escape_multiline()+"\""; p_store_string_func(p_store_string_ud, str ); } break; case Variant::VECTOR2: { @@ -2123,20 +2123,20 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str dict.get_key_list(&keys); keys.sort(); - p_store_string_func(p_store_string_ud,"{ "); + 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); - 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); if (E->next()) - p_store_string_func(p_store_string_ud,", "); + p_store_string_func(p_store_string_ud,",\n"); } - p_store_string_func(p_store_string_ud," }"); + p_store_string_func(p_store_string_ud,"\n}"); } break; diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 30af9b0094..6f3243e385 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -118,17 +118,20 @@ bool AnimationPlayer::_get(const StringName& p_name,Variant &r_ret) const { } else if (name=="blend_times") { - Array array; - - array.resize(blend_times.size()*3); - int idx=0; + Vector keys; for(Map::Element *E=blend_times.front();E;E=E->next()) { - array.set(idx*3+0,E->key().from); - array.set(idx*3+1,E->key().to); - array.set(idx*3+2,E->get()); - idx++; + keys.ordered_insert(E->key()); } + + Array array; + for(int i=0;i0) - sgroups+=", "; - sgroups+="\""+groups[j].operator String().c_escape()+"\""; + sgroups+="\""+String(groups[j]).c_escape()+"\",\n"; } - sgroups+=" ]"; + sgroups+="]"; header+=sgroups; }