aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map
diff options
context:
space:
mode:
author Arturo <69714460+Jarturog@users.noreply.github.com>2024-02-18 21:27:58 +0100
committer Arturo <69714460+Jarturog@users.noreply.github.com>2024-02-22 16:34:52 +0100
commit35b4fa2e5c6c7fd082493ec143cf236da69f7ba1 (patch)
treed3721476d72d0c25d52b51ec9845025f4e044384 /src/openvic-simulation/map
parent5216e893ebc5253b123bbf15b7509745d38f5a80 (diff)
Regions are now coloured from colors.txtregion-colours
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r--src/openvic-simulation/map/Map.cpp22
-rw-r--r--src/openvic-simulation/map/Map.hpp5
2 files changed, 20 insertions, 7 deletions
diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp
index a5cd6a6..f87246f 100644
--- a/src/openvic-simulation/map/Map.cpp
+++ b/src/openvic-simulation/map/Map.cpp
@@ -292,7 +292,7 @@ void Map::lock_water_provinces() {
Logger::info("Locked water provinces after registering ", water_provinces.size());
}
-bool Map::add_region(std::string_view identifier, Region::provinces_t const& provinces) {
+bool Map::add_region(std::string_view identifier, Region::provinces_t const& provinces, colour_t colour) {
if (identifier.empty()) {
Logger::error("Invalid region identifier - empty!");
return false;
@@ -304,7 +304,7 @@ bool Map::add_region(std::string_view identifier, Region::provinces_t const& pro
const bool meta = std::any_of(provinces.begin(), provinces.end(), std::bind_front(&Province::get_has_region));
- Region region { identifier, provinces.front()->get_colour(), meta };
+ Region region { identifier, colour, meta };
bool ret = region.add_provinces(provinces);
region.lock();
if (regions.add_item(std::move(region))) {
@@ -562,15 +562,27 @@ bool Map::load_province_positions(BuildingTypeManager const& building_type_manag
})(root);
}
-bool Map::load_region_file(ast::NodeCPtr root) {
+bool Map::load_region_colours(ast::NodeCPtr root, std::vector<colour_t>& colours) {
+ return expect_dictionary_reserve_length(
+ colours,
+ [&colours](std::string_view key, ast::NodeCPtr value) -> bool {
+ if (key != "color") {
+ Logger::error("Invalid key in region colours: \"", key, "\"");
+ return false;
+ }
+ return expect_colour(vector_callback(colours))(value);
+ })(root);
+}
+
+bool Map::load_region_file(ast::NodeCPtr root, std::vector<colour_t> const& colours) {
const bool ret = expect_dictionary_reserve_length(
regions,
- [this](std::string_view region_identifier, ast::NodeCPtr region_node) -> bool {
+ [this, &colours](std::string_view region_identifier, ast::NodeCPtr region_node) -> bool {
Region::provinces_t provinces;
bool ret = expect_list_reserve_length(
provinces, expect_province_identifier(vector_callback_pointer(provinces))
)(region_node);
- ret &= add_region(region_identifier, provinces);
+ ret &= add_region(region_identifier, provinces, colours[regions.size() % colours.size()]);
return ret;
}
)(root);
diff --git a/src/openvic-simulation/map/Map.hpp b/src/openvic-simulation/map/Map.hpp
index a472a6c..e2c4bd6 100644
--- a/src/openvic-simulation/map/Map.hpp
+++ b/src/openvic-simulation/map/Map.hpp
@@ -116,7 +116,7 @@ namespace OpenVic {
Province* get_selected_province();
Province::index_t get_selected_province_index() const;
- bool add_region(std::string_view identifier, Region::provinces_t const& provinces);
+ bool add_region(std::string_view identifier, Region::provinces_t const& provinces, colour_t colour);
bool add_mapmode(std::string_view identifier, Mapmode::colour_func_t colour_func);
@@ -139,7 +139,8 @@ namespace OpenVic {
bool load_province_definitions(std::vector<ovdl::csv::LineObject> const& lines);
/* Must be loaded after adjacencies so we know what provinces are coastal, and so can have a port */
bool load_province_positions(BuildingTypeManager const& building_type_manager, ast::NodeCPtr root);
- bool load_region_file(ast::NodeCPtr root);
+ static bool load_region_colours(ast::NodeCPtr root, std::vector<colour_t>& colours);
+ bool load_region_file(ast::NodeCPtr root, std::vector<colour_t> const& colours);
bool load_map_images(fs::path const& province_path, fs::path const& terrain_path, bool detailed_errors);
bool generate_and_load_province_adjacencies(std::vector<ovdl::csv::LineObject> const& additional_adjacencies);
bool load_climate_file(ModifierManager const& modifier_manager, ast::NodeCPtr root);