Skip to content

Commit

Permalink
Improve UID support for main scene
Browse files Browse the repository at this point in the history
  • Loading branch information
KoBeWi committed Dec 16, 2024
1 parent b9437c3 commit 62d4928
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
18 changes: 9 additions & 9 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,7 @@ void EditorNode::_dialog_action(String p_file) {
load_scene(p_file);
} break;
case SETTINGS_PICK_MAIN_SCENE: {
ProjectSettings::get_singleton()->set("application/run/main_scene", p_file);
ProjectSettings::get_singleton()->set("application/run/main_scene", ResourceUID::path_to_uid(p_file));
ProjectSettings::get_singleton()->save();
// TODO: Would be nice to show the project manager opened with the highlighted field.

Expand Down Expand Up @@ -2134,7 +2134,7 @@ void EditorNode::_dialog_action(String p_file) {
} break;

case FILE_SAVE_AND_RUN_MAIN_SCENE: {
ProjectSettings::get_singleton()->set("application/run/main_scene", p_file);
ProjectSettings::get_singleton()->set("application/run/main_scene", ResourceUID::path_to_uid(p_file));
ProjectSettings::get_singleton()->save();

if (file->get_file_mode() == EditorFileDialog::FILE_MODE_SAVE_FILE) {
Expand Down Expand Up @@ -3962,25 +3962,25 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b
return OK;
}

String lpath = ResourceUID::ensure_path(p_scene);
if (!p_set_inherited) {
for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
if (editor_data.get_scene_path(i) == p_scene) {
if (editor_data.get_scene_path(i) == lpath) {
_set_current_scene(i);
return OK;
}
}

if (!p_force_open_imported && FileAccess::exists(p_scene + ".import")) {
open_imported->set_text(vformat(TTR("Scene '%s' was automatically imported, so it can't be modified.\nTo make changes to it, a new inherited scene can be created."), p_scene.get_file()));
if (!p_force_open_imported && FileAccess::exists(lpath + ".import")) {
open_imported->set_text(vformat(TTR("Scene '%s' was automatically imported, so it can't be modified.\nTo make changes to it, a new inherited scene can be created."), lpath.get_file()));
open_imported->popup_centered();
new_inherited_button->grab_focus();
open_import_request = p_scene;
open_import_request = lpath;
return OK;
}
}

String lpath = ProjectSettings::get_singleton()->localize_path(p_scene);

lpath = ProjectSettings::get_singleton()->localize_path(lpath);
if (!lpath.begins_with("res://")) {
show_accept(TTR("Error loading scene, it must be inside the project path. Use 'Import' to open the scene, then save it inside the project path."), TTR("OK"));
opening_prev = false;
Expand Down Expand Up @@ -4081,7 +4081,7 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b

set_edited_scene(new_scene);

String config_file_path = EditorPaths::get_singleton()->get_project_settings_dir().path_join(p_scene.get_file() + "-editstate-" + p_scene.md5_text() + ".cfg");
String config_file_path = EditorPaths::get_singleton()->get_project_settings_dir().path_join(lpath.get_file() + "-editstate-" + lpath.md5_text() + ".cfg");
Ref<ConfigFile> editor_state_cf;
editor_state_cf.instantiate();
Error editor_state_cf_err = editor_state_cf->load(config_file_path);
Expand Down
6 changes: 3 additions & 3 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory

// Create all items for the files in the subdirectory.
if (display_mode == DISPLAY_MODE_TREE_ONLY) {
String main_scene = GLOBAL_GET("application/run/main_scene");
const String main_scene = ResourceUID::ensure_path(GLOBAL_GET("application/run/main_scene"));

// Build the list of the files to display.
List<FileInfo> file_list;
Expand Down Expand Up @@ -1125,7 +1125,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) {
sort_file_info_list(file_list, file_sort);

// Fills the ItemList control node from the FileInfos.
String main_scene = GLOBAL_GET("application/run/main_scene");
const String main_scene = ResourceUID::ensure_path(GLOBAL_GET("application/run/main_scene"));
for (FileInfo &E : file_list) {
FileInfo *finfo = &(E);
String fname = finfo->name;
Expand Down Expand Up @@ -2379,7 +2379,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
case FILE_MAIN_SCENE: {
// Set as main scene with selected scene file.
if (p_selected.size() == 1) {
ProjectSettings::get_singleton()->set("application/run/main_scene", p_selected[0]);
ProjectSettings::get_singleton()->set("application/run/main_scene", ResourceUID::path_to_uid(p_selected[0]));
ProjectSettings::get_singleton()->save();
_update_tree(get_uncollapsed_paths());
_update_file_list(true);
Expand Down
4 changes: 2 additions & 2 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3817,8 +3817,8 @@ int Main::start() {

#endif // TOOLS_ENABLED

if (script.is_empty() && game_path.is_empty() && String(GLOBAL_GET("application/run/main_scene")) != "") {
game_path = GLOBAL_GET("application/run/main_scene");
if (script.is_empty() && game_path.is_empty()) {
game_path = ResourceUID::ensure_path(GLOBAL_GET("application/run/main_scene"));
}

#ifdef TOOLS_ENABLED
Expand Down

0 comments on commit 62d4928

Please sign in to comment.