diff options
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r-- | src/openvic-simulation/map/Map.cpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/map/TerrainType.cpp | 31 |
2 files changed, 4 insertions, 29 deletions
diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp index e29f104..7ecff39 100644 --- a/src/openvic-simulation/map/Map.cpp +++ b/src/openvic-simulation/map/Map.cpp @@ -406,7 +406,7 @@ bool Map::load_region_file(ast::NodeCPtr root) { static constexpr colour_t colour_at(uint8_t const* colour_data, int32_t idx) { /* colour_data is filled with BGR byte triplets - to get pixel idx as a * single RGB value, multiply idx by 3 to get the index of the corresponding - * triplet, then combine the bytes in reverse order. + * triplet, then combine the bytes in reverse order. */ idx *= 3; return (colour_data[idx + 2] << 16) | (colour_data[idx + 1] << 8) | colour_data[idx]; diff --git a/src/openvic-simulation/map/TerrainType.cpp b/src/openvic-simulation/map/TerrainType.cpp index 3134332..e688625 100644 --- a/src/openvic-simulation/map/TerrainType.cpp +++ b/src/openvic-simulation/map/TerrainType.cpp @@ -82,35 +82,10 @@ bool TerrainTypeManager::_load_terrain_type_categories(ModifierManager const& mo ModifierValue values; colour_t colour = NULL_COLOUR; bool is_water = false; - bool has_colour = false, has_is_water = false; - bool ret = modifier_manager.expect_modifier_value(move_variable_callback(values), - [&colour, &has_colour, &is_water, &has_is_water](std::string_view key, ast::NodeCPtr value) -> bool { - if (key == "color") { - if (!has_colour) { - has_colour = true; - return expect_colour(assign_variable_callback(colour))(value); - } else { - Logger::error("Duplicate terrain type colour key!"); - return false; - } - } else if (key == "is_water") { - if (!has_is_water) { - has_is_water = true; - return expect_bool(assign_variable_callback(is_water))(value); - } else { - Logger::error("Duplicate terrain type is_water key!"); - return false; - } - } else { - Logger::error("Invalid terrain type entry key: ", key); - return false; - } - } + bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(values), + "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)), + "is_water", ZERO_OR_ONE, expect_bool(assign_variable_callback(is_water)) )(type_node); - if (!has_colour) { - Logger::error("Terrain type missing color key: ", type_key); - ret = false; - } ret &= add_terrain_type(type_key, colour, std::move(values), is_water); return ret; } |