diff options
author | Hop311 <Hop3114@gmail.com> | 2023-09-26 18:15:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-26 18:15:43 +0200 |
commit | ca3996510ed6e26a81c781992d33c335ca250a16 (patch) | |
tree | e456ce0a8355ae2936d78a99b6c77ef785a8e5d5 /src/openvic-simulation/map/TerrainType.cpp | |
parent | 63e462fceff981f79bcbae53e8d90fc59733e8c2 (diff) | |
parent | 1c7b3239ab4e9f75d0605e5da852daf5afaa8c4a (diff) |
Merge pull request #35 from OpenVicProject/expect-modifier-keys
Expect modifier value + keys function
Diffstat (limited to 'src/openvic-simulation/map/TerrainType.cpp')
-rw-r--r-- | src/openvic-simulation/map/TerrainType.cpp | 31 |
1 files changed, 3 insertions, 28 deletions
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; } |