From 9e658e29d2a47d39eabe9ba6651b50403440e918 Mon Sep 17 00:00:00 2001 From: Bastiaan Olij Date: Wed, 17 Jul 2024 12:04:06 +1000 Subject: [PATCH] Fixed creating default action map --- .../editor/openxr_action_map_editor.cpp | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/modules/openxr/editor/openxr_action_map_editor.cpp b/modules/openxr/editor/openxr_action_map_editor.cpp index 51e6c3e2773..a353073f215 100644 --- a/modules/openxr/editor/openxr_action_map_editor.cpp +++ b/modules/openxr/editor/openxr_action_map_editor.cpp @@ -248,32 +248,27 @@ void OpenXRActionMapEditor::_on_interaction_profile_selected(const String p_path void OpenXRActionMapEditor::_load_action_map(const String p_path, bool p_create_new_if_missing) { Error err = OK; - action_map = ResourceLoader::load(p_path, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err); - if (err != OK) { - if ((err == ERR_FILE_NOT_FOUND || err == ERR_CANT_OPEN) && p_create_new_if_missing) { - action_map.instantiate(); - action_map->create_default_action_sets(); - - // Save it immediately - err = ResourceSaver::save(action_map, p_path); - if (err != OK) { - // Show warning but continue. - EditorNode::get_singleton()->show_warning(vformat(TTR("Error saving file %s: %s"), edited_path, error_names[err])); - } else { - // Reload so it's cached. - action_map = ResourceLoader::load(p_path, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err); - if (err != OK) { - // Show warning but continue. - EditorNode::get_singleton()->show_warning(vformat(TTR("Error reloading file %s: %s"), edited_path, error_names[err])); - } - } - } else { + Ref da = DirAccess::create(DirAccess::ACCESS_RESOURCES); + if (da->file_exists(p_path)) { + action_map = ResourceLoader::load(p_path, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err); + if (err != OK) { EditorNode::get_singleton()->show_warning(vformat(TTR("Error loading %s: %s."), edited_path, error_names[err])); edited_path = ""; header_label->set_text(""); return; } + } else if (p_create_new_if_missing) { + action_map.instantiate(); + action_map->create_default_action_sets(); + action_map->set_path(p_path); + + // Save it immediately + err = ResourceSaver::save(action_map, p_path); + if (err != OK) { + // Show warning but continue. + EditorNode::get_singleton()->show_warning(vformat(TTR("Error saving file %s: %s"), edited_path, error_names[err])); + } } edited_path = p_path;