From f19c9fbbb8983371ebf79affadfcc45c44a28a43 Mon Sep 17 00:00:00 2001 From: Hop311 Date: Tue, 26 Sep 2023 15:19:27 +0100 Subject: Expect modifier value + keys function --- src/openvic-simulation/map/TerrainType.cpp | 31 +++--------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) (limited to 'src/openvic-simulation/map/TerrainType.cpp') 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; } -- cgit v1.2.3-56-ga3b1