Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple minor version migration #96861

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions editor/project_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ void ProjectManager::_open_selected_projects_ask() {
if (!unsupported_features.is_empty()) {
String warning_message = "";
for (int i = 0; i < unsupported_features.size(); i++) {
String feature = unsupported_features[i];
const String &feature = unsupported_features[i];
if (feature == "Double Precision") {
warning_message += TTR("Warning: This project uses double precision floats, but this version of\nGodot uses single precision floats. Opening this project may cause data loss.\n\n");
unsupported_features.remove_at(i);
Expand All @@ -590,6 +590,7 @@ void ProjectManager::_open_selected_projects_ask() {
unsupported_features.remove_at(i);
i--;
} else if (ProjectList::project_feature_looks_like_version(feature)) {
version_convert_feature = feature;
warning_message += vformat(TTR("Warning: This project was last edited in Godot %s. Opening will change it to Godot %s.\n\n"), Variant(feature), Variant(VERSION_BRANCH));
unsupported_features.remove_at(i);
i--;
Expand All @@ -610,6 +611,16 @@ void ProjectManager::_open_selected_projects_ask() {
_open_selected_projects();
}

void ProjectManager::_open_selected_projects_with_migration() {
#ifndef DISABLE_DEPRECATED
if (project_list->get_selected_projects().size() == 1) {
// Only migrate if a single project is opened.
_minor_project_migrate();
}
#endif
_open_selected_projects();
}

void ProjectManager::_install_project(const String &p_zip_path, const String &p_title) {
project_dialog->set_mode(ProjectDialog::MODE_INSTALL);
project_dialog->set_zip_path(p_zip_path);
Expand Down Expand Up @@ -877,6 +888,34 @@ void ProjectManager::add_new_tag(const String &p_tag) {

// Project converter/migration tool.

#ifndef DISABLE_DEPRECATED
void ProjectManager::_minor_project_migrate() {
const ProjectList::Item migrated_project = project_list->get_selected_projects()[0];

if (version_convert_feature.begins_with("4.3")) {
// Migrate layout after scale changes.
const float edscale = EDSCALE;
if (edscale != 1.0) {
Ref<ConfigFile> layout_file;
layout_file.instantiate();

const String layout_path = migrated_project.path.path_join(".godot/editor/editor_layout.cfg");
Error err = layout_file->load(layout_path);
if (err == OK) {
for (int i = 0; i < 4; i++) {
const String key = "dock_hsplit_" + itos(i + 1);
int old_value = layout_file->get_value("docks", key, 0);
if (old_value != 0) {
layout_file->set_value("docks", key, old_value / edscale);
}
}
layout_file->save(layout_path);
}
}
}
}
#endif

void ProjectManager::_full_convert_button_pressed() {
ask_update_settings->hide();
ask_full_convert_dialog->popup_centered(Size2i(600.0 * EDSCALE, 0));
Expand Down Expand Up @@ -1487,7 +1526,7 @@ ProjectManager::ProjectManager() {

ask_update_settings = memnew(ConfirmationDialog);
ask_update_settings->set_autowrap(true);
ask_update_settings->get_ok_button()->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_open_selected_projects));
ask_update_settings->get_ok_button()->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_open_selected_projects_with_migration));
full_convert_button = ask_update_settings->add_button(TTR("Convert Full Project"), !GLOBAL_GET("gui/common/swap_cancel_ok"));
full_convert_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_full_convert_button_pressed));
add_child(ask_update_settings);
Expand Down
6 changes: 6 additions & 0 deletions editor/project_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class ProjectManager : public Control {
void _run_project_confirm();
void _open_selected_projects();
void _open_selected_projects_ask();
void _open_selected_projects_with_migration();

void _install_project(const String &p_zip_path, const String &p_title);
void _import_project();
Expand Down Expand Up @@ -223,6 +224,11 @@ class ProjectManager : public Control {
ConfirmationDialog *ask_update_settings = nullptr;
Button *full_convert_button = nullptr;

String version_convert_feature;

#ifndef DISABLE_DEPRECATED
void _minor_project_migrate();
#endif
void _full_convert_button_pressed();
void _perform_full_project_conversion();

Expand Down
Loading