Skip to content

Commit e2323b8

Browse files
committed
time duration reader for recipes
1 parent ca8f492 commit e2323b8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/recipe.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ bool recipe::has_flag( const std::string &flag_name ) const
152152
return flags.count( flag_name );
153153
}
154154

155+
struct time_duration_as_moves_reader : public generic_typed_reader<time_duration_as_moves_reader> {
156+
int64_t get_next( const JsonValue &jv ) const {
157+
time_duration ret;
158+
jv.read( ret );
159+
return to_moves<int64_t>( ret );
160+
}
161+
};
162+
155163
void recipe::load( const JsonObject &jo, const std::string_view src )
156164
{
157165
abstract = jo.has_string( "abstract" );
@@ -221,10 +229,7 @@ void recipe::load( const JsonObject &jo, const std::string_view src )
221229
return;
222230
}
223231

224-
if( jo.has_string( "time" ) ) {
225-
time = to_moves<int>( read_from_json_string<time_duration>( jo.get_member( "time" ),
226-
time_duration::units ) );
227-
}
232+
optional( jo, was_loaded, "time", time, time_duration_as_moves_reader{}, 0 );
228233
optional( jo, was_loaded, "difficulty", difficulty, numeric_bound_reader<int> {0, MAX_SKILL} );
229234
optional( jo, was_loaded, "flags", flags );
230235

0 commit comments

Comments
 (0)