Skip to content

Commit

Permalink
Auto-reload scripts with external editor
Browse files Browse the repository at this point in the history
  • Loading branch information
yjh0502 committed Aug 18, 2021
1 parent 2875cd1 commit 5c66891
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions editor/plugins/script_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,10 @@ void ScriptEditor::_res_saved_callback(const Ref<Resource> &p_res) {
}

_update_script_names();
_trigger_live_script_reload();
}

void ScriptEditor::_trigger_live_script_reload() {
if (!pending_auto_reload && auto_reload_running_scripts) {
call_deferred("_live_auto_reload_running_scripts");
pending_auto_reload = true;
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/script_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ class ScriptEditor : public PanelContainer {

bool pending_auto_reload;
bool auto_reload_running_scripts;
void _trigger_live_script_reload();
void _live_auto_reload_running_scripts();

void _update_selected_editor_menu();
Expand Down
2 changes: 2 additions & 0 deletions editor/plugins/script_text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,8 @@ void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_fo
script->set_source_code(rel_script->get_source_code());
script->set_last_modified_time(rel_script->get_last_modified_time());
script->update_exports();

_trigger_live_script_reload();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/gdscript/gdscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2168,7 +2168,7 @@ RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_ori

if (p_path.ends_with(".gde") || p_path.ends_with(".gdc")) {
script->set_script_path(p_original_path); // script needs this.
script->set_path(p_original_path);
script->set_path(p_original_path, true);
Error err = script->load_byte_code(p_path);
ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot load byte code from file '" + p_path + "'.");

Expand All @@ -2177,7 +2177,7 @@ RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_ori
ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot load source code from file '" + p_path + "'.");

script->set_script_path(p_original_path); // script needs this.
script->set_path(p_original_path);
script->set_path(p_original_path, true);

script->reload();
}
Expand Down

0 comments on commit 5c66891

Please sign in to comment.