aboutsummaryrefslogtreecommitdiff
path: root/extension/src/LoadGameCompatibility.cpp
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-08-12 18:56:14 +0200
committer Hop311 <hop3114@gmail.com>2023-08-12 18:56:14 +0200
commitfe74604d96d1d28b811ebe45d1d06356cf79bc6f (patch)
treef57c608c657681666c29e28bf1283833767cb7ea /extension/src/LoadGameCompatibility.cpp
parent4c43951e70aaa2e7265d3b3f3c4964c048b9328d (diff)
string_view changes + general cleanup
Diffstat (limited to 'extension/src/LoadGameCompatibility.cpp')
-rw-r--r--extension/src/LoadGameCompatibility.cpp80
1 files changed, 40 insertions, 40 deletions
diff --git a/extension/src/LoadGameCompatibility.cpp b/extension/src/LoadGameCompatibility.cpp
index ddde5b8..71435a4 100644
--- a/extension/src/LoadGameCompatibility.cpp
+++ b/extension/src/LoadGameCompatibility.cpp
@@ -17,57 +17,57 @@ Error GameSingleton::_load_province_identifier_file_compatibility_mode(String co
Error err = FileAccess::get_open_error();
if (err != OK || file.is_null()) {
UtilityFunctions::push_error("Failed to load compatibility mode province identifier file: ", file_path);
- return err == OK ? FAILED : err;
- }
-
- int line_number = 0;
- while (!file->eof_reached()) {
- const PackedStringArray line = file->get_csv_line(";");
- line_number++;
+ if (err == OK) err = FAILED;
+ } else {
+ int line_number = 0;
+ while (!file->eof_reached()) {
+ const PackedStringArray line = file->get_csv_line(";");
+ line_number++;
- if (line.is_empty() || (line.size() == 1 && line[0].is_empty()))
- continue;
+ if (line.is_empty() || (line.size() == 1 && line[0].is_empty()))
+ continue;
- if (line_number < 2) continue; // skip header line
- index_t id = NULL_INDEX;
- colour_t colour = NULL_COLOUR;
- if (line.size() > 0) {
- if (line[0].is_empty()) {
- id = game_manager.map.get_province_count() + 1;
- } else if (line[0].is_valid_int()) {
- const int64_t val = line[0].to_int();
- if (val > NULL_INDEX && val <= MAX_INDEX) id = val;
- }
- for (int i = 1; i < 4; ++i) {
- if (line.size() > i) {
- if (line[i].is_valid_int()) {
- const int64_t int_val = line[i].to_int();
- if (int_val >= NULL_COLOUR && int_val <= FULL_COLOUR) {
- colour = (colour << 8) | int_val;
- continue;
- }
- } else if (line[i].is_valid_float()) {
- const double double_val = line[i].to_float();
- if (std::trunc(double_val) == double_val) {
- const int64_t int_val = double_val;
+ if (line_number < 2) continue; // skip header line
+ index_t id = NULL_INDEX;
+ colour_t colour = NULL_COLOUR;
+ if (line.size() > 0) {
+ if (line[0].is_empty()) {
+ id = game_manager.map.get_province_count() + 1;
+ } else if (line[0].is_valid_int()) {
+ const int64_t val = line[0].to_int();
+ if (val > NULL_INDEX && val <= MAX_INDEX) id = val;
+ }
+ for (int i = 1; i < 4; ++i) {
+ if (line.size() > i) {
+ if (line[i].is_valid_int()) {
+ const int64_t int_val = line[i].to_int();
if (int_val >= NULL_COLOUR && int_val <= FULL_COLOUR) {
colour = (colour << 8) | int_val;
continue;
}
+ } else if (line[i].is_valid_float()) {
+ const double double_val = line[i].to_float();
+ if (std::trunc(double_val) == double_val) {
+ const int64_t int_val = double_val;
+ if (int_val >= NULL_COLOUR && int_val <= FULL_COLOUR) {
+ colour = (colour << 8) | int_val;
+ continue;
+ }
+ }
}
}
+ colour = NULL_COLOUR;
+ break;
}
- colour = NULL_COLOUR;
- break;
}
+ if (id == NULL_INDEX || colour == NULL_COLOUR) {
+ UtilityFunctions::push_error("Invalid province ID-colour entry \"", line, "\" on line ", line_number, " in file: ", file_path);
+ err = FAILED;
+ continue;
+ }
+ static const std::string province_prefix = "PROV";
+ if (game_manager.map.add_province(province_prefix + std::to_string(id), colour) != SUCCESS) err = FAILED;
}
- if (id == NULL_INDEX || colour == NULL_COLOUR) {
- UtilityFunctions::push_error("Invalid province ID-colour entry \"", line, "\" on line ", line_number, " in file: ", file_path);
- err = FAILED;
- continue;
- }
- static const std::string province_prefix = "PROV";
- if (game_manager.map.add_province(province_prefix + std::to_string(id), colour) != SUCCESS) err = FAILED;
}
game_manager.map.lock_provinces();
return err;