From 9708e3a043a496123d460be924efd26f103a591b Mon Sep 17 00:00:00 2001 From: kennycastro007 Date: Thu, 15 Aug 2019 10:02:03 -0400 Subject: [PATCH] Fixed issue #8376 (#9866) #8376: Added static function show_error in S6Importer.cpp --- contributors.md | 1 + src/openrct2/Game.cpp | 2 -- src/openrct2/Game.h | 2 -- src/openrct2/GameState.cpp | 14 -------------- src/openrct2/rct2/S6Importer.cpp | 27 +++++++++++++++------------ 5 files changed, 16 insertions(+), 30 deletions(-) diff --git a/contributors.md b/contributors.md index 3d43463dfa..eaab02a41b 100644 --- a/contributors.md +++ b/contributors.md @@ -132,6 +132,7 @@ The following people are not part of the development team, but have been contrib * Steve Xu (stevexu-umich) * (aw20368) * Jim Armstrong (41northstudios) +* Kenny Castro-Monroy (kennycastro007) ## Toolchain * (Balletie) - macOS diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 99a9ad6e6e..bda1089541 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -83,8 +83,6 @@ uint32_t gCurrentRealTimeTicks; rct_string_id gGameCommandErrorTitle; rct_string_id gGameCommandErrorText; -uint8_t gErrorType; -rct_string_id gErrorStringId; using namespace OpenRCT2; diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index 51619c0c22..37b150210b 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -133,8 +133,6 @@ using GAME_COMMAND_POINTER = void( extern rct_string_id gGameCommandErrorTitle; extern rct_string_id gGameCommandErrorText; -extern uint8_t gErrorType; -extern rct_string_id gErrorStringId; extern GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT]; diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index ff881c3453..142e704471 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -292,20 +292,6 @@ void GameState::UpdateLogic() // Update windows // window_dispatch_update_all(); - if (gErrorType != ERROR_TYPE_NONE) - { - rct_string_id title_text = STR_UNABLE_TO_LOAD_FILE; - rct_string_id body_text = gErrorStringId; - if (gErrorType == ERROR_TYPE_GENERIC) - { - title_text = gErrorStringId; - body_text = 0xFFFF; - } - gErrorType = ERROR_TYPE_NONE; - - context_show_error(title_text, body_text); - } - // Start autosave timer after update if (gLastAutoSaveUpdate == AUTOSAVE_PAUSE) { diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 16a5c9739f..ed29354d9d 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -1528,6 +1528,15 @@ std::unique_ptr ParkImporter::CreateS6(IObjectRepository& objectR return std::make_unique(objectRepository); } +static void show_error(uint8_t errorType, rct_string_id errorStringId) +{ + if (errorType == ERROR_TYPE_GENERIC) + { + context_show_error(errorStringId, 0xFFFF); + } + context_show_error(STR_UNABLE_TO_LOAD_FILE, errorStringId); +} + void load_from_sv6(const char* path) { auto context = OpenRCT2::GetContext(); @@ -1546,19 +1555,16 @@ void load_from_sv6(const char* path) } catch (const ObjectLoadException&) { - gErrorType = ERROR_TYPE_FILE_LOAD; - gErrorStringId = STR_FILE_CONTAINS_INVALID_DATA; + show_error(ERROR_TYPE_FILE_LOAD, STR_FILE_CONTAINS_INVALID_DATA); } catch (const IOException& loadError) { - gErrorType = ERROR_TYPE_FILE_LOAD; - gErrorStringId = STR_GAME_SAVE_FAILED; log_error("Error loading: %s", loadError.what()); + show_error(ERROR_TYPE_FILE_LOAD, STR_GAME_SAVE_FAILED); } catch (const std::exception&) { - gErrorType = ERROR_TYPE_FILE_LOAD; - gErrorStringId = STR_FILE_CONTAINS_INVALID_DATA; + show_error(ERROR_TYPE_FILE_LOAD, STR_FILE_CONTAINS_INVALID_DATA); } } @@ -1584,20 +1590,17 @@ void load_from_sc6(const char* path) } catch (const ObjectLoadException& loadError) { - gErrorType = ERROR_TYPE_FILE_LOAD; - gErrorStringId = STR_GAME_SAVE_FAILED; log_error("Error loading: %s", loadError.what()); + show_error(ERROR_TYPE_FILE_LOAD, STR_GAME_SAVE_FAILED); } catch (const IOException& loadError) { - gErrorType = ERROR_TYPE_FILE_LOAD; - gErrorStringId = STR_GAME_SAVE_FAILED; log_error("Error loading: %s", loadError.what()); + show_error(ERROR_TYPE_FILE_LOAD, STR_GAME_SAVE_FAILED); } catch (const std::exception&) { - gErrorType = ERROR_TYPE_FILE_LOAD; - gErrorStringId = STR_FILE_CONTAINS_INVALID_DATA; + show_error(ERROR_TYPE_FILE_LOAD, STR_FILE_CONTAINS_INVALID_DATA); } gScreenAge = 0; gLastAutoSaveUpdate = AUTOSAVE_PAUSE;