From fd836cad270f7eb9645356cd583c8f11bf737b0f Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 31 Dec 2015 00:31:00 -0300 Subject: -Ensure .tscn and .tres always save in a deterministic way, fixes #2495 -Scene edit state is saved outside the scene now, to avoid changes .tscn files when nothing really changed -Created a VariantWriter helper to unify all variant to text writing -Moved SceneFormatText writing to VariantWriter -Moved ConfigFile to use VariantWriter and VariantParser, added compatibility mode for old .cfg files that use engine.cfg format --- tools/editor/editor_node.cpp | 61 ++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 27 deletions(-) (limited to 'tools/editor/editor_node.cpp') diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index b30c87586..4438123df 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -584,59 +584,66 @@ void EditorNode::_dialog_display_file_error(String p_file,Error p_error) { } -void EditorNode::_get_scene_metadata() { +void EditorNode::_get_scene_metadata(const String& p_file) { Node *scene = editor_data.get_edited_scene_root(); if (!scene) return; + String path = EditorSettings::get_singleton()->get_project_settings_path().plus_file(p_file.get_file()+"-editstate-"+p_file.md5_text()+".cfg"); - if (scene->has_meta("__editor_plugin_states__")) { + Ref cf; + cf.instance(); - Dictionary md = scene->get_meta("__editor_plugin_states__"); - editor_data.set_editor_states(md); + Error err = cf->load(path); + if (err!=OK) + return; //must not exist - } + List esl; + cf->get_section_keys("editor_states",&esl); - if (scene->has_meta("__editor_run_settings__")) { + Dictionary md; + for (List::Element *E=esl.front();E;E=E->next()) { - Dictionary md = scene->get_meta("__editor_run_settings__"); - if (md.has("run_mode")) - run_settings_dialog->set_run_mode(md["run_mode"]); - if (md.has("custom_args")) - run_settings_dialog->set_custom_arguments(md["custom_args"]); + Variant st=cf->get_value("editor_states",E->get()); + if (st.get_type()) { + md[E->get()]=st; + } } + + editor_data.set_editor_states(md); + } -void EditorNode::_set_scene_metadata() { +void EditorNode::_set_scene_metadata(const String& p_file) { Node *scene = editor_data.get_edited_scene_root(); if (!scene) return; - { /* Editor States */ - Dictionary md = editor_data.get_editor_states(); + scene->set_meta("__editor_run_settings__",Variant()); //clear it (no point in keeping it) + scene->set_meta("__editor_plugin_states__",Variant()); - if (!md.empty()) { - scene->set_meta("__editor_plugin_states__",md); - } - } + String path = EditorSettings::get_singleton()->get_project_settings_path().plus_file(p_file.get_file()+"-editstate-"+p_file.md5_text()+".cfg"); - { /* Run Settings */ + Ref cf; + cf.instance(); + Dictionary md = editor_data.get_editor_states(); + List keys; + md.get_key_list(&keys); - Dictionary md; - md["run_mode"]=run_settings_dialog->get_run_mode(); - md["custom_args"]=run_settings_dialog->get_custom_arguments(); - scene->set_meta("__editor_run_settings__",md); - } - + for(List::Element *E=keys.front();E;E=E->next()) { + cf->set_value("editor_states",E->get(),md[E->get()]); + } + Error err = cf->save(path); + ERR_FAIL_COND(err!=OK); } @@ -954,7 +961,7 @@ void EditorNode::_save_scene(String p_file) { } - _set_scene_metadata(); + _set_scene_metadata(p_file); Ref sdata; @@ -3652,7 +3659,7 @@ Error EditorNode::load_scene(const String& p_scene, bool p_ignore_broken_deps,bo new_scene->set_scene_instance_state(Ref()); set_edited_scene(new_scene); - _get_scene_metadata(); + _get_scene_metadata(p_scene); /* editor_data.set_edited_scene_root(new_scene); -- cgit v1.2.3-70-g09d2