aboutsummaryrefslogtreecommitdiff
path: root/extension/src
diff options
context:
space:
mode:
Diffstat (limited to 'extension/src')
-rw-r--r--extension/src/GameSingleton.cpp2
-rw-r--r--extension/src/GameSingleton.hpp2
-rw-r--r--extension/src/LoadGameCompatibility.cpp80
-rw-r--r--extension/src/LoadGameOpenVic.cpp12
4 files changed, 50 insertions, 46 deletions
diff --git a/extension/src/GameSingleton.cpp b/extension/src/GameSingleton.cpp
index baf4d44..7fc713a 100644
--- a/extension/src/GameSingleton.cpp
+++ b/extension/src/GameSingleton.cpp
@@ -9,7 +9,7 @@
using namespace godot;
using namespace OpenVic;
-TerrainVariant::TerrainVariant(std::string const& new_identfier,
+TerrainVariant::TerrainVariant(const std::string_view new_identfier,
colour_t new_colour, Ref<Image> const& new_image)
: HasIdentifierAndColour { new_identfier, new_colour, true },
image { new_image } {}
diff --git a/extension/src/GameSingleton.hpp b/extension/src/GameSingleton.hpp
index c4e90e0..cd8cdd0 100644
--- a/extension/src/GameSingleton.hpp
+++ b/extension/src/GameSingleton.hpp
@@ -12,7 +12,7 @@ namespace OpenVic {
private:
const godot::Ref<godot::Image> image;
- TerrainVariant(std::string const& new_identfier, colour_t new_colour,
+ TerrainVariant(const std::string_view new_identfier, colour_t new_colour,
godot::Ref<godot::Image> const& new_image);
public:
static constexpr size_t MAX_INDEX = 1 << (8 * sizeof(Map::terrain_t));
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;
diff --git a/extension/src/LoadGameOpenVic.cpp b/extension/src/LoadGameOpenVic.cpp
index 27fb265..627578f 100644
--- a/extension/src/LoadGameOpenVic.cpp
+++ b/extension/src/LoadGameOpenVic.cpp
@@ -157,7 +157,11 @@ Error GameSingleton::_parse_region_entry(String const& identifier, Variant const
UtilityFunctions::push_error("Invalid province list for region \"", identifier, "\": ", entry);
return FAILED;
}
- return ERR(game_manager.map.add_region(godot_to_std_string(identifier), province_identifiers));
+ std::vector<std::string_view> province_identifier_views;
+ for (std::string const& str : province_identifiers) {
+ province_identifier_views.push_back(str);
+ }
+ return ERR(game_manager.map.add_region(godot_to_std_string(identifier), province_identifier_views));
}
Error GameSingleton::_load_region_file(String const& file_path) {
@@ -271,7 +275,7 @@ Error GameSingleton::_load_map_images(String const& province_image_path, String
// Generate interleaved province and terrain ID image
if (game_manager.map.generate_province_shape_image(province_dims.x, province_dims.y, province_image->get_data().ptr(),
- terrain_image->get_data().ptr(), terrain_variant_map) != SUCCESS) err = FAILED;
+ terrain_image->get_data().ptr(), terrain_variant_map, true) != SUCCESS) err = FAILED;
static constexpr int32_t GPU_DIM_LIMIT = 0x3FFF;
// For each dimension of the image, this finds the small number of equal subdivisions required get the individual texture dims under GPU_DIM_LIMIT
@@ -364,8 +368,8 @@ Error GameSingleton::_parse_good_entry(String const& identifier, Variant const&
if (var_overseas_maintenance.get_type() == Variant::BOOL) overseas_maintenance = var_overseas_maintenance;
else UtilityFunctions::push_error("Invalid good overseas maintenance bool value for ", identifier, ": ", var_overseas_maintenance);
- return ERR(game_manager.good_manager.add_good(godot_to_std_string(identifier), godot_to_std_string(category),
- colour, base_price, default_available, tradeable, currency, overseas_maintenance));
+ return ERR(game_manager.good_manager.add_good(godot_to_std_string(identifier), colour, godot_to_std_string(category),
+ base_price, default_available, tradeable, currency, overseas_maintenance));
}
Error GameSingleton::_load_goods(String const& defines_path, String const& icons_dir_path) {