Merge pull request #94457 from BastiaanOlij/fix_load_action_map

Fix creating default action map
This commit is contained in:
Rémi Verschelde 2024-07-17 12:52:54 +02:00
commit f4942b7350
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -248,31 +248,26 @@ 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) { void OpenXRActionMapEditor::_load_action_map(const String p_path, bool p_create_new_if_missing) {
Error err = OK; Error err = OK;
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
if (da->file_exists(p_path)) {
action_map = ResourceLoader::load(p_path, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err); action_map = ResourceLoader::load(p_path, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err);
if (err != OK) { if (err != OK) {
if ((err == ERR_FILE_NOT_FOUND || err == ERR_CANT_OPEN) && p_create_new_if_missing) { 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.instantiate();
action_map->create_default_action_sets(); action_map->create_default_action_sets();
action_map->set_path(p_path);
// Save it immediately // Save it immediately
err = ResourceSaver::save(action_map, p_path); err = ResourceSaver::save(action_map, p_path);
if (err != OK) { if (err != OK) {
// Show warning but continue. // Show warning but continue.
EditorNode::get_singleton()->show_warning(vformat(TTR("Error saving file %s: %s"), edited_path, error_names[err])); 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 {
EditorNode::get_singleton()->show_warning(vformat(TTR("Error loading %s: %s."), edited_path, error_names[err]));
edited_path = "";
header_label->set_text("");
return;
} }
} }