2to3 exporter: Enable script conversion and option to mark changes

This commit is contained in:
Rémi Verschelde 2018-03-16 11:48:39 +01:00
parent ddeb4ff2b0
commit 29e2182c41
4 changed files with 22 additions and 7 deletions

View File

@ -2056,7 +2056,7 @@ void EditorExportGodot3::_save_config(const String &p_path) {
f->close(); f->close();
} }
Error EditorExportGodot3::_convert_script(const String &p_path, const String &p_target_path) { Error EditorExportGodot3::_convert_script(const String &p_path, const String &p_target_path, bool mark_converted_lines) {
FileAccessRef src = FileAccess::open(p_path, FileAccess::READ); FileAccessRef src = FileAccess::open(p_path, FileAccess::READ);
ERR_FAIL_COND_V(!src.operator->(), FAILED); ERR_FAIL_COND_V(!src.operator->(), FAILED);
@ -2064,9 +2064,11 @@ Error EditorExportGodot3::_convert_script(const String &p_path, const String &p_
ERR_FAIL_COND_V(!dst.operator->(), FAILED); ERR_FAIL_COND_V(!dst.operator->(), FAILED);
String http_var = ""; String http_var = "";
const String note = " #-- NOTE: Automatically converted by Godot 2 to 3 converter, please review";
while (!src->eof_reached()) { while (!src->eof_reached()) {
String line = src->get_line(); String line = src->get_line();
String origline = line;
// Convert _fixed_process( => _physics_process( // Convert _fixed_process( => _physics_process(
RegEx regexp("(.*)_fixed_process\\((.*)"); RegEx regexp("(.*)_fixed_process\\((.*)");
@ -2252,13 +2254,18 @@ Error EditorExportGodot3::_convert_script(const String &p_path, const String &p_
} while (count >= 1 && tries++ < 10); } while (count >= 1 && tries++ < 10);
if (mark_converted_lines && line != origline) {
// Add explanatory comment on the changed line
line += note;
}
dst->store_line(line); dst->store_line(line);
} }
return OK; return OK;
} }
Error EditorExportGodot3::export_godot3(const String &p_path, bool convert_scripts) { Error EditorExportGodot3::export_godot3(const String &p_path, bool convert_scripts, bool mark_converted_lines) {
List<String> files; List<String> files;
_find_files(EditorFileSystem::get_singleton()->get_filesystem(), &files); _find_files(EditorFileSystem::get_singleton()->get_filesystem(), &files);
@ -2468,7 +2475,7 @@ Error EditorExportGodot3::export_godot3(const String &p_path, bool convert_scrip
} else { } else {
if (convert_scripts && extension == "gd") { if (convert_scripts && extension == "gd") {
err = _convert_script(path, target_path); err = _convert_script(path, target_path, mark_converted_lines);
} else { } else {
//single file, copy it //single file, copy it
err = directory->copy(path, target_path); err = directory->copy(path, target_path);

View File

@ -87,12 +87,12 @@ class EditorExportGodot3 {
void _unpack_packed_scene(ExportData &resource); void _unpack_packed_scene(ExportData &resource);
void _pack_packed_scene(ExportData &resource); void _pack_packed_scene(ExportData &resource);
Error _convert_script(const String &p_path, const String &p_target_path); Error _convert_script(const String &p_path, const String &p_target_path, bool mark_converted_lines);
void _find_files(EditorFileSystemDirectory *p_dir, List<String> *r_files); void _find_files(EditorFileSystemDirectory *p_dir, List<String> *r_files);
public: public:
Error export_godot3(const String &p_path, bool convert_scripts); Error export_godot3(const String &p_path, bool convert_scripts, bool mark_converted_lines);
EditorExportGodot3(); EditorExportGodot3();
}; };

View File

@ -5101,7 +5101,7 @@ void EditorNode::_export_godot3_path(const String &p_path) {
location = nl; location = nl;
} }
Error err = export_godot3.export_godot3(p_path, export_godot3_dialog_convert_scripts->is_pressed()); Error err = export_godot3.export_godot3(p_path, export_godot3_dialog_convert_scripts->is_pressed(), export_godot3_dialog_mark_converted_lines->is_pressed());
if (err != OK) { if (err != OK) {
show_warning(TTR("Error exporting project to Godot 3.0.")); show_warning(TTR("Error exporting project to Godot 3.0."));
} }
@ -6370,10 +6370,17 @@ EditorNode::EditorNode() {
export_godot3_dialog = memnew(FileDialog); export_godot3_dialog = memnew(FileDialog);
export_godot3_dialog->set_access(FileDialog::ACCESS_FILESYSTEM); export_godot3_dialog->set_access(FileDialog::ACCESS_FILESYSTEM);
export_godot3_dialog->set_mode(FileDialog::MODE_OPEN_DIR); export_godot3_dialog->set_mode(FileDialog::MODE_OPEN_DIR);
export_godot3_dialog_convert_scripts = memnew(CheckButton); export_godot3_dialog_convert_scripts = memnew(CheckButton);
export_godot3_dialog_convert_scripts->set_text(TTR("Convert scripts (experimental)")); export_godot3_dialog_convert_scripts->set_text(TTR("Convert scripts (experimental)"));
export_godot3_dialog_convert_scripts->set_pressed(false); export_godot3_dialog_convert_scripts->set_pressed(true);
export_godot3_dialog->get_vbox()->add_child(export_godot3_dialog_convert_scripts); export_godot3_dialog->get_vbox()->add_child(export_godot3_dialog_convert_scripts);
export_godot3_dialog_mark_converted_lines = memnew(CheckButton);
export_godot3_dialog_mark_converted_lines->set_text(TTR("Mark converted lines in scripts with a comment"));
export_godot3_dialog_mark_converted_lines->set_pressed(false);
export_godot3_dialog->get_vbox()->add_child(export_godot3_dialog_mark_converted_lines);
gui_base->add_child(export_godot3_dialog); gui_base->add_child(export_godot3_dialog);
export_godot3_dialog->connect("dir_selected", this, "_export_godot3_path"); export_godot3_dialog->connect("dir_selected", this, "_export_godot3_path");

View File

@ -280,6 +280,7 @@ private:
EditorExportGodot3 export_godot3; EditorExportGodot3 export_godot3;
FileDialog *export_godot3_dialog; FileDialog *export_godot3_dialog;
CheckButton *export_godot3_dialog_convert_scripts; CheckButton *export_godot3_dialog_convert_scripts;
CheckButton *export_godot3_dialog_mark_converted_lines;
CreateDialog *create_dialog; CreateDialog *create_dialog;