From 45443a165147859f83df37223572cdd40df476b4 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 13 Jun 2016 10:58:32 -0300 Subject: [PATCH] Changed reload logic to auto-hard-reload scripts on save. It's simpler to use and also fixes #4756 --- core/script_language.cpp | 12 +++++++++++- core/script_language.h | 4 ++++ core/variant_parser.cpp | 3 ++- modules/gdscript/gd_script.cpp | 5 +++++ tools/editor/plugins/script_editor_plugin.cpp | 9 +++++++-- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/core/script_language.cpp b/core/script_language.cpp index b3116a0297e..68a694398a0 100644 --- a/core/script_language.cpp +++ b/core/script_language.cpp @@ -32,7 +32,7 @@ ScriptLanguage *ScriptServer::_languages[MAX_LANGUAGES]; int ScriptServer::_language_count=0; bool ScriptServer::scripting_enabled=true; - +bool ScriptServer::reload_scripts_on_save=false; void Script::_notification( int p_what) { @@ -92,6 +92,16 @@ void ScriptServer::init_languages() { } } +void ScriptServer::set_reload_scripts_on_save(bool p_enable) { + + reload_scripts_on_save=p_enable; +} + +bool ScriptServer::is_reload_scripts_on_save_enabled() { + + return reload_scripts_on_save; +} + void ScriptInstance::get_property_state(List > &state) { List pinfo; diff --git a/core/script_language.h b/core/script_language.h index cbf6d8e1161..478ebd88ed0 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -47,6 +47,7 @@ class ScriptServer { static ScriptLanguage *_languages[MAX_LANGUAGES]; static int _language_count; static bool scripting_enabled; + static bool reload_scripts_on_save; public: static void set_scripting_enabled(bool p_enabled); @@ -55,6 +56,9 @@ public: static ScriptLanguage *get_language(int p_idx); static void register_language(ScriptLanguage *p_language); + static void set_reload_scripts_on_save(bool p_enable); + static bool is_reload_scripts_on_save_enabled(); + static void init_languages(); }; diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index 2e7a9c0bbc8..875a144fef8 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -1791,8 +1791,9 @@ Error VariantParser::parse(Stream *p_stream, Variant& r_ret, String &r_err_str, static String rtosfix(double p_value) { + if (p_value==0.0) - return "0"; //avoid negative zero being written, which may annoy git, svn, etc. for changes when they don't exist. + return "0"; //avoid negative zero (-0) being written, which may annoy git, svn, etc. for changes when they don't exist. else return rtoss(p_value); } diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 359a9fe2d51..026fd048697 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -1898,6 +1898,11 @@ Error ResourceFormatSaverGDScript::save(const String &p_path,const RES& p_resour } file->close(); memdelete(file); + + if (ScriptServer::is_reload_scripts_on_save_enabled()) { + GDScriptLanguage::get_singleton()->reload_tool_script(p_resource,false); + } + return OK; } diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index 07356722148..48505324d31 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -2155,7 +2155,9 @@ void ScriptEditor::save_all_scripts() { editor->save_resource(script); //ResourceSaver::save(script->get_path(),script); + } + } } @@ -2276,6 +2278,8 @@ void ScriptEditor::_editor_settings_changed() { ste->get_text_edit()->set_draw_breakpoint_gutter(EditorSettings::get_singleton()->get("text_editor/show_breakpoint_gutter")); } + ScriptServer::set_reload_scripts_on_save(EDITOR_DEF("text_editor/auto_reload_and_parse_scripts_on_save",true)); + } void ScriptEditor::_autosave_scripts() { @@ -2617,8 +2621,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { edit_menu->get_popup()->add_item(TTR("Auto Indent"),EDIT_AUTO_INDENT,KEY_MASK_CMD|KEY_I); edit_menu->get_popup()->connect("item_pressed", this,"_menu_option"); edit_menu->get_popup()->add_separator(); - edit_menu->get_popup()->add_item(TTR("Reload Tool Script"),FILE_TOOL_RELOAD,KEY_MASK_CMD|KEY_R); - edit_menu->get_popup()->add_item(TTR("Reload Tool Script (Soft)"),FILE_TOOL_RELOAD_SOFT,KEY_MASK_CMD|KEY_MASK_SHIFT|KEY_R); + edit_menu->get_popup()->add_item(TTR("Soft Reload Script"),FILE_TOOL_RELOAD_SOFT,KEY_MASK_CMD|KEY_MASK_SHIFT|KEY_R); search_menu = memnew( MenuButton ); @@ -2922,6 +2925,7 @@ ScriptEditorPlugin::ScriptEditorPlugin(EditorNode *p_node) { script_editor->hide(); EDITOR_DEF("text_editor/auto_reload_scripts_on_external_change",true); + ScriptServer::set_reload_scripts_on_save(EDITOR_DEF("text_editor/auto_reload_and_parse_scripts_on_save",true)); EDITOR_DEF("text_editor/open_dominant_script_on_scene_change",true); EDITOR_DEF("external_editor/use_external_editor",false); EDITOR_DEF("external_editor/exec_path",""); @@ -2933,6 +2937,7 @@ ScriptEditorPlugin::ScriptEditorPlugin(EditorNode *p_node) { EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,"external_editor/exec_path",PROPERTY_HINT_GLOBAL_FILE)); EDITOR_DEF("external_editor/exec_flags",""); + }