Merge pull request #6850 from mattsc/mp_map_errors

MP Create Game dialog: improve error handling
This commit is contained in:
mattsc 2022-07-09 06:52:10 -07:00 committed by GitHub
commit 26081536a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions

View file

@ -72,6 +72,8 @@ void scenario::set_metadata()
try {
map_.reset(new gamemap(map_data));
} catch(const incorrect_map_format_error& e) {
// Set map content to nullptr, so that it fails can_launch_game()
map_.reset(nullptr);
data_["description"] = _("Map could not be loaded: ") + e.message;
ERR_CF << "map could not be loaded: " << e.message << '\n';
@ -662,6 +664,8 @@ void create_engine::init_all_levels()
try {
map.reset(new gamemap(user_map_data["map_data"]));
} catch (const incorrect_map_format_error& e) {
// Set map content to nullptr, so that it fails can_launch_game()
map.reset(nullptr);
user_map_data["description"] = _("Map could not be loaded: ") + e.message;
ERR_CF << "map could not be loaded: " << e.message << '\n';

View file

@ -660,7 +660,6 @@ void mp_create_game::update_details()
boost::replace_all(title, "\n", " " + font::unicode_em_dash + " ");
find_widget<styled_widget>(get_window(), "game_title", false).set_label(title);
show_description(create_engine_.current_level().description());
switch(create_engine_.current_level_type()) {
case level_type::type::scenario:
@ -714,6 +713,9 @@ void mp_create_game::update_details()
break;
}
}
// This needs to be at the end, since errors found expanding the map data are put into the description
show_description(create_engine_.current_level().description());
}
void mp_create_game::update_map_settings()

View file

@ -709,9 +709,10 @@ static ter_layer string_to_layer_(std::string_view str)
return NO_LAYER;
}
// Validate the string
VALIDATE(str.size() <= 4, _("A terrain with a string with more "
"than 4 characters has been found, the affected terrain is:") + std::string(str));
if(str.size() > 4) {
throw error("A terrain with a string with more "
"than 4 characters has been found, the affected terrain is: " + std::string(str));
}
ter_layer result = 0;
// The conversion to int puts the first char